Repository navigation
chore: enable gossipsub validation #7746
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
Merged
EclesioMeloJunior
merged 10 commits into
main
from
fetch-beacon-gossipsub-1-validate-gossip
Oct 15, 2026
+218
−42
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6d42317
chore: enable gossipsub validation
EclesioMeloJunior 0e8ff76
Merge branch 'main' into fetch-beacon-gossipsub-1-validate-gossip
EclesioMeloJunior 5b58fba
chore: address comment
EclesioMeloJunior 0f2b128
Merge branch 'fetch-beacon-gossipsub-1-validate-gossip' of github.com…
EclesioMeloJunior 5c7a52e
chore: fix lint
EclesioMeloJunior e176fb7
chore: enable gossipsub validation
EclesioMeloJunior 4bbf07b
chore: address comment
EclesioMeloJunior a9169e0
Merge branch 'main' of github.com:ChainSafe/forest into fetch-beacon-…
EclesioMeloJunior ea963bf
Merge branch 'fetch-beacon-gossipsub-1-validate-gossip' of github.com…
EclesioMeloJunior 88cc68d
Merge branch 'main' of github.com:ChainSafe/forest into fetch-beacon-…
EclesioMeloJunior File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,127 @@ | ||
| // Copyright 2019-2026 ChainSafe Systems | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| use libp2p::{ | ||
| PeerId, | ||
| gossipsub::{self, MessageAcceptance, MessageId, TopicHash}, | ||
| }; | ||
|
|
||
| use crate::{ | ||
| blocks::{CachingBlockHeader, GossipBlock, RawBlockHeader}, | ||
| libp2p::{ | ||
| NetworkEvent, PubsubMessage, PubsubTopic, | ||
| service::{Verdict, handle_gossip_event}, | ||
| }, | ||
| message::SignedMessage, | ||
| shim::{ | ||
| address::Address, | ||
| crypto::Signature, | ||
| message::{Message, Message_v3}, | ||
| }, | ||
| test_utils::dummy_ticket, | ||
| }; | ||
|
|
||
| const NETWORK: &str = "testgossipvalidation"; | ||
|
|
||
| // `MessageAcceptance` doesn't implement `PartialEq`. | ||
| fn assert_verdict(actual: &MessageAcceptance, expected: MessageAcceptance) { | ||
| assert_eq!( | ||
| std::mem::discriminant(actual), | ||
| std::mem::discriminant(&expected), | ||
| "verdict {actual:?}, expected {expected:?}" | ||
| ); | ||
| } | ||
|
|
||
| fn gossip_message_event(data: Vec<u8>, topic: TopicHash) -> gossipsub::Event { | ||
| gossipsub::Event::Message { | ||
| propagation_source: PeerId::random(), | ||
| message_id: MessageId::new(b"test"), | ||
| message: gossipsub::Message { | ||
| source: None, | ||
| data, | ||
| sequence_number: None, | ||
| topic, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| fn gossip_block() -> Vec<u8> { | ||
| fvm_ipld_encoding::to_vec(&GossipBlock { | ||
| header: CachingBlockHeader::new(RawBlockHeader { | ||
| miner_address: Address::new_id(0), | ||
| ticket: dummy_ticket(0), | ||
| ..Default::default() | ||
| }), | ||
| bls_messages: vec![], | ||
| secpk_messages: vec![], | ||
| }) | ||
| .unwrap() | ||
| } | ||
|
|
||
| fn gossip_message() -> Vec<u8> { | ||
| let message: Message = Message_v3 { | ||
| to: Address::new_id(0).into(), | ||
| from: Address::new_id(0).into(), | ||
| ..Message_v3::default() | ||
| } | ||
| .into(); | ||
| fvm_ipld_encoding::to_vec(&SignedMessage::new_unchecked( | ||
| message, | ||
| Signature::new_secp256k1(vec![0]), | ||
| )) | ||
| .unwrap() | ||
| } | ||
|
|
||
| /// Blocks and messages are accepted once decoded; anything else is ignored. | ||
| #[rstest::rstest] | ||
| #[case::block( | ||
| Some(PubsubTopic::Blocks), | ||
| gossip_block(), | ||
| MessageAcceptance::Accept, | ||
| true | ||
| )] | ||
| #[case::message( | ||
| Some(PubsubTopic::Messages), | ||
| gossip_message(), | ||
| MessageAcceptance::Accept, | ||
| true | ||
| )] | ||
| #[case::undecodable_block(Some(PubsubTopic::Blocks), vec![0xff], MessageAcceptance::Ignore, false)] | ||
| #[case::undecodable_message(Some(PubsubTopic::Messages), vec![0xff], MessageAcceptance::Ignore, false)] | ||
| #[case::unknown_topic(None, gossip_block(), MessageAcceptance::Ignore, false)] | ||
| #[tokio::test] | ||
| async fn filecoin_gossip_verdicts( | ||
| #[case] kind: Option<PubsubTopic>, | ||
| #[case] data: Vec<u8>, | ||
| #[case] expected: MessageAcceptance, | ||
| #[case] emitted: bool, | ||
| ) { | ||
| let block_topic = PubsubTopic::Blocks.ident(NETWORK).to_string(); | ||
| let msg_topic = PubsubTopic::Messages.ident(NETWORK).to_string(); | ||
| let topic = TopicHash::from_raw(match kind { | ||
| Some(kind) => kind.ident(NETWORK).to_string(), | ||
| None => "/unknown/topic".into(), | ||
| }); | ||
| let (tx, rx) = flume::unbounded(); | ||
|
|
||
| let Verdict { | ||
| acceptance: verdict, | ||
| .. | ||
| } = handle_gossip_event( | ||
| gossip_message_event(data, topic), | ||
| &tx, | ||
| &block_topic, | ||
| &msg_topic, | ||
| ) | ||
| .await | ||
| .expect("an immediate verdict"); | ||
|
|
||
| assert_verdict(&verdict, expected); | ||
| match rx.try_recv() { | ||
| Ok(NetworkEvent::PubsubMessage { | ||
| message: PubsubMessage::Block(_) | PubsubMessage::Message(_), | ||
| }) => assert!(emitted, "nothing should be emitted"), | ||
| Ok(other) => panic!("unexpected event: {other:?}"), | ||
| Err(_) => assert!(!emitted, "a decoded message should be emitted"), | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.