From df7bb99d4679f74de3b6bf4e55936d9ad9d6f191 Mon Sep 17 00:00:00 2001 From: Dennis Won Date: Fri, 9 Aug 2019 08:52:09 -0700 Subject: [PATCH] rename tx throttline configuration key name to localnetMaxNumRecentTxsPerAccountLimit --- internal/configs/sharding/fixedschedule.go | 10 +++++----- internal/configs/sharding/localnet.go | 16 ++++++++-------- internal/configs/sharding/mainnet.go | 16 ++++++++-------- internal/configs/sharding/shardingconfig.go | 4 ++-- internal/configs/sharding/testnet.go | 16 ++++++++-------- node/node.go | 2 -- node/worker/worker.go | 18 +++++++++--------- 7 files changed, 40 insertions(+), 42 deletions(-) diff --git a/internal/configs/sharding/fixedschedule.go b/internal/configs/sharding/fixedschedule.go index da63e28b3..3e9d426d0 100644 --- a/internal/configs/sharding/fixedschedule.go +++ b/internal/configs/sharding/fixedschedule.go @@ -40,8 +40,8 @@ func (s fixedSchedule) MaxTxAmountLimit() *big.Int { return amountBigInt } -func (s fixedSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { - return mainnetMaxNumTxsPerAccountPastHourLimit +func (s fixedSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { + return mainnetMaxNumRecentTxsPerAccountLimit } func (s fixedSchedule) MaxTxsPerBlockLimit() int { @@ -50,9 +50,9 @@ func (s fixedSchedule) MaxTxsPerBlockLimit() int { func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountLimit: s.MaxTxAmountLimit(), - MaxNumTxsPerAccountPastHourLimit: s.MaxNumTxsPerAccountPastHourLimit(), - MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(), + MaxTxAmountLimit: s.MaxTxAmountLimit(), + MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(), + MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(), } } diff --git a/internal/configs/sharding/localnet.go b/internal/configs/sharding/localnet.go index 967ea70b1..524866b1f 100644 --- a/internal/configs/sharding/localnet.go +++ b/internal/configs/sharding/localnet.go @@ -20,9 +20,9 @@ const ( localnetEpochBlock1 = 20 twoOne = 5 - localnetMaxTxAmountLimit = 1e2 // unit is in One - localnetMaxNumTxsPerAccountPastHourLimit = 2 - localnetMaxTxsPerBlockLimit = 8000 + localnetMaxTxAmountLimit = 1e2 // unit is in One + localnetMaxNumRecentTxsPerAccountLimit = 2 + localnetMaxTxsPerBlockLimit = 8000 ) func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { @@ -68,8 +68,8 @@ func (ls localnetSchedule) MaxTxAmountLimit() *big.Int { return amountBigInt } -func (ls localnetSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { - return localnetMaxNumTxsPerAccountPastHourLimit +func (ls localnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { + return localnetMaxNumRecentTxsPerAccountLimit } func (ls localnetSchedule) MaxTxsPerBlockLimit() int { @@ -78,9 +78,9 @@ func (ls localnetSchedule) MaxTxsPerBlockLimit() int { func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountLimit: ls.MaxTxAmountLimit(), - MaxNumTxsPerAccountPastHourLimit: ls.MaxNumTxsPerAccountPastHourLimit(), - MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(), + MaxTxAmountLimit: ls.MaxTxAmountLimit(), + MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(), + MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(), } } diff --git a/internal/configs/sharding/mainnet.go b/internal/configs/sharding/mainnet.go index 07767006b..be67807c7 100644 --- a/internal/configs/sharding/mainnet.go +++ b/internal/configs/sharding/mainnet.go @@ -16,9 +16,9 @@ const ( mainnetV0_3Epoch = 8 mainnetV0_4Epoch = 10 - mainnetMaxTxAmountLimit = 1e3 // unit is in One - mainnetMaxNumTxsPerAccountPastHourLimit = 10 - mainnetMaxTxsPerBlockLimit = 8000 + mainnetMaxTxAmountLimit = 1e3 // unit is in One + mainnetMaxNumRecentTxsPerAccountLimit = 10 + mainnetMaxTxsPerBlockLimit = 8000 ) // MainnetSchedule is the mainnet sharding configuration schedule. @@ -77,8 +77,8 @@ func (ms mainnetSchedule) MaxTxAmountLimit() *big.Int { return amountBigInt } -func (ms mainnetSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { - return mainnetMaxNumTxsPerAccountPastHourLimit +func (ms mainnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { + return mainnetMaxNumRecentTxsPerAccountLimit } func (ms mainnetSchedule) MaxTxsPerBlockLimit() int { @@ -87,9 +87,9 @@ func (ms mainnetSchedule) MaxTxsPerBlockLimit() int { func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountLimit: ms.MaxTxAmountLimit(), - MaxNumTxsPerAccountPastHourLimit: ms.MaxNumTxsPerAccountPastHourLimit(), - MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(), + MaxTxAmountLimit: ms.MaxTxAmountLimit(), + MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(), + MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(), } } diff --git a/internal/configs/sharding/shardingconfig.go b/internal/configs/sharding/shardingconfig.go index cbc8cb05f..11fa24f7b 100644 --- a/internal/configs/sharding/shardingconfig.go +++ b/internal/configs/sharding/shardingconfig.go @@ -26,7 +26,7 @@ type Schedule interface { MaxTxAmountLimit() *big.Int // Max number of transactions of a particular account per block level - MaxNumTxsPerAccountPastHourLimit() uint64 + MaxNumRecentTxsPerAccountLimit() uint64 // Max total number of transactions in a block MaxTxsPerBlockLimit() int @@ -88,7 +88,7 @@ type TxsThrottleConfig struct { MaxTxAmountLimit *big.Int // Max number of transactions of a particular account for the past hour - MaxNumTxsPerAccountPastHourLimit uint64 + MaxNumRecentTxsPerAccountLimit uint64 // Max total number of transactions in a block MaxTxsPerBlockLimit int diff --git a/internal/configs/sharding/testnet.go b/internal/configs/sharding/testnet.go index 80b37c14f..5cc544aa5 100644 --- a/internal/configs/sharding/testnet.go +++ b/internal/configs/sharding/testnet.go @@ -20,9 +20,9 @@ const ( testnetEpochBlock1 = 78 threeOne = 111 - testnetMaxTxAmountLimit = 1e3 // unit is in One - testnetMaxNumTxsPerAccountPastHourLimit = 10 - testnetMaxTxsPerBlockLimit = 8000 + testnetMaxTxAmountLimit = 1e3 // unit is in One + testnetMaxNumRecentTxsPerAccountLimit = 10 + testnetMaxTxsPerBlockLimit = 8000 ) func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { @@ -69,8 +69,8 @@ func (ts testnetSchedule) MaxTxAmountLimit() *big.Int { return amountBigInt } -func (ts testnetSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { - return testnetMaxNumTxsPerAccountPastHourLimit +func (ts testnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { + return testnetMaxNumRecentTxsPerAccountLimit } func (ts testnetSchedule) MaxTxsPerBlockLimit() int { @@ -79,9 +79,9 @@ func (ts testnetSchedule) MaxTxsPerBlockLimit() int { func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ - MaxTxAmountLimit: ts.MaxTxAmountLimit(), - MaxNumTxsPerAccountPastHourLimit: ts.MaxNumTxsPerAccountPastHourLimit(), - MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(), + MaxTxAmountLimit: ts.MaxTxAmountLimit(), + MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(), + MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(), } } diff --git a/node/node.go b/node/node.go index 1c8b2df35..79b6c69d9 100644 --- a/node/node.go +++ b/node/node.go @@ -344,8 +344,6 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardc node.ConfirmedBlockChannel = make(chan *types.Block) node.BeaconBlockChannel = make(chan *types.Block) - node.recentTxsStats = make(types.RecentTxsStats) - node.TxPool = core.NewTxPool(core.DefaultTxPoolConfig, node.Blockchain().Config(), chain) node.Worker = worker.New(node.Blockchain().Config(), chain, node.Consensus, node.Consensus.ShardID) diff --git a/node/worker/worker.go b/node/worker/worker.go index d3c6ab9bc..9c735eb9e 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.Logger().Debug(). Int("MaxTxsPerBlockLimit", (*txsThrottleConfig).MaxTxsPerBlockLimit). Msg("Throttling tx with max txs per block limit") - return sender, shardingconfig.Unselect + return sender, shardingconfig.TxUnselect } // throttle a single sender sending too many transactions in one block @@ -78,7 +78,7 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R Uint64("MaxTxAmountLimit", (*txsThrottleConfig).MaxTxAmountLimit.Uint64()). Uint64("Tx amount", tx.Value().Uint64()). Msg("Throttling tx with max amount limit") - return sender, shardingconfig.Invalid + return sender, shardingconfig.TxInvalid } // throttle too large transaction @@ -86,14 +86,14 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R for _, blockTxsCounts := range recentTxsStats { numTxsPastHour += blockTxsCounts[sender] } - if numTxsPastHour >= (*txsThrottleConfig).MaxNumTxsPerAccountPastHourLimit { + if numTxsPastHour >= (*txsThrottleConfig).MaxNumRecentTxsPerAccountLimit { utils.Logger().Debug(). - Uint64("MaxNumTxsPerAccountPastHourLimit", (*txsThrottleConfig).MaxNumTxsPerAccountPastHourLimit). + Uint64("MaxNumRecentTxsPerAccountLimit", (*txsThrottleConfig).MaxNumRecentTxsPerAccountLimit). Msg("Throttling tx with max txs per account in a single block limit") - return sender, shardingconfig.Unselect + return sender, shardingconfig.TxUnselect } - return sender, shardingconfig.Select + return sender, shardingconfig.TxSelect } // SelectTransactionsForNewBlock selects transactions for new block. @@ -112,21 +112,21 @@ func (w *Worker) SelectTransactionsForNewBlock(newBlockNum uint64, txs types.Tra sender, flag := w.throttleTxs(selected, recentTxsStats, txsThrottleConfig, tx) switch flag { - case shardingconfig.Unselect: + case shardingconfig.TxUnselect: unselected = append(unselected, tx) utils.Logger().Info(). Str("Transaction Id", tx.Hash().Hex()). Str("txThrottleFlag", flag.String()). Msg("Transaction Throttle flag") - case shardingconfig.Invalid: + case shardingconfig.TxInvalid: invalid = append(invalid, tx) utils.Logger().Info(). Str("txThrottleFlag", flag.String()). Str("Transaction Id", tx.Hash().Hex()). Msg("Transaction Throttle flag") - case shardingconfig.Select: + case shardingconfig.TxSelect: snap := w.current.state.Snapshot() _, err := w.commitTransaction(tx, coinbase) if err != nil {