|
|
@ -90,9 +90,7 @@ type Node struct { |
|
|
|
BlockChannel chan *types.Block // The channel to send newly proposed blocks
|
|
|
|
BlockChannel chan *types.Block // The channel to send newly proposed blocks
|
|
|
|
ConfirmedBlockChannel chan *types.Block // The channel to send confirmed 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
|
|
|
|
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
|
|
|
|
DRand *drand.DRand // The instance for distributed randomness protocol
|
|
|
|
|
|
|
|
|
|
|
|
// Shard databases
|
|
|
|
// Shard databases
|
|
|
@ -112,7 +110,12 @@ type Node struct { |
|
|
|
// BeaconNeighbors store only neighbor nodes in the beacon chain shard
|
|
|
|
// 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
|
|
|
|
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 |
|
|
|
Worker *worker.Worker |
|
|
|
BeaconWorker *worker.Worker // worker for beacon chain
|
|
|
|
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 { |
|
|
|
func (node *Node) getTransactionsForNewBlock(coinbase common.Address) types.Transactions { |
|
|
|
node.pendingTxMutex.Lock() |
|
|
|
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
|
|
|
|
// 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 |
|
|
|
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 { |
|
|
|
for blockNum := range node.recentTxsStats { |
|
|
|
blockNumHourAgo := (time.Hour / time.Second) / node.BlockPeriod |
|
|
|
blockNumHourAgo := uint64(time.Hour / node.BlockPeriod) |
|
|
|
if blockNum < node.Consensus.ChainReader.CurrentHeader().Number.Uint64()-uint64(blockNumHourAgo) { |
|
|
|
|
|
|
|
|
|
|
|
if blockNumHourAgo < newBlockNum-blockNum { |
|
|
|
delete(node.recentTxsStats, blockNum) |
|
|
|
delete(node.recentTxsStats, blockNum) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|