Skip to content

fix(sequencer): replace panicking .expect() calls with typed error returns#441

Open
paschal533 wants to merge 2 commits intologos-blockchain:mainfrom
paschal533:fix/crash-malformation-error
Open

fix(sequencer): replace panicking .expect() calls with typed error returns#441
paschal533 wants to merge 2 commits intologos-blockchain:mainfrom
paschal533:fix/crash-malformation-error

Conversation

@paschal533
Copy link
Copy Markdown

@paschal533 paschal533 commented Apr 11, 2026

Summary

The sequencer service was panicking and crashing the whole process when it received a transaction it could not encode to check its size. Two call sites in send_transaction used .expect() on operations that can legitimately fail with well-formed client input:

  • borsh::to_vec(&tx).expect(...), can fail if the transaction graph contains types that cannot be serialized
  • u64::try_from(encoded_tx.len()).expect(...), truncation on platforms where usize > u64 maximum, which is not the current target but is still unreachable-panicking code

Instead of killing the server, these paths now return typed TransactionMalformationError variants over RPC so the caller gets a meaningful error code (InvalidParams) and message.

Changes

  • common/src/transaction.rs, add From<TransactionMalformationError> for ErrorObjectOwned mapping every variant to InvalidParams. Three unit tests verify the mapping for each variant.
  • common/Cargo.toml, add jsonrpsee workspace dependency (needed by the From impl).
  • sequencer/service/src/service.rs, replace both .expect() sites with map_err(ErrorObjectOwned::from)?, using the new From impl. The transaction-too-large check now uses saturating_sub to keep the header overhead arithmetic panic-free as well.

Why this matters

A single malformed or oversized transaction submitted by any client could previously take down the entire sequencer, requiring a manual restart. With this change the server stays alive and returns the error to the sender.

Test plan

  • cargo test -p common, three new malformation error mapping tests
  • cargo test -p sequencer_service send_transaction, existing tests still pass; the new send_transaction_too_large_returns_invalid_params test verifies the size limit path returns InvalidParams (not a panic)

…ationError

Replace panicking .expect() calls in send_transaction with proper error
propagation using TransactionMalformationError variants. Unify the size
error to use TransactionMalformationError::TransactionTooLarge instead
of a raw format string. Add unit tests for too-large and valid transaction
paths.
@paschal533 paschal533 force-pushed the fix/crash-malformation-error branch from 7f229e5 to 6d7f481 Compare April 11, 2026 23:53
Copy link
Copy Markdown
Collaborator

@schouhy schouhy left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Good catch!

Copy link
Copy Markdown
Collaborator

@Pravdyvy Pravdyvy left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants