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

Proposal for block header lookup via block number in the history network #334

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions history/history-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The chain history network is a [Kademlia](https://pdos.csail.mit.edu/~petar/pape

Execution chain history data consists of historical block headers, block bodies (transactions, ommers and withdrawals) and block receipts.

In addition, the chain history network provides individual epoch records for the full range of pre-merge blocks mined before the transition to proof of stake.
In addition, the chain history network provides block number to historical block header lookups
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick period at end of sentence


### Data

Expand All @@ -20,19 +20,16 @@ In addition, the chain history network provides individual epoch records for the
- Ommers
- Withdrawals
- Receipts
- Header epoch records (pre-merge only)

#### Retrieval

The network supports the following mechanisms for data retrieval:

- Block header by block header hash
- Block header by block number
- Block body by block header hash
- Block receipts by block header hash
- Header epoch record by epoch record hash

> The presence of the pre-merge header records provides an indirect way to lookup blocks by their number, but is restricted to pre-merge blocks. Retrieval of blocks by their number for post-merge blocks is not intrinsically supported within this network.
>
> This sub-protocol does **not** support retrieval of transactions by hash, only the full set of transactions for a given block. See the "Canonical Transaction Index" sub-protocol of the Portal Network for more information on how the portal network implements lookup of transactions by their individual hashes.

## Specification
Expand Down Expand Up @@ -168,23 +165,40 @@ BlockHeaderWithProof = Container(
)
```

> **_Note:_** The `BlockHeaderProof` allows to provide headers without a proof (`None`).
For pre-merge headers, clients SHOULD NOT accept headers without a proof
as there is the `HistoricalHashesAccumulatorProof` solution available.
For post-merge headers, there is currently no proof solution and clients MAY
accept headers without a proof.

##### Block Header by Hash

```python
# Content and content key

block_header_key = Container(block_hash: Bytes32)
selector = 0x00

block_header_with_proof = BlockHeaderWithProof(header: rlp.encode(header)), proof: proof)
block_header_with_proof = BlockHeaderWithProof(header: rlp.encode(header), proof: proof)

content = SSZ.serialize(block_header_with_proof)
content_key = selector + SSZ.serialize(block_header_key)
```

> **_Note:_** The `BlockHeaderProof` allows to provide headers without a proof (`None`).
For pre-merge headers, clients SHOULD NOT accept headers without a proof
as there is the `HistoricalHashesAccumulatorProof` solution available.
For post-merge headers, there is currently no proof solution and clients MAY
accept headers without a proof.
##### Block Header by Number


```python
# Content and content key

block_number_key = Container(block_number: uint64)
selector = 0x04
Copy link
Collaborator

@kdeme kdeme Sep 6, 2024

Choose a reason for hiding this comment

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

What's the reasoning not to reuse the 0x03 value of Epoch Records?

Avoiding some clashing of older versions that still decode this differently and it being more clear when something sends the old 0x03 data?

Copy link
Member Author

Choose a reason for hiding this comment

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

Avoiding some clashing of older versions that still decode this differently and it being more clear when something sends the old 0x03 data?

Initially

What's the reasoning not to reuse the 0x03 value of Epoch Records?

I am fine reusing it, I wasn't sure if that was ok, I will update it now

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure myself / have no strong preference.

With no reuse the transition period can be somewhat more clean in terms of error logs, and there are enough numbers available.
But I don't think it's really an issue to re-use either, and the end result is more clean :)

Copy link
Member

Choose a reason for hiding this comment

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

I'm inclined towards re-using rather than leaving a gap. Not a strong feeling.


block_header_with_proof = BlockHeaderWithProof(header: rlp.encode(header), proof: proof)

content = SSZ.serialize(block_header_with_proof)
content_key = selector + SSZ.serialize(block_number_key)
```

#### Block Body

Expand Down Expand Up @@ -261,17 +275,6 @@ content_key = selector + SSZ.serialize(receipt_key)

Note: The type-specific receipts encoding might be different for future receipt types, but this content encoding is agnostic to the underlying receipt encodings.

#### Epoch Record

```python
epoch_record_key = Container(epoch_hash: Bytes32)
selector = 0x03
epoch_hash = hash_tree_root(epoch_record)

content = SSZ.serialize(epoch_record)
content_key = selector + SSZ.serialize(epoch_record_key)
```

### Algorithms

#### The "Historical Hashes Accumulator"
Expand Down
Loading