From 4ea4d2dc3473afd9d2eda6ef6b359accce1f0946 Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Fri, 18 Aug 2017 21:52:20 +0200 Subject: core, eth: add bloombit indexer, filter based on it --- eth/api_backend.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'eth/api_backend.go') diff --git a/eth/api_backend.go b/eth/api_backend.go index 19ef79f23..fa3cf3f80 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -28,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth/downloader" + "github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" @@ -194,3 +195,29 @@ func (b *EthApiBackend) EventMux() *event.TypeMux { func (b *EthApiBackend) AccountManager() *accounts.Manager { return b.eth.AccountManager() } + +func (b *EthApiBackend) GetBloomBits(ctx context.Context, bitIdx uint64, sectionIdxList []uint64) ([][]byte, error) { + results := make([][]byte, len(sectionIdxList)) + var err error + for i, sectionIdx := range sectionIdxList { + sectionHead := core.GetCanonicalHash(b.eth.chainDb, (sectionIdx+1)*bloomBitsSection-1) + results[i], err = core.GetBloomBits(b.eth.chainDb, bitIdx, sectionIdx, sectionHead) + if err != nil { + return nil, err + } + } + return results, nil +} + +func (b *EthApiBackend) BloomBitsSections() uint64 { + sections, _, _ := b.eth.bbIndexer.Sections() + return sections +} + +func (b *EthApiBackend) BloomBitsConfig() filters.BloomConfig { + return filters.BloomConfig{ + SectionSize: bloomBitsSection, + MaxRequestLen: 16, + MaxRequestWait: 0, + } +} -- cgit v1.2.3 From f585f9eee8cb18423c23fe8b517b5b4cbe3b3755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Tue, 29 Aug 2017 14:13:11 +0300 Subject: core, eth: clean up bloom filtering, add some tests --- eth/api_backend.go | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'eth/api_backend.go') diff --git a/eth/api_backend.go b/eth/api_backend.go index fa3cf3f80..91f392f94 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -24,11 +24,11 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth/downloader" - "github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" @@ -196,28 +196,13 @@ func (b *EthApiBackend) AccountManager() *accounts.Manager { return b.eth.AccountManager() } -func (b *EthApiBackend) GetBloomBits(ctx context.Context, bitIdx uint64, sectionIdxList []uint64) ([][]byte, error) { - results := make([][]byte, len(sectionIdxList)) - var err error - for i, sectionIdx := range sectionIdxList { - sectionHead := core.GetCanonicalHash(b.eth.chainDb, (sectionIdx+1)*bloomBitsSection-1) - results[i], err = core.GetBloomBits(b.eth.chainDb, bitIdx, sectionIdx, sectionHead) - if err != nil { - return nil, err - } - } - return results, nil -} - -func (b *EthApiBackend) BloomBitsSections() uint64 { - sections, _, _ := b.eth.bbIndexer.Sections() - return sections +func (b *EthApiBackend) BloomStatus() (uint64, uint64) { + sections, _, _ := b.eth.bloomIndexer.Sections() + return params.BloomBitsBlocks, sections } -func (b *EthApiBackend) BloomBitsConfig() filters.BloomConfig { - return filters.BloomConfig{ - SectionSize: bloomBitsSection, - MaxRequestLen: 16, - MaxRequestWait: 0, +func (b *EthApiBackend) ServiceFilter(ctx context.Context, session *bloombits.MatcherSession) { + for i := 0; i < bloomFilterThreads; i++ { + go session.Multiplex(bloomRetrievalBatch, bloomRetrievalWait, b.eth.bloomRequests) } } -- cgit v1.2.3