mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +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
|
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)
|
preIndex := position(snap.signers(), pre)
|
||||||
curIndex := position(snap.signers(), cur)
|
curIndex := position(snap.signers(), cur)
|
||||||
log.Info("Debugging info", "number of masternodes", len(snap.signers()), "previous", pre, "position", preIndex, "current", cur, "position", curIndex)
|
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.
|
// 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.
|
// header for running the transactions on top.
|
||||||
func (c *Clique) Prepare(chain consensus.ChainReader, header *types.Header) error {
|
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)
|
// 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{}
|
header.Nonce = types.BlockNonce{}
|
||||||
|
|
||||||
number := header.Number.Uint64()
|
number := header.Number.Uint64()
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"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/consensus/misc"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"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)
|
log.Error("Failed when trying to commit new work", "err", err)
|
||||||
return
|
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")
|
log.Info("Not our turn to commit block. Wait for next time")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue