From bc027c4fc0bd89f8c787d1eabb9067e5a04219f8 Mon Sep 17 00:00:00 2001 From: Rahulraj04 Date: Sat, 17 Nov 2018 12:34:24 +0530 Subject: [PATCH] check nonce special transaction before promote --- core/blockchain.go | 2 +- core/tx_pool.go | 17 ++--------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 679d2f3a1d..2559930fb4 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1348,7 +1348,7 @@ func (bc *BlockChain) getResultBlock(block *types.Block, verifiedM2 bool) (*Resu return nil, err } proctime := time.Since(bstart) - log.Debug("Caculate new block", "number", block.Number(), "hash", block.Hash(), "uncles", len(block.Uncles()), + log.Debug("Calculate new block", "number", block.Number(), "hash", block.Hash(), "uncles", len(block.Uncles()), "txs", len(block.Transactions()), "gas", block.GasUsed(), "elapsed", common.PrettyDuration(time.Since(bstart)), "process", process) return &ResultProcessBlock{receipts: receipts, logs: logs, state: state, proctime: proctime, usedGas: usedGas}, nil } diff --git a/core/tx_pool.go b/core/tx_pool.go index 09335e87ef..d4a89a7837 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -647,7 +647,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (bool, error) { return false, err } from, _ := types.Sender(pool.signer, tx) // already validated - if tx.IsSpecialTransaction() && pool.IsMasterNode != nil && pool.IsMasterNode(from) { + if tx.IsSpecialTransaction() && pool.IsMasterNode != nil && pool.IsMasterNode(from) && pool.pendingState.GetNonce(from) == tx.Nonce() { return pool.promoteSpecialTx(from, tx) } // If the transaction pool is full, discard underpriced transactions @@ -813,20 +813,7 @@ func (pool *TxPool) promoteSpecialTx(addr common.Address, tx *types.Transaction) // Set the potentially new pending nonce and notify any subsystems of the new tx pool.beats[addr] = time.Now() pool.pendingState.SetNonce(addr, tx.Nonce()+1) - broadcastTxs := types.Transactions{} - for i := tx.Nonce() - 1; i > 0; i-- { - before := list.txs.Get(i) - if before == nil || before.IsSpecialTransaction() { - break - } - broadcastTxs = append(broadcastTxs, before) - } - broadcastTxs = append(broadcastTxs, tx) - go func() { - for _, btx := range broadcastTxs { - pool.txFeed.Send(TxPreEvent{btx}) - } - }() + go pool.txFeed.Send(TxPreEvent{tx}) return true, nil }