Skip to content

Commit 790a98a

Browse files
theStackluke-jr
andcommitted
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 <[email protected]>
1 parent 43e71f7 commit 790a98a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/rpc/blockchain.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -3010,11 +3010,13 @@ static RPCHelpMan dumptxoutset()
30103010

30113011
const ArgsManager& args{EnsureAnyArgsman(request.context)};
30123012
const fs::path path = fsbridge::AbsPathJoin(args.GetDataDirNet(), fs::u8path(request.params[0].get_str()));
3013+
const auto path_info{fs::status(path)};
30133014
// Write to a temporary path and then move into `path` on completion
30143015
// to avoid confusion due to an interruption.
3015-
const fs::path temppath = fsbridge::AbsPathJoin(args.GetDataDirNet(), fs::u8path(request.params[0].get_str() + ".incomplete"));
3016+
const fs::path temppath = fs::is_fifo(path_info) ? path : // If a named pipe is passed, write directly to it
3017+
fsbridge::AbsPathJoin(args.GetDataDirNet(), fs::u8path(request.params[0].get_str() + ".incomplete"));
30163018

3017-
if (fs::exists(path)) {
3019+
if (fs::exists(path_info) && !fs::is_fifo(path_info)) {
30183020
throw JSONRPCError(
30193021
RPC_INVALID_PARAMETER,
30203022
path.utf8string() + " already exists. If you are sure this is what you want, "
@@ -3091,7 +3093,7 @@ static RPCHelpMan dumptxoutset()
30913093
}
30923094

30933095
UniValue result = WriteUTXOSnapshot(*chainstate, cursor.get(), &stats, tip, afile, path, temppath, node.rpc_interruption_point);
3094-
fs::rename(temppath, path);
3096+
if (!fs::is_fifo(path_info)) fs::rename(temppath, path);
30953097

30963098
result.pushKV("path", path.utf8string());
30973099
return result;

src/util/fs.h

+4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ static inline bool exists(const path& p)
9090
{
9191
return std::filesystem::exists(p);
9292
}
93+
static inline bool exists(const std::filesystem::file_status& s)
94+
{
95+
return std::filesystem::exists(s);
96+
}
9397

9498
// Allow explicit quoted stream I/O.
9599
static inline auto quoted(const std::string& s)

0 commit comments

Comments
 (0)