Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: libp2p #6630

Merged
merged 40 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1e01559
initial
sdbondi Oct 3, 2024
1d873a0
wip
sdbondi Oct 7, 2024
dcd7aaa
wip
sdbondi Oct 8, 2024
2bfef79
wip
sdbondi Oct 10, 2024
5f0eb29
wip
sdbondi Oct 10, 2024
1165c3a
wip
sdbondi Oct 10, 2024
20ec341
Merge branch 'development' into libp2p
sdbondi Oct 10, 2024
50e73cc
wip
sdbondi Oct 10, 2024
3065b7a
wip
sdbondi Oct 10, 2024
bae57e8
wip
sdbondi Oct 11, 2024
45fc0b2
wip: wallet begins dun dun dun
sdbondi Oct 12, 2024
924e1b5
wip
sdbondi Oct 14, 2024
0ee154c
Merge branch 'development' into libp2p
sdbondi Oct 14, 2024
eba4f00
wip
sdbondi Oct 14, 2024
9714357
wip:wallet ffi
sdbondi Oct 15, 2024
3f9a237
Merge branch 'development' into libp2p
sdbondi Oct 15, 2024
51d3da5
machete
sdbondi Oct 15, 2024
dc855ae
wip: clean up wait for first bn connection code
sdbondi Oct 15, 2024
41d9dae
Merge branch 'development' into libp2p
sdbondi Oct 15, 2024
29d7466
wip:ffi
sdbondi Oct 15, 2024
7b2d1cb
wallet ffi and mmproxy
sdbondi Oct 16, 2024
67376b5
cucumbers
sdbondi Oct 16, 2024
261275c
clippies
sdbondi Oct 16, 2024
1f6d9be
Merge branch 'development' into libp2p
sdbondi Oct 16, 2024
bb470d3
improve error logging if networking fails in base node
sdbondi Oct 16, 2024
ce09dc0
always dial when using dial-peer cmd
sdbondi Oct 16, 2024
7b2a085
dont show loopback in whois, remove libtor feature from CI
sdbondi Oct 16, 2024
60d50c3
remove chat from CI
sdbondi Oct 16, 2024
c8b7cf7
cucumber ffi
sdbondi Oct 16, 2024
d9dfaee
Merge branch 'development' into libp2p
sdbondi Oct 17, 2024
0d5746b
remove comms from test_utils
sdbondi Oct 17, 2024
45a437d
code cleanup and use nightly-2024-10-14 in CI
sdbondi Oct 17, 2024
626eb87
rust nightly sweetspot 2024-08-01
sdbondi Oct 17, 2024
92880e8
fix cucumbers
sdbondi Oct 18, 2024
271ee02
Merge branch 'development' into libp2p
sdbondi Oct 18, 2024
7fcfc5e
increase gossipsub message size
sdbondi Oct 24, 2024
aca83cf
Merge branch 'development' into libp2p
sdbondi Oct 30, 2024
659172d
merge fixes
sdbondi Oct 30, 2024
7dbac69
review comments
sdbondi Oct 30, 2024
60e0fb5
feat: impl supported protocols, unban all peers, autonat status
sdbondi Oct 30, 2024
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
Prev Previous commit
Next Next commit
wip:wallet ffi
sdbondi committed Oct 15, 2024
commit 9714357655bddba1d638b403f8f246145f2f005d
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -23,14 +23,12 @@
use std::{fs, fs::File, io, io::Write, path::Path, sync::Arc};

use log::*;
use rand::rngs::OsRng;
use serde::{de::DeserializeOwned, Serialize};
use tari_common::{
configuration::bootstrap::prompt,
exit_codes::{ExitCode, ExitError},
};
use tari_network::{identity, multiaddr::Multiaddr};
use tari_utilities::hex::Hex;
use tari_network::identity;

pub const LOG_TARGET: &str = "minotari_application";

4 changes: 2 additions & 2 deletions applications/minotari_app_utilities/src/parse_miner_input.rs
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ pub fn wallet_payment_address(
network: Network,
) -> Result<TariAddress, ParseInputError> {
// Verify config setting
return match TariAddress::from_str(&config_wallet_payment_address) {
match TariAddress::from_str(&config_wallet_payment_address) {
Ok(address) => {
if address == TariAddress::default() {
println!();
@@ -147,7 +147,7 @@ pub fn wallet_payment_address(
"Wallet payment address '{}' not valid ({})",
config_wallet_payment_address, err
))),
};
}
}

/// User requested quit
2 changes: 1 addition & 1 deletion applications/minotari_app_utilities/src/utilities.rs
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ use tari_common_types::{
tari_address::TariAddress,
types::{PrivateKey, PublicKey, Signature},
};
use tari_network::{identity::PeerId, Peer, ToPeerId};
use tari_network::{identity::PeerId, ToPeerId};
use tari_utilities::hex::{Hex, HexError};
use thiserror::Error;
use tokio::{runtime, runtime::Runtime};
95 changes: 64 additions & 31 deletions applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
@@ -565,38 +565,71 @@ pub async fn start_wallet(
) -> Result<(), ExitError> {
debug!(target: LOG_TARGET, "Setting base node peer");

if base_nodes.is_empty() {
return Err(ExitError::new(
ExitCode::WalletError,
"No base nodes configured to connect to",
));
}
let selected_base_node = base_nodes.choose(&mut OsRng).expect("base_nodes is not empty");
let net_address = selected_base_node.addresses();
if net_address.is_empty() {
return Err(ExitError::new(
ExitCode::ConfigError,
"Configured base node has no address!",
));
}

let pk = selected_base_node
.public_key()
.clone()
.try_into_sr25519()
.map_err(|e| ExitError::new(ExitCode::ConfigError, format!("Invalid key type: {}", e)))?
.inner_key()
.clone();

wallet
.set_base_node_peer(pk, Some(net_address[0].clone()), Some(base_nodes.to_vec()))
.await
.map_err(|e| {
ExitError::new(
ExitCode::WalletError,
format!("Error setting wallet base node peer. {}", e),
if let Some(selected_base_node) = base_nodes.choose(&mut OsRng) {
let pk = selected_base_node
.public_key()
.clone()
.try_into_sr25519()
.map_err(|e| ExitError::new(ExitCode::ConfigError, format!("Invalid key type: {}", e)))?
.inner_key()
.clone();

wallet
.set_base_node_peer(
pk,
selected_base_node.addresses().first().cloned(),
Some(base_nodes.to_vec()),
)
})?;
.await
.map_err(|e| {
ExitError::new(
ExitCode::WalletError,
format!("Error setting wallet base node peer. {}", e),
)
})?;
} else {
let mut remaining_time = 10usize;
loop {
let conns = wallet.network.get_active_connections().await.map_err(|e| {
ExitError::new(
ExitCode::WalletError,
format!("Error setting wallet base node peer. {}", e),
)
})?;
if let Some(conn) = conns
.iter()
.find(|c| c.public_key.is_some() && !c.is_wallet_user_agent())
{
wallet
.set_base_node_peer(
conn.public_key
.clone()
.unwrap()
.try_into_sr25519()
.unwrap()
.inner_key()
.clone(),
None,
Some(base_nodes.to_vec()),
)
.await
.map_err(|e| {
ExitError::new(
ExitCode::WalletError,
format!("Error setting wallet base node peer. {}", e),
)
})?;
break;
}
if remaining_time == 0 {
warn!(target: LOG_TARGET, "No base node peer connections within 10s. Please configure a base node.");
break;
}
debug!(target: LOG_TARGET, "Waiting for active base node connections");
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
remaining_time -= 1;
}
}

// Restart transaction protocols if not running in script or command modes
if !matches!(wallet_mode, WalletMode::Command(_)) && !matches!(wallet_mode, WalletMode::Script(_)) {
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/src/ui/app.rs
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ impl<B: Backend> App<B> {
title: String,
wallet: WalletSqlite,
wallet_config: WalletConfig,
base_node_selected: Peer,
base_node_selected: Option<Peer>,
base_node_config: PeerConfig,
notifier: Notifier,
) -> Result<Self, ExitError> {
Original file line number Diff line number Diff line change
@@ -143,7 +143,10 @@ impl<B: Backend> Component<B> for BaseNode {
let base_node_id = Spans::from(vec![
Span::styled(" Connected Base Node ID: ", Style::default().fg(Color::Magenta)),
Span::styled(
app_state.get_selected_base_node().peer_id().to_string(),
app_state
.get_selected_base_node()
.map(|p| p.peer_id().to_string())
.unwrap_or_else(|| "<none>".to_string()),
Style::default().fg(base_node_id_color),
),
Span::styled(" ", Style::default().fg(Color::White)),
Original file line number Diff line number Diff line change
@@ -46,21 +46,23 @@ pub struct NetworkTab {
}

impl NetworkTab {
pub fn new(base_node_selected: Peer) -> Self {
let public_key = public_key_to_string(base_node_selected.public_key());
let address = display_address(&base_node_selected);
pub fn new(base_node_selected: Option<Peer>) -> Self {
let public_key = base_node_selected
.as_ref()
.map(|p| public_key_to_string(p.public_key()));
let address = base_node_selected.as_ref().map(display_address);

Self {
balance: Balance::new(),
base_node_edit_mode: BaseNodeInputMode::None,
public_key_field: public_key.clone(),
previous_public_key_field: public_key,
address_field: address.clone(),
previous_address_field: address,
public_key_field: public_key.clone().unwrap_or_default(),
previous_public_key_field: public_key.unwrap_or_default(),
address_field: address.clone().unwrap_or_default(),
previous_address_field: address.unwrap_or_default(),
error_message: None,
confirmation_dialog: false,
base_node_list_state: WindowedListState::new(),
detailed_base_node: Some(base_node_selected),
detailed_base_node: base_node_selected,
}
}

@@ -106,7 +108,7 @@ impl NetworkTab {
.collect();

for (peer_type, peer) in base_node_list {
let selected = peer.peer_id() == selected_peer.peer_id();
let selected = selected_peer.as_ref().map_or(false, |p| peer.peer_id() == p.peer_id());
let style = styles
.get(&selected)
.unwrap_or(&Style::default().fg(Color::Reset))
@@ -129,7 +131,7 @@ impl NetworkTab {
.heading_style(Style::default().fg(Color::Magenta))
.max_width(MAX_WIDTH)
.add_column(Some("Type"), Some(17), column0_items)
.add_column(Some("NodeID"), Some(27), column1_items)
.add_column(Some("NodeID"), Some(57), column1_items)
.add_column(Some("Public Key"), Some(65), column2_items);
column_list.render(f, areas[1], &mut base_node_list_state);
}
@@ -263,7 +265,12 @@ impl NetworkTab {
let (public_key, style) = match self.base_node_edit_mode {
BaseNodeInputMode::PublicKey => (self.public_key_field.clone(), Style::default().fg(Color::Magenta)),
BaseNodeInputMode::Address => (self.public_key_field.clone(), Style::default()),
_ => (public_key_to_string(peer.public_key()), Style::default()),
_ => (
peer.as_ref()
.map(|p| public_key_to_string(p.public_key()))
.unwrap_or_default(),
Style::default(),
),
};

let pubkey_input = Paragraph::new(public_key)
@@ -274,7 +281,7 @@ impl NetworkTab {
let (public_address, style) = match self.base_node_edit_mode {
BaseNodeInputMode::PublicKey => (self.address_field.clone(), Style::default()),
BaseNodeInputMode::Address => (self.address_field.clone(), Style::default().fg(Color::Magenta)),
_ => (display_address(peer), Style::default()),
_ => (peer.map(display_address).unwrap_or_default(), Style::default()),
};

let address_input = Paragraph::new(public_address)
@@ -300,10 +307,10 @@ impl NetworkTab {
self.previous_public_key_field = self.public_key_field.clone();
self.previous_address_field = self.address_field.clone();
let base_node_previous = app_state.get_previous_base_node().clone();
let public_key = public_key_to_string(base_node_previous.public_key());
let public_address = display_address(&base_node_previous);
self.public_key_field = public_key;
self.address_field = public_address;
let public_key = base_node_previous.map(|p| public_key_to_string(p.public_key()));
let public_address = base_node_previous.map(display_address);
self.public_key_field = public_key.unwrap_or_default();
self.address_field = public_address.unwrap_or_default();
self.confirmation_dialog = false;
self.base_node_edit_mode = BaseNodeInputMode::Selection;
return KeyHandled::Handled;
@@ -320,7 +327,7 @@ impl NetworkTab {
BaseNodeInputMode::PublicKey => match c {
'\n' => {
self.previous_address_field = self.address_field.clone();
self.address_field = "".to_string();
self.address_field = String::new();
self.base_node_edit_mode = BaseNodeInputMode::Address;
return KeyHandled::Handled;
},
@@ -452,7 +459,9 @@ impl<B: Backend> Component<B> for NetworkTab {
},
's' => {
// set the currently selected base node as a custom base node
let base_node = app_state.get_selected_base_node();
let Some(base_node) = app_state.get_selected_base_node() else {
return;
};
let public_key = public_key_to_string(base_node.public_key());
let address = base_node.addresses().first().map(|a| a.to_string()).unwrap_or_default();

@@ -496,7 +505,7 @@ impl<B: Backend> Component<B> for NetworkTab {
_ => {
self.base_node_list_state.select(None);
self.base_node_edit_mode = BaseNodeInputMode::None;
self.detailed_base_node = Some(app_state.get_selected_base_node().clone());
self.detailed_base_node = app_state.get_selected_base_node().cloned();
},
}
}
@@ -507,7 +516,7 @@ impl<B: Backend> Component<B> for NetworkTab {
.set_num_items(app_state.get_base_node_list().len());
self.base_node_list_state.next();
self.detailed_base_node = match self.base_node_list_state.selected() {
None => Some(app_state.get_selected_base_node().clone()),
None => app_state.get_selected_base_node().cloned(),
Some(i) => {
let (_, peer) = match app_state.get_base_node_list().get(i) {
None => ("".to_string(), None),
@@ -525,7 +534,7 @@ impl<B: Backend> Component<B> for NetworkTab {
.set_num_items(app_state.get_base_node_list().len());
self.base_node_list_state.previous();
self.detailed_base_node = match self.base_node_list_state.selected() {
None => Some(app_state.get_selected_base_node().clone()),
None => app_state.get_selected_base_node().cloned(),
Some(i) => {
let (_, peer) = match app_state.get_base_node_list().get(i) {
None => ("".to_string(), None),
Loading