Renamed the prev MaxNumTxsPerBlockLimit to tx pool size limit and added another config value MaxNumTxsPerBlockLimit separately

pull/1319/head
Dennis Won 5 years ago
parent 24a87fdcc3
commit dffe6652a7
  1. 2
      core/types/transaction.go
  2. 11
      internal/configs/sharding/fixedschedule.go
  3. 14
      internal/configs/sharding/localnet.go
  4. 14
      internal/configs/sharding/mainnet.go
  5. 14
      internal/configs/sharding/shardingconfig.go
  6. 14
      internal/configs/sharding/testnet.go
  7. 2
      node/node.go
  8. 16
      node/worker/worker.go

@ -295,6 +295,8 @@ func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) {
// Transactions is a Transaction slice type for basic sorting. // Transactions is a Transaction slice type for basic sorting.
type Transactions []*Transaction type Transactions []*Transaction
// TODO: put these temp custom txs data structures into other places to keep Transaction type code clean.
// RecentTxsStats is a recent transactions stats map tracking stats like BlockTxsCounts. // RecentTxsStats is a recent transactions stats map tracking stats like BlockTxsCounts.
type RecentTxsStats map[uint64]BlockTxsCounts type RecentTxsStats map[uint64]BlockTxsCounts

@ -44,15 +44,20 @@ func (s fixedSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return mainnetMaxNumRecentTxsPerAccountLimit return mainnetMaxNumRecentTxsPerAccountLimit
} }
func (s fixedSchedule) MaxTxsPerBlockLimit() int { func (s fixedSchedule) MaxTxPoolSizeLimit() int {
return mainnetMaxTxsPerBlockLimit return mainnetMaxTxPoolSizeLimit
}
func (s fixedSchedule) MaxNumTxsPerBlockLimit() int {
return mainnetMaxNumTxsPerBlockLimit
} }
func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: s.MaxTxAmountLimit(), MaxTxAmountLimit: s.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(), MaxTxPoolSizeLimit: s.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: s.MaxNumTxsPerBlockLimit(),
} }
} }

@ -22,7 +22,8 @@ const (
localnetMaxTxAmountLimit = 1e2 // unit is in One localnetMaxTxAmountLimit = 1e2 // unit is in One
localnetMaxNumRecentTxsPerAccountLimit = 2 localnetMaxNumRecentTxsPerAccountLimit = 2
localnetMaxTxsPerBlockLimit = 8000 localnetMaxTxPoolSizeLimit = 8000
localnetMaxNumTxsPerBlockLimit = 1000
) )
func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
@ -72,15 +73,20 @@ func (ls localnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return localnetMaxNumRecentTxsPerAccountLimit return localnetMaxNumRecentTxsPerAccountLimit
} }
func (ls localnetSchedule) MaxTxsPerBlockLimit() int { func (ls localnetSchedule) MaxTxPoolSizeLimit() int {
return localnetMaxTxsPerBlockLimit return localnetMaxTxPoolSizeLimit
}
func (ls localnetSchedule) MaxNumTxsPerBlockLimit() int {
return localnetMaxNumTxsPerBlockLimit
} }
func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: ls.MaxTxAmountLimit(), MaxTxAmountLimit: ls.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(), MaxTxPoolSizeLimit: ls.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: ls.MaxNumTxsPerBlockLimit(),
} }
} }

@ -15,7 +15,8 @@ const (
mainnetMaxTxAmountLimit = 1e3 // unit is in One mainnetMaxTxAmountLimit = 1e3 // unit is in One
mainnetMaxNumRecentTxsPerAccountLimit = 10 mainnetMaxNumRecentTxsPerAccountLimit = 10
mainnetMaxTxsPerBlockLimit = 8000 mainnetMaxTxPoolSizeLimit = 8000
mainnetMaxNumTxsPerBlockLimit = 1000
) )
// MainnetSchedule is the mainnet sharding configuration schedule. // MainnetSchedule is the mainnet sharding configuration schedule.
@ -72,15 +73,20 @@ func (ms mainnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return mainnetMaxNumRecentTxsPerAccountLimit return mainnetMaxNumRecentTxsPerAccountLimit
} }
func (ms mainnetSchedule) MaxTxsPerBlockLimit() int { func (ms mainnetSchedule) MaxTxPoolSizeLimit() int {
return mainnetMaxTxsPerBlockLimit return mainnetMaxTxPoolSizeLimit
}
func (ms mainnetSchedule) MaxNumTxsPerBlockLimit() int {
return mainnetMaxNumTxsPerBlockLimit
} }
func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: ms.MaxTxAmountLimit(), MaxTxAmountLimit: ms.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(), MaxTxPoolSizeLimit: ms.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: ms.MaxNumTxsPerBlockLimit(),
} }
} }

@ -28,8 +28,11 @@ type Schedule interface {
// Max number of transactions of a particular account per block level // Max number of transactions of a particular account per block level
MaxNumRecentTxsPerAccountLimit() uint64 MaxNumRecentTxsPerAccountLimit() uint64
// Max total number of transactions in a block // Max total number of transactions allowed as pending transactions in transaction pool
MaxTxsPerBlockLimit() int MaxTxPoolSizeLimit() int
// Max total number of transactions allowed to be processed per block
MaxNumTxsPerBlockLimit() int
// configuration for throttling pending transactions // configuration for throttling pending transactions
TxsThrottleConfig() *TxsThrottleConfig TxsThrottleConfig() *TxsThrottleConfig
@ -92,6 +95,9 @@ type TxsThrottleConfig struct {
// Max number of transactions of a particular account for the past hour // Max number of transactions of a particular account for the past hour
MaxNumRecentTxsPerAccountLimit uint64 MaxNumRecentTxsPerAccountLimit uint64
// Max total number of transactions in a block // Max total number of transactions allowed as pending transactions in transaction pool
MaxTxsPerBlockLimit int MaxTxPoolSizeLimit int
// Max total number of transactions allowed to be processed per block
MaxNumTxsPerBlockLimit int
} }

@ -22,7 +22,8 @@ const (
testnetMaxTxAmountLimit = 1e3 // unit is in One testnetMaxTxAmountLimit = 1e3 // unit is in One
testnetMaxNumRecentTxsPerAccountLimit = 10 testnetMaxNumRecentTxsPerAccountLimit = 10
testnetMaxTxsPerBlockLimit = 8000 testnetMaxTxPoolSizeLimit = 8000
testnetMaxNumTxsPerBlockLimit = 1000
) )
func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance {
@ -73,15 +74,20 @@ func (ts testnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 {
return testnetMaxNumRecentTxsPerAccountLimit return testnetMaxNumRecentTxsPerAccountLimit
} }
func (ts testnetSchedule) MaxTxsPerBlockLimit() int { func (ts testnetSchedule) MaxTxPoolSizeLimit() int {
return testnetMaxTxsPerBlockLimit return testnetMaxTxPoolSizeLimit
}
func (ts testnetSchedule) MaxNumTxsPerBlockLimit() int {
return testnetMaxNumTxsPerBlockLimit
} }
func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig {
return &TxsThrottleConfig{ return &TxsThrottleConfig{
MaxTxAmountLimit: ts.MaxTxAmountLimit(), MaxTxAmountLimit: ts.MaxTxAmountLimit(),
MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(), MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(),
MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(), MaxTxPoolSizeLimit: ts.MaxTxPoolSizeLimit(),
MaxNumTxsPerBlockLimit: ts.MaxNumTxsPerBlockLimit(),
} }
} }

@ -226,7 +226,7 @@ func (node *Node) Beaconchain() *core.BlockChain {
} }
func (node *Node) reducePendingTransactions() { func (node *Node) reducePendingTransactions() {
txPoolLimit := core.ShardingSchedule.MaxTxsPerBlockLimit() txPoolLimit := core.ShardingSchedule.MaxTxPoolSizeLimit()
curLen := len(node.pendingTransactions) curLen := len(node.pendingTransactions)
// If length of pendingTransactions is greater than TxPoolLimit then by greedy take the TxPoolLimit recent transactions. // If length of pendingTransactions is greater than TxPoolLimit then by greedy take the TxPoolLimit recent transactions.

@ -66,10 +66,10 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R
} }
// already selected max num txs // already selected max num txs
if len(selected) > txsThrottleConfig.MaxTxsPerBlockLimit { if len(selected) > txsThrottleConfig.MaxNumTxsPerBlockLimit {
utils.GetLogInstance().Info("Throttling tx with max txs per block limit", utils.GetLogInstance().Info("Throttling tx with max num txs per block limit",
"tx Id", tx.Hash().Hex(), "tx Id", tx.Hash().Hex(),
"MaxTxsPerBlockLimit", txsThrottleConfig.MaxTxsPerBlockLimit) "MaxNumTxsPerBlockLimit", txsThrottleConfig.MaxNumTxsPerBlockLimit)
return sender, shardingconfig.TxUnselect return sender, shardingconfig.TxUnselect
} }
@ -143,7 +143,17 @@ func (w *Worker) SelectTransactionsForNewBlock(newBlockNum uint64, txs types.Tra
"Transaction Id", tx.Hash().Hex(), "Transaction Id", tx.Hash().Hex(),
"txThrottleFlag", flag.String()) "txThrottleFlag", flag.String())
} }
utils.GetLogInstance().Info("Transaction gas limit info",
"Transaction Id", tx.Hash().Hex(),
"tx gas limit", tx.Gas())
} }
utils.GetLogInstance().Info("Block gas limit and usage info",
"newBlockNum", newBlockNum,
"block gas limit", w.current.header.GasLimit,
"block gas used", w.current.header.GasUsed)
return selected, unselected, invalid return selected, unselected, invalid
} }

Loading…
Cancel
Save