MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / importmempool

Function importmempool

src/rpc/mempool.cpp:1127–1186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1125}
1126
1127static RPCMethod importmempool()
1128{
1129 return RPCMethod{
1130 "importmempool",
1131 "Import a mempool.dat file and attempt to add its contents to the mempool.\n"
1132 "Warning: Importing untrusted files is dangerous, especially if metadata from the file is taken over.",
1133 {
1134 {"filepath", RPCArg::Type::STR, RPCArg::Optional::NO, "The mempool file"},
1135 {"options",
1136 RPCArg::Type::OBJ_NAMED_PARAMS,
1137 RPCArg::Optional::OMITTED,
1138 "",
1139 {
1140 {"use_current_time", RPCArg::Type::BOOL, RPCArg::Default{true},
1141 "Whether to use the current system time or use the entry time metadata from the mempool file.\n"
1142 "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior."},
1143 {"apply_fee_delta_priority", RPCArg::Type::BOOL, RPCArg::Default{false},
1144 "Whether to apply the fee delta metadata from the mempool file.\n"
1145 "It will be added to any existing fee deltas.\n"
1146 "The fee delta can be set by the prioritisetransaction RPC.\n"
1147 "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior.\n"
1148 "Only set this bool if you understand what it does."},
1149 {"apply_unbroadcast_set", RPCArg::Type::BOOL, RPCArg::Default{false},
1150 "Whether to apply the unbroadcast set metadata from the mempool file.\n"
1151 "Warning: Importing untrusted metadata may lead to unexpected issues and undesirable behavior."},
1152 },
1153 RPCArgOptions{.oneline_description = "options"}},
1154 },
1155 RPCResult{RPCResult::Type::OBJ, "", "", std::vector<RPCResult>{}},
1156 RPCExamples{HelpExampleCli("importmempool", "/path/to/mempool.dat") + HelpExampleRpc("importmempool", "/path/to/mempool.dat")},
1157 [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue {
1158 const NodeContext& node{EnsureAnyNodeContext(request.context)};
1159
1160 CTxMemPool& mempool{EnsureMemPool(node)};
1161 ChainstateManager& chainman = EnsureChainman(node);
1162 Chainstate& chainstate = chainman.ActiveChainstate();
1163
1164 if (chainman.IsInitialBlockDownload()) {
1165 throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Can only import the mempool after the block download and sync is done.");
1166 }
1167
1168 const fs::path load_path{fs::u8path(self.Arg<std::string_view>("filepath"))};
1169 const UniValue& use_current_time{request.params[1]["use_current_time"]};
1170 const UniValue& apply_fee_delta{request.params[1]["apply_fee_delta_priority"]};
1171 const UniValue& apply_unbroadcast{request.params[1]["apply_unbroadcast_set"]};
1172 node::ImportMempoolOptions opts{
1173 .use_current_time = use_current_time.isNull() ? true : use_current_time.get_bool(),
1174 .apply_fee_delta_priority = apply_fee_delta.isNull() ? false : apply_fee_delta.get_bool(),
1175 .apply_unbroadcast_set = apply_unbroadcast.isNull() ? false : apply_unbroadcast.get_bool(),
1176 };
1177
1178 if (!node::LoadMempool(mempool, load_path, chainstate, std::move(opts))) {
1179 throw JSONRPCError(RPC_MISC_ERROR, "Unable to import mempool file, see debug log for details.");
1180 }
1181
1182 UniValue ret{UniValue::VOBJ};
1183 return ret;
1184 },

Callers

nothing calls this directly

Calls 8

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
u8pathFunction · 0.85
LoadMempoolFunction · 0.85
isNullMethod · 0.80
get_boolMethod · 0.80

Tested by

no test coverage detected