Skip to content

Commit e30b13a

Browse files
committed
Merge #315: Improve GetPeerInfo
0d93ad7 node: Use get_peer_info method (Tobin C. Harding) d561e5c Explicitly check type of GetPeerInfo vector element (Tobin C. Harding) 8a26cd0 Improve GetPeerInfo (Tobin C. Harding) Pull request description: In #310 I got mixed up and added fields to the v17 types `GetPeerInfo` struct that do not appear in the docs. This was masked by using `Option`. And not helped by the fact that a bunch of other `Option`s are used because the docs do not match what Core returns. These bugs propagated up through the version numbers. Go over them all and sort it out. Note also that we were incorrectly re-exporting `PeerInfo` from v19 even though the `PeerInfo` struct that was actually being used is found in the version specific file along with `GetPeerInfo` - face palm. And finally, remove all the 'vXY and later' docs, this is implied by the module. These sorts of comments should only be found in `model`. ACKs for top commit: jamillambert: ACK 0d93ad7 Tree-SHA512: a9565d056abc63a7b35d1041756f9f01e3dc98d357c3b911c531e4eb254747a28a4b4bdb8a36022d76807ec8849a5e3572688a148f6dae9d0d8716e442c2c9bf
2 parents ced8ebe + 0d93ad7 commit e30b13a

File tree

15 files changed

+63
-88
lines changed

15 files changed

+63
-88
lines changed

integration_test/tests/network.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ fn get_peer_info_three_node_network() {
120120
node2.mine_a_block();
121121
node3.mine_a_block();
122122

123+
let json: GetPeerInfo = node1.client.get_peer_info().expect("getpeerinfo");
124+
// This verifies that we re-exported the correct `PeerInfo` type at the module level.
125+
let _: PeerInfo = json.0[0];
126+
123127
// FIXME: Fails if we use equal to 2 ???
124128
assert!(node1.peers_connected() >= 1);
125129
assert!(node2.peers_connected() >= 1);

node/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -918,10 +918,8 @@ mod test {
918918
}
919919

920920
fn peers_connected(client: &Client) -> usize {
921-
// FIXME: Once client implements get_peer_info use it.
922-
// This is kinda cool, it shows we can call any RPC method using the client.
923-
let result: Vec<serde_json::Value> = client.call("getpeerinfo", &[]).unwrap();
924-
result.len()
921+
let json = client.get_peer_info().expect("get_peer_info");
922+
json.0.len()
925923
}
926924

927925
fn init() -> String {

types/src/v17/network/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ pub struct PeerInfo {
196196
/// Local address as reported by the peer.
197197
#[serde(rename = "addrlocal")]
198198
pub address_local: Option<String>,
199-
/// Network (ipv4, ipv6, or onion) the peer connected through.
200-
pub network: Option<String>,
201199
/// The services offered.
202200
pub services: String,
203201
/// Whether peer has asked us to relay transactions to it.
@@ -252,16 +250,14 @@ pub struct PeerInfo {
252250
pub synced_blocks: i64,
253251
/// The heights of blocks we're currently asking from this peer.
254252
pub inflight: Vec<u64>,
255-
/// Whether the peer is whitelisted (deprecated in v0.21).
253+
/// Whether the peer is whitelisted.
256254
pub whitelisted: Option<bool>,
257255
/// The total bytes sent aggregated by message type.
258256
#[serde(rename = "bytessent_per_msg")]
259257
pub bytes_sent_per_message: BTreeMap<String, u64>,
260258
/// The total bytes received aggregated by message type.
261259
#[serde(rename = "bytesrecv_per_msg")]
262260
pub bytes_received_per_message: BTreeMap<String, u64>,
263-
/// Type of connection.
264-
pub connection_type: Option<String>,
265261
}
266262

267263
/// Result of JSON-RPC method `listbanned`.

types/src/v18/network/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ pub struct PeerInfo {
5757
/// Local address as reported by the peer.
5858
#[serde(rename = "addrlocal")]
5959
pub address_local: Option<String>,
60-
/// Network (ipv4, ipv6, or onion) the peer connected through.
61-
pub network: Option<String>,
6260
/// The services offered.
6361
pub services: String,
6462
/// Whether peer has asked us to relay transactions to it.
@@ -113,17 +111,15 @@ pub struct PeerInfo {
113111
pub synced_blocks: i64,
114112
/// The heights of blocks we're currently asking from this peer.
115113
pub inflight: Vec<u64>,
116-
/// Whether the peer is whitelisted (deprecated in v0.21).
114+
/// Whether the peer is whitelisted.
117115
pub whitelisted: Option<bool>,
118116
/// The minimum fee rate for transactions this peer accepts.
119117
#[serde(rename = "minfeefilter")]
120-
pub min_fee_filter: Option<f64>,
118+
pub min_fee_filter: f64,
121119
/// The total bytes sent aggregated by message type.
122120
#[serde(rename = "bytessent_per_msg")]
123121
pub bytes_sent_per_message: BTreeMap<String, u64>,
124122
/// The total bytes received aggregated by message type.
125123
#[serde(rename = "bytesrecv_per_msg")]
126124
pub bytes_received_per_message: BTreeMap<String, u64>,
127-
/// Type of connection.
128-
pub connection_type: Option<String>,
129125
}

types/src/v19/network/mod.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct GetNetworkInfo {
3030
/// The services we offer to the network (hex string).
3131
#[serde(rename = "localservices")]
3232
pub local_services: String,
33-
/// The services we offer to the network. v0.19 and later only.
33+
/// The services we offer to the network.
3434
#[serde(rename = "localservicesnames")]
3535
pub local_services_names: Vec<String>,
3636
/// `true` if transaction relay is requested from peers.
@@ -83,11 +83,9 @@ pub struct PeerInfo {
8383
/// Local address as reported by the peer.
8484
#[serde(rename = "addrlocal")]
8585
pub address_local: Option<String>,
86-
/// Network (ipv4, ipv6, or onion) the peer connected through.
87-
pub network: Option<String>,
8886
/// The services offered.
8987
pub services: String,
90-
/// The services offered, in human-readable form. v0.19 and later only.
88+
/// The services offered, in human-readable form.
9189
#[serde(rename = "servicesnames")]
9290
pub services_names: Vec<String>,
9391
/// Whether peer has asked us to relay transactions to it.
@@ -144,17 +142,15 @@ pub struct PeerInfo {
144142
pub inflight: Vec<u64>,
145143
/// Any special permissions that have been granted to this peer. v0.19 and later only.
146144
pub permissions: Vec<String>,
147-
/// The minimum fee rate for transactions this peer accepts. v0.19 and later only.
148-
#[serde(rename = "minfeefilter")]
149-
pub minimum_fee_filter: f64,
150-
/// Whether the peer is whitelisted (deprecated in v0.21).
145+
/// Whether the peer is whitelisted.
151146
pub whitelisted: Option<bool>,
147+
/// The minimum fee rate for transactions this peer accepts.
148+
#[serde(rename = "minfeefilter")]
149+
pub min_fee_filter: f64,
152150
/// The total bytes sent aggregated by message type.
153151
#[serde(rename = "bytessent_per_msg")]
154152
pub bytes_sent_per_message: BTreeMap<String, u64>,
155153
/// The total bytes received aggregated by message type.
156154
#[serde(rename = "bytesrecv_per_msg")]
157155
pub bytes_received_per_message: BTreeMap<String, u64>,
158-
/// Type of connection.
159-
pub connection_type: Option<String>,
160156
}

types/src/v21/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub use self::{
245245
SoftforkType,
246246
},
247247
generating::GenerateBlock,
248-
network::{GetNetworkInfo, GetPeerInfo},
248+
network::{GetNetworkInfo, GetPeerInfo, PeerInfo},
249249
util::{GetIndexInfo, GetIndexInfoName},
250250
wallet::{
251251
ImportDescriptors, ImportDescriptorsResult, PsbtBumpFee, PsbtBumpFeeError, Send, SendError,
@@ -298,8 +298,7 @@ pub use crate::{
298298
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError, GetBlockchainInfoError,
299299
GetChainTxStats, GetDescriptorInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose,
300300
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetRpcInfo, MapMempoolEntryError,
301-
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
302-
SetWalletFlag,
301+
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, SetWalletFlag,
303302
},
304303
v20::{
305304
Banned, CreateMultisig, GenerateToDescriptor, GetTransaction, GetTransactionDetail,

types/src/v21/network/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct PeerInfo {
9191
pub network: Option<String>,
9292
/// The services offered.
9393
pub services: String,
94-
/// The services offered, in human-readable form. v0.19 and later only.
94+
/// The services offered, in human-readable form.
9595
#[serde(rename = "servicesnames")]
9696
pub services_names: Vec<String>,
9797
/// Whether peer has asked us to relay transactions to it.
@@ -141,9 +141,6 @@ pub struct PeerInfo {
141141
/// The starting height (block) of the peer.
142142
#[serde(rename = "startingheight")]
143143
pub starting_height: i64,
144-
/// The ban score.
145-
#[serde(rename = "banscore")]
146-
pub ban_score: Option<i64>,
147144
/// The last header we have in common with this peer.
148145
pub synced_headers: i64,
149146
/// The last block we have in common with this peer.
@@ -159,11 +156,11 @@ pub struct PeerInfo {
159156
pub addresses_rate_limited: usize,
160157
/// Any special permissions that have been granted to this peer. v0.19 and later only.
161158
pub permissions: Vec<String>,
162-
/// The minimum fee rate for transactions this peer accepts. v0.19 and later only.
163-
#[serde(rename = "minfeefilter")]
164-
pub minimum_fee_filter: f64,
165-
/// Whether the peer is whitelisted (deprecated in v0.21).
159+
/// Whether the peer is whitelisted.
166160
pub whitelisted: Option<bool>,
161+
/// The minimum fee rate for transactions this peer accepts.
162+
#[serde(rename = "minfeefilter")]
163+
pub min_fee_filter: Option<f64>, // Docs rekon this exists.
167164
/// The total bytes sent aggregated by message type.
168165
#[serde(rename = "bytessent_per_msg")]
169166
pub bytes_sent_per_message: BTreeMap<String, u64>,

types/src/v22/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ mod wallet;
254254
pub use self::{
255255
blockchain::GetMempoolInfo,
256256
control::Logging,
257-
network::{Banned, GetPeerInfo, ListBanned},
257+
network::{Banned, GetPeerInfo, ListBanned, PeerInfo},
258258
raw_transactions::{DecodeScript, DecodeScriptError},
259259
signer::EnumerateSigners,
260260
wallet::{ListDescriptors, WalletDisplayAddress},
@@ -305,8 +305,7 @@ pub use crate::{
305305
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError, GetBlockchainInfoError,
306306
GetChainTxStats, GetDescriptorInfo, GetMempoolAncestors, GetMempoolAncestorsVerbose,
307307
GetMempoolDescendants, GetMempoolDescendantsVerbose, GetRpcInfo, MapMempoolEntryError,
308-
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
309-
SetWalletFlag,
308+
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, SetWalletFlag,
310309
},
311310
v20::{CreateMultisig, GenerateToDescriptor, GetTransaction, GetTransactionDetail},
312311
v21::{

types/src/v22/network.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub struct PeerInfo {
6161
pub network: Option<String>,
6262
/// The services offered.
6363
pub services: String,
64-
/// The services offered, in human-readable form. v0.19 and later only.
64+
/// The services offered, in human-readable form.
6565
#[serde(rename = "servicesnames")]
6666
pub services_names: Vec<String>,
6767
/// Whether peer has asked us to relay transactions to it.
@@ -105,19 +105,16 @@ pub struct PeerInfo {
105105
pub subversion: String,
106106
/// Inbound (true) or Outbound (false).
107107
pub inbound: bool,
108-
/// Whether we selected peer as (compact blocks) high-bandwidth peer. v22 and later only.
108+
/// Whether we selected peer as (compact blocks) high-bandwidth peer.
109109
pub bip152_hb_to: bool,
110-
/// Whether peer selected us as (compact blocks) high-bandwidth peer. v22 and later only.
110+
/// Whether peer selected us as (compact blocks) high-bandwidth peer.
111111
pub bip152_hb_from: bool,
112112
/// Whether connection was due to addnode/-connect or if it was an automatic/inbound connection.
113113
#[serde(rename = "addnode")]
114114
pub add_node: Option<bool>,
115115
/// The starting height (block) of the peer.
116116
#[serde(rename = "startingheight")]
117117
pub starting_height: i64,
118-
/// The ban score.
119-
#[serde(rename = "banscore")]
120-
pub ban_score: Option<i64>,
121118
/// The last header we have in common with this peer.
122119
pub synced_headers: i64,
123120
/// The last block we have in common with this peer.
@@ -133,11 +130,11 @@ pub struct PeerInfo {
133130
pub addresses_rate_limited: usize,
134131
/// Any special permissions that have been granted to this peer. v0.19 and later only.
135132
pub permissions: Vec<String>,
136-
/// The minimum fee rate for transactions this peer accepts. v0.19 and later only.
137-
#[serde(rename = "minfeefilter")]
138-
pub minimum_fee_filter: f64,
139-
/// Whether the peer is whitelisted (deprecated in v0.21).
133+
/// Whether the peer is whitelisted.
140134
pub whitelisted: Option<bool>,
135+
/// The minimum fee rate for transactions this peer accepts.
136+
#[serde(rename = "minfeefilter")]
137+
pub min_fee_filter: Option<f64>, // Docs rekon this exists.
141138
/// The total bytes sent aggregated by message type.
142139
#[serde(rename = "bytessent_per_msg")]
143140
pub bytes_sent_per_message: BTreeMap<String, u64>,

types/src/v23/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub use self::{
250250
GetDeploymentInfoError, GetMempoolEntry, SaveMempool,
251251
},
252252
control::Logging,
253-
network::GetPeerInfo,
253+
network::{GetPeerInfo, PeerInfo},
254254
raw_transactions::{
255255
DecodePsbt, DecodePsbtError, DecodeScript, DecodeScriptError, GlobalXpub, Proprietary,
256256
PsbtInput, PsbtOutput,
@@ -304,8 +304,8 @@ pub use crate::{
304304
GetBlockFilterError, GetBlockchainInfoError, GetChainTxStats, GetDescriptorInfo,
305305
GetMempoolAncestors, GetMempoolAncestorsVerbose, GetMempoolDescendants,
306306
GetMempoolDescendantsVerbose, GetRpcInfo, MapMempoolEntryError, MempoolEntry,
307-
MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo, SetWalletFlag,
308-
Softfork, SoftforkType,
307+
MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, SetWalletFlag, Softfork,
308+
SoftforkType,
309309
},
310310
v20::{GenerateToDescriptor, GetTransactionDetail},
311311
v21::{

0 commit comments

Comments
 (0)