diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2017-10-24 21:19:09 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-10-24 21:19:09 +0800 |
commit | ca376ead88a5a26626a90abdb62f4de7f6313822 (patch) | |
tree | 71d11e3b6cd40d2bf29033b7e23d30d04e086558 /light/lightchain.go | |
parent | 6d6a5a93370371a33fb815d7ae47b60c7021c86a (diff) | |
download | go-tangerine-ca376ead88a5a26626a90abdb62f4de7f6313822.tar go-tangerine-ca376ead88a5a26626a90abdb62f4de7f6313822.tar.gz go-tangerine-ca376ead88a5a26626a90abdb62f4de7f6313822.tar.bz2 go-tangerine-ca376ead88a5a26626a90abdb62f4de7f6313822.tar.lz go-tangerine-ca376ead88a5a26626a90abdb62f4de7f6313822.tar.xz go-tangerine-ca376ead88a5a26626a90abdb62f4de7f6313822.tar.zst go-tangerine-ca376ead88a5a26626a90abdb62f4de7f6313822.zip |
les, light: LES/2 protocol version (#14970)
This PR implements the new LES protocol version extensions:
* new and more efficient Merkle proofs reply format (when replying to
a multiple Merkle proofs request, we just send a single set of trie
nodes containing all necessary nodes)
* BBT (BloomBitsTrie) works similarly to the existing CHT and contains
the bloombits search data to speed up log searches
* GetTxStatusMsg returns the inclusion position or the
pending/queued/unknown state of a transaction referenced by hash
* an optional signature of new block data (number/hash/td) can be
included in AnnounceMsg to provide an option for "very light
clients" (mobile/embedded devices) to skip expensive Ethash check
and accept multiple signatures of somewhat trusted servers (still a
lot better than trusting a single server completely and retrieving
everything through RPC). The new client mode is not implemented in
this PR, just the protocol extension.
Diffstat (limited to 'light/lightchain.go')
-rw-r--r-- | light/lightchain.go | 36 |
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() |