aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
author0xb10c <b10c@b10c.me>2023-12-04 15:56:40 +0100
committer0xb10c <b10c@b10c.me>2024-03-19 17:38:33 +0100
commit6205466512d4b94d1e507a77ab2151425790d29f (patch)
treeb4d2154e10892009f7e0ac35e0b9f5fdcf277a62 /src/rpc
parent9f2609de09eb6299548e4c56b0f325361c5ad781 (diff)
downloadbitcoin-6205466512d4b94d1e507a77ab2151425790d29f.tar.xz
rpc: "addpeeraddress tried" return error on failure
When trying to add an address to the IP address manager tried table, it's first added to the new table and then moved to the tried table. Previously, adding a conflicting address to the address manager's tried table with test-only `addpeeraddress tried=true` RPC would return `{ "success": true }`. However, the address would not be added to the tried table, but would remain in the new table. This caused, e.g., issue 28964. This is fixed by returning `{ "success": false, "error": "failed-adding-to-tried" }` for failed tried table additions. Since the address remaining in the new table can't be removed (the address manager interface does not support removing addresses at the moment and adding this seems to be a bigger effort), an error message is returned. This indicates to a user why the RPC failed and allows accounting for the extra address in the new table. Also: To check the number of addresses in each addrman table, the addrman checks were re-run and the log output of this check was asserted. Ideally, logs shouldn't be used as an interface in automated tests. To avoid asserting the logs, use the getaddrmaninfo and getrawaddrman RPCs (which weren't implemented when the test was added). Removing the "getnodeaddress" calls would also remove the addrman checks from the test, which could reduce the test coverage. To avoid this, these are kept.
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/net.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 3fa2b18495..f935a3b08f 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -951,7 +951,7 @@ static RPCHelpMan getnodeaddresses()
static RPCHelpMan addpeeraddress()
{
return RPCHelpMan{"addpeeraddress",
- "\nAdd the address of a potential peer to the address manager. This RPC is for testing only.\n",
+ "Add the address of a potential peer to an address manager table. This RPC is for testing only.",
{
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address of the peer"},
{"port", RPCArg::Type::NUM, RPCArg::Optional::NO, "The port of the peer"},
@@ -960,7 +960,8 @@ static RPCHelpMan addpeeraddress()
RPCResult{
RPCResult::Type::OBJ, "", "",
{
- {RPCResult::Type::BOOL, "success", "whether the peer address was successfully added to the address manager"},
+ {RPCResult::Type::BOOL, "success", "whether the peer address was successfully added to the address manager table"},
+ {RPCResult::Type::STR, "error", /*optional=*/true, "error description, if the address could not be added"},
},
},
RPCExamples{
@@ -989,8 +990,13 @@ static RPCHelpMan addpeeraddress()
success = true;
if (tried) {
// Attempt to move the address to the tried addresses table.
- addrman.Good(address);
+ if (!addrman.Good(address)) {
+ success = false;
+ obj.pushKV("error", "failed-adding-to-tried");
+ }
}
+ } else {
+ obj.pushKV("error", "failed-adding-to-new");
}
}