From 75d729efde85e743a324fa36f723abd34df75f3e Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 16 Aug 2018 11:17:30 +0700 Subject: [PATCH] gofmt, bypass signed recently for epoch block --- consensus/clique/clique.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 97c66dc9b9..0a653c8531 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -397,9 +397,9 @@ func (c *Clique) GetMasternodes(chain consensus.ChainReader, header *types.Heade n := header.Number.Uint64() e := c.config.Epoch switch { - case n % e == 0: + case n%e == 0: return c.GetMasternodesFromCheckpointHeader(header, n, e) - case n % e != 0: + case n%e != 0: h := chain.GetHeaderByNumber(n - (n % e)) return c.GetMasternodesFromCheckpointHeader(h, n, e) default: @@ -450,7 +450,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo } // If an on-disk checkpoint snapshot can be found, use that // checkpoint snapshot = checkpoint - gap - if (number + c.config.Gap)%c.config.Epoch == 0 { + if (number+c.config.Gap)%c.config.Epoch == 0 { if s, err := loadSnapshot(c.config, c.signatures, c.db, hash); err == nil { log.Trace("Loaded voting snapshot form disk", "number", number, "hash", hash) snap = s @@ -504,7 +504,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo c.recents.Add(snap.Hash, snap) // If we've generated a new checkpoint snapshot, save to disk - if (snap.Number + c.config.Gap)%c.config.Epoch == 0 { + if (snap.Number+c.config.Gap)%c.config.Epoch == 0 { if err = snap.store(c.db); err != nil { return nil, err } @@ -575,7 +575,10 @@ func (c *Clique) verifySeal(chain consensus.ChainReader, header *types.Header, p if recent == signer { // Signer is among recents, only fail if the current block doesn't shift it out if limit := uint64(len(masternodes)/2 + 1); seen > number-limit { - return errUnauthorized + // Only take into account the non-epoch blocks + if number%c.config.Epoch != 0 { + return errUnauthorized + } } } } @@ -752,10 +755,13 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch if recent == signer { // Signer is among recents, only wait if the current block doesn't shift it out if limit := uint64(len(masternodes)/2 + 1); number < limit || seen > number-limit { - log.Info("Debugging", "len(masternodes)", len(masternodes), "number", number, "limit", limit, "seen", seen, "recent", recent.String(), "snap.Recents", snap.Recents) - log.Info("Signed recently, must wait for others") - <-stop - return nil, nil + // Only take into account the non-epoch blocks + if number%c.config.Epoch != 0 { + log.Info("Debugging", "len(masternodes)", len(masternodes), "number", number, "limit", limit, "seen", seen, "recent", recent.String(), "snap.Recents", snap.Recents) + log.Info("Signed recently, must wait for others") + <-stop + return nil, nil + } } } }