diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-10-12 23:58:51 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-10-17 03:28:59 +0800 |
commit | 6dc14788a238f3e0ec786c6c04d476a3b957e645 (patch) | |
tree | 8f3f5f91506bc4c7532543043add1eaea3fd28e7 /core/types/bloom9.go | |
parent | 30f057aaf9891fb37f82d94c24b8aa35d388e07b (diff) | |
download | go-tangerine-6dc14788a238f3e0ec786c6c04d476a3b957e645.tar.gz go-tangerine-6dc14788a238f3e0ec786c6c04d476a3b957e645.tar.zst go-tangerine-6dc14788a238f3e0ec786c6c04d476a3b957e645.zip |
core, eth/filters, miner, xeth: Optimised log filtering
Log filtering is now using a MIPmap like approach where addresses of
logs are added to a mapped bloom bin. The current levels for the MIP are
in ranges of 1.000.000, 500.000, 100.000, 50.000, 1.000. Logs are
therefor filtered in batches of 1.000.
Diffstat (limited to 'core/types/bloom9.go')
-rw-r--r-- | core/types/bloom9.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/core/types/bloom9.go b/core/types/bloom9.go index f87ae58e6..97db20ee9 100644 --- a/core/types/bloom9.go +++ b/core/types/bloom9.go @@ -17,6 +17,7 @@ package types import ( + "fmt" "math/big" "github.com/ethereum/go-ethereum/common" @@ -28,6 +29,46 @@ type bytesBacked interface { Bytes() []byte } +const bloomLength = 256 + +type Bloom [bloomLength]byte + +func BytesToBloom(b []byte) Bloom { + var bloom Bloom + bloom.SetBytes(b) + return bloom +} + +func (b *Bloom) SetBytes(d []byte) { + if len(b) < len(d) { + panic(fmt.Sprintf("bloom bytes too big %d %d", len(b), len(d))) + } + + copy(b[bloomLength-len(d):], d) +} + +func (b *Bloom) Add(d *big.Int) { + bin := new(big.Int).SetBytes(b[:]) + bin.Or(bin, bloom9(d.Bytes())) + b.SetBytes(bin.Bytes()) +} + +func (b Bloom) Big() *big.Int { + return common.Bytes2Big(b[:]) +} + +func (b Bloom) Bytes() []byte { + return b[:] +} + +func (b Bloom) Test(test *big.Int) bool { + return BloomLookup(b, test) +} + +func (b Bloom) TestBytes(test []byte) bool { + return b.Test(common.BytesToBig(test)) +} + func CreateBloom(receipts Receipts) Bloom { bin := new(big.Int) for _, receipt := range receipts { |