Skip to content

Commit ed47949

Browse files
committed
Merge bitcoin#23398: rpc: add return message to savemempool RPC
aa1a4c9 Add file validation to savemempool RPC test (lsilva01) 871e64d Add filename to savemempool RPC result (lsilva01) Pull request description: Currently, if the user calls the `savemempool` RPC method, there is no way to know where the file was created (unless the user knows internal implementation details). This PR adds a return message stating the file name and path where the mempool was saved and changes `mempool_persist.py` to validate this new return message. ACKs for top commit: laanwj: Code review ACK aa1a4c9 Tree-SHA512: e8b1dd0a8976e5eb15f7476c9651e492d2c621a67e0b726721fa7a2ae0ddd272ee28b87a2d0c650bd635e07fa96bdefe77bece4deb6486ef3ee9a4f83423a840
2 parents 8f86820 + aa1a4c9 commit ed47949

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/rpc/blockchain.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,11 @@ static RPCHelpMan savemempool()
22022202
return RPCHelpMan{"savemempool",
22032203
"\nDumps the mempool to disk. It will fail until the previous dump is fully loaded.\n",
22042204
{},
2205-
RPCResult{RPCResult::Type::NONE, "", ""},
2205+
RPCResult{
2206+
RPCResult::Type::OBJ, "", "",
2207+
{
2208+
{RPCResult::Type::STR, "filename", "the directory and file where the mempool was saved"},
2209+
}},
22062210
RPCExamples{
22072211
HelpExampleCli("savemempool", "")
22082212
+ HelpExampleRpc("savemempool", "")
@@ -2211,6 +2215,8 @@ static RPCHelpMan savemempool()
22112215
{
22122216
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
22132217

2218+
const NodeContext& node = EnsureAnyNodeContext(request.context);
2219+
22142220
if (!mempool.IsLoaded()) {
22152221
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
22162222
}
@@ -2219,7 +2225,10 @@ static RPCHelpMan savemempool()
22192225
throw JSONRPCError(RPC_MISC_ERROR, "Unable to dump mempool to disk");
22202226
}
22212227

2222-
return NullUniValue;
2228+
UniValue ret(UniValue::VOBJ);
2229+
ret.pushKV("filename", fs::path((node.args->GetDataDirNet() / "mempool.dat")).u8string());
2230+
2231+
return ret;
22232232
},
22242233
};
22252234
}

test/functional/mempool_persist.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,9 @@ def run_test(self):
149149
mempooldat1 = os.path.join(self.nodes[1].datadir, self.chain, 'mempool.dat')
150150
self.log.debug("Remove the mempool.dat file. Verify that savemempool to disk via RPC re-creates it")
151151
os.remove(mempooldat0)
152-
self.nodes[0].savemempool()
152+
result0 = self.nodes[0].savemempool()
153153
assert os.path.isfile(mempooldat0)
154+
assert_equal(result0['filename'], mempooldat0)
154155

155156
self.log.debug("Stop nodes, make node1 use mempool.dat from node0. Verify it has 6 transactions")
156157
os.rename(mempooldat0, mempooldat1)

0 commit comments

Comments
 (0)