rename tx throttline configuration key name to localnetMaxNumRecentTxsPerAccountLimit

pull/1319/head
Dennis Won 5 years ago
parent 987306a9f8
commit dae2e393c9
  1. 10
      internal/configs/sharding/fixedschedule.go
  2. 16
      internal/configs/sharding/localnet.go
  3. 16
      internal/configs/sharding/mainnet.go
  4. 4
      internal/configs/sharding/shardingconfig.go
  5. 16
      internal/configs/sharding/testnet.go
  6. 2
      node/node.go
  7. 18
      node/worker/worker.go

@ -40,8 +40,8 @@ func (s fixedSchedule) MaxTxAmountLimit() *big.Int {
return amountBigInt return amountBigInt
} }
func (s fixedSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { func (s fixedSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return mainnetMaxNumTxsPerAccountPastHourLimit return mainnetMaxNumRecentTxsPerAccountLimit
} }
func (s fixedSchedule) MaxTxsPerBlockLimit() int { func (s fixedSchedule) MaxTxsPerBlockLimit() int {
@ -50,9 +50,9 @@ func (s fixedSchedule) MaxTxsPerBlockLimit() int {
func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: s.MaxTxAmountLimit(), MaxTxAmountLimit: s.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: s.MaxNumTxsPerAccountPastHourLimit(), MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(),
} }
} }

@ -20,9 +20,9 @@ const (
localnetEpochBlock1 = 20 localnetEpochBlock1 = 20
twoOne = 5 twoOne = 5
localnetMaxTxAmountLimit = 1e2 // unit is in One localnetMaxTxAmountLimit = 1e2 // unit is in One
localnetMaxNumTxsPerAccountPastHourLimit = 2 localnetMaxNumRecentTxsPerAccountLimit = 2
localnetMaxTxsPerBlockLimit = 8000 localnetMaxTxsPerBlockLimit = 8000
) )
func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
@ -68,8 +68,8 @@ func (ls localnetSchedule) MaxTxAmountLimit() *big.Int {
return amountBigInt return amountBigInt
} }
func (ls localnetSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { func (ls localnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return localnetMaxNumTxsPerAccountPastHourLimit return localnetMaxNumRecentTxsPerAccountLimit
} }
func (ls localnetSchedule) MaxTxsPerBlockLimit() int { func (ls localnetSchedule) MaxTxsPerBlockLimit() int {
@ -78,9 +78,9 @@ func (ls localnetSchedule) MaxTxsPerBlockLimit() int {
func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: ls.MaxTxAmountLimit(), MaxTxAmountLimit: ls.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: ls.MaxNumTxsPerAccountPastHourLimit(), MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(),
} }
} }

@ -13,9 +13,9 @@ const (
mainnetV1Epoch = 1 mainnetV1Epoch = 1
mainnetV2Epoch = 5 mainnetV2Epoch = 5
mainnetMaxTxAmountLimit = 1e3 // unit is in One mainnetMaxTxAmountLimit = 1e3 // unit is in One
mainnetMaxNumTxsPerAccountPastHourLimit = 10 mainnetMaxNumRecentTxsPerAccountLimit = 10
mainnetMaxTxsPerBlockLimit = 8000 mainnetMaxTxsPerBlockLimit = 8000
) )
// MainnetSchedule is the mainnet sharding configuration schedule. // MainnetSchedule is the mainnet sharding configuration schedule.
@ -68,8 +68,8 @@ func (ms mainnetSchedule) MaxTxAmountLimit() *big.Int {
return amountBigInt return amountBigInt
} }
func (ms mainnetSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { func (ms mainnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return mainnetMaxNumTxsPerAccountPastHourLimit return mainnetMaxNumRecentTxsPerAccountLimit
} }
func (ms mainnetSchedule) MaxTxsPerBlockLimit() int { func (ms mainnetSchedule) MaxTxsPerBlockLimit() int {
@ -78,9 +78,9 @@ func (ms mainnetSchedule) MaxTxsPerBlockLimit() int {
func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: ms.MaxTxAmountLimit(), MaxTxAmountLimit: ms.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: ms.MaxNumTxsPerAccountPastHourLimit(), MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(),
} }
} }

@ -26,7 +26,7 @@ type Schedule interface {
MaxTxAmountLimit() *big.Int MaxTxAmountLimit() *big.Int
// Max number of transactions of a particular account per block level // Max number of transactions of a particular account per block level
MaxNumTxsPerAccountPastHourLimit() uint64 MaxNumRecentTxsPerAccountLimit() uint64
// Max total number of transactions in a block // Max total number of transactions in a block
MaxTxsPerBlockLimit() int MaxTxsPerBlockLimit() int
@ -88,7 +88,7 @@ type TxsThrottleConfig struct {
MaxTxAmountLimit *big.Int MaxTxAmountLimit *big.Int
// Max number of transactions of a particular account for the past hour // Max number of transactions of a particular account for the past hour
MaxNumTxsPerAccountPastHourLimit uint64 MaxNumRecentTxsPerAccountLimit uint64
// Max total number of transactions in a block // Max total number of transactions in a block
MaxTxsPerBlockLimit int MaxTxsPerBlockLimit int

@ -20,9 +20,9 @@ const (
testnetEpochBlock1 = 78 testnetEpochBlock1 = 78
threeOne = 111 threeOne = 111
testnetMaxTxAmountLimit = 1e3 // unit is in One testnetMaxTxAmountLimit = 1e3 // unit is in One
testnetMaxNumTxsPerAccountPastHourLimit = 10 testnetMaxNumRecentTxsPerAccountLimit = 10
testnetMaxTxsPerBlockLimit = 8000 testnetMaxTxsPerBlockLimit = 8000
) )
func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
@ -69,8 +69,8 @@ func (ts testnetSchedule) MaxTxAmountLimit() *big.Int {
return amountBigInt return amountBigInt
} }
func (ts testnetSchedule) MaxNumTxsPerAccountPastHourLimit() uint64 { func (ts testnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return testnetMaxNumTxsPerAccountPastHourLimit return testnetMaxNumRecentTxsPerAccountLimit
} }
func (ts testnetSchedule) MaxTxsPerBlockLimit() int { func (ts testnetSchedule) MaxTxsPerBlockLimit() int {
@ -79,9 +79,9 @@ func (ts testnetSchedule) MaxTxsPerBlockLimit() int {
func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: ts.MaxTxAmountLimit(), MaxTxAmountLimit: ts.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: ts.MaxNumTxsPerAccountPastHourLimit(), MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(), MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(),
} }
} }

@ -344,8 +344,6 @@ func New(host p2p.Host, consensusObj *consensus.Consensus, chainDBFactory shardc
node.ConfirmedBlockChannel = make(chan *types.Block) node.ConfirmedBlockChannel = make(chan *types.Block)
node.BeaconBlockChannel = 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.TxPool = core.NewTxPool(core.DefaultTxPoolConfig, node.Blockchain().Config(), chain)
node.Worker = worker.New(node.Blockchain().Config(), chain, node.Consensus, node.Consensus.ShardID) node.Worker = worker.New(node.Blockchain().Config(), chain, node.Consensus, node.Consensus.ShardID)

@ -69,7 +69,7 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R
utils.Logger().Debug(). utils.Logger().Debug().
Int("MaxTxsPerBlockLimit", (*txsThrottleConfig).MaxTxsPerBlockLimit). Int("MaxTxsPerBlockLimit", (*txsThrottleConfig).MaxTxsPerBlockLimit).
Msg("Throttling tx with max txs per block limit") 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 // 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("MaxTxAmountLimit", (*txsThrottleConfig).MaxTxAmountLimit.Uint64()).
Uint64("Tx amount", tx.Value().Uint64()). Uint64("Tx amount", tx.Value().Uint64()).
Msg("Throttling tx with max amount limit") Msg("Throttling tx with max amount limit")
return sender, shardingconfig.Invalid return sender, shardingconfig.TxInvalid
} }
// throttle too large transaction // throttle too large transaction
@ -86,14 +86,14 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R
for _, blockTxsCounts := range recentTxsStats { for _, blockTxsCounts := range recentTxsStats {
numTxsPastHour += blockTxsCounts[sender] numTxsPastHour += blockTxsCounts[sender]
} }
if numTxsPastHour >= (*txsThrottleConfig).MaxNumTxsPerAccountPastHourLimit { if numTxsPastHour >= (*txsThrottleConfig).MaxNumRecentTxsPerAccountLimit {
utils.Logger().Debug(). utils.Logger().Debug().
Uint64("MaxNumTxsPerAccountPastHourLimit", (*txsThrottleConfig).MaxNumTxsPerAccountPastHourLimit). Uint64("MaxNumRecentTxsPerAccountLimit", (*txsThrottleConfig).MaxNumRecentTxsPerAccountLimit).
Msg("Throttling tx with max txs per account in a single block limit") 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. // 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) sender, flag := w.throttleTxs(selected, recentTxsStats, txsThrottleConfig, tx)
switch flag { switch flag {
case shardingconfig.Unselect: case shardingconfig.TxUnselect:
unselected = append(unselected, tx) unselected = append(unselected, tx)
utils.Logger().Info(). utils.Logger().Info().
Str("Transaction Id", tx.Hash().Hex()). Str("Transaction Id", tx.Hash().Hex()).
Str("txThrottleFlag", flag.String()). Str("txThrottleFlag", flag.String()).
Msg("Transaction Throttle flag") Msg("Transaction Throttle flag")
case shardingconfig.Invalid: case shardingconfig.TxInvalid:
invalid = append(invalid, tx) invalid = append(invalid, tx)
utils.Logger().Info(). utils.Logger().Info().
Str("txThrottleFlag", flag.String()). Str("txThrottleFlag", flag.String()).
Str("Transaction Id", tx.Hash().Hex()). Str("Transaction Id", tx.Hash().Hex()).
Msg("Transaction Throttle flag") Msg("Transaction Throttle flag")
case shardingconfig.Select: case shardingconfig.TxSelect:
snap := w.current.state.Snapshot() snap := w.current.state.Snapshot()
_, err := w.commitTransaction(tx, coinbase) _, err := w.commitTransaction(tx, coinbase)
if err != nil { if err != nil {

Loading…
Cancel
Save