github.com/MetalBlockchain/subnet-evm@v0.4.9/eth/bloombits.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. 2 // 3 // This file is a derived work, based on the go-ethereum library whose original 4 // notices appear below. 5 // 6 // It is distributed under a license compatible with the licensing terms of the 7 // original code from which it is derived. 8 // 9 // Much love to the original authors for their work. 10 // ********** 11 // Copyright 2017 The go-ethereum Authors 12 // This file is part of the go-ethereum library. 13 // 14 // The go-ethereum library is free software: you can redistribute it and/or modify 15 // it under the terms of the GNU Lesser General Public License as published by 16 // the Free Software Foundation, either version 3 of the License, or 17 // (at your option) any later version. 18 // 19 // The go-ethereum library is distributed in the hope that it will be useful, 20 // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 // GNU Lesser General Public License for more details. 23 // 24 // You should have received a copy of the GNU Lesser General Public License 25 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 26 27 package eth 28 29 import ( 30 "time" 31 32 "github.com/MetalBlockchain/subnet-evm/core/rawdb" 33 "github.com/ethereum/go-ethereum/common/bitutil" 34 ) 35 36 const ( 37 // bloomServiceThreads is the number of goroutines used globally by an Ethereum 38 // instance to service bloombits lookups for all running filters. 39 bloomServiceThreads = 16 40 41 // bloomFilterThreads is the number of goroutines used locally per filter to 42 // multiplex requests onto the global servicing goroutines. 43 bloomFilterThreads = 3 44 45 // bloomRetrievalBatch is the maximum number of bloom bit retrievals to service 46 // in a single batch. 47 bloomRetrievalBatch = 16 48 49 // bloomRetrievalWait is the maximum time to wait for enough bloom bit requests 50 // to accumulate request an entire batch (avoiding hysteresis). 51 bloomRetrievalWait = time.Duration(0) 52 ) 53 54 // startBloomHandlers starts a batch of goroutines to accept bloom bit database 55 // retrievals from possibly a range of filters and serving the data to satisfy. 56 func (eth *Ethereum) startBloomHandlers(sectionSize uint64) { 57 for i := 0; i < bloomServiceThreads; i++ { 58 go func() { 59 for { 60 select { 61 case <-eth.closeBloomHandler: 62 return 63 64 case request := <-eth.bloomRequests: 65 task := <-request 66 task.Bitsets = make([][]byte, len(task.Sections)) 67 for i, section := range task.Sections { 68 head := rawdb.ReadCanonicalHash(eth.chainDb, (section+1)*sectionSize-1) 69 if compVector, err := rawdb.ReadBloomBits(eth.chainDb, task.Bit, section, head); err == nil { 70 if blob, err := bitutil.DecompressBytes(compVector, int(sectionSize/8)); err == nil { 71 task.Bitsets[i] = blob 72 } else { 73 task.Error = err 74 } 75 } else { 76 task.Error = err 77 } 78 } 79 request <- task 80 } 81 } 82 }() 83 } 84 }