Skip to content

Commit 988672d

Browse files
authored
Merge of #7050
2 parents 6d5bcfa + 015d454 commit 988672d

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

beacon_node/beacon_chain/src/bellatrix_readiness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
171171
return BellatrixReadiness::NotSynced;
172172
}
173173
let params = MergeConfig::from_chainspec(&self.spec);
174-
let current_difficulty = el.get_current_difficulty().await.ok();
174+
let current_difficulty = el.get_current_difficulty().await.ok().flatten();
175175
BellatrixReadiness::Ready {
176176
config: params,
177177
current_difficulty,

beacon_node/execution_layer/src/engine_api.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,18 @@ pub struct ExecutionBlock {
142142
pub block_number: u64,
143143

144144
pub parent_hash: ExecutionBlockHash,
145-
pub total_difficulty: Uint256,
145+
pub total_difficulty: Option<Uint256>,
146146
#[serde(with = "serde_utils::u64_hex_be")]
147147
pub timestamp: u64,
148148
}
149149

150+
impl ExecutionBlock {
151+
pub fn terminal_total_difficulty_reached(&self, terminal_total_difficulty: Uint256) -> bool {
152+
self.total_difficulty
153+
.is_none_or(|td| td >= terminal_total_difficulty)
154+
}
155+
}
156+
150157
#[superstruct(
151158
variants(V1, V2, V3),
152159
variant_attributes(derive(Clone, Debug, Eq, Hash, PartialEq),),

beacon_node/execution_layer/src/lib.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ impl<E: EthSpec> ExecutionLayer<E> {
621621
}
622622

623623
/// Get the current difficulty of the PoW chain.
624-
pub async fn get_current_difficulty(&self) -> Result<Uint256, ApiError> {
624+
pub async fn get_current_difficulty(&self) -> Result<Option<Uint256>, ApiError> {
625625
let block = self
626626
.engine()
627627
.api
@@ -1680,7 +1680,8 @@ impl<E: EthSpec> ExecutionLayer<E> {
16801680
self.execution_blocks().await.put(block.block_hash, block);
16811681

16821682
loop {
1683-
let block_reached_ttd = block.total_difficulty >= spec.terminal_total_difficulty;
1683+
let block_reached_ttd =
1684+
block.terminal_total_difficulty_reached(spec.terminal_total_difficulty);
16841685
if block_reached_ttd {
16851686
if block.parent_hash == ExecutionBlockHash::zero() {
16861687
return Ok(Some(block));
@@ -1689,7 +1690,8 @@ impl<E: EthSpec> ExecutionLayer<E> {
16891690
.get_pow_block(engine, block.parent_hash)
16901691
.await?
16911692
.ok_or(ApiError::ExecutionBlockNotFound(block.parent_hash))?;
1692-
let parent_reached_ttd = parent.total_difficulty >= spec.terminal_total_difficulty;
1693+
let parent_reached_ttd =
1694+
parent.terminal_total_difficulty_reached(spec.terminal_total_difficulty);
16931695

16941696
if block_reached_ttd && !parent_reached_ttd {
16951697
return Ok(Some(block));
@@ -1765,9 +1767,11 @@ impl<E: EthSpec> ExecutionLayer<E> {
17651767
parent: ExecutionBlock,
17661768
spec: &ChainSpec,
17671769
) -> bool {
1768-
let is_total_difficulty_reached = block.total_difficulty >= spec.terminal_total_difficulty;
1769-
let is_parent_total_difficulty_valid =
1770-
parent.total_difficulty < spec.terminal_total_difficulty;
1770+
let is_total_difficulty_reached =
1771+
block.terminal_total_difficulty_reached(spec.terminal_total_difficulty);
1772+
let is_parent_total_difficulty_valid = parent
1773+
.total_difficulty
1774+
.is_some_and(|td| td < spec.terminal_total_difficulty);
17711775
is_total_difficulty_reached && is_parent_total_difficulty_valid
17721776
}
17731777

beacon_node/execution_layer/src/test_utils/execution_block_generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,14 @@ impl<E: EthSpec> Block<E> {
8484
block_hash: block.block_hash,
8585
block_number: block.block_number,
8686
parent_hash: block.parent_hash,
87-
total_difficulty: block.total_difficulty,
87+
total_difficulty: Some(block.total_difficulty),
8888
timestamp: block.timestamp,
8989
},
9090
Block::PoS(payload) => ExecutionBlock {
9191
block_hash: payload.block_hash(),
9292
block_number: payload.block_number(),
9393
parent_hash: payload.parent_hash(),
94-
total_difficulty,
94+
total_difficulty: Some(total_difficulty),
9595
timestamp: payload.timestamp(),
9696
},
9797
}

0 commit comments

Comments
 (0)