rename tx throttline configuration key name to localnetMaxNumRecentTxsPerAccountLimit

pull/1319/head
Dennis Won 5 years ago
parent df2f2eb3c9
commit df7bb99d46
  1. 6
      internal/configs/sharding/fixedschedule.go
  2. 8
      internal/configs/sharding/localnet.go
  3. 8
      internal/configs/sharding/mainnet.go
  4. 4
      internal/configs/sharding/shardingconfig.go
  5. 8
      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 {
@ -51,7 +51,7 @@ func (s fixedSchedule) MaxTxsPerBlockLimit() int {
func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: s.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: s.MaxNumTxsPerAccountPastHourLimit(),
MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(),
}
}

@ -21,7 +21,7 @@ const (
twoOne = 5
localnetMaxTxAmountLimit = 1e2 // unit is in One
localnetMaxNumTxsPerAccountPastHourLimit = 2
localnetMaxNumRecentTxsPerAccountLimit = 2
localnetMaxTxsPerBlockLimit = 8000
)
@ -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 {
@ -79,7 +79,7 @@ func (ls localnetSchedule) MaxTxsPerBlockLimit() int {
func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: ls.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: ls.MaxNumTxsPerAccountPastHourLimit(),
MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(),
}
}

@ -17,7 +17,7 @@ const (
mainnetV0_4Epoch = 10
mainnetMaxTxAmountLimit = 1e3 // unit is in One
mainnetMaxNumTxsPerAccountPastHourLimit = 10
mainnetMaxNumRecentTxsPerAccountLimit = 10
mainnetMaxTxsPerBlockLimit = 8000
)
@ -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 {
@ -88,7 +88,7 @@ func (ms mainnetSchedule) MaxTxsPerBlockLimit() int {
func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: ms.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: ms.MaxNumTxsPerAccountPastHourLimit(),
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

@ -21,7 +21,7 @@ const (
threeOne = 111
testnetMaxTxAmountLimit = 1e3 // unit is in One
testnetMaxNumTxsPerAccountPastHourLimit = 10
testnetMaxNumRecentTxsPerAccountLimit = 10
testnetMaxTxsPerBlockLimit = 8000
)
@ -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 {
@ -80,7 +80,7 @@ func (ts testnetSchedule) MaxTxsPerBlockLimit() int {
func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{
MaxTxAmountLimit: ts.MaxTxAmountLimit(),
MaxNumTxsPerAccountPastHourLimit: ts.MaxNumTxsPerAccountPastHourLimit(),
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