feat(STF): implement Gloas Fork - #462
Conversation
spiral-ladder
left a comment
There was a problem hiding this comment.
first pass, mostly on utils/gloas.zig
| } | ||
|
|
||
| pub fn canBuilderCoverBid(allocator: Allocator, state: *BeaconState(.gloas), builder_index: u64, bid_amount: u64) !bool { | ||
| var builders = try state.inner.get("builders"); |
There was a problem hiding this comment.
| var builders = try state.inner.get("builders"); | |
| var builders = try state.inner.getReadonly("builders"); |
| var data: PtcWindowEpochCacheData = undefined; | ||
|
|
||
| for (0..preset.SLOTS_PER_EPOCH) |i| { | ||
| try ptc_window.getValue(undefined, i, &data.previous[i]); |
There was a problem hiding this comment.
out of scope of this PR, but would be nice if we had getReadonlyByRange for this usecase
|
One overarching thought that is out of scope of this PR is that I still kinda dislike the whole dumping of everything into |
|
#464 might've broken |
|
I suggest to add some OOM/Double free fault injection test using the |
I did the benchmarking and found near to no regresssions. |
spiral-ladder
left a comment
There was a problem hiding this comment.
reviewed process_withdrawals.zig and utils/gloas.zig
| const processed_partial_withdrawals_count = expected_withdrawals_result.processed_partial_withdrawals_count; | ||
| const expected_withdrawals = expected_withdrawals_result.withdrawals.items; | ||
| const num_withdrawals = expected_withdrawals.len; | ||
| // [New in EIP-7732] Return early if parent block is empty |
There was a problem hiding this comment.
I think we can do without the [new in ...] comments
| // [New in EIP-7732] Return early if parent block is empty |
| const latest_withdrawal = if (expected_withdrawals.len > 0) expected_withdrawals[expected_withdrawals.len - 1] else null; | ||
| if (latest_withdrawal) |lw| { | ||
| try state.setNextWithdrawalIndex(lw.index + 1); |
There was a problem hiding this comment.
We can probably skip the optional here
| const latest_withdrawal = if (expected_withdrawals.len > 0) expected_withdrawals[expected_withdrawals.len - 1] else null; | |
| if (latest_withdrawal) |lw| { | |
| try state.setNextWithdrawalIndex(lw.index + 1); | |
| if (expected_withdrawals.len > 0) { | |
| try state.setNextWithdrawalIndex(expected_withdrawals[expected_withdrawals.len - 1].index + 1); | |
| } |
later below expected_withdrawals.len == preset.MAX_WITHDRAWALS_PER_PAYLOAD check necessarily means expected_withdrawals.len > 0
| /// Called by the block proposer to find a list of withdrawals to include in the block. | ||
| /// | ||
| /// This list is assumed to be bounded by `preset.MAX_WITHDRAWALS_PER_PAYLOAD`. | ||
| /// | ||
| /// Caller should deinit `withdrawal_balances` with .deinit() after use. | ||
| // Consumer should deinit WithdrawalsResult with .deinit() after use |
There was a problem hiding this comment.
why was this removed? it's also not a doc comment (triple slash instead of double slash)
| /// Convert a builder index to a flagged validator index for use in Withdrawal containers. | ||
| /// Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-convert_builder_index_to_validator_index | ||
| pub fn convertBuilderIndexToValidatorIndex(builder_index: u64) u64 { | ||
| return if (hasBuilderIndexFlag(builder_index)) builder_index else builder_index | c.BUILDER_INDEX_FLAG; |
There was a problem hiding this comment.
this is idempotent so we don't need the if check
| return if (hasBuilderIndexFlag(builder_index)) builder_index else builder_index | c.BUILDER_INDEX_FLAG; | |
| return builder_index | c.BUILDER_INDEX_FLAG; |
| /// Convert a flagged validator index back to a builder index. | ||
| /// Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-convert_validator_index_to_builder_index | ||
| pub fn convertValidatorIndexToBuilderIndex(validator_index: u64) u64 { | ||
| return if (hasBuilderIndexFlag(validator_index)) validator_index & ~c.BUILDER_INDEX_FLAG else validator_index; |
There was a problem hiding this comment.
| return if (hasBuilderIndexFlag(validator_index)) validator_index & ~c.BUILDER_INDEX_FLAG else validator_index; | |
| return validator_index & ~c.BUILDER_INDEX_FLAG; |
|
|
||
| /// Check if a validator index represents a builder (has the builder flag set). | ||
| /// Spec: https://github.com/ethereum/consensus-specs/blob/v1.7.0-alpha.1/specs/gloas/beacon-chain.md#new-is_builder_index | ||
| pub fn isBuilderIndex(validator_index: u64) bool { |
There was a problem hiding this comment.
this is just wrapping hasBuilderIndexFlag? We should move that here instead to align with spec
| }; | ||
|
|
||
| var domain: ct.primitive.Domain.Type = undefined; | ||
| computeDomain(c.DOMAIN_BUILDER_DEPOSIT, config.chain.GENESIS_FORK_VERSION, c.ZERO_HASH, &domain) catch return false; |
There was a problem hiding this comment.
a bit long, add a trailing comma and fmt
| computeDomain(c.DOMAIN_BUILDER_DEPOSIT, config.chain.GENESIS_FORK_VERSION, c.ZERO_HASH, &domain) catch return false; | |
| computeDomain(c.DOMAIN_BUILDER_DEPOSIT, config.chain.GENESIS_FORK_VERSION, c.ZERO_HASH, &domain,) catch return false; |
|
|
||
| pub fn isAttestationSameSlotRootCache(root_cache: *RootCache(.gloas), data: *const ct.phase0.AttestationData.Type) !bool { |
There was a problem hiding this comment.
this should maybe even be in root_cache.zig
| pub fn isAttestationSameSlotRootCache(root_cache: *RootCache(.gloas), data: *const ct.phase0.AttestationData.Type) !bool { | |
| /// Use cached block roots to avoid repeated state root lookups while matching the spec's is_attestation_same_slot behavior. | |
| pub fn isAttestationSameSlotRootCache(root_cache: *RootCache(.gloas), data: *const ct.phase0.AttestationData.Type) !bool { |
|
We should also keep this aligned with the spec test version in https://github.com/ChainSafe/lodestar/blob/62b30e7337e3bbc1098037b0e856ef6b2f106466/spec-tests-version.json edit: but this will need #99 |
This pr implements
v1.7.0-alpha.11supersedes feat(STF): implement Gloas Fork #303