github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/les/bloombits.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:38</date> 10 //</624450093260476416> 11 12 13 package les 14 15 import ( 16 "time" 17 18 "github.com/ethereum/go-ethereum/common/bitutil" 19 "github.com/ethereum/go-ethereum/light" 20 ) 21 22 const ( 23 //BloomServiceThreads是以太坊全局使用的Goroutine数。 24 //实例到服务BloomBits查找所有正在运行的筛选器。 25 bloomServiceThreads = 16 26 27 //BloomFilterThreads是每个筛选器本地使用的goroutine数,用于 28 //将请求多路传输到全局服务goroutine。 29 bloomFilterThreads = 3 30 31 //BloomRetrievalBatch是要服务的最大Bloom位检索数。 32 //一批。 33 bloomRetrievalBatch = 16 34 35 //BloomRetrievalWait是等待足够的Bloom位请求的最长时间。 36 //累积请求整个批(避免滞后)。 37 bloomRetrievalWait = time.Microsecond * 100 38 ) 39 40 //StartBloomHandlers启动一批Goroutine以接受BloomBit数据库 41 //从可能的一系列过滤器中检索并为数据提供满足条件的服务。 42 func (eth *LightEthereum) startBloomHandlers(sectionSize uint64) { 43 for i := 0; i < bloomServiceThreads; i++ { 44 go func() { 45 for { 46 select { 47 case <-eth.shutdownChan: 48 return 49 50 case request := <-eth.bloomRequests: 51 task := <-request 52 task.Bitsets = make([][]byte, len(task.Sections)) 53 compVectors, err := light.GetBloomBits(task.Context, eth.odr, task.Bit, task.Sections) 54 if err == nil { 55 for i := range task.Sections { 56 if blob, err := bitutil.DecompressBytes(compVectors[i], int(sectionSize/8)); err == nil { 57 task.Bitsets[i] = blob 58 } else { 59 task.Error = err 60 } 61 } 62 } else { 63 task.Error = err 64 } 65 request <- task 66 } 67 } 68 }() 69 } 70 } 71