Skip to content

Fix: Viem sends random undefined blocks#575

Merged
GabrielMartinezRodriguez merged 1 commit intomasterfrom
gabriel/fix-block-undefined
Apr 13, 2025
Merged

Fix: Viem sends random undefined blocks#575
GabrielMartinezRodriguez merged 1 commit intomasterfrom
gabriel/fix-block-undefined

Conversation

@GabrielMartinezRodriguez
Copy link
Contributor

@GabrielMartinezRodriguez GabrielMartinezRodriguez commented Mar 31, 2025

Description

Viem sends random undefined blocks during network problems, which causes unexpected behavior

Toggle Checklist

Checklist

Basics

  • B1. I have applied the proper label & proper branch name (e.g. norswap/build-system-caching).
  • B2. This PR is not so big that it should be split & addresses only one concern.
  • B3. The PR targets the lowest branch it can (ideally master).

Reminder: PR review guidelines

Correctness

  • C1. Builds and passes tests.
  • C2. The code is properly parameterized & compatible with different environments (e.g. local,
    testnet, mainnet, standalone wallet, ...).
  • C3. I have manually tested my changes & connected features.

< INDICATE BROWSER, DEMO APP & OTHER ENV DETAILS USED FOR TESTING HERE >

< INDICATE TESTED SCENARIOS (USER INTERFACE INTERACTION, CODE FLOWS) HERE >

  • C4. I have performed a thorough self-review of my code after submitting the PR,
    and have updated the code & comments accordingly.

Architecture & Documentation

  • D1. I made it easy to reason locally about the code, by (1) using proper abstraction boundaries,
    (2) commenting these boundaries correctly, (3) adding inline comments for context when needed.
  • D2. All public-facing APIs & meaningful (non-local) internal APIs are properly documented in code
    comments.
  • D3. If appropriate, the general architecture of the code is documented in a code comment or
    in a Markdown document.
  • D4. An appropriate Changeset has been generated (and committed) for changes that touch npm published packages (currently packages/core and packages/react), see here for more info.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 31, 2025

Deploying happychain with  Cloudflare Pages  Cloudflare Pages

Latest commit: db10c52
Status:⚡️  Build in progress...

View logs

@GabrielMartinezRodriguez GabrielMartinezRodriguez changed the title fix(txm): receive blocks undefined from viem Receive blocks undefined from viem Mar 31, 2025
@GabrielMartinezRodriguez GabrielMartinezRodriguez marked this pull request as ready for review March 31, 2025 09:55
@GabrielMartinezRodriguez GabrielMartinezRodriguez added the reviewing-1 Ready for, or undergoing first-line review label Mar 31, 2025
@GabrielMartinezRodriguez GabrielMartinezRodriguez changed the title Receive blocks undefined from viem Fix: Viem sends random undefined blocks Mar 31, 2025
This was referenced Mar 31, 2025

private onNewBlock(block: LatestBlock) {
private onNewBlock(block: LatestBlock | undefined) {
if (!block) {
Copy link
Contributor

@aodhgan aodhgan Apr 1, 2025

Choose a reason for hiding this comment

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

so weird this can happen.. I see they are somewhat dangerously-widening casting to any here: https://github.com/wevm/viem/blob/main/src/actions/public/watchBlocks.ts#L172

looking through the docs and implementation for Viems watchBlocks there is also emitMissed
https://viem.sh/docs/actions/public/watchBlocks.html#emitmissed-optional
https://github.com/wevm/viem/blob/main/src/actions/public/watchBlocks.ts#L162

looking at the implementation it detects if the "latest" block number is not +1 from the last, and will send the missing blocks in the interval. this might be useful for us. wdyt? can be a another PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be interesting but would need to be handled with caution as the blocks as used as a clock as well so we wouldn't want to trigger say the transaction monitor in rapid fire.

In fact, I think we don't otherwise need to see every block — but we should make sure. Can we enqueue an issue for this (= make sure it's okay if we miss block + document).

@aodhgan aodhgan added merge-blocked Ready to merge, waiting for downstack and removed reviewing-1 Ready for, or undergoing first-line review labels Apr 1, 2025
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from d9ca14c to 0563ec5 Compare April 3, 2025 11:18
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-block-undefined branch from 0cfc909 to 357ffc8 Compare April 3, 2025 11:18
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 0563ec5 to f8961b8 Compare April 3, 2025 11:37
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-block-undefined branch from 357ffc8 to 7776719 Compare April 3, 2025 11:37
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from f8961b8 to 4b1dec2 Compare April 3, 2025 13:07
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-block-undefined branch from 7776719 to e914fb7 Compare April 3, 2025 13:08
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 4b1dec2 to 269498c Compare April 7, 2025 10:42
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-block-undefined branch from e914fb7 to 8372d4b Compare April 7, 2025 10:42
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from a5a0a16 to 7bd96c6 Compare April 10, 2025 08:01
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 7bd96c6 to 1952e64 Compare April 10, 2025 08:37
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 1952e64 to ff6ba03 Compare April 10, 2025 08:51
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from ff6ba03 to 9b6be7f Compare April 10, 2025 09:13
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 9b6be7f to 52f3721 Compare April 10, 2025 09:56
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 52f3721 to cf6a8e8 Compare April 10, 2025 11:51
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from cf6a8e8 to d388440 Compare April 10, 2025 11:56
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from d388440 to 3e362df Compare April 13, 2025 21:30
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 3e362df to 48d79d7 Compare April 13, 2025 21:36
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 48d79d7 to d3a8679 Compare April 13, 2025 21:37
Base automatically changed from gabriel/fix-txm-heap-out-of-memory to master April 13, 2025 21:38
@GabrielMartinezRodriguez GabrielMartinezRodriguez merged commit ddb0f5c into master Apr 13, 2025
2 of 4 checks passed
@GabrielMartinezRodriguez GabrielMartinezRodriguez deleted the gabriel/fix-block-undefined branch April 13, 2025 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-blocked Ready to merge, waiting for downstack

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants