rpc: support writing UTXO set dump (dumptxoutset) to a named pipe

This allows external tooling (e.g. converters) to consume the output
directly, rather than having to write the dump to disk first and then
read it from there again.

Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
This commit is contained in:
Sebastian Falbesoner 2024-12-24 01:31:55 +01:00
parent fc39a4f568
commit 2e8072edbe
2 changed files with 11 additions and 4 deletions

View File

@ -3109,11 +3109,12 @@ static RPCHelpMan dumptxoutset()
const ArgsManager& args{EnsureAnyArgsman(request.context)};
const fs::path path = fsbridge::AbsPathJoin(args.GetDataDirNet(), fs::u8path(self.Arg<std::string_view>("path")));
const auto path_info{fs::status(path)};
// Write to a temporary path and then move into `path` on completion
// to avoid confusion due to an interruption.
const fs::path temppath = path + ".incomplete";
// to avoid confusion due to an interruption. If a named pipe passed, write directly to it.
const fs::path temppath = fs::is_fifo(path_info) ? path : path + ".incomplete";
if (fs::exists(path)) {
if (fs::exists(path_info) && !fs::is_fifo(path_info)) {
throw JSONRPCError(
RPC_INVALID_PARAMETER,
path.utf8string() + " already exists. If you are sure this is what you want, "
@ -3197,7 +3198,9 @@ static RPCHelpMan dumptxoutset()
path,
temppath,
node.rpc_interruption_point);
fs::rename(temppath, path);
if (!fs::is_fifo(path_info)) {
fs::rename(temppath, path);
}
result.pushKV("path", path.utf8string());
return result;

View File

@ -96,6 +96,10 @@ static inline bool exists(const path& p)
{
return std::filesystem::exists(p);
}
static inline bool exists(const std::filesystem::file_status& s)
{
return std::filesystem::exists(s);
}
// Allow explicit quoted stream I/O.
static inline auto quoted(const std::string& s)