Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Adding loadbot ERC20 and ERC721 token transfer mode #425

Merged
merged 40 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f968a1c
* Added erc20 contract bytecode and abi
ZeljkoBenovic Feb 10, 2022
3da7931
Added support for erc20 token transfer
ZeljkoBenovic Feb 10, 2022
a99d99c
Pleasing linter gods
ZeljkoBenovic Feb 11, 2022
28480f6
* Added gasUsed metric
ZeljkoBenovic Feb 15, 2022
a70c821
* Added average blocks utilistaion metric
ZeljkoBenovic Feb 15, 2022
d8e6ff2
Linter fixes
ZeljkoBenovic Feb 17, 2022
12ec83c
Merge branch 'develop' into feature/loadbot_erc20
ZeljkoBenovic Feb 17, 2022
61c2e9a
added erc721 loadbot mode
ZeljkoBenovic Feb 25, 2022
e155634
move contract bytecode encoding to GetExampleTransaction()
dbrajovic Feb 25, 2022
1e834c1
refactor erc20 mode
dbrajovic Mar 1, 2022
b5265d9
add erc20 generator
dbrajovic Mar 1, 2022
c77fac6
* Fix grammar errors
ZeljkoBenovic Mar 1, 2022
1251e7a
Merge branch 'feature/loadbot_erc721' into feature/loadbot_erc20
ZeljkoBenovic Mar 1, 2022
438adc5
* Added ERC721 support
ZeljkoBenovic Mar 2, 2022
6b3aef8
* Fixed some error returns
ZeljkoBenovic Mar 2, 2022
2a95042
increase wait for receipt timeout threshold
ZeljkoBenovic Mar 2, 2022
32f5d10
upped min receipt wait time to 2 min.
ZeljkoBenovic Mar 2, 2022
397510d
* Set max-conns default to very high value
ZeljkoBenovic Mar 2, 2022
7c8e097
pleasing linter gods
ZeljkoBenovic Mar 2, 2022
7e0ee0b
Merge branch 'develop' into feature/loadbot_erc20
ZeljkoBenovic Mar 7, 2022
e70281e
* refactored to acomodate Cobra CLI
ZeljkoBenovic Mar 7, 2022
2a541d3
removed receiptTimeout unnecessary declaration
ZeljkoBenovic Mar 8, 2022
4997af2
added calculateGasMetrics method
ZeljkoBenovic Mar 8, 2022
9660f02
calculateGasMetrics method set to run async
ZeljkoBenovic Mar 8, 2022
c181cf7
created updateGasEstimate method
ZeljkoBenovic Mar 26, 2022
168f73c
* moved constructor args to const
ZeljkoBenovic Mar 26, 2022
f2881dd
moved error channel out of the for loop
ZeljkoBenovic Mar 26, 2022
912c140
set json omitempty on ContractAddress and ContractBlockData
ZeljkoBenovic Mar 27, 2022
fd63762
* moved contract deployment exectution data to dedicated method
ZeljkoBenovic Mar 27, 2022
ecf9a2e
* using errorgroup to wait for errors for goroutines in calculateGasM…
ZeljkoBenovic Mar 27, 2022
a9000c8
* added isValidMode method
ZeljkoBenovic Mar 27, 2022
6e26304
* restored calcMaxTimeout func
ZeljkoBenovic Mar 27, 2022
3c8fa5a
* increased min wait time for receipts to 60s
ZeljkoBenovic Mar 27, 2022
65207fa
* added isTokenTransferMode helper method
ZeljkoBenovic Mar 27, 2022
0d0dc34
* moved contract related data from BaseGenerator to ContractTnxsGener…
ZeljkoBenovic Mar 27, 2022
37a0fba
pleasing lint gods
ZeljkoBenovic Mar 27, 2022
601ceef
Merge branch 'develop' into feature/loadbot_erc20
ZeljkoBenovic Mar 29, 2022
7e9ba05
resolve conflicts
ZeljkoBenovic Mar 29, 2022
ac607d1
Added token supply description
ZeljkoBenovic Mar 29, 2022
f87e680
lint fix
ZeljkoBenovic Mar 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions command/loadbot/abis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package loadbot

const (
//nolint:lll
ERC20ABI = `[{"inputs":[{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"string","name":"coinName","type":"string"},{"internalType":"string","name":"coinSymbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"tokenOwner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokens","type":"uint256"}],"name":"Transfer","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"delegate","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"delegate","type":"address"},{"internalType":"uint256","name":"numTokens","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenOwner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"numTokens","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"buyer","type":"address"},{"internalType":"uint256","name":"numTokens","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]`
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
//nolint:lll
ERC20BIN = "60806040523480156200001157600080fd5b506040516200146538038062001465833981810160405281019062000037919062000363565b81600090805190602001906200004f929190620000db565b50806001908051906020019062000068929190620000db565b506005600260006101000a81548160ff021916908360ff16021790555082600581905550600554600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555050505062000462565b828054620000e9906200042c565b90600052602060002090601f0160209004810192826200010d576000855562000159565b82601f106200012857805160ff191683800117855562000159565b8280016001018555821562000159579182015b82811115620001585782518255916020019190600101906200013b565b5b5090506200016891906200016c565b5090565b5b80821115620001875760008160009055506001016200016d565b5090565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b620001b4816200019f565b8114620001c057600080fd5b50565b600081519050620001d481620001a9565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6200022f82620001e4565b810181811067ffffffffffffffff82111715620002515762000250620001f5565b5b80604052505050565b6000620002666200018b565b905062000274828262000224565b919050565b600067ffffffffffffffff821115620002975762000296620001f5565b5b620002a282620001e4565b9050602081019050919050565b60005b83811015620002cf578082015181840152602081019050620002b2565b83811115620002df576000848401525b50505050565b6000620002fc620002f68462000279565b6200025a565b9050828152602081018484840111156200031b576200031a620001df565b5b62000328848285620002af565b509392505050565b600082601f830112620003485762000347620001da565b5b81516200035a848260208601620002e5565b91505092915050565b6000806000606084860312156200037f576200037e62000195565b5b60006200038f86828701620001c3565b935050602084015167ffffffffffffffff811115620003b357620003b26200019a565b5b620003c18682870162000330565b925050604084015167ffffffffffffffff811115620003e557620003e46200019a565b5b620003f38682870162000330565b9150509250925092565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806200044557607f821691505b602082108114156200045c576200045b620003fd565b5b50919050565b610ff380620004726000396000f3fe60806040526004361061008a5760003560e01c8063313ce56711610059578063313ce5671461016957806370a082311461019457806395d89b41146101d1578063a9059cbb146101fc578063dd62ed3e1461023957610094565b806306fdde0314610099578063095ea7b3146100c457806318160ddd1461010157806323b872dd1461012c57610094565b3661009457600080fd5b600080fd5b3480156100a557600080fd5b506100ae610276565b6040516100bb9190610a9b565b60405180910390f35b3480156100d057600080fd5b506100eb60048036038101906100e69190610b56565b610304565b6040516100f89190610bb1565b60405180910390f35b34801561010d57600080fd5b506101166103f6565b6040516101239190610bdb565b60405180910390f35b34801561013857600080fd5b50610153600480360381019061014e9190610bf6565b610400565b6040516101609190610bb1565b60405180910390f35b34801561017557600080fd5b5061017e6106f2565b60405161018b9190610c65565b60405180910390f35b3480156101a057600080fd5b506101bb60048036038101906101b69190610c80565b610705565b6040516101c89190610bdb565b60405180910390f35b3480156101dd57600080fd5b506101e661074e565b6040516101f39190610a9b565b60405180910390f35b34801561020857600080fd5b50610223600480360381019061021e9190610b56565b6107dc565b6040516102309190610bb1565b60405180910390f35b34801561024557600080fd5b50610260600480360381019061025b9190610cad565b61097b565b60405161026d9190610bdb565b60405180910390f35b6000805461028390610d1c565b80601f01602080910402602001604051908101604052809291908181526020018280546102af90610d1c565b80156102fc5780601f106102d1576101008083540402835291602001916102fc565b820191906000526020600020905b8154815290600101906020018083116102df57829003601f168201915b505050505081565b600081600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516103e49190610bdb565b60405180910390a36001905092915050565b6000600554905090565b6000600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115610484576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161047b90610dc0565b60405180910390fd5b600460008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115610543576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161053a90610e52565b60405180910390fd5b81600360008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546105929190610ea1565b9250508190555081600460008673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546106259190610ea1565b9250508190555081600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600082825461067b9190610ed5565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516106df9190610bdb565b60405180910390a3600190509392505050565b600260009054906101000a900460ff1681565b6000600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6001805461075b90610d1c565b80601f016020809104026020016040519081016040528092919081815260200182805461078790610d1c565b80156107d45780601f106107a9576101008083540402835291602001916107d4565b820191906000526020600020905b8154815290600101906020018083116107b757829003601f168201915b505050505081565b6000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054821115610860576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161085790610f9d565b60405180910390fd5b81600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546108af9190610ea1565b9250508190555081600360008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546109059190610ed5565b925050819055508273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516109699190610bdb565b60405180910390a36001905092915050565b6000600460008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054905092915050565b600081519050919050565b600082825260208201905092915050565b60005b83811015610a3c578082015181840152602081019050610a21565b83811115610a4b576000848401525b50505050565b6000601f19601f8301169050919050565b6000610a6d82610a02565b610a778185610a0d565b9350610a87818560208601610a1e565b610a9081610a51565b840191505092915050565b60006020820190508181036000830152610ab58184610a62565b905092915050565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610aed82610ac2565b9050919050565b610afd81610ae2565b8114610b0857600080fd5b50565b600081359050610b1a81610af4565b92915050565b6000819050919050565b610b3381610b20565b8114610b3e57600080fd5b50565b600081359050610b5081610b2a565b92915050565b60008060408385031215610b6d57610b6c610abd565b5b6000610b7b85828601610b0b565b9250506020610b8c85828601610b41565b9150509250929050565b60008115159050919050565b610bab81610b96565b82525050565b6000602082019050610bc66000830184610ba2565b92915050565b610bd581610b20565b82525050565b6000602082019050610bf06000830184610bcc565b92915050565b600080600060608486031215610c0f57610c0e610abd565b5b6000610c1d86828701610b0b565b9350506020610c2e86828701610b0b565b9250506040610c3f86828701610b41565b9150509250925092565b600060ff82169050919050565b610c5f81610c49565b82525050565b6000602082019050610c7a6000830184610c56565b92915050565b600060208284031215610c9657610c95610abd565b5b6000610ca484828501610b0b565b91505092915050565b60008060408385031215610cc457610cc3610abd565b5b6000610cd285828601610b0b565b9250506020610ce385828601610b0b565b9150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b60006002820490506001821680610d3457607f821691505b60208210811415610d4857610d47610ced565b5b50919050565b7f546865206f776e657220646f65736e2774206861766520656e6f75676820667560008201527f6e647320746f206d616b6520746865207472616e736665722100000000000000602082015250565b6000610daa603983610a0d565b9150610db582610d4e565b604082019050919050565b60006020820190508181036000830152610dd981610d9d565b9050919050565b7f5468652064656c656761746520646f73656e2774206861766520656e6f75676860008201527f20616c6c6f77616e636520746f206d616b6520746865207472616e7366657221602082015250565b6000610e3c604083610a0d565b9150610e4782610de0565b604082019050919050565b60006020820190508181036000830152610e6b81610e2f565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610eac82610b20565b9150610eb783610b20565b925082821015610eca57610ec9610e72565b5b828203905092915050565b6000610ee082610b20565b9150610eeb83610b20565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610f2057610f1f610e72565b5b828201905092915050565b7f5468652073656e64657220646f73656e2774206861766520656e6f756768206660008201527f756e647320746f206d616b6520746865207472616e7366657221000000000000602082015250565b6000610f87603a83610a0d565b9150610f9282610f2b565b604082019050919050565b60006020820190508181036000830152610fb681610f7a565b905091905056fea2646970667358221220b323d4c936f691bb75019e448b4dad3aadc00d047eba1c01d09c1d4c10b373d464736f6c634300080b0033"
)
144 changes: 115 additions & 29 deletions command/loadbot/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import (
"context"
"crypto/ecdsa"
"fmt"
"github.com/0xPolygon/polygon-edge/command/loadbot/generator"
txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto"
"github.com/golang/protobuf/ptypes/any"
"log"
"math/big"
"sync"
"sync/atomic"
"time"

"github.com/0xPolygon/polygon-edge/command/loadbot/generator"
txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto"
"github.com/golang/protobuf/ptypes/any"

"github.com/0xPolygon/polygon-edge/helper/tests"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/go-web3"
Expand All @@ -20,7 +22,7 @@ import (

const (
maxReceiptWait = 5 * time.Minute
minReceiptWait = 30 * time.Second
minReceiptWait = 60 * time.Second

defaultFastestTurnAround = time.Hour * 24
defaultSlowestTurnAround = time.Duration(0)
Expand All @@ -33,6 +35,7 @@ type Mode string
const (
transfer Mode = "transfer"
deploy Mode = "deploy"
erc20 Mode = "erc20"
)

type Account struct {
Expand All @@ -54,6 +57,7 @@ type Configuration struct {
GasPrice *big.Int
GasLimit *big.Int
ContractArtifact *generator.ContractArtifact
ConstructorArgs []byte // smart contract constructor args
}

type metadata struct {
Expand Down Expand Up @@ -87,6 +91,9 @@ type ExecDuration struct {

// TotalExecTime is the total execution time for a single loadbot run
TotalExecTime time.Duration

// gas per block used
GasUsed map[uint64]uint64
}

// calcTurnAroundMetrics updates the turn around metrics based on the turnAroundMap
Expand Down Expand Up @@ -156,6 +163,16 @@ type Metrics struct {
TotalTransactionsSentCount uint64
FailedTransactionsCount uint64
TransactionDuration ExecDuration

// contracts
FailedContractTransactionsCount uint64
ContractDeploymentDuration ExecDuration
ContractAddress web3.Address
ContractGasMetrics BlockGasMetrics

CumulativeGasUsed uint64

GasMetrics BlockGasMetrics
}

type Loadbot struct {
Expand All @@ -164,6 +181,16 @@ type Loadbot struct {
generator generator.TransactionGenerator
}

type BlockGasMetrics struct {
Blocks map[uint64]GasMetrics
BlockGasMutex *sync.Mutex
}

type GasMetrics struct {
GasUsed uint64
GasLimit uint64
}

// calcMaxTimeout calculates the max timeout for transactions receipts
// based on the transaction count and tps params
func calcMaxTimeout(count, tps uint64) time.Duration {
Expand Down Expand Up @@ -227,10 +254,25 @@ func estimateGas(client *jsonrpc.Client, txn *types.Transaction) (uint64, error)

func (l *Loadbot) executeTxn(
client txpoolOp.TxnPoolOperatorClient,
mode string,
contractAddr *types.Address,
) (web3.Hash, error) {
txn, err := l.generator.GenerateTransaction()
if err != nil {
return web3.Hash{}, err
var (
txn *types.Transaction
err error
)

if mode == "erc20Transfer" {
// convert web3 to types address
txn, err = l.generator.GenerateTokenTransferTransaction(mode, contractAddr)
if err != nil {
return web3.Hash{}, err
}
} else {
txn, err = l.generator.GenerateTransaction(mode)
if err != nil {
return web3.Hash{}, err
}
}

addReq := &txpoolOp.AddTxnReq{
Expand Down Expand Up @@ -286,23 +328,26 @@ func (l *Loadbot) Run() error {

// Set up the transaction generator
generatorParams := &generator.GeneratorParams{
Nonce: nonce,
ChainID: l.cfg.ChainID,
SenderAddress: sender.Address,
SenderKey: sender.PrivateKey,
GasPrice: gasPrice,
Value: l.cfg.Value,
Nonce: nonce,
ChainID: l.cfg.ChainID,
SenderAddress: sender.Address,
RecieverAddress: l.cfg.Receiver,
SenderKey: sender.PrivateKey,
GasPrice: gasPrice,
Value: l.cfg.Value,
ContractArtifact: l.cfg.ContractArtifact,
ConstructorArgs: l.cfg.ConstructorArgs,
}

var (
txnGenerator generator.TransactionGenerator
genErr error = nil
genErr error
)

switch l.cfg.GeneratorMode {
case transfer:
txnGenerator, genErr = generator.NewTransferGenerator(generatorParams)
case deploy:
default:
txnGenerator, genErr = generator.NewDeployGenerator(generatorParams)
}

Expand Down Expand Up @@ -340,6 +385,9 @@ func (l *Loadbot) Run() error {

startTime := time.Now()

// deploy contracts
l.deployContract(grpcClient, jsonClient, receiptTimeout)

for i := uint64(0); i < l.cfg.Count; i++ {
<-ticker.C

Expand All @@ -350,23 +398,45 @@ func (l *Loadbot) Run() error {
go func(index uint64) {
defer wg.Done()

var txHash web3.Hash
// Start the performance timer
start := time.Now()

// Execute the transaction
txHash, err := l.executeTxn(grpcClient)
if err != nil {
l.generator.MarkFailedTxn(&generator.FailedTxnInfo{
Index: index,
TxHash: txHash.String(),
Error: &generator.TxnError{
Error: err,
ErrorType: generator.AddErrorType,
},
})
atomic.AddUint64(&l.metrics.FailedTransactionsCount, 1)

return
// run different transactions for different modes
if l.cfg.GeneratorMode == erc20 {
// Execute ERC20 Contract token transaction and report any errors
contractAddr := types.Address(l.metrics.ContractAddress)

txHash, err = l.executeTxn(grpcClient, "erc20Transfer", &contractAddr)
Kourin1996 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
l.generator.MarkFailedTxn(&generator.FailedTxnInfo{
Index: index,
TxHash: txHash.String(),
Error: &generator.TxnError{
Error: err,
ErrorType: generator.AddErrorType,
},
})
atomic.AddUint64(&l.metrics.FailedTransactionsCount, 1)

return
}
} else {
// Execute the transaction
txHash, err = l.executeTxn(grpcClient, "transaction", &types.ZeroAddress)
if err != nil {
l.generator.MarkFailedTxn(&generator.FailedTxnInfo{
Index: index,
TxHash: txHash.String(),
Error: &generator.TxnError{
Error: err,
ErrorType: generator.AddErrorType,
},
})
atomic.AddUint64(&l.metrics.FailedTransactionsCount, 1)

return
}
}

ctx, cancel := context.WithTimeout(context.Background(), receiptTimeout)
Expand All @@ -386,6 +456,10 @@ func (l *Loadbot) Run() error {

return
}
// initialise block numbers
l.metrics.GasMetrics.BlockGasMutex.Lock()
l.metrics.GasMetrics.Blocks[receipt.BlockNumber] = GasMetrics{}
l.metrics.GasMetrics.BlockGasMutex.Unlock()
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

// Stop the performance timer
end := time.Now()
Expand All @@ -404,6 +478,18 @@ func (l *Loadbot) Run() error {

endTime := time.Now()

// get block gas usage information
for k, v := range l.metrics.GasMetrics.Blocks {
blockInfom, err := jsonClient.Eth().GetBlockByNumber(web3.BlockNumber(k), false)
if err != nil {
log.Fatalln("Could not fetch block by number")
}

v.GasLimit = blockInfom.GasLimit
v.GasUsed = blockInfom.GasUsed
l.metrics.GasMetrics.Blocks[k] = v
}

// Calculate the turn around metrics now that the loadbot is done
l.metrics.TransactionDuration.calcTurnAroundMetrics()
l.metrics.TransactionDuration.TotalExecTime = endTime.Sub(startTime)
Expand Down
Loading