-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add duplicate message validation to mempool (#202)
Throw away messages that already exist in the trie in the mempool before forwarding to the engine.
- Loading branch information
1 parent
25d6759
commit 6be566a
Showing
6 changed files
with
139 additions
and
13 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
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,46 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use std::collections::HashMap; | ||
|
||
use tokio::sync::mpsc; | ||
|
||
use crate::{ | ||
mempool::mempool::Mempool, | ||
storage::store::{ | ||
engine::{MempoolMessage, ShardEngine}, | ||
test_helper, | ||
}, | ||
utils::factory::messages_factory, | ||
}; | ||
|
||
use self::test_helper::{default_custody_address, default_signer}; | ||
|
||
fn setup() -> (ShardEngine, Mempool) { | ||
let (_mempool_tx, mempool_rx) = mpsc::channel(100); | ||
let (engine, _) = test_helper::new_engine(); | ||
let mut shard_senders = HashMap::new(); | ||
shard_senders.insert(1, engine.get_senders()); | ||
let mut shard_stores = HashMap::new(); | ||
shard_stores.insert(1, engine.get_stores()); | ||
let mempool = Mempool::new(mempool_rx, 1, shard_senders, shard_stores); | ||
(engine, mempool) | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_duplicate_message_is_invalid() { | ||
let (mut engine, mut mempool) = setup(); | ||
test_helper::register_user( | ||
1234, | ||
default_signer(), | ||
default_custody_address(), | ||
&mut engine, | ||
) | ||
.await; | ||
let cast = messages_factory::casts::create_cast_add(1234, "hello", None, None); | ||
let valid = mempool.message_is_valid(&MempoolMessage::UserMessage(cast.clone())); | ||
assert!(valid); | ||
test_helper::commit_message(&mut engine, &cast).await; | ||
let valid = mempool.message_is_valid(&MempoolMessage::UserMessage(cast.clone())); | ||
assert!(!valid) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
pub mod mempool; | ||
pub mod routing; | ||
|
||
#[cfg(test)] | ||
mod mempool_test; |
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