Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PredicateHealthCheck re-register bug #674

Open
zone117x opened this issue Oct 31, 2024 · 0 comments
Open

PredicateHealthCheck re-register bug #674

zone117x opened this issue Oct 31, 2024 · 0 comments
Assignees

Comments

@zone117x
Copy link
Member

The chainhook client healthcheck code detects inactive predicates, and re-registers using the same predicate from when the app was started.

This causes chainhook to re-send old events starting at the block_height that the client specified on startup.

async function startChainhookServer() {
  const blockHeight = await db.getChainTipBlockHeight();
  const predicate = {
    name: 'metadata-api-blocks',
    version: 1,
    chain: 'stacks',
    networks: {
      mainnet: {
        start_block: blockHeight, // <-- predicate re-registration uses whatever this value was on app start
        include_contract_abi: true,
        if_this: {
          scope: 'block_height',
          higher_than: 1,
        },
      },
    },
  };
  const observer: EventObserverOptions = {
    predicate_health_check_interval_ms: 300_000,
    // ...
  };
  const server = new ChainhookEventObserver(observer, { ... });
  await server.start([predicate], payload => db.processPayload(payload));
}

This could be solved with something like a callback where the client can provide an updated predicate for re-registration. E.g.:

  const observer: EventObserverOptions = {
    predicate_health_check_interval_ms: 300_000,
    predicate_reregister_callback: async (predicate) => {
      predicate.networks.mainnet.start_block = await db.getChainTipBlockHeight();
      return predicate;
    },
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants