From 2e8072edbeb20a8c05c0dbd06ca105bc4dd07b96 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Tue, 24 Dec 2024 01:31:55 +0100 Subject: [PATCH] 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 --- src/rpc/blockchain.cpp | 11 +++++++---- src/util/fs.h | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 475c5ca41c9..3beea79f419 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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("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; diff --git a/src/util/fs.h b/src/util/fs.h index 147904d030a..dce371cc5ef 100644 --- a/src/util/fs.h +++ b/src/util/fs.h @@ -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)