-
Notifications
You must be signed in to change notification settings - Fork 839
Implement gossip.SetWithBloomFilter #4632
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c6439f2
5c29684
01e4f33
0b09d08
1ca0b4f
88f1fb0
690e1ae
98b2978
3ba684b
edc2d77
a8313ed
9d27671
fddd265
f3bbb0d
fb3b413
cb16af9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ import ( | |
| "google.golang.org/protobuf/proto" | ||
|
|
||
| "github.com/ava-labs/avalanchego/database/memdb" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/config" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/upgrade/ap0" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/plugin/evm/vmtest" | ||
| "github.com/ava-labs/avalanchego/graft/coreth/utils/utilstest" | ||
|
|
@@ -29,6 +28,7 @@ import ( | |
| "github.com/ava-labs/avalanchego/snow/engine/enginetest" | ||
| "github.com/ava-labs/avalanchego/snow/snowtest" | ||
| "github.com/ava-labs/avalanchego/snow/validators" | ||
| "github.com/ava-labs/avalanchego/utils/bloom" | ||
| "github.com/ava-labs/avalanchego/utils/crypto/secp256k1" | ||
| "github.com/ava-labs/avalanchego/utils/logging" | ||
| "github.com/ava-labs/avalanchego/utils/set" | ||
|
|
@@ -107,31 +107,20 @@ func TestEthTxGossip(t *testing.T) { | |
| } | ||
|
|
||
| // Ask the VM for any new transactions. We should get nothing at first. | ||
| emptyBloomFilter, err := gossip.NewBloomFilter( | ||
| prometheus.NewRegistry(), | ||
| "", | ||
| config.TxGossipBloomMinTargetElements, | ||
| config.TxGossipBloomTargetFalsePositiveRate, | ||
| config.TxGossipBloomResetFalsePositiveRate, | ||
| requestBytes, err := gossip.MarshalAppRequest( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (out of scope) Just noting that these changes are identical to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah there is probably a nice test helper that should be made at some point. I really didn't want to refactor all of the testing here... Just wanted to change the tests as minimally as possible to work with the new interface |
||
| bloom.EmptyFilter.Marshal(), | ||
| agoUtils.RandomBytes(32), | ||
| ) | ||
| require.NoError(err) | ||
| emptyBloomFilterBytes, _ := emptyBloomFilter.Marshal() | ||
| request := &sdk.PullGossipRequest{ | ||
| Filter: emptyBloomFilterBytes, | ||
| Salt: agoUtils.RandomBytes(32), | ||
| } | ||
|
|
||
| requestBytes, err := proto.Marshal(request) | ||
| require.NoError(err) | ||
|
|
||
| wg := &sync.WaitGroup{} | ||
| wg.Add(1) | ||
| onResponse := func(_ context.Context, _ ids.NodeID, responseBytes []byte, err error) { | ||
| require.NoError(err) | ||
|
|
||
| response := &sdk.PullGossipResponse{} | ||
| require.NoError(proto.Unmarshal(responseBytes, response)) | ||
| require.Empty(response.Gossip) | ||
| response, err := gossip.ParseAppResponse(responseBytes) | ||
| require.NoError(err) | ||
| require.Empty(response) | ||
| wg.Done() | ||
| } | ||
| require.NoError(client.AppRequest(ctx, set.Of(vm.ctx.NodeID), requestBytes, onResponse)) | ||
|
|
@@ -151,19 +140,22 @@ func TestEthTxGossip(t *testing.T) { | |
| // wait so we aren't throttled by the vm | ||
| time.Sleep(5 * time.Second) | ||
|
|
||
| marshaller := GossipEthTxMarshaller{} | ||
| // Ask the VM for new transactions. We should get the newly issued tx. | ||
| wg.Add(1) | ||
| onResponse = func(_ context.Context, _ ids.NodeID, responseBytes []byte, err error) { | ||
| require.NoError(err) | ||
|
|
||
| response := &sdk.PullGossipResponse{} | ||
| require.NoError(proto.Unmarshal(responseBytes, response)) | ||
| require.Len(response.Gossip, 1) | ||
| response, err := gossip.ParseAppResponse(responseBytes) | ||
| require.NoError(err) | ||
|
|
||
| gotTx, err := marshaller.UnmarshalGossip(response.Gossip[0]) | ||
| txBytes, err := signedTx.MarshalBinary() | ||
| require.NoError(err) | ||
| require.Equal(signedTx.Hash(), gotTx.Tx.Hash()) | ||
| require.Equal( | ||
| [][]byte{ | ||
| txBytes, | ||
| }, | ||
| response, | ||
| ) | ||
|
|
||
| wg.Done() | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ import ( | |
| // | ||
| // Invariant: The returned bloom filter is not safe to reset concurrently with | ||
| // other operations. However, it is otherwise safe to access concurrently. | ||
| // | ||
| // Deprecated: [BloomSet] should be used to manage bloom filters. | ||
| func NewBloomFilter( | ||
| registerer prometheus.Registerer, | ||
| namespace string, | ||
|
|
@@ -45,6 +47,7 @@ func NewBloomFilter( | |
| return filter, err | ||
| } | ||
|
|
||
| // Deprecated: [BloomSet] should be used to manage bloom filters. | ||
| type BloomFilter struct { | ||
| minTargetElements int | ||
| targetFalsePositiveProbability float64 | ||
|
|
@@ -72,12 +75,8 @@ func (b *BloomFilter) Has(gossipable Gossipable) bool { | |
| return bloom.Contains(b.bloom, h[:], b.salt[:]) | ||
| } | ||
|
|
||
| func (b *BloomFilter) Marshal() ([]byte, []byte) { | ||
| bloomBytes := b.bloom.Marshal() | ||
| // salt must be copied here to ensure the bytes aren't overwritten if salt | ||
| // is later modified. | ||
| salt := b.salt | ||
| return bloomBytes, salt[:] | ||
| func (b *BloomFilter) BloomFilter() (*bloom.Filter, ids.ID) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my understanding: why
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think there was a reason in the old code - I think we just went with hash =
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I returned an array rather than a slice to avoid needing to do the copy.. It could just be |
||
| return b.bloom, b.salt | ||
| } | ||
|
|
||
| // ResetBloomFilterIfNeeded resets a bloom filter if it breaches [targetFalsePositiveProbability]. | ||
|
|
@@ -86,6 +85,8 @@ func (b *BloomFilter) Marshal() ([]byte, []byte) { | |
| // the same [targetFalsePositiveProbability]. | ||
| // | ||
| // Returns true if the bloom filter was reset. | ||
| // | ||
| // Deprecated: [BloomSet] should be used to manage bloom filters. | ||
| func ResetBloomFilterIfNeeded( | ||
| bloomFilter *BloomFilter, | ||
| targetElements int, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.