Fix deadlock by awaiting for pending block event
@@ -562,7 +562,7 @@ impl TestSetup {
self.execute_priority_op(deposit);
}
- fn execute_tx(&self, tx: FranklinTx) {
+ fn execute_tx(&mut self, tx: FranklinTx) {
let block = ProposedBlock {
priority_ops: Vec::new(),
txs: vec![tx],
@@ -574,10 +574,13 @@ impl TestSetup {
.await
.expect("sk receiver dropped");
};
+ // Request miniblock execution.
block_on(block_sender);
+ // Receive the pending block processing request from state keeper.
+ block_on(self.await_for_pending_block_request());
}
- fn execute_priority_op(&self, op: PriorityOp) {
+ fn execute_priority_op(&mut self, op: PriorityOp) {
let block = ProposedBlock {
priority_ops: vec![op],
txs: Vec::new(),
@@ -589,7 +592,10 @@ impl TestSetup {
.await
.expect("sk receiver dropped");
};
+ // Request miniblock execution.
block_on(block_sender);
+ // Receive the pending block processing request from state keeper.
+ block_on(self.await_for_pending_block_request());
}
pub fn exit(
@@ -746,8 +752,10 @@ impl TestSetup {
self.execute_tx(withdraw);
}
- fn await_for_block_commit_request(&mut self) -> BlockCommitRequest {
- while let Some(new_block_event) = block_on(self.proposed_blocks_receiver.next()) {
+ /// Waits for `CommitRequest::Block` to appear on proposed blocks receiver, ignoring
+ /// the pending blocks.
+ async fn await_for_block_commit_request(&mut self) -> BlockCommitRequest {
+ while let Some(new_block_event) = self.proposed_blocks_receiver.next().await {
match new_block_event {
CommitRequest::Block(new_block, receiver) => {
receiver.send(()).unwrap();
@@ -762,6 +770,28 @@ impl TestSetup {
panic!("Proposed blocks receiver dropped");
}
+ /// Takes the next `CommitRequest` from the proposed blocks receiver and expects
+ /// it to be `PendingBlock`. Panics otherwise.
+ async fn await_for_pending_block_request(&mut self) {
+ let new_block_event = self
+ .proposed_blocks_receiver
+ .next()
+ .await
+ .expect("StateKeeper sender dropped");
+ match new_block_event {
+ CommitRequest::Block(new_block, _) => {
+ panic!(
+ "Expected pending block, got full block proposed. Block: {:?}",
+ new_block
+ );
+ }
+ CommitRequest::PendingBlock(_, receiver) => {
+ // Notify state keeper that we've processed the request.
+ receiver.send(()).unwrap();
+ }
+ }
+ }
+
/// Should not be used execept special cases(when we want to commit but don't want to verify block)
pub fn execute_commit_block(&mut self) -> ETHExecResult {
let block_sender = async {
@@ -773,7 +803,7 @@ impl TestSetup {
};
block_on(block_sender);
- let new_block = self.await_for_block_commit_request();
+ let new_block = block_on(self.await_for_block_commit_request());
block_on(self.commit_account.commit_block(&new_block.block)).expect("block commit fail")
}
@@ -787,7 +817,7 @@ impl TestSetup {
.expect("sk receiver dropped");
};
block_on(block_sender);
- let new_block = self.await_for_block_commit_request();
+ let new_block = block_on(self.await_for_block_commit_request());
block_on(self.commit_account.commit_block(&new_block.block))
.expect("block commit send tx")
