Page MenuHomePhabricator

[Chronik] Add `/pause` and `/resume` endpoints
ClosedPublic

Authored by tobias_ruck on Aug 18 2023, 05:42.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC49de3da617bb: [Chronik] Add `/pause` and `/resume` endpoints
Summary

Background: This is added so we can reproduce the bug in D14361. It only occurs when Chronik is lagging behind the node, so to simulate this, we allow pausing and resuming Chronik indexing.

Note that this only pauses the indexing, querying the indexer still works fine (it might return old data though).

A commented-out reproduction of the bug mentioned in D14361 can be found in chronik_pause.py, this should be uncommented once the bug is fixed.

We enable pausing in Chronik by adding a pair of Pause and PauseNotify structs:

  • Pause::block_if_paused allows blocking the thread if paused, until resumed by PauseNotify.
  • PauseNotify blocks subsequent calls to Pause::block_if_paused, or resumes them.

Since we use the newer wait_for function of tokio, we update the tokio version to the most recent version.

Pause doesn't need to be behind any lock, so it won't result in a deadlock when e.g. trying to read from Chronik.

However, any call to SyncWithValidationInterfaceQueue while paused would block forever; this means we can't use the RPC methods like sendrawtransaction, submitblock, invalidateblock etc., we can however use the P2P network directly, e.g. with send_txs_and_test and send_blocks_and_test.

Test Plan

ninja && ./test/functional/test_runner.py chronik_pause

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

tobias_ruck updated this revision to Diff 41846.

fix fmt

Fabien added inline comments.
chronik/chronik-cpp/chronik.cpp
33 ↗(On Diff #41846)

Nit: in this special case it's probably safer to have the flag AND'ed with the IsTestChain() methode from chainparams.h, as you really never want this to be set on mainnet (with some warning in the log).

This revision is now accepted and ready to land.Aug 18 2023, 10:39

add InitError when using -chronikallowpause on mainnet, fix some comments