Skip to content

Commit

Permalink
reuse Clique voting strategy for now, leave header.Coinbase empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtuna committed Jun 1, 2018
1 parent 789e03f commit d91e00e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 7 additions & 4 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,15 @@ func position(list []common.Address, x common.Address) int {
return -1
}

func YourTurn(snap *Snapshot, pre, cur common.Address) bool {
func YourTurn(snap *Snapshot, header *types.Header, cur common.Address) (bool, error) {
pre, err := ecrecover(header, snap.sigcache)
if err != nil {
return false, err
}
preIndex := position(snap.signers(), pre)
curIndex := position(snap.signers(), cur)
log.Info("Debugging info", "number of masternodes", len(snap.signers()), "previous", pre, "position", preIndex, "current", cur, "position", curIndex)
return (preIndex+1)%len(snap.signers()) == curIndex || pre.String() == genesisCoinBase
return (preIndex+1)%len(snap.signers()) == curIndex || pre.String() == genesisCoinBase, nil
}

// snapshot retrieves the authorization snapshot at a given point in time.
Expand Down Expand Up @@ -530,8 +534,7 @@ func (c *Clique) verifySeal(chain consensus.ChainReader, header *types.Header, p
// header for running the transactions on top.
func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) error {
// If the block isn't a checkpoint, cast a random vote (good enough for now)
//FIXME: keep header.Coinbase == miner's address
//header.Coinbase = common.Address{}
header.Coinbase = common.Address{}
header.Nonce = types.BlockNonce{}

number := header.Number.Uint64()
Expand Down
8 changes: 7 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
Expand Down Expand Up @@ -408,7 +409,12 @@ func (self *worker) commitNewWork() {
log.Error("Failed when trying to commit new work", "err", err)
return
}
if !clique.YourTurn(snap, parent.Coinbase(), self.coinbase) {
ok, err := clique.YourTurn(snap, parent.Header(), self.coinbase)
if err != nil {
log.Error("Failed when trying to commit new work", "err", err)
return
}
if !ok {
log.Info("Not our turn to commit block. Wait for next time")
return
}
Expand Down

0 comments on commit d91e00e

Please sign in to comment.