Skip to content

Commit

Permalink
feat(examples): log payload attributes on error (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
refcell authored Jul 11, 2024
1 parent 3b48fcb commit 02b1999
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/trusted-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ async fn sync(cli: cli::Cli) -> Result<()> {
// Peek at the next prepared attributes and validate them.
if let Some(attributes) = pipeline.peek() {
match validator.validate(attributes).await {
Ok(true) => info!(target: LOG_TARGET, "Validated payload attributes"),
Ok(false) => {
error!(target: LOG_TARGET, "Failed payload validation: {}", attributes.parent.block_info.hash);
Ok((true, _)) => info!(target: LOG_TARGET, "Validated payload attributes"),
Ok((false, expected)) => {
error!(target: LOG_TARGET, "Failed payload validation. Derived payload attributes: {:?}, Expected: {:?}", attributes, expected);
metrics::FAILED_PAYLOAD_DERIVATION.inc();
let _ = pipeline.next(); // Take the attributes and continue
continue;
Expand Down
7 changes: 5 additions & 2 deletions examples/trusted-sync/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,14 @@ impl OnlineValidator {
}

/// Validates the given [`L2AttributesWithParent`].
pub async fn validate(&self, attributes: &L2AttributesWithParent) -> Result<bool> {
pub async fn validate(
&self,
attributes: &L2AttributesWithParent,
) -> Result<(bool, L2PayloadAttributes)> {
let expected = attributes.parent.block_info.number + 1;
let tag = BlockNumberOrTag::from(expected);
match self.get_payload(tag).await {
Ok(payload) => Ok(attributes.attributes == payload),
Ok(payload) => Ok((attributes.attributes == payload, payload)),
Err(e) => {
error!(target: "validation", "Failed to fetch payload for block {}: {:?}", expected, e);
Err(e)
Expand Down

0 comments on commit 02b1999

Please sign in to comment.