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
}
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(),
}
}

@ -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(),
}
}

@ -13,9 +13,9 @@ const (
mainnetV1Epoch = 1
mainnetV2Epoch = 5
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.
@ -68,8 +68,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 {
@ -78,9 +78,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(),
}
}

@ -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

@ -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(),
}
}

@ -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)

@ -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 {

Loading…
Cancel
Save