Skip to content

Commit 929f08e

Browse files
authored
fix: update chainhook predicate start_block upon re-registration (#308)
* fix: update chainhook predicate start_block upon re-registration * fix: add missing test fields * style: consider ENV network
1 parent ba39a59 commit 929f08e

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-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: 13 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,18 @@ 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+
switch (ENV.NETWORK) {
73+
case 'mainnet':
74+
if (predicate.networks.mainnet) predicate.networks.mainnet.start_block = blockHeight;
75+
break;
76+
case 'testnet':
77+
if (predicate.networks.testnet) predicate.networks.testnet.start_block = blockHeight;
78+
break;
79+
}
80+
return predicate as Predicate;
81+
},
6982
};
7083
const chainhook: ChainhookNodeOptions = {
7184
base_url: `http://${ENV.CHAINHOOK_NODE_RPC_HOST}:${ENV.CHAINHOOK_NODE_RPC_PORT}`,

tests/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ export class TestChainhookPayloadBuilder {
12901290
},
12911291
is_streaming_blocks: true,
12921292
},
1293+
events: [],
12931294
};
12941295
private action: 'apply' | 'rollback' = 'apply';
12951296
private get lastBlock(): StacksEvent {
@@ -1330,6 +1331,13 @@ export class TestChainhookPayloadBuilder {
13301331
pox_cycle_length: 2100,
13311332
pox_cycle_position: 1722,
13321333
stacks_block_hash: '0xbccf63ec2438cf497786ce617ec7e64e2b27ee023a28a0927ee36b81870115d2',
1334+
tenure_height: null,
1335+
block_time: null,
1336+
signer_bitvec: null,
1337+
signer_signature: null,
1338+
signer_public_keys: null,
1339+
cycle_number: null,
1340+
reward_set: null,
13331341
},
13341342
parent_block_identifier: {
13351343
hash: '0xca71af03f9a3012491af2f59f3244ecb241551803d641f8c8306ffa1187938b4',

0 commit comments

Comments
 (0)