From fab80fef61ddd4afeff6e497c7e76bffcd05e8a4 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 14 Jun 2020 14:17:24 -0400 Subject: [PATCH] refactor: Remove unused EnsureChainman --- src/init.cpp | 5 +++-- src/node/context.h | 6 ------ src/rpc/blockchain.cpp | 5 ++++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index fd7c8d0f801..41b4700dde5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -1377,9 +1378,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node) node.mempool = &::mempool; assert(!node.chainman); node.chainman = &g_chainman; - ChainstateManager& chainman = EnsureChainman(node); + ChainstateManager& chainman = *Assert(node.chainman); - node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, *node.chainman, *node.mempool)); + node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), *node.scheduler, chainman, *node.mempool)); RegisterValidationInterface(node.peer_logic.get()); // sanitize comments per BIP-0014, format user agent and check total size diff --git a/src/node/context.h b/src/node/context.h index c45d9e66893..c783c39cd64 100644 --- a/src/node/context.h +++ b/src/node/context.h @@ -49,10 +49,4 @@ struct NodeContext { ~NodeContext(); }; -inline ChainstateManager& EnsureChainman(const NodeContext& node) -{ - assert(node.chainman); - return *node.chainman; -} - #endif // BITCOIN_NODE_CONTEXT_H diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 8252af3ee60..cd1b27490dd 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -75,7 +75,10 @@ CTxMemPool& EnsureMemPool(const util::Ref& context) ChainstateManager& EnsureChainman(const util::Ref& context) { NodeContext& node = EnsureNodeContext(context); - return EnsureChainman(node); + if (!node.chainman) { + throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found"); + } + return *node.chainman; } /* Calculate the difficulty for a given block index.