Skip to content

Commit d5fae8f

Browse files
committed
Fix failing test
1 parent a79f220 commit d5fae8f

File tree

8 files changed

+42
-20
lines changed

8 files changed

+42
-20
lines changed

beacon_node/beacon_chain/src/execution_payload.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ pub fn execute_payload<T: BeaconChainTypes>(
6161
Ok(status) => match status {
6262
ExecutePayloadResponseStatus::Valid { .. } => Ok(PayloadVerificationStatus::Verified),
6363
ExecutePayloadResponseStatus::Invalid { latest_valid_hash } => {
64+
let head_block_root = block.parent_root();
6465
match chain
6566
.fork_choice
6667
.write()
67-
.on_invalid_execution_payload(block_root, latest_valid_hash)
68+
.on_invalid_execution_payload(head_block_root, latest_valid_hash)
6869
{
6970
Ok(()) => warn!(
7071
chain.log,

beacon_node/beacon_chain/tests/payload_invalidation.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ impl InvalidPayloadRig {
7070
self.valid_blocks.insert(block_root);
7171
}
7272
Payload::Invalid => {
73-
mock_execution_layer.server.all_payloads_invalid();
73+
let parent = self
74+
.harness
75+
.chain
76+
.get_block(&block.message().parent_root())
77+
.unwrap()
78+
.unwrap();
79+
let parent_payload = parent.message().body().execution_payload().unwrap();
80+
mock_execution_layer
81+
.server
82+
.all_payloads_invalid(parent_payload.block_hash);
83+
7484
match self.harness.process_block(slot, block.clone()) {
7585
Err(BlockError::ExecutionPayloadError(
7686
ExecutionPayloadError::RejectedByExecutionEngine,

beacon_node/execution_layer/src/test_utils/execution_block_generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<T: EthSpec> ExecutionBlockGenerator<T> {
232232
}
233233

234234
pub fn get_payload(&mut self, id: &PayloadId) -> Option<ExecutionPayload<T>> {
235-
self.payload_ids.remove(id)
235+
self.payload_ids.get(id).cloned()
236236
}
237237

238238
pub fn execute_payload(&mut self, payload: ExecutionPayload<T>) -> ExecutePayloadResponse {

beacon_node/execution_layer/src/test_utils/handle_rpc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ pub async fn handle_rpc<T: EthSpec>(
7373
message: None,
7474
}
7575
}
76-
FixedPayloadResponse::Invalid => unimplemented!(),
76+
FixedPayloadResponse::Invalid { latest_valid_hash } => ExecutePayloadResponse {
77+
status: ExecutePayloadResponseStatus::Invalid { latest_valid_hash },
78+
message: None,
79+
},
7780
};
7881

7982
let (status, latest_valid_hash) = match response.status {

beacon_node/execution_layer/src/test_utils/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod mock_execution_layer;
3030
pub enum FixedPayloadResponse {
3131
None,
3232
Valid,
33-
Invalid,
33+
Invalid { latest_valid_hash: Hash256 },
3434
}
3535

3636
pub struct MockServer<T: EthSpec> {
@@ -125,8 +125,9 @@ impl<T: EthSpec> MockServer<T> {
125125
*self.ctx.fixed_payload_response.lock() = FixedPayloadResponse::Valid;
126126
}
127127

128-
pub fn all_payloads_invalid(&self) {
129-
*self.ctx.fixed_payload_response.lock() = FixedPayloadResponse::Invalid;
128+
pub fn all_payloads_invalid(&self, latest_valid_hash: Hash256) {
129+
*self.ctx.fixed_payload_response.lock() =
130+
FixedPayloadResponse::Invalid { latest_valid_hash };
130131
}
131132

132133
pub fn full_payload_verification(&self) {

consensus/fork_choice/src/fork_choice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,11 @@ where
447447

448448
pub fn on_invalid_execution_payload(
449449
&mut self,
450-
invalid_root: Hash256,
450+
head_block_root: Hash256,
451451
latest_valid_ancestor_root: Hash256,
452452
) -> Result<(), Error<T::Error>> {
453453
self.proto_array
454-
.process_execution_payload_invalidation(invalid_root, latest_valid_ancestor_root)
454+
.process_execution_payload_invalidation(head_block_root, latest_valid_ancestor_root)
455455
.map_err(Error::FailedToProcessInvalidExecutionPayload)
456456
}
457457

consensus/proto_array/src/proto_array.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ impl ProtoArray {
297297

298298
pub fn propagate_execution_payload_invalidation(
299299
&mut self,
300-
invalid_root: Hash256,
301-
latest_valid_ancestor_root: Hash256,
300+
head_block_root: Hash256,
301+
latest_valid_ancestor_hash: Hash256,
302302
) -> Result<(), Error> {
303303
let mut invalidated_indices: HashSet<usize> = <_>::default();
304304
let mut index = *self
305305
.indices
306-
.get(&invalid_root)
307-
.ok_or(Error::NodeUnknown(invalid_root))?;
306+
.get(&head_block_root)
307+
.ok_or(Error::NodeUnknown(head_block_root))?;
308308
let first_potential_descendant = index + 1;
309309

310310
// Collect all *ancestors* which were declared invalid since they reside between the
@@ -315,11 +315,18 @@ impl ProtoArray {
315315
.get_mut(index)
316316
.ok_or(Error::InvalidNodeIndex(index))?;
317317

318-
if node.root == latest_valid_ancestor_root {
319-
// It might be new knowledge that this block is valid, ensure that it and all
320-
// ancestors are marked as valid.
321-
self.propagate_execution_payload_validation(index)?;
322-
break;
318+
match node.execution_status {
319+
ExecutionStatus::Valid(hash)
320+
| ExecutionStatus::Invalid(hash)
321+
| ExecutionStatus::Unknown(hash) => {
322+
if hash == latest_valid_ancestor_hash {
323+
// It might be new knowledge that this block is valid, ensure that it and all
324+
// ancestors are marked as valid.
325+
self.propagate_execution_payload_validation(index)?;
326+
break;
327+
}
328+
}
329+
ExecutionStatus::Irrelevant(_) => break,
323330
}
324331

325332
match &node.execution_status {

consensus/proto_array/src/proto_array_fork_choice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ impl ProtoArrayForkChoice {
156156

157157
pub fn process_execution_payload_invalidation(
158158
&mut self,
159-
invalid_root: Hash256,
159+
head_block_root: Hash256,
160160
latest_valid_ancestor_root: Hash256,
161161
) -> Result<(), String> {
162162
self.proto_array
163-
.propagate_execution_payload_invalidation(invalid_root, latest_valid_ancestor_root)
163+
.propagate_execution_payload_invalidation(head_block_root, latest_valid_ancestor_root)
164164
.map_err(|e| format!("Failed to process invalid payload: {:?}", e))
165165
}
166166

0 commit comments

Comments
 (0)