Update for testing with Merge fixturenet. #11

Merged
telackey merged 8 commits from telackey/the_merge into main 2022-11-03 02:33:19 +00:00
26 changed files with 1392 additions and 487 deletions

View File

@ -1,4 +1,4 @@
FROM golang:1.13-alpine as builder
FROM golang:1.19-alpine as builder
RUN apk --update --no-cache add make git g++ linux-headers
# DEBUG
@ -29,4 +29,4 @@ COPY --chown=5000:5000 --from=builder /go/src/github.com/vulcanize/tx_spammer/st
COPY --from=builder /go/src/github.com/vulcanize/tx_spammer/tx_spammer tx_spammer
COPY --from=builder /go/src/github.com/vulcanize/tx_spammer/environments environments
ENTRYPOINT ["/app/startup_script.sh"]
ENTRYPOINT ["/app/startup_script.sh"]

View File

@ -1,4 +1,12 @@
## Build docker image
.PHONY: docker-build
docker-build:
docker build -t vulcanize/tx_spammer -f Dockerfile .
docker build -t vulcanize/tx_spammer -f Dockerfile .
.PHONY: build
build:
GO111MODULE=on go build -o tx_spammer .
.PHONY: contract
contract:
cd sol && solc --abi --bin -o build --overwrite Test.sol

View File

@ -1,36 +1,30 @@
[eth]
keyDirPath = "" # path to the directory with all of the key pairs to use - env: $ETH_KEY_DIR_PATH
httpPath = "" # http url for the node we wish to send all our transactions to - env: $ETH_HTTP_PATH
chainID = 421 # chain id - env: $ETH_CHAIN_ID
type = "L2" # tx type (EIP1559, Standard, or L2) - env: $ETH_TX_TYPE
keyDirPath = "./keys/" # path to the directory with all of the key pairs to use - env: $ETH_KEY_DIR_PATH
httpPath = "http://localhost:8545" # http url for the node we wish to send all our transactions to - env: $ETH_HTTP_PATH
[deployment]
number = 1 # number of contracts we will deploy for each key at keyPath - env: $ETH_DEPLOYMENT_NUMBER
hexData = "" # hex data for the contracts we will deploy - env: $ETH_DEPLOYMENT_HEX_DATA
gasLimit = 0 # gasLimit to use for the deployment txs - env: $ETH_DEPLOYMENT_GAS_LIMIT
gasPrice = "0" # gasPrice to use for the deployment txs - env: $ETH_DEPLOYMENT_GAS_PRICE
[optimism]
l1Sender = "" # l1 sender address hex to use for all txs - env: $ETH_OPTIMISM_L1_SENDER
l1RollupTxId = 0 # rollup tx id to use for all txs - env: $ETH_OPTIMISM_ROLLUP_TX_ID
sigHashType = 0 # sig hash type to use for all txs - env: $ETH_OPTIMISM_SIG_HASH_TYPE
queueOrigin = 0 # queue origin id to use for all txs - env: $ETH_OPTIMISM_QUEUE_ORIGIN
binPath = "sol/build/Test.bin" # hex data for the contracts we will deploy - env: $ETH_DEPLOYMENT_BIN_PATH
gasLimit = 100000 # gasLimit to use for the deployment txs - env: $ETH_DEPLOYMENT_GAS_LIMIT
gasTipCap = "1000000000" # gasTipCap to use for the deployment txs - env: $ETH_DEPLOYMENT_GAS_TIP_CAP
gasFeeCap = "1000000007" # gasFeeCap to use for the deployment txs - env: $ETH_DEPLOYMENT_GAS_FEE_CAP
[contractSpammer]
frequency = 30 # how often to send a transaction (in seconds) - env: $ETH_CALL_FREQ
totalNumber = 10000 # total number of transactions to send (per sender) - env: $ETH_CALL_TOTAL_NUMBER
abiPath = "" # path to the abi file for the contract we are calling - env: $ETH_CALL_ABI_PATH
frequency = -1 # how often to send a transaction (in milliseconds, -1 for no delay) - env: $ETH_CALL_FREQ
totalNumber = -1 # total number of transactions to send (per sender, -1 for unlimited) - env: $ETH_CALL_TOTAL_NUMBER
abiPath = "sol/build/Test.abi" # 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(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
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
gasLimit = 42000 # gasLimit to use for the eth call txs - env: $ETH_CALL_GAS_LIMIT
gasTipCap = "1000000000" # gasTipCap to use for the eth call txs - env: $ETH_CALL_GAS_TIP_CAP
gasFeeCap = "1000000007" # gasFeeCap to use for the eth call txs - env: $ETH_CALL_GAS_FEE_CAP
[sendSpammer]
frequency = 30 # how often to send a transaction (in seconds) - env: $ETH_SEND_FREQ
totalNumber = 10000 # total number of transactions to send (per sender) - env: $ETH_SEND_TOTAL_NUMBER
amount = "1" # amount of wei (1x10^-18 ETH) to send in each tx (be mindful of the genesis allocations) - env: $ETH_SEND_AMOUNT
gasLimit = 0 # gasLimit to use for the eth transfer txs - env: $ETH_SEND_GAS_LIMIT
gasPrice = "0" # gasPrice to use for the eth transfer txs - env: $ETH_SEND_GAS_PRICE
frequency = -1 # how often to send a transaction (in milliseconds, -1 for no delay) - env: $ETH_SEND_FREQ
totalNumber = -1 # total number of transactions to send (per sender, -1 for unlimited) - env: $ETH_SEND_TOTAL_NUMBER
amount = "10000" # amount of wei (1x10^-18 ETH) to send in each tx (be mindful of the genesis allocations) - env: $ETH_SEND_AMOUNT
gasLimit = 21000 # gasLimit to use for the eth transfer txs - env: $ETH_SEND_GAS_LIMIT
gasTipCap = "1000000000" # gasTipCap to use for the eth transfer txs - env: $ETH_SEND_GAS_TIP_CAP
gasFeeCap = "1000000007" # gasFeeCap to use for the eth transfer txs - env: $ETH_SEND_GAS_FEE_CAP

53
go.mod
View File

@ -3,10 +3,55 @@ module github.com/vulcanize/tx_spammer
go 1.13
require (
github.com/ethereum/go-ethereum v1.9.10
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.0
github.com/spf13/viper v1.7.1
github.com/Azure/azure-pipeline-go v0.2.2 // indirect
github.com/Azure/azure-storage-blob-go v0.7.0 // indirect
github.com/Azure/go-autorest/autorest/adal v0.8.0 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/aristanetworks/goarista v0.0.0-20170210015632-ea17b1a17847 // indirect
github.com/aws/aws-sdk-go v1.25.48 // indirect
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c // indirect
github.com/btcsuite/btcd v0.0.0-20171128150713-2e60448ffcc6 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/coreos/bbolt v1.3.2 // indirect
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/elastic/gosigar v0.8.1-0.20180330100440-37f05ff46ffa // indirect
github.com/ethereum/go-ethereum v1.10.25
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect
github.com/jmoiron/sqlx v1.2.0 // indirect
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/pborman/uuid v0.0.0-20170112150404-1b00554d8222 // indirect
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff // indirect
github.com/rs/xhandler v0.0.0-20160618193221-ed27b6fd6521 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sirupsen/logrus v1.9.0
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cobra v1.6.0
github.com/spf13/viper v1.13.0
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570 // indirect
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.5.0 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
github.com/urfave/cli v1.22.1 // indirect
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.etcd.io/bbolt v1.3.2 // indirect
golang.org/x/crypto v0.0.0-20221012134737-56aed061732a // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/text v0.4.0 // indirect
gopkg.in/olebedev/go-duktape.v3 v3.0.0-20200316214253-d7b0ff38cac9 // indirect
gopkg.in/resty.v1 v1.12.0 // indirect
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
gotest.tools v2.2.0+incompatible // indirect
)
replace github.com/ethereum/go-ethereum v1.9.10 => github.com/vulcanize/go-ethereum v1.9.10-optimism-0.0.2

867
go.sum

File diff suppressed because it is too large Load Diff

1
keys/0.key Normal file
View File

@ -0,0 +1 @@
888814df89c4358d7ddb3fa4b0213e7331239a80e1f013eaa7b2deca2a41a218

1
keys/1.key Normal file
View File

@ -0,0 +1 @@
570b909da9669b2f35a0b1ac70b8358516d55ae1b5b3710e95e9a94395090597

1
keys/2.key Normal file
View File

@ -0,0 +1 @@
111b7500bdce494d6f4bcfe8c2a0dde2ef92f751d9070fac6475dbd6d8021b3f

1
keys/3.key Normal file
View File

@ -0,0 +1 @@
fb1e9af328c283ca3e2486e7c24d13582b7912057d8b9542ff41503c85bc05c0

1
keys/4.key Normal file
View File

@ -0,0 +1 @@
be4aa664815ea3bc3d63118649a733f6c96b243744310806ecb6d96359ab62cf

1
keys/5.key Normal file
View File

@ -0,0 +1 @@
6177345b77c4069ac4d553f8b43cf68a799ca4bb63eac93d6cf796d63694ebf0

View File

@ -18,9 +18,12 @@ package auto
import (
"bytes"
"context"
"crypto/ecdsa"
"fmt"
"github.com/ethereum/go-ethereum/ethclient"
"io/ioutil"
"math"
"math/big"
"path/filepath"
"strings"
@ -28,7 +31,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
@ -48,21 +50,17 @@ func init() {
// Config holds all the parameters for the auto tx spammer
type Config struct {
// HTTP client for sending transactions
Client *rpc.Client
RpcClient *rpc.Client
EthClient *ethclient.Client
ChainID *big.Int
// Key pairs for the accounts we will use to deploy contracts and send txs
SenderKeys []*ecdsa.PrivateKey
SenderAddrs []common.Address
// Type of the txs we are working with
Type shared.TxType
// Tx signer for the chain we are working with
Signer types.Signer
// Configuration for Optimism L2
OptimismConfig *OptimismConfig
// Configuration for the initial contract deployment
DeploymentConfig *DeploymentConfig
@ -71,54 +69,47 @@ type Config struct {
// Configuration for the eth transfer txs
SendConfig *SendConfig
// Configuration for EIP1559
EIP1559Config *EIP1559Config
}
// OptimismConfig holds the tx paramaters specific to Optimism L2
type OptimismConfig struct {
L1SenderAddr *common.Address
L1RollupTxId *hexutil.Uint64
SigHashType types.SignatureHashType
QueueOrigin types.QueueOrigin
}
// DeploymentConfig holds the parameters for the contract deployment contracts
type DeploymentConfig struct {
GasLimit uint64
GasPrice *big.Int
Data []byte
ChainID *big.Int
GasLimit uint64
GasFeeCap *big.Int
GasTipCap *big.Int
Data []byte
Number uint64
}
// CallConfig holds the parameters for the contract calling txs
type CallConfig struct {
GasLimit uint64
GasPrice *big.Int
ChainID *big.Int
GasLimit uint64
GasFeeCap *big.Int
GasTipCap *big.Int
Amount *big.Int
MethodName string
ABI abi.ABI
StorageValue uint64
StorageAddrs []common.Address
MethodName string
ABI abi.ABI
ContractAddrs []common.Address
Frequency time.Duration
Frequency time.Duration
TotalNumber int
}
// SendConfig holds the parameters for the eth transfer txs
type SendConfig struct {
GasLimit uint64
GasPrice *big.Int
Amount *big.Int
ChainID *big.Int
GasLimit uint64
GasFeeCap *big.Int
GasTipCap *big.Int
Amount *big.Int
DestinationAddresses []common.Address
Frequency time.Duration
Frequency time.Duration
TotalNumber int
}
// todo: EIP1559Config
type EIP1559Config struct{}
func NewConfig() (*Config, error) {
// Initialize rpc client
httpPathStr := viper.GetString(ethHttpPath)
@ -133,6 +124,11 @@ func NewConfig() (*Config, error) {
return nil, err
}
ethClient, err := ethclient.Dial(httpPathStr)
if err != nil {
return nil, err
}
// Load keys
keyDirPath := viper.GetString(ethKeyDirPath)
if keyDirPath == "" {
@ -157,102 +153,70 @@ func NewConfig() (*Config, error) {
senderAddrs = append(senderAddrs, crypto.PubkeyToAddress(key.PublicKey))
}
// Load tx type
txType, err := shared.TxTypeFromString(viper.GetString(ethType))
// Detect chain ID.
chainID, err := ethClient.ChainID(context.Background())
if err != nil {
return nil, err
}
// Load signer
chainID := viper.GetUint64(ethChainID)
signer, err := shared.TxSigner(txType, chainID)
if err != nil {
return nil, err
}
// Load optimism config
var optimismConfig *OptimismConfig
if txType == shared.OptimismL1ToL2 || txType == shared.OptimismL2 {
optimismConfig = NewOptimismConfig()
}
signer := shared.TxSigner(chainID)
// Load deployment config
deploymentConfig, err := NewDeploymentConfig()
deploymentConfig, err := NewDeploymentConfig(chainID)
if err != nil {
return nil, err
}
// Load call config
callConfig, err := NewCallConfig()
callConfig, err := NewCallConfig(chainID)
if err != nil {
return nil, err
}
// Load send config
sendConfig, err := NewSendConfig()
sendConfig, err := NewSendConfig(chainID)
if err != nil {
return nil, err
}
// Assemble and return
return &Config{
Client: rpcClient,
RpcClient: rpcClient,
EthClient: ethClient,
SenderKeys: keys,
SenderAddrs: senderAddrs,
Type: txType,
Signer: signer,
OptimismConfig: optimismConfig,
DeploymentConfig: deploymentConfig,
CallConfig: callConfig,
SendConfig: sendConfig,
}, nil
}
// NewOptimismConfig constructs and returns a new OptimismConfig
func NewOptimismConfig() *OptimismConfig {
l1SenderStr := viper.GetString(ethOptimismL1Sender)
var l1Sender *common.Address
if l1SenderStr != "" {
sender := common.HexToAddress(l1SenderStr)
l1Sender = &sender
}
l1RollupTxId := viper.GetUint64(ethOptimismRollupTxID)
l1rtid := (hexutil.Uint64)(l1RollupTxId)
sigHashType := viper.GetUint(ethOptimismSigHashType)
queueOrigin := viper.GetInt64(ethOptimismQueueOrigin)
return &OptimismConfig{
L1SenderAddr: l1Sender,
L1RollupTxId: &l1rtid,
SigHashType: (types.SignatureHashType)(uint8(sigHashType)),
QueueOrigin: (types.QueueOrigin)(queueOrigin),
}
}
// NewDeploymentConfig constructs and returns a new DeploymentConfig
func NewDeploymentConfig() (*DeploymentConfig, error) {
hexData := viper.GetString(ethDeploymentData)
data := common.Hex2Bytes(hexData)
gasPriceStr := viper.GetString(ethDeploymentGasPrice)
gasPrice, ok := new(big.Int).SetString(gasPriceStr, 10)
if !ok {
return nil, fmt.Errorf("unable to convert gasPrice string (%s) into big.Int", gasPriceStr)
func NewDeploymentConfig(chainID *big.Int) (*DeploymentConfig, error) {
binPath := viper.GetString(ethDeploymentBinPath)
if binPath == "" {
return nil, fmt.Errorf("missing deployment.binPath")
}
binBytes, err := ioutil.ReadFile(binPath)
if err != nil {
return nil, err
}
data := common.Hex2Bytes(string(binBytes))
return &DeploymentConfig{
Number: viper.GetUint64(ethDeploymentNumber),
Data: data,
GasPrice: gasPrice,
GasLimit: viper.GetUint64(ethDeploymentGasLimit),
ChainID: chainID,
Number: viper.GetUint64(ethDeploymentNumber),
Data: data,
GasLimit: viper.GetUint64(ethDeploymentGasLimit),
GasFeeCap: big.NewInt(viper.GetInt64(ethDeploymentGasFeeCap)),
GasTipCap: big.NewInt(viper.GetInt64(ethDeploymentGasTipCap)),
}, nil
}
// NewCallConfig constructs and returns a new CallConfig
func NewCallConfig() (*CallConfig, error) {
gasPriceStr := viper.GetString(ethCallGasPrice)
gasPrice, ok := new(big.Int).SetString(gasPriceStr, 10)
if !ok {
return nil, fmt.Errorf("unable to convert gasPrice string (%s) into big.Int", gasPriceStr)
}
func NewCallConfig(chainID *big.Int) (*CallConfig, error) {
abiPath := viper.GetString(ethCallABIPath)
if abiPath == "" {
return nil, fmt.Errorf("missing contractSpammer.abiPath")
@ -270,44 +234,60 @@ func NewCallConfig() (*CallConfig, error) {
if !exist {
return nil, fmt.Errorf("method '%s' not found in provided abi", methodName)
}
number := viper.GetUint64(ethCallTotalNumber)
addrs := make([]common.Address, number)
for i := uint64(0); i < number; i++ {
addrs[i] = crypto.CreateAddress(storageAddressSeed, i)
var frequency time.Duration
tmpFreq := viper.GetInt(ethCallFrequency)
if tmpFreq <= 0 {
frequency = time.Microsecond
} else {
frequency = viper.GetDuration(ethCallFrequency) * time.Millisecond
}
totalNumber := viper.GetInt(ethCallTotalNumber)
if totalNumber < 0 {
totalNumber = math.MaxInt
}
return &CallConfig{
GasPrice: gasPrice,
GasLimit: viper.GetUint64(ethCallGasLimit),
MethodName: methodName,
ABI: parsedABI,
StorageValue: viper.GetUint64(ethCallStorageValue),
Frequency: viper.GetDuration(ethCallFrequency),
StorageAddrs: addrs,
ChainID: chainID,
GasLimit: viper.GetUint64(ethCallGasLimit),
GasFeeCap: big.NewInt(viper.GetInt64(ethCallGasFeeCap)),
GasTipCap: big.NewInt(viper.GetInt64(ethCallGasTipCap)),
MethodName: methodName,
ABI: parsedABI,
Frequency: frequency,
TotalNumber: totalNumber,
}, nil
}
// NewSendConfig constructs and returns a new SendConfig
func NewSendConfig() (*SendConfig, error) {
func NewSendConfig(chainID *big.Int) (*SendConfig, error) {
amountStr := viper.GetString(ethSendAmount)
amount, ok := new(big.Int).SetString(amountStr, 10)
if !ok {
return nil, fmt.Errorf("unable to convert amount string (%s) into big.Int", amountStr)
}
gasPriceStr := viper.GetString(ethSendGasPrice)
gasPrice, ok := new(big.Int).SetString(gasPriceStr, 10)
if !ok {
return nil, fmt.Errorf("unable to convert gasPrice string (%s) into big.Int", gasPriceStr)
var frequency time.Duration
tmpFreq := viper.GetInt(ethCallFrequency)
if tmpFreq <= 0 {
frequency = time.Microsecond
} else {
frequency = viper.GetDuration(ethCallFrequency) * time.Millisecond
}
number := viper.GetUint64(ethSendTotalNumber)
addrs := make([]common.Address, number)
for i := uint64(0); i < number; i++ {
addrs[i] = crypto.CreateAddress(receiverAddressSeed, i)
totalNumber := viper.GetInt(ethSendTotalNumber)
if totalNumber < 0 {
totalNumber = math.MaxInt
}
return &SendConfig{
DestinationAddresses: addrs,
Frequency: viper.GetDuration(ethSendFrequency),
Amount: amount,
GasPrice: gasPrice,
GasLimit: viper.GetUint64(ethSendGasLimit),
ChainID: chainID,
Frequency: frequency,
Amount: amount,
GasLimit: viper.GetUint64(ethSendGasLimit),
GasFeeCap: big.NewInt(viper.GetInt64(ethSendGasFeeCap)),
GasTipCap: big.NewInt(viper.GetInt64(ethSendGasTipCap)),
TotalNumber: totalNumber,
}, nil
}

View File

@ -18,6 +18,7 @@ package auto
import (
"crypto/ecdsa"
"github.com/sirupsen/logrus"
"time"
"github.com/ethereum/go-ethereum/common"
@ -32,7 +33,6 @@ const (
// ContractDeployer is responsible for deploying contracts
type ContractDeployer struct {
client *rpc.Client
ty shared.TxType
txGenerator *TxGenerator
senderKeys []*ecdsa.PrivateKey
senderAddrs []common.Address
@ -42,8 +42,7 @@ type ContractDeployer struct {
// NewContractDeployer returns a new ContractDeployer
func NewContractDeployer(config *Config, gen *TxGenerator) *ContractDeployer {
return &ContractDeployer{
client: config.Client,
ty: config.Type,
client: config.RpcClient,
txGenerator: gen,
config: config.DeploymentConfig,
senderKeys: config.SenderKeys,
@ -59,17 +58,20 @@ func (cp *ContractDeployer) Deploy() ([]common.Address, error) {
for i := uint64(0); i < cp.config.Number; i++ {
<-ticker.C
for i, key := range cp.senderKeys {
txBytes, contractAddr, err := cp.txGenerator.GenerateTx(cp.ty, &GenParams{
logrus.Debugf("Generating contract deployment for %s.", cp.senderAddrs[i].Hex())
signedTx, contractAddr, err := cp.txGenerator.GenerateTx(&GenParams{
ChainID: cp.config.ChainID,
Sender: cp.senderAddrs[i],
SenderKey: key,
GasLimit: cp.config.GasLimit,
GasPrice: cp.config.GasPrice,
GasFeeCap: cp.config.GasFeeCap,
GasTipCap: cp.config.GasTipCap,
Data: cp.config.Data,
})
if err != nil {
return nil, err
}
if err := shared.SendRawTransaction(cp.client, txBytes); err != nil {
if err := shared.SendTransaction(cp.client, signedTx); err != nil {
return nil, err
}
contractAddrs = append(contractAddrs, contractAddr)

View File

@ -22,91 +22,77 @@ const (
// env variables
ETH_KEY_DIR_PATH = "ETH_KEY_DIR_PATH"
ETH_HTTP_PATH = "ETH_HTTP_PATH"
ETH_CHAIN_ID = "ETH_CHAIN_ID"
ETH_TX_TYPE = "ETH_TX_TYPE"
ETH_DEPLOYMENT_NUMBER = "ETH_DEPLOYMENT_NUMBER"
ETH_DEPLOYMENT_HEX_DATA = "ETH_DEPLOYMENT_HEX_DATA"
ETH_DEPLOYMENT_GAS_LIMIT = "ETH_DEPLOYMENT_GAS_LIMIT"
ETH_DEPLOYMENT_GAS_PRICE = "ETH_DEPLOYMENT_GAS_PRICE"
ETH_DEPLOYMENT_NUMBER = "ETH_DEPLOYMENT_NUMBER"
ETH_DEPLOYMENT_BIN_PATH = "ETH_DEPLOYMENT_BIN_PATH"
ETH_DEPLOYMENT_GAS_LIMIT = "ETH_DEPLOYMENT_GAS_LIMIT"
ETH_DEPLOYMENT_GAS_FEE_CAP = "ETH_DEPLOYMENT_GAS_FEE_CAP"
ETH_DEPLOYMENT_GAS_TIP_CAP = "ETH_DEPLOYMENT_GAS_TIP_CAP"
ETH_OPTIMISM_L1_SENDER = "ETH_OPTIMISM_L1_SENDER"
ETH_OPTIMISM_ROLLUP_TX_ID = "ETH_OPTIMISM_ROLLUP_TX_ID"
ETH_OPTIMISM_SIG_HASH_TYPE = "ETH_OPTIMISM_SIG_HASH_TYPE"
ETH_OPTIMISM_QUEUE_ORIGIN = "ETH_OPTIMISM_QUEUE_ORIGIN"
ETH_CALL_FREQ = "ETH_CALL_FREQ"
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_STORAGE_VALUE = "ETH_CALL_STORAGE_VALUE"
ETH_CALL_GAS_LIMIT = "ETH_CALL_GAS_LIMIT"
ETH_CALL_GAS_PRICE = "ETH_CALL_GAS_PRICE"
ETH_CALL_FREQ = "ETH_CALL_FREQ"
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_GAS_LIMIT = "ETH_CALL_GAS_LIMIT"
ETH_CALL_GAS_FEE_CAP = "ETH_CALL_GAS_FEE_CAP"
ETH_CALL_GAS_TIP_CAP = "ETH_CALL_GAS_TIP_CAP"
ETH_SEND_FREQ = "ETH_SEND_FREQ"
ETH_SEND_TOTAL_NUMBER = "ETH_SEND_TOTAL_NUMBER"
ETH_SEND_AMOUNT = "ETH_SEND_AMOUNT"
ETH_SEND_GAS_LIMIT = "ETH_SEND_GAS_LIMIT"
ETH_SEND_GAS_PRICE = "ETH_SEND_GAS_PRICE"
ETH_SEND_GAS_FEE_CAP = "ETH_SEND_GAS_FEE_CAP"
ETH_SEND_GAS_TIP_CAP = "ETH_SEND_GAS_TIP_CAP"
// toml bindings
ethKeyDirPath = "eth.keyDirPath"
ethHttpPath = "eth.httpPath"
ethChainID = "eth.chainID"
ethType = "eth.type"
ethDeploymentNumber = "deployment.number"
ethDeploymentData = "deployment.hexData"
ethDeploymentGasPrice = "deployment.gasPrice"
ethDeploymentGasLimit = "deployment.gasLimit"
ethDeploymentBinPath = "deployment.binPath"
ethDeploymentNumber = "deployment.number"
ethDeploymentGasLimit = "deployment.gasLimit"
ethDeploymentGasFeeCap = "deployment.gasFeeCap"
ethDeploymentGasTipCap = "deployment.gasTipCap"
ethOptimismL1Sender = "optimism.l1Sender"
ethOptimismRollupTxID = "optimism.l1RollupTxId"
ethOptimismSigHashType = "optimism.sigHashType"
ethOptimismQueueOrigin = "optimism.queueOrigin"
ethCallFrequency = "contractSpammer.frequency"
ethCallTotalNumber = "contractSpammer.totalNumber"
ethCallABIPath = "contractSpammer.abiPath"
ethCallMethodName = "contractSpammer.methodName"
ethCallStorageValue = "contractSpammer.storageValue"
ethCallGasLimit = "contractSpammer.gasLimit"
ethCallGasPrice = "contractSpammer.gasPrice"
ethCallFrequency = "contractSpammer.frequency"
ethCallTotalNumber = "contractSpammer.totalNumber"
ethCallABIPath = "contractSpammer.abiPath"
ethCallMethodName = "contractSpammer.methodName"
ethCallGasLimit = "contractSpammer.gasLimit"
ethCallGasFeeCap = "contractSpammer.gasFeeCap"
ethCallGasTipCap = "contractSpammer.gasTipCap"
ethSendFrequency = "sendSpammer.frequency"
ethSendTotalNumber = "sendSpammer.totalNumber"
ethSendAmount = "sendSpammer.amount"
ethSendGasLimit = "sendSpammer.gasLimit"
ethSendGasPrice = "sendSpammer.gasPrice"
ethSendGasFeeCap = "sendSpammer.gasFeeCap"
ethSendGasTipCap = "sendSpammer.gasTipCap"
)
func bindEnv() {
viper.BindEnv(ethKeyDirPath, ETH_KEY_DIR_PATH)
viper.BindEnv(ethHttpPath, ETH_HTTP_PATH)
viper.BindEnv(ethType, ETH_TX_TYPE)
viper.BindEnv(ethChainID, ETH_CHAIN_ID)
viper.BindEnv(ethOptimismL1Sender, ETH_OPTIMISM_L1_SENDER)
viper.BindEnv(ethOptimismQueueOrigin, ETH_OPTIMISM_QUEUE_ORIGIN)
viper.BindEnv(ethOptimismRollupTxID, ETH_OPTIMISM_ROLLUP_TX_ID)
viper.BindEnv(ethOptimismSigHashType, ETH_OPTIMISM_SIG_HASH_TYPE)
viper.BindEnv(ethDeploymentNumber, ETH_DEPLOYMENT_NUMBER)
viper.BindEnv(ethDeploymentData, ETH_DEPLOYMENT_HEX_DATA)
viper.BindEnv(ethDeploymentBinPath, ETH_DEPLOYMENT_BIN_PATH)
viper.BindEnv(ethDeploymentGasLimit, ETH_DEPLOYMENT_GAS_LIMIT)
viper.BindEnv(ethDeploymentGasPrice, ETH_DEPLOYMENT_GAS_PRICE)
viper.BindEnv(ethDeploymentGasFeeCap, ETH_DEPLOYMENT_GAS_FEE_CAP)
viper.BindEnv(ethDeploymentGasTipCap, ETH_DEPLOYMENT_GAS_TIP_CAP)
viper.BindEnv(ethCallABIPath, ETH_CALL_ABI_PATH)
viper.BindEnv(ethCallFrequency, ETH_CALL_FREQ)
viper.BindEnv(ethCallGasLimit, ETH_CALL_GAS_LIMIT)
viper.BindEnv(ethCallGasPrice, ETH_CALL_GAS_PRICE)
viper.BindEnv(ethCallGasFeeCap, ETH_CALL_GAS_FEE_CAP)
viper.BindEnv(ethCallGasTipCap, ETH_CALL_GAS_TIP_CAP)
viper.BindEnv(ethCallMethodName, ETH_CALL_METHOD_NAME)
viper.BindEnv(ethCallStorageValue, ETH_CALL_STORAGE_VALUE)
viper.BindEnv(ethCallTotalNumber, ETH_CALL_TOTAL_NUMBER)
viper.BindEnv(ethSendFrequency, ETH_SEND_FREQ)
viper.BindEnv(ethSendTotalNumber, ETH_SEND_TOTAL_NUMBER)
viper.BindEnv(ethSendAmount, ETH_SEND_AMOUNT)
viper.BindEnv(ethSendGasLimit, ETH_SEND_GAS_LIMIT)
viper.BindEnv(ethSendGasPrice, ETH_SEND_GAS_PRICE)
viper.BindEnv(ethSendGasFeeCap, ETH_SEND_GAS_FEE_CAP)
viper.BindEnv(ethSendGasTipCap, ETH_SEND_GAS_TIP_CAP)
viper.BindEnv(ethSendGasLimit, ETH_CALL_GAS_LIMIT)
}

View File

@ -17,6 +17,7 @@
package auto
import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rpc"
"github.com/sirupsen/logrus"
"github.com/vulcanize/tx_spammer/pkg/shared"
@ -30,25 +31,29 @@ type EthSender struct {
// NewEthSender returns a new EthSender
func NewEthSender(config *Config) *EthSender {
return &EthSender{
client: config.Client,
client: config.RpcClient,
}
}
// Send awaits txs off the provided work queue and sends them
func (s *EthSender) Send(quitChan <-chan bool, txRlpChan <-chan []byte) (<-chan bool, <-chan error) {
func (s *EthSender) Send(quitChan <-chan bool, txChan <-chan *types.Transaction, sentCh chan *types.Transaction) (<-chan bool, <-chan error) {
// err channel returned to calling context
errChan := make(chan error)
doneChan := make(chan bool)
go func() {
defer close(doneChan)
counter := 0
for {
select {
case tx := <-txRlpChan:
if err := shared.SendRawTransaction(s.client, tx); err != nil {
case tx := <-txChan:
counter += 1
if err := shared.SendTransaction(s.client, tx); err != nil {
errChan <- err
} else {
sentCh <- tx
}
case <-quitChan:
logrus.Info("quitting Send loop")
logrus.Infof("quitting Send loop (sent %d)", counter)
return
}
}

View File

@ -50,31 +50,56 @@ func (s *Spammer) Loop(quitChan <-chan bool) (<-chan bool, error) {
genQuit := make(chan bool)
senderQuit := make(chan bool)
doneChan := make(chan bool)
genDoneChan, txRlpChan, genErrChan := s.TxGenerator.GenerateTxs(genQuit, contractAddrs)
sendDoneChan, sendErrChan := s.Sender.Send(senderQuit, txRlpChan)
watcher := NewTxWatcher(s.config.EthClient)
watcher.Start()
s.config.CallConfig.ContractAddrs = contractAddrs
genDoneChan, txChan, genErrChan := s.TxGenerator.GenerateTxs(genQuit)
sendDoneChan, sendErrChan := s.Sender.Send(senderQuit, txChan, watcher.PendingTxCh)
go func() {
defer close(doneChan)
for {
select {
case err := <-genErrChan:
logrus.Errorf("tx generation error: %v", err)
close(genQuit)
recoverClose(genQuit)
<-genDoneChan
close(senderQuit)
recoverClose(senderQuit)
<-sendDoneChan
recoverClose(watcher.quitCh)
case err := <-sendErrChan:
logrus.Errorf("tx sending error: %v", err)
close(genQuit)
recoverClose(genQuit)
<-genDoneChan
close(senderQuit)
recoverClose(senderQuit)
<-sendDoneChan
recoverClose(watcher.quitCh)
case <-quitChan:
logrus.Error("shutting down tx spammer")
close(genQuit)
logrus.Info("shutting down tx spammer")
recoverClose(genQuit)
<-genDoneChan
close(senderQuit)
recoverClose(senderQuit)
<-sendDoneChan
recoverClose(watcher.quitCh)
case <-sendDoneChan:
recoverClose(watcher.quitCh)
return
case <-genDoneChan:
recoverClose(senderQuit)
}
}
}()
return doneChan, nil
}
func recoverClose(ch chan bool) (justClosed bool) {
defer func() {
if recover() != nil {
justClosed = false
}
}()
close(ch)
return true
}

View File

@ -17,17 +17,17 @@
package auto
import (
"context"
"crypto/ecdsa"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
log "github.com/sirupsen/logrus"
"math/big"
"math/rand"
"sync"
"sync/atomic"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/vulcanize/tx_spammer/pkg/shared"
)
@ -36,15 +36,24 @@ type TxGenerator struct {
config *Config
// keep track of account nonces locally so we aren't spamming to determine the nonce
// this assumes these accounts are not sending txs outside this process
nonces map[common.Address]*uint64
nonces map[common.Address]uint64
lock sync.Mutex
}
func (gen *TxGenerator) claimNonce(addr common.Address) uint64 {
gen.lock.Lock()
ret := gen.nonces[addr]
gen.nonces[addr] += 1
gen.lock.Unlock()
return ret
}
// NewTxGenerator creates a new tx generator
func NewTxGenerator(config *Config) *TxGenerator {
nonces := make(map[common.Address]*uint64)
nonces := make(map[common.Address]uint64)
for _, addr := range config.SenderAddrs {
startingNonce := uint64(0)
nonces[addr] = &startingNonce
nonce, _ := config.EthClient.PendingNonceAt(context.Background(), addr)
nonces[addr] = nonce
}
return &TxGenerator{
nonces: nonces,
@ -56,25 +65,28 @@ func NewTxGenerator(config *Config) *TxGenerator {
type GenParams struct {
Sender common.Address
SenderKey *ecdsa.PrivateKey
ChainID *big.Int
GasTipCap *big.Int
GasFeeCap *big.Int
GasLimit uint64
To *common.Address
Amount *big.Int
GasLimit uint64
GasPrice *big.Int
Data []byte
}
func (gen *TxGenerator) GenerateTxs(quitChan <-chan bool, contractAddrs []common.Address) (<-chan bool, <-chan []byte, <-chan error) {
txRlpChan := make(chan []byte)
func (gen *TxGenerator) GenerateTxs(quitChan <-chan bool) (<-chan bool, <-chan *types.Transaction, <-chan error) {
txChan := make(chan *types.Transaction)
errChan := make(chan error)
wg := new(sync.WaitGroup)
for i, sender := range gen.config.SenderKeys {
if len(gen.config.SendConfig.DestinationAddresses) > 0 {
if gen.config.SendConfig.TotalNumber > 0 {
wg.Add(1)
go gen.genSends(wg, gen.config.Type, txRlpChan, errChan, quitChan, sender, gen.config.SenderAddrs[i], gen.config.SendConfig)
go gen.genSends(wg, txChan, errChan, quitChan, sender, gen.config.SenderAddrs[i], gen.config.SendConfig)
}
if len(gen.config.CallConfig.StorageAddrs) > 0 {
if gen.config.CallConfig.TotalNumber > 0 {
wg.Add(1)
go gen.genCalls(wg, gen.config.Type, txRlpChan, errChan, quitChan, sender, gen.config.SenderAddrs[i], gen.config.CallConfig)
go gen.genCalls(wg, txChan, errChan, quitChan, sender, gen.config.SenderAddrs[i], gen.config.CallConfig)
}
}
doneChan := make(chan bool)
@ -82,108 +94,111 @@ func (gen *TxGenerator) GenerateTxs(quitChan <-chan bool, contractAddrs []common
wg.Wait()
close(doneChan)
}()
return doneChan, txRlpChan, errChan
return doneChan, txChan, errChan
}
func (gen *TxGenerator) genSends(wg *sync.WaitGroup, ty shared.TxType, txRlpChan chan<- []byte, errChan chan<- error, quitChan <-chan bool, senderKey *ecdsa.PrivateKey, senderAddr common.Address, sendConfig *SendConfig) {
func (gen *TxGenerator) genSends(wg *sync.WaitGroup, txChan chan<- *types.Transaction, errChan chan<- error, quitChan <-chan bool, senderKey *ecdsa.PrivateKey, senderAddr common.Address, sendConfig *SendConfig) {
defer wg.Done()
ticker := time.NewTicker(sendConfig.Frequency)
for _, dst := range sendConfig.DestinationAddresses {
for i := 0; i < sendConfig.TotalNumber; i++ {
select {
case <-ticker.C:
txRlp, _, err := gen.GenerateTx(ty, &GenParams{
dst := crypto.CreateAddress(receiverAddressSeed, uint64(i))
log.Debugf("Generating send from %s to %s.", senderAddr.Hex(), dst.Hex())
rawTx, _, err := gen.GenerateTx(&GenParams{
ChainID: sendConfig.ChainID,
To: &dst,
Sender: senderAddr,
SenderKey: senderKey,
GasLimit: sendConfig.GasLimit,
GasPrice: sendConfig.GasPrice,
GasFeeCap: sendConfig.GasFeeCap,
GasTipCap: sendConfig.GasTipCap,
Amount: sendConfig.Amount,
To: &dst,
})
if err != nil {
errChan <- err
continue
}
txRlpChan <- txRlp
txChan <- rawTx
case <-quitChan:
return
}
}
log.Info("Done generating sends for ", senderAddr.Hex())
}
func (gen *TxGenerator) genCalls(wg *sync.WaitGroup, ty shared.TxType, txRlpChan chan<- []byte, errChan chan<- error, quitChan <-chan bool, senderKey *ecdsa.PrivateKey, senderAddr common.Address, callConfig *CallConfig) {
func (gen *TxGenerator) genCalls(wg *sync.WaitGroup, txChan chan<- *types.Transaction, errChan chan<- error, quitChan <-chan bool, senderKey *ecdsa.PrivateKey, senderAddr common.Address, callConfig *CallConfig) {
defer wg.Done()
ticker := time.NewTicker(callConfig.Frequency)
for _, addr := range callConfig.StorageAddrs {
for i := 0; i < callConfig.TotalNumber; i++ {
select {
case <-ticker.C:
data, err := callConfig.ABI.Pack(callConfig.MethodName, addr, callConfig.StorageValue)
contractAddr := callConfig.ContractAddrs[rand.Intn(len(callConfig.ContractAddrs))]
log.Debugf("Generating call from %s to %s.", senderAddr.Hex(), contractAddr.Hex())
data, err := callConfig.ABI.Pack(callConfig.MethodName, contractAddr, big.NewInt(int64(i)))
if err != nil {
errChan <- err
continue
}
txRlp, _, err := gen.GenerateTx(ty, &GenParams{
rawTx, _, err := gen.GenerateTx(&GenParams{
Sender: senderAddr,
SenderKey: senderKey,
GasLimit: callConfig.GasLimit,
GasPrice: callConfig.GasPrice,
GasFeeCap: callConfig.GasFeeCap,
GasTipCap: callConfig.GasTipCap,
Data: data,
To: &contractAddr,
})
if err != nil {
errChan <- err
continue
}
txRlpChan <- txRlp
txChan <- rawTx
case <-quitChan:
return
}
}
log.Info("Done generating calls for ", senderAddr.Hex())
}
// GenerateTx generates tx from the provided params
func (gen TxGenerator) GenerateTx(ty shared.TxType, params *GenParams) ([]byte, common.Address, error) {
switch ty {
case shared.OptimismL2:
return gen.genL2(params, gen.config.OptimismConfig)
case shared.Standard:
return gen.gen(params)
case shared.EIP1559:
return gen.gen1559(params, gen.config.EIP1559Config)
default:
return nil, common.Address{}, fmt.Errorf("unsupported tx type: %s", ty.String())
}
}
func (gen TxGenerator) genL2(params *GenParams, op *OptimismConfig) ([]byte, common.Address, error) {
nonce := atomic.AddUint64(gen.nonces[params.Sender], 1)
func (gen *TxGenerator) GenerateTx(params *GenParams) (*types.Transaction, common.Address, error) {
nonce := gen.claimNonce(params.Sender)
tx := new(types.Transaction)
var contractAddr common.Address
var err error
if params.To == nil {
tx = types.NewContractCreation(nonce, params.Amount, params.GasLimit, params.GasPrice, params.Data, op.L1SenderAddr, op.L1RollupTxId, op.QueueOrigin)
contractAddr, err = shared.WriteContractAddr(shared.DefaultDeploymentAddrLogPathPrefix, params.Sender, nonce)
tx = types.NewTx(
&types.DynamicFeeTx{
ChainID: params.ChainID,
Nonce: nonce,
Gas: params.GasLimit,
GasTipCap: params.GasTipCap,
GasFeeCap: params.GasFeeCap,
To: nil,
Value: params.Amount,
Data: params.Data,
})
contractAddr, err = shared.WriteContractAddr("", params.Sender, nonce)
if err != nil {
return nil, common.Address{}, err
}
} else {
tx = types.NewTransaction(nonce, *params.To, params.Amount, params.GasLimit, params.GasPrice, params.Data, op.L1SenderAddr, op.L1RollupTxId, op.QueueOrigin, op.SigHashType)
tx = types.NewTx(
&types.DynamicFeeTx{
ChainID: params.ChainID,
Nonce: nonce,
GasTipCap: params.GasTipCap,
GasFeeCap: params.GasFeeCap,
Gas: params.GasLimit,
To: params.To,
Value: params.Amount,
Data: params.Data,
})
}
signedTx, err := types.SignTx(tx, gen.config.Signer, params.SenderKey)
if err != nil {
return nil, common.Address{}, err
}
txRlp, err := rlp.EncodeToBytes(signedTx)
if err != nil {
return nil, common.Address{}, err
}
return txRlp, contractAddr, err
}
func (gen TxGenerator) gen(params *GenParams) ([]byte, common.Address, error) {
// TODO: support standard geth
return nil, common.Address{}, errors.New("L1 support not yet available")
}
func (gen TxGenerator) gen1559(params *GenParams, eip1559Config *EIP1559Config) ([]byte, common.Address, error) {
// TODO: support EIP1559
return nil, common.Address{}, errors.New("1559 support not yet available")
return signedTx, contractAddr, err
}

60
pkg/auto/tx_watcher.go Normal file
View File

@ -0,0 +1,60 @@
package auto
import (
"context"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/sirupsen/logrus"
"time"
)
type TxWatcher struct {
PendingTxCh chan *types.Transaction
ethClient *ethclient.Client
quitCh chan bool
startedAt time.Time
counter uint
}
func NewTxWatcher(ethClient *ethclient.Client) *TxWatcher {
return &TxWatcher{
PendingTxCh: make(chan *types.Transaction, 2500),
ethClient: ethClient,
quitCh: make(chan bool),
}
}
func (tw *TxWatcher) Start() {
tw.startedAt = time.Now()
go func() {
defer close(tw.PendingTxCh)
for {
select {
case tx := <-tw.PendingTxCh:
tw.counter += 1
if 0 == tw.counter%50 {
logrus.Debugf("TxW: checking on TX %s (%d in channel)", tx.Hash().Hex(), len(tw.PendingTxCh))
var receipt *types.Receipt = nil
sleep := time.Millisecond
start := time.Now()
for receipt == nil {
receipt, _ = tw.ethClient.TransactionReceipt(context.Background(), tx.Hash())
if nil == receipt {
time.Sleep(sleep)
sleep *= 2
} else {
elapsed := time.Now().Sub(tw.startedAt)
logrus.Debugf("TxW: TX %s found in block %s after %dms.", tx.Hash().Hex(),
receipt.BlockNumber.String(), time.Now().Sub(start).Milliseconds())
logrus.Infof("TxW: %d in %.0f seconds (%.2f/sec, %d pending)",
tw.counter, elapsed.Seconds(), float64(tw.counter)/elapsed.Seconds(), len(tw.PendingTxCh))
}
}
}
case <-tw.quitCh:
logrus.Infof("TxW: quitting with %d in channel", len(tw.PendingTxCh))
return
}
}
}()
}

View File

@ -24,11 +24,7 @@ import (
"strings"
"time"
"github.com/vulcanize/tx_spammer/pkg/shared"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rpc"
"github.com/spf13/viper"
@ -42,29 +38,16 @@ type TxParams struct {
// HTTP Client for this tx type
Client *rpc.Client
// Type of the tx
Type shared.TxType
// Chain ID
ChainID uint64
// Universal tx fields
To *common.Address
GasLimit uint64
GasPrice *big.Int // nil if eip1559
Amount *big.Int
Data []byte
Sender common.Address
// Optimism-specific metadata fields
L1SenderAddr *common.Address
L1RollupTxId *hexutil.Uint64
SigHashType types.SignatureHashType
QueueOrigin types.QueueOrigin
// EIP1559-specific fields
GasPremium *big.Int
FeeCap *big.Int
// DynamicFeeTx properties - Start
ChainID *big.Int
Nonce uint64
GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas
GasFeeCap *big.Int // a.k.a. maxFeePerGas
Gas uint64
To *common.Address // nil means contract creation
Value *big.Int
Data []byte
// DynamicFeeTx properties - End
// Sender key, if left the senderKeyPath is empty we generate a new key
SenderKey *ecdsa.PrivateKey
@ -72,6 +55,7 @@ type TxParams struct {
ContractAddrWritePath string
// Sending params
Sender common.Address
// How often we send a tx of this type
Frequency time.Duration
// Total number of txs of this type to send
@ -80,7 +64,7 @@ type TxParams struct {
Delay time.Duration
}
// NewConfig returns a new tx spammer config
// NewTxParams NewConfig returns a new tx spammer config
func NewTxParams() ([]TxParams, error) {
bindEnv()
addrLogPath := viper.GetString("eth.addrLogPath")
@ -100,16 +84,6 @@ func NewTxParams() ([]TxParams, error) {
return nil, err
}
// Get tx type and chain id
txTypeStr := viper.GetString(txName + typeSuffix)
if txTypeStr == "" {
return nil, fmt.Errorf("need tx type for tx %s", txName)
}
txType, err := shared.TxTypeFromString(txTypeStr)
if err != nil {
return nil, err
}
// Get basic fields
toStr := viper.GetString(txName + toSuffix)
var toAddr *common.Address
@ -124,17 +98,9 @@ func NewTxParams() ([]TxParams, error) {
return nil, fmt.Errorf("amount (%s) for tx %s is not valid", amountStr, txName)
}
}
gasPriceStr := viper.GetString(txName + gasPriceSuffix)
var gasPrice *big.Int
if gasPriceStr != "" {
gasPrice = new(big.Int)
if _, ok := gasPrice.SetString(gasPriceStr, 10); !ok {
return nil, fmt.Errorf("gasPrice (%s) for tx %s is not valid", gasPriceStr, txName)
}
}
gasLimit := viper.GetUint64(txName + gasLimitSuffix)
hex := viper.GetString(txName + dataSuffix)
data := make([]byte, 0)
var data []byte = nil
if hex != "" {
data = common.Hex2Bytes(hex)
}
@ -165,62 +131,41 @@ func NewTxParams() ([]TxParams, error) {
return nil, err
}
// Attempt to load Optimism fields
l1SenderStr := viper.GetString(txName + l1SenderSuffix)
var l1Sender *common.Address
if l1SenderStr != "" {
sender := common.HexToAddress(l1SenderStr)
l1Sender = &sender
}
l1RollupTxId := viper.GetUint64(txName + l1RollupTxIdSuffix)
l1rtid := (hexutil.Uint64)(l1RollupTxId)
sigHashType := viper.GetUint(txName + sigHashTypeSuffix)
queueOrigin := viper.GetInt64(txName + queueOriginSuffix)
// If gasPrice was empty, attempt to load EIP1559 fields
var feeCap, gasPremium *big.Int
if gasPrice == nil {
feeCapStr := viper.GetString(txName + feeCapSuffix)
gasPremiumString := viper.GetString(txName + gasPremiumSuffix)
if feeCapStr == "" {
return nil, fmt.Errorf("tx %s is missing feeCapStr", txName)
}
if gasPremiumString == "" {
return nil, fmt.Errorf("tx %s is missing gasPremiumStr", txName)
}
feeCap = new(big.Int)
gasPremium = new(big.Int)
if _, ok := feeCap.SetString(feeCapStr, 10); !ok {
return nil, fmt.Errorf("unable to set feeCap to %s for tx %s", feeCapStr, txName)
}
if _, ok := gasPremium.SetString(gasPremiumString, 10); !ok {
return nil, fmt.Errorf("unable to set gasPremium to %s for tx %s", gasPremiumString, txName)
}
var feeCap, tipCap *big.Int
feeCapStr := viper.GetString(txName + feeCapSuffix)
tipCapStr := viper.GetString(txName + tipCapSuffix)
if feeCapStr == "" {
return nil, fmt.Errorf("tx %s is missing feeCapStr", txName)
}
if tipCapStr == "" {
return nil, fmt.Errorf("tx %s is missing tipCapStr", txName)
}
feeCap = new(big.Int)
tipCap = new(big.Int)
if _, ok := feeCap.SetString(feeCapStr, 10); !ok {
return nil, fmt.Errorf("unable to set feeCap to %s for tx %s", feeCapStr, txName)
}
if _, ok := tipCap.SetString(tipCapStr, 10); !ok {
return nil, fmt.Errorf("unable to set tipCap to %s for tx %s", tipCapStr, txName)
}
txParams[i] = TxParams{
Name: txName,
Client: rpcClient,
Type: txType,
ChainID: viper.GetUint64(txName + chainIDSuffix),
GasTipCap: tipCap,
GasFeeCap: feeCap,
Gas: gasLimit,
To: toAddr,
GasLimit: gasLimit,
GasPrice: gasPrice,
Amount: amount,
Value: amount,
Data: data,
Sender: sender,
L1SenderAddr: l1Sender,
L1RollupTxId: &l1rtid,
SigHashType: (types.SignatureHashType)(uint8(sigHashType)),
QueueOrigin: (types.QueueOrigin)(queueOrigin),
GasPremium: gasPremium,
FeeCap: feeCap,
SenderKey: key,
StartingNonce: viper.GetUint64(txName + startingNonceSuffix),
ContractAddrWritePath: viper.GetString(txName + contractWriteSuffix),
Frequency: viper.GetDuration(txName + frequencySuffix),
Frequency: viper.GetDuration(txName+frequencySuffix) * time.Millisecond,
TotalNumber: viper.GetUint64(txName + totalNumberSuffix),
Delay: viper.GetDuration(txName + delaySuffix),
Delay: viper.GetDuration(txName+delaySuffix) * time.Millisecond,
}
}
return txParams, nil

View File

@ -33,20 +33,15 @@ const (
toSuffix = ".to"
amountSuffix = ".amount"
gasLimitSuffix = ".gasLimit"
gasPriceSuffix = ".gasPrice"
gasPremiumSuffix = ".gasPremium"
feeCapSuffix = ".feeCap"
tipCapSuffix = ".tipCap"
dataSuffix = ".data"
senderKeyPathSuffix = ".senderKeyPath"
writeSenderPathSuffix = ".writeSenderPath"
l1SenderSuffix = ".l1Sender"
l1RollupTxIdSuffix = ".l1RollupTxId"
sigHashTypeSuffix = ".sigHashType"
frequencySuffix = ".frequency"
totalNumberSuffix = ".totalNumber"
delaySuffix = ".delay"
startingNonceSuffix = ".startingNonce"
queueOriginSuffix = ".queueOrigin"
chainIDSuffix = ".chainID"
contractWriteSuffix = ".writeDeploymentAddrPath"
)

View File

@ -17,8 +17,6 @@
package manual
import (
"errors"
"fmt"
"sync/atomic"
"github.com/ethereum/go-ethereum/common"
@ -46,54 +44,46 @@ func NewTxGenerator(params []TxParams) *TxGenerator {
}
// GenerateTx generates tx from the provided params
func (tg TxGenerator) GenerateTx(params TxParams) ([]byte, error) {
tx := make([]byte, 0)
switch params.Type {
case shared.OptimismL2:
return tg.genL2(params)
case shared.Standard:
return tg.gen(params)
case shared.EIP1559:
return tg.gen1559(params)
default:
return nil, fmt.Errorf("unsupported tx type: %s", params.Type.String())
}
return tx, nil
}
func (gen TxGenerator) genL2(params TxParams) ([]byte, error) {
func (gen TxGenerator) GenerateTx(params TxParams) ([]byte, error) {
nonce := atomic.AddUint64(gen.nonces[params.Sender], 1)
tx := new(types.Transaction)
if params.To == nil {
tx = types.NewContractCreation(nonce, params.Amount, params.GasLimit, params.GasPrice, params.Data, params.L1SenderAddr, params.L1RollupTxId, params.QueueOrigin)
tx = types.NewTx(
&types.DynamicFeeTx{
ChainID: params.ChainID,
Nonce: nonce,
Gas: params.Gas,
GasTipCap: params.GasTipCap,
GasFeeCap: params.GasFeeCap,
To: nil,
Value: params.Value,
Data: params.Data,
})
if _, err := shared.WriteContractAddr(params.ContractAddrWritePath, params.Sender, nonce); err != nil {
return nil, err
}
} else {
tx = types.NewTransaction(nonce, *params.To, params.Amount, params.GasLimit, params.GasPrice, params.Data, params.L1SenderAddr, params.L1RollupTxId, params.QueueOrigin, params.SigHashType)
}
signer, err := shared.TxSigner(shared.OptimismL2, params.ChainID)
if err != nil {
return nil, err
tx = types.NewTx(
&types.DynamicFeeTx{
ChainID: params.ChainID,
Nonce: nonce,
Gas: params.Gas,
GasTipCap: params.GasTipCap,
GasFeeCap: params.GasFeeCap,
To: params.To,
Value: params.Value,
Data: params.Data,
})
}
signer := shared.TxSigner(params.ChainID)
signedTx, err := types.SignTx(tx, signer, params.SenderKey)
if err != nil {
return nil, err
}
txRlp, err := rlp.EncodeToBytes(signedTx)
rawTx, err := rlp.EncodeToBytes(signedTx)
if err != nil {
return nil, err
}
return txRlp, nil
}
func (gen TxGenerator) gen(params TxParams) ([]byte, error) {
// TODO: support standard geth
return nil, errors.New("L1 support not yet available")
}
func (gen TxGenerator) gen1559(params TxParams) ([]byte, error) {
// TODO: support EIP1559
return nil, errors.New("1559 support not yet available")
return rawTx, nil
}

View File

@ -1,63 +0,0 @@
// VulcanizeDB
// Copyright © 2020 Vulcanize
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package shared
import (
"fmt"
"strings"
)
type TxType int
const (
Unsupported TxType = iota
Standard
OptimismL2
OptimismL1ToL2
EIP1559
)
func (tt TxType) String() string {
switch tt {
case Standard:
return "Standard"
case OptimismL2:
return "L2"
case OptimismL1ToL2:
return "L1toL2"
case EIP1559:
return "EIP1559"
default:
return "Unsupported"
}
}
// TxTypeFromString returns the tx enum type from provided string
func TxTypeFromString(str string) (TxType, error) {
switch strings.ToLower(str) {
case "geth", "standard", "parity":
return Standard, nil
case "l2":
return OptimismL2, nil
case "l1", "l2tol1":
return OptimismL1ToL2, nil
case "eip1559":
return EIP1559, nil
default:
return Unsupported, fmt.Errorf("unsupported tx type: %s", str)
}
}

View File

@ -18,7 +18,7 @@ package shared
import (
"context"
"fmt"
"github.com/sirupsen/logrus"
"math/big"
"os"
@ -31,20 +31,35 @@ import (
)
// ChainConfig returns the appropriate ethereum chain config for the provided chain id
func TxSigner(kind TxType, chainID uint64) (types.Signer, error) {
switch kind {
case Standard, EIP1559:
return types.NewEIP155Signer(new(big.Int).SetUint64(chainID)), nil
case OptimismL2, OptimismL1ToL2:
return types.NewOVMSigner(new(big.Int).SetUint64(chainID)), nil
default:
return nil, fmt.Errorf("chain config for chainid %d not available", chainID)
func TxSigner(chainID *big.Int) types.Signer {
return types.NewLondonSigner(chainID)
}
// SendTransaction sends a signed tx using the provided client
func SendTransaction(rpcClient *rpc.Client, tx *types.Transaction) error {
msg, _ := tx.AsMessage(TxSigner(tx.ChainId()), big.NewInt(1))
if nil == tx.To() {
logrus.Debugf("TX %s to create contract %s (sender %s)",
tx.Hash().Hex(), crypto.CreateAddress(msg.From(), tx.Nonce()), msg.From().Hex())
} else if nil == tx.Data() || len(tx.Data()) == 0 {
logrus.Debugf("TX %s sending %s Wei to %s (sender %s)",
tx.Hash().Hex(), tx.Value().String(), msg.To().Hex(), msg.From().Hex())
} else {
logrus.Debugf("TX %s calling contract %s (sender %s)",
tx.Hash().Hex(), msg.To().Hex(), msg.From().Hex())
}
data, err := tx.MarshalBinary()
if err != nil {
return err
}
return SendRawTransaction(rpcClient, data)
}
// SendRawTransaction sends a raw, signed tx using the provided client
func SendRawTransaction(rpcClient *rpc.Client, txRlp []byte) error {
return rpcClient.CallContext(context.Background(), nil, "eth_sendRawTransaction", hexutil.Encode(txRlp))
func SendRawTransaction(rpcClient *rpc.Client, raw []byte) error {
logrus.Debug("eth_sendRawTransaction: ", hexutil.Encode(raw))
return rpcClient.CallContext(context.Background(), nil, "eth_sendRawTransaction", hexutil.Encode(raw))
}
// WriteContractAddr appends a contract addr to an out file

28
sol/Test.sol Normal file
View File

@ -0,0 +1,28 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
contract Test {
address payable owner;
modifier onlyOwner {
require(
msg.sender == owner,
"Only owner can call this function."
);
_;
}
mapping(address => uint256) public data;
constructor() {
owner = payable(msg.sender);
}
function Put(address addr, uint256 value) public {
data[addr] = value;
}
function close() public onlyOwner {
selfdestruct(owner);
}
}

1
sol/build/Test.abi Normal file
View File

@ -0,0 +1 @@
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"Put","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"close","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"data","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

1
sol/build/Test.bin Normal file
View File

@ -0,0 +1 @@
608060405234801561001057600080fd5b50336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506103cc806100606000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80632802348a1461004657806343d726d614610062578063b90d3d0c1461006c575b600080fd5b610060600480360381019061005b919061025c565b61009c565b005b61006a6100e4565b005b6100866004803603810190610081919061029c565b6101ab565b60405161009391906102d8565b60405180910390f35b80600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610172576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161016990610376565b60405180910390fd5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b60016020528060005260406000206000915090505481565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006101f3826101c8565b9050919050565b610203816101e8565b811461020e57600080fd5b50565b600081359050610220816101fa565b92915050565b6000819050919050565b61023981610226565b811461024457600080fd5b50565b60008135905061025681610230565b92915050565b60008060408385031215610273576102726101c3565b5b600061028185828601610211565b925050602061029285828601610247565b9150509250929050565b6000602082840312156102b2576102b16101c3565b5b60006102c084828501610211565b91505092915050565b6102d281610226565b82525050565b60006020820190506102ed60008301846102c9565b92915050565b600082825260208201905092915050565b7f4f6e6c79206f776e65722063616e2063616c6c20746869732066756e6374696f60008201527f6e2e000000000000000000000000000000000000000000000000000000000000602082015250565b60006103606022836102f3565b915061036b82610304565b604082019050919050565b6000602082019050818103600083015261038f81610353565b905091905056fea26469706673582212201d7a5e3145cb5b1067ff7c8bb867ec5228d0645ac9eea2ad26735c9b2ad33cd764736f6c63430008110033