From 3b3422dc54c2cba482eaecd82cf386186bdadf3e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 28 May 2018 20:19:14 -0700 Subject: [PATCH] gcs/builder: update regular filter to exclude txid In this commit, we update the regular filter to exclude the txid, as in most cases we can use the output script for the same purpose. --- gcs/builder/builder.go | 12 ++++-------- gcs/gcsbench_test.go | 7 ++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/gcs/builder/builder.go b/gcs/builder/builder.go index 713a95f..edf2a2a 100644 --- a/gcs/builder/builder.go +++ b/gcs/builder/builder.go @@ -20,7 +20,8 @@ const DefaultP = 20 // GCSBuilder is a utility class that makes building GCS filters convenient. type GCSBuilder struct { - p uint8 + p uint8 + key [gcs.KeySize]byte // data is a set of entries represented as strings. This is done to @@ -242,8 +243,8 @@ func WithKeyP(key [gcs.KeySize]byte, p uint8) *GCSBuilder { return WithKeyPN(key, p, 0) } -// WithKey creates a GCSBuilder with specified key. Probability is set to -// 20 (2^-20 collision probability). Estimated filter size is set to zero, which +// WithKey creates a GCSBuilder with specified key. Probability is set to 19 +// (2^-19 collision probability). Estimated filter size is set to zero, which // means more reallocations are done when building the filter. func WithKey(key [gcs.KeySize]byte) *GCSBuilder { return WithKeyPN(key, DefaultP, 0) @@ -314,11 +315,6 @@ func BuildBasicFilter(block *wire.MsgBlock) (*gcs.Filter, error) { // adding the outpoint data as well as the data pushes within the // pkScript. for i, tx := range block.Transactions { - // First we'll compute the bash of the transaction and add that - // directly to the filter. - txHash := tx.TxHash() - b.AddHash(&txHash) - // Skip the inputs for the coinbase transaction if i != 0 { // Each each txin, we'll add a serialized version of diff --git a/gcs/gcsbench_test.go b/gcs/gcsbench_test.go index e74cfa4..448e01c 100644 --- a/gcs/gcsbench_test.go +++ b/gcs/gcsbench_test.go @@ -10,7 +10,7 @@ import ( "math/rand" "testing" - "github.com/roasbeef/btcutil/gcs" + "github.com/btcsuite/btcutil/gcs" ) func genRandFilterElements(numElements uint) ([][]byte, error) { @@ -46,8 +46,9 @@ func BenchmarkGCSFilterBuild50000(b *testing.B) { var localFilter *gcs.Filter for i := 0; i < b.N; i++ { - localFilter, err = gcs.BuildGCSFilter(P, key, - randFilterElems) + localFilter, err = gcs.BuildGCSFilter( + P, key, randFilterElems, + ) if err != nil { b.Fatalf("unable to generate filter: %v", err) }