Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 24 additions & 26 deletions network/p2p/gossip/bloom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/require"

"github.com/ava-labs/avalanchego/ids"
)

func TestBloomFilterRefresh(t *testing.T) {
Expand All @@ -21,24 +19,24 @@ func TestBloomFilterRefresh(t *testing.T) {
targetFalsePositiveProbability float64
resetFalsePositiveProbability float64
resetCount uint64
add []*testTx
expected []*testTx
add []tx
expected []tx
}{
{
name: "no refresh",
minTargetElements: 1,
targetFalsePositiveProbability: 0.01,
resetFalsePositiveProbability: 1,
resetCount: 0, // maxCount = 9223372036854775807
add: []*testTx{
{id: ids.ID{0}},
{id: ids.ID{1}},
{id: ids.ID{2}},
add: []tx{
{0},
{1},
{2},
},
expected: []*testTx{
{id: ids.ID{0}},
{id: ids.ID{1}},
{id: ids.ID{2}},
expected: []tx{
{0},
{1},
{2},
},
},
{
Expand All @@ -47,13 +45,13 @@ func TestBloomFilterRefresh(t *testing.T) {
targetFalsePositiveProbability: 0.01,
resetFalsePositiveProbability: 0.0000000000000001, // maxCount = 1
resetCount: 1,
add: []*testTx{
{id: ids.ID{0}},
{id: ids.ID{1}},
{id: ids.ID{2}},
add: []tx{
{0},
{1},
{2},
},
expected: []*testTx{
{id: ids.ID{2}},
expected: []tx{
{2},
},
},
{
Expand All @@ -62,15 +60,15 @@ func TestBloomFilterRefresh(t *testing.T) {
targetFalsePositiveProbability: 0.01,
resetFalsePositiveProbability: 0.0000000000000001, // maxCount = 1
resetCount: 2,
add: []*testTx{
{id: ids.ID{0}},
{id: ids.ID{1}},
{id: ids.ID{2}},
{id: ids.ID{3}},
{id: ids.ID{4}},
add: []tx{
{0},
{1},
{2},
{3},
{4},
},
expected: []*testTx{
{id: ids.ID{4}},
expected: []tx{
{4},
},
},
}
Expand Down
40 changes: 1 addition & 39 deletions network/p2p/gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network/p2p"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/utils/bloom"
"github.com/ava-labs/avalanchego/utils/buffer"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
Expand All @@ -40,10 +39,7 @@ const (

var (
_ Gossiper = (*ValidatorGossiper)(nil)
_ Gossiper = (*PullGossiper[*testTx])(nil)
_ Gossiper = (*NoOpGossiper)(nil)

_ Set[*testTx] = (*FullSet[*testTx])(nil)
_ Gossiper = (*PullGossiper[Gossipable])(nil)

ioTypeLabels = []string{ioLabel, typeLabel}
sentPushLabels = prometheus.Labels{
Expand Down Expand Up @@ -597,37 +593,3 @@ func Every(ctx context.Context, log logging.Logger, gossiper Gossiper, frequency
}
}
}

type NoOpGossiper struct{}

func (NoOpGossiper) Gossip(context.Context) error {
return nil
}

type TestGossiper struct {
GossipF func(ctx context.Context) error
}

func (t *TestGossiper) Gossip(ctx context.Context) error {
return t.GossipF(ctx)
}

type FullSet[T Gossipable] struct{}

func (FullSet[_]) Gossip(context.Context) error {
return nil
}

func (FullSet[T]) Add(T) error {
return nil
}

func (FullSet[T]) Has(ids.ID) bool {
return true
}

func (FullSet[T]) Iterate(func(gossipable T) bool) {}

func (FullSet[_]) GetFilter() ([]byte, []byte) {
return bloom.FullFilter.Marshal(), ids.Empty[:]
}
Loading