top level service; adjustments
This commit is contained in:
parent
3cff19fc83
commit
da9dd220d0
@ -45,7 +45,10 @@ func autoSend() {
|
||||
}
|
||||
txSpammer := auto.NewTxSpammer(config)
|
||||
quitChan := make(chan bool)
|
||||
doneChan := txSpammer.Loop(quitChan)
|
||||
doneChan, err := txSpammer.Loop(quitChan)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
shutdown := make(chan os.Signal)
|
||||
@ -54,8 +57,8 @@ func autoSend() {
|
||||
close(quitChan)
|
||||
}()
|
||||
<-doneChan
|
||||
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(autoSendCmd)
|
||||
}
|
@ -46,7 +46,10 @@ func sendTxs() {
|
||||
}
|
||||
txSpammer := manual.NewTxSpammer(params)
|
||||
quitChan := make(chan bool)
|
||||
doneChan := txSpammer.Loop(quitChan)
|
||||
doneChan, err := txSpammer.Loop(quitChan)
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
shutdown := make(chan os.Signal)
|
||||
|
@ -21,12 +21,10 @@
|
||||
frequency = 30 # how often to send a transaction (in seconds) - env: $ETH_CALL_FREQ
|
||||
totalNumber = 10000 # total number of transactions to send (across all senders) - env: $ETH_CALL_TOTAL_NUMBER
|
||||
abiPath = "" # path to the abi file for the contract we are calling - env: $ETH_CALL_ABI_PATH
|
||||
# NOTE: we expect to be calling a method such as Put(uint256 pos, uint256 val) where the first argument is an
|
||||
# NOTE: we expect to be calling a method such as Put(address addr, uint256 val) where the first argument is an
|
||||
# integer than we can increment to store values at new locations in the contract trie (to grow it) and
|
||||
# the second argument is an integer value that we store at these positions
|
||||
methodName = "Put" # the method name we are calling - env: $ETH_CALL_METHOD_NAME
|
||||
positionStart = 0 # the starting value for the first argument - env: $ETH_CALL_POSITION_START
|
||||
positionEnd = 1000 # the maximum value for the first argument - env: $ETH_CALL_POSITION_END
|
||||
storageValue = 1337 # the value we store at each position - env: $ETH_CALL_STORAGE_VALUE
|
||||
gasLimit = 0 # gasLimit to use for the eth call txs - env: $ETH_CALL_GAS_LIMIT
|
||||
gasPrice = "0" # gasPrice to use for the eth call txs - env: $ETH_CALL_GAS_PRICE
|
||||
|
@ -284,8 +284,6 @@ func NewCallConfig() (*CallConfig, error) {
|
||||
GasLimit: viper.GetUint64(ethCallGasLimit),
|
||||
MethodName: methodName,
|
||||
ABI: parsedABI,
|
||||
PositionEnd: viper.GetUint64(ethCallPositionEnd),
|
||||
PositionStart: viper.GetUint64(ethCallPositionStart),
|
||||
StorageValue: viper.GetUint64(ethCallStorageValue),
|
||||
Frequency: viper.GetDuration(ethCallFrequency),
|
||||
}, nil
|
||||
|
@ -16,21 +16,62 @@
|
||||
|
||||
package auto
|
||||
|
||||
import "crypto/ecdsa"
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/vulcanize/tx_spammer/pkg/shared"
|
||||
)
|
||||
|
||||
const (
|
||||
contractDeploymentDelay = time.Duration(15) * time.Second
|
||||
)
|
||||
|
||||
// ContractDeployer is responsible for deploying contracts
|
||||
type ContractDeployer struct {
|
||||
SenderKeys []*ecdsa.PrivateKey
|
||||
Config *DeploymentConfig
|
||||
client *rpc.Client
|
||||
ty shared.TxType
|
||||
txGenerator *TxGenerator
|
||||
senderKeys []*ecdsa.PrivateKey
|
||||
senderAddrs []common.Address
|
||||
config *DeploymentConfig
|
||||
}
|
||||
|
||||
func NewContractDeployer(config *Config) *ContractDeployer {
|
||||
// NewContractDeployer returns a new ContractDeployer
|
||||
func NewContractDeployer(config *Config, gen *TxGenerator) *ContractDeployer {
|
||||
return &ContractDeployer{
|
||||
Config: config.DeploymentConfig,
|
||||
SenderKeys: config.SenderKeys,
|
||||
client: config.Client,
|
||||
ty: config.Type,
|
||||
txGenerator: gen,
|
||||
config: config.DeploymentConfig,
|
||||
senderKeys: config.SenderKeys,
|
||||
senderAddrs: config.SenderAddrs,
|
||||
}
|
||||
}
|
||||
|
||||
// Deploy deploys the contracts according to the config provided at construction
|
||||
func (cp *ContractDeployer) Deploy() error {
|
||||
ticker := time.NewTicker(contractDeploymentDelay)
|
||||
for i := uint64(0); i < cp.config.Number; i++ {
|
||||
<- ticker.C
|
||||
for i, key := range cp.senderKeys {
|
||||
txBytes, err := cp.txGenerator.GenerateTx(cp.ty, &GenParams{
|
||||
Sender: cp.senderAddrs[i],
|
||||
SenderKey: key,
|
||||
GasLimit: cp.config.GasLimit,
|
||||
GasPrice: cp.config.GasPrice,
|
||||
Data: cp.config.Data,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := shared.SendRawTransaction(cp.client, txBytes); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -40,8 +40,6 @@ const (
|
||||
ETH_CALL_TOTAL_NUMBER = "ETH_CALL_TOTAL_NUMBER"
|
||||
ETH_CALL_ABI_PATH = "ETH_CALL_ABI_PATH"
|
||||
ETH_CALL_METHOD_NAME = "ETH_CALL_METHOD_NAME"
|
||||
ETH_CALL_POSITION_START = "ETH_CALL_POSITION_START"
|
||||
ETH_CALL_POSITION_END = "ETH_CALL_POSITION_END"
|
||||
ETH_CALL_STORAGE_VALUE = "ETH_CALL_STORAGE_VALUE"
|
||||
ETH_CALL_GAS_LIMIT = "ETH_CALL_GAS_LIMIT"
|
||||
ETH_CALL_GAS_PRICE = "ETH_CALL_GAS_PRICE"
|
||||
@ -73,8 +71,6 @@ const (
|
||||
ethCallTotalNumber = "contractSpammer.totalNumber"
|
||||
ethCallABIPath = "contractSpammer.abiPath"
|
||||
ethCallMethodName = "contractSpammer.methodName"
|
||||
ethCallPositionStart = "contractSpammer.positionStart"
|
||||
ethCallPositionEnd = "contractSpammer.positionEnd"
|
||||
ethCallStorageValue = "contractSpammer.storageValue"
|
||||
ethCallGasLimit = "contractSpammer.gasLimit"
|
||||
ethCallGasPrice = "contractSpammer.gasPrice"
|
||||
@ -108,8 +104,6 @@ func bindEnv() {
|
||||
viper.BindEnv(ethCallGasLimit, ETH_CALL_GAS_LIMIT)
|
||||
viper.BindEnv(ethCallGasPrice, ETH_CALL_GAS_PRICE)
|
||||
viper.BindEnv(ethCallMethodName, ETH_CALL_METHOD_NAME)
|
||||
viper.BindEnv(ethCallPositionEnd, ETH_CALL_POSITION_END)
|
||||
viper.BindEnv(ethCallPositionStart, ETH_CALL_POSITION_START)
|
||||
viper.BindEnv(ethCallStorageValue, ETH_CALL_STORAGE_VALUE)
|
||||
viper.BindEnv(ethCallTotalNumber, ETH_CALL_TOTAL_NUMBER)
|
||||
|
||||
|
@ -18,6 +18,7 @@ package auto
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/vulcanize/tx_spammer/pkg/shared"
|
||||
)
|
||||
|
||||
@ -47,6 +48,7 @@ func (s *EthSender) Send(quitChan <-chan bool, txRlpChan <-chan []byte) (<-chan
|
||||
errChan <- err
|
||||
}
|
||||
case <-quitChan:
|
||||
logrus.Info("quitting the Send loop")
|
||||
close(doneChan)
|
||||
return
|
||||
}
|
||||
|
@ -24,33 +24,48 @@ import (
|
||||
// Spammer underlying struct type for spamming service
|
||||
type Spammer struct {
|
||||
Deployer *ContractDeployer
|
||||
Caller *ContractCaller
|
||||
Sender *EthSender
|
||||
TxGenerator *TxGenerator
|
||||
}
|
||||
|
||||
// NewTxSpammer creates a new tx spamming service
|
||||
func NewTxSpammer(config *Config) shared.Service {
|
||||
gen := NewTxGenerator(config)
|
||||
return &Spammer{
|
||||
Deployer: NewContractDeployer(config),
|
||||
Caller: NewContractCaller(config),
|
||||
Deployer: NewContractDeployer(config, gen),
|
||||
Sender: NewEthSender(config),
|
||||
TxGenerator: gen,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Spammer) Loop(quitChan <-chan bool) <-chan bool {
|
||||
forwardQuit := make(chan bool)
|
||||
doneChan, errChan := s.Sender.Send(forwardQuit)
|
||||
func (s *Spammer) Loop(quitChan <-chan bool) (<-chan bool, error) {
|
||||
if err := s.Deployer.Deploy(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
senderQuit := make(chan bool)
|
||||
generatorQuit := make(chan bool)
|
||||
genDoneChan, txRlpChan, genErrChan := s.TxGenerator.GenerateTxs(generatorQuit)
|
||||
|
||||
doneChan, errChan := s.Sender.Send(senderQuit, txRlpChan)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case <-genDoneChan:
|
||||
logrus.Info("all txs have been generated, beginning shut down sequence")
|
||||
senderQuit <- true
|
||||
case err := <-genErrChan:
|
||||
logrus.Error(err)
|
||||
senderQuit <- true
|
||||
case err := <-errChan:
|
||||
logrus.Error(err)
|
||||
case forwardQuit <- <-quitChan:
|
||||
return
|
||||
case <-doneChan:
|
||||
senderQuit <- true // NOTE: sender will close doneChan when it receives a quit signal
|
||||
case <-quitChan:
|
||||
senderQuit <- true
|
||||
case <-doneChan: // NOTE CONT: which will be received here so that this context can close down only once the sender and generator have
|
||||
generatorQuit <- true
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return doneChan
|
||||
return doneChan, nil
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ type TxGenerator struct {
|
||||
}
|
||||
|
||||
// NewTxGenerator creates a new tx generator
|
||||
func NewTxGenerator(config Config) *TxGenerator {
|
||||
func NewTxGenerator(config *Config) *TxGenerator {
|
||||
nonces := make(map[common.Address]*uint64)
|
||||
for _, addr := range config.SenderAddrs {
|
||||
startingNonce := uint64(0)
|
||||
@ -56,7 +56,6 @@ func NewTxGenerator(config Config) *TxGenerator {
|
||||
|
||||
// GenParams params for GenerateTx method calls
|
||||
type GenParams struct {
|
||||
Signer types.Signer
|
||||
Sender common.Address
|
||||
SenderKey *ecdsa.PrivateKey
|
||||
To *common.Address
|
||||
@ -66,8 +65,10 @@ type GenParams struct {
|
||||
Data []byte
|
||||
}
|
||||
|
||||
// GenerateTxs loops and generates txs according the configuration passed in during construction
|
||||
func (tg TxGenerator) GenerateTxs(quitChan <-chan bool) (<-chan bool, <-chan []byte, <-chan error) {
|
||||
|
||||
// TODO: this
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
// GenerateTx generates tx from the provided params
|
||||
@ -98,7 +99,7 @@ func (gen TxGenerator) genL2(params *GenParams, op *OptimismConfig) ([]byte, err
|
||||
} else {
|
||||
tx = types.NewTransaction(nonce, *params.To, params.Amount, params.GasLimit, params.GasPrice, params.Data, op.L1SenderAddr, op.L1RollupTxId, op.QueueOrigin, op.SigHashType)
|
||||
}
|
||||
signedTx, err := types.SignTx(tx, params.Signer, params.SenderKey)
|
||||
signedTx, err := types.SignTx(tx, gen.signer, params.SenderKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ func NewTxSpammer(params []TxParams) shared.Service {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Spammer) Loop(quitChan <-chan bool) <-chan bool {
|
||||
func (s *Spammer) Loop(quitChan <-chan bool) (<-chan bool, error) {
|
||||
forwardQuit := make(chan bool)
|
||||
doneChan, errChan := s.Sender.Send(forwardQuit)
|
||||
go func() {
|
||||
@ -46,5 +46,5 @@ func (s *Spammer) Loop(quitChan <-chan bool) <-chan bool {
|
||||
}
|
||||
}
|
||||
}()
|
||||
return doneChan
|
||||
return doneChan, nil
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ package shared
|
||||
|
||||
// Service looping interface
|
||||
type Service interface {
|
||||
Loop(quitChan <-chan bool) (doneChan <-chan bool)
|
||||
Loop(quitChan <-chan bool) (doneChan <-chan bool, err error)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user