Skip to content

Commit

Permalink
Merge pull request #41 from astriaorg/bharath/add-basic-gas-station
Browse files Browse the repository at this point in the history
feat: allow spamooor to send txs via composer
  • Loading branch information
bharath-123 authored Jun 21, 2024
2 parents 886cf1c + ff85d46 commit 4416d70
Show file tree
Hide file tree
Showing 7 changed files with 2,549 additions and 65 deletions.
18 changes: 13 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ module github.com/astriaorg/spamooor
go 1.21.1

require (
buf.build/gen/go/astria/astria/protocolbuffers/go v1.34.2-20240417015050-1257bfd50bd3.2
buf.build/gen/go/astria/composer-apis/grpc/go v1.4.0-20240528191859-5569d2ee7204.1
buf.build/gen/go/astria/composer-apis/protocolbuffers/go v1.34.2-20240528191859-5569d2ee7204.2
github.com/ethereum/go-ethereum v1.13.10
github.com/holiman/uint256 v1.2.4
github.com/sirupsen/logrus v1.9.3
github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.17.0
golang.org/x/crypto v0.21.0
google.golang.org/grpc v1.64.0
)

require (
Expand All @@ -23,8 +27,7 @@ require (
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
Expand All @@ -33,8 +36,13 @@ require (
github.com/tklauser/numcpus v0.6.1 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.15.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/protobuf v1.34.2 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
2,372 changes: 2,365 additions & 7 deletions go.sum

Large diffs are not rendered by default.

56 changes: 40 additions & 16 deletions scenarios/eoatx/eoatx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,35 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/astriaorg/spamooor/scenariotypes"
"github.com/astriaorg/spamooor/tester"
"github.com/astriaorg/spamooor/txbuilder"
"github.com/astriaorg/spamooor/utils"
)

type ScenarioOptions struct {
TotalCount uint64
Throughput uint64
MaxPending uint64
MaxWallets uint64
Timeout uint64
BaseFee uint64
TipFee uint64
Amount uint64
RandomAmount bool
RandomTarget bool
TotalCount uint64
Throughput uint64
MaxPending uint64
MaxWallets uint64
Timeout uint64
BaseFee uint64
TipFee uint64
Amount uint64
RandomAmount bool
RandomTarget bool
ComposerAddress string
SendViaComposer bool
}

type Scenario struct {
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
composerConn *grpc.ClientConn

pendingCount uint64
pendingChan chan bool
Expand All @@ -60,6 +66,8 @@ func (s *Scenario) Flags(flags *pflag.FlagSet) error {
flags.Uint64Var(&s.options.Amount, "amount", 20, "Transfer amount per transaction (in gwei)")
flags.BoolVar(&s.options.RandomAmount, "random-amount", false, "Use random amounts for transactions (with --amount as limit)")
flags.BoolVar(&s.options.RandomTarget, "random-target", false, "Use random to addresses for transactions")
flags.BoolVar(&s.options.SendViaComposer, "send-via-composer", false, "Send transactions via composer")
flags.StringVar(&s.options.ComposerAddress, "composer-address", "", "The address of composer to which to send txs to")
return nil
}

Expand Down Expand Up @@ -88,6 +96,15 @@ func (s *Scenario) Init(testerCfg *tester.TesterConfig) error {
s.pendingChan = make(chan bool, s.options.MaxPending)
}

if s.options.SendViaComposer {
conn, err := grpc.NewClient(s.options.ComposerAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}

s.composerConn = conn
}

return nil
}

Expand Down Expand Up @@ -225,9 +242,16 @@ func (s *Scenario) sendTx(txIdx uint64) (*types.Transaction, *txbuilder.Client,
return nil, nil, err
}

err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
if s.options.SendViaComposer {
err = client.SendTransactionViaComposer(tx, s.composerConn)
if err != nil {
return nil, client, err
}
} else {
err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
}
}

s.pendingWGroup.Add(1)
Expand Down
56 changes: 39 additions & 17 deletions scenarios/erctx/erctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package erctx
import (
"crypto/rand"
"fmt"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"math/big"
"os"
"sync"
Expand All @@ -22,22 +24,25 @@ import (
)

type ScenarioOptions struct {
TotalCount uint64
Throughput uint64
MaxPending uint64
MaxWallets uint64
Timeout uint64
BaseFee uint64
TipFee uint64
Amount uint64
RandomAmount bool
RandomTarget bool
TotalCount uint64
Throughput uint64
MaxPending uint64
MaxWallets uint64
Timeout uint64
BaseFee uint64
TipFee uint64
Amount uint64
RandomAmount bool
RandomTarget bool
ComposerAddress string
SendViaComposer bool
}

type Scenario struct {
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
composerConn *grpc.ClientConn

contractAddr common.Address

Expand All @@ -63,6 +68,8 @@ func (s *Scenario) Flags(flags *pflag.FlagSet) error {
flags.Uint64Var(&s.options.Amount, "amount", 20, "Transfer amount per transaction (in gwei)")
flags.BoolVar(&s.options.RandomAmount, "random-amount", false, "Use random amounts for transactions (with --amount as limit)")
flags.BoolVar(&s.options.RandomTarget, "random-target", false, "Use random to addresses for transactions")
flags.StringVar(&s.options.ComposerAddress, "composer-address", "localhost:50051", "Address of the composer service")
flags.BoolVar(&s.options.SendViaComposer, "send-via-composer", false, "Send transactions via composer")
return nil
}

Expand Down Expand Up @@ -91,10 +98,18 @@ func (s *Scenario) Init(testerCfg *tester.TesterConfig) error {
s.pendingChan = make(chan bool, s.options.MaxPending)
}

if s.options.SendViaComposer {
conn, err := grpc.NewClient(s.options.ComposerAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}

s.composerConn = conn
}

return nil
}

// TODO - move contract deployment to Setup
func (s *Scenario) Setup(testerCfg *tester.Tester) error {
s.logger.Infof("setting up scenario: erctx")
s.tester = testerCfg
Expand Down Expand Up @@ -309,9 +324,16 @@ func (s *Scenario) sendTx(txIdx uint64) (*types.Transaction, *txbuilder.Client,
return nil, nil, err
}

err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
if s.options.SendViaComposer {
err = client.SendTransactionViaComposer(tx, s.composerConn)
if err != nil {
return nil, client, err
}
} else {
err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
}
}

s.pendingWGroup.Add(1)
Expand Down
51 changes: 37 additions & 14 deletions scenarios/gasburnertx/gasburnertx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
largetx "github.com/astriaorg/spamooor/scenarios/gasburnertx/contracts"
"github.com/astriaorg/spamooor/utils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"math/big"
"os"
"sync"
Expand All @@ -22,20 +24,23 @@ import (
)

type ScenarioOptions struct {
TotalCount uint64
Throughput uint64
MaxPending uint64
MaxWallets uint64
Timeout uint64
BaseFee uint64
TipFee uint64
GasUnitsToBurn uint64
TotalCount uint64
Throughput uint64
MaxPending uint64
MaxWallets uint64
Timeout uint64
BaseFee uint64
TipFee uint64
GasUnitsToBurn uint64
ComposerAddress string
SendViaComposer bool
}

type Scenario struct {
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
composerConn *grpc.ClientConn

gasBurnerContractAddr common.Address

Expand All @@ -59,6 +64,8 @@ func (s *Scenario) Flags(flags *pflag.FlagSet) error {
flags.Uint64Var(&s.options.BaseFee, "basefee", 20, "Max fee per gas to use in large transactions (in gwei)")
flags.Uint64Var(&s.options.TipFee, "tipfee", 2, "Max tip per gas to use in large transactions (in gwei)")
flags.Uint64Var(&s.options.GasUnitsToBurn, "gas-units-to-burn", 2000000, "The number of gas units for each tx to cost")
flags.StringVar(&s.options.ComposerAddress, "composer-address", "localhost:50051", "Address of the composer service")
flags.BoolVar(&s.options.SendViaComposer, "send-via-composer", false, "Send transactions via composer")

return nil
}
Expand Down Expand Up @@ -88,6 +95,15 @@ func (s *Scenario) Init(testerCfg *tester.TesterConfig) error {
s.pendingChan = make(chan bool, s.options.MaxPending)
}

if s.options.SendViaComposer {
conn, err := grpc.NewClient(s.options.ComposerAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}

s.composerConn = conn
}

return nil
}

Expand Down Expand Up @@ -266,9 +282,16 @@ func (s *Scenario) sendTx(txIdx uint64) (*types.Transaction, *txbuilder.Client,
return nil, nil, err
}

err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
if s.options.SendViaComposer {
err = client.SendTransactionViaComposer(tx, s.composerConn)
if err != nil {
return nil, client, err
}
} else {
err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
}
}

s.pendingWGroup.Add(1)
Expand Down
33 changes: 27 additions & 6 deletions scenarios/univ2tx/univ2tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/holiman/uint256"
"github.com/sirupsen/logrus"
"github.com/spf13/pflag"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"math/big"
"os"
"sync"
Expand All @@ -31,12 +33,15 @@ type ScenarioOptions struct {
DaiMintAmount uint64
AmountToSwap uint64
RandomAmountToSwap bool
ComposerAddress string
SendViaComposer bool
}

type Scenario struct {
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
options ScenarioOptions
logger *logrus.Entry
tester *tester.Tester
composerConn *grpc.ClientConn

uniswapFactoryContract common.Address
wethContract common.Address
Expand Down Expand Up @@ -68,6 +73,8 @@ func (s *Scenario) Flags(flags *pflag.FlagSet) error {
flag.Uint64Var(&s.options.DaiMintAmount, "dai-mint-amount", 1, "Amount of dai to mint for each child wallet (in ethers)")
flag.Uint64Var(&s.options.AmountToSwap, "amount-to-swap", 1, "Amount of tokens to swap in each transaction(in gwei)")
flag.BoolVar(&s.options.RandomAmountToSwap, "random-amount-to-swap", false, "Randomize the amount of tokens to swap in each transaction(in gwei)")
flags.StringVar(&s.options.ComposerAddress, "composer-address", "localhost:50051", "Address of the composer service")
flags.BoolVar(&s.options.SendViaComposer, "send-via-composer", false, "Send transactions via composer")

return nil
}
Expand Down Expand Up @@ -101,6 +108,13 @@ func (s *Scenario) Init(testerCfg *tester.TesterConfig) error {
s.daiMintAmount = big.NewInt(0).Mul(big.NewInt(int64(s.options.DaiMintAmount)), big.NewInt(1000000000000000000))
}

conn, err := grpc.NewClient(s.options.ComposerAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return err
}

s.composerConn = conn

return nil
}

Expand Down Expand Up @@ -388,9 +402,16 @@ func (s *Scenario) sendTx(txIdx uint64) (*types.Transaction, *txbuilder.Client,
return nil, nil, err
}

err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
if s.options.SendViaComposer {
err = client.SendTransactionViaComposer(tx, s.composerConn)
if err != nil {
return nil, client, err
}
} else {
err = client.SendTransaction(tx)
if err != nil {
return nil, client, err
}
}

s.pendingWGroup.Add(1)
Expand Down
Loading

0 comments on commit 4416d70

Please sign in to comment.