Skip to content
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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

FrederikBolding
Copy link
Contributor

@FrederikBolding FrederikBolding commented Jan 8, 2025

This PR adds a basic implementation of the gossipped mempool described in #180.

It uses the existing mempool implementation but changes the key to use a key derived from the timestamp and identity of a message. Additions to the mempool are broadcast using a new gossip message. Messages are also evicted from the mempool when shard chunks are emitted that contain messages contained in the mempool.

Some minor changes to the channels and overall plumbing was required to setup the mempool communication.

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/mempool/mempool.rs Outdated Show resolved Hide resolved
src/storage/store/engine.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/node/snapchain_node.rs Outdated Show resolved Hide resolved
src/proto/blocks.proto Outdated Show resolved Hide resolved
@FrederikBolding FrederikBolding changed the title feat: Implement basic gossipped mempool feat: Add gossip and eviction to the mempool Jan 10, 2025
Copy link
Contributor

@sanjayprabhu sanjayprabhu left a 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());
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved things around a bit in 4842eaf - lmk what you think!

src/network/gossip.rs Outdated Show resolved Hide resolved
@@ -149,6 +170,43 @@ impl Mempool {
return true;
}

async fn insert(&mut self, message: MempoolMessage) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you want additional stats or tweaks to the formatting

Some(messages) => {
messages.insert(MempoolKey { inserted_at: Instant::now()}, message.clone());
for system_message in transaction.system_messages {
mempool.remove(&system_message.mempool_key());
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FrederikBolding FrederikBolding marked this pull request as ready for review January 16, 2025 21:59
const HOST_FOR_TEST: &str = "127.0.0.1";
const PORT_FOR_TEST: u32 = 9388;

fn setup_gossip_mempool(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are there 2 different setup functions? Do the existing tests break with the gossip set up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, I was just assuming that we didn't want to complicate the other tests further by adding additional complexity.

I can unify the setup function if preferred!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to set up the full mempool with gossip for all tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you find that the tests are getting out of hand with this approach, let's reconsider though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@sanjayprabhu sanjayprabhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants