-
Notifications
You must be signed in to change notification settings - Fork 962
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
Blobgas computation in CL #3813
base: dev
Are you sure you want to change the base?
Changes from 22 commits
4c29b0b
71f2912
1aa7488
d658c86
97dfba2
29c8275
5a7f74c
053103d
3e09a34
43d2089
3960883
4b1c429
b3328ac
2eda0a9
91e23da
172e27f
4fd2be8
63813eb
b0ac4cb
c2b9858
3c93ea2
709a424
c499d3a
35fd6c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,11 @@ | |
- [New `compute_consolidation_epoch_and_update_churn`](#new-compute_consolidation_epoch_and_update_churn) | ||
- [Updated `slash_validator`](#updated-slash_validator) | ||
- [Beacon chain state transition function](#beacon-chain-state-transition-function) | ||
- [Execution engine](#execution-engine) | ||
- [Request data](#request-data) | ||
- [Engine APIs](#engine-apis) | ||
- [Modified `notify_new_payload`](#modified-notify_new_payload) | ||
- [Modified `verify_and_notify_new_payload`](#modified-verify_and_notify_new_payload) | ||
- [Epoch processing](#epoch-processing) | ||
- [Updated `process_epoch`](#updated-process_epoch) | ||
- [Updated `process_registry_updates`](#updated--process_registry_updates) | ||
|
@@ -180,6 +185,13 @@ The following values are (non-configurable) constants used throughout the specif | |
| - | - | - | | ||
| `MAX_PENDING_PARTIALS_PER_WITHDRAWALS_SWEEP` | `uint64(2**3)` (= 8)| *[New in Electra:EIP7002]* Maximum number of pending partial withdrawals to process per payload | | ||
|
||
### Blobs | ||
|
||
| Name | Value | Description | | ||
| - | - | - | | ||
| `TARGET_BLOBS_PER_BLOCK` | `uint64(3)` | *[New in Electra]* Target number of blobs per block | | ||
|
||
|
||
## Configuration | ||
|
||
### Validator cycle | ||
|
@@ -332,7 +344,7 @@ class ExecutionPayload(Container): | |
transactions: List[Transaction, MAX_TRANSACTIONS_PER_PAYLOAD] | ||
withdrawals: List[Withdrawal, MAX_WITHDRAWALS_PER_PAYLOAD] | ||
blob_gas_used: uint64 | ||
excess_blob_gas: uint64 | ||
excess_blob_gas: uint64 # [Deprecated in Electra: compute blob gas in CL] | ||
deposit_requests: List[DepositRequest, MAX_DEPOSIT_REQUESTS_PER_PAYLOAD] # [New in Electra:EIP6110] | ||
# [New in Electra:EIP7002:EIP7251] | ||
withdrawal_requests: List[WithdrawalRequest, MAX_WITHDRAWAL_REQUESTS_PER_PAYLOAD] | ||
|
@@ -362,7 +374,7 @@ class ExecutionPayloadHeader(Container): | |
transactions_root: Root | ||
withdrawals_root: Root | ||
blob_gas_used: uint64 | ||
excess_blob_gas: uint64 | ||
excess_blob_gas: uint64 # [Deprecated in Electra: compute blob gas in CL] | ||
deposit_requests_root: Root # [New in Electra:EIP6110] | ||
withdrawal_requests_root: Root # [New in Electra:EIP7002:EIP7251] | ||
consolidation_requests_root: Root # [New in Electra:EIP7251] | ||
|
@@ -423,10 +435,50 @@ class BeaconState(Container): | |
# [New in Electra:EIP7251] | ||
pending_partial_withdrawals: List[PendingPartialWithdrawal, PENDING_PARTIAL_WITHDRAWALS_LIMIT] | ||
pending_consolidations: List[PendingConsolidation, PENDING_CONSOLIDATIONS_LIMIT] # [New in Electra:EIP7251] | ||
# [New in Electra: compute blob gas in CL] | ||
excess_blob_gas: uint64 | ||
base_fee_per_blob_gas: uint64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to keep this parameter to be in the state as it can be easily computed given the state? |
||
``` | ||
|
||
## Helper functions | ||
|
||
### Blob gas fee computation | ||
|
||
#### `fake_exponential` | ||
|
||
```python | ||
def fake_exponential(factor: int, numerator: int, denominator: int) -> int: | ||
i = 1 | ||
output = 0 | ||
numerator_accum = factor * denominator | ||
while numerator_accum > 0: | ||
output += numerator_accum | ||
numerator_accum = (numerator_accum * numerator) // (denominator * i) | ||
i += 1 | ||
return output // denominator | ||
``` | ||
|
||
#### `fake_exponential` | ||
dankrad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```python | ||
def get_blob_base_fee_update_fraction(max_blobs: int, target_blobs:int)) -> int: | ||
max_excess_per_block = (max_blobs - target_blobs) * BLOB_GAS_PER_BLOB | ||
# 1 / ln(9 / 8) ~= 8.49 = 849 / 1000 | ||
dankrad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return max_excess_per_block * 849 // 1000 | ||
``` | ||
|
||
|
||
#### `get_base_fee_per_blob_gas` | ||
|
||
```python | ||
def get_base_fee_per_blob_gas(state: BeaconState) -> int: | ||
return fake_exponential( | ||
MIN_BASE_FEE_PER_BLOB_GAS, | ||
state.excess_blob_gas, | ||
get_blob_base_fee_update_fraction(MAX_BLOBS, TARGET_BLOBS_PER_BLOCK) | ||
) | ||
``` | ||
|
||
### Predicates | ||
|
||
#### Updated `compute_proposer_index` | ||
|
@@ -789,6 +841,56 @@ def slash_validator(state: BeaconState, | |
|
||
## Beacon chain state transition function | ||
|
||
### Execution engine | ||
|
||
#### Request data | ||
|
||
#### Engine APIs | ||
|
||
##### Modified `notify_new_payload` | ||
|
||
*Note*: The function `notify_new_payload` is modified to include the blob gas fee. | ||
|
||
```python | ||
def notify_new_payload(self: ExecutionEngine, | ||
execution_payload: ExecutionPayload, | ||
parent_beacon_block_root: Root, | ||
base_fee_per_blob_gas: uint64) -> bool: | ||
""" | ||
Return ``True`` if and only if ``execution_payload`` is valid with respect to ``self.execution_state``. | ||
""" | ||
... | ||
``` | ||
|
||
##### Modified `verify_and_notify_new_payload` | ||
|
||
```python | ||
def verify_and_notify_new_payload(self: ExecutionEngine, | ||
state: BeaconState, | ||
new_payload_request: NewPayloadRequest) -> bool: | ||
""" | ||
Return ``True`` if and only if ``new_payload_request`` is valid with respect to ``self.execution_state``. | ||
""" | ||
execution_payload = new_payload_request.execution_payload | ||
parent_beacon_block_root = new_payload_request.parent_beacon_block_root | ||
|
||
if not self.is_valid_block_hash(execution_payload, parent_beacon_block_root): | ||
return False | ||
|
||
if not self.is_valid_versioned_hashes(new_payload_request): | ||
return False | ||
|
||
# [Modified in Electra] | ||
if not self.notify_new_payload(execution_payload, | ||
parent_beacon_block_root, | ||
get_base_fee_per_blob_gas(state)): | ||
return False | ||
|
||
state.excess_blob_gas += execution_payload.blob_gas_used | ||
dankrad marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this like should be a part of the def compute_excess_blob_gas(excess_blob_gas: uint64, blob_gas_used: uint64) -> uint64:
if blob_gas_used > TARGET_BLOB_GAS_PER_BLOCK:
return excess_blob_gas + blob_gas_used - TARGET_BLOB_GAS_PER_BLOCK
else:
if excess_blob_gas < TARGET_BLOB_GAS_PER_BLOCK - blob_gas_used
return uint64(0)
else:
return excess_blob_gas - (TARGET_BLOB_GAS_PER_BLOCK - blob_gas_used) |
||
|
||
return True | ||
``` | ||
|
||
### Epoch processing | ||
|
||
#### Updated `process_epoch` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Electra -- Fork Choice | ||
|
||
## Table of contents | ||
<!-- TOC --> | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
|
||
- [Introduction](#introduction) | ||
- [Containers](#containers) | ||
- [Helpers](#helpers) | ||
- [Extended `PayloadAttributes`](#extended-payloadattributes) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- /TOC --> | ||
|
||
## Introduction | ||
|
||
This is the modification of the fork choice accompanying the Electra upgrade. | ||
|
||
## Containers | ||
|
||
## Helpers | ||
|
||
### Extended `PayloadAttributes` | ||
|
||
`PayloadAttributes` is extended with the maximum number of blobs per block. | ||
|
||
```python | ||
@dataclass | ||
class PayloadAttributes(object): | ||
timestamp: uint64 | ||
prev_randao: Bytes32 | ||
suggested_fee_recipient: ExecutionAddress | ||
withdrawals: Sequence[Withdrawal] | ||
parent_beacon_block_root: Root | ||
base_fee_per_blob_gas: uint64 # [New in Electra] | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this field can be repurposed and renamed to
base_fee_per_blob_gas
, this is to make EL block self-contained in terms of execution which is required for optimistic sync (in an edge case but still). Then, this parameter must be verified in theprocess_execution_payload
: