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 | |
parent | 355fc47d396298bccf93c37bdbba9b9e88864790 (diff) | |
download | go-tangerine-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar go-tangerine-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar.gz go-tangerine-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar.bz2 go-tangerine-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar.lz go-tangerine-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar.xz go-tangerine-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.tar.zst go-tangerine-9f036647e4b3e7c3aa8941dc239f85326a5e5ecd.zip |
consensus/clique, light: light client snapshots on Rinkeby
Diffstat (limited to 'consensus')
-rw-r--r-- | consensus/clique/clique.go | 31 | ||||
-rw-r--r-- | consensus/clique/snapshot_test.go | 2 |
2 files changed, 17 insertions, 16 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 diff --git a/consensus/clique/snapshot_test.go b/consensus/clique/snapshot_test.go index 5ac730c9e..17719884f 100644 --- a/consensus/clique/snapshot_test.go +++ b/consensus/clique/snapshot_test.go @@ -84,7 +84,7 @@ func (r *testerChainReader) GetHeaderByNumber(number uint64) *types.Header { if number == 0 { return rawdb.ReadHeader(r.db, rawdb.ReadCanonicalHash(r.db, 0), 0) } - panic("not supported") + return nil } // Tests that voting is evaluated correctly for various simple and complex scenarios. |