Skip to content

feat: track on-chain RCA offers for dipper idempotency gate#6

Closed
MoonBoi9001 wants to merge 2 commits into
mainfrom
mb9/track-on-chain-rca-offers
Closed

feat: track on-chain RCA offers for dipper idempotency gate#6
MoonBoi9001 wants to merge 2 commits into
mainfrom
mb9/track-on-chain-rca-offers

Conversation

@MoonBoi9001
Copy link
Copy Markdown
Member

@MoonBoi9001 MoonBoi9001 commented Apr 23, 2026

Motivation

The indexing-payments-subgraph tracks the IndexingAgreement lifecycle from the point an indexer calls acceptIndexingAgreement on-chain -- the AgreementAccepted event creates the stateful entity and subsequent AgreementUpdated / AgreementCanceled / RCACollected events mutate it. What the subgraph does not currently index is the earlier pre-accept step where dipper calls RecurringCollector.offer() to post the RCA offer that indexers will later accept.

Dipper needs to know whether an offer for a given agreement already exists on-chain before submitting a new one. Without that check, a dipper crash between broadcasting offer() and persisting the result locally would cause the restart to resubmit, wasting gas on an already-successful on-chain transaction.

Summary

  • Adds a handleOfferStored mapping on the RecurringCollector data source that creates an Offer entity keyed by agreementId (bytes16) when the contract emits OfferStored.
  • Declares Offer immutable. Duplicate OfferStored events for the same agreementId are guaranteed by the contract's id derivation to carry the same offerHash, so the handler returns early on the second event rather than attempting an immutable rewrite (which would halt the subgraph).
  • Adds the OfferStored event to abis/RecurringCollector.json and binds it in subgraph.template.yaml.
  • Matchstick coverage for the handler: first-wins entity creation and duplicate-event no-op.

Generated with Claude Code

@MoonBoi9001 MoonBoi9001 force-pushed the mb9/track-on-chain-rca-offers branch from a788f72 to eb408d4 Compare April 23, 2026 04:32
Comment thread src/recurringCollector.ts
}

export function handleOfferStored(event: OfferStoredEvent): void {
// First-offer entity keyed by agreementId (bytes16). Immutable: if an
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is exactly as described here. We are using the agreementId as unique key but OfferStored could be emitted multiple times for the same agreement id. If an offer is created and updated we would be skipping the update event:

if ($.rcauOffers[rcau.agreementId].offerHash != rcauHash) {
    $.rcauOffers[rcau.agreementId] = StoredOffer({ offerHash: rcauHash, data: abi.encode(rcau) });
    emit OfferStored(rcau.agreementId, agreement.payer, OFFER_TYPE_UPDATE, rcauHash);
}

To keep immutable entities we would have to use the offerHash as an id but then from the dipper we would need to find the latest valid offer. I would suggest we drop immutability and overwrite the Offer with the latest terms, that way from dipper we query by agreement id and use the latest values.

MoonBoi9001 and others added 2 commits May 7, 2026 11:32
Adds a handleOfferStored mapping to the RecurringCollector data source
that creates an immutable Offer entity keyed by agreementId (bytes16) on
each OfferStored event.

Dipper queries this entity before calling RecurringCollector.offer() to
avoid re-submitting an offer after a crashed-mid-flight restart where the
on-chain transaction landed but dipper lost track of it. For a given
agreementId the RCA identifying fields (payer, dataService, serviceProvider,
deadline, nonce) are fixed by the id derivation, so duplicate OfferStored
events for the same id carry the same offerHash by construction -- the
entity is modelled as write-only and first-wins to reflect that. The
handler returns early if an Offer for the same id already exists, which
guards crash-recovery resubmissions and chain reorg re-emissions from
halting the subgraph on an immutable rewrite.

Includes matchstick coverage for handleOfferStored (first-wins and
duplicate-event guard).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop the branches: [main] filter so stacked PRs whose base is another
branch in the same repo (e.g. PR #7 stacked on this one) still get
build-and-test runs. Keep the push trigger narrow to main so CI does
not fire on every force-push across feature branches.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MoonBoi9001 MoonBoi9001 force-pushed the mb9/track-on-chain-rca-offers branch from c18a47d to ec72172 Compare May 7, 2026 03:32
MoonBoi9001 added a commit that referenced this pull request May 11, 2026
OfferStored fires twice for an agreement that is created and then
updated: once with OFFER_TYPE_NEW carrying the original hash, then
with OFFER_TYPE_UPDATE carrying the new hash. The earlier handler
treated the second event as a no-op, leaving stale terms in the
Offer entity and silently dropping the update. Refresh offerType
and offerHash on every event; keep createdAt pinned to the first
OFFER_TYPE_NEW so consumers can still distinguish initial offer
from subsequent updates.

Per Maikol's review on PR #6.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MoonBoi9001 MoonBoi9001 deleted the mb9/track-on-chain-rca-offers branch May 11, 2026 08:09
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