Skip to content

Commit

Permalink
block 1 - all masternodes race to create
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtuna committed Jun 1, 2018
1 parent cfdde43 commit 789e03f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 789e03f

Please sign in to comment.