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

Sequencer catchup #1151

Merged
merged 4 commits into from
Mar 12, 2024
Merged

Sequencer catchup #1151

merged 4 commits into from
Mar 12, 2024

Conversation

sveitser
Copy link
Collaborator

@sveitser sveitser commented Feb 26, 2024

  • Add function to fetch forgotten leaves of the fee merkle tree.
  • Add function to fetch merkle tree frontier (not hooked up yet, might change).

TODO

  • Get a the right view number for querying catchup API.
  • Tests.
  • Many TODOs in code.

@sveitser sveitser requested a review from tbro February 26, 2024 19:13
Copy link
Member

@jbearer jbearer left a comment

Choose a reason for hiding this comment

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

Definitely on the right track. Let's ask the consensus team about where to get the view number

}
}
tracing::warn!("Could not fetch account from any peer, retrying");
// TODO: backoff? for testing a function that doesn't loop forever is probably more convenient.
Copy link
Member

Choose a reason for hiding this comment

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

IMO:

  • Make backoff a parameter to set in the constructor. We can set it really short for tests that are expected to fail a few times before eventually succeeding (testing the backoff case)
  • Make a separate function that returns an error, for easy unit testing. Then the main function just call that function in a loop.

sequencer/src/catchup.rs Outdated Show resolved Hide resolved
Some(balance.cloned().unwrap_or_default().add(amount))
})
.expect("update_with succeeds");
// TODO: can this really not fail?
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so, b/c both Some or None cases are handled in the closure. I feel that this can be written more succinctly, though, by remembering the account balance in the Ok(NotInMemory) case of the match on update_with (as you've done ~line 143).

@tbro tbro force-pushed the instance-state-add-l1-client branch 4 times, most recently from 8ac034a to d652382 Compare February 29, 2024 18:11
@tbro tbro mentioned this pull request Feb 22, 2024
2 tasks
@tbro tbro force-pushed the instance-state-add-l1-client branch from 5834477 to a01aad7 Compare February 29, 2024 23:50
Base automatically changed from instance-state-add-l1-client to main March 1, 2024 16:27
sequencer/src/catchup.rs Outdated Show resolved Hide resolved
sequencer/src/catchup.rs Show resolved Hide resolved
.await;

// Insert missing fee state entries
let mut state = parent_state.clone();
Copy link
Member

Choose a reason for hiding this comment

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

Since we're cloning state here we could pass it into from_info by value and avoid a second clone (although clone should be fairly cheap now that stuff is Arced)

@sveitser
Copy link
Collaborator Author

sveitser commented Mar 7, 2024

Edit: the issue sees to be the impl Into Iterator in the function and the wrong error message from the compiler mentioned in the issue below. So I'm unblocked again.

@jbearer I tried to use box dyn trait in the last commit 053d95f, this fails to compile with the error message

error[E0391]: cycle detected when computing type of opaque `header::<impl at sequencer/src/header.rs:255:1: 255:38>::new::{opaque#0}`
   --> sequencer/src/header.rs:256:5

full error message at the end.

I wonder if the actual problem is object safety due to using async in the trait and the error message is just wrong (rust-lang/rust#119502).

I saw here here that using async_trait might help but the error message is the same.

    Checking sequencer v0.1.0 (/Users/lulu/r/EspressoSystems/espresso-sequencer/sequencer)
error[E0391]: cycle detected when checking effective visibilities
    |
note: ...which requires computing type of `state::<impl at sequencer/src/state.rs:254:1: 254:47>::validate_and_apply_header::{opaque#0}`...
   --> sequencer/src/state.rs:263:5
    |
263 | /     async fn validate_and_apply_header(
264 | |         &self,
265 | |         instance: &Self::Instance,
266 | |         parent_leaf: &Leaf,
267 | |         proposed_header: &Header,
268 | |     ) -> Result<Self, Self::Error> {
    | |__________________________________^
note: ...which requires computing type of opaque `state::<impl at sequencer/src/state.rs:254:1: 254:47>::validate_and_apply_header::{opaque#0}`...
   --> sequencer/src/state.rs:263:5
    |
263 | /     async fn validate_and_apply_header(
264 | |         &self,
265 | |         instance: &Self::Instance,
266 | |         parent_leaf: &Leaf,
267 | |         proposed_header: &Header,
268 | |     ) -> Result<Self, Self::Error> {
    | |__________________________________^
note: ...which requires type-checking `state::<impl at sequencer/src/state.rs:254:1: 254:47>::validate_and_apply_header`...
   --> sequencer/src/state.rs:263:5
    |
263 | /     async fn validate_and_apply_header(
264 | |         &self,
265 | |         instance: &Self::Instance,
266 | |         parent_leaf: &Leaf,
267 | |         proposed_header: &Header,
268 | |     ) -> Result<Self, Self::Error> {
    | |__________________________________^
    = note: ...which again requires checking effective visibilities, completing the cycle
note: cycle used when type-checking `header::<impl at sequencer/src/header.rs:255:1: 255:38>::new`
   --> sequencer/src/header.rs:256:5
    |
256 | /     async fn new(
257 | |         parent_state: &ValidatedState,
258 | |         instance_state: &NodeState,
259 | |         parent_leaf: &Leaf,
260 | |         payload_commitment: VidCommitment,
261 | |         metadata: <<SeqTypes as NodeType>::BlockPayload as BlockPayload>::Metadata,
262 | |     ) -> Self {
    | |_____________^
    = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error[E0391]: cycle detected when computing type of opaque `header::<impl at sequencer/src/header.rs:255:1: 255:38>::new::{opaque#0}`
   --> sequencer/src/header.rs:256:5
    |
256 | /     async fn new(
257 | |         parent_state: &ValidatedState,
258 | |         instance_state: &NodeState,
259 | |         parent_leaf: &Leaf,
260 | |         payload_commitment: VidCommitment,
261 | |         metadata: <<SeqTypes as NodeType>::BlockPayload as BlockPayload>::Metadata,
262 | |     ) -> Self {
    | |_____________^
    |
note: ...which requires type-checking `header::<impl at sequencer/src/header.rs:255:1: 255:38>::new`...
   --> sequencer/src/header.rs:256:5
    |
256 | /     async fn new(
257 | |         parent_state: &ValidatedState,
258 | |         instance_state: &NodeState,
259 | |         parent_leaf: &Leaf,
260 | |         payload_commitment: VidCommitment,
261 | |         metadata: <<SeqTypes as NodeType>::BlockPayload as BlockPayload>::Metadata,
262 | |     ) -> Self {
    | |_____________^
    = note: ...which requires checking effective visibilities...
note: ...which requires computing type of `header::<impl at sequencer/src/header.rs:255:1: 255:38>::new::{opaque#0}`...
   --> sequencer/src/header.rs:256:5
    |
256 | /     async fn new(
257 | |         parent_state: &ValidatedState,
258 | |         instance_state: &NodeState,
259 | |         parent_leaf: &Leaf,
260 | |         payload_commitment: VidCommitment,
261 | |         metadata: <<SeqTypes as NodeType>::BlockPayload as BlockPayload>::Metadata,
262 | |     ) -> Self {
    | |_____________^
    = note: ...which again requires computing type of opaque `header::<impl at sequencer/src/header.rs:255:1: 255:38>::new::{opaque#0}`, completing the cycle
note: cycle used when comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process
   --> sequencer/src/header.rs:256:5
    |
256 | /     async fn new(
257 | |         parent_state: &ValidatedState,
258 | |         instance_state: &NodeState,
259 | |         parent_leaf: &Leaf,
260 | |         payload_commitment: VidCommitment,
261 | |         metadata: <<SeqTypes as NodeType>::BlockPayload as BlockPayload>::Metadata,
262 | |     ) -> Self {
    | |_____________^
    = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

For more information about this error, try `rustc --explain E0391`.
error: could not compile `sequencer` (lib) due to 2 previous errors

sequencer/src/state.rs Outdated Show resolved Hide resolved
sequencer/src/state.rs Outdated Show resolved Hide resolved
tbro pushed a commit that referenced this pull request Mar 7, 2024
- Add functions to fetch from peers.

[squashed version of #1151]
.chain(l1_deposits.iter().map(|info| info.account())),
);

// Fetch missing fee state entries
Copy link
Member

Choose a reason for hiding this comment

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

We also need to fetch the blocks frontier if missing

.expect_ok()
.unwrap();
mt.remember(view.get_u64(), elem, proof.clone())
Copy link
Collaborator Author

@sveitser sveitser Mar 8, 2024

Choose a reason for hiding this comment

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

This is currently where the test panics. The element returned by lookup doesn't match the one passed in to the function.

@sveitser
Copy link
Collaborator Author

@jbearer @tbro I don't know if anyone reviewed my changes in detail. I looked at the work that @jbearer added and it looks great.

@sveitser sveitser marked this pull request as ready for review March 11, 2024 14:42
@@ -338,6 +477,12 @@ impl FeeAmount {
}
}

impl From<u64> for FeeAmount {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we had this before, but we removed it. Why are we putting it back again?

Copy link
Collaborator Author

@sveitser sveitser Mar 12, 2024

Choose a reason for hiding this comment

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

I think it's currently only used in one place, when deleting it I get:

error[E0277]: the trait bound `state::FeeAmount: From<{integer}>` is not satisfied
   --> sequencer/src/api.rs:920:56
    |
920 |         state.prefund_account(Default::default(), 1000.into());
    |                                                        ^^^^ the trait `From<{integer}>` is not implemented for `state::FeeAmount`
    |
    = help: the trait `From<ethers::types::U256>` is implemented for `state::FeeAmount`
    = help: for that trait implementation, expected `ethers::types::U256`, found `{integer}`
    = note: required for `{integer}` to implement `Into<state::FeeAmount>`

I don't really mind keeping it, it's simple and will probably be used more once we add more tests.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's just something that makes sense since FeeAmount is supposed to act like a number. E.g. U256 also implements this

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea I don't think it hurts anything either but you can just do: U256::from(1000).into().

Copy link
Member

@jbearer jbearer left a comment

Choose a reason for hiding this comment

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

@sveitser I did review your changes so if you've reviewed my changes I think we're good

sveitser and others added 2 commits March 12, 2024 16:39
- Add functions to fetch from peers.
- Re-organize block building

1. Check what's missing
2. Fetch missing data from peers
3. Build block

- Restore merkle tree frontier
- dd backoff to state peers
- Make state peers configurable
- Add nightly dev shell
- Initial mock implementation of StateCatchup
- Address review comments
This commit adds catchup to the restartability test, so that it should
in theory pass now. However, it is still failing due to an error from
HotShot: "Couldn't find parent view in state map". I will look into
this more next week. For now, the test remains ignored.
@sveitser sveitser merged commit 97d28e5 into main Mar 12, 2024
11 checks passed
@sveitser sveitser deleted the ma/sequencer-catchup branch March 12, 2024 15:57
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