diff options
author | Péter Szilágyi <peterke@gmail.com> | 2018-08-21 19:39:28 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-08-21 20:21:59 +0800 |
commit | 9f036647e4b3e7c3aa8941dc239f85326a5e5ecd (patch) | |
tree | 4a9062b5300e326ad773c0dc010f7d7606480eaa /consensus/clique/clique.go | |
parent | 355fc47d396298bccf93c37bdbba9b9e88864790 (diff) | |
download | dexon-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar.gz dexon-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar.zst dexon-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.zip |
consensus/clique, light: light client snapshots on Rinkeby
Diffstat (limited to 'consensus/clique/clique.go')
-rw-r--r-- | consensus/clique/clique.go | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 59bb3d40b..085944701 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -387,22 +387,23 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo break } } - // If we're at block zero, make a snapshot - if number == 0 { - genesis := chain.GetHeaderByNumber(0) - if err := c.VerifyHeader(chain, genesis, false); err != nil { - return nil, err - } - signers := make([]common.Address, (len(genesis.Extra)-extraVanity-extraSeal)/common.AddressLength) - for i := 0; i < len(signers); i++ { - copy(signers[i][:], genesis.Extra[extraVanity+i*common.AddressLength:]) - } - snap = newSnapshot(c.config, c.signatures, 0, genesis.Hash(), signers) - if err := snap.store(c.db); err != nil { - return nil, err + // If we're at an checkpoint block, make a snapshot if it's known + if number%c.config.Epoch == 0 { + checkpoint := chain.GetHeaderByNumber(number) + if checkpoint != nil { + hash := checkpoint.Hash() + + signers := make([]common.Address, (len(checkpoint.Extra)-extraVanity-extraSeal)/common.AddressLength) + for i := 0; i < len(signers); i++ { + copy(signers[i][:], checkpoint.Extra[extraVanity+i*common.AddressLength:]) + } + snap = newSnapshot(c.config, c.signatures, number, hash, signers) + if err := snap.store(c.db); err != nil { + return nil, err + } + log.Info("Stored checkpoint snapshot to disk", "number", number, "hash", hash) + break } - log.Trace("Stored genesis voting snapshot to disk") - break } // No snapshot for this header, gather the header and move backward var header *types.Header |