mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 14:14:30 +00:00
reuse Clique voting strategy for now, leave header.Coinbase empty
This commit is contained in:
parent
2fb2d7404d
commit
1e59069d3a
2 changed files with 14 additions and 5 deletions
|
|
@ -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.
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue