diff --git a/cmd/client/wallet_stress_test/main.go b/cmd/client/wallet_stress_test/main.go index df6bdb9bd..027da9c50 100644 --- a/cmd/client/wallet_stress_test/main.go +++ b/cmd/client/wallet_stress_test/main.go @@ -242,7 +242,7 @@ func processStressTestCommand() { var receiverState *AccountState var retry uint32 - for i := 0; i < 10; i++ { + for i := 0; ; i++ { for retry = 0; retry < 10; retry++ { shardIDToAccountStateSender = FetchBalance(senderAddress) shardIDToAccountStateReceiver = FetchBalance(receiverAddress) @@ -268,11 +268,16 @@ func processStressTestCommand() { receiverBalance := receiverState.balance // amount 1/10th of the balance - amountBigInt := senderBalance.Div(senderBalance, big.NewInt(10)) + amountBigInt := senderBalance.Div(senderBalance, big.NewInt(1)) fmt.Printf("\nsender: balance (shard %d: %s, nonce: %v)\n", shardID, convertBalanceIntoReadableFormat(senderBalance), senderState.nonce) fmt.Printf("receiver balance (shard %d: %s, nonce: %v)\n", shardID, convertBalanceIntoReadableFormat(receiverBalance), receiverState.nonce) + // stop stress testing here after printing out the final balance + if i == 10 { + break + } + tx := types.NewTransaction( senderState.nonce, receiverAddress, uint32(shardID), amountBigInt, gasLimit, gasPriceBigInt, data) diff --git a/core/types/transaction.go b/core/types/transaction.go index 6657b5342..6311b07a2 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -19,6 +19,7 @@ package types import ( "container/heap" "errors" + "fmt" "io" "math/big" "sync/atomic" @@ -27,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rlp" + common2 "github.com/harmony-one/harmony/internal/common" ) // no go:generate gencodec -type txdata -field-override txdataMarshaling -out gen_tx_json.go @@ -489,6 +491,26 @@ func (m Message) CheckNonce() bool { // RecentTxsStats is a recent transactions stats map tracking stats like BlockTxsCounts. type RecentTxsStats map[uint64]BlockTxsCounts +// String returns the string formatted representation of RecentTxsStats +func (rts RecentTxsStats) String() string { + ret := "{ " + for blockNum, blockTxsCounts := range rts { + ret += fmt.Sprintf("blockNum:%d=%s", blockNum, blockTxsCounts.String()) + } + ret += " }" + return ret +} + // BlockTxsCounts is a transactions counts map of // the number of transactions made by each account in a block on this node. type BlockTxsCounts map[common.Address]uint64 + +// String returns the string formatted representation of BlockTxsCounts +func (btc BlockTxsCounts) String() string { + ret := "{ " + for sender, numTxs := range btc { + ret += fmt.Sprintf("%s:%d,", common2.MustAddressToBech32(sender), numTxs) + } + ret += " }" + return ret +} diff --git a/node/node.go b/node/node.go index 76e2d7d43..0c5c3f5e0 100644 --- a/node/node.go +++ b/node/node.go @@ -265,10 +265,9 @@ func (node *Node) getTransactionsForNewBlock(coinbase common.Address) types.Tran newBlockNum := node.Blockchain().CurrentBlock().NumberU64() + 1 // remove old (> txsThrottleConfigRecentTxDuration) blockNum keys from recentTxsStats and initiailize for the new block + recentTxsBlockNumGap := uint64(txsThrottleConfig.RecentTxDuration / node.BlockPeriod) for blockNum := range node.recentTxsStats { - blockNumHourAgo := uint64(txsThrottleConfig.RecentTxDuration / node.BlockPeriod) - - if blockNumHourAgo < newBlockNum-blockNum { + if recentTxsBlockNumGap < newBlockNum-blockNum { delete(node.recentTxsStats, blockNum) } } diff --git a/node/worker/worker.go b/node/worker/worker.go index c56b99a33..7f6716f1c 100644 --- a/node/worker/worker.go +++ b/node/worker/worker.go @@ -69,7 +69,7 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R utils.GetLogInstance().Info("Throttling tx with max amount limit", "tx Id", tx.Hash().Hex(), "MaxTxAmountLimit", txsThrottleConfig.MaxTxAmountLimit.Uint64(), - "Tx amount", tx.Value().Uint64()) + "Tx amount", tx.Value()) return sender, shardingconfig.TxInvalid }