diff --git a/core/quorum/block_voting.go b/core/quorum/block_voting.go index badd637e1..ea30c467b 100755 --- a/core/quorum/block_voting.go +++ b/core/quorum/block_voting.go @@ -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() @@ -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 diff --git a/core/tx_pool.go b/core/tx_pool.go index 2535609c7..b294b0e28 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -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 {