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

feat: dedockerize nodes #319

Merged
merged 24 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bcda877
Working local testing
ChaoticTempest Oct 11, 2023
97eceaf
Moved running local related testing functions over to local.rs
ChaoticTempest Oct 11, 2023
fa5f204
Reduced LeaderNode::api to not require arguments
ChaoticTempest Oct 11, 2023
3fff52a
Moved all containers init into env/
ChaoticTempest Oct 12, 2023
869c39a
Moved containers.rs and local.rs into env/
ChaoticTempest Oct 12, 2023
9d967f3
Change feature flag to docker-test
ChaoticTempest Oct 12, 2023
4895ad5
Fix docker test
ChaoticTempest Oct 12, 2023
2d496cf
Consistent way to create CLI args
ChaoticTempest Oct 12, 2023
920b895
Removed need for integration-tests/main.rs
ChaoticTempest Oct 12, 2023
b4de4f0
Merge branch 'develop' of github.com:near/mpc-recovery into phuong/fe…
ChaoticTempest Oct 12, 2023
46b615a
Update docs and cleanup
ChaoticTempest Oct 12, 2023
fdcbeaf
Merge branch 'develop' of github.com:near/mpc-recovery into phuong/fe…
ChaoticTempest Oct 13, 2023
d68e11f
Cleanup
ChaoticTempest Oct 13, 2023
3f2fc62
setup-env cmd
ChaoticTempest Oct 13, 2023
8c7288e
Update GA pipeline
ChaoticTempest Oct 13, 2023
2b04955
More cleanup
ChaoticTempest Oct 13, 2023
9fbf7f5
Use env::run for setup-env
ChaoticTempest Oct 13, 2023
3921623
More cleanup
ChaoticTempest Oct 13, 2023
8ca535a
Better setup-env logging
ChaoticTempest Oct 13, 2023
3325261
prefer 127.0.0.1 over localhost to enforce IPv4
itegulov Oct 16, 2023
c7d3837
Separate out docker image dep
ChaoticTempest Oct 16, 2023
cb00f2c
Merge branch 'phuong/feat/dedockerize-node' of github.com:near/mpc-re…
ChaoticTempest Oct 16, 2023
6c56325
Rename local_url to pk_local_url
ChaoticTempest Oct 16, 2023
0b925a8
Move mpc-recovery build step
ChaoticTempest Oct 16, 2023
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
More cleanup
  • Loading branch information
ChaoticTempest committed Oct 13, 2023
commit 2b0495598b44991b1470f61bca024a6fb82b52e1
27 changes: 13 additions & 14 deletions integration-tests/src/env/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ pub struct SignerNode<'a> {
pub container: Container<'a, GenericImage>,
pub address: String,
pub local_address: String,

env: String,
node_id: usize,
sk_share: ExpandedKeyPair,
cipher_key: GenericArray<u8, U32>,
Expand All @@ -508,7 +510,7 @@ impl SignerNode<'_> {
.with_env_var("RUST_LOG", "mpc_recovery=DEBUG");

let args = mpc_recovery::Cli::StartSign {
env: "dev".to_string(),
env: ctx.env.clone(),
node_id: node_id as u64,
web_port: Self::CONTAINER_PORT,
sk_share: Some(serde_json::to_string(&sk_share)?),
Expand Down Expand Up @@ -553,6 +555,8 @@ impl SignerNode<'_> {
container,
address: full_address,
local_address: format!("http://localhost:{host_port}"),

env: ctx.env.clone(),
node_id,
sk_share: sk_share.clone(),
cipher_key: *cipher_key,
Expand All @@ -563,6 +567,7 @@ impl SignerNode<'_> {

pub fn api(&self) -> SignerNodeApi {
SignerNodeApi {
env: self.env.clone(),
address: self.local_address.clone(),
node_id: self.node_id,
sk_share: self.sk_share.clone(),
Expand All @@ -585,9 +590,8 @@ impl SignerNodeApi {
&self,
new_cipher_key: &GenericArray<u8, U32>,
) -> anyhow::Result<(Aes256Gcm, Aes256Gcm)> {
let env = "dev".to_string();
let gcp_service = mpc_recovery::gcp::GcpService::new(
env,
self.env.clone(),
self.gcp_project_id.clone(),
Some(self.gcp_datastore_local_url.clone()),
)
Expand Down Expand Up @@ -622,28 +626,23 @@ impl<'a> LeaderNode<'a> {
// Container port used for the docker network, does not have to be unique
const CONTAINER_PORT: u16 = 3000;

pub async fn run(
ctx: &Context<'a>,
sign_nodes: Vec<String>,
near_root_account: &AccountId,
account_creator_id: &AccountId,
account_creator_sk: &workspaces::types::SecretKey,
) -> anyhow::Result<LeaderNode<'a>> {
pub async fn run(ctx: &Context<'a>, sign_nodes: Vec<String>) -> anyhow::Result<LeaderNode<'a>> {
tracing::info!("Running leader node container...");
let account_creator = &ctx.relayer_ctx.creator_account;

let image = GenericImage::new("near/mpc-recovery", "latest")
.with_wait_for(WaitFor::Nothing)
.with_exposed_port(Self::CONTAINER_PORT)
.with_env_var("RUST_LOG", "mpc_recovery=DEBUG");

let args = mpc_recovery::Cli::StartLeader {
env: "dev".to_string(),
env: ctx.env.clone(),
web_port: Self::CONTAINER_PORT,
sign_nodes,
near_rpc: ctx.relayer_ctx.sandbox.address.clone(),
near_root_account: near_root_account.to_string(),
account_creator_id: account_creator_id.clone(),
account_creator_sk: Some(account_creator_sk.to_string()),
near_root_account: ctx.relayer_ctx.worker.root_account()?.id().to_string(),
account_creator_id: account_creator.id().clone(),
account_creator_sk: Some(account_creator.secret_key().to_string()),
fast_auth_partners: Some(
serde_json::json!([
{
Expand Down
34 changes: 15 additions & 19 deletions integration-tests/src/env/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::util;

pub struct SignerNode {
pub address: String,
env: String,
node_id: usize,
sk_share: ExpandedKeyPair,
cipher_key: GenericArray<u8, U32>,
Expand All @@ -27,18 +28,17 @@ pub struct SignerNode {

impl SignerNode {
pub async fn run(
web_port: u16,
ctx: &super::Context<'_>,
node_id: u64,
sk_share: &ExpandedKeyPair,
cipher_key: &GenericArray<u8, U32>,
ctx: &super::Context<'_>,
release: bool,
) -> anyhow::Result<Self> {
let executable = util::executable(release)
let executable = util::executable(ctx.release)
.context("could not find target dir while running signing node")?;
let web_port = util::pick_unused_port().await?;

let args = mpc_recovery::Cli::StartSign {
env: "dev".to_string(),
env: ctx.env.clone(),
node_id,
web_port,
sk_share: Some(serde_json::to_string(&sk_share)?),
Expand Down Expand Up @@ -88,6 +88,7 @@ impl SignerNode {

Ok(Self {
address,
env: ctx.env.clone(),
node_id: node_id as usize,
sk_share: sk_share.clone(),
cipher_key: *cipher_key,
Expand All @@ -100,6 +101,7 @@ impl SignerNode {
pub fn api(&self) -> SignerNodeApi {
SignerNodeApi {
address: self.address.clone(),
env: self.env.clone(),
node_id: self.node_id,
sk_share: self.sk_share.clone(),
cipher_key: self.cipher_key,
Expand All @@ -120,27 +122,21 @@ pub struct LeaderNode {
}

impl LeaderNode {
pub async fn run(
ctx: &super::Context<'_>,
web_port: u16,
sign_nodes: Vec<String>,
near_root_account: &workspaces::AccountId,
account_creator_id: &workspaces::AccountId,
account_creator_sk: &workspaces::types::SecretKey,
release: bool,
) -> anyhow::Result<Self> {
pub async fn run(ctx: &super::Context<'_>, sign_nodes: Vec<String>) -> anyhow::Result<Self> {
tracing::info!("Running leader node...");
let executable = util::executable(release)
let executable = util::executable(ctx.release)
.context("could not find target dir while running leader node")?;
let account_creator = &ctx.relayer_ctx.creator_account;
let web_port = util::pick_unused_port().await?;

let args = mpc_recovery::Cli::StartLeader {
env: "dev".to_string(),
env: ctx.env.clone(),
web_port,
sign_nodes,
near_rpc: ctx.relayer_ctx.sandbox.local_address.clone(),
near_root_account: near_root_account.to_string(),
account_creator_id: account_creator_id.clone(),
account_creator_sk: Some(account_creator_sk.to_string()),
near_root_account: ctx.relayer_ctx.worker.root_account()?.id().to_string(),
account_creator_id: account_creator.id().clone(),
account_creator_sk: Some(account_creator.secret_key().to_string()),
fast_auth_partners: Some(
serde_json::json!([
{
Expand Down
57 changes: 23 additions & 34 deletions integration-tests/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ use mpc_recovery::relayer::NearRpcAndRelayerClient;
use mpc_recovery::GenerateResult;

use crate::env::containers::DockerClient;
use crate::{initialize_relayer, util, RelayerCtx};
use crate::{initialize_relayer, RelayerCtx};

pub const NETWORK: &str = "mpc_it_network";
pub const GCP_PROJECT_ID: &str = "mpc-recovery-gcp-project";
const ENV: &str = "dev";
const NETWORK: &str = "mpc_it_network";
const GCP_PROJECT_ID: &str = "mpc-recovery-gcp-project";
// TODO: figure out how to instantiate and use a local firebase deployment
pub const FIREBASE_AUDIENCE_ID: &str = "test_audience";
const FIREBASE_AUDIENCE_ID: &str = "test_audience";

pub struct SignerNodeApi {
pub env: String,
pub address: String,
pub node_id: usize,
pub sk_share: ExpandedKeyPair,
Expand Down Expand Up @@ -84,10 +86,12 @@ impl Nodes<'_> {
}

pub struct Context<'a> {
pub env: String,
pub docker_client: &'a DockerClient,
pub docker_network: String,
pub gcp_project_id: String,
pub audience_id: String,
pub release: bool,

pub relayer_ctx: RelayerCtx<'a>,
pub datastore: containers::Datastore<'a>,
Expand All @@ -112,10 +116,12 @@ pub async fn setup(docker_client: &DockerClient) -> anyhow::Result<Context<'_>>
let oidc_provider = oidc_provider?;

Ok(Context {
env: ENV.to_string(),
docker_client,
docker_network: docker_network.to_string(),
gcp_project_id: gcp_project_id.to_string(),
audience_id: FIREBASE_AUDIENCE_ID.to_string(),
release: true,
relayer_ctx,
datastore,
oidc_provider,
Expand All @@ -136,17 +142,8 @@ pub async fn docker(nodes: usize, docker_client: &DockerClient) -> anyhow::Resul
.await
.into_iter()
.collect::<Result<Vec<_>, _>>()?;
let signer_urls: &Vec<_> = &signer_nodes.iter().map(|n| n.address.clone()).collect();

let near_root_account = ctx.relayer_ctx.worker.root_account()?;
let leader_node = containers::LeaderNode::run(
&ctx,
signer_urls.clone(),
near_root_account.id(),
ctx.relayer_ctx.creator_account.id(),
ctx.relayer_ctx.creator_account.secret_key(),
)
.await?;
let sign_nodes = signer_nodes.iter().map(|n| n.address.clone()).collect();
let leader_node = containers::LeaderNode::run(&ctx, sign_nodes).await?;

Ok(Nodes::Docker {
ctx,
Expand All @@ -161,31 +158,15 @@ pub async fn host(nodes: usize, docker_client: &DockerClient) -> anyhow::Result<
let GenerateResult { pk_set, secrets } = mpc_recovery::generate(nodes);
let mut signer_node_futures = Vec::with_capacity(nodes);
for (i, (share, cipher_key)) in secrets.iter().enumerate().take(nodes) {
signer_node_futures.push(local::SignerNode::run(
util::pick_unused_port().await?,
i as u64,
share,
cipher_key,
&ctx,
true,
));
signer_node_futures.push(local::SignerNode::run(&ctx, i as u64, share, cipher_key));
}
let signer_nodes = futures::future::join_all(signer_node_futures)
.await
.into_iter()
.collect::<Result<Vec<_>, _>>()?;

let near_root_account = ctx.relayer_ctx.worker.root_account()?;
let leader_node = local::LeaderNode::run(
&ctx,
util::pick_unused_port().await?,
signer_nodes.iter().map(|n| n.address.clone()).collect(),
near_root_account.id(),
ctx.relayer_ctx.creator_account.id(),
ctx.relayer_ctx.creator_account.secret_key(),
true,
)
.await?;
let sign_nodes = signer_nodes.iter().map(|n| n.address.clone()).collect();
let leader_node = local::LeaderNode::run(&ctx, sign_nodes).await?;

Ok(Nodes::Local {
ctx,
Expand All @@ -194,3 +175,11 @@ pub async fn host(nodes: usize, docker_client: &DockerClient) -> anyhow::Result<
signer_nodes,
})
}

pub async fn run(nodes: usize, docker_client: &DockerClient) -> anyhow::Result<Nodes> {
#[cfg(feature = "docker-test")]
return docker(nodes, docker_client).await;

#[cfg(not(feature = "docker-test"))]
return host(nodes, docker_client).await;
}
10 changes: 4 additions & 6 deletions integration-tests/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use mpc_recovery_integration_tests::env::containers::DockerClient;
use workspaces::{network::Sandbox, Worker};

pub struct TestContext {
env: String,
leader_node: env::LeaderNodeApi,
pk_set: Vec<Point<Ed25519>>,
worker: Worker<Sandbox>,
Expand All @@ -24,7 +25,7 @@ pub struct TestContext {
impl TestContext {
pub async fn gcp_service(&self) -> anyhow::Result<GcpService> {
GcpService::new(
"dev".into(),
self.env.clone(),
self.gcp_project_id.clone(),
Some(self.gcp_datastore_url.clone()),
)
Expand All @@ -38,13 +39,10 @@ where
Fut: core::future::Future<Output = anyhow::Result<Val>>,
{
let docker_client = DockerClient::default();
let nodes = if cfg!(feature = "docker-test") {
env::docker(nodes, &docker_client).await?
} else {
env::host(nodes, &docker_client).await?
};
let nodes = env::run(nodes, &docker_client).await?;

f(TestContext {
env: nodes.ctx().env.clone(),
pk_set: nodes.pk_set(),
leader_node: nodes.leader_api(),
signer_nodes: nodes.signer_apis(),
Expand Down