mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-03-24 19:23:22 +00:00
fix: integartion tests fix
This commit is contained in:
parent
02953999aa
commit
a9a0c386ad
@ -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<Vec<PublicAccountPublicInitialData>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub initial_commitments: Option<Vec<PrivateAccountPublicInitialData>>,
|
||||
}
|
||||
|
||||
impl IndexerConfig {
|
||||
|
||||
@ -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<Vec<nssa_core::Commitment>> = 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<Vec<(nssa::AccountId, u128)>> =
|
||||
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");
|
||||
|
||||
|
||||
@ -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<AccountInitialData> {
|
||||
fn sequencer_initial_accounts(&self) -> Vec<PublicAccountPublicInitialData> {
|
||||
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<CommitmentsInitialData> {
|
||||
fn sequencer_initial_commitments(&self) -> Vec<PrivateAccountPublicInitialData> {
|
||||
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(),
|
||||
|
||||
@ -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<Vec<PublicAccountPublicInitialData>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub initial_commitments: Option<Vec<PrivateAccountPublicInitialData>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
|
||||
@ -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<BC: BlockSettlementClientTrait, IC: IndexerClientTrait> SequencerCore<BC, I
|
||||
info!(
|
||||
"No database found when starting the sequencer. Creating a fresh new with the initial data"
|
||||
);
|
||||
initial_state()
|
||||
|
||||
let initial_commitments: Option<Vec<nssa_core::Commitment>> = 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<Vec<(nssa::AccountId, u128)>> =
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -385,6 +385,8 @@ mod tests {
|
||||
}),
|
||||
},
|
||||
indexer_rpc_url: "ws://localhost:8779".parse().unwrap(),
|
||||
initial_accounts: None,
|
||||
initial_commitments: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -201,6 +201,8 @@ pub struct WalletConfig {
|
||||
/// Basic authentication credentials
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub basic_auth: Option<BasicAuth>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub initial_accounts: Option<Vec<InitialAccountData>>,
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user