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

STR-718 Rework L1 access from OL STF #469

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from
Draft

Conversation

delbonis
Copy link
Contributor

Description

The goal of this PR is to change the OL bookkeeping so we're only actually checking in with the L1 at the end of the epoch when we're preparing the epoch checkpoint.

This is incomplete, and may require some storage refactors if we go deep enough. Not sure there yet.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor
  • New or updated tests

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 53.93939% with 228 lines in your changes missing coverage. Please review.

Project coverage is 56.17%. Comparing base (f81dc17) to head (6613eb0).

Files with missing lines Patch % Lines
crates/chaintsn/src/epoch.rs 54.77% 123 Missing ⚠️
crates/state/src/state_op.rs 46.08% 62 Missing ⚠️
crates/state/src/chain_state.rs 64.15% 19 Missing ⚠️
crates/consensus-logic/src/duty/block_assembly.rs 0.00% 10 Missing ⚠️
crates/proof-impl/cl-stf/src/lib.rs 0.00% 5 Missing ⚠️
crates/consensus-logic/src/fork_choice_manager.rs 0.00% 3 Missing ⚠️
crates/state/src/l1/maturation_queue.rs 0.00% 3 Missing ⚠️
bin/strata-client/src/main.rs 0.00% 1 Missing ⚠️
crates/chaintsn/src/transition.rs 85.71% 1 Missing ⚠️
...rates/consensus-logic/src/csm/client_transition.rs 0.00% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main     #469      +/-   ##
==========================================
- Coverage   56.65%   56.17%   -0.48%     
==========================================
  Files         275      276       +1     
  Lines       29192    29226      +34     
==========================================
- Hits        16538    16419     -119     
- Misses      12654    12807     +153     
Files with missing lines Coverage Δ
crates/rocksdb-store/src/chain_state/db.rs 98.73% <100.00%> (+0.03%) ⬆️
crates/state/src/bridge_ops.rs 9.09% <100.00%> (-7.58%) ⬇️
crates/state/src/bridge_state.rs 58.82% <100.00%> (-0.16%) ⬇️
crates/state/src/l1/header.rs 73.17% <100.00%> (-5.78%) ⬇️
crates/test-utils/src/evm_ee.rs 97.24% <100.00%> (+0.05%) ⬆️
bin/strata-client/src/main.rs 0.00% <0.00%> (ø)
crates/chaintsn/src/transition.rs 89.79% <85.71%> (+6.92%) ⬆️
...rates/consensus-logic/src/csm/client_transition.rs 62.02% <0.00%> (ø)
crates/consensus-logic/src/fork_choice_manager.rs 0.00% <0.00%> (ø)
crates/state/src/l1/maturation_queue.rs 0.00% <0.00%> (-40.00%) ⬇️
... and 5 more

... and 9 files with indirect coverage changes

crates/chaintsn/src/epoch.rs Outdated Show resolved Hide resolved
///
/// Includes:
/// * Processes L1 withdrawals that are safe to dispatch to specific deposits.
/// * Reassigns deposits that have passed their deadling to new operators.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// * Reassigns deposits that have passed their deadling to new operators.
/// * Reassigns deposits that have passed their deadline to new operators.

deadline? :D

let new_exec_height = cur_block_height as u32 + params.dispatch_assignment_dur;

// Sequence in which we assign the operators to the deposits. This is kinda
// shitty because it might not account for available funds but it works for
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// shitty because it might not account for available funds but it works for
// XXX because it might not account for available funds but it works for

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// shitty because it might not account for available funds but it works for
// suboptimal because it might not account for available funds but it works for

crates/chaintsn/src/epoch.rs Outdated Show resolved Hide resolved
@delbonis delbonis force-pushed the STR-291-stf-refacs branch 2 times, most recently from 05ee729 to 9df4b98 Compare December 2, 2024 19:20
pub(crate) l1_state: l1::L1ViewState,
/// Epoch-level state that we only change as of the last block of an epoch.
// TODO this might be reworked to be managed separately
pub(crate) epoch_state: EpochState,

/// Pending withdrawals that have been initiated but haven't been sent out.
pub(crate) pending_withdraws: StateQueue<bridge_ops::WithdrawalIntent>,

/// Execution environment state. This is just for the single EE we support
/// right now.
pub(crate) exec_env_state: exec_env::ExecEnvState,
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, can the ExecEnvState be somehow derived from Chainstate, or maybe designed to be derived that way? Because I think it would be more transparent and explicit to prepare it before we call EE(s) and also less storage footprint. Something like derive_env_state(Chainstate, Params, ...) -> ExecEnvState

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, could you expand on what the value of this would be? I'm trying to be as data-oriented as possible here since I anticipate some refactors in the future here when we support async EE consensus.

cur_ckpt_index = seqrpc.strata_getLatestCheckpointIndex()
return cur_ckpt_idx > first_ckpt_idx

wait_until_with_value(_f, lambda v: v, "Epoch never finalized", timeout, step)
Copy link
Contributor

@bewakes bewakes Dec 3, 2024

Choose a reason for hiding this comment

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

The caller doesn't seem to use the returned value, so could be simplified with wait_until.

wait_until(_f, "Error never vinalizesd", timeout, step)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh good point, I didn't realize what I was doing.

Comment on lines +14 to +15
let epoch_init_slot = get_epoch_initial_slot(epoch, params);
epoch_init_slot + (params.target_l2_batch_size - 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is simpler?

Suggested change
let epoch_init_slot = get_epoch_initial_slot(epoch, params);
epoch_init_slot + (params.target_l2_batch_size - 1)
get_epoch_initial_slot(epoch + 1, params) - 1

Comment on lines 75 to 76
for tx in e.deposit_update_txs() {
if let ProtocolOperation::Deposit(deposit_info) = tx.tx().protocol_operation() {
Copy link
Contributor

@bewakes bewakes Dec 3, 2024

Choose a reason for hiding this comment

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

Asking for deposit_update_txs and then checking if the pattern match and .tx().protocol_operation() look a bit weird, the interface could be simpler I guess, just getting the deposit infos from payload.


DepositState::Accepted => {
// If we have an intent to assign, we can dispatch it to this deposit.
if have_ready_intent {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can move this to match line to avoid one nesting


DepositState::Dispatched(dstate) => {
// Check if the deposit is past the threshold.
if cur_block_height >= dstate.exec_deadline() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for this maybe?

Copy link
Contributor

@bewakes bewakes left a comment

Choose a reason for hiding this comment

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

Some nit comments. I think the process_deposit_updates function can be made better with helper functions.

@delbonis
Copy link
Contributor Author

delbonis commented Dec 3, 2024

@bewakes Appreciate the comments. Going to take a while to circle back to most of these since I'm working on the more tricky areas right now for stuff that breaks due to the consensus/bridging refactors.

@john-light john-light changed the title STR-291 Rework L1 access from OL STF STR-718 Rework L1 access from OL STF Dec 11, 2024
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.

3 participants