les: implement ultralight client (#16904)

For more information about this light client mode, read
https://hackmd.io/s/HJy7jjZpm
This commit is contained in:
b00ris
2019-01-24 14:18:26 +03:00
committed by Felix Lange
parent b8f9b3779f
commit 769657060e
23 changed files with 1288 additions and 179 deletions

View File

@ -70,6 +70,8 @@ type LightChain struct {
wg sync.WaitGroup
engine consensus.Engine
disableCheckFreq bool
}
// NewLightChain returns a fully initialised light chain using information
@ -354,6 +356,9 @@ func (self *LightChain) postChainEvents(events []interface{}) {
// In the case of a light chain, InsertHeaderChain also creates and posts light
// chain events when necessary.
func (self *LightChain) InsertHeaderChain(chain []*types.Header, checkFreq int) (int, error) {
if self.disableCheckFreq {
checkFreq = 0
}
start := time.Now()
if i, err := self.hc.ValidateHeaderChain(chain, checkFreq); err != nil {
return i, err
@ -526,3 +531,17 @@ func (self *LightChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscri
func (self *LightChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription {
return self.scope.Track(new(event.Feed).Subscribe(ch))
}
//DisableCheckFreq disables header validation. It needs for ULC
func (self *LightChain) DisableCheckFreq() {
self.mu.Lock()
defer self.mu.Unlock()
self.disableCheckFreq = true
}
//EnableCheckFreq enables header validation
func (self *LightChain) EnableCheckFreq() {
self.mu.Lock()
defer self.mu.Unlock()
self.disableCheckFreq = false
}