Problem
Two guaranteed-miss Postgres lookups happen on hot paths:
-
Transaction dedup via Transaction.load() in every handler (handleDataSetCreated, handleDataSetDeleted, handleStorageProviderChanged, handlePossessionProven, handleNextProvingPeriod, handlePiecesAdded in subgraph/src/pdp-verifier.ts). A transaction's events are always processed within one block, so the entity can only pre-exist in the in-block cache — but load() on a not-yet-existing entity is a guaranteed DB round-trip for the first event of each tx.
-
Root.load() existence check in handlePiecesAdded (pdp-verifier.ts:1109-1116). The contract's nextPieceId is monotonic — piece IDs are never reused — and the code's own log message says "This shouldn't happen." That's one DB miss per piece added during backfill.
Proposal
- Replace
Transaction.load(id) with Transaction.loadInBlock(id) at all sites (apiVersion is 0.0.9, so it's available). This is the documented use case for loadInBlock: entities created earlier in the same block.
- Drop the
Root.load existence check and construct the Root unconditionally.
Acceptance criteria
Problem
Two guaranteed-miss Postgres lookups happen on hot paths:
Transaction dedup via
Transaction.load()in every handler (handleDataSetCreated,handleDataSetDeleted,handleStorageProviderChanged,handlePossessionProven,handleNextProvingPeriod,handlePiecesAddedinsubgraph/src/pdp-verifier.ts). A transaction's events are always processed within one block, so the entity can only pre-exist in the in-block cache — butload()on a not-yet-existing entity is a guaranteed DB round-trip for the first event of each tx.Root.load()existence check inhandlePiecesAdded(pdp-verifier.ts:1109-1116). The contract'snextPieceIdis monotonic — piece IDs are never reused — and the code's own log message says "This shouldn't happen." That's one DB miss per piece added during backfill.Proposal
Transaction.load(id)withTransaction.loadInBlock(id)at all sites (apiVersion is 0.0.9, so it's available). This is the documented use case forloadInBlock: entities created earlier in the same block.Root.loadexistence check and construct the Root unconditionally.Acceptance criteria
Transaction.load()remains inpdp-verifier.tshandlePiecesAdded