From 789e03f167e08a75596a4361ec23c982b64b5f3e Mon Sep 17 00:00:00 2001 From: Tuna Date: Wed, 30 May 2018 14:52:15 +0700 Subject: [PATCH] block 1 - all masternodes race to create --- consensus/clique/clique.go | 11 ++++++++--- miner/worker.go | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 69176ac2ff..d845734f17 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -47,7 +47,8 @@ const ( inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory inmemorySignatures = 4096 // Number of recent block signatures to keep in memory - wiggleTime = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers + wiggleTime = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers + genesisCoinBase = "0x0000000000000000000000000000000000000000" ) // Clique proof-of-authority protocol constants. @@ -384,7 +385,10 @@ func position(list []common.Address, x common.Address) int { } func YourTurn(snap *Snapshot, pre, cur common.Address) bool { - return (position(snap.signers(), pre)+1) % len(snap.signers()) == position(snap.signers(), cur) + 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 } // snapshot retrieves the authorization snapshot at a given point in time. @@ -526,7 +530,8 @@ 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) - header.Coinbase = common.Address{} + //FIXME: keep header.Coinbase == miner's address + //header.Coinbase = common.Address{} header.Nonce = types.BlockNonce{} number := header.Number.Uint64() diff --git a/miner/worker.go b/miner/worker.go index 40d2b63dad..4f27e6d3ce 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -409,7 +409,7 @@ func (self *worker) commitNewWork() { return } if !clique.YourTurn(snap, parent.Coinbase(), self.coinbase) { - log.Info("Not our turn to commit block", "wait", nil) + log.Info("Not our turn to commit block. Wait for next time") return } }