Skip to content

Commit

Permalink
wait for fragment to enter mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
zeegomo committed Jun 8, 2021
1 parent a09e3af commit 8b4dddb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 7 deletions.
Expand Up @@ -26,7 +26,7 @@ pub fn test_mempool_pool_max_entries_limit() {
value: 100.into(),
},
])
.with_slot_duration(2)
.with_slot_duration(5)
.with_mempool(Mempool {
pool_max_entries: 1.into(),
log_max_entries: 100.into(),
Expand Down Expand Up @@ -54,6 +54,16 @@ pub fn test_mempool_pool_max_entries_limit() {
.send_transaction(&mut sender, &receiver, &jormungandr, 1.into())
.unwrap();

// Wait until the fragment enters the mempool
FragmentVerifier
.wait_fragment(
Duration::from_millis(100),
mempool_check.clone(),
true,
&jormungandr,
)
.unwrap();

jormungandr
.correct_state_verifier()
.fragment_logs()
Expand Down Expand Up @@ -170,6 +180,16 @@ pub fn test_mempool_log_max_entries_only_one_fragment() {
.send_transaction(&mut sender, &receiver, &jormungandr, 1.into())
.unwrap();

// Wait until the fragment enters the mempool
FragmentVerifier
.wait_fragment(
Duration::from_millis(100),
first_fragment.clone(),
true,
&jormungandr,
)
.unwrap();

jormungandr
.correct_state_verifier()
.fragment_logs()
Expand Down Expand Up @@ -283,10 +303,20 @@ pub fn test_mempool_pool_max_entries_overrides_log_max_entries() {
.send_transaction(&mut sender, &receiver, &jormungandr, 1.into())
.unwrap();

fragment_sender
let second_transaction = fragment_sender
.send_transaction(&mut sender, &receiver, &jormungandr, 1.into())
.unwrap();

// Wait until the fragment enters the mempool
FragmentVerifier
.wait_fragment(
Duration::from_millis(100),
second_transaction,
true,
&jormungandr,
)
.unwrap();

jormungandr
.correct_state_verifier()
.fragment_logs()
Expand Down
Expand Up @@ -84,6 +84,16 @@ pub fn test_mempool_pool_max_entries_limit() {
.send_fragment_batch(vec![first_transaction, second_transaction], false),
);

// Wait until the fragment enters the mempool
FragmentVerifier
.wait_fragment(
Duration::from_millis(100),
mempools[0].clone(),
true,
&jormungandr,
)
.unwrap();

jormungandr
.correct_state_verifier()
.fragment_logs()
Expand Down Expand Up @@ -262,6 +272,16 @@ pub fn test_mempool_log_max_entries_only_one_fragment() {
.send_fragment_batch(vec![first_transaction, second_transaction], false),
);

// Wait until the fragment enters the mempool
FragmentVerifier
.wait_fragment(
Duration::from_millis(100),
mempools[0].clone(),
true,
&jormungandr,
)
.unwrap();

jormungandr
.correct_state_verifier()
.fragment_logs()
Expand Down Expand Up @@ -426,14 +446,24 @@ pub fn test_mempool_pool_max_entries_overrides_log_max_entries() {
)
.unwrap();

fragment_sender
let mempools = fragment_sender
.send_batch_fragments(
vec![first_transaction, second_transaction],
false,
&jormungandr,
)
.unwrap();

// Wait until the fragment enters the mempool
FragmentVerifier
.wait_fragment(
Duration::from_millis(100),
mempools[1].clone(),
true,
&jormungandr,
)
.unwrap();

jormungandr
.correct_state_verifier()
.fragment_logs()
Expand Down
Expand Up @@ -280,7 +280,7 @@ impl<'a, S: SyncNode + Send> AdversaryFragmentSender<'a, S> {
node: &A,
) -> Result<(), AdversaryFragmentSenderError> {
let verifier = FragmentVerifier;
match verifier.wait_fragment(Duration::from_secs(2), check.clone(), node)? {
match verifier.wait_fragment(Duration::from_secs(2), check.clone(), false, node)? {
FragmentStatus::Rejected { .. } => Ok(()),
FragmentStatus::InABlock { date, block } => {
Err(AdversaryFragmentSenderError::FragmentNotRejected {
Expand Down
Expand Up @@ -343,7 +343,7 @@ impl<'a, S: SyncNode + Send> FragmentSender<'a, S> {
node: &A,
) -> Result<(), FragmentSenderError> {
let verifier = FragmentVerifier;
match verifier.wait_fragment(Duration::from_secs(2), check.clone(), node)? {
match verifier.wait_fragment(Duration::from_secs(2), check.clone(), false, node)? {
FragmentStatus::Rejected { reason } => Err(FragmentSenderError::FragmentNotInBlock {
alias: FragmentNode::alias(node).to_string(),
reason,
Expand Down
Expand Up @@ -117,7 +117,7 @@ impl FragmentVerifier {
node: &A,
) -> Result<(), FragmentVerifierError> {
for check in checks {
let status = self.wait_fragment(duration, check, node)?;
let status = self.wait_fragment(duration, check, false, node)?;
self.is_in_block(status, node)?;
}
Ok(())
Expand All @@ -129,7 +129,7 @@ impl FragmentVerifier {
check: MemPoolCheck,
node: &A,
) -> Result<(), FragmentVerifierError> {
let status = self.wait_fragment(duration, check, node)?;
let status = self.wait_fragment(duration, check, false, node)?;
self.is_in_block(status, node)
}

Expand Down Expand Up @@ -181,6 +181,7 @@ impl FragmentVerifier {
&self,
duration: Duration,
check: MemPoolCheck,
exit_on_pending: bool,
node: &A,
) -> Result<FragmentStatus, FragmentVerifierError> {
let max_try = 50;
Expand All @@ -197,6 +198,7 @@ impl FragmentVerifier {
match status {
FragmentStatus::Rejected { .. } => return Ok(status),
FragmentStatus::InABlock { .. } => return Ok(status),
FragmentStatus::Pending if exit_on_pending => return Ok(status),
_ => (),
}
std::thread::sleep(duration);
Expand Down

0 comments on commit 8b4dddb

Please sign in to comment.