Skip to content

Commit

Permalink
Merge pull request #17 from jpmorganchase/nonce
Browse files Browse the repository at this point in the history
core/quorum: check if transaction was already applied
  • Loading branch information
patrickmn committed Nov 21, 2016
2 parents c6c4f91 + 269a7ee commit 6ce6123
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/quorum/block_maker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type pendingState struct {
gp *core.GasPool
ownedAccounts *set.Set
txs types.Transactions // set of transactions
txsHashes *set.Set
lowGasTxs types.Transactions
failedTxs types.Transactions
parent *types.Block
Expand Down Expand Up @@ -55,6 +56,7 @@ func (ps *pendingState) applyTransaction(tx *types.Transaction, bc *core.BlockCh
return err, nil
}
ps.txs = append(ps.txs, tx)
ps.txsHashes.Add(tx.Hash())
ps.receipts = append(ps.receipts, receipt)

return nil, logs
Expand All @@ -73,6 +75,11 @@ func (ps *pendingState) applyTransactions(txs *types.TransactionsByPriorityAndNo
if tx == nil {
break
}

if ps.txsHashes.Has(tx.Hash()) {
continue
}

// Error may be ignored here. The error has already been checked
// during transaction acceptance is the transaction pool.
from, _ := tx.From()
Expand Down
3 changes: 3 additions & 0 deletions core/quorum/block_voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func (bv *BlockVoting) resetPendingState(parent *types.Block) {
header: bv.makeHeader(parent),
gp: new(core.GasPool),
ownedAccounts: accountAddressesSet(bv.am.Accounts()),
txsHashes: set.New(),
}

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

ch, err := bv.canonHash(bv.pState.header.Number.Uint64())
if err != nil {
bv.resetPendingState(bv.bc.CurrentFastBlock())
return nil, err
}
if ch != bv.pState.parent.Hash() {
bv.resetPendingState(bv.bc.CurrentFastBlock())
return nil, fmt.Errorf("invalid canonical hash, expected %s got %s", ch.Hex(), bv.pState.header.Hash().Hex())
}

Expand Down

0 comments on commit 6ce6123

Please sign in to comment.