This system ensures reliable delivery of block-level webhook events from an external blockchain event source ("Chainhook"). Using Cloudflare Durable Objects and Workers, the architecture provides:
- Resilience to duplication
- Robust handling of chainhook failure
- Efficient, scalable event delivery
- Future-ready fan-out support to multiple destinations
- Receive every anchored block event from the chainhook
- Prevent duplicate forwarding via global deduplication (using
block_hash) - Deliver payloads to at least one downstream service, with future fan-out support
- Handle chainhook creation, health monitoring, and re-creation in a modular way
- Scale horizontally as new API keys and use cases are added
This will be a new DO specifically for handling chainhooks.
External Chainhook Service → ChainhookDO (per Hiro Platform API key) → RelayWorker → Destination Webhook(s)
- ChainhookDO handles:
- Chainhook lifecycle (auth, create, monitor, recreate)
- Receiving webhook payloads from created chainhook
- Forwarding payloads to RelayWorker for processing
- RelayWorker handles:
- Deduplication via KV
- Forwarding to destination(s)
- KV Store handles:
- Global deduplication keyed by
block_hash
- Global deduplication keyed by
- Initialize and manage the chainhook (via external API)
- Receive POSTs from the chainhook
- Forward payloads to
RelayWorker - Monitor health and recreate chainhook if it's stale or failed
chainhook_id- Last known
block_hash - Last activity timestamp
POST /event– handles incoming block payloadsGET /status– returns internal DO state (for debugging)
- Check chainhook status via external API
- Compare expected vs. actual block delivery timing
- Recreate hook if needed
- Receive block payload from DO
- Extract
block_hash - Check for deduplication in KV store
- If new:
- Store hash in KV
- Forward payload to downstream endpoint
- log event and stats in KV
- If duplicate:
- Drop payload silently
- log event and stats in KV
Namespace: KV_BLOCKS
- Key: block hash (e.g.,
blk_0xabc123...) - Value: typed object that includes
"delivered", timestamp, helpful info - TTL: Infinite, if we need to update can overwrite but not expecting to
Namespace: KV_LOGS
- Key: ISO timestamp, something that auto sorts itself like YYYYMMDD but more unique
- Value: typed object that represents a possible outcome e.g. SUCCESS, ERROR with detail where appropriate
- TTL: Infinite, can bundle up and store in R2 in later phase
KV_BLOCKS– KV namespace for deduplication of blocksKV_LOGS- KV namespace for any logged messagesDESTINATION_URL– initial destination for payloads (delivered via POST)
Create a consistent object structure and make sure everything has exported TypeScript types for easy reference.
We will use a downstream UI to read and interpret the data from KV separate to the main project here.
| Event | Log Message |
|---|---|
| Startup | "DO started for API key: {key}" |
| Hook creation | "Created chainhook: {id}" |
| Incoming webhook | "Received block: {block_hash}" |
| Forwarded | "Forwarded block {block_hash} to RelayWorker" |
| Health check | "Checking chainhook health" |
| Recreation | "Recreated chainhook for {key}" |
| Error | "Error handling block {block_hash}: {error}" |
| Event | Log Message |
|---|---|
| Incoming | "Received block: {block_hash}" |
| Duplicate | "Duplicate block: {block_hash}" |
| Forwarded | "Forwarded block {block_hash} to {destination}" |
| Failed forward | "Failed to deliver block {block_hash}: {status}" |
- Fan-out to multiple destinations
- Retry and queueing for failed deliveries
- Chain reorg detection and rollback handling
- Signature verification of incoming payloads
- Dashboard for chainhook status and logs
This document forms the foundation for the implementation task plan.
Tasks will include:
- DO scaffold with fetch + alarm
- Chainhook API integration
- Worker with KV dedup and forward logic
- Logging utility functions
- Deployment scripts + testing
- Each block has a globally unique
block_hash, making it ideal for use as the KV deduplication key. - No payload filtering is done at this stage — every anchored block is delivered.