Skip to content

Conversation

@GabrielMartinezRodriguez
Copy link
Contributor

@GabrielMartinezRodriguez GabrielMartinezRodriguez commented Jun 27, 2025

Description

This PR solves multiple issues in the faucet:

  • The first issue was that the faucet wasn't being monitored by the monitor service, so ironically it ran out of funds.

  • Another issue fixed was that the faucet was limiting usage based on both successful and failed transactions. Now it only considers successful transactions.

  • The threshold in the monitor service was increased because it was previously equal to the amount of tokens sent per request. This could cause problems if multiple users requested funds at the same time.

  • A race condition was fixed in the transaction manager (TXM) where the same transaction was sent multiple times. This caused the faucet to occasionally send duplicate transactions for a single request. The issue occurred because the transaction was being monitored in the TXM before the collection process had fully completed.

  • TXM traces are now exported from the faucet to allow debugging in case of issues.

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 are documented in the docs.
    Public APIS and 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) with make changeset for
    breaking and meaningful changes in packages (not required for cleanups & refactors).

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 27, 2025

Deploying happychain with  Cloudflare Pages  Cloudflare Pages

Latest commit: 79781af
Status: ✅  Deploy successful!
Preview URL: https://6e6d3c71.happychain.pages.dev
Branch Preview URL: https://gabriel-fix-faucet.happychain.pages.dev

View logs

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@GabrielMartinezRodriguez GabrielMartinezRodriguez marked this pull request as ready for review June 27, 2025 09:00
@GabrielMartinezRodriguez GabrielMartinezRodriguez changed the title chore(faucet): monitor faucet Fix faucet Jun 27, 2025
@GabrielMartinezRodriguez GabrielMartinezRodriguez added the reviewing-1 Ready for, or undergoing first-line review label Jun 27, 2025
@norswap norswap added reviewing-2 Ready for, or undergoing final review and removed reviewing-1 Ready for, or undergoing first-line review labels Aug 1, 2025
export FUND_THRESHOLD=10000000000000000
export MONITOR_ADDRESSES=0x10EBe5E4E8b4B5413D8e1f91A21cE4143B6bd8F5,0x3cBD2130C2D4D6aDAA9c9054360C29e00d99f0BA,0xBAc858b1AD51527F3c4A22f146246c9913e97cFd,0x84dcb507875af1786bb6623a625d3f9aae9fda4f,0xAE45fD410bf09f27DA574D3EF547567A479F4594,0x71E30C67d58015293f452468E4754b18bAFFd807,0xE55b09F1b78B72515ff1d1a0E3C14AD5D707fdE8,0x634de6fbFfE60EE6D1257f6be3E8AF4CfefEf697,0xe8bD127b013600E5c6f864e5C07E918fa80BFF89
export FUND_THRESHOLD=100000000000000000
export FUNDS_TO_SEND=10000000000000000
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export FUNDS_TO_SEND=10000000000000000
export FUNDS_TO_SEND=100000000000000000

Let's also increase the funds to send to 0.1 HAPPY — this will avoid topping up the faucet every time someone pulls from it (the faucet sents 0.01 HAPPY), instead topping up once every 10 pulls.

Comment on lines 375 to 384
if (transaction.collectionBlock && transaction.collectionBlock > block.number - 5n) {
// Skip transactions collected in the last 5 blocks to prevent race conditions between
// the transaction collector and monitor processing the same transaction simultaneously
span.addEvent("txm.tx-monitor.handle-not-attempted-transaction.skip-transaction", {
transactionIntentId: transaction.intentId,
collectionBlock: Number(transaction.collectionBlock),
blockNumber: Number(block.number),
})
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Waiting 5 blocks might introduce a lot of lag in our retries.
I'm retooling this so that we mark transaction that haven't gone through the initial submission as a new TransactionStatus.NotAttempted and we filter to not process these transactions in the TxMonitor.

@norswap norswap force-pushed the gabriel/fix-faucet branch from 9d2cfcf to 2a4bb9f Compare August 3, 2025 10:13
@norswap norswap merged commit 63d867f into master Aug 3, 2025
4 checks passed
@norswap norswap deleted the gabriel/fix-faucet branch August 3, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

reviewing-2 Ready for, or undergoing final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants