Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
anusha-ctrl committed Jul 19, 2023
1 parent 8e7bbdc commit f7d3850
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
1 change: 0 additions & 1 deletion cmd/simulator/load/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func ExecuteLoader(ctx context.Context, config config.Config) error {

// Construct the arguments for the load simulator
clients := make([]ethclient.Client, 0, len(config.Endpoints))

for i := 0; i < config.Workers; i++ {
clientURI := config.Endpoints[i%len(config.Endpoints)]
client, err := ethclient.Dial(clientURI)
Expand Down
25 changes: 9 additions & 16 deletions cmd/simulator/txs/tx_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,37 @@ import (
"context"
"crypto/ecdsa"
"fmt"
"time"

"github.com/ava-labs/subnet-evm/core/types"
"github.com/ava-labs/subnet-evm/ethclient"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
)

var _ TxSequence[TimedTx] = (*txSequence)(nil)
var _ TxSequence[*types.Transaction] = (*txSequence)(nil)

type CreateTx func(key *ecdsa.PrivateKey, nonce uint64) (*types.Transaction, error)

type TimedTx struct {
Tx *types.Transaction
IssuanceDuration time.Duration
ConfirmationDuration time.Duration
}

// GenerateTxSequence fetches the current nonce of key and calls [generator] [numTxs] times sequentially to generate a sequence of transactions.
func GenerateTxSequence(ctx context.Context, generator CreateTx, client ethclient.Client, key *ecdsa.PrivateKey, numTxs uint64) (TxSequence[TimedTx], error) {

Check failure on line 21 in cmd/simulator/txs/tx_generator.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: TimedTx (typecheck)

Check failure on line 21 in cmd/simulator/txs/tx_generator.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests

undefined: TimedTx
address := ethcrypto.PubkeyToAddress(key.PublicKey)
startingNonce, err := client.NonceAt(ctx, address, nil)
if err != nil {
return nil, fmt.Errorf("failed to fetch nonce for address %s: %w", address, err)
}
txs := make([]TimedTx, 0, numTxs)
txs := make([]*types.Transaction, 0, numTxs)
for i := uint64(0); i < numTxs; i++ {
tx, err := generator(key, startingNonce+i)
if err != nil {
return nil, fmt.Errorf("failed to sign tx at index %d: %w", i, err)
}
timedTx := TimedTx{Tx: tx}
txs = append(txs, timedTx)

txs = append(txs, tx)
}
return ConvertTxSliceToSequence(txs), nil
}

func GenerateTxSequences(ctx context.Context, generator CreateTx, client ethclient.Client, keys []*ecdsa.PrivateKey, txsPerKey uint64) ([]TxSequence[TimedTx], error) {

Check failure on line 39 in cmd/simulator/txs/tx_generator.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: TimedTx (typecheck)

Check failure on line 39 in cmd/simulator/txs/tx_generator.go

View workflow job for this annotation

GitHub Actions / Golang Unit Tests

undefined: TimedTx
txSequences := make([]TxSequence[TimedTx], len(keys))
txSequences := make([]TxSequence[*types.Transaction], len(keys))
for i, key := range keys {
txs, err := GenerateTxSequence(ctx, generator, client, key, txsPerKey)
if err != nil {
Expand All @@ -56,11 +49,11 @@ func GenerateTxSequences(ctx context.Context, generator CreateTx, client ethclie
}

type txSequence struct {
txChan chan TimedTx
txChan chan *types.Transaction
}

func ConvertTxSliceToSequence(txs []TimedTx) TxSequence[TimedTx] {
txChan := make(chan TimedTx, len(txs))
func ConvertTxSliceToSequence(txs []*types.Transaction) TxSequence[*types.Transaction] {
txChan := make(chan *types.Transaction, len(txs))
for _, tx := range txs {
txChan <- tx
}
Expand All @@ -71,6 +64,6 @@ func ConvertTxSliceToSequence(txs []TimedTx) TxSequence[TimedTx] {
}
}

func (t *txSequence) Chan() <-chan TimedTx {
func (t *txSequence) Chan() <-chan *types.Transaction {
return t.txChan
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanche-network-runner v1.6.0
github.com/ava-labs/avalanchego v1.10.2
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e
github.com/cespare/cp v0.1.0
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ github.com/ava-labs/avalanchego v1.10.2 h1:kDM2xfQDaewueUCxJUujPlbNQ91gtJfXY9Z0C
github.com/ava-labs/avalanchego v1.10.2/go.mod h1:PsNLfOc9FnsnoJ8CjauclvFy6BCSVZmT05I4c9rm4a4=
github.com/ava-labs/coreth v0.12.2-rc.0 h1:nGhGN4bYqid5EgqH/GFky2ybY8bGRxto6Bo7nes1V+Y=
github.com/ava-labs/coreth v0.12.2-rc.0/go.mod h1:/5x54QlIKjlPebkdzTA5ic9wXdejbWOnQosztkv9jxo=
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e h1:dSeuFcs4WAJJnswS8vXy7YY1+fdlbVPuEVmDAfqvFOQ=
github.com/aybabtme/uniplot v0.0.0-20151203143629-039c559e5e7e/go.mod h1:uh71c5Vc3VNIplXOFXsnDy21T1BepgT32c5X/YPrOyc=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
Expand Down

0 comments on commit f7d3850

Please sign in to comment.