Skip to content

Commit

Permalink
Add state based registration to registration server
Browse files Browse the repository at this point in the history
Since the register endpoint can be called simultaneously by multiple router, we need to queue up these txs and
batch them together and setup the correct nonce
  • Loading branch information
Pranay Tulugu committed Sep 15, 2023
1 parent 916f39f commit 2df26e8
Show file tree
Hide file tree
Showing 14 changed files with 612 additions and 299 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ settings = { path = "../settings" }
rita_client = { path = "../rita_client", features = ["dev_env"] }
rita_common = { path = "../rita_common", features = ["integration_test"] }
rita_exit = { path = "../rita_exit", features = ["dev_env"] }
rita_client_registration = { path = "../rita_client_registration" }
ctrlc = { version = "3.2.1", features = ["termination"] }
diesel = { version = "1.4", features = ["postgres", "r2d2"] }
diesel_migrations = { version = "1.4", features = ["postgres"] }
Expand All @@ -34,3 +35,6 @@ num256 = "0.5"
num-traits = "0.2"
web30 = "1.0"
lazy_static = "1.4"
actix-web = { version = "4.3", default_features = false, features = [
"openssl",
] }
13 changes: 13 additions & 0 deletions integration_tests/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ pub fn generate_rita_config_file(path: String) -> Result<(), KernelInterfaceErro
.to_string();
lines.push(exit);

let contact_info = "
[exit_client.contact_info.number.national]\n
value = 7040000000\n
zeros = 0\n
[exit_client.contact_info.number.code]\n
source = \"plus\"\n
value = 1\n
"
.to_string();
lines.push(contact_info);

let log = "
[log]\n
enabled = true\n"
Expand All @@ -64,6 +75,7 @@ pub fn generate_exit_config_file(path: String) -> Result<(), KernelInterfaceErro
let mut lines: Vec<String> = Vec::new();
let desc = "
db_uri = \"postgres://postgres@localhost/test\"\n
client_registration_url = \"https://7.7.7.1:40400/register_router\"\n
workers = 1\n
description = \"just a normal althea exit\"\n"
.to_string();
Expand Down Expand Up @@ -115,6 +127,7 @@ pub fn generate_exit_config_file(path: String) -> Result<(), KernelInterfaceErro
wg_public_key = \"H/ABwzXk834OwGYU8CZGfFxNZOd+BAJEaVDHiEiWWhU=\"\n
wg_private_key = \"ALxcZm2r58gY0sB4vIfnjShc86qBoVK3f32H9VrwqWU=\"\n
wg_private_key_path = \"/tmp/exit-priv\"\n
registered_users_contract_addr = \"0xb9b674D720F96995ca033ec347df080d500c2230\"\n
pass = \"Some pass here\"\n"
.to_string();
lines.push(exit_network);
Expand Down
196 changes: 196 additions & 0 deletions integration_tests/src/contract_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
use std::{thread, time::Duration};

use althea_types::Identity;
use rita_client_registration::client_db::{
add_client_to_registered_list, get_all_regsitered_clients, get_registered_client_using_ethkey,
get_registered_client_using_meship, get_registered_client_using_wgkey,
};
use web30::client::Web3;

use crate::{
payments_eth::{ETH_MINER_KEY, WEB3_TIMEOUT},
utils::{get_altheadb_contract_addr, get_eth_node},
};

pub async fn run_altheadb_contract_test() {
// Try adding a dummy entry and validating that we can retrive them
validate_contract_functionality().await;

thread::sleep(Duration::from_secs(1000));
}

pub async fn validate_contract_functionality() {
let contact = Web3::new(&get_eth_node(), WEB3_TIMEOUT);

// Define the users
let user = Identity {
mesh_ip: "fd00::1337".parse().unwrap(),
eth_address: "0x02ad6b480DFeD806C63a0839C6f1f3136c5fD515"
.parse()
.unwrap(),
wg_public_key: "sPtNGQbyPpCsqSKD6PbnflB1lIUCd259Vhd0mJfJeGo="
.parse()
.unwrap(),
nickname: None,
};

let user_2 = Identity {
mesh_ip: "fd00::1447:1447".parse().unwrap(),
eth_address: "0x1994A73F79F9648d4a8064D9C0F221fB1007Fd2F"
.parse()
.unwrap(),
wg_public_key: "Yhyj+CKZbyEKea/9hdIFje98yc5Cukt1Pbq0qWB4Aqw="
.parse()
.unwrap(),
nickname: None,
};

let user_3 = Identity {
mesh_ip: "fd00::3000:1117".parse().unwrap(),
eth_address: "0x9c33D0dFdc9E3f7cC73bE3A575C31cfe3059C76a"
.parse()
.unwrap(),
wg_public_key: "fzOUfEqYzRE0MwfR5o7XV+MKZKj/qEfELRzQTRTKAB8="
.parse()
.unwrap(),
nickname: None,
};

// Try requests when there are no users present
let res = get_all_regsitered_clients(
&contact,
ETH_MINER_KEY
.parse::<clarity::PrivateKey>()
.unwrap()
.to_address(),
get_altheadb_contract_addr(),
)
.await
.unwrap();

assert!(res.is_empty());

let res = get_registered_client_using_wgkey(
user.wg_public_key,
ETH_MINER_KEY
.parse::<clarity::PrivateKey>()
.unwrap()
.to_address(),
get_altheadb_contract_addr(),
&contact,
)
.await;

assert!(res.is_err());

// Add the first user
let _res = add_client_to_registered_list(
&contact,
user,
get_altheadb_contract_addr(),
ETH_MINER_KEY.parse().unwrap(),
None,
vec![],
)
.await
.unwrap();

thread::sleep(Duration::from_secs(5));

// Try requesting some info that doesnt exist
let res = get_registered_client_using_ethkey(
"0x3d261902a988d94599d7f0Bd4c2e4514D73BB329"
.parse()
.unwrap(),
ETH_MINER_KEY
.parse::<clarity::PrivateKey>()
.unwrap()
.to_address(),
get_altheadb_contract_addr(),
&contact,
)
.await;

assert!(res.is_err());

// Add the second user
let _res = add_client_to_registered_list(
&contact,
user_2,
get_altheadb_contract_addr(),
ETH_MINER_KEY.parse().unwrap(),
None,
vec![],
)
.await
.unwrap();

thread::sleep(Duration::from_secs(5));

// Add the third user
let _res = add_client_to_registered_list(
&contact,
user_3,
get_altheadb_contract_addr(),
ETH_MINER_KEY.parse().unwrap(),
None,
vec![],
)
.await
.unwrap();

thread::sleep(Duration::from_secs(10));

let res = get_all_regsitered_clients(
&contact,
ETH_MINER_KEY
.parse::<clarity::PrivateKey>()
.unwrap()
.to_address(),
get_altheadb_contract_addr(),
)
.await;

println!("All users are : {:?}", res);

thread::sleep(Duration::from_secs(5));

let res = get_registered_client_using_wgkey(
user.wg_public_key,
ETH_MINER_KEY
.parse::<clarity::PrivateKey>()
.unwrap()
.to_address(),
get_altheadb_contract_addr(),
&contact,
)
.await
.unwrap();
assert_eq!(res, user);

let res = get_registered_client_using_ethkey(
user_2.eth_address,
ETH_MINER_KEY
.parse::<clarity::PrivateKey>()
.unwrap()
.to_address(),
get_altheadb_contract_addr(),
&contact,
)
.await
.unwrap();
assert_eq!(res, user_2);

let res = get_registered_client_using_meship(
user_3.mesh_ip,
ETH_MINER_KEY
.parse::<clarity::PrivateKey>()
.unwrap()
.to_address(),
get_altheadb_contract_addr(),
&contact,
)
.await
.unwrap();
assert_eq!(res, user_3);
}
25 changes: 21 additions & 4 deletions integration_tests/src/five_nodes.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::payments_eth::{ONE_ETH, WEB3_TIMEOUT};
use crate::setup_utils::database::start_postgres;
use crate::setup_utils::namespaces::*;
use crate::setup_utils::rita::thread_spawner;
use crate::utils::{
get_default_settings, register_all_namespaces_to_exit, test_all_internet_connectivity,
test_reach_all, test_routes,
get_default_settings, register_all_namespaces_to_exit, send_eth_bulk,
test_all_internet_connectivity, test_reach_all, test_routes,
};
use log::info;
use std::collections::HashMap;
use std::thread;
use std::time::Duration;
use web30::client::Web3;

/// Runs a five node fixed network map test scenario, this does basic network setup and tests reachability to
/// all destinations
Expand All @@ -27,7 +29,7 @@ pub async fn run_five_node_test_scenario() {
let res = setup_ns(namespaces.clone());
info!("Namespaces setup: {res:?}");

let _ = thread_spawner(namespaces.clone(), client_settings, exit_settings)
let rita_identities = thread_spawner(namespaces.clone(), client_settings, exit_settings)
.expect("Could not spawn Rita threads");
info!("Thread Spawner: {res:?}");

Expand All @@ -38,11 +40,26 @@ pub async fn run_five_node_test_scenario() {

test_routes(namespaces.clone(), expected_routes);

// Exits need to have funds to request a registered client list, which is needed for proper setup
info!("Topup exits with funds");
let web3 = Web3::new("http://localhost:8545", WEB3_TIMEOUT);
let mut to_top_up = Vec::new();
for c in rita_identities.client_identities {
to_top_up.push(c.eth_address);
}
for e in rita_identities.exit_identities {
to_top_up.push(e.eth_address)
}

info!("Sending 50 eth to all routers");
send_eth_bulk((ONE_ETH * 50).into(), &to_top_up, &web3).await;

info!("Registering routers to the exit");
register_all_namespaces_to_exit(namespaces.clone()).await;

thread::sleep(Duration::from_secs(10));

info!("Checking for wg_exit tunnel setup");
thread::sleep(Duration::from_secs(5));
test_all_internet_connectivity(namespaces.clone());
}

Expand Down
2 changes: 2 additions & 0 deletions integration_tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ extern crate lazy_static;
use std::time::Duration;

pub mod config;
pub mod contract_test;
pub mod debts;
pub mod five_nodes;
pub mod mutli_exit;
pub mod payments_althea;
pub mod payments_eth;
pub mod registration_server;
pub mod setup_utils;
pub mod utils;

Expand Down
Loading

0 comments on commit 2df26e8

Please sign in to comment.