Skip to content

Commit

Permalink
oops forgot to add this to diff
Browse files Browse the repository at this point in the history
  • Loading branch information
samliok committed Nov 5, 2024
1 parent 01d501d commit fa8043a
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 114 deletions.
8 changes: 8 additions & 0 deletions examples/morpheusvm/throughput/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,11 @@ func (*SpamHelper) GetTransfer(address codec.Address, amount uint64, memo []byte
Memo: memo,
}}
}

func (sh *SpamHelper) GetAction() []chain.Action {
return []chain.Action{&actions.Transfer{
To: codec.Address{},
Value: 0,
Memo: []byte{},
}}
}
216 changes: 106 additions & 110 deletions tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ package e2e

import (
"fmt"
"sync"
"time"

"github.com/ava-labs/avalanchego/api/info"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/tests/fixture/tmpnet"
"github.com/stretchr/testify/require"

"github.com/ava-labs/hypersdk/abi"
Expand All @@ -22,7 +19,6 @@ import (
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/tests/workload"
"github.com/ava-labs/hypersdk/throughput"
"github.com/ava-labs/hypersdk/utils"

ginkgo "github.com/onsi/ginkgo/v2"
)
Expand Down Expand Up @@ -137,112 +133,112 @@ var _ = ginkgo.Describe("[HyperSDK Spam Workloads]", func() {
})
})

var _ = ginkgo.Describe("[HyperSDK Syncing]", func() {
ginkgo.It("[Sync]", func() {
tc := e2e.NewTestContext()
require := require.New(tc)
blockchainID := e2e.GetEnv(tc).GetNetwork().GetSubnet(vmName).Chains[0].ChainID

uris := getE2EURIs(tc, blockchainID)
ginkgo.By("Generate 128 blocks", func() {
txWorkload.GenerateBlocks(tc.ContextWithTimeout(5*time.Minute), require, uris, 128)
})

var (
bootstrapNode *tmpnet.Node
bootstrapNodeURI string
)
ginkgo.By("Start a new node to bootstrap", func() {
bootstrapNode = e2e.CheckBootstrapIsPossible(tc, e2e.GetEnv(tc).GetNetwork())
bootstrapNodeURI = formatURI(bootstrapNode.URI, blockchainID)
uris = append(uris, bootstrapNodeURI)
})
ginkgo.By("Accept a transaction after state sync", func() {
txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, bootstrapNodeURI, uris)
})

ginkgo.By("Restart the node", func() {
require.NoError(e2e.GetEnv(tc).GetNetwork().RestartNode(tc.DefaultContext(), ginkgo.GinkgoWriter, bootstrapNode))
})
ginkgo.By("Generate > StateSyncMinBlocks=512", func() {
txWorkload.GenerateBlocks(tc.ContextWithTimeout(20*time.Minute), require, uris, 512)
})
var (
syncNode *tmpnet.Node
syncNodeURI string
)
ginkgo.By("Start a new node to state sync", func() {
syncNode = e2e.CheckBootstrapIsPossible(tc, e2e.GetEnv(tc).GetNetwork())
syncNodeURI = formatURI(syncNode.URI, blockchainID)
uris = append(uris, syncNodeURI)
utils.Outf("{{blue}}sync node uri: %s{{/}}\n", syncNodeURI)
c := jsonrpc.NewJSONRPCClient(syncNodeURI)
_, _, _, err := c.Network(tc.DefaultContext())
require.NoError(err)
})
ginkgo.By("Accept a transaction after state sync", func() {
txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, syncNodeURI, uris)
})
ginkgo.By("Pause the node", func() {
// TODO: remove the need to call SaveAPIPort from the test
require.NoError(syncNode.SaveAPIPort())
require.NoError(syncNode.Stop(tc.DefaultContext()))

// TODO: remove extra Ping check and rely on tmpnet to stop the node correctly
c := jsonrpc.NewJSONRPCClient(syncNodeURI)
ok, err := c.Ping(tc.DefaultContext())
require.Error(err) //nolint:forbidigo
require.False(ok)
})
ginkgo.By("Generate 256 blocks", func() {
// Generate blocks on all nodes except the paused node
runningURIs := uris[:len(uris)-1]
txWorkload.GenerateBlocks(tc.ContextWithTimeout(5*time.Minute), require, runningURIs, 256)
})
ginkgo.By("Resume the node", func() {
require.NoError(e2e.GetEnv(tc).GetNetwork().StartNode(tc.DefaultContext(), ginkgo.GinkgoWriter, syncNode))
utils.Outf("Waiting for sync node to restart")
require.NoError(tmpnet.WaitForHealthy(tc.DefaultContext(), syncNode))

utils.Outf("{{blue}}sync node reporting healthy: %s{{/}}\n", syncNodeURI)

c := jsonrpc.NewJSONRPCClient(syncNodeURI)
_, _, _, err := c.Network(tc.DefaultContext())
require.NoError(err)
})

ginkgo.By("Accept a transaction after resuming", func() {
txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, syncNodeURI, uris)
})
ginkgo.By("State sync while broadcasting txs", func() {
stopChannel := make(chan struct{})
wg := &sync.WaitGroup{}
defer wg.Wait()
defer close(stopChannel)

wg.Add(1)
go func() {
defer wg.Done()
// Recover failure if exits
defer ginkgo.GinkgoRecover()
txWorkload.GenerateUntilStop(tc.DefaultContext(), require, uris, 128, stopChannel)
}()

// Give time for transactions to start processing
time.Sleep(5 * time.Second)

syncConcurrentNode := e2e.CheckBootstrapIsPossible(tc, e2e.GetEnv(tc).GetNetwork())
syncConcurrentNodeURI := formatURI(syncConcurrentNode.URI, blockchainID)
uris = append(uris, syncConcurrentNodeURI)
c := jsonrpc.NewJSONRPCClient(syncConcurrentNodeURI)
_, _, _, err := c.Network(tc.DefaultContext())
require.NoError(err)
})
ginkgo.By("Accept a transaction after syncing", func() {
txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, uris[0], uris)
})
})
})
// var _ = ginkgo.Describe("[HyperSDK Syncing]", func() {
// ginkgo.It("[Sync]", func() {
// tc := e2e.NewTestContext()
// require := require.New(tc)
// blockchainID := e2e.GetEnv(tc).GetNetwork().GetSubnet(vmName).Chains[0].ChainID

// uris := getE2EURIs(tc, blockchainID)
// ginkgo.By("Generate 128 blocks", func() {
// txWorkload.GenerateBlocks(tc.ContextWithTimeout(5*time.Minute), require, uris, 128)
// })

// var (
// bootstrapNode *tmpnet.Node
// bootstrapNodeURI string
// )
// ginkgo.By("Start a new node to bootstrap", func() {
// bootstrapNode = e2e.CheckBootstrapIsPossible(tc, e2e.GetEnv(tc).GetNetwork())
// bootstrapNodeURI = formatURI(bootstrapNode.URI, blockchainID)
// uris = append(uris, bootstrapNodeURI)
// })
// ginkgo.By("Accept a transaction after state sync", func() {
// txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, bootstrapNodeURI, uris)
// })

// ginkgo.By("Restart the node", func() {
// require.NoError(e2e.GetEnv(tc).GetNetwork().RestartNode(tc.DefaultContext(), ginkgo.GinkgoWriter, bootstrapNode))
// })
// ginkgo.By("Generate > StateSyncMinBlocks=512", func() {
// txWorkload.GenerateBlocks(tc.ContextWithTimeout(20*time.Minute), require, uris, 512)
// })
// var (
// syncNode *tmpnet.Node
// syncNodeURI string
// )
// ginkgo.By("Start a new node to state sync", func() {
// syncNode = e2e.CheckBootstrapIsPossible(tc, e2e.GetEnv(tc).GetNetwork())
// syncNodeURI = formatURI(syncNode.URI, blockchainID)
// uris = append(uris, syncNodeURI)
// utils.Outf("{{blue}}sync node uri: %s{{/}}\n", syncNodeURI)
// c := jsonrpc.NewJSONRPCClient(syncNodeURI)
// _, _, _, err := c.Network(tc.DefaultContext())
// require.NoError(err)
// })
// ginkgo.By("Accept a transaction after state sync", func() {
// txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, syncNodeURI, uris)
// })
// ginkgo.By("Pause the node", func() {
// // TODO: remove the need to call SaveAPIPort from the test
// require.NoError(syncNode.SaveAPIPort())
// require.NoError(syncNode.Stop(tc.DefaultContext()))

// // TODO: remove extra Ping check and rely on tmpnet to stop the node correctly
// c := jsonrpc.NewJSONRPCClient(syncNodeURI)
// ok, err := c.Ping(tc.DefaultContext())
// require.Error(err) //nolint:forbidigo
// require.False(ok)
// })
// ginkgo.By("Generate 256 blocks", func() {
// // Generate blocks on all nodes except the paused node
// runningURIs := uris[:len(uris)-1]
// txWorkload.GenerateBlocks(tc.ContextWithTimeout(5*time.Minute), require, runningURIs, 256)
// })
// ginkgo.By("Resume the node", func() {
// require.NoError(e2e.GetEnv(tc).GetNetwork().StartNode(tc.DefaultContext(), ginkgo.GinkgoWriter, syncNode))
// utils.Outf("Waiting for sync node to restart")
// require.NoError(tmpnet.WaitForHealthy(tc.DefaultContext(), syncNode))

// utils.Outf("{{blue}}sync node reporting healthy: %s{{/}}\n", syncNodeURI)

// c := jsonrpc.NewJSONRPCClient(syncNodeURI)
// _, _, _, err := c.Network(tc.DefaultContext())
// require.NoError(err)
// })

// ginkgo.By("Accept a transaction after resuming", func() {
// txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, syncNodeURI, uris)
// })
// ginkgo.By("State sync while broadcasting txs", func() {
// stopChannel := make(chan struct{})
// wg := &sync.WaitGroup{}
// defer wg.Wait()
// defer close(stopChannel)

// wg.Add(1)
// go func() {
// defer wg.Done()
// // Recover failure if exits
// defer ginkgo.GinkgoRecover()
// txWorkload.GenerateUntilStop(tc.DefaultContext(), require, uris, 128, stopChannel)
// }()

// // Give time for transactions to start processing
// time.Sleep(5 * time.Second)

// syncConcurrentNode := e2e.CheckBootstrapIsPossible(tc, e2e.GetEnv(tc).GetNetwork())
// syncConcurrentNodeURI := formatURI(syncConcurrentNode.URI, blockchainID)
// uris = append(uris, syncConcurrentNodeURI)
// c := jsonrpc.NewJSONRPCClient(syncConcurrentNodeURI)
// _, _, _, err := c.Network(tc.DefaultContext())
// require.NoError(err)
// })
// ginkgo.By("Accept a transaction after syncing", func() {
// txWorkload.GenerateTxs(tc.DefaultContext(), require, 1, uris[0], uris)
// })
// })
// })

func getE2EURIs(tc tests.TestContext, blockchainID ids.ID) []string {
nodeURIs := e2e.GetEnv(tc).GetNetwork().GetNodeURIs()
Expand Down
2 changes: 2 additions & 0 deletions throughput/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ type SpamHelper interface {
// Memo is used to ensure that each transaction is unique (even if between the same
// sender and receiver for the same amount).
GetTransfer(address codec.Address, amount uint64, memo []byte) []chain.Action

GetAction() []chain.Action
}
6 changes: 2 additions & 4 deletions throughput/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ func (s Spammer) broadcast(
recipientIndex++
}
}
recipient := accounts[recipientIndex].Address
issuer := getRandomIssuer(issuers)
g.Go(func() error {
factory := factories[senderIndex]
Expand All @@ -239,12 +238,11 @@ func (s Spammer) broadcast(
utils.Outf("{{orange}}tx has insufficient funds:{{/}} %s\n", sender.Address)
return fmt.Errorf("%s has insufficient funds", sender.Address)
}
funds[sender.Address] = balance - feePerTx - amountToTransfer
funds[recipient] += amountToTransfer
funds[sender.Address] = balance - feePerTx
fundsL.Unlock()

// Send transaction
actions := sh.GetTransfer(recipient, amountToTransfer, s.tracker.uniqueBytes())
actions := sh.GetAction()
return issuer.Send(ctx, actions, factory, feePerTx)
})
}
Expand Down

0 comments on commit fa8043a

Please sign in to comment.