@@ -22,16 +22,22 @@ import (
2222 "github.com/ethereum/go-ethereum/core/types"
2323)
2424
25- // errSectionOutOfBounds is returned if the user tried to add more bloom filters
26- // to the batch than available space, or if tries to retrieve above the capacity,
27- var errSectionOutOfBounds = errors .New ("section out of bounds" )
25+ var (
26+ // errSectionOutOfBounds is returned if the user tried to add more bloom filters
27+ // to the batch than available space, or if tries to retrieve above the capacity.
28+ errSectionOutOfBounds = errors .New ("section out of bounds" )
29+
30+ // errBloomBitOutOfBounds is returned if the user tried to retrieve specified
31+ // bit bloom above the capacity.
32+ errBloomBitOutOfBounds = errors .New ("bloom bit out of bounds" )
33+ )
2834
2935// Generator takes a number of bloom filters and generates the rotated bloom bits
3036// to be used for batched filtering.
3137type Generator struct {
3238 blooms [types .BloomBitLength ][]byte // Rotated blooms for per-bit matching
3339 sections uint // Number of sections to batch together
34- nextBit uint // Next bit to set when adding a bloom
40+ nextSec uint // Next section to set when adding a bloom
3541}
3642
3743// NewGenerator creates a rotated bloom generator that can iteratively fill a
@@ -51,15 +57,15 @@ func NewGenerator(sections uint) (*Generator, error) {
5157// in memory accordingly.
5258func (b * Generator ) AddBloom (index uint , bloom types.Bloom ) error {
5359 // Make sure we're not adding more bloom filters than our capacity
54- if b .nextBit >= b .sections {
60+ if b .nextSec >= b .sections {
5561 return errSectionOutOfBounds
5662 }
57- if b .nextBit != index {
63+ if b .nextSec != index {
5864 return errors .New ("bloom filter with unexpected index" )
5965 }
6066 // Rotate the bloom and insert into our collection
61- byteIndex := b .nextBit / 8
62- bitMask := byte (1 ) << byte (7 - b .nextBit % 8 )
67+ byteIndex := b .nextSec / 8
68+ bitMask := byte (1 ) << byte (7 - b .nextSec % 8 )
6369
6470 for i := 0 ; i < types .BloomBitLength ; i ++ {
6571 bloomByteIndex := types .BloomByteLength - 1 - i / 8
@@ -69,19 +75,19 @@ func (b *Generator) AddBloom(index uint, bloom types.Bloom) error {
6975 b .blooms [i ][byteIndex ] |= bitMask
7076 }
7177 }
72- b .nextBit ++
78+ b .nextSec ++
7379
7480 return nil
7581}
7682
7783// Bitset returns the bit vector belonging to the given bit index after all
7884// blooms have been added.
7985func (b * Generator ) Bitset (idx uint ) ([]byte , error ) {
80- if b .nextBit != b .sections {
86+ if b .nextSec != b .sections {
8187 return nil , errors .New ("bloom not fully generated yet" )
8288 }
83- if idx >= b . sections {
84- return nil , errSectionOutOfBounds
89+ if idx >= types . BloomBitLength {
90+ return nil , errBloomBitOutOfBounds
8591 }
8692 return b .blooms [idx ], nil
8793}
0 commit comments