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
cucumbers
sdbondi committed Oct 16, 2024
commit 67376b592dced63fa03d9844f18a3cb7856240b1
952 changes: 0 additions & 952 deletions 2q

This file was deleted.

2 changes: 0 additions & 2 deletions Cargo.lock

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

12 changes: 2 additions & 10 deletions applications/minotari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
@@ -99,21 +99,13 @@ use tari_key_manager::{
key_manager_service::{KeyId, KeyManagerInterface},
SeedWords,
};
use tari_network::{
multiaddr::Multiaddr,
DiscoveryResult,
NetworkEvent,
NetworkHandle,
NetworkingService,
Peer,
ToPeerId,
};
use tari_network::{multiaddr::Multiaddr, NetworkEvent, NetworkHandle, NetworkingService, Peer, ToPeerId};
use tari_p2p::{auto_update::AutoUpdateConfig, peer_seeds::SeedPeer, PeerSeedsConfig};
use tari_script::{push_pubkey_script, CheckSigSchnorrSignature};
use tari_shutdown::Shutdown;
use tari_utilities::{encoding::MBase58, hex::Hex, ByteArray, SafePassword};
use tokio::{
sync::{broadcast, mpsc, oneshot::error::RecvError},
sync::{broadcast, mpsc},
time::{sleep, timeout},
};

4 changes: 2 additions & 2 deletions applications/minotari_console_wallet/src/lib.rs
Original file line number Diff line number Diff line change
@@ -64,8 +64,8 @@ use tari_common::{
};
use tari_common_types::wallet_types::WalletType;
use tari_key_manager::cipher_seed::CipherSeed;
#[cfg(all(unix, feature = "libtor"))]
use tari_libtor::tor::Tor;
// #[cfg(all(unix, feature = "libtor"))]
// use tari_libtor::tor::Tor;
use tari_shutdown::Shutdown;
use tari_utilities::SafePassword;
use tokio::runtime::Runtime;
Original file line number Diff line number Diff line change
@@ -4,12 +4,7 @@
use std::collections::HashMap;

use log::*;
use tari_network::{
identity::{sr25519::PublicKey, OtherVariantError},
public_key_to_string,
Peer,
};
use tari_utilities::hex::Hex;
use tari_network::{public_key_to_string, Peer};
use tokio::runtime::Handle;
use tui::{
backend::Backend,
6 changes: 2 additions & 4 deletions applications/minotari_node/src/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -63,8 +63,6 @@ use tokio::sync::mpsc;
use crate::ApplicationConfig;

const LOG_TARGET: &str = "c::bn::initialization";
/// The minimum buffer size for the base node pubsub_connector channel
const BASE_NODE_BUFFER_MIN_SIZE: usize = 30;

pub struct BaseNodeBootstrapper<'a, B> {
pub app_config: &'a ApplicationConfig,
@@ -83,7 +81,7 @@ where B: BlockchainBackend + 'static
#[allow(clippy::too_many_lines)]
pub async fn bootstrap(self) -> Result<ServiceHandles, ExitError> {
let mut base_node_config = self.app_config.base_node.clone();
let mut p2p_config = self.app_config.base_node.p2p.clone();
let p2p_config = self.app_config.base_node.p2p.clone();
let peer_seeds = &self.app_config.peer_seeds;

let mempool_config = base_node_config.mempool.service.clone();
@@ -163,7 +161,7 @@ where B: BlockchainBackend + 'static
}

async fn setup_rpc_services(
mut networking: NetworkHandle,
networking: NetworkHandle,
handles: &ServiceHandles,
db: AsyncBlockchainDb<B>,
config: &P2pConfig,
2 changes: 1 addition & 1 deletion base_layer/chat_ffi/src/application_config.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ use tari_chat_client::{
networking::Multiaddr,
};
use tari_common::configuration::{MultiaddrList, Network, StringList};
use tari_p2p::{PeerSeedsConfig, TransportConfig, TransportType};
use tari_p2p::PeerSeedsConfig;

use crate::error::{InterfaceError, LibChatError};

9 changes: 2 additions & 7 deletions base_layer/chat_ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ use callback_handler::CallbackContactStatusChange;
use libc::c_int;
use log::info;
use minotari_app_utilities::identity_management::setup_node_identity;
use tari_chat_client::{config::ApplicationConfig, networking::PeerFeatures, ChatClient as ChatClientTrait, Client};
use tari_chat_client::{config::ApplicationConfig, ChatClient as ChatClientTrait, Client};
use tari_common_types::tari_address::TariAddress;
use tari_contacts::contacts_service::handle::ContactsServiceHandle;
use tokio::runtime::Runtime;
@@ -129,12 +129,7 @@ pub unsafe extern "C" fn create_chat_client(
ptr::null_mut::<ChatClient>()
};

let identity = match setup_node_identity(
(*config).chat_client.identity_file.clone(),
(*config).chat_client.p2p.public_addresses.clone().into_vec(),
true,
PeerFeatures::COMMUNICATION_NODE,
) {
let identity = match setup_node_identity((*config).chat_client.identity_file.clone(), true) {
Ok(node_id) => node_id,
_ => {
bad_identity("No identity loaded".to_string());
3 changes: 2 additions & 1 deletion base_layer/contacts/src/chat_client/src/networking.rs
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
use std::{str::FromStr, sync::Arc, time::Duration};

use tari_contacts::contacts_service::{handle::ContactsServiceHandle, ContactsServiceInitializer};
pub use tari_network::multiaddr::Multiaddr;
use tari_network::{identity, NetworkHandle, Peer};
use tari_p2p::{
connector::InboundMessaging,
@@ -41,7 +42,7 @@ use crate::{
error::NetworkingError,
};

const LOG_TARGET: &str = "contacts::chat_client::networking";
const _LOG_TARGET: &str = "contacts::chat_client::networking";

pub async fn start(
node_identity: Arc<identity::Keypair>,
1 change: 1 addition & 0 deletions base_layer/core/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ pub mod one_sided;
pub mod rolling_avg;
#[cfg(feature = "base_node")]
pub mod rolling_vec;
#[cfg(feature = "base_node")]
pub(crate) mod waiting_requests;

/// Hasher used in the DAN to derive masks and encrypted value keys
2 changes: 2 additions & 0 deletions base_layer/core/src/topics.rs
Original file line number Diff line number Diff line change
@@ -20,5 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#[cfg(feature = "base_node")]
pub const BLOCK_TOPIC: &str = "tari-block";
#[cfg(feature = "base_node")]
pub const TRANSACTION_TOPIC: &str = "tari-transaction";
22 changes: 11 additions & 11 deletions base_layer/p2p/src/peer_seeds.rs
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ impl DnsSeedResolver {
}

/// Parsed information from a DNS seed record
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(try_from = "String", into = "String")]
pub struct SeedPeer {
pub public_key: RistrettoPublicKey,
@@ -115,16 +115,14 @@ impl FromStr for SeedPeer {

impl Display for SeedPeer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}::{}",
self.public_key,
self.addresses
.iter()
.map(|ma| ma.to_string())
.collect::<Vec<_>>()
.join("::")
)
write!(f, "{}::", self.public_key)?;
for (i, addr) in self.addresses.iter().enumerate() {
write!(f, "{}", addr)?;
if i != self.addresses.len() - 1 {
write!(f, "::")?;
}
}
Ok(())
}
}

@@ -175,6 +173,8 @@ mod test {
"06e98e9c5eb52bd504836edec1878eccf12eb9f26a5fe5ec0e279423156e657a"
);
assert_eq!(seed.addresses.len(), 2);
let s2 = seed.to_string().parse::<SeedPeer>().unwrap();
assert_eq!(seed, s2);
}

#[test]
1 change: 0 additions & 1 deletion base_layer/wallet_ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -58,7 +58,6 @@ use std::{
slice,
str::FromStr,
sync::Arc,
time::Duration,
};

use chrono::{DateTime, Local};
4 changes: 2 additions & 2 deletions integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,8 +12,8 @@ minotari_app_grpc = { path = "../applications/minotari_app_grpc" }
minotari_app_utilities = { path = "../applications/minotari_app_utilities" }
minotari_node = { path = "../applications/minotari_node", features = ["metrics"] }
minotari_node_grpc_client = { path = "../clients/rust/base_node_grpc_client" }
tari_chat_client = { path = "../base_layer/contacts/src/chat_client" }
minotari_chat_ffi = { path = "../base_layer/chat_ffi" }
#tari_chat_client = { path = "../base_layer/contacts/src/chat_client" }
#minotari_chat_ffi = { path = "../base_layer/chat_ffi" }
tari_crypto = { version = "0.21.0" }
tari_common = { path = "../common" }
tari_common_types = { path = "../base_layer/common_types" }
23 changes: 19 additions & 4 deletions integration_tests/src/base_node_process.rs
Original file line number Diff line number Diff line change
@@ -36,27 +36,35 @@ use tari_common::{
configuration::{CommonConfig, MultiaddrList},
network_check::set_network_if_choice_valid,
};
use tari_network::identity;
use tari_crypto::ristretto::RistrettoPublicKey;
use tari_network::{identity, multiaddr::Multiaddr};
use tari_p2p::{auto_update::AutoUpdateConfig, Network, PeerSeedsConfig};
use tari_shutdown::Shutdown;
use tokio::task;
use tonic::transport::Channel;

use crate::{get_peer_addresses, get_port, wait_for_service, TariWorld};
use crate::{get_peer_seeds, get_port, wait_for_service, TariWorld};

#[derive(Clone)]
pub struct BaseNodeProcess {
pub name: String,
pub port: u64,
pub grpc_port: u64,
pub identity: identity::Keypair,
pub public_key: RistrettoPublicKey,
pub temp_dir_path: PathBuf,
pub is_seed_node: bool,
pub seed_nodes: Vec<String>,
pub config: BaseNodeConfig,
pub kill_signal: Shutdown,
}

impl BaseNodeProcess {
pub fn get_listen_addr(&self) -> Multiaddr {
format!("/ip4/127.0.0.1/tcp/{}", self.port).parse().unwrap()
}
}

impl Drop for BaseNodeProcess {
fn drop(&mut self) {
self.kill();
@@ -128,6 +136,13 @@ pub async fn spawn_base_node_with_config(
port,
grpc_port,
identity: base_node_identity.clone(),
public_key: base_node_identity
.public()
.clone()
.try_into_sr25519()
.unwrap()
.inner_key()
.clone(),
temp_dir_path: temp_dir_path.clone(),
is_seed_node,
seed_nodes: peers.clone(),
@@ -137,7 +152,7 @@ pub async fn spawn_base_node_with_config(

let name_cloned = bn_name.clone();

let peer_addresses = get_peer_addresses(world, &peers).await;
let peer_seeds = get_peer_seeds(world, &peers).await;

let mut common_config = CommonConfig::default();
common_config.base_path = temp_dir_path.clone();
@@ -148,7 +163,7 @@ pub async fn spawn_base_node_with_config(
base_node: base_node_config,
metrics: MetricsConfig::default(),
peer_seeds: PeerSeedsConfig {
peer_seeds: peer_addresses.into(),
peer_seeds: peer_seeds.into(),
dns_seeds_use_dnssec: false,
..Default::default()
},
1 change: 1 addition & 0 deletions integration_tests/src/ffi/callbacks.rs
Original file line number Diff line number Diff line change
@@ -337,6 +337,7 @@ impl Callbacks {
START.call_once(|| {
INSTANCE = Some(Self::default());
});
#[allow(static_mut_refs)]
INSTANCE.as_mut().unwrap()
}
}
23 changes: 14 additions & 9 deletions integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -23,10 +23,12 @@
use std::{convert::TryFrom, net::TcpListener, ops::Range, path::PathBuf, process, time::Duration};

use rand::Rng;
use tari_p2p::peer_seeds::SeedPeer;
use tokio::net::TcpSocket;

pub mod base_node_process;
pub mod chat_client;
pub mod chat_ffi;
// pub mod chat_client;
// pub mod chat_ffi;
pub mod ffi;
pub mod merge_mining_proxy;
pub mod miner;
@@ -57,13 +59,13 @@ pub fn get_base_dir() -> PathBuf {
}

pub async fn wait_for_service(port: u64) {
// The idea is that if the port is taken it means the service is running.
// If the port is not taken the service hasn't come up yet
// Check if we can open a socket to a port.
let max_tries = 4 * 60;
let mut attempts = 0;
let addr = ([127u8, 0, 0, 1], u16::try_from(port).unwrap()).into();

loop {
if TcpListener::bind(("127.0.0.1", u16::try_from(port).unwrap())).is_err() {
if TcpSocket::new_v4().unwrap().connect(addr).await.is_ok() {
return;
}

@@ -76,12 +78,15 @@ pub async fn wait_for_service(port: u64) {
}
}

pub async fn get_peer_addresses(world: &TariWorld, peers: &[String]) -> Vec<String> {
peers
pub async fn get_peer_seeds(world: &TariWorld, seed_peer_names: &[String]) -> Vec<String> {
seed_peer_names
.iter()
.map(|peer_string| {
let peer = world.base_nodes.get(peer_string.as_str()).unwrap().identity.to_peer();
peer.to_short_string()
let bn = world.base_nodes.get(peer_string.as_str()).unwrap();
SeedPeer::new(bn.public_key.clone(), vec![format!("/ip4/127.0.0.1/tcp/{}", bn.port)
.parse()
.unwrap()])
.to_string()
})
.collect()
}
Loading