Page MenuHomePhabricator

[chronik] implement blockchain.block.header electrum method
Needs RevisionPublic

Authored by PiRK on Tue, Jan 7, 14:30.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Summary

Return the block header at the given height. If cp_height is zero, return the raw block header as a hexadecimal string. Otherwise a dictionary with the raw block header, the merkle root of all headers up to and including cp_height, and the merkle branch of header up to root.

See https://electrum-cash-protocol.readthedocs.io/en/latest/protocol-methods.html#blockchain-block-header

Test Plan

ninja check-functional

On mainnet, check results against fulcrum:

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

echo '{"jsonrpc": "2.0", "method": "blockchain.block.header",  "params": [400000, 800000], "id": "test"}' | nc 127.0.0.1 50001
echo '{"jsonrpc": "2.0", "method": "blockchain.block.header",  "params": [400000, 800000], "id": "test"}' | nc electrum.bitcoinabc.org 50001

Event Timeline

Tail of the build log:

    Checking postcard v1.1.1
    Checking serde_spanned v0.6.8
    Checking toml_datetime v0.6.8
   Compiling pyo3 v0.23.3
    Checking seahash v4.1.0
    Checking sync_wrapper v1.0.2
    Checking topo_sort v0.4.0
    Checking winnow v0.6.20
    Checking axum-core v0.4.5
    Checking chronik-plugin-common v0.1.0 (/work/chronik/chronik-plugin-common)
    Checking karyon_core v0.2.0
    Checking chronik-plugin v0.1.0 (/work/chronik/chronik-plugin)
   Compiling chronik-proto v0.1.0 (/work/chronik/chronik-proto)
    Checking hyper v1.5.1
   Compiling karyon_jsonrpc_macro v0.2.0
    Checking tokio-tungstenite v0.24.0
    Checking tower v0.5.1
   Compiling chronik-bridge v0.1.0 (/work/chronik/chronik-bridge)
    Checking hyper-util v0.1.10
    Checking memoffset v0.9.1
    Checking futures-executor v0.3.31
    Checking serde_urlencoded v0.7.1
    Checking serde_path_to_error v0.1.16
    Checking unicode-segmentation v1.12.0
    Checking base64 v0.22.1
    Checking unindent v0.2.3
    Checking matchit v0.7.3
    Checking tower-http v0.5.2
    Checking toml_edit v0.22.22
    Checking futures v0.3.31
    Checking convert_case v0.6.0
    Checking axum v0.7.9
   Compiling librocksdb-sys v0.11.0+8.1.1
   Compiling pyo3-macros v0.23.3
    Checking toml v0.8.19
    Checking chronik-plugin-impl v0.1.0 (/work/chronik/chronik-plugin-impl)
   Compiling aws-lc-rs v1.11.1
   Compiling rustls v0.23.19
    Checking rustls-webpki v0.102.8
    Checking tokio-rustls v0.26.1
    Checking karyon_async_rustls v0.2.0
    Checking karyon_net v0.2.0
    Checking karyon_jsonrpc v0.2.0
    Checking rocksdb v0.21.0
    Checking chronik-db v0.1.0 (/work/chronik/chronik-db)
    Checking chronik-indexer v0.1.0 (/work/chronik/chronik-indexer)
    Checking chronik-http v0.1.0 (/work/chronik/chronik-http)
error: deref which would be done by auto-deref
   --> chronik/chronik-http/src/electrum.rs:401:44
    |
401 |                 "root": be_bytes_to_le_hex(&*proto_header.root),
    |                                            ^^^^^^^^^^^^^^^^^^^ help: try: `&proto_header.root`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
    = note: `-D clippy::explicit-auto-deref` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::explicit_auto_deref)]`

error: could not compile `chronik-http` (lib) due to 1 previous error
ninja: build stopped: cannot make progress due to previous errors.
Build build-chronik failed with exit code 1

Tail of the build log:

    Checking url v2.5.4
    Checking chronik-plugin-common v0.1.0 (/work/chronik/chronik-plugin-common)
    Checking toml_datetime v0.6.8
    Checking chronik-plugin v0.1.0 (/work/chronik/chronik-plugin)
    Checking serde_spanned v0.6.8
   Compiling pyo3 v0.23.3
    Checking seahash v4.1.0
   Compiling chronik-proto v0.1.0 (/work/chronik/chronik-proto)
    Checking topo_sort v0.4.0
    Checking sync_wrapper v1.0.2
    Checking winnow v0.6.20
    Checking karyon_core v0.2.0
    Checking hyper v1.5.1
    Checking axum-core v0.4.5
    Checking tokio-tungstenite v0.24.0
   Compiling karyon_jsonrpc_macro v0.2.0
    Checking tower v0.5.1
   Compiling chronik-bridge v0.1.0 (/work/chronik/chronik-bridge)
    Checking hyper-util v0.1.10
    Checking memoffset v0.9.1
    Checking serde_urlencoded v0.7.1
    Checking futures-executor v0.3.31
    Checking serde_path_to_error v0.1.16
    Checking matchit v0.7.3
    Checking unicode-segmentation v1.12.0
    Checking unindent v0.2.3
    Checking base64 v0.22.1
    Checking tower-http v0.5.2
    Checking futures v0.3.31
    Checking convert_case v0.6.0
    Checking toml_edit v0.22.22
   Compiling librocksdb-sys v0.11.0+8.1.1
    Checking axum v0.7.9
   Compiling pyo3-macros v0.23.3
    Checking toml v0.8.19
    Checking chronik-plugin-impl v0.1.0 (/work/chronik/chronik-plugin-impl)
   Compiling aws-lc-rs v1.11.1
   Compiling rustls v0.23.19
    Checking rustls-webpki v0.102.8
    Checking tokio-rustls v0.26.1
    Checking karyon_async_rustls v0.2.0
    Checking karyon_net v0.2.0
    Checking karyon_jsonrpc v0.2.0
    Checking rocksdb v0.21.0
    Checking chronik-db v0.1.0 (/work/chronik/chronik-db)
    Checking chronik-indexer v0.1.0 (/work/chronik/chronik-indexer)
    Checking chronik-http v0.1.0 (/work/chronik/chronik-http)
error: deref which would be done by auto-deref
   --> chronik/chronik-http/src/electrum.rs:401:44
    |
401 |                 "root": be_bytes_to_le_hex(&*proto_header.root),
    |                                            ^^^^^^^^^^^^^^^^^^^ help: try: `&proto_header.root`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref
    = note: `-D clippy::explicit-auto-deref` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(clippy::explicit_auto_deref)]`

error: could not compile `chronik-http` (lib) due to 1 previous error
ninja: build stopped: cannot make progress due to previous errors.
Build build-chronik-plugins failed with exit code 1
PiRK edited the summary of this revision. (Show Details)
PiRK edited the test plan for this revision. (Show Details)

add tests

revert accidental deletion of other test (fixme: in a different diff actually run test_transaction_get)

PiRK published this revision for review.Tue, Jan 7, 15:14
Fabien requested changes to this revision.Tue, Jan 7, 21:58
Fabien added a subscriber: Fabien.
Fabien added inline comments.
chronik/chronik-http/src/electrum.rs
371

Now that the custom error with String has been merged you should use that. You can change the package version to use the github commit with the change until it's released

This revision now requires changes to proceed.Tue, Jan 7, 21:58