forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Adding loadbot ERC20 and ERC721 token transfer modes (0xPol…
…ygon#425) * Added erc20 and erc721 contract bytecode and ABI * Added new flag option for erc20 and erc721 transfers * Added contract deployment metrics to the output * Added support for ERC20 token transfer * Added percentual gas usage metric * Added percentual average blocks utilization metric * Added support for ERC721 token minting * Set http `max-conns` default to very high value * Added `max-wait` flag for custom time to wait for receipts * Increased default max wait time for receipts to 2 min. * Gas metrics (block gas usage) are now calculated async Co-authored-by: dbrajovic <dbrajovic3@gmail.com>
- Loading branch information
1 parent
3543e50
commit f59d3ca
Showing
18 changed files
with
1,345 additions
and
95 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package loadbot | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/0xPolygon/polygon-edge/command/loadbot/generator" | ||
"github.com/0xPolygon/polygon-edge/helper/tests" | ||
txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto" | ||
"github.com/0xPolygon/polygon-edge/types" | ||
|
||
"github.com/umbracle/go-web3/jsonrpc" | ||
) | ||
|
||
func (l *Loadbot) deployContract( | ||
grpcClient txpoolOp.TxnPoolOperatorClient, | ||
jsonClient *jsonrpc.Client, | ||
receiptTimeout time.Duration) error { | ||
start := time.Now() | ||
|
||
_, ok := l.generator.(generator.ContractTxnGenerator) | ||
if !ok { | ||
return fmt.Errorf("invalid generator type, it needs to be a generator.ContractTxnGenerator interface") | ||
} | ||
|
||
// deploy SC | ||
txHash, err := l.executeTxn(grpcClient) | ||
if err != nil { | ||
//nolint:forcetypeassert | ||
l.generator.(generator.ContractTxnGenerator).MarkFailedContractTxn(&generator.FailedContractTxnInfo{ | ||
TxHash: txHash.String(), | ||
Error: &generator.TxnError{ | ||
Error: err, | ||
ErrorType: generator.AddErrorType, | ||
}, | ||
}) | ||
atomic.AddUint64(&l.metrics.ContractMetrics.FailedContractTransactionsCount, 1) | ||
|
||
return fmt.Errorf("could not execute transaction, %w", err) | ||
} | ||
|
||
// set timeout | ||
ctx, cancel := context.WithTimeout(context.Background(), receiptTimeout) | ||
defer cancel() | ||
|
||
// and wait for receipt | ||
receipt, err := tests.WaitForReceipt(ctx, jsonClient.Eth(), txHash) | ||
|
||
if err != nil { | ||
//nolint:forcetypeassert | ||
l.generator.(generator.ContractTxnGenerator).MarkFailedContractTxn(&generator.FailedContractTxnInfo{ | ||
TxHash: txHash.String(), | ||
Error: &generator.TxnError{ | ||
Error: err, | ||
ErrorType: generator.ReceiptErrorType, | ||
}, | ||
}) | ||
atomic.AddUint64(&l.metrics.ContractMetrics.FailedContractTransactionsCount, 1) | ||
|
||
return fmt.Errorf("could not get the receipt, %w", err) | ||
} | ||
|
||
end := time.Now() | ||
// initialize gas metrics map with block nuber as index | ||
l.metrics.ContractMetrics.ContractGasMetrics.Blocks[receipt.BlockNumber] = GasMetrics{} | ||
// fetch contract address | ||
l.metrics.ContractMetrics.ContractAddress = receipt.ContractAddress | ||
// set contract address in order to get new example txn and gas estimate | ||
//nolint:forcetypeassert | ||
l.generator.(generator.ContractTxnGenerator).SetContractAddress(types.StringToAddress( | ||
receipt.ContractAddress.String(), | ||
)) | ||
|
||
// we're done with SC deployment | ||
// we defined SC address and | ||
// now get new gas estimates for CS token transfers | ||
if err := l.updateGasEstimate(jsonClient); err != nil { | ||
return fmt.Errorf("unable to get gas estimate, %w", err) | ||
} | ||
|
||
// record contract deployment metrics | ||
l.metrics.ContractMetrics.ContractDeploymentDuration.reportTurnAroundTime( | ||
txHash, | ||
&metadata{ | ||
turnAroundTime: end.Sub(start), | ||
blockNumber: receipt.BlockNumber, | ||
}, | ||
) | ||
// calculate contract deployment metrics | ||
if err := l.calculateGasMetrics(jsonClient, l.metrics.ContractMetrics.ContractGasMetrics); err != nil { | ||
return fmt.Errorf("unable to calculate contract block gas metrics: %w", err) | ||
} | ||
|
||
l.metrics.ContractMetrics.ContractDeploymentDuration.calcTurnAroundMetrics() | ||
l.metrics.ContractMetrics.ContractDeploymentDuration.TotalExecTime = end.Sub(start) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.