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

Add state validation error types #1543

Merged
merged 18 commits into from
Jun 7, 2024
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ snafu = "0.8"
strum = { version = "0.26", features = ["derive"] }
surf-disco = "0.7"
tagged-base64 = "0.4"
thiserror = "1.0.61"
tide-disco = "0.7"
time = "0.3"
tracing = "0.1"
Expand Down
1 change: 1 addition & 0 deletions sequencer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ snafu = { workspace = true }
strum = { workspace = true }
surf-disco = { workspace = true }
tagged-base64 = { workspace = true }
thiserror = { workspace = true }
tide-disco = { workspace = true }
time = { workspace = true }
tokio-postgres = { version = "0.7", default-features = false, features = [ # disabling the default features removes dependence on the tokio runtime
Expand Down
48 changes: 30 additions & 18 deletions sequencer/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ mod test_headers {
catchup::mock::MockStateCatchup,
eth_signature_key::EthKeyPair,
l1_client::L1Client,
state::{validate_proposal, BlockMerkleTree, FeeAccount, FeeMerkleTree},
state::{
validate_proposal, BlockMerkleTree, FeeAccount, FeeMerkleTree, ProposalValidationError,
},
NodeState,
};
use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
Expand Down Expand Up @@ -805,19 +807,20 @@ mod test_headers {
.unwrap()
.0;

let result = validate_proposal(
&state,
ChainConfig {
chain_id: U256::zero().into(),
..Default::default()
},
&parent_leaf,
&proposal,
&vid_common,
)
.unwrap_err();
let chain_config = ChainConfig {
chain_id: U256::zero().into(),
..Default::default()
};
let err = validate_proposal(&state, chain_config, &parent_leaf, &proposal, &vid_common)
.unwrap_err();

assert!(format!("{}", result.root_cause()).starts_with("Invalid Chain Config:"));
assert_eq!(
ProposalValidationError::InvalidChainConfig {
expected: format!("{:?}", chain_config),
proposal: format!("{:?}", proposal.chain_config)
},
err
);

// Advance `proposal.height` to trigger validation error.

Expand All @@ -826,7 +829,7 @@ mod test_headers {
.await
.unwrap()
.0;
let result = validate_proposal(
let err = validate_proposal(
&validated_state,
genesis.instance_state.chain_config,
&parent_leaf,
Expand All @@ -835,8 +838,11 @@ mod test_headers {
)
.unwrap_err();
assert_eq!(
format!("{}", result.root_cause()),
"Invalid Height Error: 0, 0"
ProposalValidationError::InvalidHeight {
parent_height: 0,
proposal_height: 0
},
err
);

// proposed `Header` root should include parent + parent.commit
Expand All @@ -848,7 +854,7 @@ mod test_headers {
.unwrap()
.0;

let result = validate_proposal(
let err = validate_proposal(
&validated_state,
genesis.instance_state.chain_config,
&parent_leaf,
Expand All @@ -857,7 +863,13 @@ mod test_headers {
)
.unwrap_err();
// Fails b/c `proposal` has not advanced from `parent`
assert!(format!("{}", result.root_cause()).contains("Invalid Block Root Error"));
assert_eq!(
ProposalValidationError::InvalidBlockRoot {
expected_root: validated_state.block_merkle_tree.commitment(),
proposal_root: proposal.block_merkle_tree_root
},
err
);
}

#[async_std::test]
Expand Down
Loading
Loading