Merge pull request #17 from jpmorganchase/nonce

core/quorum: check if transaction was already applied
This commit is contained in:
Patrick Mylund Nielsen 2016-11-21 11:41:28 -05:00 committed by GitHub
commit 6ce61232f9
2 changed files with 10 additions and 0 deletions

View File

@ -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
@ -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
@ -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()

View File

@ -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)
@ -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())
}