Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
Fix keystore after integration testing (#252)
Browse files Browse the repository at this point in the history
* fix evm key store filename

* fix evm key store filename

* hex encode evm private key

* add missing crate

* more logs

* log

* fix join subnet

* fix join subnet

* fix top down target subnet to parent

* fix top down target subnet to child

* fix itest

* fix create itest

* itest use agent from
  • Loading branch information
cryptoAtwill authored Jul 12, 2023

Verified

This commit was signed with the committer’s verified signature.
burgholzer Lukas Burgholzer
1 parent 4970fb0 commit 46e798c
Showing 10 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ bytes = "1.4.0"
serde_bytes = "0.11.9"
clap = { version = "4.1.4", features = ["env", "derive"] }
thiserror = { workspace = true }
hex = { workspace = true }
serde_tuple = "0.5.0"
zeroize = "1.6.0"

2 changes: 2 additions & 0 deletions identity/src/evm/mod.rs
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ use zeroize::Zeroize;

pub use crate::evm::persistent::PersistentKeyStore;

pub const DEFAULT_KEYSTORE_NAME: &str = "evm_keystore.json";

/// The key store trait for different evm key store
pub trait KeyStore {
/// The type of the key that is stored
4 changes: 3 additions & 1 deletion identity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -6,5 +6,7 @@
mod evm;
mod fvm;

pub use crate::evm::{KeyInfo as EvmKeyInfo, KeyStore as EvmKeyStore, PersistentKeyStore};
pub use crate::evm::{
KeyInfo as EvmKeyInfo, KeyStore as EvmKeyStore, PersistentKeyStore, DEFAULT_KEYSTORE_NAME,
};
pub use crate::fvm::*;
5 changes: 4 additions & 1 deletion src/manager/evm/manager.rs
Original file line number Diff line number Diff line change
@@ -95,7 +95,10 @@ impl SubnetManager for EthSubnetManager {

log::info!("creating subnet on evm with params: {params:?}");

let signer = self.get_signer(&payload_to_evm_address(from.payload())?)?;
let evm_from = payload_to_evm_address(from.payload())?;
log::debug!("original from address: {from:?}, evm: {evm_from:?}");

let signer = self.get_signer(&evm_from)?;
let registry_contract =
SubnetRegistry::new(self.ipc_contract_info.registry_addr, Arc::new(signer));

7 changes: 3 additions & 4 deletions src/server/handlers/config.rs
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@ use crate::config::ReloadableConfig;
use crate::server::JsonRPCRequestHandler;
use anyhow::anyhow;
use async_trait::async_trait;
use ipc_identity::PersistentKeyStore;
use ipc_identity::{KeyStore, KeyStoreConfig, KEYSTORE_NAME};
use ipc_identity::{PersistentKeyStore, DEFAULT_KEYSTORE_NAME};
use serde::{Deserialize, Serialize};
use std::{path::Path, sync::Arc};

@@ -56,9 +56,8 @@ pub fn new_evm_keystore_from_config(
) -> anyhow::Result<PersistentKeyStore<ethers::types::Address>> {
let repo_str = config.get_config_repo();
if let Some(repo_str) = repo_str {
let repo = Path::new(&repo_str);
PersistentKeyStore::new(repo.into())
.map_err(|e| anyhow!("Failed to create evm keystore: {}", e))
let repo = Path::new(&repo_str).join(DEFAULT_KEYSTORE_NAME);
PersistentKeyStore::new(repo).map_err(|e| anyhow!("Failed to create evm keystore: {}", e))
} else {
Err(anyhow!("No keystore repo found in config"))
}
2 changes: 1 addition & 1 deletion src/server/handlers/manager/create.rs
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ impl JsonRPCRequestHandler for CreateSubnetHandler {
};

let from = parse_from(subnet_config, request.from)?;
log::debug!("conn: {:?}", conn.subnet());
log::debug!("conn: {:?}, from: {from:?}", conn.subnet());

let created_subnet_addr = conn
.manager()
8 changes: 6 additions & 2 deletions src/server/handlers/wallet/import.rs
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ pub struct FvmImportParams {

#[derive(Debug, Serialize, Deserialize)]
pub struct EvmImportParams {
/// Base64 encoded private key string
/// Hex encoded private key string
pub private_key: String,
}

@@ -93,7 +93,11 @@ impl WalletImportHandler {
fn import_evm(&self, request: &EvmImportParams) -> anyhow::Result<WalletImportResponse> {
let mut keystore = self.evm_keystore.write().unwrap();

let private_key = base64::engine::general_purpose::STANDARD.decode(&request.private_key)?;
let private_key = if !request.private_key.starts_with("0x") {
hex::decode(&request.private_key)?
} else {
hex::decode(&request.private_key.as_str()[2..])?
};
let addr = keystore.put(EvmKeyInfo::new(private_key))?;

Ok(WalletImportResponse {
2 changes: 1 addition & 1 deletion testing/itest/src/infra/mod.rs
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ impl SubnetInfra {

let actor_addr = util::create_subnet(
self.config.ipc_agent_url(),
self.config.parent_wallet_address.clone(),
None,
parent,
self.config.name.clone(),
self.config.number_of_nodes as u64,
3 changes: 2 additions & 1 deletion testing/itest/src/infra/subnet.rs
Original file line number Diff line number Diff line change
@@ -365,7 +365,8 @@ impl SubnetNode {
pub async fn join_subnet(&self) -> Result<()> {
util::join_subnet(
self.ipc_agent_url.clone(),
self.wallet_address.clone().unwrap(),
None,
Some(self.wallet_address.clone().unwrap()),
self.id.to_string(),
DEFAULT_MIN_STAKE,
self.validator.net_addr.clone().unwrap(),
11 changes: 6 additions & 5 deletions testing/itest/src/infra/util.rs
Original file line number Diff line number Diff line change
@@ -21,14 +21,14 @@ fn client_from_url(url: String) -> anyhow::Result<IpcAgentClient<JsonRpcClientIm
/// Create a new subnet in the actor
pub async fn create_subnet(
ipc_agent_url: String,
from: String,
from: Option<String>,
parent: String,
name: String,
min_validators: u64,
) -> anyhow::Result<String> {
let client = client_from_url(ipc_agent_url)?;
let params = CreateSubnetParams {
from: Some(from),
from,
parent,
name,
min_validator_stake: DEFAULT_MIN_STAKE,
@@ -42,18 +42,19 @@ pub async fn create_subnet(
/// Join the subnet
pub async fn join_subnet(
ipc_agent_url: String,
from: String,
from: Option<String>,
worker_addr: Option<String>,
subnet: String,
collateral: f64,
validator_net_addr: String,
) -> anyhow::Result<()> {
let client = client_from_url(ipc_agent_url)?;
let params = JoinSubnetParams {
subnet,
from: Some(from),
from,
collateral,
validator_net_addr,
worker_addr: None,
worker_addr,
};
client.join_subnet(params).await
}

0 comments on commit 46e798c

Please sign in to comment.