-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: Add gossip and eviction to the mempool #200
base: main
Are you sure you want to change the base?
Conversation
9945334
to
84c2000
Compare
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.
Nice, generally looks good. Please add some tests for:
- Messages being evicted from the mempool on confirmation
- Messages submitted to one node is gossiped to another node.
|
||
pub fn mempool_key(&self) -> MempoolKey { | ||
if let Some(data) = &self.data { | ||
return MempoolKey::new(data.timestamp as u64, self.hex_hash()); |
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.
I think this function should live inside the mempool. I would add a trait in the mempool for this, and implement the trait for the structs in there. Rest of the code doesn't have to care about this.
@@ -287,6 +313,15 @@ impl SnapchainGossip { | |||
let encoded_message = gossip_message.encode_to_vec(); | |||
self.publish(encoded_message); | |||
}, | |||
Some(GossipEvent::BroadcastMempoolMessage(message)) => { | |||
debug!("Broadcasting mempool message"); |
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.
Let's remove the debug logs
@@ -149,6 +170,43 @@ impl Mempool { | |||
return true; | |||
} | |||
|
|||
async fn insert(&mut self, message: MempoolMessage) { |
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.
Let's emit some stats here, number of inserts tagged by success/failure and message type, and a guage for the current size of the mempool by shard.
Some(messages) => { | ||
messages.insert(MempoolKey { inserted_at: Instant::now()}, message.clone()); | ||
for system_message in transaction.system_messages { | ||
mempool.remove(&system_message.mempool_key()); |
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.
We should record the same stats as above when removing from the mempool as well
This PR adds a basic implementation of the gossipped mempool described in #180.
Opening in draft as I am looking for feedback on the direction before proceeding.