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

feat(conductor)!: implement chain ID checks #1482

Merged
merged 24 commits into from
Oct 1, 2024

Conversation

ethanoroshiba
Copy link
Contributor

@ethanoroshiba ethanoroshiba commented Sep 10, 2024

Summary

Implemented chain ID validation for both the sequencer and Celestia readers in Conductor.

Background

This is to safeguard against connecting to an incorrect network.

This change was previously blocking on a switch to solely using gRPC for communication with sequencer, but after offline discussion it was decided to implement the chain ID check anyways using the HTTP client.

Changes

  • Added sequencer and Celestia chain ID environment variables.
  • Added chain ID checks to the initialization of both the sequencer and Celestia readers.
  • Changed conductor run_until_stopped() to return with an error so that it will not fail silently.

Testing

Added 2 blackbox tests to ensure the conductor exits with the proper error in the event of both a Celestia and sequencer chain ID mismatch.

Breaking Changelist

  • Added ASTRIA_CONDUCTOR_SEQUENCER_CHAIN_ID and ASTRIA_CONDUCTOR_CELESTIA_CHAIN_ID environment variables, without which conductor will not function.

Related Issues

closes #986

@github-actions github-actions bot added conductor pertaining to the astria-conductor crate cd labels Sep 10, 2024
@ethanoroshiba ethanoroshiba marked this pull request as ready for review September 11, 2024 18:53
@ethanoroshiba ethanoroshiba requested review from a team as code owners September 11, 2024 18:53
Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

Blocking this merge because this change exposes private types publicly

Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

Don't expose implementation details in the public API of service crates.

crates/astria-conductor/src/celestia/builder.rs Outdated Show resolved Hide resolved
crates/astria-conductor/tests/blackbox/soft_only.rs Outdated Show resolved Hide resolved
crates/astria-conductor/tests/blackbox/firm_only.rs Outdated Show resolved Hide resolved
crates/astria-conductor/src/config.rs Outdated Show resolved Hide resolved
crates/astria-conductor/src/sequencer/builder.rs Outdated Show resolved Hide resolved
crates/astria-conductor/src/sequencer/mod.rs Outdated Show resolved Hide resolved
if let Some(SequencerChainIdError::MismatchedSequencerChainId {
expected,
actual,
}) = err.downcast_ref::<SequencerChainIdError>()
Copy link
Member

Choose a reason for hiding this comment

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

Don't test implementation details in blackbox tests.

It's fine to assert that it exits after receiving a bad chain ID.

let mut source = e.source();
while source.is_some() {
let err = source.unwrap();
if let Some(CelestiaChainIdError::MismatchedCelestiaChainId {
Copy link
Member

Choose a reason for hiding this comment

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

As above, don't assert on implementation details in blackbox tests. Just check behaviour.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With checking the error source text itself, I've managed to work it such that the tests still check the error result without exposing any underlying types. It feels like the tests should probably ensure that the correct thing is causing the error, as opposed to succeeding for any kind of early exit, but I understand this is fragile so I can change if needed.

Mock as GrpcMock,
};

// We have to create our own test conductor and perform mounts manually because `TestConductor`
Copy link
Member

Choose a reason for hiding this comment

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

Instead of doing all that lifting here, could you have made use of https://doc.rust-lang.org/std/mem/struct.ManuallyDrop.html to inhibit the custom Drop from being called?

Copy link
Contributor Author

@ethanoroshiba ethanoroshiba Sep 30, 2024

Choose a reason for hiding this comment

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

In attempting to do so, I'm not sure this method will work either. Calling await on the conductor contained by ManuallyDrop<TestConductor> errs because await takes ownership of the conductor. ManuallyDrop does have a method take() which would allow for this, but it is an unsafe function and as far as I know these can't be used in tests :/

Copy link
Member

Choose a reason for hiding this comment

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

OK, let's leave this for now.

Copy link
Member

Choose a reason for hiding this comment

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

Can you make a followup issue to clean this up?

Copy link
Member

@SuperFluffy SuperFluffy left a comment

Choose a reason for hiding this comment

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

I think this is ready to get merged. :) Thank you for your work!

To bring this over the line I did two things:

  • flatten the return value of the conductor::Handle future by giving some extra context;
  • replaced the undocumented eyre::ErrReport alias by eyre::Report.

Ok(Err(err)) => Err(err.wrap_err("conductor failed failed")),
Err(err) => Err(eyre::ErrReport::from(err).wrap_err("conductor failed")),
Ok(Err(err)) => Err(err.wrap_err("conductor exited with an error")),
Err(err) => Err(eyre::ErrReport::from(err).wrap_err("conductor panicked")),
Copy link
Member

Choose a reason for hiding this comment

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

Please don't use undocumented type aliases like ErrReport.

@ethanoroshiba ethanoroshiba added this pull request to the merge queue Oct 1, 2024
Merged via the queue into main with commit 8a4eafc Oct 1, 2024
43 checks passed
@ethanoroshiba ethanoroshiba deleted the ENG-73/conductor_chain_id_verification branch October 1, 2024 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cd conductor pertaining to the astria-conductor crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

validate communicating with correct sequencer chain
4 participants