Merge pull request #17466 from karalabe/rinkeby-light-snapshots
consensus/clique, light: light client snapshots on Rinkeby
This commit is contained in:
commit
1dcad8b2de
@ -387,23 +387,24 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we're at block zero, make a snapshot
|
// If we're at an checkpoint block, make a snapshot if it's known
|
||||||
if number == 0 {
|
if number%c.config.Epoch == 0 {
|
||||||
genesis := chain.GetHeaderByNumber(0)
|
checkpoint := chain.GetHeaderByNumber(number)
|
||||||
if err := c.VerifyHeader(chain, genesis, false); err != nil {
|
if checkpoint != nil {
|
||||||
return nil, err
|
hash := checkpoint.Hash()
|
||||||
}
|
|
||||||
signers := make([]common.Address, (len(genesis.Extra)-extraVanity-extraSeal)/common.AddressLength)
|
signers := make([]common.Address, (len(checkpoint.Extra)-extraVanity-extraSeal)/common.AddressLength)
|
||||||
for i := 0; i < len(signers); i++ {
|
for i := 0; i < len(signers); i++ {
|
||||||
copy(signers[i][:], genesis.Extra[extraVanity+i*common.AddressLength:])
|
copy(signers[i][:], checkpoint.Extra[extraVanity+i*common.AddressLength:])
|
||||||
}
|
}
|
||||||
snap = newSnapshot(c.config, c.signatures, 0, genesis.Hash(), signers)
|
snap = newSnapshot(c.config, c.signatures, number, hash, signers)
|
||||||
if err := snap.store(c.db); err != nil {
|
if err := snap.store(c.db); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Trace("Stored genesis voting snapshot to disk")
|
log.Info("Stored checkpoint snapshot to disk", "number", number, "hash", hash)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// No snapshot for this header, gather the header and move backward
|
// No snapshot for this header, gather the header and move backward
|
||||||
var header *types.Header
|
var header *types.Header
|
||||||
if len(parents) > 0 {
|
if len(parents) > 0 {
|
||||||
|
@ -84,7 +84,7 @@ func (r *testerChainReader) GetHeaderByNumber(number uint64) *types.Header {
|
|||||||
if number == 0 {
|
if number == 0 {
|
||||||
return rawdb.ReadHeader(r.db, rawdb.ReadCanonicalHash(r.db, 0), 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.
|
// Tests that voting is evaluated correctly for various simple and complex scenarios.
|
||||||
|
@ -464,23 +464,33 @@ func (self *LightChain) GetHeaderByNumberOdr(ctx context.Context, number uint64)
|
|||||||
func (self *LightChain) Config() *params.ChainConfig { return self.hc.Config() }
|
func (self *LightChain) Config() *params.ChainConfig { return self.hc.Config() }
|
||||||
|
|
||||||
func (self *LightChain) SyncCht(ctx context.Context) bool {
|
func (self *LightChain) SyncCht(ctx context.Context) bool {
|
||||||
|
// If we don't have a CHT indexer, abort
|
||||||
if self.odr.ChtIndexer() == nil {
|
if self.odr.ChtIndexer() == nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
headNum := self.CurrentHeader().Number.Uint64()
|
// Ensure the remote CHT head is ahead of us
|
||||||
chtCount, _, _ := self.odr.ChtIndexer().Sections()
|
head := self.CurrentHeader().Number.Uint64()
|
||||||
if headNum+1 < chtCount*CHTFrequencyClient {
|
sections, _, _ := self.odr.ChtIndexer().Sections()
|
||||||
num := chtCount*CHTFrequencyClient - 1
|
|
||||||
header, err := GetHeaderByNumber(ctx, self.odr, num)
|
latest := sections*CHTFrequencyClient - 1
|
||||||
if header != nil && err == nil {
|
if clique := self.hc.Config().Clique; clique != nil {
|
||||||
|
latest -= latest % clique.Epoch // epoch snapshot for clique
|
||||||
|
}
|
||||||
|
if head >= latest {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// Retrieve the latest useful header and update to it
|
||||||
|
if header, err := GetHeaderByNumber(ctx, self.odr, latest); header != nil && err == nil {
|
||||||
self.mu.Lock()
|
self.mu.Lock()
|
||||||
|
defer self.mu.Unlock()
|
||||||
|
|
||||||
|
// Ensure the chain didn't move past the latest block while retrieving it
|
||||||
if self.hc.CurrentHeader().Number.Uint64() < header.Number.Uint64() {
|
if self.hc.CurrentHeader().Number.Uint64() < header.Number.Uint64() {
|
||||||
|
log.Info("Updated latest header based on CHT", "number", header.Number, "hash", header.Hash())
|
||||||
self.hc.SetCurrentHeader(header)
|
self.hc.SetCurrentHeader(header)
|
||||||
}
|
}
|
||||||
self.mu.Unlock()
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,28 +58,29 @@ type TrustedCheckpoint struct {
|
|||||||
SectionHead, CHTRoot, BloomRoot common.Hash
|
SectionHead, CHTRoot, BloomRoot common.Hash
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
// trustedCheckpoints associates each known checkpoint with the genesis hash of the chain it belongs to
|
||||||
mainnetCheckpoint = TrustedCheckpoint{
|
var trustedCheckpoints = map[common.Hash]TrustedCheckpoint{
|
||||||
|
params.MainnetGenesisHash: {
|
||||||
name: "mainnet",
|
name: "mainnet",
|
||||||
SectionIdx: 187,
|
SectionIdx: 187,
|
||||||
SectionHead: common.HexToHash("e6baa034efa31562d71ff23676512dec6562c1ad0301e08843b907e81958c696"),
|
SectionHead: common.HexToHash("e6baa034efa31562d71ff23676512dec6562c1ad0301e08843b907e81958c696"),
|
||||||
CHTRoot: common.HexToHash("28001955219719cf06de1b08648969139d123a9835fc760547a1e4dabdabc15a"),
|
CHTRoot: common.HexToHash("28001955219719cf06de1b08648969139d123a9835fc760547a1e4dabdabc15a"),
|
||||||
BloomRoot: common.HexToHash("395ca2373fc662720ac6b58b3bbe71f68aa0f38b63b2d3553dd32ff3c51eebc4"),
|
BloomRoot: common.HexToHash("395ca2373fc662720ac6b58b3bbe71f68aa0f38b63b2d3553dd32ff3c51eebc4"),
|
||||||
}
|
},
|
||||||
|
params.TestnetGenesisHash: {
|
||||||
ropstenCheckpoint = TrustedCheckpoint{
|
|
||||||
name: "ropsten",
|
name: "ropsten",
|
||||||
SectionIdx: 117,
|
SectionIdx: 117,
|
||||||
SectionHead: common.HexToHash("9529b38631ae30783f56cbe4c3b9f07575b770ecba4f6e20a274b1e2f40fede1"),
|
SectionHead: common.HexToHash("9529b38631ae30783f56cbe4c3b9f07575b770ecba4f6e20a274b1e2f40fede1"),
|
||||||
CHTRoot: common.HexToHash("6f48e9f101f1fac98e7d74fbbcc4fda138358271ffd974d40d2506f0308bb363"),
|
CHTRoot: common.HexToHash("6f48e9f101f1fac98e7d74fbbcc4fda138358271ffd974d40d2506f0308bb363"),
|
||||||
BloomRoot: common.HexToHash("8242342e66e942c0cd893484e6736b9862ceb88b43ca344bb06a8285ac1b6d64"),
|
BloomRoot: common.HexToHash("8242342e66e942c0cd893484e6736b9862ceb88b43ca344bb06a8285ac1b6d64"),
|
||||||
}
|
},
|
||||||
)
|
params.RinkebyGenesisHash: {
|
||||||
|
name: "rinkeby",
|
||||||
// trustedCheckpoints associates each known checkpoint with the genesis hash of the chain it belongs to
|
SectionIdx: 85,
|
||||||
var trustedCheckpoints = map[common.Hash]TrustedCheckpoint{
|
SectionHead: common.HexToHash("92cfa67afc4ad8ab0dcbc6fa49efd14b5b19402442e7317e6bc879d85f89d64d"),
|
||||||
params.MainnetGenesisHash: mainnetCheckpoint,
|
CHTRoot: common.HexToHash("2802ec92cd7a54a75bca96afdc666ae7b99e5d96cf8192dcfb09588812f51564"),
|
||||||
params.TestnetGenesisHash: ropstenCheckpoint,
|
BloomRoot: common.HexToHash("ebefeb31a9a42866d8cf2d2477704b4c3d7c20d0e4e9b5aaa77f396e016a1263"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
|
MainnetGenesisHash = common.HexToHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
|
||||||
TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
|
TestnetGenesisHash = common.HexToHash("0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d")
|
||||||
|
RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user