aboutsummaryrefslogtreecommitdiffstats
path: root/light/lightchain.go
diff options
context:
space:
mode:
Diffstat (limited to 'light/lightchain.go')
-rw-r--r--light/lightchain.go36
1 files changed, 24 insertions, 12 deletions
diff --git a/light/lightchain.go b/light/lightchain.go
index 4c877a771..30baeaccb 100644
--- a/light/lightchain.go
+++ b/light/lightchain.go
@@ -95,15 +95,8 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
if bc.genesisBlock == nil {
return nil, core.ErrNoGenesis
}
- if bc.genesisBlock.Hash() == params.MainnetGenesisHash {
- // add trusted CHT
- WriteTrustedCht(bc.chainDb, TrustedCht{Number: 1040, Root: common.HexToHash("bb4fb4076cbe6923c8a8ce8f158452bbe19564959313466989fda095a60884ca")})
- log.Info("Added trusted CHT for mainnet")
- }
- if bc.genesisBlock.Hash() == params.TestnetGenesisHash {
- // add trusted CHT
- WriteTrustedCht(bc.chainDb, TrustedCht{Number: 400, Root: common.HexToHash("2a4befa19e4675d939c3dc22dca8c6ae9fcd642be1f04b06bd6e4203cc304660")})
- log.Info("Added trusted CHT for ropsten testnet")
+ if cp, ok := trustedCheckpoints[bc.genesisBlock.Hash()]; ok {
+ bc.addTrustedCheckpoint(cp)
}
if err := bc.loadLastState(); err != nil {
@@ -120,6 +113,22 @@ func NewLightChain(odr OdrBackend, config *params.ChainConfig, engine consensus.
return bc, nil
}
+// addTrustedCheckpoint adds a trusted checkpoint to the blockchain
+func (self *LightChain) addTrustedCheckpoint(cp trustedCheckpoint) {
+ if self.odr.ChtIndexer() != nil {
+ StoreChtRoot(self.chainDb, cp.sectionIdx, cp.sectionHead, cp.chtRoot)
+ self.odr.ChtIndexer().AddKnownSectionHead(cp.sectionIdx, cp.sectionHead)
+ }
+ if self.odr.BloomTrieIndexer() != nil {
+ StoreBloomTrieRoot(self.chainDb, cp.sectionIdx, cp.sectionHead, cp.bloomTrieRoot)
+ self.odr.BloomTrieIndexer().AddKnownSectionHead(cp.sectionIdx, cp.sectionHead)
+ }
+ if self.odr.BloomIndexer() != nil {
+ self.odr.BloomIndexer().AddKnownSectionHead(cp.sectionIdx, cp.sectionHead)
+ }
+ log.Info("Added trusted checkpoint", "chain name", cp.name)
+}
+
func (self *LightChain) getProcInterrupt() bool {
return atomic.LoadInt32(&self.procInterrupt) == 1
}
@@ -449,10 +458,13 @@ func (self *LightChain) GetHeaderByNumberOdr(ctx context.Context, number uint64)
}
func (self *LightChain) SyncCht(ctx context.Context) bool {
+ if self.odr.ChtIndexer() == nil {
+ return false
+ }
headNum := self.CurrentHeader().Number.Uint64()
- cht := GetTrustedCht(self.chainDb)
- if headNum+1 < cht.Number*ChtFrequency {
- num := cht.Number*ChtFrequency - 1
+ chtCount, _, _ := self.odr.ChtIndexer().Sections()
+ if headNum+1 < chtCount*ChtFrequency {
+ num := chtCount*ChtFrequency - 1
header, err := GetHeaderByNumber(ctx, self.odr, num)
if header != nil && err == nil {
self.mu.Lock()