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

Fix padding for single txn blocks #17

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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
27 changes: 23 additions & 4 deletions protocol_decoder/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ impl ProcessedBlockTrace {
&other_data,
&extra_data,
&initial_tries_for_dummies,
&curr_block_tries,
!self.withdrawals.is_empty(),
);

if !self.withdrawals.is_empty() {
Expand Down Expand Up @@ -304,10 +306,13 @@ impl ProcessedBlockTrace {
other_data: &OtherBlockData,
extra_data: &ExtraBlockData,
initial_tries: &PartialTrieState,
final_tries: &PartialTrieState,
has_withdrawals: bool,
) -> bool {
match gen_inputs.len() {
0 => {
// Need to pad with two dummy entries.
debug_assert!(initial_tries.state == final_tries.state);
// We need to pad with two dummy entries.
gen_inputs.extend(create_dummy_txn_pair_for_empty_block(
other_data,
extra_data,
Expand All @@ -317,9 +322,23 @@ impl ProcessedBlockTrace {
true
}
1 => {
// Just need one.
let dummy_txn = create_dummy_gen_input(other_data, extra_data, initial_tries);
gen_inputs.insert(0, dummy_txn);
// We just need one dummy entry.
// If there are withdrawals, we will need to append them at the end of the block
// execution, in which case we directly append the dummy proof
// after the only txn of this block.
// If there are no withdrawals, then the dummy proof will be prepended to the
// actual txn.
match has_withdrawals {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use if { … } else { … }?

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually find that using a match on a bool is usually more readable (there might be something wrong with me, idk 🙃) than an if / else. I think using a match is a bit less common though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah not sure why I went for match, maybe an implicit preference as Brendan said, happy to change though

Copy link

Choose a reason for hiding this comment

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

I'd vote for keeping match

false => {
let dummy_txn =
create_dummy_gen_input(other_data, extra_data, initial_tries);
gen_inputs.insert(0, dummy_txn)
}
true => {
let dummy_txn = create_dummy_gen_input(other_data, extra_data, final_tries);
gen_inputs.push(dummy_txn)
}
};

true
}
Expand Down