fix recentTxsCounts map data clean up bug

pull/1319/head
Dennis Won 5 years ago
parent a9b36f3b6e
commit bf07063a2e
  1. 16
      core/types/transaction.go
  2. 20
      node/node.go
  3. 2
      node/worker/worker.go

@ -295,15 +295,6 @@ 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
// BlockTxsCounts is a transactions counts map of
// the number of transactions made by each account in a block on this node.
type BlockTxsCounts map[common.Address]uint64
// Len returns the length of s.
func (s Transactions) Len() int { return len(s) }
@ -494,3 +485,10 @@ func (m Message) Data() []byte {
func (m Message) CheckNonce() bool {
return m.checkNonce
}
// RecentTxsStats is a recent transactions stats map tracking stats like BlockTxsCounts.
type RecentTxsStats map[uint64]BlockTxsCounts
// BlockTxsCounts is a transactions counts map of
// the number of transactions made by each account in a block on this node.
type BlockTxsCounts map[common.Address]uint64

@ -90,9 +90,7 @@ type Node struct {
BlockChannel chan *types.Block // The channel to send newly proposed blocks
ConfirmedBlockChannel chan *types.Block // The channel to send confirmed blocks
BeaconBlockChannel chan *types.Block // The channel to send beacon blocks for non-beaconchain nodes
pendingTransactions types.Transactions // All the transactions received but not yet processed for Consensus
pendingTxMutex sync.Mutex
recentTxsStats types.RecentTxsStats
DRand *drand.DRand // The instance for distributed randomness protocol
// Shard databases
@ -112,7 +110,12 @@ type Node struct {
// BeaconNeighbors store only neighbor nodes in the beacon chain shard
BeaconNeighbors sync.Map // All the neighbor nodes, key is the sha256 of Peer IP/Port, value is the p2p.Peer
TxPool *core.TxPool
TxPool *core.TxPool // TODO migrate to TxPool from pendingTransactions list below
pendingTransactions types.Transactions // All the transactions received but not yet processed for Consensus
pendingTxMutex sync.Mutex
recentTxsStats types.RecentTxsStats
Worker *worker.Worker
BeaconWorker *worker.Worker // worker for beacon chain
@ -256,13 +259,14 @@ func (node *Node) AddPendingTransaction(newTx *types.Transaction) {
func (node *Node) getTransactionsForNewBlock(coinbase common.Address) types.Transactions {
node.pendingTxMutex.Lock()
// update recentTxsStats and initiailize for the new block
// the next block number to be added in consensus protocol, which is always one more than current chain header block
newBlockNum := node.Blockchain().CurrentBlock().NumberU64() + 1
// remove old (currently > 1 hr) blockNum keys from recentTxsStats and initiailize for the new block
for blockNum := range node.recentTxsStats {
blockNumHourAgo := (time.Hour / time.Second) / node.BlockPeriod
if blockNum < node.Consensus.ChainReader.CurrentHeader().Number.Uint64()-uint64(blockNumHourAgo) {
blockNumHourAgo := uint64(time.Hour / node.BlockPeriod)
if blockNumHourAgo < newBlockNum-blockNum {
delete(node.recentTxsStats, blockNum)
}
}

@ -91,7 +91,7 @@ func (w *Worker) throttleTxs(selected types.Transactions, recentTxsStats types.R
utils.GetLogInstance().Info("Throttling tx with max txs per account in a single block limit",
"tx Id", tx.Hash().Hex(),
"MaxNumRecentTxsPerAccountLimit", txsThrottleConfig.MaxNumRecentTxsPerAccountLimit)
return sender, shardingconfig.TxUnselect
return sender, shardingconfig.TxInvalid
}
return sender, shardingconfig.TxSelect

Loading…
Cancel
Save