Handling Chain Reorganizations
GetBlock webhooks deliver at least once and send reorg corrections. How to de-duplicate deliveries and undo events whose block left the chain.
A chain reorganization (reorg) replaces recent blocks with another branch. An event you received in the unconfirmed phase can therefore disappear from the chain. GetBlock tells you when that happens, and your handler has to undo what it did for that event.
At-least-once delivery
Delivery is at least once: the same event can arrive more than once, for example when your answer was lost and GetBlock retried.
De-duplicate on eventId + phase. Each eventId arrives at most once per phase:
Phase
confirmed
removed
Unconfirmed
false
false
Confirmed
true
false
Removed (reorg correction)
false
true
A webhook that takes both phases receives two deliveries per event, so de-duplicating on eventId alone would drop the confirmed one.
eventId is opaque: store and compare it as a string, do not parse it.
Reorg corrections
"removed": truemeans the block holding the event left the canonical chain. Undo whatever you did for thateventId. The correction carries the sameeventIdand the same payload as the original delivery.A correction can arrive for an
eventIdyou never stored — treat it as a no-op. Corrections are matched against the webhook's current settings, so a webhook created, resumed or re-filtered between an event and its reorg can receive the removal of an event it never got. Such a delivery is billed like any other attempt.The same transfer re-mined in another block arrives as a new event with a new
eventId, possibly before the removal of the old one.CU spent on deliveries are not returned when a reorg removes the event.
Which phase to subscribe to
Corrections are delivered with the unconfirmed phase only.
A webhook that takes
confirmedonly is not told about a reorg that happens after its confirmed delivery. Includeunconfirmedif you need to hear about late reorgs.A reorg that happens before the confirmation depth is reached simply cancels the confirmed delivery: the event never arrives as confirmed.
A common pattern for payments: show a payment as pending when the unconfirmed delivery arrives, credit it when the confirmed delivery arrives, and roll it back on a correction.
Handling example
For the full payload of each delivery see Delivery Format.
Last updated
Was this helpful?