-
Notifications
You must be signed in to change notification settings - Fork 189
refactor: msg pool to make more structured part 2 #7006
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
Draft
akaladarshi
wants to merge
4
commits into
main
Choose a base branch
from
akaladarshi/msgpool-refactor-phase2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a5a84fb
introduce local store and cache structures to simply the msg pool
akaladarshi a86d8c4
introduce replublish structure to simplify the msg pool
akaladarshi 5760ba2
address ai comments
akaladarshi 4861a31
change local store addr to hashset so we don't have to republish the …
akaladarshi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2019-2026 ChainSafe Systems | ||
| // SPDX-License-Identifier: Apache-2.0, MIT | ||
|
|
||
| //! Tracks local-wallet senders and the messages they have published. | ||
| //! | ||
| //! Only messages from these senders are eligible for republishing, and only | ||
| //! these messages are replayed into the pending store on `load_local`. | ||
|
|
||
| use ahash::HashSet; | ||
| use parking_lot::RwLock as SyncRwLock; | ||
|
|
||
| use crate::message::SignedMessage; | ||
| use crate::shim::address::Address; | ||
|
|
||
| #[derive(Default)] | ||
| pub(in crate::message_pool) struct LocalStore { | ||
| addrs: SyncRwLock<HashSet<Address>>, | ||
| msgs: SyncRwLock<HashSet<SignedMessage>>, | ||
| } | ||
|
|
||
| impl LocalStore { | ||
| pub(in crate::message_pool) fn new() -> Self { | ||
| Self::default() | ||
| } | ||
|
|
||
| pub(in crate::message_pool) fn add(&self, msg: SignedMessage, resolved_from: Address) { | ||
| self.addrs.write().insert(resolved_from); | ||
| self.msgs.write().insert(msg); | ||
| } | ||
|
|
||
| pub(in crate::message_pool) fn known_local_addrs(&self) -> HashSet<Address> { | ||
| self.addrs.read().clone() | ||
| } | ||
|
|
||
| pub(in crate::message_pool) fn snapshot_msgs(&self) -> Vec<SignedMessage> { | ||
| self.msgs.read().iter().cloned().collect() | ||
| } | ||
|
|
||
| pub(in crate::message_pool) fn remove_msg(&self, msg: &SignedMessage) { | ||
| self.msgs.write().remove(msg); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::message::MessageRead as _; | ||
| use crate::shim::econ::TokenAmount; | ||
| use crate::shim::message::Message as ShimMessage; | ||
|
|
||
| fn make_smsg(from: Address, seq: u64) -> SignedMessage { | ||
| SignedMessage::mock_bls_signed_message(ShimMessage { | ||
| from, | ||
| sequence: seq, | ||
| gas_premium: TokenAmount::from_atto(100u64), | ||
| gas_limit: 1_000_000, | ||
| ..ShimMessage::default() | ||
| }) | ||
| } | ||
|
|
||
| #[test] | ||
| fn add_records_address_and_message() { | ||
| let store = LocalStore::new(); | ||
| let addr = Address::new_id(1); | ||
| let msg = make_smsg(addr, 0); | ||
|
|
||
| store.add(msg.clone(), addr); | ||
|
|
||
| assert_eq!(store.known_local_addrs(), vec![addr]); | ||
| let msgs = store.snapshot_msgs(); | ||
| assert_eq!(msgs.len(), 1); | ||
| assert_eq!(msgs[0].sequence(), 0); | ||
| } | ||
|
|
||
| #[test] | ||
| fn add_appends_addresses_in_order() { | ||
| let store = LocalStore::new(); | ||
| let a1 = Address::new_id(1); | ||
| let a2 = Address::new_id(2); | ||
|
|
||
| store.add(make_smsg(a1, 0), a1); | ||
| store.add(make_smsg(a2, 0), a2); | ||
|
|
||
| assert_eq!(store.known_local_addrs(), vec![a1, a2]); | ||
| } | ||
|
|
||
| #[test] | ||
| fn remove_msg_drops_only_the_named_message() { | ||
| let store = LocalStore::new(); | ||
| let addr = Address::new_id(1); | ||
| let m0 = make_smsg(addr, 0); | ||
| let m1 = make_smsg(addr, 1); | ||
|
|
||
| store.add(m0.clone(), addr); | ||
| store.add(m1.clone(), addr); | ||
| store.remove_msg(&m0); | ||
|
|
||
| let remaining = store.snapshot_msgs(); | ||
| assert_eq!(remaining.len(), 1); | ||
| assert_eq!(remaining[0].sequence(), 1); | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The republish trigger is checking the wrong condition.
mark_republished()returnstruewhen the CID was not in the current-cycle set yet. Using that as the trigger condition flips the behavior: any previously unseen block message wakes the republisher, while a block that actually includes one of this cycle's republished messages does not. This needs a read-only membership check instead of an inserting check.Suggested direction
RepublishState::was_republishedshould readrepublished.contains(cid)without mutating the set.🤖 Prompt for AI Agents