diff --git a/gcs/builder/builder.go b/gcs/builder/builder.go index 7f79b58..264085c 100644 --- a/gcs/builder/builder.go +++ b/gcs/builder/builder.go @@ -372,14 +372,9 @@ func BuildExtFilter(block *wire.MsgBlock) (*gcs.Filter, error) { // GetFilterHash returns the double-SHA256 of the filter. func GetFilterHash(filter *gcs.Filter) (chainhash.Hash, error) { - var zero chainhash.Hash - if filter == nil { - return zero, nil - } - filterData, err := filter.NBytes() if err != nil { - return zero, err + return chainhash.Hash{}, err } return chainhash.DoubleHashH(filterData), nil diff --git a/gcs/gcs.go b/gcs/gcs.go index b0f735e..73a5121 100644 --- a/gcs/gcs.go +++ b/gcs/gcs.go @@ -25,9 +25,6 @@ var ( // ErrPTooBig signifies that the filter can't handle `1/2**P` // collision probability. ErrPTooBig = fmt.Errorf("P is too big to fit in uint32") - - // ErrNoData signifies that an empty slice was passed. - ErrNoData = fmt.Errorf("No data provided") ) const ( @@ -98,9 +95,6 @@ func BuildGCSFilter(P uint8, key [KeySize]byte, data [][]byte) (*Filter, error) // Some initial parameter checks: make sure we have data from which to // build the filter, and make sure our parameters will fit the hash // function we're using. - if len(data) == 0 { - return nil, ErrNoData - } if uint64(len(data)) >= (1 << 32) { return nil, ErrNTooBig } @@ -115,6 +109,11 @@ func BuildGCSFilter(P uint8, key [KeySize]byte, data [][]byte) (*Filter, error) } f.modulusNP = uint64(f.n) << P + // Shortcut if the filter is empty. + if f.n == 0 { + return &f, nil + } + // Build the filter. values := make(uint64Slice, 0, len(data)) b := bstream.NewBStreamWriter(0) @@ -358,7 +357,7 @@ func (f *Filter) MatchAny(key [KeySize]byte, data [][]byte) (bool, error) { // Basic sanity check. if len(data) == 0 { - return false, ErrNoData + return false, nil } // Create a filter bitstream.