From 02953999aacc4cc479fb7a29d2b74d9ee6c117b9 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Fri, 13 Mar 2026 18:23:39 +0200 Subject: [PATCH 1/9] feat: general initial state --- Cargo.lock | 3 + common/src/block.rs | 16 -- indexer/core/Cargo.toml | 1 + indexer/core/src/config.rs | 9 +- indexer/core/src/lib.rs | 40 +--- key_protocol/src/initial_state.rs | 363 ++++++++++++++++++++++++++++++ key_protocol/src/lib.rs | 1 + sequencer_core/Cargo.toml | 1 + sequencer_core/src/config.rs | 9 +- sequencer_core/src/lib.rs | 161 +++---------- sequencer_rpc/Cargo.toml | 1 + sequencer_rpc/src/process.rs | 91 ++------ wallet/src/chain_storage.rs | 99 +------- wallet/src/cli/config.rs | 3 +- wallet/src/config.rs | 340 ++-------------------------- wallet/src/helperfunctions.rs | 13 +- 16 files changed, 473 insertions(+), 678 deletions(-) create mode 100644 key_protocol/src/initial_state.rs diff --git a/Cargo.lock b/Cargo.lock index 33f810e0..da5b8c35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3749,6 +3749,7 @@ dependencies = [ "common", "futures", "humantime-serde", + "key_protocol", "log", "logos-blockchain-core", "nssa", @@ -7462,6 +7463,7 @@ dependencies = [ "futures", "humantime-serde", "jsonrpsee", + "key_protocol", "log", "logos-blockchain-core", "logos-blockchain-key-management-system-service", @@ -7493,6 +7495,7 @@ dependencies = [ "futures", "hex", "itertools 0.14.0", + "key_protocol", "log", "mempool", "nssa", diff --git a/common/src/block.rs b/common/src/block.rs index 0343435b..8c59b0ea 100644 --- a/common/src/block.rs +++ b/common/src/block.rs @@ -1,6 +1,4 @@ use borsh::{BorshDeserialize, BorshSerialize}; -use nssa::AccountId; -use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256, digest::FixedOutput}; use crate::{HashType, transaction::NSSATransaction}; @@ -109,20 +107,6 @@ impl From for HashableBlockData { } } -/// Helper struct for account (de-)serialization -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct AccountInitialData { - pub account_id: AccountId, - pub balance: u128, -} - -/// Helper struct to (de-)serialize initial commitments -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct CommitmentsInitialData { - pub npk: nssa_core::NullifierPublicKey, - pub account: nssa_core::account::Account, -} - #[cfg(test)] mod tests { use crate::{HashType, block::HashableBlockData, test_utils}; diff --git a/indexer/core/Cargo.toml b/indexer/core/Cargo.toml index 792fb4b7..1f6c41a2 100644 --- a/indexer/core/Cargo.toml +++ b/indexer/core/Cargo.toml @@ -10,6 +10,7 @@ bedrock_client.workspace = true nssa.workspace = true nssa_core.workspace = true storage.workspace = true +key_protocol.workspace = true anyhow.workspace = true log.workspace = true diff --git a/indexer/core/src/config.rs b/indexer/core/src/config.rs index 95e6147c..fad10ec5 100644 --- a/indexer/core/src/config.rs +++ b/indexer/core/src/config.rs @@ -7,10 +7,7 @@ use std::{ use anyhow::{Context as _, Result}; pub use bedrock_client::BackoffConfig; -use common::{ - block::{AccountInitialData, CommitmentsInitialData}, - config::BasicAuth, -}; +use common::config::BasicAuth; use humantime_serde; pub use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; @@ -29,10 +26,6 @@ pub struct ClientConfig { pub struct IndexerConfig { /// Home dir of sequencer storage pub home: PathBuf, - /// List of initial accounts data - pub initial_accounts: Vec, - /// List of initial commitments - pub initial_commitments: Vec, /// Sequencers signing key pub signing_key: [u8; 32], #[serde(with = "humantime_serde")] diff --git a/indexer/core/src/lib.rs b/indexer/core/src/lib.rs index 6d56eb18..002a6c91 100644 --- a/indexer/core/src/lib.rs +++ b/indexer/core/src/lib.rs @@ -2,9 +2,11 @@ use std::collections::VecDeque; use anyhow::Result; use bedrock_client::{BedrockClient, HeaderId}; -use common::block::{Block, HashableBlockData}; -// ToDo: Remove after testnet -use common::{HashType, PINATA_BASE58}; +use common::{ + HashType, + block::{Block, HashableBlockData}, +}; +use key_protocol::initial_state::initial_state_testnet; use log::{debug, error, info}; use logos_blockchain_core::mantle::{ Op, SignedMantleTx, @@ -54,36 +56,8 @@ impl IndexerCore { let channel_genesis_msg_id = [0; 32]; let start_block = hashable_data.into_pending_block(&signing_key, channel_genesis_msg_id); - // This is a troubling moment, because changes in key protocol can - // affect this. And indexer can not reliably ask this data from sequencer - // because indexer must be independent from it. - // ToDo: move initial state generation into common and use the same method - // for indexer and sequencer. This way both services buit at same version - // could be in sync. - let initial_commitments: Vec = config - .initial_commitments - .iter() - .map(|init_comm_data| { - let npk = &init_comm_data.npk; - - let mut acc = init_comm_data.account.clone(); - - acc.program_owner = nssa::program::Program::authenticated_transfer_program().id(); - - nssa_core::Commitment::new(npk, &acc) - }) - .collect(); - - let init_accs: Vec<(nssa::AccountId, u128)> = config - .initial_accounts - .iter() - .map(|acc_data| (acc_data.account_id, acc_data.balance)) - .collect(); - - let mut state = nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments); - - // ToDo: Remove after testnet - state.add_pinata_program(PINATA_BASE58.parse().unwrap()); + // ToDo: replace with `initial_state()` after testnet + let state = initial_state_testnet(); let home = config.home.join("rocksdb"); diff --git a/key_protocol/src/initial_state.rs b/key_protocol/src/initial_state.rs new file mode 100644 index 00000000..8011d471 --- /dev/null +++ b/key_protocol/src/initial_state.rs @@ -0,0 +1,363 @@ +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::{ + KeyChain, + secret_holders::{PrivateKeyHolder, SecretSpendingKey}, +}; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct PublicAccountPublicInitialData { + pub account_id: AccountId, + pub balance: u128, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct PrivateAccountPublicInitialData { + pub npk: nssa_core::NullifierPublicKey, + pub account: nssa_core::account::Account, +} + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct PublicAccountPrivateInitialData { + pub account_id: nssa::AccountId, + pub pub_sign_key: nssa::PrivateKey, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PrivateAccountPrivateInitialData { + pub account_id: nssa::AccountId, + pub account: nssa_core::account::Account, + pub key_chain: KeyChain, +} + +pub fn initial_pub_accounts_private_keys() -> Vec { + let acc1_pub_sign_key = PrivateKey::try_new([ + 16, 162, 106, 154, 236, 125, 52, 184, 35, 100, 238, 174, 69, 197, 41, 77, 187, 10, 118, 75, + 0, 11, 148, 238, 185, 181, 133, 17, 220, 72, 124, 77, + ]) + .unwrap(); + + let acc2_pub_sign_key = PrivateKey::try_new([ + 113, 121, 64, 177, 204, 85, 229, 214, 178, 6, 109, 191, 29, 154, 63, 38, 242, 18, 244, 219, + 8, 208, 35, 136, 23, 127, 207, 237, 216, 169, 190, 27, + ]) + .unwrap(); + + vec![ + PublicAccountPrivateInitialData { + account_id: AccountId::from(&PublicKey::new_from_private_key(&acc1_pub_sign_key)), + pub_sign_key: acc1_pub_sign_key, + }, + PublicAccountPrivateInitialData { + account_id: AccountId::from(&PublicKey::new_from_private_key(&acc2_pub_sign_key)), + pub_sign_key: acc2_pub_sign_key, + }, + ] +} + +pub fn initial_priv_accounts_private_keys() -> Vec { + let key_chain_1 = KeyChain { + secret_spending_key: SecretSpendingKey([ + 93, 13, 190, 240, 250, 33, 108, 195, 176, 40, 144, 61, 4, 28, 58, 112, 53, 161, 42, + 238, 155, 27, 23, 176, 208, 121, 15, 229, 165, 180, 99, 143, + ]), + private_key_holder: PrivateKeyHolder { + nullifier_secret_key: [ + 25, 21, 186, 59, 180, 224, 101, 64, 163, 208, 228, 43, 13, 185, 100, 123, 156, 47, + 80, 179, 72, 51, 115, 11, 180, 99, 21, 201, 48, 194, 118, 144, + ], + viewing_secret_key: [ + 5, 85, 114, 119, 141, 187, 202, 170, 122, 253, 198, 81, 150, 8, 155, 21, 192, 65, + 24, 124, 116, 98, 110, 106, 137, 90, 165, 239, 80, 13, 222, 30, + ], + }, + nullifer_public_key: NullifierPublicKey([ + 167, 108, 50, 153, 74, 47, 151, 188, 140, 79, 195, 31, 181, 9, 40, 167, 201, 32, 175, + 129, 45, 245, 223, 193, 210, 170, 247, 128, 167, 140, 155, 129, + ]), + viewing_public_key: Secp256k1Point(vec![ + 2, 210, 206, 38, 213, 4, 182, 198, 220, 47, 93, 148, 61, 84, 148, 250, 158, 45, 8, 81, + 48, 80, 46, 230, 87, 210, 47, 204, 76, 58, 214, 167, 81, + ]), + }; + + let key_chain_2 = KeyChain { + secret_spending_key: SecretSpendingKey([ + 48, 175, 124, 10, 230, 240, 166, 14, 249, 254, 157, 226, 208, 124, 122, 177, 203, 139, + 192, 180, 43, 120, 55, 151, 50, 21, 113, 22, 254, 83, 148, 56, + ]), + private_key_holder: PrivateKeyHolder { + nullifier_secret_key: [ + 99, 82, 190, 140, 234, 10, 61, 163, 15, 211, 179, 54, 70, 166, 87, 5, 182, 68, 117, + 244, 217, 23, 99, 9, 4, 177, 230, 125, 109, 91, 160, 30, + ], + viewing_secret_key: [ + 205, 32, 76, 251, 255, 236, 96, 119, 61, 111, 65, 100, 75, 218, 12, 22, 17, 170, + 55, 226, 21, 154, 161, 34, 208, 74, 27, 1, 119, 13, 88, 128, + ], + }, + nullifer_public_key: NullifierPublicKey([ + 32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, 243, 134, + 135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165, + ]), + viewing_public_key: Secp256k1Point(vec![ + 2, 79, 110, 46, 203, 29, 206, 205, 18, 86, 27, 189, 104, 103, 113, 181, 110, 53, 78, + 172, 11, 171, 190, 18, 126, 214, 81, 77, 192, 154, 58, 195, 238, + ]), + }; + + vec![ + PrivateAccountPrivateInitialData { + account_id: AccountId::from(&key_chain_1.nullifer_public_key), + account: Account { + program_owner: [0, 0, 0, 0, 0, 0, 0, 0], + balance: 10000, + data: Data::default(), + nonce: 0, + }, + key_chain: key_chain_1, + }, + PrivateAccountPrivateInitialData { + account_id: AccountId::from(&key_chain_2.nullifer_public_key), + account: Account { + program_owner: [0, 0, 0, 0, 0, 0, 0, 0], + balance: 20000, + data: Data::default(), + nonce: 0, + }, + key_chain: key_chain_2, + }, + ] +} + +pub fn initial_commitments() -> Vec { + initial_priv_accounts_private_keys() + .into_iter() + .map(|data| PrivateAccountPublicInitialData { + npk: data.key_chain.nullifer_public_key.clone(), + account: data.account.clone(), + }) + .collect() +} + +pub fn initial_accounts() -> Vec { + let initial_account_ids = initial_pub_accounts_private_keys() + .into_iter() + .map(|data| data.account_id) + .collect::>(); + + vec![ + PublicAccountPublicInitialData { + account_id: initial_account_ids[0], + balance: 10000, + }, + PublicAccountPublicInitialData { + account_id: initial_account_ids[1], + balance: 20000, + }, + ] +} + +pub fn initial_state() -> V02State { + let initial_commitments: Vec = initial_commitments() + .iter() + .map(|init_comm_data| { + let npk = &init_comm_data.npk; + + let mut acc = init_comm_data.account.clone(); + + acc.program_owner = nssa::program::Program::authenticated_transfer_program().id(); + + nssa_core::Commitment::new(npk, &acc) + }) + .collect(); + + let init_accs: Vec<(nssa::AccountId, u128)> = initial_accounts() + .iter() + .map(|acc_data| (acc_data.account_id, acc_data.balance)) + .collect(); + + nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments) +} + +pub fn initial_state_testnet() -> V02State { + let mut state = initial_state(); + + state.add_pinata_program(PINATA_BASE58.parse().unwrap()); + + state +} + +#[cfg(test)] +mod tests { + use std::str::FromStr; + + use super::*; + + #[test] + fn test_pub_state_consistency() { + let init_accs_private_data = initial_pub_accounts_private_keys(); + let init_accs_pub_data = initial_accounts(); + + assert_eq!( + init_accs_private_data[0].account_id, + init_accs_pub_data[0].account_id + ); + + assert_eq!( + init_accs_private_data[1].account_id, + init_accs_pub_data[1].account_id + ); + + assert_eq!( + init_accs_pub_data[0], + PublicAccountPublicInitialData { + account_id: AccountId::from_str("6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV") + .unwrap(), + balance: 10000, + } + ); + + assert_eq!( + init_accs_pub_data[1], + PublicAccountPublicInitialData { + account_id: AccountId::from_str("7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo") + .unwrap(), + balance: 20000, + } + ) + } + + #[test] + fn test_private_state_consistency() { + let init_private_accs_keys = initial_priv_accounts_private_keys(); + let init_comms = initial_commitments(); + + assert_eq!( + init_private_accs_keys[0] + .key_chain + .secret_spending_key + .produce_private_key_holder(None) + .nullifier_secret_key, + init_private_accs_keys[0] + .key_chain + .private_key_holder + .nullifier_secret_key + ); + assert_eq!( + init_private_accs_keys[0] + .key_chain + .secret_spending_key + .produce_private_key_holder(None) + .viewing_secret_key, + init_private_accs_keys[0] + .key_chain + .private_key_holder + .viewing_secret_key + ); + assert_eq!( + init_private_accs_keys[0] + .key_chain + .private_key_holder + .generate_nullifier_public_key(), + init_private_accs_keys[0].key_chain.nullifer_public_key + ); + assert_eq!( + init_private_accs_keys[0] + .key_chain + .private_key_holder + .generate_viewing_public_key(), + init_private_accs_keys[0].key_chain.viewing_public_key + ); + + assert_eq!( + init_private_accs_keys[1] + .key_chain + .secret_spending_key + .produce_private_key_holder(None) + .nullifier_secret_key, + init_private_accs_keys[1] + .key_chain + .private_key_holder + .nullifier_secret_key + ); + assert_eq!( + init_private_accs_keys[1] + .key_chain + .secret_spending_key + .produce_private_key_holder(None) + .viewing_secret_key, + init_private_accs_keys[1] + .key_chain + .private_key_holder + .viewing_secret_key + ); + assert_eq!( + init_private_accs_keys[1] + .key_chain + .private_key_holder + .generate_nullifier_public_key(), + init_private_accs_keys[1].key_chain.nullifer_public_key + ); + assert_eq!( + init_private_accs_keys[1] + .key_chain + .private_key_holder + .generate_viewing_public_key(), + init_private_accs_keys[1].key_chain.viewing_public_key + ); + + assert_eq!( + init_private_accs_keys[0].account_id.to_string(), + "5ya25h4Xc9GAmrGB2WrTEnEWtQKJwRwQx3Xfo2tucNcE" + ); + assert_eq!( + init_private_accs_keys[1].account_id.to_string(), + "E8HwiTyQe4H9HK7icTvn95HQMnzx49mP9A2ddtMLpNaN" + ); + + assert_eq!( + init_private_accs_keys[0].key_chain.nullifer_public_key, + init_comms[0].npk + ); + assert_eq!( + init_private_accs_keys[1].key_chain.nullifer_public_key, + init_comms[1].npk + ); + + assert_eq!( + init_comms[0], + PrivateAccountPublicInitialData { + npk: NullifierPublicKey([ + 167, 108, 50, 153, 74, 47, 151, 188, 140, 79, 195, 31, 181, 9, 40, 167, 201, + 32, 175, 129, 45, 245, 223, 193, 210, 170, 247, 128, 167, 140, 155, 129, + ]), + account: Account { + program_owner: [0, 0, 0, 0, 0, 0, 0, 0], + balance: 10000, + data: Data::default(), + nonce: 0, + }, + } + ); + + assert_eq!( + init_comms[1], + PrivateAccountPublicInitialData { + npk: NullifierPublicKey([ + 32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, + 243, 134, 135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165, + ]), + account: Account { + program_owner: [0, 0, 0, 0, 0, 0, 0, 0], + balance: 20000, + data: Data::default(), + nonce: 0, + }, + } + ) + } +} diff --git a/key_protocol/src/lib.rs b/key_protocol/src/lib.rs index 1a52c202..7c056ec8 100644 --- a/key_protocol/src/lib.rs +++ b/key_protocol/src/lib.rs @@ -1,2 +1,3 @@ +pub mod initial_state; pub mod key_management; pub mod key_protocol_core; diff --git a/sequencer_core/Cargo.toml b/sequencer_core/Cargo.toml index e939c7ae..1d4e604e 100644 --- a/sequencer_core/Cargo.toml +++ b/sequencer_core/Cargo.toml @@ -11,6 +11,7 @@ common.workspace = true storage.workspace = true mempool.workspace = true bedrock_client.workspace = true +key_protocol.workspace = true base58.workspace = true anyhow.workspace = true diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 003b82e8..05a0dc72 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -8,10 +8,7 @@ use std::{ use anyhow::Result; use bedrock_client::BackoffConfig; use bytesize::ByteSize; -use common::{ - block::{AccountInitialData, CommitmentsInitialData}, - config::BasicAuth, -}; +use common::config::BasicAuth; use humantime_serde; use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; @@ -43,10 +40,6 @@ pub struct SequencerConfig { pub retry_pending_blocks_timeout: Duration, /// Port to listen pub port: u16, - /// List of initial accounts data - pub initial_accounts: Vec, - /// List of initial commitments - pub initial_commitments: Vec, /// Sequencer own signing key pub signing_key: [u8; 32], /// Bedrock configuration options diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 083728bf..fdb65d2a 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -10,6 +10,7 @@ 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}; @@ -98,30 +99,9 @@ impl SequencerCore { info!( - "No database found when starting the sequencer. Creating a fresh new with the initial data in config" + "No database found when starting the sequencer. Creating a fresh new with the initial data" ); - let initial_commitments: Vec = config - .initial_commitments - .iter() - .map(|init_comm_data| { - let npk = &init_comm_data.npk; - - let mut acc = init_comm_data.account.clone(); - - acc.program_owner = - nssa::program::Program::authenticated_transfer_program().id(); - - nssa_core::Commitment::new(npk, &acc) - }) - .collect(); - - let init_accs: Vec<(nssa::AccountId, u128)> = config - .initial_accounts - .iter() - .map(|acc_data| (acc_data.account_id, acc_data.balance)) - .collect(); - - nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments) + initial_state() } }; @@ -360,26 +340,20 @@ fn load_or_create_signing_key(path: &Path) -> Result { #[cfg(all(test, feature = "mock"))] mod tests { - use std::{pin::pin, str::FromStr as _, time::Duration}; + use std::{pin::pin, time::Duration}; - use base58::ToBase58; use bedrock_client::BackoffConfig; - use common::{ - block::AccountInitialData, test_utils::sequencer_sign_key_for_testing, - transaction::NSSATransaction, - }; + 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 nssa::{AccountId, PrivateKey}; use crate::{ config::{BedrockConfig, SequencerConfig}, mock::SequencerCoreWithMockClients, }; - fn setup_sequencer_config_variable_initial_accounts( - initial_accounts: Vec, - ) -> SequencerConfig { + fn setup_sequencer_config() -> SequencerConfig { let tempdir = tempfile::tempdir().unwrap(); let home = tempdir.path().to_path_buf(); @@ -393,8 +367,6 @@ mod tests { mempool_max_size: 10000, block_create_timeout: Duration::from_secs(1), port: 8080, - initial_accounts, - initial_commitments: vec![], signing_key: *sequencer_sign_key_for_testing().value(), bedrock_config: BedrockConfig { backoff: BackoffConfig { @@ -410,38 +382,12 @@ mod tests { } } - fn setup_sequencer_config() -> SequencerConfig { - let acc1_account_id: Vec = vec![ - 148, 179, 206, 253, 199, 51, 82, 86, 232, 2, 152, 122, 80, 243, 54, 207, 237, 112, 83, - 153, 44, 59, 204, 49, 128, 84, 160, 227, 216, 149, 97, 102, - ]; - - let acc2_account_id: Vec = vec![ - 30, 145, 107, 3, 207, 73, 192, 230, 160, 63, 238, 207, 18, 69, 54, 216, 103, 244, 92, - 94, 124, 248, 42, 16, 141, 19, 119, 18, 14, 226, 140, 204, - ]; - - let initial_acc1 = AccountInitialData { - account_id: AccountId::from_str(&acc1_account_id.to_base58()).unwrap(), - balance: 10000, - }; - - let initial_acc2 = AccountInitialData { - account_id: AccountId::from_str(&acc2_account_id.to_base58()).unwrap(), - balance: 20000, - }; - - let initial_accounts = vec![initial_acc1, initial_acc2]; - - setup_sequencer_config_variable_initial_accounts(initial_accounts) - } - fn create_signing_key_for_account1() -> nssa::PrivateKey { - nssa::PrivateKey::try_new([1; 32]).unwrap() + initial_pub_accounts_private_keys()[0].pub_sign_key.clone() } fn create_signing_key_for_account2() -> nssa::PrivateKey { - nssa::PrivateKey::try_new([2; 32]).unwrap() + initial_pub_accounts_private_keys()[1].pub_sign_key.clone() } async fn common_setup() -> (SequencerCoreWithMockClients, MemPoolHandle) { @@ -475,8 +421,8 @@ mod tests { assert_eq!(sequencer.sequencer_config.max_num_tx_in_block, 10); assert_eq!(sequencer.sequencer_config.port, 8080); - let acc1_account_id = config.initial_accounts[0].account_id; - let acc2_account_id = config.initial_accounts[1].account_id; + let acc1_account_id = initial_accounts()[0].account_id; + let acc2_account_id = initial_accounts()[1].account_id; let balance_acc_1 = sequencer.state.get_account_by_id(acc1_account_id).balance; let balance_acc_2 = sequencer.state.get_account_by_id(acc2_account_id).balance; @@ -485,47 +431,6 @@ mod tests { assert_eq!(20000, balance_acc_2); } - #[tokio::test] - async fn test_start_different_intial_accounts_balances() { - let acc1_account_id: Vec = vec![ - 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, - 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, - ]; - - let acc2_account_id: Vec = vec![ - 77, 75, 108, 209, 54, 16, 50, 202, 155, 210, 174, 185, 217, 0, 170, 77, 69, 217, 234, - 216, 10, 201, 66, 51, 116, 196, 81, 167, 37, 77, 7, 102, - ]; - - let initial_acc1 = AccountInitialData { - account_id: AccountId::from_str(&acc1_account_id.to_base58()).unwrap(), - balance: 10000, - }; - - let initial_acc2 = AccountInitialData { - account_id: AccountId::from_str(&acc2_account_id.to_base58()).unwrap(), - balance: 20000, - }; - - let initial_accounts = vec![initial_acc1, initial_acc2]; - - let config = setup_sequencer_config_variable_initial_accounts(initial_accounts); - let (sequencer, _mempool_handle) = - SequencerCoreWithMockClients::start_from_config(config.clone()).await; - - let acc1_account_id = config.initial_accounts[0].account_id; - let acc2_account_id = config.initial_accounts[1].account_id; - - assert_eq!( - 10000, - sequencer.state.get_account_by_id(acc1_account_id).balance - ); - assert_eq!( - 20000, - sequencer.state.get_account_by_id(acc2_account_id).balance - ); - } - #[test] fn test_transaction_pre_check_pass() { let tx = common::test_utils::produce_dummy_empty_transaction(); @@ -536,10 +441,10 @@ mod tests { #[tokio::test] async fn test_transaction_pre_check_native_transfer_valid() { - let (sequencer, _mempool_handle) = common_setup().await; + let (_sequencer, _mempool_handle) = common_setup().await; - let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id; - let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id; + let acc1 = initial_accounts()[0].account_id; + let acc2 = initial_accounts()[1].account_id; let sign_key1 = create_signing_key_for_account1(); @@ -555,8 +460,8 @@ mod tests { async fn test_transaction_pre_check_native_transfer_other_signature() { let (mut sequencer, _mempool_handle) = common_setup().await; - let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id; - let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id; + let acc1 = initial_accounts()[0].account_id; + let acc2 = initial_accounts()[1].account_id; let sign_key2 = create_signing_key_for_account2(); @@ -580,8 +485,8 @@ mod tests { async fn test_transaction_pre_check_native_transfer_sent_too_much() { let (mut sequencer, _mempool_handle) = common_setup().await; - let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id; - let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id; + let acc1 = initial_accounts()[0].account_id; + let acc2 = initial_accounts()[1].account_id; let sign_key1 = create_signing_key_for_account1(); @@ -607,8 +512,8 @@ mod tests { async fn test_transaction_execute_native_transfer() { let (mut sequencer, _mempool_handle) = common_setup().await; - let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id; - let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id; + let acc1 = initial_accounts()[0].account_id; + let acc2 = initial_accounts()[1].account_id; let sign_key1 = create_signing_key_for_account1(); @@ -669,8 +574,8 @@ mod tests { async fn test_replay_transactions_are_rejected_in_the_same_block() { let (mut sequencer, mempool_handle) = common_setup().await; - let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id; - let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id; + let acc1 = initial_accounts()[0].account_id; + let acc2 = initial_accounts()[1].account_id; let sign_key1 = create_signing_key_for_account1(); @@ -701,8 +606,8 @@ mod tests { async fn test_replay_transactions_are_rejected_in_different_blocks() { let (mut sequencer, mempool_handle) = common_setup().await; - let acc1 = sequencer.sequencer_config.initial_accounts[0].account_id; - let acc2 = sequencer.sequencer_config.initial_accounts[1].account_id; + let acc1 = initial_accounts()[0].account_id; + let acc2 = initial_accounts()[1].account_id; let sign_key1 = create_signing_key_for_account1(); @@ -736,8 +641,8 @@ mod tests { #[tokio::test] async fn test_restart_from_storage() { let config = setup_sequencer_config(); - let acc1_account_id = config.initial_accounts[0].account_id; - let acc2_account_id = config.initial_accounts[1].account_id; + let acc1_account_id = initial_accounts()[0].account_id; + let acc2_account_id = initial_accounts()[1].account_id; let balance_to_move = 13; // In the following code block a transaction will be processed that moves `balance_to_move` @@ -746,7 +651,7 @@ mod tests { { let (mut sequencer, mempool_handle) = SequencerCoreWithMockClients::start_from_config(config.clone()).await; - let signing_key = PrivateKey::try_new([1; 32]).unwrap(); + let signing_key = create_signing_key_for_account1(); let tx = common::test_utils::create_transaction_native_token_transfer( acc1_account_id, @@ -777,11 +682,11 @@ mod tests { // Balances should be consistent with the stored block assert_eq!( balance_acc_1, - config.initial_accounts[0].balance - balance_to_move + initial_accounts()[0].balance - balance_to_move ); assert_eq!( balance_acc_2, - config.initial_accounts[1].balance + balance_to_move + initial_accounts()[1].balance + balance_to_move ); } @@ -828,15 +733,15 @@ mod tests { #[tokio::test] async fn test_produce_block_with_correct_prev_meta_after_restart() { let config = setup_sequencer_config(); - let acc1_account_id = config.initial_accounts[0].account_id; - let acc2_account_id = config.initial_accounts[1].account_id; + let acc1_account_id = initial_accounts()[0].account_id; + let acc2_account_id = initial_accounts()[1].account_id; // Step 1: Create initial database with some block metadata let expected_prev_meta = { let (mut sequencer, mempool_handle) = SequencerCoreWithMockClients::start_from_config(config.clone()).await; - let signing_key = PrivateKey::try_new([1; 32]).unwrap(); + let signing_key = create_signing_key_for_account1(); // Add a transaction and produce a block to set up block metadata let tx = common::test_utils::create_transaction_native_token_transfer( @@ -861,7 +766,7 @@ mod tests { SequencerCoreWithMockClients::start_from_config(config.clone()).await; // Step 3: Submit a new transaction - let signing_key = PrivateKey::try_new([1; 32]).unwrap(); + let signing_key = create_signing_key_for_account1(); let tx = common::test_utils::create_transaction_native_token_transfer( acc1_account_id, 1, // Next nonce diff --git a/sequencer_rpc/Cargo.toml b/sequencer_rpc/Cargo.toml index 42aa978f..09641a00 100644 --- a/sequencer_rpc/Cargo.toml +++ b/sequencer_rpc/Cargo.toml @@ -10,6 +10,7 @@ common.workspace = true mempool.workspace = true sequencer_core = { workspace = true } bedrock_client.workspace = true +key_protocol.workspace = true anyhow.workspace = true serde_json.workspace = true diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index b3dca691..3fb7a6d9 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use actix_web::Error as HttpError; use base64::{Engine, engine::general_purpose}; use common::{ - block::{AccountInitialData, HashableBlockData}, + block::HashableBlockData, rpc_primitives::{ errors::RpcError, message::{Message, Request}, @@ -23,6 +23,7 @@ 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::{ @@ -201,13 +202,7 @@ impl JsonHandler let _get_initial_testnet_accounts_request = GetInitialTestnetAccountsRequest::parse(Some(request.params))?; - let initial_accounts: Vec = { - let state = self.sequencer_state.lock().await; - - state.sequencer_config().initial_accounts.clone() - }; - - respond(initial_accounts) + respond(initial_accounts()) } /// Returns the balance of the account at the given account_id. @@ -340,16 +335,14 @@ impl JsonHandler #[cfg(test)] mod tests { - use std::{str::FromStr as _, sync::Arc, time::Duration}; + use std::{sync::Arc, time::Duration}; - use base58::ToBase58; use base64::{Engine, engine::general_purpose}; use bedrock_client::BackoffConfig; use common::{ - block::AccountInitialData, config::BasicAuth, test_utils::sequencer_sign_key_for_testing, - transaction::NSSATransaction, + config::BasicAuth, test_utils::sequencer_sign_key_for_testing, transaction::NSSATransaction, }; - use nssa::AccountId; + use key_protocol::initial_state::{initial_accounts, initial_pub_accounts_private_keys}; use sequencer_core::{ config::{BedrockConfig, SequencerConfig}, mock::{MockBlockSettlementClient, MockIndexerClient, SequencerCoreWithMockClients}, @@ -366,27 +359,6 @@ mod tests { fn sequencer_config_for_tests() -> SequencerConfig { let tempdir = tempdir().unwrap(); let home = tempdir.path().to_path_buf(); - let acc1_id: Vec = vec![ - 148, 179, 206, 253, 199, 51, 82, 86, 232, 2, 152, 122, 80, 243, 54, 207, 237, 112, 83, - 153, 44, 59, 204, 49, 128, 84, 160, 227, 216, 149, 97, 102, - ]; - - let acc2_id: Vec = vec![ - 30, 145, 107, 3, 207, 73, 192, 230, 160, 63, 238, 207, 18, 69, 54, 216, 103, 244, 92, - 94, 124, 248, 42, 16, 141, 19, 119, 18, 14, 226, 140, 204, - ]; - - let initial_acc1 = AccountInitialData { - account_id: AccountId::from_str(&acc1_id.to_base58()).unwrap(), - balance: 10000, - }; - - let initial_acc2 = AccountInitialData { - account_id: AccountId::from_str(&acc2_id.to_base58()).unwrap(), - balance: 20000, - }; - - let initial_accounts = vec![initial_acc1, initial_acc2]; SequencerConfig { home, @@ -398,8 +370,6 @@ mod tests { mempool_max_size: 1000, block_create_timeout: Duration::from_secs(1), port: 8080, - initial_accounts, - initial_commitments: vec![], signing_key: *sequencer_sign_key_for_testing().value(), retry_pending_blocks_timeout: Duration::from_secs(60 * 4), bedrock_config: BedrockConfig { @@ -418,30 +388,18 @@ mod tests { } } - async fn components_for_tests() -> ( - JsonHandlerWithMockClients, - Vec, - NSSATransaction, - ) { + async fn components_for_tests() -> (JsonHandlerWithMockClients, NSSATransaction) { let config = sequencer_config_for_tests(); let (mut sequencer_core, mempool_handle) = SequencerCoreWithMockClients::start_from_config(config).await; - let initial_accounts = sequencer_core.sequencer_config().initial_accounts.clone(); - let signing_key = nssa::PrivateKey::try_new([1; 32]).unwrap(); + let signing_key = initial_pub_accounts_private_keys()[0].pub_sign_key.clone(); let balance_to_move = 10; let tx = common::test_utils::create_transaction_native_token_transfer( - AccountId::from_str( - &[ - 148, 179, 206, 253, 199, 51, 82, 86, 232, 2, 152, 122, 80, 243, 54, 207, 237, - 112, 83, 153, 44, 59, 204, 49, 128, 84, 160, 227, 216, 149, 97, 102, - ] - .to_base58(), - ) - .unwrap(), + initial_accounts()[0].account_id, 0, - AccountId::from_str(&[2; 32].to_base58()).unwrap(), + initial_accounts()[1].account_id, balance_to_move, signing_key, ); @@ -464,7 +422,6 @@ mod tests { mempool_handle, max_block_size, }, - initial_accounts, tx, ) } @@ -494,7 +451,7 @@ mod tests { #[actix_web::test] async fn test_get_account_balance_for_non_existent_account() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_account_balance", @@ -516,7 +473,7 @@ mod tests { #[actix_web::test] async fn test_get_account_balance_for_invalid_base58() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_account_balance", @@ -546,7 +503,7 @@ mod tests { #[actix_web::test] async fn test_get_account_balance_for_invalid_length() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_account_balance", @@ -576,9 +533,9 @@ mod tests { #[actix_web::test] async fn test_get_account_balance_for_existing_account() { - let (json_handler, initial_accounts, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; - let acc1_id = initial_accounts[0].account_id; + let acc1_id = initial_accounts()[0].account_id; let request = serde_json::json!({ "jsonrpc": "2.0", @@ -601,7 +558,7 @@ mod tests { #[actix_web::test] async fn test_get_accounts_nonces_for_non_existent_account() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_accounts_nonces", @@ -623,10 +580,10 @@ mod tests { #[actix_web::test] async fn test_get_accounts_nonces_for_existent_account() { - let (json_handler, initial_accounts, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; - let acc1_id = initial_accounts[0].account_id; - let acc2_id = initial_accounts[1].account_id; + let acc1_id = initial_accounts()[0].account_id; + let acc2_id = initial_accounts()[1].account_id; let request = serde_json::json!({ "jsonrpc": "2.0", @@ -649,7 +606,7 @@ mod tests { #[actix_web::test] async fn test_get_account_data_for_non_existent_account() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_account", @@ -676,7 +633,7 @@ mod tests { #[actix_web::test] async fn test_get_transaction_by_hash_for_non_existent_hash() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_transaction_by_hash", @@ -698,7 +655,7 @@ mod tests { #[actix_web::test] async fn test_get_transaction_by_hash_for_invalid_hex() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_transaction_by_hash", @@ -729,7 +686,7 @@ mod tests { #[actix_web::test] async fn test_get_transaction_by_hash_for_invalid_length() { - let (json_handler, _, _) = components_for_tests().await; + let (json_handler, _) = components_for_tests().await; let request = serde_json::json!({ "jsonrpc": "2.0", "method": "get_transaction_by_hash", @@ -760,7 +717,7 @@ mod tests { #[actix_web::test] async fn test_get_transaction_by_hash_for_existing_transaction() { - let (json_handler, _, tx) = components_for_tests().await; + let (json_handler, tx) = components_for_tests().await; let tx_hash_hex = hex::encode(tx.hash()); let expected_base64_encoded = general_purpose::STANDARD.encode(borsh::to_vec(&tx).unwrap()); diff --git a/wallet/src/chain_storage.rs b/wallet/src/chain_storage.rs index a4b22a31..b0794fc3 100644 --- a/wallet/src/chain_storage.rs +++ b/wallet/src/chain_storage.rs @@ -95,7 +95,7 @@ impl WalletChainStore { let mut public_init_acc_map = BTreeMap::new(); let mut private_init_acc_map = BTreeMap::new(); - for init_acc_data in config.initial_accounts.clone() { + 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); @@ -162,101 +162,7 @@ mod tests { }; use super::*; - use crate::config::{ - InitialAccountData, PersistentAccountDataPrivate, PersistentAccountDataPublic, - }; - - fn create_initial_accounts() -> Vec { - let initial_acc1 = serde_json::from_str( - r#"{ - "Public": { - "account_id": "6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV", - "pub_sign_key": [ - 16, - 162, - 106, - 154, - 236, - 125, - 52, - 184, - 35, - 100, - 238, - 174, - 69, - 197, - 41, - 77, - 187, - 10, - 118, - 75, - 0, - 11, - 148, - 238, - 185, - 181, - 133, - 17, - 220, - 72, - 124, - 77 - ] - } - }"#, - ) - .unwrap(); - - let initial_acc2 = serde_json::from_str( - r#"{ - "Public": { - "account_id": "7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo", - "pub_sign_key": [ - 113, - 121, - 64, - 177, - 204, - 85, - 229, - 214, - 178, - 6, - 109, - 191, - 29, - 154, - 63, - 38, - 242, - 18, - 244, - 219, - 8, - 208, - 35, - 136, - 23, - 127, - 207, - 237, - 216, - 169, - 190, - 27 - ] - } - }"#, - ) - .unwrap(); - - let initial_accounts = vec![initial_acc1, initial_acc2]; - - initial_accounts - } + use crate::config::{PersistentAccountDataPrivate, PersistentAccountDataPublic}; fn create_sample_wallet_config() -> WalletConfig { WalletConfig { @@ -266,7 +172,6 @@ mod tests { seq_tx_poll_max_blocks: 5, seq_poll_max_retries: 10, seq_block_poll_max_amount: 100, - initial_accounts: create_initial_accounts(), basic_auth: None, } } diff --git a/wallet/src/cli/config.rs b/wallet/src/cli/config.rs index bc0e3662..6366a143 100644 --- a/wallet/src/cli/config.rs +++ b/wallet/src/cli/config.rs @@ -4,6 +4,7 @@ use clap::Subcommand; use crate::{ WalletCore, cli::{SubcommandReturnValue, WalletSubcommand}, + config::InitialAccountData, }; /// Represents generic config CLI subcommand @@ -68,7 +69,7 @@ impl WalletSubcommand for ConfigSubcommand { ); } "initial_accounts" => { - println!("{:#?}", wallet_core.storage.wallet_config.initial_accounts); + println!("{:#?}", 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 3780a065..09d0e3a7 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -8,9 +8,12 @@ use std::{ use anyhow::{Context as _, Result}; use common::config::BasicAuth; use humantime_serde; -use key_protocol::key_management::{ - KeyChain, - key_tree::{ +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, }, }; @@ -18,12 +21,6 @@ use log::warn; use serde::{Deserialize, Serialize}; use url::Url; -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct InitialAccountDataPublic { - pub account_id: nssa::AccountId, - pub pub_sign_key: nssa::PrivateKey, -} - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PersistentAccountDataPublic { pub account_id: nssa::AccountId, @@ -31,13 +28,6 @@ pub struct PersistentAccountDataPublic { pub data: ChildKeysPublic, } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct InitialAccountDataPrivate { - pub account_id: nssa::AccountId, - pub account: nssa_core::account::Account, - pub key_chain: KeyChain, -} - #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PersistentAccountDataPrivate { pub account_id: nssa::AccountId, @@ -51,8 +41,21 @@ pub struct PersistentAccountDataPrivate { #[allow(clippy::large_enum_variant)] #[derive(Debug, Clone, Serialize, Deserialize)] pub enum InitialAccountData { - Public(InitialAccountDataPublic), - Private(InitialAccountDataPrivate), + Public(PublicAccountPrivateInitialData), + Private(PrivateAccountPrivateInitialData), +} + +impl InitialAccountData { + pub(crate) fn create_initial_accounts_data() -> Vec { + let pub_data = initial_pub_accounts_private_keys(); + let priv_data = initial_priv_accounts_private_keys(); + + pub_data + .into_iter() + .map(Into::into) + .chain(priv_data.into_iter().map(Into::into)) + .collect() + } } // Big difference in enum variants sizes @@ -130,14 +133,14 @@ impl PersistentAccountData { } } -impl From for InitialAccountData { - fn from(value: InitialAccountDataPublic) -> Self { +impl From for InitialAccountData { + fn from(value: PublicAccountPrivateInitialData) -> Self { Self::Public(value) } } -impl From for InitialAccountData { - fn from(value: InitialAccountDataPrivate) -> Self { +impl From for InitialAccountData { + fn from(value: PrivateAccountPrivateInitialData) -> Self { Self::Private(value) } } @@ -195,8 +198,6 @@ pub struct WalletConfig { pub seq_poll_max_retries: u64, /// Max amount of blocks to poll in one request pub seq_block_poll_max_amount: u64, - /// Initial accounts for wallet - pub initial_accounts: Vec, /// Basic authentication credentials #[serde(skip_serializing_if = "Option::is_none")] pub basic_auth: Option, @@ -212,291 +213,6 @@ impl Default for WalletConfig { seq_poll_max_retries: 5, seq_block_poll_max_amount: 100, basic_auth: None, - initial_accounts: { - let init_acc_json = r#" - [ - { - "Public": { - "account_id": "6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV", - "pub_sign_key": [ - 16, - 162, - 106, - 154, - 236, - 125, - 52, - 184, - 35, - 100, - 238, - 174, - 69, - 197, - 41, - 77, - 187, - 10, - 118, - 75, - 0, - 11, - 148, - 238, - 185, - 181, - 133, - 17, - 220, - 72, - 124, - 77 - ] - } - }, - { - "Public": { - "account_id": "7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo", - "pub_sign_key": [ - 113, - 121, - 64, - 177, - 204, - 85, - 229, - 214, - 178, - 6, - 109, - 191, - 29, - 154, - 63, - 38, - 242, - 18, - 244, - 219, - 8, - 208, - 35, - 136, - 23, - 127, - 207, - 237, - 216, - 169, - 190, - 27 - ] - } - }, - { - "Private": { - "account_id": "FpdcxBrMkHWqXCBQ6FG98eYfWGY6jWZRsKNSi1FwDMxy", - "account": { - "program_owner": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "balance": 10000, - "data": [], - "nonce": 0 - }, - "key_chain": { - "secret_spending_key": [ - 239, - 27, - 159, - 83, - 199, - 194, - 132, - 33, - 20, - 28, - 217, - 103, - 101, - 57, - 27, - 125, - 84, - 57, - 19, - 86, - 98, - 135, - 161, - 221, - 108, - 125, - 152, - 174, - 161, - 64, - 16, - 200 - ], - "private_key_holder": { - "nullifier_secret_key": [ - 71, - 195, - 16, - 119, - 0, - 98, - 35, - 106, - 139, - 82, - 145, - 50, - 27, - 140, - 206, - 19, - 53, - 122, - 166, - 76, - 195, - 0, - 16, - 19, - 21, - 143, - 155, - 119, - 9, - 200, - 81, - 105 - ], - "viewing_secret_key": [ - 5, - 117, - 221, - 27, - 236, - 199, - 53, - 22, - 249, - 231, - 98, - 147, - 213, - 116, - 191, - 82, - 188, - 148, - 175, - 98, - 139, - 52, - 232, - 249, - 220, - 217, - 83, - 58, - 112, - 155, - 197, - 196 - ] - }, - "nullifer_public_key": [ - 177, - 64, - 1, - 11, - 87, - 38, - 254, - 159, - 231, - 165, - 1, - 94, - 64, - 137, - 243, - 76, - 249, - 101, - 251, - 129, - 33, - 101, - 189, - 30, - 42, - 11, - 191, - 34, - 103, - 186, - 227, - 230 - ], - "viewing_public_key": [ - 2, 69, 126, 43, 158, 209, 172, 144, 23, 185, 208, 25, 163, 166, 176, 200, 225, 251, 106, 211, 4, 199, 112, 243, 207, 144, 135, 56, 157, 167, 32, 219, 38] - } - } - }, - { - "Private": { - "account_id": "E8HwiTyQe4H9HK7icTvn95HQMnzx49mP9A2ddtMLpNaN", - "account": { - "program_owner": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 - ], - "balance": 20000, - "data": [], - "nonce": 0 - }, - "key_chain": { - "secret_spending_key": [ - 48, 175, 124, 10, 230, 240, 166, 14, 249, 254, 157, 226, 208, 124, 122, 177, 203, 139, 192, 180, 43, 120, 55, 151, 50, 21, 113, 22, 254, 83, 148, 56], - "private_key_holder": { - "nullifier_secret_key": [ - 99, 82, 190, 140, 234, 10, 61, 163, 15, 211, 179, 54, 70, 166, 87, 5, 182, 68, 117, 244, 217, 23, 99, 9, 4, 177, 230, 125, 109, 91, 160, 30 - ], - "viewing_secret_key": [ - 205, 32, 76, 251, 255, 236, 96, 119, 61, 111, 65, 100, 75, 218, 12, 22, 17, 170, 55, 226, 21, 154, 161, 34, 208, 74, 27, 1, 119, 13, 88, 128 - ] - }, - "nullifer_public_key": [ - 32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, 243, 134, 135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165 - ], - "viewing_public_key": [ - 2, 79, 110, 46, 203, 29, 206, 205, 18, 86, 27, 189, 104, 103, 113, 181, 110, 53, 78, 172, 11, 171, 190, 18, 126, 214, 81, 77, 192, 154, 58, 195, 238 - ] - } - } - } - ] - "#; - serde_json::from_str(init_acc_json).unwrap() - }, } } } @@ -546,7 +262,6 @@ impl WalletConfig { seq_tx_poll_max_blocks, seq_poll_max_retries, seq_block_poll_max_amount, - initial_accounts, basic_auth, } = self; @@ -557,7 +272,6 @@ impl WalletConfig { seq_tx_poll_max_blocks: o_seq_tx_poll_max_blocks, seq_poll_max_retries: o_seq_poll_max_retries, seq_block_poll_max_amount: o_seq_block_poll_max_amount, - initial_accounts: o_initial_accounts, basic_auth: o_basic_auth, } = overrides; @@ -585,10 +299,6 @@ impl WalletConfig { warn!("Overriding wallet config 'seq_block_poll_max_amount' to {v}"); *seq_block_poll_max_amount = v; } - if let Some(v) = o_initial_accounts { - warn!("Overriding wallet config 'initial_accounts' to {v:#?}"); - *initial_accounts = v; - } if let Some(v) = o_basic_auth { warn!("Overriding wallet config 'basic_auth' to {v:#?}"); *basic_auth = v; diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index 20c04968..f7978f87 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -2,7 +2,10 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr}; use anyhow::Result; use base64::{Engine, engine::general_purpose::STANDARD as BASE64}; -use key_protocol::key_protocol_core::NSSAUserData; +use key_protocol::{ + initial_state::{PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData}, + key_protocol_core::NSSAUserData, +}; use nssa::Account; use nssa_core::account::Nonce; use rand::{RngCore, rngs::OsRng}; @@ -11,8 +14,8 @@ use serde::Serialize; use crate::{ HOME_DIR_ENV_VAR, config::{ - InitialAccountData, InitialAccountDataPrivate, InitialAccountDataPublic, Label, - PersistentAccountDataPrivate, PersistentAccountDataPublic, PersistentStorage, + InitialAccountData, Label, PersistentAccountDataPrivate, PersistentAccountDataPublic, + PersistentStorage, }, }; @@ -89,7 +92,7 @@ pub fn produce_data_for_storage( for (account_id, key) in &user_data.default_pub_account_signing_keys { vec_for_storage.push( - InitialAccountData::Public(InitialAccountDataPublic { + InitialAccountData::Public(PublicAccountPrivateInitialData { account_id: *account_id, pub_sign_key: key.clone(), }) @@ -99,7 +102,7 @@ pub fn produce_data_for_storage( for (account_id, (key_chain, account)) in &user_data.default_user_private_accounts { vec_for_storage.push( - InitialAccountData::Private(InitialAccountDataPrivate { + InitialAccountData::Private(PrivateAccountPrivateInitialData { account_id: *account_id, account: account.clone(), key_chain: key_chain.clone(), From a9a0c386ad68dd63065962c3366d502095acaa55 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Mon, 16 Mar 2026 15:15:35 +0200 Subject: [PATCH 2/9] fix: integartion tests fix --- indexer/core/src/config.rs | 7 +++++ indexer/core/src/lib.rs | 47 ++++++++++++++++++++++++++++++--- integration_tests/src/config.rs | 35 +++++++++++++----------- sequencer_core/src/config.rs | 7 +++++ sequencer_core/src/lib.rs | 42 ++++++++++++++++++++++++++++- sequencer_rpc/src/process.rs | 2 ++ wallet/src/chain_storage.rs | 44 ++++++++++++++++++++++-------- wallet/src/config.rs | 9 +++++++ 8 files changed, 162 insertions(+), 31 deletions(-) diff --git a/indexer/core/src/config.rs b/indexer/core/src/config.rs index fad10ec5..2b4bfa47 100644 --- a/indexer/core/src/config.rs +++ b/indexer/core/src/config.rs @@ -9,6 +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 url::Url; @@ -32,6 +35,10 @@ pub struct IndexerConfig { pub consensus_info_polling_interval: Duration, pub bedrock_client_config: ClientConfig, pub channel_id: ChannelId, + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_accounts: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_commitments: Option>, } impl IndexerConfig { diff --git a/indexer/core/src/lib.rs b/indexer/core/src/lib.rs index 002a6c91..0ab190d5 100644 --- a/indexer/core/src/lib.rs +++ b/indexer/core/src/lib.rs @@ -3,7 +3,7 @@ use std::collections::VecDeque; use anyhow::Result; use bedrock_client::{BedrockClient, HeaderId}; use common::{ - HashType, + HashType, PINATA_BASE58, block::{Block, HashableBlockData}, }; use key_protocol::initial_state::initial_state_testnet; @@ -12,6 +12,7 @@ use logos_blockchain_core::mantle::{ Op, SignedMantleTx, ops::channel::{ChannelId, inscribe::InscriptionOp}, }; +use nssa::V02State; use crate::{block_store::IndexerStore, config::IndexerConfig}; @@ -56,8 +57,48 @@ impl IndexerCore { let channel_genesis_msg_id = [0; 32]; let start_block = hashable_data.into_pending_block(&signing_key, channel_genesis_msg_id); - // ToDo: replace with `initial_state()` after testnet - let state = initial_state_testnet(); + let initial_commitments: Option> = config + .initial_commitments + .clone() + .map(|initial_commitments| { + initial_commitments + .iter() + .map(|init_comm_data| { + let npk = &init_comm_data.npk; + + let mut acc = init_comm_data.account.clone(); + + acc.program_owner = + nssa::program::Program::authenticated_transfer_program().id(); + + nssa_core::Commitment::new(npk, &acc) + }) + .collect() + }); + + let init_accs: Option> = + config.initial_accounts.clone().map(|initial_accounts| { + initial_accounts + .iter() + .map(|acc_data| (acc_data.account_id, acc_data.balance)) + .collect() + }); + + // If initial commitments or accounts are present in config, need to construct state from + // them + let state = if initial_commitments.is_some() || init_accs.is_some() { + let mut state = V02State::new_with_genesis_accounts( + &init_accs.unwrap_or_default(), + &initial_commitments.unwrap_or_default(), + ); + + // ToDo: Remove after testnet + state.add_pinata_program(PINATA_BASE58.parse().unwrap()); + + state + } else { + initial_state_testnet() + }; let home = config.home.join("rocksdb"); diff --git a/integration_tests/src/config.rs b/integration_tests/src/config.rs index 8dd18a25..e1922cc4 100644 --- a/integration_tests/src/config.rs +++ b/integration_tests/src/config.rs @@ -2,16 +2,19 @@ use std::{net::SocketAddr, path::PathBuf, time::Duration}; use anyhow::{Context, Result}; use bytesize::ByteSize; -use common::block::{AccountInitialData, CommitmentsInitialData}; use indexer_service::{BackoffConfig, ChannelId, ClientConfig, IndexerConfig}; -use key_protocol::key_management::KeyChain; +use key_protocol::{ + initial_state::{ + PrivateAccountPrivateInitialData, PrivateAccountPublicInitialData, + PublicAccountPrivateInitialData, PublicAccountPublicInitialData, + }, + 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 url::Url; -use wallet::config::{ - InitialAccountData, InitialAccountDataPrivate, InitialAccountDataPublic, WalletConfig, -}; +use wallet::config::{InitialAccountData, WalletConfig}; pub fn indexer_config( bedrock_addr: SocketAddr, @@ -30,8 +33,8 @@ pub fn indexer_config( max_retries: 10, }, }, - initial_accounts: initial_data.sequencer_initial_accounts(), - initial_commitments: initial_data.sequencer_initial_commitments(), + initial_accounts: Some(initial_data.sequencer_initial_accounts()), + initial_commitments: Some(initial_data.sequencer_initial_commitments()), signing_key: [37; 32], channel_id: bedrock_channel_id(), }) @@ -81,8 +84,8 @@ pub fn sequencer_config( block_create_timeout, retry_pending_blocks_timeout: Duration::from_secs(120), port: 0, - initial_accounts: initial_data.sequencer_initial_accounts(), - initial_commitments: initial_data.sequencer_initial_commitments(), + initial_accounts: Some(initial_data.sequencer_initial_accounts()), + initial_commitments: Some(initial_data.sequencer_initial_commitments()), signing_key: [37; 32], bedrock_config: BedrockConfig { backoff: BackoffConfig { @@ -111,7 +114,7 @@ pub fn wallet_config( seq_tx_poll_max_blocks: 15, seq_poll_max_retries: 10, seq_block_poll_max_amount: 100, - initial_accounts: initial_data.wallet_initial_accounts(), + initial_accounts: Some(initial_data.wallet_initial_accounts()), basic_auth: None, }) } @@ -184,13 +187,13 @@ impl InitialData { } } - fn sequencer_initial_accounts(&self) -> Vec { + fn sequencer_initial_accounts(&self) -> Vec { self.public_accounts .iter() .map(|(priv_key, balance)| { let pub_key = PublicKey::new_from_private_key(priv_key); let account_id = AccountId::from(&pub_key); - AccountInitialData { + PublicAccountPublicInitialData { account_id, balance: *balance, } @@ -198,10 +201,10 @@ impl InitialData { .collect() } - fn sequencer_initial_commitments(&self) -> Vec { + fn sequencer_initial_commitments(&self) -> Vec { self.private_accounts .iter() - .map(|(key_chain, account)| CommitmentsInitialData { + .map(|(key_chain, account)| PrivateAccountPublicInitialData { npk: key_chain.nullifer_public_key.clone(), account: account.clone(), }) @@ -214,14 +217,14 @@ impl InitialData { .map(|(priv_key, _)| { let pub_key = PublicKey::new_from_private_key(priv_key); let account_id = AccountId::from(&pub_key); - InitialAccountData::Public(InitialAccountDataPublic { + InitialAccountData::Public(PublicAccountPrivateInitialData { account_id, pub_sign_key: priv_key.clone(), }) }) .chain(self.private_accounts.iter().map(|(key_chain, account)| { let account_id = AccountId::from(&key_chain.nullifer_public_key); - InitialAccountData::Private(InitialAccountDataPrivate { + InitialAccountData::Private(PrivateAccountPrivateInitialData { account_id, account: account.clone(), key_chain: key_chain.clone(), diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 05a0dc72..e92c3794 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -10,6 +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 url::Url; @@ -46,6 +49,10 @@ pub struct SequencerConfig { pub bedrock_config: BedrockConfig, /// Indexer RPC URL pub indexer_rpc_url: Url, + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_accounts: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_commitments: Option>, } #[derive(Clone, Serialize, Deserialize)] diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index fdb65d2a..9a103a5f 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -14,6 +14,7 @@ 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}; +use nssa::V02State; use crate::{ block_settlement_client::{BlockSettlementClient, BlockSettlementClientTrait, MsgId}, @@ -101,7 +102,44 @@ impl SequencerCore> = config + .initial_commitments + .clone() + .map(|initial_commitments| { + initial_commitments + .iter() + .map(|init_comm_data| { + let npk = &init_comm_data.npk; + + let mut acc = init_comm_data.account.clone(); + + acc.program_owner = + nssa::program::Program::authenticated_transfer_program().id(); + + nssa_core::Commitment::new(npk, &acc) + }) + .collect() + }); + + let init_accs: Option> = + config.initial_accounts.clone().map(|initial_accounts| { + initial_accounts + .iter() + .map(|acc_data| (acc_data.account_id, acc_data.balance)) + .collect() + }); + + // If initial commitments or accounts are present in config, need to construct state + // from them + if initial_commitments.is_some() || init_accs.is_some() { + V02State::new_with_genesis_accounts( + &init_accs.unwrap_or_default(), + &initial_commitments.unwrap_or_default(), + ) + } else { + initial_state() + } } }; @@ -379,6 +417,8 @@ mod tests { }, retry_pending_blocks_timeout: Duration::from_secs(60 * 4), indexer_rpc_url: "ws://localhost:8779".parse().unwrap(), + initial_accounts: None, + initial_commitments: None, } } diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index 3fb7a6d9..75ace675 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -385,6 +385,8 @@ mod tests { }), }, indexer_rpc_url: "ws://localhost:8779".parse().unwrap(), + initial_accounts: None, + initial_commitments: None, } } diff --git a/wallet/src/chain_storage.rs b/wallet/src/chain_storage.rs index b0794fc3..2c998c8a 100644 --- a/wallet/src/chain_storage.rs +++ b/wallet/src/chain_storage.rs @@ -95,18 +95,39 @@ impl WalletChainStore { let mut public_init_acc_map = BTreeMap::new(); let mut private_init_acc_map = BTreeMap::new(); - 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); + // 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)); + } } - 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)); + } + } 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)); + } } } } @@ -173,6 +194,7 @@ mod tests { seq_poll_max_retries: 10, seq_block_poll_max_amount: 100, basic_auth: None, + initial_accounts: None, } } diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 09d0e3a7..a5422d17 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -201,6 +201,8 @@ pub struct WalletConfig { /// Basic authentication credentials #[serde(skip_serializing_if = "Option::is_none")] pub basic_auth: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_accounts: Option>, } impl Default for WalletConfig { @@ -213,6 +215,7 @@ impl Default for WalletConfig { seq_poll_max_retries: 5, seq_block_poll_max_amount: 100, basic_auth: None, + initial_accounts: None, } } } @@ -263,6 +266,7 @@ impl WalletConfig { seq_poll_max_retries, seq_block_poll_max_amount, basic_auth, + initial_accounts, } = self; let WalletConfigOverrides { @@ -273,6 +277,7 @@ impl WalletConfig { seq_poll_max_retries: o_seq_poll_max_retries, seq_block_poll_max_amount: o_seq_block_poll_max_amount, basic_auth: o_basic_auth, + initial_accounts: o_initial_accounts, } = overrides; if let Some(v) = o_override_rust_log { @@ -303,5 +308,9 @@ impl WalletConfig { warn!("Overriding wallet config 'basic_auth' to {v:#?}"); *basic_auth = v; } + if let Some(v) = o_initial_accounts { + warn!("Overriding wallet config 'initial_accounts' to {v:#?}"); + *initial_accounts = v; + } } } From 6b6b3a0fe8a3690d281155887016fc1d85347295 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Mon, 16 Mar 2026 15:56:26 +0200 Subject: [PATCH 3/9] fix: dep fix --- Cargo.lock | 2 -- sequencer_core/Cargo.toml | 1 - sequencer_rpc/Cargo.toml | 1 - 3 files changed, 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f2e2a65c..f326b1a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7454,7 +7454,6 @@ name = "sequencer_core" version = "0.1.0" dependencies = [ "anyhow", - "base58", "bedrock_client", "borsh", "bytesize", @@ -7486,7 +7485,6 @@ dependencies = [ "actix-cors", "actix-web", "anyhow", - "base58", "base64 0.22.1", "bedrock_client", "borsh", diff --git a/sequencer_core/Cargo.toml b/sequencer_core/Cargo.toml index 1d4e604e..fa740c42 100644 --- a/sequencer_core/Cargo.toml +++ b/sequencer_core/Cargo.toml @@ -13,7 +13,6 @@ mempool.workspace = true bedrock_client.workspace = true key_protocol.workspace = true -base58.workspace = true anyhow.workspace = true serde.workspace = true serde_json.workspace = true diff --git a/sequencer_rpc/Cargo.toml b/sequencer_rpc/Cargo.toml index 09641a00..c4907e49 100644 --- a/sequencer_rpc/Cargo.toml +++ b/sequencer_rpc/Cargo.toml @@ -18,7 +18,6 @@ log.workspace = true serde.workspace = true actix-cors.workspace = true futures.workspace = true -base58.workspace = true hex.workspace = true tempfile.workspace = true base64.workspace = true From b5afcba4c4527d1583c74ced14d36d22b45b7906 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Mon, 16 Mar 2026 17:02:22 +0200 Subject: [PATCH 4/9] fix: moved constants into consts --- key_protocol/src/initial_state.rs | 180 +++++++++++++++++------------- 1 file changed, 104 insertions(+), 76 deletions(-) diff --git a/key_protocol/src/initial_state.rs b/key_protocol/src/initial_state.rs index 8011d471..3af9182f 100644 --- a/key_protocol/src/initial_state.rs +++ b/key_protocol/src/initial_state.rs @@ -8,6 +8,74 @@ use crate::key_management::{ secret_holders::{PrivateKeyHolder, SecretSpendingKey}, }; +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, + 11, 148, 238, 185, 181, 133, 17, 220, 72, 124, 77, +]; + +const PRIVATE_KEY_PUB_ACC_B: [u8; 32] = [ + 113, 121, 64, 177, 204, 85, 229, 214, 178, 6, 109, 191, 29, 154, 63, 38, 242, 18, 244, 219, 8, + 208, 35, 136, 23, 127, 207, 237, 216, 169, 190, 27, +]; + +const SSK_PRIV_ACC_A: [u8; 32] = [ + 93, 13, 190, 240, 250, 33, 108, 195, 176, 40, 144, 61, 4, 28, 58, 112, 53, 161, 42, 238, 155, + 27, 23, 176, 208, 121, 15, 229, 165, 180, 99, 143, +]; + +const SSK_PRIV_ACC_B: [u8; 32] = [ + 48, 175, 124, 10, 230, 240, 166, 14, 249, 254, 157, 226, 208, 124, 122, 177, 203, 139, 192, + 180, 43, 120, 55, 151, 50, 21, 113, 22, 254, 83, 148, 56, +]; + +const NSK_PRIV_ACC_A: [u8; 32] = [ + 25, 21, 186, 59, 180, 224, 101, 64, 163, 208, 228, 43, 13, 185, 100, 123, 156, 47, 80, 179, 72, + 51, 115, 11, 180, 99, 21, 201, 48, 194, 118, 144, +]; + +const NSK_PRIV_ACC_B: [u8; 32] = [ + 99, 82, 190, 140, 234, 10, 61, 163, 15, 211, 179, 54, 70, 166, 87, 5, 182, 68, 117, 244, 217, + 23, 99, 9, 4, 177, 230, 125, 109, 91, 160, 30, +]; + +const VSK_PRIV_ACC_A: [u8; 32] = [ + 5, 85, 114, 119, 141, 187, 202, 170, 122, 253, 198, 81, 150, 8, 155, 21, 192, 65, 24, 124, 116, + 98, 110, 106, 137, 90, 165, 239, 80, 13, 222, 30, +]; + +const VSK_PRIV_ACC_B: [u8; 32] = [ + 205, 32, 76, 251, 255, 236, 96, 119, 61, 111, 65, 100, 75, 218, 12, 22, 17, 170, 55, 226, 21, + 154, 161, 34, 208, 74, 27, 1, 119, 13, 88, 128, +]; + +const VPK_PRIV_ACC_A: [u8; 33] = [ + 2, 210, 206, 38, 213, 4, 182, 198, 220, 47, 93, 148, 61, 84, 148, 250, 158, 45, 8, 81, 48, 80, + 46, 230, 87, 210, 47, 204, 76, 58, 214, 167, 81, +]; + +const VPK_PRIV_ACC_B: [u8; 33] = [ + 2, 79, 110, 46, 203, 29, 206, 205, 18, 86, 27, 189, 104, 103, 113, 181, 110, 53, 78, 172, 11, + 171, 190, 18, 126, 214, 81, 77, 192, 154, 58, 195, 238, +]; + +const NPK_PRIV_ACC_A: [u8; 32] = [ + 167, 108, 50, 153, 74, 47, 151, 188, 140, 79, 195, 31, 181, 9, 40, 167, 201, 32, 175, 129, 45, + 245, 223, 193, 210, 170, 247, 128, 167, 140, 155, 129, +]; + +const NPK_PRIV_ACC_B: [u8; 32] = [ + 32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, 243, 134, 135, 210, + 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165, +]; + +const DEFAULT_PROGRAM_OWNER: [u32; 8] = [0, 0, 0, 0, 0, 0, 0, 0]; + +const PUB_ACC_A_INITIAL_BALANCE: u128 = 10000; +const PUB_ACC_B_INITIAL_BALANCE: u128 = 20000; + +const PRIV_ACC_A_INITIAL_BALANCE: u128 = 10000; +const PRIV_ACC_B_INITIAL_BALANCE: u128 = 20000; + #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct PublicAccountPublicInitialData { pub account_id: AccountId, @@ -34,17 +102,9 @@ pub struct PrivateAccountPrivateInitialData { } pub fn initial_pub_accounts_private_keys() -> Vec { - let acc1_pub_sign_key = PrivateKey::try_new([ - 16, 162, 106, 154, 236, 125, 52, 184, 35, 100, 238, 174, 69, 197, 41, 77, 187, 10, 118, 75, - 0, 11, 148, 238, 185, 181, 133, 17, 220, 72, 124, 77, - ]) - .unwrap(); + let acc1_pub_sign_key = PrivateKey::try_new(PRIVATE_KEY_PUB_ACC_A).unwrap(); - let acc2_pub_sign_key = PrivateKey::try_new([ - 113, 121, 64, 177, 204, 85, 229, 214, 178, 6, 109, 191, 29, 154, 63, 38, 242, 18, 244, 219, - 8, 208, 35, 136, 23, 127, 207, 237, 216, 169, 190, 27, - ]) - .unwrap(); + let acc2_pub_sign_key = PrivateKey::try_new(PRIVATE_KEY_PUB_ACC_B).unwrap(); vec![ PublicAccountPrivateInitialData { @@ -60,61 +120,31 @@ pub fn initial_pub_accounts_private_keys() -> Vec Vec { let key_chain_1 = KeyChain { - secret_spending_key: SecretSpendingKey([ - 93, 13, 190, 240, 250, 33, 108, 195, 176, 40, 144, 61, 4, 28, 58, 112, 53, 161, 42, - 238, 155, 27, 23, 176, 208, 121, 15, 229, 165, 180, 99, 143, - ]), + secret_spending_key: SecretSpendingKey(SSK_PRIV_ACC_A), private_key_holder: PrivateKeyHolder { - nullifier_secret_key: [ - 25, 21, 186, 59, 180, 224, 101, 64, 163, 208, 228, 43, 13, 185, 100, 123, 156, 47, - 80, 179, 72, 51, 115, 11, 180, 99, 21, 201, 48, 194, 118, 144, - ], - viewing_secret_key: [ - 5, 85, 114, 119, 141, 187, 202, 170, 122, 253, 198, 81, 150, 8, 155, 21, 192, 65, - 24, 124, 116, 98, 110, 106, 137, 90, 165, 239, 80, 13, 222, 30, - ], + nullifier_secret_key: NSK_PRIV_ACC_A, + viewing_secret_key: VSK_PRIV_ACC_A, }, - nullifer_public_key: NullifierPublicKey([ - 167, 108, 50, 153, 74, 47, 151, 188, 140, 79, 195, 31, 181, 9, 40, 167, 201, 32, 175, - 129, 45, 245, 223, 193, 210, 170, 247, 128, 167, 140, 155, 129, - ]), - viewing_public_key: Secp256k1Point(vec![ - 2, 210, 206, 38, 213, 4, 182, 198, 220, 47, 93, 148, 61, 84, 148, 250, 158, 45, 8, 81, - 48, 80, 46, 230, 87, 210, 47, 204, 76, 58, 214, 167, 81, - ]), + nullifer_public_key: NullifierPublicKey(NPK_PRIV_ACC_A), + viewing_public_key: Secp256k1Point(VPK_PRIV_ACC_A.to_vec()), }; let key_chain_2 = KeyChain { - secret_spending_key: SecretSpendingKey([ - 48, 175, 124, 10, 230, 240, 166, 14, 249, 254, 157, 226, 208, 124, 122, 177, 203, 139, - 192, 180, 43, 120, 55, 151, 50, 21, 113, 22, 254, 83, 148, 56, - ]), + secret_spending_key: SecretSpendingKey(SSK_PRIV_ACC_B), private_key_holder: PrivateKeyHolder { - nullifier_secret_key: [ - 99, 82, 190, 140, 234, 10, 61, 163, 15, 211, 179, 54, 70, 166, 87, 5, 182, 68, 117, - 244, 217, 23, 99, 9, 4, 177, 230, 125, 109, 91, 160, 30, - ], - viewing_secret_key: [ - 205, 32, 76, 251, 255, 236, 96, 119, 61, 111, 65, 100, 75, 218, 12, 22, 17, 170, - 55, 226, 21, 154, 161, 34, 208, 74, 27, 1, 119, 13, 88, 128, - ], + nullifier_secret_key: NSK_PRIV_ACC_B, + viewing_secret_key: VSK_PRIV_ACC_B, }, - nullifer_public_key: NullifierPublicKey([ - 32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, 243, 134, - 135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165, - ]), - viewing_public_key: Secp256k1Point(vec![ - 2, 79, 110, 46, 203, 29, 206, 205, 18, 86, 27, 189, 104, 103, 113, 181, 110, 53, 78, - 172, 11, 171, 190, 18, 126, 214, 81, 77, 192, 154, 58, 195, 238, - ]), + nullifer_public_key: NullifierPublicKey(NPK_PRIV_ACC_B), + viewing_public_key: Secp256k1Point(VPK_PRIV_ACC_B.to_vec()), }; vec![ PrivateAccountPrivateInitialData { account_id: AccountId::from(&key_chain_1.nullifer_public_key), account: Account { - program_owner: [0, 0, 0, 0, 0, 0, 0, 0], - balance: 10000, + program_owner: DEFAULT_PROGRAM_OWNER, + balance: PRIV_ACC_A_INITIAL_BALANCE, data: Data::default(), nonce: 0, }, @@ -123,8 +153,8 @@ pub fn initial_priv_accounts_private_keys() -> Vec Vec { vec![ PublicAccountPublicInitialData { account_id: initial_account_ids[0], - balance: 10000, + balance: PUB_ACC_A_INITIAL_BALANCE, }, PublicAccountPublicInitialData { account_id: initial_account_ids[1], - balance: 20000, + balance: PUB_ACC_B_INITIAL_BALANCE, }, ] } @@ -197,6 +227,12 @@ mod tests { use super::*; + const PUB_ACC_A_TEXT_ADDR: &str = "6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV"; + const PUB_ACC_B_TEXT_ADDR: &str = "7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo"; + + const PRIV_ACC_A_TEXT_ADDR: &str = "5ya25h4Xc9GAmrGB2WrTEnEWtQKJwRwQx3Xfo2tucNcE"; + const PRIV_ACC_B_TEXT_ADDR: &str = "E8HwiTyQe4H9HK7icTvn95HQMnzx49mP9A2ddtMLpNaN"; + #[test] fn test_pub_state_consistency() { let init_accs_private_data = initial_pub_accounts_private_keys(); @@ -215,18 +251,16 @@ mod tests { assert_eq!( init_accs_pub_data[0], PublicAccountPublicInitialData { - account_id: AccountId::from_str("6iArKUXxhUJqS7kCaPNhwMWt3ro71PDyBj7jwAyE2VQV") - .unwrap(), - balance: 10000, + account_id: AccountId::from_str(PUB_ACC_A_TEXT_ADDR).unwrap(), + balance: PUB_ACC_A_INITIAL_BALANCE, } ); assert_eq!( init_accs_pub_data[1], PublicAccountPublicInitialData { - account_id: AccountId::from_str("7wHg9sbJwc6h3NP1S9bekfAzB8CHifEcxKswCKUt3YQo") - .unwrap(), - balance: 20000, + account_id: AccountId::from_str(PUB_ACC_B_TEXT_ADDR).unwrap(), + balance: PUB_ACC_B_INITIAL_BALANCE, } ) } @@ -312,11 +346,11 @@ mod tests { assert_eq!( init_private_accs_keys[0].account_id.to_string(), - "5ya25h4Xc9GAmrGB2WrTEnEWtQKJwRwQx3Xfo2tucNcE" + PRIV_ACC_A_TEXT_ADDR ); assert_eq!( init_private_accs_keys[1].account_id.to_string(), - "E8HwiTyQe4H9HK7icTvn95HQMnzx49mP9A2ddtMLpNaN" + PRIV_ACC_B_TEXT_ADDR ); assert_eq!( @@ -331,13 +365,10 @@ mod tests { assert_eq!( init_comms[0], PrivateAccountPublicInitialData { - npk: NullifierPublicKey([ - 167, 108, 50, 153, 74, 47, 151, 188, 140, 79, 195, 31, 181, 9, 40, 167, 201, - 32, 175, 129, 45, 245, 223, 193, 210, 170, 247, 128, 167, 140, 155, 129, - ]), + npk: NullifierPublicKey(NPK_PRIV_ACC_A), account: Account { - program_owner: [0, 0, 0, 0, 0, 0, 0, 0], - balance: 10000, + program_owner: DEFAULT_PROGRAM_OWNER, + balance: PRIV_ACC_A_INITIAL_BALANCE, data: Data::default(), nonce: 0, }, @@ -347,13 +378,10 @@ mod tests { assert_eq!( init_comms[1], PrivateAccountPublicInitialData { - npk: NullifierPublicKey([ - 32, 67, 72, 164, 106, 53, 66, 239, 141, 15, 52, 230, 136, 177, 2, 236, 207, - 243, 134, 135, 210, 143, 87, 232, 215, 128, 194, 120, 113, 224, 4, 165, - ]), + npk: NullifierPublicKey(NPK_PRIV_ACC_B), account: Account { - program_owner: [0, 0, 0, 0, 0, 0, 0, 0], - balance: 20000, + program_owner: DEFAULT_PROGRAM_OWNER, + balance: PRIV_ACC_B_INITIAL_BALANCE, data: Data::default(), nonce: 0, }, From a0ab6ad92dd7dfcc572a25fdb1152cc554fcdca5 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Wed, 18 Mar 2026 18:32:05 +0200 Subject: [PATCH 5/9] fix: lint fix --- indexer/core/src/config.rs | 2 +- integration_tests/src/config.rs | 4 +- key_protocol/src/initial_state.rs | 18 ++++--- sequencer_core/src/config.rs | 2 +- sequencer_core/src/lib.rs | 81 +++++++++++++++---------------- sequencer_rpc/src/process.rs | 5 +- wallet/src/config.rs | 22 ++++----- wallet/src/helperfunctions.rs | 8 +-- 8 files changed, 72 insertions(+), 70 deletions(-) diff --git a/indexer/core/src/config.rs b/indexer/core/src/config.rs index e45870df..5eb8dd92 100644 --- a/indexer/core/src/config.rs +++ b/indexer/core/src/config.rs @@ -29,7 +29,7 @@ pub struct ClientConfig { pub struct IndexerConfig { /// Home dir of sequencer storage. pub home: PathBuf, - /// Sequencers signing key + /// Sequencers signing key. pub signing_key: [u8; 32], #[serde(with = "humantime_serde")] pub consensus_info_polling_interval: Duration, diff --git a/integration_tests/src/config.rs b/integration_tests/src/config.rs index cce50db1..875e1652 100644 --- a/integration_tests/src/config.rs +++ b/integration_tests/src/config.rs @@ -142,11 +142,11 @@ impl InitialData { }) .chain(self.private_accounts.iter().map(|(key_chain, account)| { let account_id = AccountId::from(&key_chain.nullifer_public_key); - InitialAccountData::Private(PrivateAccountPrivateInitialData { + InitialAccountData::Private(Box::new(PrivateAccountPrivateInitialData { account_id, account: account.clone(), key_chain: key_chain.clone(), - }) + })) })) .collect() } diff --git a/key_protocol/src/initial_state.rs b/key_protocol/src/initial_state.rs index 3af9182f..2150bd4c 100644 --- a/key_protocol/src/initial_state.rs +++ b/key_protocol/src/initial_state.rs @@ -101,6 +101,7 @@ pub struct PrivateAccountPrivateInitialData { pub key_chain: KeyChain, } +#[must_use] pub fn initial_pub_accounts_private_keys() -> Vec { let acc1_pub_sign_key = PrivateKey::try_new(PRIVATE_KEY_PUB_ACC_A).unwrap(); @@ -118,6 +119,7 @@ pub fn initial_pub_accounts_private_keys() -> Vec Vec { let key_chain_1 = KeyChain { secret_spending_key: SecretSpendingKey(SSK_PRIV_ACC_A), @@ -163,16 +165,18 @@ pub fn initial_priv_accounts_private_keys() -> Vec Vec { initial_priv_accounts_private_keys() .into_iter() .map(|data| PrivateAccountPublicInitialData { npk: data.key_chain.nullifer_public_key.clone(), - account: data.account.clone(), + account: data.account, }) .collect() } +#[must_use] pub fn initial_accounts() -> Vec { let initial_account_ids = initial_pub_accounts_private_keys() .into_iter() @@ -191,6 +195,7 @@ pub fn initial_accounts() -> Vec { ] } +#[must_use] pub fn initial_state() -> V02State { let initial_commitments: Vec = initial_commitments() .iter() @@ -213,6 +218,7 @@ pub fn initial_state() -> V02State { nssa::V02State::new_with_genesis_accounts(&init_accs, &initial_commitments) } +#[must_use] pub fn initial_state_testnet() -> V02State { let mut state = initial_state(); @@ -223,7 +229,7 @@ pub fn initial_state_testnet() -> V02State { #[cfg(test)] mod tests { - use std::str::FromStr; + use std::str::FromStr as _; use super::*; @@ -234,7 +240,7 @@ mod tests { const PRIV_ACC_B_TEXT_ADDR: &str = "E8HwiTyQe4H9HK7icTvn95HQMnzx49mP9A2ddtMLpNaN"; #[test] - fn test_pub_state_consistency() { + fn pub_state_consistency() { let init_accs_private_data = initial_pub_accounts_private_keys(); let init_accs_pub_data = initial_accounts(); @@ -262,11 +268,11 @@ mod tests { account_id: AccountId::from_str(PUB_ACC_B_TEXT_ADDR).unwrap(), balance: PUB_ACC_B_INITIAL_BALANCE, } - ) + ); } #[test] - fn test_private_state_consistency() { + fn private_state_consistency() { let init_private_accs_keys = initial_priv_accounts_private_keys(); let init_comms = initial_commitments(); @@ -386,6 +392,6 @@ mod tests { nonce: 0, }, } - ) + ); } } diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 7e8343fa..46ee6945 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -43,7 +43,7 @@ pub struct SequencerConfig { pub retry_pending_blocks_timeout: Duration, /// Port to listen. pub port: u16, - /// Sequencer own signing key + /// Sequencer own signing key. pub signing_key: [u8; 32], /// Bedrock configuration options. pub bedrock_config: BedrockConfig, diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 30a63108..5f5653da 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -94,53 +94,50 @@ impl SequencerCore { - info!("Found local database. Loading state and pending blocks from it."); - state - } - None => { - info!( - "No database found when starting the sequencer. Creating a fresh new with the initial data" - ); + let mut state = if let Some(state) = store.get_nssa_state() { + info!("Found local database. Loading state and pending blocks from it."); + state + } else { + info!( + "No database found when starting the sequencer. Creating a fresh new with the initial data" + ); - let initial_commitments: Option> = config - .initial_commitments - .clone() - .map(|initial_commitments| { - initial_commitments - .iter() - .map(|init_comm_data| { - let npk = &init_comm_data.npk; + let initial_commitments: Option> = config + .initial_commitments + .clone() + .map(|initial_commitments| { + initial_commitments + .iter() + .map(|init_comm_data| { + let npk = &init_comm_data.npk; - let mut acc = init_comm_data.account.clone(); + let mut acc = init_comm_data.account.clone(); - acc.program_owner = - nssa::program::Program::authenticated_transfer_program().id(); + acc.program_owner = + nssa::program::Program::authenticated_transfer_program().id(); - nssa_core::Commitment::new(npk, &acc) - }) - .collect() - }); + nssa_core::Commitment::new(npk, &acc) + }) + .collect() + }); - let init_accs: Option> = - config.initial_accounts.clone().map(|initial_accounts| { - initial_accounts - .iter() - .map(|acc_data| (acc_data.account_id, acc_data.balance)) - .collect() - }); + let init_accs: Option> = + config.initial_accounts.clone().map(|initial_accounts| { + initial_accounts + .iter() + .map(|acc_data| (acc_data.account_id, acc_data.balance)) + .collect() + }); - // If initial commitments or accounts are present in config, need to construct state - // from them - if initial_commitments.is_some() || init_accs.is_some() { - V02State::new_with_genesis_accounts( - &init_accs.unwrap_or_default(), - &initial_commitments.unwrap_or_default(), - ) - } else { - initial_state() - } + // If initial commitments or accounts are present in config, need to construct state + // from them + if initial_commitments.is_some() || init_accs.is_some() { + V02State::new_with_genesis_accounts( + &init_accs.unwrap_or_default(), + &initial_commitments.unwrap_or_default(), + ) + } else { + initial_state() } }; @@ -485,7 +482,7 @@ mod tests { } #[tokio::test] - async fn test_transaction_pre_check_native_transfer_valid() { + async fn transaction_pre_check_native_transfer_valid() { let (_sequencer, _mempool_handle) = common_setup().await; let acc1 = initial_accounts()[0].account_id; diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index 443eb6f8..ce27e3f7 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -197,7 +197,8 @@ impl JsonHandler /// Returns the initial accounts for testnet. /// `ToDo`: Useful only for testnet and needs to be removed later. - async fn get_initial_testnet_accounts(&self, request: Request) -> Result { + #[expect(clippy::unused_self, reason = "Let all methods be uniform")] + fn get_initial_testnet_accounts(&self, request: Request) -> Result { let _get_initial_testnet_accounts_request = GetInitialTestnetAccountsRequest::parse(Some(request.params))?; @@ -320,7 +321,7 @@ impl JsonHandler GET_BLOCK_RANGE => self.process_get_block_range_data(request).await, GET_GENESIS => self.process_get_genesis(request).await, GET_LAST_BLOCK => self.process_get_last_block(request).await, - GET_INITIAL_TESTNET_ACCOUNTS => self.get_initial_testnet_accounts(request).await, + GET_INITIAL_TESTNET_ACCOUNTS => self.get_initial_testnet_accounts(request), GET_ACCOUNT_BALANCE => self.process_get_account_balance(request).await, GET_ACCOUNTS_NONCES => self.process_get_accounts_nonces(request).await, GET_ACCOUNT => self.process_get_account(request).await, diff --git a/wallet/src/config.rs b/wallet/src/config.rs index 6774044b..146b1a21 100644 --- a/wallet/src/config.rs +++ b/wallet/src/config.rs @@ -41,10 +41,18 @@ pub struct PersistentAccountDataPrivate { #[derive(Debug, Clone, Serialize, Deserialize)] pub enum InitialAccountData { Public(PublicAccountPrivateInitialData), - Private(PrivateAccountPrivateInitialData), + Private(Box), } impl InitialAccountData { + #[must_use] + pub const fn account_id(&self) -> nssa::AccountId { + match &self { + Self::Public(acc) => acc.account_id, + Self::Private(acc) => acc.account_id, + } + } + pub(crate) fn create_initial_accounts_data() -> Vec { let pub_data = initial_pub_accounts_private_keys(); let priv_data = initial_priv_accounts_private_keys(); @@ -117,16 +125,6 @@ impl PersistentStorage { } } -impl InitialAccountData { - #[must_use] - pub fn account_id(&self) -> nssa::AccountId { - match &self { - Self::Public(acc) => acc.account_id, - Self::Private(acc) => acc.account_id, - } - } -} - impl PersistentAccountData { #[must_use] pub fn account_id(&self) -> nssa::AccountId { @@ -146,7 +144,7 @@ impl From for InitialAccountData { impl From for InitialAccountData { fn from(value: PrivateAccountPrivateInitialData) -> Self { - Self::Private(value) + Self::Private(Box::new(value)) } } diff --git a/wallet/src/helperfunctions.rs b/wallet/src/helperfunctions.rs index 02e85fd7..ceeb467f 100644 --- a/wallet/src/helperfunctions.rs +++ b/wallet/src/helperfunctions.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, path::PathBuf, str::FromStr as _}; -use anyhow::{Context, Result}; -use base58::ToBase58; +use anyhow::{Context as _, Result}; +use base58::ToBase58 as _; use key_protocol::{ initial_state::{PrivateAccountPrivateInitialData, PublicAccountPrivateInitialData}, key_protocol_core::NSSAUserData, @@ -132,11 +132,11 @@ pub fn produce_data_for_storage( for (account_id, (key_chain, account)) in &user_data.default_user_private_accounts { vec_for_storage.push( - InitialAccountData::Private(PrivateAccountPrivateInitialData { + InitialAccountData::Private(Box::new(PrivateAccountPrivateInitialData { account_id: *account_id, account: account.clone(), key_chain: key_chain.clone(), - }) + })) .into(), ); } From 2c9361c6b51f61d9c07f2e7b87a3c1530d3a3b33 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 19 Mar 2026 13:01:43 +0200 Subject: [PATCH 6/9] fix: suggestions 1 --- indexer/core/src/config.rs | 4 ++-- indexer/core/src/lib.rs | 8 +++++--- integration_tests/src/config.rs | 12 ++++++------ sequencer_core/src/config.rs | 4 ++-- sequencer_core/src/lib.rs | 12 +++++++----- sequencer_rpc/src/process.rs | 4 ++-- 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/indexer/core/src/config.rs b/indexer/core/src/config.rs index 5eb8dd92..fced57d9 100644 --- a/indexer/core/src/config.rs +++ b/indexer/core/src/config.rs @@ -36,9 +36,9 @@ pub struct IndexerConfig { pub bedrock_client_config: ClientConfig, pub channel_id: ChannelId, #[serde(skip_serializing_if = "Option::is_none")] - pub initial_accounts: Option>, + pub initial_public_accounts: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub initial_commitments: Option>, + pub initial_private_accounts: Option>, } impl IndexerConfig { diff --git a/indexer/core/src/lib.rs b/indexer/core/src/lib.rs index 1f20e822..ca17bd64 100644 --- a/indexer/core/src/lib.rs +++ b/indexer/core/src/lib.rs @@ -58,7 +58,7 @@ impl IndexerCore { let genesis_block = hashable_data.into_pending_block(&signing_key, channel_genesis_msg_id); let initial_commitments: Option> = config - .initial_commitments + .initial_private_accounts .clone() .map(|initial_commitments| { initial_commitments @@ -76,8 +76,10 @@ impl IndexerCore { .collect() }); - let init_accs: Option> = - config.initial_accounts.clone().map(|initial_accounts| { + let init_accs: Option> = config + .initial_public_accounts + .clone() + .map(|initial_accounts| { initial_accounts .iter() .map(|acc_data| (acc_data.account_id, acc_data.balance)) diff --git a/integration_tests/src/config.rs b/integration_tests/src/config.rs index 875e1652..98181d26 100644 --- a/integration_tests/src/config.rs +++ b/integration_tests/src/config.rs @@ -105,7 +105,7 @@ impl InitialData { } } - fn sequencer_initial_accounts(&self) -> Vec { + fn sequencer_initial_public_accounts(&self) -> Vec { self.public_accounts .iter() .map(|(priv_key, balance)| { @@ -119,7 +119,7 @@ impl InitialData { .collect() } - fn sequencer_initial_commitments(&self) -> Vec { + fn sequencer_initial_private_accounts(&self) -> Vec { self.private_accounts .iter() .map(|(key_chain, account)| PrivateAccountPublicInitialData { @@ -184,8 +184,8 @@ pub fn indexer_config( max_retries: 10, }, }, - initial_accounts: Some(initial_data.sequencer_initial_accounts()), - initial_commitments: Some(initial_data.sequencer_initial_commitments()), + initial_public_accounts: Some(initial_data.sequencer_initial_public_accounts()), + initial_private_accounts: Some(initial_data.sequencer_initial_private_accounts()), signing_key: [37; 32], channel_id: bedrock_channel_id(), }) @@ -216,8 +216,8 @@ pub fn sequencer_config( block_create_timeout, retry_pending_blocks_timeout: Duration::from_secs(120), port: 0, - initial_accounts: Some(initial_data.sequencer_initial_accounts()), - initial_commitments: Some(initial_data.sequencer_initial_commitments()), + initial_public_accounts: Some(initial_data.sequencer_initial_public_accounts()), + initial_private_accounts: Some(initial_data.sequencer_initial_private_accounts()), signing_key: [37; 32], bedrock_config: BedrockConfig { backoff: BackoffConfig { diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 46ee6945..571ead1a 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -50,9 +50,9 @@ pub struct SequencerConfig { /// Indexer RPC URL. pub indexer_rpc_url: Url, #[serde(skip_serializing_if = "Option::is_none")] - pub initial_accounts: Option>, + pub initial_public_accounts: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub initial_commitments: Option>, + pub initial_private_accounts: Option>, } #[derive(Clone, Serialize, Deserialize)] diff --git a/sequencer_core/src/lib.rs b/sequencer_core/src/lib.rs index 5f5653da..22a388dd 100644 --- a/sequencer_core/src/lib.rs +++ b/sequencer_core/src/lib.rs @@ -103,7 +103,7 @@ impl SequencerCore> = config - .initial_commitments + .initial_private_accounts .clone() .map(|initial_commitments| { initial_commitments @@ -121,8 +121,10 @@ impl SequencerCore> = - config.initial_accounts.clone().map(|initial_accounts| { + let init_accs: Option> = config + .initial_public_accounts + .clone() + .map(|initial_accounts| { initial_accounts .iter() .map(|acc_data| (acc_data.account_id, acc_data.balance)) @@ -419,8 +421,8 @@ mod tests { }, retry_pending_blocks_timeout: Duration::from_secs(60 * 4), indexer_rpc_url: "ws://localhost:8779".parse().unwrap(), - initial_accounts: None, - initial_commitments: None, + initial_public_accounts: None, + initial_private_accounts: None, } } diff --git a/sequencer_rpc/src/process.rs b/sequencer_rpc/src/process.rs index ce27e3f7..d662dacd 100644 --- a/sequencer_rpc/src/process.rs +++ b/sequencer_rpc/src/process.rs @@ -385,8 +385,8 @@ mod tests { }), }, indexer_rpc_url: "ws://localhost:8779".parse().unwrap(), - initial_accounts: None, - initial_commitments: None, + initial_public_accounts: None, + initial_private_accounts: None, } } From afa0a63c955fbde4603921e823bcc48d8499ea7e Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 19 Mar 2026 18:01:15 +0200 Subject: [PATCH 7/9] 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, From e6cb4ecf9444ed8fd2b90c039836a2c345d4e49d Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Thu, 19 Mar 2026 19:47:47 +0200 Subject: [PATCH 8/9] fix: machete fix --- Cargo.lock | 3 --- indexer/core/Cargo.toml | 1 - sequencer_core/Cargo.toml | 1 - sequencer_rpc/Cargo.toml | 1 - 4 files changed, 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43a1264f..1dba023f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3707,7 +3707,6 @@ dependencies = [ "common", "futures", "humantime-serde", - "key_protocol", "log", "logos-blockchain-core", "nssa", @@ -7439,7 +7438,6 @@ dependencies = [ "futures", "humantime-serde", "jsonrpsee", - "key_protocol", "log", "logos-blockchain-core", "logos-blockchain-key-management-system-service", @@ -7471,7 +7469,6 @@ dependencies = [ "futures", "hex", "itertools 0.14.0", - "key_protocol", "log", "mempool", "nssa", diff --git a/indexer/core/Cargo.toml b/indexer/core/Cargo.toml index 2d7ec258..33fe2d9d 100644 --- a/indexer/core/Cargo.toml +++ b/indexer/core/Cargo.toml @@ -13,7 +13,6 @@ bedrock_client.workspace = true nssa.workspace = true nssa_core.workspace = true storage.workspace = true -key_protocol.workspace = true testnet_initial_state.workspace = true anyhow.workspace = true diff --git a/sequencer_core/Cargo.toml b/sequencer_core/Cargo.toml index 3801945f..e1ff0895 100644 --- a/sequencer_core/Cargo.toml +++ b/sequencer_core/Cargo.toml @@ -14,7 +14,6 @@ common.workspace = true storage.workspace = true mempool.workspace = true bedrock_client.workspace = true -key_protocol.workspace = true testnet_initial_state.workspace = true anyhow.workspace = true diff --git a/sequencer_rpc/Cargo.toml b/sequencer_rpc/Cargo.toml index f6da68e8..afab1a89 100644 --- a/sequencer_rpc/Cargo.toml +++ b/sequencer_rpc/Cargo.toml @@ -13,7 +13,6 @@ common.workspace = true mempool.workspace = true sequencer_core = { workspace = true } bedrock_client.workspace = true -key_protocol.workspace = true testnet_initial_state.workspace = true anyhow.workspace = true From ce136348e7a746a28b1e9380848aef1c88ac1593 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Mon, 23 Mar 2026 19:22:56 +0200 Subject: [PATCH 9/9] fix: deny fix --- Cargo.lock | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9f6e2154..6102fb5d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,7 +162,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -173,7 +173,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -629,9 +629,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" [[package]] name = "astral-tokio-tar" -version = "0.5.6" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec179a06c1769b1e42e1e2cbe74c7dcdb3d6383c838454d063eaac5bbb7ebbe5" +checksum = "3c23f3af104b40a3430ccb90ed5f7bd877a8dc5c26fc92fde51a22b40890dcf9" dependencies = [ "filetime", "futures-core", @@ -1938,7 +1938,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ab67060fc6b8ef687992d439ca0fa36e7ed17e9a0b16b25b601e8757df720de" dependencies = [ "data-encoding", - "syn 2.0.117", + "syn 1.0.109", ] [[package]] @@ -2087,7 +2087,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -2388,7 +2388,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5931,7 +5931,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" dependencies = [ "anyhow", - "itertools 0.14.0", + "itertools 0.10.5", "proc-macro2", "quote", "syn 2.0.117", @@ -5944,7 +5944,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27c6023962132f4b30eb4c172c91ce92d933da334c59c23cddee82358ddafb0b" dependencies = [ "anyhow", - "itertools 0.14.0", + "itertools 0.10.5", "proc-macro2", "quote", "syn 2.0.117", @@ -6862,7 +6862,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -6931,9 +6931,9 @@ checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" [[package]] name = "rustls-webpki" -version = "0.103.9" +version = "0.103.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +checksum = "df33b2b81ac578cabaf06b89b0631153a3f416b0a886e8a7a1707fb51abbd1ef" dependencies = [ "ring", "rustls-pki-types", @@ -7539,7 +7539,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.60.2", ] [[package]] @@ -7790,7 +7790,7 @@ dependencies = [ "getrandom 0.4.2", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -7843,9 +7843,9 @@ dependencies = [ [[package]] name = "testcontainers" -version = "0.27.1" +version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c0624faaa317c56d6d19136580be889677259caf5c897941c6f446b4655068" +checksum = "0bd36b06a2a6c0c3c81a83be1ab05fe86460d054d4d51bf513bc56b3e15bdc22" dependencies = [ "astral-tokio-tar", "async-trait", @@ -8954,7 +8954,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]]