diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-08-29 19:13:11 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2017-09-06 16:14:19 +0800 |
commit | f585f9eee8cb18423c23fe8b517b5b4cbe3b3755 (patch) | |
tree | 08c232ee58318c20f971cf8e3f5dfa09f1e2caf7 /core/types | |
parent | 4ea4d2dc3473afd9d2eda6ef6b359accce1f0946 (diff) | |
download | go-tangerine-f585f9eee8cb18423c23fe8b517b5b4cbe3b3755.tar.gz go-tangerine-f585f9eee8cb18423c23fe8b517b5b4cbe3b3755.tar.zst go-tangerine-f585f9eee8cb18423c23fe8b517b5b4cbe3b3755.zip |
core, eth: clean up bloom filtering, add some tests
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/bloom9.go | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/core/types/bloom9.go b/core/types/bloom9.go index bdc6e60e7..a76b6f33c 100644 --- a/core/types/bloom9.go +++ b/core/types/bloom9.go @@ -28,10 +28,16 @@ type bytesBacked interface { Bytes() []byte } -const bloomLength = 256 +const ( + // BloomByteLength represents the number of bytes used in a header log bloom. + BloomByteLength = 256 -// Bloom represents a 256 bit bloom filter. -type Bloom [bloomLength]byte + // BloomBitLength represents the number of bits used in a header log bloom. + BloomBitLength = 8 * BloomByteLength +) + +// Bloom represents a 2048 bit bloom filter. +type Bloom [BloomByteLength]byte // BytesToBloom converts a byte slice to a bloom filter. // It panics if b is not of suitable size. @@ -47,7 +53,7 @@ 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) + copy(b[BloomByteLength-len(d):], d) } // Add adds d to the filter. Future calls of Test(d) will return true. @@ -106,20 +112,6 @@ func LogsBloom(logs []*Log) *big.Int { return bin } -type BloomIndexList [3]uint - -// BloomIndexes returns the bloom filter bit indexes belonging to the given key -func BloomIndexes(b []byte) BloomIndexList { - b = crypto.Keccak256(b[:]) - - var r [3]uint - for i, _ := range r { - r[i] = (uint(b[i+i+1]) + (uint(b[i+i]) << 8)) & 2047 - } - - return r -} - func bloom9(b []byte) *big.Int { b = crypto.Keccak256(b[:]) |