Skip to content

Commit 8d7a445

Browse files
committed
Merge #439: Add hidden RPC getrawaddrman
a7a8785 Add hidden RPC getrawaddrman (deadmanoz) Pull request description: Add support for the hidden `getrawaddrman` RPC that returns raw address manager table entries (added v26). This RPC is marked as experimental and hidden from the API docs by default. The `mapped_as` and `source_mapped_as` fields are `Option<u32>` following the established pattern for version-specific fields (no `into.rs` required because these are additions rather than removals or changed types). These fields were added in Bitcoin Core v28 and will deserialise as `None` for earlier versions or when `-asmap` is not configured. Note: will have conflicts with #435 and #433, happy to rebase after either merges ACKs for top commit: tcharding: ACK a7a8785 jamillambert: ACK a7a8785 Tree-SHA512: 592c499e6f129fafdc764c4fad729f18315a6f9baca3c16a74471929337b49366771db297789e2db89a7fe3602e2a2644f4de6221280098e8c136138a209756c
2 parents 7de11e5 + a7a8785 commit 8d7a445

14 files changed

Lines changed: 206 additions & 34 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing JSON-RPC methods on a client.
4+
//!
5+
//! Specifically this is `== Hidden ==` methods that are not listed in the
6+
//! API docs of Bitcoin Core `v26`.
7+
//!
8+
//! All macros require `Client` to be in scope.
9+
//!
10+
//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`.
11+
12+
/// Implements Bitcoin Core JSON-RPC API method `getrawaddrman`.
13+
#[macro_export]
14+
macro_rules! impl_client_v26__get_raw_addrman {
15+
() => {
16+
impl Client {
17+
pub fn get_raw_addrman(&self) -> Result<GetRawAddrMan> {
18+
self.call("getrawaddrman", &[])
19+
}
20+
}
21+
};
22+
}

client/src/client_sync/v26/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! We ignore option arguments unless they effect the shape of the returned JSON data.
66
77
pub mod blockchain;
8+
pub mod hidden;
89
pub mod mining;
910
pub mod network;
1011
pub mod raw_transactions;
@@ -84,12 +85,13 @@ crate::impl_client_v17__invalidate_block!();
8485
crate::impl_client_v22__add_connection!();
8586
crate::impl_client_v21__add_peer_address!();
8687
crate::impl_client_v17__estimate_raw_fee!();
88+
crate::impl_client_v26__get_raw_addrman!();
89+
crate::impl_client_v20__mock_scheduler!();
90+
crate::impl_client_v17__reconsider_block!();
91+
crate::impl_client_v17__sync_with_validation_interface_queue!();
8792
crate::impl_client_v17__wait_for_block!();
8893
crate::impl_client_v17__wait_for_block_height!();
8994
crate::impl_client_v17__wait_for_new_block!();
90-
crate::impl_client_v17__sync_with_validation_interface_queue!();
91-
crate::impl_client_v17__reconsider_block!();
92-
crate::impl_client_v20__mock_scheduler!();
9395

9496
// == Mining ==
9597
crate::impl_client_v17__get_block_template!();

client/src/client_sync/v27/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ crate::impl_client_v17__invalidate_block!();
8080
crate::impl_client_v27__add_connection!();
8181
crate::impl_client_v21__add_peer_address!();
8282
crate::impl_client_v17__estimate_raw_fee!();
83+
crate::impl_client_v26__get_raw_addrman!();
84+
crate::impl_client_v20__mock_scheduler!();
85+
crate::impl_client_v17__reconsider_block!();
86+
crate::impl_client_v17__sync_with_validation_interface_queue!();
8387
crate::impl_client_v17__wait_for_block!();
8488
crate::impl_client_v17__wait_for_block_height!();
8589
crate::impl_client_v17__wait_for_new_block!();
86-
crate::impl_client_v17__sync_with_validation_interface_queue!();
87-
crate::impl_client_v17__reconsider_block!();
88-
crate::impl_client_v20__mock_scheduler!();
8990

9091
// == Mining ==
9192
crate::impl_client_v17__get_block_template!();

client/src/client_sync/v28/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ crate::impl_client_v17__invalidate_block!();
8181
crate::impl_client_v27__add_connection!();
8282
crate::impl_client_v21__add_peer_address!();
8383
crate::impl_client_v17__estimate_raw_fee!();
84+
crate::impl_client_v26__get_raw_addrman!();
85+
crate::impl_client_v20__mock_scheduler!();
86+
crate::impl_client_v17__reconsider_block!();
87+
crate::impl_client_v17__sync_with_validation_interface_queue!();
8488
crate::impl_client_v17__wait_for_block!();
8589
crate::impl_client_v17__wait_for_block_height!();
8690
crate::impl_client_v17__wait_for_new_block!();
87-
crate::impl_client_v17__sync_with_validation_interface_queue!();
88-
crate::impl_client_v17__reconsider_block!();
89-
crate::impl_client_v20__mock_scheduler!();
9091

9192
// == Mining ==
9293
crate::impl_client_v17__get_block_template!();

client/src/client_sync/v29/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,19 @@ crate::impl_client_v20__generate_to_descriptor!();
7979
crate::impl_client_v17__invalidate_block!();
8080

8181
// == Hidden ==
82-
crate::impl_client_v29__get_orphan_txs_verbosity_2!();
83-
crate::impl_client_v29__get_orphan_txs_verbosity_1!();
84-
crate::impl_client_v29__get_orphan_txs!();
8582
crate::impl_client_v27__add_connection!();
8683
crate::impl_client_v21__add_peer_address!();
8784
crate::impl_client_v17__estimate_raw_fee!();
85+
crate::impl_client_v29__get_orphan_txs!();
86+
crate::impl_client_v29__get_orphan_txs_verbosity_1!();
87+
crate::impl_client_v29__get_orphan_txs_verbosity_2!();
88+
crate::impl_client_v26__get_raw_addrman!();
89+
crate::impl_client_v20__mock_scheduler!();
90+
crate::impl_client_v17__reconsider_block!();
91+
crate::impl_client_v17__sync_with_validation_interface_queue!();
8892
crate::impl_client_v17__wait_for_block!();
8993
crate::impl_client_v17__wait_for_block_height!();
9094
crate::impl_client_v17__wait_for_new_block!();
91-
crate::impl_client_v17__sync_with_validation_interface_queue!();
92-
crate::impl_client_v17__reconsider_block!();
93-
crate::impl_client_v20__mock_scheduler!();
9495

9596
// == Mining ==
9697
crate::impl_client_v17__get_block_template!();

client/src/client_sync/v30/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ crate::impl_client_v20__generate_to_descriptor!();
7979
crate::impl_client_v17__invalidate_block!();
8080

8181
// == Hidden ==
82-
crate::impl_client_v29__get_orphan_txs_verbosity_2!();
83-
crate::impl_client_v29__get_orphan_txs_verbosity_1!();
84-
crate::impl_client_v29__get_orphan_txs!();
8582
crate::impl_client_v27__add_connection!();
8683
crate::impl_client_v21__add_peer_address!();
87-
crate::impl_client_v17__sync_with_validation_interface_queue!();
88-
crate::impl_client_v17__reconsider_block!();
84+
crate::impl_client_v29__get_orphan_txs!();
85+
crate::impl_client_v29__get_orphan_txs_verbosity_1!();
86+
crate::impl_client_v29__get_orphan_txs_verbosity_2!();
87+
crate::impl_client_v26__get_raw_addrman!();
8988
crate::impl_client_v20__mock_scheduler!();
89+
crate::impl_client_v17__reconsider_block!();
90+
crate::impl_client_v17__sync_with_validation_interface_queue!();
9091

9192
// == Mining ==
9293
crate::impl_client_v17__get_block_template!();

integration_test/tests/hidden.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,33 @@ fn hidden__mock_scheduler() {
238238

239239
let _: () = node.client.mock_scheduler(1).expect("mockscheduler");
240240
}
241+
242+
#[test]
243+
#[cfg(not(feature = "v25_and_below"))]
244+
fn hidden__get_raw_addrman() {
245+
let node = Node::with_wallet(Wallet::None, &[]);
246+
247+
// Add a peer address so the address manager has something.
248+
let peer_address = "1.2.3.4";
249+
let peer_port = 8333;
250+
node.client.add_peer_address(peer_address, peer_port).expect("addpeeraddress");
251+
252+
let json: GetRawAddrMan = node.client.get_raw_addrman().expect("getrawaddrman");
253+
254+
let entry = json
255+
.new
256+
.values()
257+
.find(|e| e.address == peer_address && e.port == peer_port)
258+
.expect("added peer should appear in the 'new' table");
259+
260+
assert_eq!(entry.network, "ipv4");
261+
assert!(entry.services > 0);
262+
assert!(entry.time > 0);
263+
264+
// mapped_as fields added in v28, only present with -asmap config.
265+
#[cfg(not(feature = "v27_and_below"))]
266+
{
267+
assert!(entry.mapped_as.is_none(), "mapped_as requires -asmap config");
268+
assert!(entry.source_mapped_as.is_none(), "source_mapped_as requires -asmap config");
269+
}
270+
}

types/src/v26/hidden.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core `v26` - hidden.
4+
//!
5+
//! Types for methods that are excluded from the API docs by default.
6+
7+
use alloc::collections::BTreeMap;
8+
9+
use serde::{Deserialize, Serialize};
10+
11+
/// Result of JSON-RPC method `getrawaddrman`.
12+
///
13+
/// > getrawaddrman
14+
/// >
15+
/// > EXPERIMENTAL warning: this call may be changed in future releases.
16+
/// >
17+
/// > Returns information on all address manager entries for the new and tried tables.
18+
///
19+
/// This is a hidden RPC, useful for testing and development.
20+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
21+
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
22+
pub struct GetRawAddrMan {
23+
/// Addresses in the "new" table (potential peers discovered but not yet connected to).
24+
pub new: BTreeMap<String, RawAddrManEntry>,
25+
/// Addresses in the "tried" table (peers successfully connected to in the past).
26+
pub tried: BTreeMap<String, RawAddrManEntry>,
27+
}
28+
29+
/// An entry in the address manager table. Part of `getrawaddrman`.
30+
///
31+
/// The key in the parent map is formatted as "bucket/position" indicating the
32+
/// location in the relevant address manager table.
33+
///
34+
/// Field order matches Bitcoin Core's RPC response definition.
35+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
36+
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
37+
pub struct RawAddrManEntry {
38+
/// The address of the node.
39+
pub address: String,
40+
/// The port number of the node.
41+
pub port: u16,
42+
/// The network (ipv4, ipv6, onion, i2p, cjdns) of the address.
43+
pub network: String,
44+
/// The services offered by the node.
45+
pub services: u64,
46+
/// The UNIX epoch time when the node was last seen.
47+
pub time: i64,
48+
/// The address that relayed the address to us.
49+
pub source: String,
50+
/// The network (ipv4, ipv6, onion, i2p, cjdns) of the source address.
51+
pub source_network: String,
52+
}

types/src/v26/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
251251
mod blockchain;
252252
mod control;
253+
mod hidden;
253254
mod mining;
254255
mod network;
255256
mod raw_transactions;
@@ -262,6 +263,7 @@ pub use self::{
262263
GetTxOutSetInfo, GetTxOutSetInfoError, LoadTxOutSet, LoadTxOutSetError,
263264
},
264265
control::Logging,
266+
hidden::{GetRawAddrMan, RawAddrManEntry},
265267
mining::{GetPrioritisedTransactions, PrioritisedTransaction},
266268
network::{AddrManInfoNetwork, GetAddrManInfo, GetPeerInfo, PeerInfo},
267269
raw_transactions::{

types/src/v27/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ pub use crate::{
335335
v26::{
336336
AddrManInfoNetwork, ChainState, CreateWallet, DescriptorProcessPsbt,
337337
DescriptorProcessPsbtError, DumpTxOutSet, DumpTxOutSetError, GetAddrManInfo, GetBalances,
338-
GetBalancesError, GetChainStates, GetChainStatesError, GetPeerInfo, GetTransaction,
339-
GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo,
338+
GetBalancesError, GetChainStates, GetChainStatesError, GetPeerInfo, GetRawAddrMan,
339+
GetTransaction, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo,
340340
GetWalletInfoError, GetWalletInfoScanning, LastProcessedBlock, LastProcessedBlockError,
341-
LoadTxOutSet, LoadTxOutSetError, LoadWallet, Logging, PeerInfo, SubmitPackage,
342-
SubmitPackageError, SubmitPackageTxResult, SubmitPackageTxResultError,
341+
LoadTxOutSet, LoadTxOutSetError, LoadWallet, Logging, PeerInfo, RawAddrManEntry,
342+
SubmitPackage, SubmitPackageError, SubmitPackageTxResult, SubmitPackageTxResultError,
343343
SubmitPackageTxResultFees, SubmitPackageTxResultFeesError, UnloadWallet, WalletProcessPsbt,
344344
WalletProcessPsbtError,
345345
},

0 commit comments

Comments
 (0)