diff --git a/core/types/transaction.go b/core/types/transaction.go index 609b83044..cb186a469 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -295,6 +295,8 @@ func (tx *Transaction) RawSignatureValues() (*big.Int, *big.Int, *big.Int) { // Transactions is a Transaction slice type for basic sorting. 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. type RecentTxsStats map[uint64]BlockTxsCounts diff --git a/internal/configs/sharding/fixedschedule.go b/internal/configs/sharding/fixedschedule.go index f308bed67..db7f4057f 100644 --- a/internal/configs/sharding/fixedschedule.go +++ b/internal/configs/sharding/fixedschedule.go @@ -44,15 +44,20 @@ func (s fixedSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { return mainnetMaxNumRecentTxsPerAccountLimit } -func (s fixedSchedule) MaxTxsPerBlockLimit() int { - return mainnetMaxTxsPerBlockLimit +func (s fixedSchedule) MaxTxPoolSizeLimit() int { + return mainnetMaxTxPoolSizeLimit +} + +func (s fixedSchedule) MaxNumTxsPerBlockLimit() int { + return mainnetMaxNumTxsPerBlockLimit } func (s fixedSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ MaxTxAmountLimit: s.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: s.MaxNumRecentTxsPerAccountLimit(), - MaxTxsPerBlockLimit: s.MaxTxsPerBlockLimit(), + MaxTxPoolSizeLimit: s.MaxTxPoolSizeLimit(), + MaxNumTxsPerBlockLimit: s.MaxNumTxsPerBlockLimit(), } } diff --git a/internal/configs/sharding/localnet.go b/internal/configs/sharding/localnet.go index b3db864ce..4416fa674 100644 --- a/internal/configs/sharding/localnet.go +++ b/internal/configs/sharding/localnet.go @@ -22,7 +22,8 @@ const ( localnetMaxTxAmountLimit = 1e2 // unit is in One localnetMaxNumRecentTxsPerAccountLimit = 2 - localnetMaxTxsPerBlockLimit = 8000 + localnetMaxTxPoolSizeLimit = 8000 + localnetMaxNumTxsPerBlockLimit = 1000 ) func (localnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { @@ -72,15 +73,20 @@ func (ls localnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { return localnetMaxNumRecentTxsPerAccountLimit } -func (ls localnetSchedule) MaxTxsPerBlockLimit() int { - return localnetMaxTxsPerBlockLimit +func (ls localnetSchedule) MaxTxPoolSizeLimit() int { + return localnetMaxTxPoolSizeLimit +} + +func (ls localnetSchedule) MaxNumTxsPerBlockLimit() int { + return localnetMaxNumTxsPerBlockLimit } func (ls localnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ MaxTxAmountLimit: ls.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: ls.MaxNumRecentTxsPerAccountLimit(), - MaxTxsPerBlockLimit: ls.MaxTxsPerBlockLimit(), + MaxTxPoolSizeLimit: ls.MaxTxPoolSizeLimit(), + MaxNumTxsPerBlockLimit: ls.MaxNumTxsPerBlockLimit(), } } diff --git a/internal/configs/sharding/mainnet.go b/internal/configs/sharding/mainnet.go index d441b1d52..4c86eac8b 100644 --- a/internal/configs/sharding/mainnet.go +++ b/internal/configs/sharding/mainnet.go @@ -15,7 +15,8 @@ const ( mainnetMaxTxAmountLimit = 1e3 // unit is in One mainnetMaxNumRecentTxsPerAccountLimit = 10 - mainnetMaxTxsPerBlockLimit = 8000 + mainnetMaxTxPoolSizeLimit = 8000 + mainnetMaxNumTxsPerBlockLimit = 1000 ) // MainnetSchedule is the mainnet sharding configuration schedule. @@ -72,15 +73,20 @@ func (ms mainnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { return mainnetMaxNumRecentTxsPerAccountLimit } -func (ms mainnetSchedule) MaxTxsPerBlockLimit() int { - return mainnetMaxTxsPerBlockLimit +func (ms mainnetSchedule) MaxTxPoolSizeLimit() int { + return mainnetMaxTxPoolSizeLimit +} + +func (ms mainnetSchedule) MaxNumTxsPerBlockLimit() int { + return mainnetMaxNumTxsPerBlockLimit } func (ms mainnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ MaxTxAmountLimit: ms.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: ms.MaxNumRecentTxsPerAccountLimit(), - MaxTxsPerBlockLimit: ms.MaxTxsPerBlockLimit(), + MaxTxPoolSizeLimit: ms.MaxTxPoolSizeLimit(), + MaxNumTxsPerBlockLimit: ms.MaxNumTxsPerBlockLimit(), } } diff --git a/internal/configs/sharding/shardingconfig.go b/internal/configs/sharding/shardingconfig.go index 9edbb254b..1b6feb2cf 100644 --- a/internal/configs/sharding/shardingconfig.go +++ b/internal/configs/sharding/shardingconfig.go @@ -28,8 +28,11 @@ type Schedule interface { // Max number of transactions of a particular account per block level MaxNumRecentTxsPerAccountLimit() uint64 - // Max total number of transactions in a block - MaxTxsPerBlockLimit() int + // Max total number of transactions allowed as pending transactions in transaction pool + MaxTxPoolSizeLimit() int + + // Max total number of transactions allowed to be processed per block + MaxNumTxsPerBlockLimit() int // configuration for throttling pending transactions TxsThrottleConfig() *TxsThrottleConfig @@ -92,6 +95,9 @@ type TxsThrottleConfig struct { // Max number of transactions of a particular account for the past hour MaxNumRecentTxsPerAccountLimit uint64 - // Max total number of transactions in a block - MaxTxsPerBlockLimit int + // Max total number of transactions allowed as pending transactions in transaction pool + MaxTxPoolSizeLimit int + + // Max total number of transactions allowed to be processed per block + MaxNumTxsPerBlockLimit int } diff --git a/internal/configs/sharding/testnet.go b/internal/configs/sharding/testnet.go index 1e478e68f..a472bb417 100644 --- a/internal/configs/sharding/testnet.go +++ b/internal/configs/sharding/testnet.go @@ -22,7 +22,8 @@ const ( testnetMaxTxAmountLimit = 1e3 // unit is in One testnetMaxNumRecentTxsPerAccountLimit = 10 - testnetMaxTxsPerBlockLimit = 8000 + testnetMaxTxPoolSizeLimit = 8000 + testnetMaxNumTxsPerBlockLimit = 1000 ) func (testnetSchedule) InstanceForEpoch(epoch *big.Int) Instance { @@ -73,15 +74,20 @@ func (ts testnetSchedule) MaxNumRecentTxsPerAccountLimit() uint64 { return testnetMaxNumRecentTxsPerAccountLimit } -func (ts testnetSchedule) MaxTxsPerBlockLimit() int { - return testnetMaxTxsPerBlockLimit +func (ts testnetSchedule) MaxTxPoolSizeLimit() int { + return testnetMaxTxPoolSizeLimit +} + +func (ts testnetSchedule) MaxNumTxsPerBlockLimit() int { + return testnetMaxNumTxsPerBlockLimit } func (ts testnetSchedule) TxsThrottleConfig() *TxsThrottleConfig { return &TxsThrottleConfig{ MaxTxAmountLimit: ts.MaxTxAmountLimit(), MaxNumRecentTxsPerAccountLimit: ts.MaxNumRecentTxsPerAccountLimit(), - MaxTxsPerBlockLimit: ts.MaxTxsPerBlockLimit(), + MaxTxPoolSizeLimit: ts.MaxTxPoolSizeLimit(), + MaxNumTxsPerBlockLimit: ts.MaxNumTxsPerBlockLimit(), } } diff --git a/node/node.go b/node/node.go index 6fb042c23..32e4df98b 100644 --- a/node/node.go +++ b/node/node.go @@ -226,7 +226,7 @@ func (node *Node) Beaconchain() *core.BlockChain { } func (node *Node) reducePendingTransactions() { - txPoolLimit := core.ShardingSchedule.MaxTxsPerBlockLimit() + txPoolLimit := core.ShardingSchedule.MaxTxPoolSizeLimit() curLen := len(node.pendingTransactions) // If length of pendingTransactions is greater than TxPoolLimit then by greedy take the TxPoolLimit recent transactions. diff --git a/node/worker/worker.go b/node/worker/worker.go index b4f1c1615..76daaf9d6 100644 --- a/node/worker/worker.go +++ b/node/worker/worker.go @@ -66,10 +66,10 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R } // already selected max num txs - if len(selected) > txsThrottleConfig.MaxTxsPerBlockLimit { - utils.GetLogInstance().Info("Throttling tx with max txs per block limit", + if len(selected) > txsThrottleConfig.MaxNumTxsPerBlockLimit { + utils.GetLogInstance().Info("Throttling tx with max num txs per block limit", "tx Id", tx.Hash().Hex(), - "MaxTxsPerBlockLimit", txsThrottleConfig.MaxTxsPerBlockLimit) + "MaxNumTxsPerBlockLimit", txsThrottleConfig.MaxNumTxsPerBlockLimit) return sender, shardingconfig.TxUnselect } @@ -143,7 +143,17 @@ func (w *Worker) SelectTransactionsForNewBlock(newBlockNum uint64, txs types.Tra "Transaction Id", tx.Hash().Hex(), "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 }