Skip to content

Commit

Permalink
Merge pull request ethereum#14 from bas-vk/votenonce
Browse files Browse the repository at this point in the history
quorum: retrieve nonce from txpool instead of pending state
  • Loading branch information
patrickmn authored Nov 18, 2016
2 parents a961389 + 9653112 commit 116bb45
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
24 changes: 16 additions & 8 deletions core/quorum/block_voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,19 @@ func (bv *BlockVoting) run(strat BlockMakerStrategy) {
case core.TxPreEvent: // tx entered pool, apply to pending state
bv.applyTransaction(e.Tx)
case Vote:
txHash, err := bv.vote(e.Number, e.Hash)
if err == nil && e.TxHash != nil {
e.TxHash <- txHash
} else if err != nil && e.Err != nil {
e.Err <- err
} else if err != nil {
if glog.V(logger.Debug) {
glog.Errorf("Unable to vote: %v", err)
if bv.synced {
txHash, err := bv.vote(e.Number, e.Hash)
if err == nil && e.TxHash != nil {
e.TxHash <- txHash
} else if err != nil && e.Err != nil {
e.Err <- err
} else if err != nil {
if glog.V(logger.Debug) {
glog.Errorf("Unable to vote: %v", err)
}
}
} else {
e.Err <- fmt.Errorf("Node not synced")
}
case CreateBlock:
block, err := bv.createBlock()
Expand Down Expand Up @@ -367,6 +371,10 @@ func (bv *BlockVoting) vote(height *big.Int, hash common.Hash) (common.Hash, err
glog.Infof("vote for %s on height %d", hash.Hex(), height)
}

nonce := bv.txpool.Nonce(bv.voteSession.TransactOpts.From)
bv.voteSession.TransactOpts.Nonce = new(big.Int).SetUint64(nonce)
defer func() { bv.voteSession.TransactOpts.Nonce = nil }()

tx, err := bv.voteSession.Vote(height, hash)
if err != nil {
return common.Hash{}, err
Expand Down
11 changes: 11 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ func (pool *TxPool) eventLoop() {
}
}

// Nonce returns the nonce for the given addr from the pending state.
// Can only be used for local transactions.
func (pool *TxPool) Nonce(addr common.Address) uint64 {
pool.mu.Lock()
defer pool.mu.Unlock()
if pool.pendingState == nil {
pool.resetState()
}
return pool.pendingState.GetNonce(addr)
}

func (pool *TxPool) resetState() {
currentState, _, err := pool.currentState()
if err != nil {
Expand Down

0 comments on commit 116bb45

Please sign in to comment.