-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a bug in pubsub message ID hash function (#791)
The prior implementation I believe intended to include additional fields into account when calculating the message ID from data. But was only returning hash of data for both manifest and GPBFT messages. Fix this by writing the data to the hasher, _then_ computing the hash with no suffix.
- Loading branch information
Showing
2 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package psutil_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/filecoin-project/go-f3/internal/psutil" | ||
pubsub_pb "github.com/libp2p/go-libp2p-pubsub/pb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestManifestMessageIdFn(t *testing.T) { | ||
for _, test := range []struct { | ||
name string | ||
one *pubsub_pb.Message | ||
other *pubsub_pb.Message | ||
expectEqualID bool | ||
}{ | ||
{ | ||
name: "same topic different data", | ||
one: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
From: []byte("barreleye"), | ||
Data: []byte("undadasea"), | ||
}, | ||
other: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
From: []byte("barreleye"), | ||
Data: []byte("lobstermuncher"), | ||
}, | ||
expectEqualID: false, | ||
}, | ||
{ | ||
name: "same data different topic", | ||
one: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
From: []byte("barreleye"), | ||
Data: []byte("undadasea"), | ||
}, | ||
other: &pubsub_pb.Message{ | ||
Topic: topic("lobster"), | ||
From: []byte("barreleye"), | ||
Data: []byte("undadasea"), | ||
}, | ||
expectEqualID: false, | ||
}, | ||
{ | ||
name: "same data and topic different sender", | ||
one: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
From: []byte("barreleye"), | ||
Data: []byte("undadasea"), | ||
}, | ||
other: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
From: []byte("fisherman"), | ||
Data: []byte("undadasea"), | ||
}, | ||
expectEqualID: false, | ||
}, | ||
} { | ||
t.Run(test.name, func(t *testing.T) { | ||
this, that := psutil.ManifestMessageIdFn(test.one), psutil.ManifestMessageIdFn(test.other) | ||
require.Equal(t, test.expectEqualID, this == that) | ||
}) | ||
} | ||
} | ||
|
||
func TestGPBFTMessageIdFn(t *testing.T) { | ||
for _, test := range []struct { | ||
name string | ||
one *pubsub_pb.Message | ||
other *pubsub_pb.Message | ||
expectEqualID bool | ||
}{ | ||
{ | ||
name: "same topic different data", | ||
one: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
Data: []byte("undadasea"), | ||
}, | ||
other: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
Data: []byte("lobstermuncher"), | ||
}, | ||
expectEqualID: false, | ||
}, | ||
{ | ||
name: "same data different topic", | ||
one: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
Data: []byte("undadasea"), | ||
}, | ||
other: &pubsub_pb.Message{ | ||
Topic: topic("lobster"), | ||
Data: []byte("undadasea"), | ||
}, | ||
expectEqualID: false, | ||
}, | ||
{ | ||
name: "same data and topic different sender", | ||
one: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
From: []byte("barreleye"), | ||
Data: []byte("undadasea"), | ||
}, | ||
other: &pubsub_pb.Message{ | ||
Topic: topic("fish"), | ||
From: []byte("fisherman"), | ||
Data: []byte("undadasea"), | ||
}, | ||
expectEqualID: true, | ||
}, | ||
} { | ||
t.Run(test.name, func(t *testing.T) { | ||
this, that := psutil.GPBFTMessageIdFn(test.one), psutil.GPBFTMessageIdFn(test.other) | ||
require.Equal(t, test.expectEqualID, this == that) | ||
}) | ||
} | ||
} | ||
|
||
func topic(s string) *string { return &s } |