From afa0a63c955fbde4603921e823bcc48d8499ea7e Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 19 Mar 2026 18:01:15 +0200 Subject: [PATCH] fix: suggestions fix 2 --- Cargo.lock | 16 ++++++ Cargo.toml | 2 + indexer/core/Cargo.toml | 2 +- indexer/core/src/config.rs | 4 +- indexer/core/src/lib.rs | 6 +-- integration_tests/Cargo.toml | 1 + integration_tests/src/config.rs | 12 ++--- .../src/key_management/secret_holders.rs | 5 +- key_protocol/src/lib.rs | 1 - nssa/Cargo.toml | 2 +- programs/amm/Cargo.toml | 6 ++- sequencer_core/Cargo.toml | 1 + sequencer_core/src/config.rs | 4 +- sequencer_core/src/lib.rs | 4 +- sequencer_rpc/Cargo.toml | 1 + sequencer_rpc/src/process.rs | 4 +- testnet_initial_state/Cargo.toml | 16 ++++++ .../src/lib.rs | 9 ++-- wallet/Cargo.toml | 1 + wallet/src/chain_storage.rs | 49 +++++++------------ wallet/src/cli/config.rs | 12 ++++- wallet/src/config.rs | 14 +++--- wallet/src/helperfunctions.rs | 6 +-- 23 files changed, 100 insertions(+), 78 deletions(-) create mode 100644 testnet_initial_state/Cargo.toml rename key_protocol/src/initial_state.rs => testnet_initial_state/src/lib.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index c3c354a9..43a1264f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3716,6 +3716,7 @@ dependencies = [ "serde_json", "storage", "tempfile", + "testnet_initial_state", "tokio", "url", ] @@ -3844,6 +3845,7 @@ dependencies = [ "serde_json", "tempfile", "testcontainers", + "testnet_initial_state", "token_core", "tokio", "url", @@ -7449,6 +7451,7 @@ dependencies = [ "serde_json", "storage", "tempfile", + "testnet_initial_state", "tokio", "url", ] @@ -7476,6 +7479,7 @@ dependencies = [ "serde", "serde_json", "tempfile", + "testnet_initial_state", "tokio", ] @@ -8179,6 +8183,17 @@ dependencies = [ "uuid", ] +[[package]] +name = "testnet_initial_state" +version = "0.1.0" +dependencies = [ + "common", + "key_protocol", + "nssa", + "nssa_core", + "serde", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -8976,6 +8991,7 @@ dependencies = [ "serde", "serde_json", "sha2", + "testnet_initial_state", "token_core", "tokio", "url", diff --git a/Cargo.toml b/Cargo.toml index bcd11651..cec35b00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ members = [ "examples/program_deployment/methods", "examples/program_deployment/methods/guest", "bedrock_client", + "testnet_initial_state", ] [workspace.dependencies] @@ -57,6 +58,7 @@ amm_core = { path = "programs/amm/core" } amm_program = { path = "programs/amm" } test_program_methods = { path = "test_program_methods" } bedrock_client = { path = "bedrock_client" } +testnet_initial_state = { path = "testnet_initial_state" } tokio = { version = "1.50", features = [ "net", diff --git a/indexer/core/Cargo.toml b/indexer/core/Cargo.toml index 56a7c813..2d7ec258 100644 --- a/indexer/core/Cargo.toml +++ b/indexer/core/Cargo.toml @@ -14,6 +14,7 @@ nssa.workspace = true nssa_core.workspace = true storage.workspace = true key_protocol.workspace = true +testnet_initial_state.workspace = true anyhow.workspace = true log.workspace = true @@ -29,4 +30,3 @@ async-stream.workspace = true [dev-dependencies] tempfile.workspace = true - diff --git a/indexer/core/src/config.rs b/indexer/core/src/config.rs index fced57d9..291e54f5 100644 --- a/indexer/core/src/config.rs +++ b/indexer/core/src/config.rs @@ -9,11 +9,9 @@ use anyhow::{Context as _, Result}; pub use bedrock_client::BackoffConfig; use common::config::BasicAuth; use humantime_serde; -use key_protocol::initial_state::{ - PrivateAccountPublicInitialData, PublicAccountPublicInitialData, -}; pub use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; +use testnet_initial_state::{PrivateAccountPublicInitialData, PublicAccountPublicInitialData}; use url::Url; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/indexer/core/src/lib.rs b/indexer/core/src/lib.rs index ca17bd64..5c453743 100644 --- a/indexer/core/src/lib.rs +++ b/indexer/core/src/lib.rs @@ -6,13 +6,13 @@ use common::{ HashType, PINATA_BASE58, block::{Block, HashableBlockData}, }; -use key_protocol::initial_state::initial_state_testnet; use log::{debug, error, info}; use logos_blockchain_core::mantle::{ Op, SignedMantleTx, ops::channel::{ChannelId, inscribe::InscriptionOp}, }; use nssa::V02State; +use testnet_initial_state::initial_state_testnet; use crate::{block_store::IndexerStore, config::IndexerConfig}; @@ -59,7 +59,7 @@ impl IndexerCore { let initial_commitments: Option> = config .initial_private_accounts - .clone() + .as_ref() .map(|initial_commitments| { initial_commitments .iter() @@ -78,7 +78,7 @@ impl IndexerCore { let init_accs: Option> = config .initial_public_accounts - .clone() + .as_ref() .map(|initial_accounts| { initial_accounts .iter() diff --git a/integration_tests/Cargo.toml b/integration_tests/Cargo.toml index b18b782f..7f9ccab3 100644 --- a/integration_tests/Cargo.toml +++ b/integration_tests/Cargo.toml @@ -20,6 +20,7 @@ serde_json.workspace = true token_core.workspace = true indexer_service_rpc.workspace = true wallet-ffi.workspace = true +testnet_initial_state.workspace = true url.workspace = true diff --git a/integration_tests/src/config.rs b/integration_tests/src/config.rs index 98181d26..277c5682 100644 --- a/integration_tests/src/config.rs +++ b/integration_tests/src/config.rs @@ -3,16 +3,14 @@ use std::{net::SocketAddr, path::PathBuf, time::Duration}; use anyhow::{Context as _, Result}; use bytesize::ByteSize; use indexer_service::{BackoffConfig, ChannelId, ClientConfig, IndexerConfig}; -use key_protocol::{ - initial_state::{ - PrivateAccountPrivateInitialData, PrivateAccountPublicInitialData, - PublicAccountPrivateInitialData, PublicAccountPublicInitialData, - }, - key_management::KeyChain, -}; +use key_protocol::key_management::KeyChain; use nssa::{Account, AccountId, PrivateKey, PublicKey}; use nssa_core::{account::Data, program::DEFAULT_PROGRAM_ID}; use sequencer_core::config::{BedrockConfig, SequencerConfig}; +use testnet_initial_state::{ + PrivateAccountPrivateInitialData, PrivateAccountPublicInitialData, + PublicAccountPrivateInitialData, PublicAccountPublicInitialData, +}; use url::Url; use wallet::config::{InitialAccountData, WalletConfig}; diff --git a/key_protocol/src/key_management/secret_holders.rs b/key_protocol/src/key_management/secret_holders.rs index db39757e..049c88a1 100644 --- a/key_protocol/src/key_management/secret_holders.rs +++ b/key_protocol/src/key_management/secret_holders.rs @@ -20,17 +20,16 @@ pub struct SeedHolder { #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] /// Secret spending key object. Can produce `PrivateKeyHolder` objects. -pub struct SecretSpendingKey(pub(crate) [u8; 32]); +pub struct SecretSpendingKey(pub [u8; 32]); pub type ViewingSecretKey = Scalar; #[derive(Serialize, Deserialize, Debug, Clone)] /// Private key holder. Produces public keys. Can produce `account_id`. Can produce shared secret /// for recepient. -#[expect(clippy::partial_pub_fields, reason = "TODO: fix later")] pub struct PrivateKeyHolder { pub nullifier_secret_key: NullifierSecretKey, - pub(crate) viewing_secret_key: ViewingSecretKey, + pub viewing_secret_key: ViewingSecretKey, } impl SeedHolder { diff --git a/key_protocol/src/lib.rs b/key_protocol/src/lib.rs index 87c7b8e4..e3fe31cf 100644 --- a/key_protocol/src/lib.rs +++ b/key_protocol/src/lib.rs @@ -1,5 +1,4 @@ #![expect(clippy::print_stdout, reason = "TODO: fix later")] -pub mod initial_state; pub mod key_management; pub mod key_protocol_core; diff --git a/nssa/Cargo.toml b/nssa/Cargo.toml index e1b6805f..b50f189b 100644 --- a/nssa/Cargo.toml +++ b/nssa/Cargo.toml @@ -37,4 +37,4 @@ test-case = "3.3.1" [features] default = [] prove = ["risc0-zkvm/prove"] -test-utils = [] \ No newline at end of file +test-utils = [] diff --git a/programs/amm/Cargo.toml b/programs/amm/Cargo.toml index 449d5dcc..30074ac8 100644 --- a/programs/amm/Cargo.toml +++ b/programs/amm/Cargo.toml @@ -8,10 +8,12 @@ license = { workspace = true } workspace = true [dependencies] -nssa = { workspace = true, optional = true, features = ["test-utils"], default-features = true } +nssa = { workspace = true, optional = true, features = [ + "test-utils", +], default-features = true } nssa_core.workspace = true token_core.workspace = true amm_core.workspace = true [features] -nssa = ["dep:nssa"] \ No newline at end of file +nssa = ["dep:nssa"] diff --git a/sequencer_core/Cargo.toml b/sequencer_core/Cargo.toml index 9f29a581..3801945f 100644 --- a/sequencer_core/Cargo.toml +++ b/sequencer_core/Cargo.toml @@ -15,6 +15,7 @@ storage.workspace = true mempool.workspace = true bedrock_client.workspace = true key_protocol.workspace = true +testnet_initial_state.workspace = true anyhow.workspace = true serde.workspace = true diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 571ead1a..d6db21ff 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -10,11 +10,9 @@ use bedrock_client::BackoffConfig; use bytesize::ByteSize; use common::config::BasicAuth; use humantime_serde; -use key_protocol::initial_state::{ - PrivateAccountPublicInitialData, PublicAccountPublicInitialData, -}; use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; +use testnet_initial_state::{PrivateAccountPublicInitialData, PublicAccountPublicInitialData}; use url::Url; // TODO: Provide default values diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 22a388dd..2bac5b08 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -10,13 +10,13 @@ use common::{ transaction::NSSATransaction, }; use config::SequencerConfig; -use key_protocol::initial_state::initial_state; use log::{error, info, warn}; use logos_blockchain_key_management_system_service::keys::{ED25519_SECRET_KEY_SIZE, Ed25519Key}; use mempool::{MemPool, MemPoolHandle}; #[cfg(feature = "mock")] pub use mock::SequencerCoreWithMockClients; use nssa::V02State; +use testnet_initial_state::initial_state; use crate::{ block_settlement_client::{BlockSettlementClient, BlockSettlementClientTrait, MsgId}, @@ -386,9 +386,9 @@ mod tests { use bedrock_client::BackoffConfig; use common::{test_utils::sequencer_sign_key_for_testing, transaction::NSSATransaction}; - use key_protocol::initial_state::{initial_accounts, initial_pub_accounts_private_keys}; use logos_blockchain_core::mantle::ops::channel::ChannelId; use mempool::MemPoolHandle; + use testnet_initial_state::{initial_accounts, initial_pub_accounts_private_keys}; use crate::{ config::{BedrockConfig, SequencerConfig}, diff --git a/sequencer_rpc/Cargo.toml b/sequencer_rpc/Cargo.toml index 4d724fd8..f6da68e8 100644 --- a/sequencer_rpc/Cargo.toml +++ b/sequencer_rpc/Cargo.toml @@ -14,6 +14,7 @@ mempool.workspace = true sequencer_core = { workspace = true } bedrock_client.workspace = true key_protocol.workspace = true +testnet_initial_state.workspace = true anyhow.workspace = true serde_json.workspace = true diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index d662dacd..4376b28a 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -23,13 +23,13 @@ use common::{ transaction::{NSSATransaction, TransactionMalformationError}, }; use itertools::Itertools as _; -use key_protocol::initial_state::initial_accounts; use log::warn; use nssa::{self, program::Program}; use sequencer_core::{ block_settlement_client::BlockSettlementClientTrait, indexer_client::IndexerClientTrait, }; use serde_json::Value; +use testnet_initial_state::initial_accounts; use super::{JsonHandler, respond, types::err_rpc::RpcErr}; @@ -342,13 +342,13 @@ mod tests { use common::{ config::BasicAuth, test_utils::sequencer_sign_key_for_testing, transaction::NSSATransaction, }; - use key_protocol::initial_state::{initial_accounts, initial_pub_accounts_private_keys}; use sequencer_core::{ config::{BedrockConfig, SequencerConfig}, mock::{MockBlockSettlementClient, MockIndexerClient, SequencerCoreWithMockClients}, }; use serde_json::Value; use tempfile::tempdir; + use testnet_initial_state::{initial_accounts, initial_pub_accounts_private_keys}; use tokio::sync::Mutex; use crate::rpc_handler; diff --git a/testnet_initial_state/Cargo.toml b/testnet_initial_state/Cargo.toml new file mode 100644 index 00000000..2b73f479 --- /dev/null +++ b/testnet_initial_state/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "testnet_initial_state" +version = "0.1.0" +edition = "2024" +license.workspace = true + +[dependencies] +key_protocol.workspace = true +nssa.workspace = true +nssa_core.workspace = true +common.workspace = true + +serde.workspace = true + +[lints] +workspace = true diff --git a/key_protocol/src/initial_state.rs b/testnet_initial_state/src/lib.rs similarity index 99% rename from key_protocol/src/initial_state.rs rename to testnet_initial_state/src/lib.rs index 2150bd4c..0c49b2e8 100644 --- a/key_protocol/src/initial_state.rs +++ b/testnet_initial_state/src/lib.rs @@ -1,12 +1,11 @@ use common::PINATA_BASE58; -use nssa::{Account, AccountId, Data, PrivateKey, PublicKey, V02State}; -use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point}; -use serde::{Deserialize, Serialize}; - -use crate::key_management::{ +use key_protocol::key_management::{ KeyChain, secret_holders::{PrivateKeyHolder, SecretSpendingKey}, }; +use nssa::{Account, AccountId, Data, PrivateKey, PublicKey, V02State}; +use nssa_core::{NullifierPublicKey, encryption::shared_key_derivation::Secp256k1Point}; +use serde::{Deserialize, Serialize}; const PRIVATE_KEY_PUB_ACC_A: [u8; 32] = [ 16, 162, 106, 154, 236, 125, 52, 184, 35, 100, 238, 174, 69, 197, 41, 77, 187, 10, 118, 75, 0, diff --git a/wallet/Cargo.toml b/wallet/Cargo.toml index 63e14bb6..ca6b8f1b 100644 --- a/wallet/Cargo.toml +++ b/wallet/Cargo.toml @@ -14,6 +14,7 @@ common.workspace = true key_protocol.workspace = true token_core.workspace = true amm_core.workspace = true +testnet_initial_state.workspace = true anyhow.workspace = true serde_json.workspace = true diff --git a/wallet/src/chain_storage.rs b/wallet/src/chain_storage.rs index 2dd9d64f..3e1a8de7 100644 --- a/wallet/src/chain_storage.rs +++ b/wallet/src/chain_storage.rs @@ -99,39 +99,24 @@ impl WalletChainStore { let mut public_init_acc_map = BTreeMap::new(); let mut private_init_acc_map = BTreeMap::new(); - // If initial accounts are present in config, need to construct state from them - if let Some(initial_accounts) = config.initial_accounts.clone() { - for init_acc_data in initial_accounts { - match init_acc_data { - InitialAccountData::Public(data) => { - public_init_acc_map.insert(data.account_id, data.pub_sign_key); - } - InitialAccountData::Private(data) => { - let mut account = data.account; - // TODO: Program owner is only known after code is compiled and can't be set - // in the config. Therefore we overwrite it here on - // startup. Fix this when program id can be fetched - // from the node and queried from the wallet. - account.program_owner = Program::authenticated_transfer_program().id(); - private_init_acc_map.insert(data.account_id, (data.key_chain, account)); - } + let initial_accounts = config + .initial_accounts + .clone() + .unwrap_or_else(InitialAccountData::create_initial_accounts_data); + + for init_acc_data in initial_accounts { + match init_acc_data { + InitialAccountData::Public(data) => { + public_init_acc_map.insert(data.account_id, data.pub_sign_key); } - } - } else { - for init_acc_data in InitialAccountData::create_initial_accounts_data() { - match init_acc_data { - InitialAccountData::Public(data) => { - public_init_acc_map.insert(data.account_id, data.pub_sign_key); - } - InitialAccountData::Private(data) => { - let mut account = data.account; - // TODO: Program owner is only known after code is compiled and can't be set - // in the config. Therefore we overwrite it here on - // startup. Fix this when program id can be fetched - // from the node and queried from the wallet. - account.program_owner = Program::authenticated_transfer_program().id(); - private_init_acc_map.insert(data.account_id, (data.key_chain, account)); - } + InitialAccountData::Private(data) => { + let mut account = data.account; + // TODO: Program owner is only known after code is compiled and can't be set + // in the config. Therefore we overwrite it here on + // startup. Fix this when program id can be fetched + // from the node and queried from the wallet. + account.program_owner = Program::authenticated_transfer_program().id(); + private_init_acc_map.insert(data.account_id, (data.key_chain, account)); } } } diff --git a/wallet/src/cli/config.rs b/wallet/src/cli/config.rs index ae70a63b..79b7aef2 100644 --- a/wallet/src/cli/config.rs +++ b/wallet/src/cli/config.rs @@ -69,7 +69,17 @@ impl WalletSubcommand for ConfigSubcommand { ); } "initial_accounts" => { - println!("{:#?}", InitialAccountData::create_initial_accounts_data()); + println!( + "{:#?}", + wallet_core + .storage + .wallet_config + .initial_accounts + .clone() + .unwrap_or_else( + InitialAccountData::create_initial_accounts_data + ) + ); } "basic_auth" => { if let Some(basic_auth) = &wallet_core.storage.wallet_config.basic_auth diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 146b1a21..10a70030 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -8,17 +8,15 @@ use std::{ use anyhow::{Context as _, Result}; use common::config::BasicAuth; use humantime_serde; -use key_protocol::{ - initial_state::{ - PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData, - initial_priv_accounts_private_keys, initial_pub_accounts_private_keys, - }, - key_management::key_tree::{ - chain_index::ChainIndex, keys_private::ChildKeysPrivate, keys_public::ChildKeysPublic, - }, +use key_protocol::key_management::key_tree::{ + chain_index::ChainIndex, keys_private::ChildKeysPrivate, keys_public::ChildKeysPublic, }; use log::warn; use serde::{Deserialize, Serialize}; +use testnet_initial_state::{ + PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData, + initial_priv_accounts_private_keys, initial_pub_accounts_private_keys, +}; use url::Url; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index ceeb467f..e12fc444 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -2,14 +2,12 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr as _}; use anyhow::{Context as _, Result}; use base58::ToBase58 as _; -use key_protocol::{ - initial_state::{PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData}, - key_protocol_core::NSSAUserData, -}; +use key_protocol::key_protocol_core::NSSAUserData; use nssa::Account; use nssa_core::account::Nonce; use rand::{RngCore as _, rngs::OsRng}; use serde::Serialize; +use testnet_initial_state::{PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData}; use crate::{ HOME_DIR_ENV_VAR,