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

chain: require that new_transactions are empty #12630

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions chain/chain/src/stateless_validation/chunk_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ impl MainTransition {
pub struct PreValidationOutput {
pub main_transition_params: MainTransition,
pub implicit_transition_params: Vec<ImplicitTransitionParams>,
/// List of the transactions that are valid and should be validated. False transactions get
/// ignored.
pub transaction_validity: Vec<bool>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -369,11 +372,19 @@ pub fn pre_validate_chunk_state_witness(

let current_protocol_version =
epoch_manager.get_epoch_protocol_version(&state_witness.epoch_id)?;
if !checked_feature!(
let transaction_validity = if checked_feature!(
"protocol_feature_relaxed_chunk_validation",
RelaxedChunkValidation,
current_protocol_version
) {
if !state_witness.new_transactions.is_empty() {
return Err(Error::InvalidChunkStateWitness(format!(
"Witness new_transactions must be empty",
)));
}
let mut check = chain.transaction_validity_check(last_chunk_block.header().clone());
state_witness.transactions.iter().map(|t| check(t)).collect::<Vec<_>>()
} else {
let new_transactions = &state_witness.new_transactions;
let (new_tx_root_from_state_witness, _) = merklize(&new_transactions);
let chunk_tx_root = state_witness.chunk_header.tx_root();
Expand Down Expand Up @@ -420,7 +431,8 @@ pub fn pre_validate_chunk_state_witness(
}
};
}
}
vec![true; state_witness.transactions.len()]
};

let main_transition_params = if last_chunk_block.header().is_genesis() {
let epoch_id = last_chunk_block.header().epoch_id();
Expand Down Expand Up @@ -462,7 +474,11 @@ pub fn pre_validate_chunk_state_witness(
})
};

Ok(PreValidationOutput { main_transition_params, implicit_transition_params })
Ok(PreValidationOutput {
main_transition_params,
implicit_transition_params,
transaction_validity,
})
}

/// Validate that receipt proofs contain the receipts that should be applied during the
Expand Down Expand Up @@ -611,7 +627,20 @@ pub fn validate_chunk_state_witness(
let (mut chunk_extra, mut outgoing_receipts) =
match (pre_validation_output.main_transition_params, cache_result) {
(MainTransition::Genesis { chunk_extra, .. }, _) => (chunk_extra, vec![]),
(MainTransition::NewChunk(new_chunk_data), None) => {
(MainTransition::NewChunk(mut new_chunk_data), None) => {
let mut validity_iterator = pre_validation_output.transaction_validity.iter();
new_chunk_data.transactions.retain(|t| {
let valid = *validity_iterator.next().unwrap();
if !valid {
tracing::debug!(
target: "chain",
message="discarding invalid transaction",
tx=%t.get_hash()
);
}
valid
});

let chunk_header = new_chunk_data.chunk_header.clone();
let NewChunkResult { apply_result: mut main_apply_result, .. } = apply_new_chunk(
ApplyChunkReason::ValidateChunkStateWitness,
Expand Down
Loading