Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(l1): getBlockHeaders eth capability test #989

Merged
merged 37 commits into from
Nov 5, 2024

Conversation

fkrause98
Copy link
Contributor

@fkrause98 fkrause98 commented Oct 25, 2024

Motivation

We' re still missing support for the eth p2p capability, this adds support for the message "getBlockHeaders",
tested with the hive test suite.

Closes #955.

Base automatically changed from 840-rlpx-listen-loop to main October 29, 2024 18:47
@fkrause98 fkrause98 marked this pull request as ready for review October 31, 2024 20:14
@fkrause98 fkrause98 requested a review from a team as a code owner October 31, 2024 20:14
Comment on lines 140 to 153
if store
.update_latest_block_number(block.header.number)
.is_err()
{
error!("Fatal: added block {} but could not update the block number -- aborting block import", block.header.number);
break;
};
if store
.set_canonical_block(block.header.number, hash)
.is_err()
{
error!("Fatal: added block {} but could not set it as canonical -- aborting block import", block.header.number);
break;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already fixed by apply_fork_choice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply_fork_choice in line 157 sets the last block imported as the head, which makes all its ancestor blocks canonical. I'd check removing this as Fede suggests and checking everything still works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

Copy link
Contributor

@Arkenan Arkenan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved assuming error handling is fixed.

Comment on lines 140 to 153
if store
.update_latest_block_number(block.header.number)
.is_err()
{
error!("Fatal: added block {} but could not update the block number -- aborting block import", block.header.number);
break;
};
if store
.set_canonical_block(block.header.number, hash)
.is_err()
{
error!("Fatal: added block {} but could not set it as canonical -- aborting block import", block.header.number);
break;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply_fork_choice in line 157 sets the last block imported as the head, which makes all its ancestor blocks canonical. I'd check removing this as Fede suggests and checking everything still works.

@@ -330,6 +336,34 @@ impl<T1: RLPDecode, T2: RLPDecode, T3: RLPDecode> RLPDecode for (T1, T2, T3) {
}
}

impl<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a small comment stating that this decodes a 4-element list as a tuple would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

pub fn fetch_headers(&self, storage: &Store) -> Vec<BlockHeader> {
let start_block = match self.startblock {
// Check we have the given block hash and fetch its number
HashOrNumber::Hash(block_hash) => storage.get_block_number(block_hash).ok().flatten(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other PR here, we should return an empty response + log if error.

for _ in 0..limit {
let Some(block_header) = storage
.get_block_header(current_block as u64)
.ok()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@fkrause98 fkrause98 added this pull request to the merge queue Nov 5, 2024
Merged via the queue into main with commit 9379be4 Nov 5, 2024
13 checks passed
@fkrause98 fkrause98 deleted the p2p-test-get-block-headers branch November 5, 2024 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TESTS] Hive P2P test GetBlockHeaders
4 participants