Skip to content

Commit 5e61f2c

Browse files
committed
fix: update chainhook predicate start_block upon re-registration
1 parent ba39a59 commit 5e61f2c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"@fastify/type-provider-typebox": "^3.2.0",
5959
"@google-cloud/storage": "^7.12.1",
6060
"@hirosystems/api-toolkit": "^1.7.1",
61-
"@hirosystems/chainhook-client": "^2.0.0",
61+
"@hirosystems/chainhook-client": "^2.4.0",
6262
"@sinclair/typebox": "^0.28.17",
6363
"@stacks/transactions": "^6.1.0",
6464
"@types/node": "^20.16.1",

src/chainhook/server.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
EventObserverOptions,
55
EventObserverPredicate,
66
Payload,
7+
Predicate,
78
StacksPayload,
89
} from '@hirosystems/chainhook-client';
910
import { PgStore } from '../pg/pg-store';
@@ -66,6 +67,16 @@ export async function startChainhookServer(args: { db: PgStore }): Promise<Chain
6667
predicate_disk_file_path: ENV.CHAINHOOK_PREDICATE_PATH,
6768
predicate_health_check_interval_ms: 300_000,
6869
node_type: 'chainhook',
70+
predicate_re_register_callback: async predicate => {
71+
const blockHeight = await args.db.getChainTipBlockHeight();
72+
if (predicate.networks.mainnet) {
73+
predicate.networks.mainnet.start_block = blockHeight;
74+
}
75+
if (predicate.networks.testnet) {
76+
predicate.networks.testnet.start_block = blockHeight;
77+
}
78+
return predicate as Predicate;
79+
},
6980
};
7081
const chainhook: ChainhookNodeOptions = {
7182
base_url: `http://${ENV.CHAINHOOK_NODE_RPC_HOST}:${ENV.CHAINHOOK_NODE_RPC_PORT}`,

0 commit comments

Comments
 (0)