Skip to content

refactor(app): Extract payload validation utilities and reduce code duplication#199

Merged
mpoke merged 15 commits intomainfrom
marius/proposal-validation
Feb 5, 2026
Merged

refactor(app): Extract payload validation utilities and reduce code duplication#199
mpoke merged 15 commits intomainfrom
marius/proposal-validation

Conversation

@mpoke
Copy link
Contributor

@mpoke mpoke commented Jan 28, 2026

Summary

  • Extract execution payload utilities into a new payload.rs module
  • Reduce code duplication in proposal validation and storage
  • Simplify validation flow by consolidating redundant functions

Changes

  • Add process_complete_proposal_parts to consolidate proposal validation logic used in both on_received_proposal_part and on_started_round
  • Create payload.rs module with:
    • ValidatedPayloadCache - moved from state.rs
    • validate_execution_payload - consolidated validation with caching
    • extract_block_header and reconstruct_execution_payload - moved from state.rs
  • Add store_undecided_value to combine store_undecided_block_data and store_undecided_proposal calls
  • Remove redundant store_undecided_block_data wrapper from State
  • Refactor on_decided and on_process_synced_value to use validate_execution_payload
  • Remove validate_payload as it was only used internally by validate_execution_payload

@mpoke mpoke requested a review from a team as a code owner January 28, 2026 10:46
app/src/state.rs Outdated
/// Stores an undecided proposal along with its block data.
///
/// WARN: The order of the two storage operations is important.
/// TODO: Add more context on why the order is important.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see a1f785a

Copy link
Member

@rnbguy rnbguy left a comment

Choose a reason for hiding this comment

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

Left few comments. Otherwise, LGTM.

"💡 Sync block validated at height {} with hash: {}",
height, new_block_hash
);
debug!(%height, "💡 Sync block validated");
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 also add back the hash ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really as we no longer have the block hash. We could get it by extracting the execution payload from the block_bytes and then use execution_payload.payload_inner.payload_inner.block_hash, but I don't see the benefit of logging the block hash in a debug message.

app/src/app.rs Outdated
Comment on lines 656 to 695
// Log stats
{
state.txs_count += tx_count as u64;
state.chain_bytes += block_bytes.len() as u64;
let elapsed_time = state.start_time.elapsed();

state.metrics.tx_stats.add_txs(tx_count as u64);
state
.metrics
.tx_stats
.add_chain_bytes(block_bytes.len() as u64);
state
.metrics
.tx_stats
.set_txs_per_second(state.txs_count as f64 / elapsed_time.as_secs_f64());
state
.metrics
.tx_stats
.set_bytes_per_second(state.chain_bytes as f64 / elapsed_time.as_secs_f64());
state.metrics.tx_stats.set_block_tx_count(tx_count as u64);
state
.metrics
.tx_stats
.set_block_size(block_bytes.len() as u64);

// Persist cumulative metrics to database for crash recovery
state
.store
.store_cumulative_metrics(state.txs_count, state.chain_bytes, elapsed_time.as_secs())
.await?;

info!(
"👉 stats at height {}: #txs={}, txs/s={:.2}, chain_bytes={}, bytes/s={:.2}",
height,
state.txs_count,
state.txs_count as f64 / elapsed_time.as_secs_f64(),
state.chain_bytes,
state.chain_bytes as f64 / elapsed_time.as_secs_f64(),
);
}
Copy link
Member

Choose a reason for hiding this comment

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

why are these removed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The stats are not removed, just moved to a separate function, see log_block_stats.

Validity::Invalid
};

cache.insert(block_hash, validity);
Copy link
Member

Choose a reason for hiding this comment

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

we call validate_execution_payload inside on_decided. do we need this caching even inside on_decided ?

I would prefer to manage cache outside this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is just an optimization that would avoid caching the validation result for the proposer. We could add a param to indicate if the validation result should be cached, but I think it just adds complexity for very little benefit.

@mpoke mpoke merged commit 145f116 into main Feb 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants