Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client/src/client_sync/v26/hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is `== Hidden ==` methods that are not listed in the
//! API docs of Bitcoin Core `v26`.
//!
//! All macros require `Client` to be in scope.
//!
//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`.

/// Implements Bitcoin Core JSON-RPC API method `getrawaddrman`.
#[macro_export]
macro_rules! impl_client_v26__get_raw_addrman {
() => {
impl Client {
pub fn get_raw_addrman(&self) -> Result<GetRawAddrman> {
self.call("getrawaddrman", &[])
}
}
};
}
2 changes: 2 additions & 0 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! We ignore option arguments unless they effect the shape of the returned JSON data.

pub mod blockchain;
pub mod hidden;
pub mod mining;
pub mod network;
pub mod raw_transactions;
Expand Down Expand Up @@ -82,6 +83,7 @@ crate::impl_client_v17__invalidate_block!();
// == Hidden ==
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v26__get_raw_addrman!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ crate::impl_client_v17__invalidate_block!();
// == Hidden ==
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v26__get_raw_addrman!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ crate::impl_client_v17__invalidate_block!();
// == Hidden ==
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v26__get_raw_addrman!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ crate::impl_client_v17__invalidate_block!();
// == Hidden ==
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v26__get_raw_addrman!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v30/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v26__get_raw_addrman!();

// == Mining ==
crate::impl_client_v17__get_block_template!();
Expand Down
24 changes: 24 additions & 0 deletions integration_test/tests/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,27 @@ fn hidden__estimate_raw_fee__modelled() {

assert!(estimate.long.scale > 0);
}

#[test]
#[cfg(not(feature = "v25_and_below"))]
fn hidden__get_raw_addrman() {
let node = Node::with_wallet(Wallet::None, &[]);

// Add a peer address so the address manager has something.
let peer_address = "1.2.3.4";
let peer_port = 8333;
node.client.add_peer_address(peer_address, peer_port).expect("addpeeraddress");

let json: GetRawAddrman = node.client.get_raw_addrman().expect("getrawaddrman");

let entry = json
.new
.values()
.find(|e| e.address == peer_address && e.port == peer_port)
.expect("added peer should appear in the 'new' table");
Comment on lines +40 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addpeeraddress supports an additional argument for adding things to the tried table. However that wasn't implemented in #334.

I think for this test it's fine to just test the new table.


assert_eq!(entry.network, "ipv4");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert_eq!(entry.network, "ipv4");
assert_eq!(entry.network, "ipv4");
assert!(entry.services > 0);
assert!(entry.time > 0);

I don't recall what source is set to when using addpeeraddress, but maybe that can be checked as well.


// mapped_as field added in v28, only present with -asmap config.
assert!(entry.mapped_as.is_none(), "mapped_as requires -asmap config");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert!(entry.mapped_as.is_none(), "mapped_as requires -asmap config");
assert!(entry.mapped_as.is_none(), "mapped_as requires -asmap config");
assert!(entry.source_mapped_as.is_none(), "mapped_as requires -asmap config");

This might break once/if asmap get's included and enabled by default. But that's probably a few versions out.

}
60 changes: 60 additions & 0 deletions types/src/v26/hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: CC0-1.0

//! The JSON-RPC API for Bitcoin Core `v26` - hidden.
//!
//! Types for methods that are excluded from the API docs by default.
use alloc::collections::BTreeMap;

use serde::{Deserialize, Serialize};

/// Result of JSON-RPC method `getrawaddrman`.
///
/// > getrawaddrman
/// >
/// > EXPERIMENTAL warning: this call may be changed in future releases.
/// >
/// > Returns information on all address manager entries for the new and tried tables.
///
/// This is a hidden RPC, useful for testing and development.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetRawAddrman {
/// Addresses in the "new" table (potential peers discovered but not yet connected to).
pub new: BTreeMap<String, RawAddrmanEntry>,
/// Addresses in the "tried" table (peers successfully connected to in the past).
pub tried: BTreeMap<String, RawAddrmanEntry>,
}

/// An entry in the address manager table. Part of `getrawaddrman`.
///
/// The key in the parent map is formatted as "bucket/position" indicating the
/// location in the relevant address manager table.
Comment on lines +31 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This key is a bit weird (not in your implementation, but in the Bitcoin Core implement). IIRC, it was done this way, as the key should be seen as Bitcoin Core implementation specific. However, RPC users might want to consume and act on it. I guess probably best to write a parser for it in downstream apps and not here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, so I'm not changing anything, the key is just a String like "255/50" as you get from the RPC directly.

///
/// Field order matches Bitcoin Core's RPC response definition.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct RawAddrmanEntry {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub struct RawAddrmanEntry {
pub struct RawAddrManEntry {

And same everywhere else that rawaddrman is converted to a Rust type.

/// The address of the node.
pub address: String,
/// Mapped AS (Autonomous System) number at the end of the BGP route to the peer.
/// Only present if the -asmap config option is set.
/// Added in Bitcoin Core v28.
pub mapped_as: Option<u32>,
Comment on lines +40 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this and props for getting as far as you did in this convoluted repo. The version specific types are designed to be exactly correct for the version i.e., v26::RawAddrManEntry should be exactly the shape returned by Core v26. This means no optional fields. Rather anytime a new field is added a new version of the struct is added, so we should have a v28::RawAddrMan (and v28::RawAddrManEntry).

(If there was an associated struct in model, where there is not in this case, it would use optional fields because the model types are version in-specific.)

Copy link
Member

@tcharding tcharding Dec 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FTR looks like you have the client stuff correct, because the v28 changes do not effect the client so the v26 client macro works just fine. I mentioned that this repo was convoluted, right?

/// The port number of the node.
pub port: u16,
/// The network (ipv4, ipv6, onion, i2p, cjdns) of the address.
pub network: String,
/// The services offered by the node.
pub services: u64,
/// The UNIX epoch time when the node was last seen.
pub time: i64,
/// The address that relayed the address to us.
pub source: String,
/// The network (ipv4, ipv6, onion, i2p, cjdns) of the source address.
pub source_network: String,
/// Mapped AS (Autonomous System) number at the end of the BGP route to the source.
/// Only present if the -asmap config option is set.
/// Added in Bitcoin Core v28.
pub source_mapped_as: Option<u32>,
}
2 changes: 2 additions & 0 deletions types/src/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@

mod blockchain;
mod control;
mod hidden;
mod mining;
mod network;
mod raw_transactions;
Expand All @@ -262,6 +263,7 @@ pub use self::{
GetTxOutSetInfo, GetTxOutSetInfoError, LoadTxOutSet, LoadTxOutSetError,
},
control::Logging,
hidden::{GetRawAddrman, RawAddrmanEntry},
mining::{GetPrioritisedTransactions, PrioritisedTransaction},
network::{AddrManInfoNetwork, GetAddrManInfo, GetPeerInfo, PeerInfo},
raw_transactions::{
Expand Down
8 changes: 4 additions & 4 deletions types/src/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ pub use crate::{
v26::{
AddrManInfoNetwork, ChainState, CreateWallet, DescriptorProcessPsbt,
DescriptorProcessPsbtError, DumpTxOutSet, DumpTxOutSetError, GetAddrManInfo, GetBalances,
GetBalancesError, GetChainStates, GetChainStatesError, GetPeerInfo, GetTransaction,
GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo,
GetBalancesError, GetChainStates, GetChainStatesError, GetPeerInfo, GetRawAddrman,
GetTransaction, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo,
GetWalletInfoError, GetWalletInfoScanning, LastProcessedBlock, LastProcessedBlockError,
LoadTxOutSet, LoadTxOutSetError, LoadWallet, Logging, PeerInfo, SubmitPackage,
SubmitPackageError, SubmitPackageTxResult, SubmitPackageTxResultError,
LoadTxOutSet, LoadTxOutSetError, LoadWallet, Logging, PeerInfo, RawAddrmanEntry,
SubmitPackage, SubmitPackageError, SubmitPackageTxResult, SubmitPackageTxResultError,
SubmitPackageTxResultFees, SubmitPackageTxResultFeesError, UnloadWallet, WalletProcessPsbt,
WalletProcessPsbtError,
},
Expand Down
10 changes: 5 additions & 5 deletions types/src/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ pub use crate::{
v26::{
AddrManInfoNetwork, ChainState, CreateWallet, DescriptorProcessPsbt,
DescriptorProcessPsbtError, DumpTxOutSet, DumpTxOutSetError, GetAddrManInfo, GetBalances,
GetBalancesError, GetChainStates, GetChainStatesError, GetPeerInfo, GetTransactionError,
GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo, GetWalletInfoError,
GetWalletInfoScanning, LastProcessedBlock, LastProcessedBlockError, LoadTxOutSet,
LoadTxOutSetError, LoadWallet, PeerInfo, UnloadWallet, WalletProcessPsbt,
WalletProcessPsbtError,
GetBalancesError, GetChainStates, GetChainStatesError, GetPeerInfo, GetRawAddrman,
GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo,
GetWalletInfoError, GetWalletInfoScanning, LastProcessedBlock, LastProcessedBlockError,
LoadTxOutSet, LoadTxOutSetError, LoadWallet, PeerInfo, RawAddrmanEntry, UnloadWallet,
WalletProcessPsbt, WalletProcessPsbtError,
},
v27::{GetPrioritisedTransactions, PrioritisedTransaction},
};
8 changes: 4 additions & 4 deletions types/src/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,10 @@ pub use crate::{
v26::{
AddrManInfoNetwork, CreateWallet, DescriptorProcessPsbt, DescriptorProcessPsbtError,
DumpTxOutSet, DumpTxOutSetError, GetAddrManInfo, GetBalances, GetBalancesError,
GetPeerInfo, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, GetWalletInfo,
GetWalletInfoError, GetWalletInfoScanning, LastProcessedBlock, LastProcessedBlockError,
LoadTxOutSet, LoadTxOutSetError, LoadWallet, PeerInfo, UnloadWallet, WalletProcessPsbt,
WalletProcessPsbtError,
GetPeerInfo, GetRawAddrman, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError,
GetWalletInfo, GetWalletInfoError, GetWalletInfoScanning, LastProcessedBlock,
LastProcessedBlockError, LoadTxOutSet, LoadTxOutSetError, LoadWallet, PeerInfo,
RawAddrmanEntry, UnloadWallet, WalletProcessPsbt, WalletProcessPsbtError,
},
v27::{GetPrioritisedTransactions, PrioritisedTransaction},
v28::{
Expand Down
6 changes: 3 additions & 3 deletions types/src/v30/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ pub use crate::{
v26::{
AddrManInfoNetwork, CreateWallet, DescriptorProcessPsbt, DescriptorProcessPsbtError,
DumpTxOutSet, DumpTxOutSetError, GetAddrManInfo, GetBalances, GetBalancesError,
GetPeerInfo, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError, LoadTxOutSet,
LoadTxOutSetError, LoadWallet, PeerInfo, UnloadWallet, WalletProcessPsbt,
WalletProcessPsbtError,
GetPeerInfo, GetRawAddrman, GetTransactionError, GetTxOutSetInfo, GetTxOutSetInfoError,
LoadTxOutSet, LoadTxOutSetError, LoadWallet, PeerInfo, RawAddrmanEntry, UnloadWallet,
WalletProcessPsbt, WalletProcessPsbtError,
},
v27::{GetPrioritisedTransactions, PrioritisedTransaction},
v28::{
Expand Down