Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

chore(node/actor): Remove .expect(...) usage#3097

Closed
varun-doshi wants to merge 5 commits intoop-rs:mainfrom
varun-doshi:varun/node-expect
Closed

chore(node/actor): Remove .expect(...) usage#3097
varun-doshi wants to merge 5 commits intoop-rs:mainfrom
varun-doshi:varun/node-expect

Conversation

@varun-doshi
Copy link
Contributor

Fixes #3090

@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

❌ Patch coverage is 92.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.2%. Comparing base (d7d4b5d) to head (decdc15).
⚠️ Report is 27 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...rates/node/service/src/actors/sequencer/builder.rs 88.3% 5 Missing ⚠️
crates/node/service/src/service/node.rs 96.2% 1 Missing ⚠️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@varun-doshi varun-doshi requested a review from op-will November 28, 2025 14:50
Comment on lines 224 to 227
if self.mode().is_sequencer() {
validate_sequencer_fields(&build_request_tx, &seal_request_tx, &unsafe_head_rx)
.ok()?;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We know self.mode().is_sequencer() is true, right? We're in the branch where sequencer_actor_builder is Some(_).

Comment on lines 223 to 232
// Validate sequencer fields if node is in sequencer mode.
if self.mode().is_sequencer() {
validate_sequencer_fields(&build_request_tx, &seal_request_tx, &unsafe_head_rx)
.ok()?;
}
let block_building_client = QueuedBlockBuildingClient {
build_request_tx: build_request_tx.expect(
"build_request_tx is None in sequencer mode. This should never happen.",
),
build_request_tx: build_request_tx.unwrap(),
reset_request_tx: reset_request_tx.clone(),
seal_request_tx: seal_request_tx.expect(
"seal_request_tx is None in sequencer mode. This should never happen.",
),
unsafe_head_rx: unsafe_head_rx.expect(
"unsafe_head_rx is None in sequencer mode. This should never happen.",
),
seal_request_tx: seal_request_tx.unwrap(),
unsafe_head_rx: unsafe_head_rx.unwrap(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

.unwrap() panics if not Some(_), right?

Perhaps it's best to change these lines to

    unsafe_head_rx: unsafe_head_rx?,

and return a well-formed error below if sequencer_actor is None when we expect it to be Some(_)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also note the .expect on line 250 below

.ok_or(SequencerBuilderError::MissingField("admin_api_rx".to_string()))?,
attributes_builder: self
.attributes_builder
.ok_or(SequencerBuilderError::MissingField("attributes_builder".to_string()))?,
Copy link
Member

Choose a reason for hiding this comment

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

Here we should change the builder to prevent it from being instantiated if the fields are not specified instead of returning an error. This involves replacing the Option by the underlying types

}
if unsafe_head_rx.is_none() {
return Err("unsafe_head_rx is None in sequencer mode. This should never happen".to_string());
}
Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need validation for those fields. We should ensure that those fields are always set whenever we build the sequencer actor using the type system

@varun-doshi
Copy link
Contributor Author

varun-doshi commented Dec 5, 2025

Changes made:

  • SequencerActorBuilder does not hold any optional fields. Fields that do not have Default, must be passed in during the new call.
  • build cannot fail since all fields must have been set by then
  • instead of creating a sequencer_builder in the first block and then creating the sequencer_actor in the second block, the code will now create the sequencer_actor at the end of the first block itself.
  • also seems to me that doing build_request_tx.unwrap() is safe since it will never be None if mode.is_sequencer()

My only concern now is that the builder approach is not exactly as it should be since most of the fields are being initialized at constructor level.

@varun-doshi
Copy link
Contributor Author

checking CI failiures

reset_request_tx: reset_request_tx.clone(),
seal_request_tx: seal_request_tx.unwrap(),
unsafe_head_rx: unsafe_head_rx.unwrap(),
};
Copy link
Member

Choose a reason for hiding this comment

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

In a follow-up we could try to tie up the is_sequencer mode to these fields so that we never need to call unwrap here

Copy link
Member

@theochap theochap left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for taking care of it

@theochap
Copy link
Member

theochap commented Dec 8, 2025

@varun-doshi can you take care of the conflicts with main?

@op-will
Copy link
Collaborator

op-will commented Dec 8, 2025

#3152 Handles this by removing the unnecessary builder

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has been inactive for 3 weeks.
It will be closed in 1 week if no further activity occurs.
If you believe this PR should remain open, please add the M-prevent-stale label or leave a comment.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

This pull request has been automatically closed due to inactivity (4 weeks total).
If you would like to continue working on this PR, please reopen it and ensure it stays active.
You can also add the M-prevent-stale label to prevent automatic closure in the future.
Thank you for your contributions.

@github-actions github-actions bot closed this Jan 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(node/actor): Remove .expect("...") usage

3 participants