From 2fb2d7404d645c6789dfba65dae0adc752930011 Mon Sep 17 00:00:00 2001 From: AnilChinchawale Date: Tue, 10 Jul 2018 16:20:55 +0530 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 08189b0c93..e29dcefdec 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 bb7cb25d05..9117adb3c8 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 } }