Page MenuHomePhabricator

[chronik] Electrum: add the blockchain.headers.subscribe endpoint
Changes PlannedPublic

Authored by Fabien on Thu, May 8, 21:05.

Details

Reviewers
None
Group Reviewers
Restricted Project
Summary

Subscribe to get the new header when a block is connected.

Test Plan

TODO: needs integration tests

In terminal 1:

./src/bitcoind -regtest -debug=chronik -chronik -chronikscripthashindex -chronikelectrumbind="127.0.0.1:50001"

In terminal 2 (can be done in several terminals):

echo '{"jsonrpc": "2.0", "method": "blockchain.headers.subscribe", "params": [], "id": "test"}' | nc 127.0.0.1 50001 | jq

in terminal 3:

./src/bitcoin-cli -regtest create regtest
./src/bitcoin-cli -regtest -generate 1

Event Timeline

tobias_ruck added inline comments.
chronik/chronik-indexer/src/subs.rs
65

is reusing subs_block not an option?

chronik/chronik-indexer/src/subs.rs
65

Could be, but I'm only interested in the connection event so having a different broadcast channel makes the code a bit simpler

chronik/chronik-indexer/src/subs.rs
65

Well you add a lot of complexity in subs.rs (which is kind of a common shared module) in order to remove a if msg.msg_type != BlockMsgType::Connected { continue; } in your code, which seem suboptimal

Reuse block subscription. This requires to add a filter on the event but overall simplifies the code.

Fabien published this revision for review.Fri, May 9, 10:00
Fabien planned changes to this revision.

still missing the tests