Skip to content

Commit f505c00

Browse files
fix(l1): wait before retring on error in dev's block producer (#5391)
**Motivation** <!-- Why does this pull request exist? What are its goals? --> There was a race condition where dev's block producer starts before the RPC. In this scenario, the block producer tries to make some requests to the Engine API, failing three times in a row and thus ending. **Description** <!-- A clear and concise general description of the changes this PR introduces --> Add a small delay between retries so Engine RPC has time to get up <!-- Link to issues: Resolves #111, Resolves #222 --> Co-authored-by: Ivan Litteri <67517699+ilitteri@users.noreply.github.com>
1 parent 11e1072 commit f505c00

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

crates/blockchain/dev/block_producer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ethrex_rpc::clients::{EngineClient, EngineClientError};
44
use ethrex_rpc::types::fork_choice::{ForkChoiceState, PayloadAttributesV3};
55
use sha2::{Digest, Sha256};
66
use std::time::{Duration, SystemTime, UNIX_EPOCH};
7+
use tokio::time::sleep;
78

89
pub async fn start_block_producer(
910
execution_client_auth_url: String,
@@ -51,6 +52,7 @@ pub async fn start_block_producer(
5152
tracing::error!(
5253
"Failed to produce block: error sending engine_forkchoiceUpdatedV3 with PayloadAttributes: {error}"
5354
);
55+
sleep(Duration::from_millis(300)).await;
5456
tries += 1;
5557
continue;
5658
}
@@ -73,6 +75,7 @@ pub async fn start_block_producer(
7375
tracing::error!(
7476
"Failed to produce block: error sending engine_getPayloadV5: {error}"
7577
);
78+
sleep(Duration::from_millis(300)).await;
7679
tries += 1;
7780
continue;
7881
}
@@ -106,6 +109,7 @@ pub async fn start_block_producer(
106109
tracing::error!(
107110
"Failed to produce block: error sending engine_newPayloadV4: {error}"
108111
);
112+
sleep(Duration::from_millis(300)).await;
109113
tries += 1;
110114
continue;
111115
}
@@ -117,6 +121,7 @@ pub async fn start_block_producer(
117121
tracing::error!(
118122
"Failed to produce block: latest_valid_hash is None in PayloadStatus: {payload_status:?}"
119123
);
124+
sleep(Duration::from_millis(300)).await;
120125
tries += 1;
121126
continue;
122127
};

0 commit comments

Comments
 (0)