What changed, and why it matters
This commit changes the /submit_raw_tx endpoint so that callers now receive clearer HTTP status codes and error reasons when the Monero daemon rejects or fails to relay a transaction. It also fixes a bug where the local mempool was incorrectly updated even when the daemon did not actually relay the transaction. The change improves API correctness and reduces confusion, but it does not appear to fix a critical security vulnerability.
Review the new status-code behavior for API consumers and ensure monitoring/alerting treats 422 responses appropriately. No urgent security patch is indicated, but operators should confirm the mempool-only-on-relayed change matches expected wallet behavior.
Security signals we found
Behavioral change in error handling for transaction submission endpoint
Local mempool no longer updated when daemon reports relayed=false
HTTP status codes now distinguish client errors (400), daemon rejection (422), and accepted-but-not-relayed (200)
Daemon error details propagated to REST client
Evidence from the diff
The patch refactors the internal response type from copyable_slice to http_response so HTTP status codes can be carried through the async completion chain. For /submit_raw_tx it now distinguishes three outcomes: (1) malformed input -> 400, (2) daemon rejects tx -> 422 with the daemon’s reason, (3) daemon accepts but does not relay -> 200 with reason=’Not relayed’ and not_relayed=true. Previously the endpoint returned 200 OK and silently added the transaction to the local mempool even when relayed=false. The mempool update is now gated on the relayed flag. The daemon’s error string and message are propagated through rpc::client to the REST response.
Changed components
docs/api/wallet.yamlsrc/rest_server.cppsrc/rpc/client.cppsrc/rpc/light_wallet.cppsrc/rpc/light_wallet.htests/unit/rest.test.cppInspect captured patch +119 / −27
### docs/api/wallet.yaml
@@ -705,13 +705,38 @@ paths:
type: object
properties:
status:
- description: Typically the response by the monero daemon attempting to relay the transaction.
+ description: Always `OK`.
type: string
example: "OK"
+ reason:
+ description: "`Not relayed` when the daemon accepts the transaction but does not relay it. Not present otherwise."
+ type: string
+ example: "Not relayed"
+ not_relayed:
+ description: "`true` when the daemon accepts the transaction but does not relay it. Not present otherwise."
+ type: boolean
required:
- status
'400':
- description: Invalid JSON.
+ description: Invalid JSON, or the transaction cannot be parsed.
+ '422':
+ description: The daemon rejects the transaction.
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ status:
+ description: Always `Failed`.
+ type: string
+ example: "Failed"
+ reason:
+ description: The reason from the daemon. The daemon joins more than one reason with ` and `.
+ type: string
+ example: "double spend and fee too low"
+ required:
+ - status
+ - reason
'405':
description: Not `POST` method.
'500':
### src/rest_server.cpp
@@ -194,28 +194,32 @@ namespace lws
}
};
- struct copyable_slice
+ struct http_response
{
epee::byte_slice value;
+ boost::beast::http::status status;
- copyable_slice(epee::byte_slice value) noexcept
- : value(std::move(value))
+ http_response(epee::byte_slice value, const boost::beast::http::status status = boost::beast::http::status::ok) noexcept
+ : value(std::move(value)), status(status)
{}
- copyable_slice(copyable_slice&&) = default;
- copyable_slice(const copyable_slice& rhs) noexcept
- : value(rhs.value.clone())
+ http_response(http_response&&) = default;
+ http_response(const http_response& rhs) noexcept
+ : value(rhs.value.clone()), status(rhs.status)
{}
- copyable_slice& operator=(copyable_slice&&) = default;
- copyable_slice& operator=(const copyable_slice& rhs) noexcept
+ http_response& operator=(http_response&&) = default;
+ http_response& operator=(const http_response& rhs) noexcept
{
if (this != std::addressof(rhs))
+ {
value = rhs.value.clone();
+ status = rhs.status;
+ }
return *this;
}
};
- using async_complete = void(expect<copyable_slice>);
+ using async_complete = void(expect<http_response>);
bool is_locked(std::uint64_t unlock_time, db::block_id last, db::block_id tx_height) noexcept
{
@@ -340,7 +344,7 @@ namespace lws
: boost::asio::coroutine(), self_(std::move(self))
{}
- void send_response(const boost::system::error_code error, const expect<copyable_slice>& value)
+ void send_response(const boost::system::error_code error, const expect<http_response>& value)
{
assert(self_ != nullptr);
assert(self_->strand.running_in_this_thread());
@@ -626,7 +630,7 @@ namespace lws
: self_(std::move(self))
{}
- void send_response(const boost::system::error_code error, expect<copyable_slice> value) const
+ void send_response(const boost::system::error_code error, expect<http_response> value) const
{
assert(self_ != nullptr);
@@ -1509,7 +1513,7 @@ namespace lws
: boost::asio::coroutine(), self_(std::move(self))
{}
- void send_response(const boost::system::error_code error, expect<copyable_slice> value)
+ void send_response(const boost::system::error_code error, expect<http_response> value, const bool relayed = false)
{
assert(self_ != nullptr);
assert(self_->strand.running_in_this_thread());
@@ -1527,7 +1531,7 @@ namespace lws
}
else
{
- if (value && self_->parent && self_->parent->mempool)
+ if (relayed && self_->parent && self_->parent->mempool)
self_->parent->mempool->add_txs({std::addressof(std::get<2>(self_->resumers.front())), 1});
MDEBUG("Completed ZMQ request in /submit_raw_tx");
@@ -1613,12 +1617,21 @@ namespace lws
const expect<void> status =
rpc::parse_response(daemon_resp, std::move(self.in));
- if (!status)
+ if (!status && daemon_resp.status == cryptonote::rpc::Message::STATUS_FAILED)
+ {
+ expect<epee::byte_slice> body =
+ json_response(async_response{daemon_resp.status, daemon_resp.error_details});
+ if (body)
+ send_response({}, http_response{std::move(*body), boost::beast::http::status::unprocessable_entity});
+ else
+ send_response({}, body.error());
+ }
+ else if (!status)
send_response({}, status.error());
else if (!daemon_resp.relayed)
- send_response({}, {lws::error::tx_relay_failed});
+ send_response({}, json_response(async_response{"OK", "Not relayed", true}));
else
- send_response({}, json_response(async_response{"OK"}));
+ send_response({}, json_response(async_response{"OK"}), true);
}
}
}
@@ -1986,7 +1999,7 @@ namespace lws
MINFO("REST error: " << error.message() << " from " << sock().remote_endpoint(ec) << " / " << this);
assert(strand_.running_in_this_thread());
- if (error.category() == wire::error::rapidjson_category() || error == lws::error::invalid_range || error == lws::error::not_enough_amount)
+ if (error.category() == wire::error::rapidjson_category() || error == lws::error::invalid_range || error == lws::error::not_enough_amount || error == lws::error::bad_client_tx)
return bad_request(boost::beast::http::status::bad_request, std::forward<F>(resume));
else if (error == lws::error::bad_verb)
return bad_request(boost::beast::http::status::method_not_allowed, std::forward<F>(resume));
@@ -2000,12 +2013,12 @@ namespace lws
}
template<typename F>
- void valid_request(epee::byte_slice body, F&& resume)
+ void valid_request(epee::byte_slice body, F&& resume, const boost::beast::http::status status = boost::beast::http::status::ok)
{
- MDEBUG("Sending HTTP 200 OK (" << body.size() << " bytes) to " << this);
+ MDEBUG("Sending HTTP " << int(status) << " (" << body.size() << " bytes) to " << this);
assert(strand_.running_in_this_thread());
- response_ = {boost::beast::http::status::ok, parser_->get().version(), std::move(body)};
+ response_ = {status, parser_->get().version(), std::move(body)};
response_.set(boost::beast::http::field::server, BOOST_BEAST_VERSION_STRING);
response_.set(boost::beast::http::field::content_type, "application/json");
response_.keep_alive(keep_alive_);
@@ -2130,14 +2143,14 @@ namespace lws
a new callable like `wrap` does (which is deprecated, see dispatch
below). */
const auto& self = self_;
- resumer = [self, resume] (expect<copyable_slice> body) mutable
+ resumer = [self, resume] (expect<http_response> body) mutable
{
boost::asio::dispatch(self->strand_, [self, resume = std::move(resume), body = std::move(body)] () mutable
{
if (!body)
self->bad_request(body.error(), std::move(resume));
else
- self->valid_request(std::move(body->value), std::move(resume));
+ self->valid_request(std::move(body->value), std::move(resume), body->status);
});
};
}
### src/rpc/client.cpp
@@ -413,6 +413,9 @@ namespace rpc
}
MERROR("Server returned RPC error: " << json_error.message << " with code " << json_error.code << " called from " << loc);
+ // Some callers send the daemon status and reason to the REST client
+ parser.status = json_error.error_str;
+ parser.error_details = json_error.message;
}
catch (const cryptonote::json::JSON_ERROR& error)
{
### src/rpc/light_wallet.cpp
@@ -955,9 +955,13 @@ namespace lws
{
wire::object(source, WIRE_FIELD(tx));
}
- void rpc::write_bytes(wire::json_writer& dest, const submit_raw_tx_response self)
+ void rpc::write_bytes(wire::json_writer& dest, const submit_raw_tx_response& self)
{
- wire::object(dest, WIRE_FIELD_COPY(status));
+ wire::object(dest,
+ WIRE_FIELD(status),
+ WIRE_FIELD_DEFAULTED(reason, std::string{}),
+ WIRE_FIELD_DEFAULTED(not_relayed, false)
+ );
}
void rpc::read_bytes(wire::json_reader& source, upsert_subaddrs_request& self)
### src/rpc/light_wallet.h
@@ -411,8 +411,10 @@ namespace rpc
{
submit_raw_tx_response() = delete;
std::string status;
+ std::string reason;
+ bool not_relayed;
};
- void write_bytes(wire::json_writer&, submit_raw_tx_response);
+ void write_bytes(wire::json_writer&, const submit_raw_tx_response&);
struct upsert_subaddrs_request
### tests/unit/rest.test.cpp
@@ -870,6 +870,51 @@ LWS_CASE("rest_server")
);
}
+ SECTION("submit_raw_tx")
+ {
+ const auto pool = std::make_shared<lws::mempool>();
+
+ EXPECT(client.disconnect());
+ init_server(pool);
+ EXPECT(client.connect(std::chrono::milliseconds{500}));
+
+ std::vector<cryptonote::tx_destination_entry> destinations;
+ destinations.emplace_back();
+ destinations.back().amount = 8000;
+ destinations.back().addr = base.m_account_address;
+ const lws_test::transaction tx = lws_test::make_tx(lest_env, base, destinations, 20, true);
+ message = "{\"tx\":\"" + epee::to_hex::string(epee::strspan<std::uint8_t>(cryptonote::tx_to_blob(tx.tx))) + "\"}";
+
+ std::vector<epee::byte_slice> messages;
+ messages.emplace_back(std::string{"{\"jsonrpc\":\"2.0\",\"id\":0,\"result\":{\"relayed\":false}}"});
+ messages.emplace_back(std::string{"{\"jsonrpc\":\"2.0\",\"id\":0,\"error\":{\"code\":-1,\"error_str\":\"Failed\",\"message\":\"double spend and fee too low\"}}"});
+ messages.emplace_back(std::string{"{\"jsonrpc\":\"2.0\",\"id\":0,\"result\":{\"relayed\":true}}"});
+ std::atomic<bool> ready{false};
+ boost::thread server_thread(&lws_test::rpc_thread, context.zmq_context(), std::cref(messages), std::ref(ready));
+ const join on_scope_exit{server_thread};
+ while (!ready)
+ boost::this_thread::sleep_for(boost::chrono::milliseconds{10});
+
+ auto full_account = get_full_account();
+
+ const auto bad_hex = invoke_base(client, "/submit_raw_tx", "{\"tx\":\"zz\"}");
+ EXPECT(bad_hex.second == 400);
+ EXPECT(bad_hex.first.empty());
+
+ response = invoke(client, "/submit_raw_tx", message);
+ EXPECT(response == "{\"status\":\"OK\",\"reason\":\"Not relayed\",\"not_relayed\":true}");
+ EXPECT(pool->scan_account(full_account).empty());
+
+ const auto rejected = invoke_base(client, "/submit_raw_tx", message);
+ EXPECT(rejected.second == 422);
+ EXPECT(rejected.first == "{\"status\":\"Failed\",\"reason\":\"double spend and fee too low\"}");
+ EXPECT(pool->scan_account(full_account).empty());
+
+ response = invoke(client, "/submit_raw_tx", message);
+ EXPECT(response == "{\"status\":\"OK\"}");
+ EXPECT(pool->scan_account(full_account).size() == 1);
+ }
+
SECTION("feed check")
{
auto response = invoke_base(client, "/feed", "");Why this scored 36/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.