Skip to content

Commit 6ce6123

Browse files
authored
Merge pull request #17 from jpmorganchase/nonce
core/quorum: check if transaction was already applied
2 parents c6c4f91 + 269a7ee commit 6ce6123

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

core/quorum/block_maker.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type pendingState struct {
2626
gp *core.GasPool
2727
ownedAccounts *set.Set
2828
txs types.Transactions // set of transactions
29+
txsHashes *set.Set
2930
lowGasTxs types.Transactions
3031
failedTxs types.Transactions
3132
parent *types.Block
@@ -55,6 +56,7 @@ func (ps *pendingState) applyTransaction(tx *types.Transaction, bc *core.BlockCh
5556
return err, nil
5657
}
5758
ps.txs = append(ps.txs, tx)
59+
ps.txsHashes.Add(tx.Hash())
5860
ps.receipts = append(ps.receipts, receipt)
5961

6062
return nil, logs
@@ -73,6 +75,11 @@ func (ps *pendingState) applyTransactions(txs *types.TransactionsByPriorityAndNo
7375
if tx == nil {
7476
break
7577
}
78+
79+
if ps.txsHashes.Has(tx.Hash()) {
80+
continue
81+
}
82+
7683
// Error may be ignored here. The error has already been checked
7784
// during transaction acceptance is the transaction pool.
7885
from, _ := tx.From()

core/quorum/block_voting.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func (bv *BlockVoting) resetPendingState(parent *types.Block) {
110110
header: bv.makeHeader(parent),
111111
gp: new(core.GasPool),
112112
ownedAccounts: accountAddressesSet(bv.am.Accounts()),
113+
txsHashes: set.New(),
113114
}
114115

115116
ps.gp.AddGas(ps.header.GasLimit)
@@ -310,9 +311,11 @@ func (bv *BlockVoting) createBlock() (*types.Block, error) {
310311

311312
ch, err := bv.canonHash(bv.pState.header.Number.Uint64())
312313
if err != nil {
314+
bv.resetPendingState(bv.bc.CurrentFastBlock())
313315
return nil, err
314316
}
315317
if ch != bv.pState.parent.Hash() {
318+
bv.resetPendingState(bv.bc.CurrentFastBlock())
316319
return nil, fmt.Errorf("invalid canonical hash, expected %s got %s", ch.Hex(), bv.pState.header.Hash().Hex())
317320
}
318321

0 commit comments

Comments
 (0)