HomePhabricator

rest: Pass in NodeContext to rest_block and use it

Description

rest: Pass in NodeContext to rest_block and use it

Summary:
Note: The third commit fixes an issue introduced by the second, when the node context does not have a chainmanager.

rest: Pass in NodeContext to rest_block

https://github.com/bitcoin/bitcoin/pull/21391/commits/3f0893479908ca28d6127c8d0ada30737cb830be

rest: Use existing NodeContext

https://github.com/bitcoin/bitcoin/pull/21391/commits/d7824acdb9b18fe8f151771a83ccae1681f16c66

rest: Add GetChainman function and use it

This is not the cleanest change but:

  1. It fixes the erroneous use of RPC's Ensure*() in rest.cpp, which cause crashes in REST contexts.

    RPC code wraps all calls in a try/except, REST code does not. Ensure*(), being part of RPC, expects that its throw's will get caught by a try/except. But if you use Ensure*() in REST code, since it doesn't have a try/except wrap, a crash will happen.
  1. It is consistent with other functions like GetMemPool.

Someone can probably make this a bit prettier.

https://github.com/bitcoin/bitcoin/pull/21767/commits/9ecade14252ad1972f668d2d2e4ef44fdfcb944a

This is a backport of core#21391 [6 & 7/14]

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Subscribers: Fabien

Differential Revision: https://reviews.bitcoinabc.org/D11584

Details

Provenance
Carl Dong <contact@carldong.me>Authored on Sep 2 2020, 21:24
PiRKCommitted on Jun 9 2022, 16:19
PiRKPushed on Jun 9 2022, 16:19
Reviewer
Restricted Project
Differential Revision
D11584: rest: Pass in NodeContext to rest_block and use it
Parents
rABC4737c56915cc: [avalanche] Respond to missing proof indices request
Branches
Unknown
Tags
Unknown