mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-18 05:59:33 +00:00
fix: integration updates
This commit is contained in:
parent
b6a0e62871
commit
c2e09031e1
489
Cargo.lock
generated
489
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,6 @@
|
|||||||
use nomos_core::mantle::ops::channel::ChannelId;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct IndexerConfig {
|
pub struct IndexerConfig {
|
||||||
pub resubscribe_interval: u64,
|
pub resubscribe_interval: u64,
|
||||||
pub channel_id: ChannelId,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,29 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bedrock_client::{BasicAuthCredentials, BedrockClient};
|
use bedrock_client::{BasicAuthCredentials, BedrockClient};
|
||||||
use common::block::{BlockHash, HashableBlockData};
|
use common::block::HashableBlockData;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use log::info;
|
use log::info;
|
||||||
use nomos_core::mantle::{
|
use nomos_core::mantle::{
|
||||||
Op, SignedMantleTx,
|
Op, SignedMantleTx,
|
||||||
ops::channel::{ChannelId, inscribe::InscriptionOp},
|
ops::channel::{ChannelId, inscribe::InscriptionOp},
|
||||||
};
|
};
|
||||||
use tokio::sync::mpsc::Sender;
|
use tokio::sync::{RwLock, mpsc::Sender};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::{config::IndexerConfig, state::IndexerState};
|
use crate::{config::IndexerConfig, message::IndexerToSequencerMessage, state::IndexerState};
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
pub mod message;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
|
|
||||||
pub struct IndexerCore {
|
pub struct IndexerCore {
|
||||||
pub bedrock_client: BedrockClient,
|
pub bedrock_client: BedrockClient,
|
||||||
pub bedrock_url: Url,
|
pub channel_sender: Sender<IndexerToSequencerMessage>,
|
||||||
pub channel_sender: Sender<BlockHash>,
|
|
||||||
pub config: IndexerConfig,
|
pub config: IndexerConfig,
|
||||||
|
pub bedrock_url: Url,
|
||||||
|
pub channel_id: ChannelId,
|
||||||
pub state: IndexerState,
|
pub state: IndexerState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,17 +31,19 @@ impl IndexerCore {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
addr: &str,
|
addr: &str,
|
||||||
auth: Option<BasicAuthCredentials>,
|
auth: Option<BasicAuthCredentials>,
|
||||||
sender: Sender<BlockHash>,
|
sender: Sender<IndexerToSequencerMessage>,
|
||||||
config: IndexerConfig,
|
config: IndexerConfig,
|
||||||
|
channel_id: ChannelId,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
bedrock_client: BedrockClient::new(auth)?,
|
bedrock_client: BedrockClient::new(auth)?,
|
||||||
bedrock_url: Url::parse(addr)?,
|
bedrock_url: Url::parse(addr)?,
|
||||||
channel_sender: sender,
|
channel_sender: sender,
|
||||||
config,
|
config,
|
||||||
|
channel_id,
|
||||||
// No state setup for now, future task.
|
// No state setup for now, future task.
|
||||||
state: IndexerState {
|
state: IndexerState {
|
||||||
latest_seen_block: 0,
|
latest_seen_block: Arc::new(RwLock::new(0)),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -63,16 +69,29 @@ impl IndexerCore {
|
|||||||
.get_block_by_id(self.bedrock_url.clone(), header_id)
|
.get_block_by_id(self.bedrock_url.clone(), header_id)
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
info!("Extracted L1 block at height {} with data {l1_block:#?}", block_info.height);
|
info!("Extracted L1 block at height {}", block_info.height);
|
||||||
|
|
||||||
let l2_blocks_parsed = parse_blocks(
|
let l2_blocks_parsed =
|
||||||
l1_block.into_transactions().into_iter(),
|
parse_blocks(l1_block.into_transactions().into_iter(), &self.channel_id);
|
||||||
&self.config.channel_id,
|
|
||||||
);
|
|
||||||
|
|
||||||
for l2_block in l2_blocks_parsed {
|
for l2_block in l2_blocks_parsed {
|
||||||
|
// State modification, will be updated in future
|
||||||
|
{
|
||||||
|
let mut guard = self.state.latest_seen_block.write().await;
|
||||||
|
if l2_block.block_id > *guard {
|
||||||
|
*guard = l2_block.block_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sending data into sequencer, may need to be expanded.
|
// Sending data into sequencer, may need to be expanded.
|
||||||
self.channel_sender.send(l2_block.block_hash()).await?;
|
let message = IndexerToSequencerMessage::BlockObserved {
|
||||||
|
l1_block_id: block_info.height,
|
||||||
|
l2_block_height: l2_block.block_id,
|
||||||
|
};
|
||||||
|
|
||||||
|
self.channel_sender.send(message.clone()).await?;
|
||||||
|
|
||||||
|
info!("Sent message {:#?} to sequencer", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +115,6 @@ pub fn parse_blocks(
|
|||||||
inscription,
|
inscription,
|
||||||
..
|
..
|
||||||
}) if channel_id == decoded_channel_id => {
|
}) if channel_id == decoded_channel_id => {
|
||||||
// Assuming, that it is how block will be inscribed on l1
|
|
||||||
borsh::from_slice::<HashableBlockData>(inscription).ok()
|
borsh::from_slice::<HashableBlockData>(inscription).ok()
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
7
indexer/src/message.rs
Normal file
7
indexer/src/message.rs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum IndexerToSequencerMessage {
|
||||||
|
BlockObserved {
|
||||||
|
l1_block_id: u64,
|
||||||
|
l2_block_height: u64,
|
||||||
|
},
|
||||||
|
}
|
||||||
@ -1,5 +1,9 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct IndexerState {
|
pub struct IndexerState {
|
||||||
// Only one field for now, for testing.
|
// Only one field for now, for testing.
|
||||||
pub latest_seen_block: u64,
|
pub latest_seen_block: Arc<RwLock<u64>>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -155,13 +155,13 @@
|
|||||||
37,
|
37,
|
||||||
37
|
37
|
||||||
],
|
],
|
||||||
"bedrock_addr": "http://127.0.0.1:8080",
|
"bedrock_config": {
|
||||||
"bedrock_auth": [
|
"channel_id": "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a",
|
||||||
"user",
|
"node_url": "http://127.0.0.1:8080",
|
||||||
"password"
|
"user": "user",
|
||||||
],
|
"password": null,
|
||||||
"indexer_config": {
|
"indexer_config": {
|
||||||
"resubscribe_interval": 1000,
|
"resubscribe_interval": 1000
|
||||||
"channel_id": "2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a2a"
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,158 @@
|
|||||||
|
{
|
||||||
|
"home": "",
|
||||||
|
"override_rust_log": null,
|
||||||
|
"genesis_id": 1,
|
||||||
|
"is_genesis_random": true,
|
||||||
|
"max_num_tx_in_block": 20,
|
||||||
|
"mempool_max_size": 10000,
|
||||||
|
"block_create_timeout_millis": 10000,
|
||||||
|
"port": 0,
|
||||||
|
"initial_accounts": [
|
||||||
|
{
|
||||||
|
"account_id": "BLgCRDXYdQPMMWVHYRFGQZbgeHx9frkipa8GtpG2Syqy",
|
||||||
|
"balance": 10000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"account_id": "Gj1mJy5W7J5pfmLRujmQaLfLMWidNxQ6uwnhb666ZwHw",
|
||||||
|
"balance": 20000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"initial_commitments": [
|
||||||
|
{
|
||||||
|
"npk": [
|
||||||
|
63,
|
||||||
|
202,
|
||||||
|
178,
|
||||||
|
231,
|
||||||
|
183,
|
||||||
|
82,
|
||||||
|
237,
|
||||||
|
212,
|
||||||
|
216,
|
||||||
|
221,
|
||||||
|
215,
|
||||||
|
255,
|
||||||
|
153,
|
||||||
|
101,
|
||||||
|
177,
|
||||||
|
161,
|
||||||
|
254,
|
||||||
|
210,
|
||||||
|
128,
|
||||||
|
122,
|
||||||
|
54,
|
||||||
|
190,
|
||||||
|
230,
|
||||||
|
151,
|
||||||
|
183,
|
||||||
|
64,
|
||||||
|
225,
|
||||||
|
229,
|
||||||
|
113,
|
||||||
|
1,
|
||||||
|
228,
|
||||||
|
97
|
||||||
|
],
|
||||||
|
"account": {
|
||||||
|
"program_owner": [
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"balance": 10000,
|
||||||
|
"data": [],
|
||||||
|
"nonce": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"npk": [
|
||||||
|
192,
|
||||||
|
251,
|
||||||
|
166,
|
||||||
|
243,
|
||||||
|
167,
|
||||||
|
236,
|
||||||
|
84,
|
||||||
|
249,
|
||||||
|
35,
|
||||||
|
136,
|
||||||
|
130,
|
||||||
|
172,
|
||||||
|
219,
|
||||||
|
225,
|
||||||
|
161,
|
||||||
|
139,
|
||||||
|
229,
|
||||||
|
89,
|
||||||
|
243,
|
||||||
|
125,
|
||||||
|
194,
|
||||||
|
213,
|
||||||
|
209,
|
||||||
|
30,
|
||||||
|
23,
|
||||||
|
174,
|
||||||
|
100,
|
||||||
|
244,
|
||||||
|
124,
|
||||||
|
74,
|
||||||
|
140,
|
||||||
|
47
|
||||||
|
],
|
||||||
|
"account": {
|
||||||
|
"program_owner": [
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
],
|
||||||
|
"balance": 20000,
|
||||||
|
"data": [],
|
||||||
|
"nonce": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"signing_key": [
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37,
|
||||||
|
37
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -38,7 +38,7 @@ static LOGGER: LazyLock<()> = LazyLock::new(env_logger::init);
|
|||||||
pub struct TestContext {
|
pub struct TestContext {
|
||||||
sequencer_server_handle: ServerHandle,
|
sequencer_server_handle: ServerHandle,
|
||||||
sequencer_loop_handle: JoinHandle<Result<()>>,
|
sequencer_loop_handle: JoinHandle<Result<()>>,
|
||||||
indexer_loop_handle: JoinHandle<Result<()>>,
|
indexer_loop_handle: Option<JoinHandle<Result<()>>>,
|
||||||
sequencer_client: SequencerClient,
|
sequencer_client: SequencerClient,
|
||||||
wallet: WalletCore,
|
wallet: WalletCore,
|
||||||
_temp_sequencer_dir: TempDir,
|
_temp_sequencer_dir: TempDir,
|
||||||
@ -46,12 +46,25 @@ pub struct TestContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TestContext {
|
impl TestContext {
|
||||||
/// Create new test context.
|
/// Create new test context in detached mode. Default.
|
||||||
pub async fn new() -> Result<Self> {
|
pub async fn new() -> Result<Self> {
|
||||||
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||||
|
|
||||||
let sequencer_config_path =
|
let sequencer_config_path =
|
||||||
PathBuf::from(manifest_dir).join("configs/sequencer/sequencer_config.json");
|
PathBuf::from(manifest_dir).join("configs/sequencer/detached/sequencer_config.json");
|
||||||
|
|
||||||
|
let sequencer_config = SequencerConfig::from_path(&sequencer_config_path)
|
||||||
|
.context("Failed to create sequencer config from file")?;
|
||||||
|
|
||||||
|
Self::new_with_sequencer_config(sequencer_config).await
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create new test context in local bedrock node attached mode.
|
||||||
|
pub async fn new_bedrock_local_attached() -> Result<Self> {
|
||||||
|
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
||||||
|
|
||||||
|
let sequencer_config_path = PathBuf::from(manifest_dir)
|
||||||
|
.join("configs/sequencer/bedrock_local_attached/sequencer_config.json");
|
||||||
|
|
||||||
let sequencer_config = SequencerConfig::from_path(&sequencer_config_path)
|
let sequencer_config = SequencerConfig::from_path(&sequencer_config_path)
|
||||||
.context("Failed to create sequencer config from file")?;
|
.context("Failed to create sequencer config from file")?;
|
||||||
@ -69,10 +82,15 @@ impl TestContext {
|
|||||||
|
|
||||||
debug!("Test context setup");
|
debug!("Test context setup");
|
||||||
|
|
||||||
let (sequencer_server_handle, sequencer_addr, sequencer_loop_handle, temp_sequencer_dir, indexer_loop_handle) =
|
let (
|
||||||
Self::setup_sequencer(sequencer_config)
|
sequencer_server_handle,
|
||||||
.await
|
sequencer_addr,
|
||||||
.context("Failed to setup sequencer")?;
|
sequencer_loop_handle,
|
||||||
|
temp_sequencer_dir,
|
||||||
|
indexer_loop_handle,
|
||||||
|
) = Self::setup_sequencer(sequencer_config)
|
||||||
|
.await
|
||||||
|
.context("Failed to setup sequencer")?;
|
||||||
|
|
||||||
// Convert 0.0.0.0 to 127.0.0.1 for client connections
|
// Convert 0.0.0.0 to 127.0.0.1 for client connections
|
||||||
// When binding to port 0, the server binds to 0.0.0.0:<random_port>
|
// When binding to port 0, the server binds to 0.0.0.0:<random_port>
|
||||||
@ -103,7 +121,13 @@ impl TestContext {
|
|||||||
|
|
||||||
async fn setup_sequencer(
|
async fn setup_sequencer(
|
||||||
mut config: SequencerConfig,
|
mut config: SequencerConfig,
|
||||||
) -> Result<(ServerHandle, SocketAddr, JoinHandle<Result<()>>, TempDir, JoinHandle<Result<()>>)> {
|
) -> Result<(
|
||||||
|
ServerHandle,
|
||||||
|
SocketAddr,
|
||||||
|
JoinHandle<Result<()>>,
|
||||||
|
TempDir,
|
||||||
|
Option<JoinHandle<Result<()>>>,
|
||||||
|
)> {
|
||||||
let temp_sequencer_dir =
|
let temp_sequencer_dir =
|
||||||
tempfile::tempdir().context("Failed to create temp dir for sequencer home")?;
|
tempfile::tempdir().context("Failed to create temp dir for sequencer home")?;
|
||||||
|
|
||||||
@ -123,7 +147,7 @@ impl TestContext {
|
|||||||
sequencer_addr,
|
sequencer_addr,
|
||||||
sequencer_loop_handle,
|
sequencer_loop_handle,
|
||||||
temp_sequencer_dir,
|
temp_sequencer_dir,
|
||||||
indexer_loop_handle
|
indexer_loop_handle,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +215,12 @@ impl Drop for TestContext {
|
|||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
sequencer_loop_handle.abort();
|
sequencer_loop_handle.abort();
|
||||||
indexer_loop_handle.abort();
|
match indexer_loop_handle {
|
||||||
|
Some(handle) => {
|
||||||
|
handle.abort();
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
};
|
||||||
|
|
||||||
// Can't wait here as Drop can't be async, but anyway stop signal should be sent
|
// Can't wait here as Drop can't be async, but anyway stop signal should be sent
|
||||||
sequencer_server_handle.stop(true).now_or_never();
|
sequencer_server_handle.stop(true).now_or_never();
|
||||||
|
|||||||
@ -6,17 +6,17 @@ use tokio::test;
|
|||||||
#[test]
|
#[test]
|
||||||
async fn indexer_run_local_node() -> Result<()> {
|
async fn indexer_run_local_node() -> Result<()> {
|
||||||
println!("Waiting 20 seconds for L1 node to start producing");
|
println!("Waiting 20 seconds for L1 node to start producing");
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(20)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
|
||||||
|
|
||||||
let ctx = TestContext::new().await?;
|
let ctx = TestContext::new_bedrock_local_attached().await?;
|
||||||
|
|
||||||
info!("Let's observe behaviour");
|
info!("Let's observe behaviour");
|
||||||
|
|
||||||
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
|
tokio::time::sleep(std::time::Duration::from_secs(300)).await;
|
||||||
|
|
||||||
let gen_id = ctx.sequencer_client().get_genesis_id().await.unwrap();
|
let gen_id = ctx.sequencer_client().get_genesis_id().await.unwrap();
|
||||||
|
|
||||||
info!("btw, gen id is {gen_id:?}");
|
info!("btw, gen id is {gen_id:?}");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use indexer::config::IndexerConfig;
|
|
||||||
use integration_tests::TestContext;
|
use integration_tests::TestContext;
|
||||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||||
use log::info;
|
use log::info;
|
||||||
@ -186,12 +185,6 @@ impl TpsTestManager {
|
|||||||
initial_accounts: initial_public_accounts,
|
initial_accounts: initial_public_accounts,
|
||||||
initial_commitments: vec![initial_commitment],
|
initial_commitments: vec![initial_commitment],
|
||||||
signing_key: [37; 32],
|
signing_key: [37; 32],
|
||||||
bedrock_addr: "0.0.0.0".to_string(),
|
|
||||||
bedrock_auth: ("".to_string(), "".to_string()),
|
|
||||||
indexer_config: IndexerConfig {
|
|
||||||
resubscribe_interval: 100,
|
|
||||||
channel_id: [42; 32].into(),
|
|
||||||
},
|
|
||||||
bedrock_config: None,
|
bedrock_config: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ use std::{
|
|||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use indexer::config::IndexerConfig;
|
use indexer::config::IndexerConfig;
|
||||||
|
use nomos_core::mantle::ops::channel::ChannelId;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
@ -48,12 +49,6 @@ pub struct SequencerConfig {
|
|||||||
pub initial_commitments: Vec<CommitmentsInitialData>,
|
pub initial_commitments: Vec<CommitmentsInitialData>,
|
||||||
/// Sequencer own signing key
|
/// Sequencer own signing key
|
||||||
pub signing_key: [u8; 32],
|
pub signing_key: [u8; 32],
|
||||||
/// Bedrock addr
|
|
||||||
pub bedrock_addr: String,
|
|
||||||
/// Bedrock auth
|
|
||||||
pub bedrock_auth: (String, String),
|
|
||||||
/// Indexer config
|
|
||||||
pub indexer_config: IndexerConfig,
|
|
||||||
/// Bedrock configuration options
|
/// Bedrock configuration options
|
||||||
pub bedrock_config: Option<BedrockConfig>,
|
pub bedrock_config: Option<BedrockConfig>,
|
||||||
}
|
}
|
||||||
@ -61,9 +56,15 @@ pub struct SequencerConfig {
|
|||||||
#[derive(Clone, Serialize, Deserialize)]
|
#[derive(Clone, Serialize, Deserialize)]
|
||||||
pub struct BedrockConfig {
|
pub struct BedrockConfig {
|
||||||
/// Bedrock channel ID
|
/// Bedrock channel ID
|
||||||
pub channel_id: [u8; 32],
|
pub channel_id: ChannelId,
|
||||||
/// Bedrock Url
|
/// Bedrock Url
|
||||||
pub node_url: String,
|
pub node_url: String,
|
||||||
|
/// Bedrock user
|
||||||
|
pub user: String,
|
||||||
|
/// Bedrock password(optional)
|
||||||
|
pub password: Option<String>,
|
||||||
|
/// Indexer config
|
||||||
|
pub indexer_config: IndexerConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SequencerConfig {
|
impl SequencerConfig {
|
||||||
|
|||||||
@ -5,10 +5,11 @@ use anyhow::Result;
|
|||||||
use common::PINATA_BASE58;
|
use common::PINATA_BASE58;
|
||||||
use common::{
|
use common::{
|
||||||
HashType,
|
HashType,
|
||||||
block::{BlockHash, HashableBlockData},
|
block::HashableBlockData,
|
||||||
transaction::{EncodedTransaction, NSSATransaction},
|
transaction::{EncodedTransaction, NSSATransaction},
|
||||||
};
|
};
|
||||||
use config::SequencerConfig;
|
use config::SequencerConfig;
|
||||||
|
use indexer::message::IndexerToSequencerMessage;
|
||||||
use log::warn;
|
use log::warn;
|
||||||
use mempool::{MemPool, MemPoolHandle};
|
use mempool::{MemPool, MemPoolHandle};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -28,7 +29,7 @@ pub struct SequencerCore {
|
|||||||
chain_height: u64,
|
chain_height: u64,
|
||||||
// No logic here for now
|
// No logic here for now
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
receiver: Receiver<BlockHash>,
|
receiver: Option<Receiver<IndexerToSequencerMessage>>,
|
||||||
block_settlement_client: Option<BlockSettlementClient>,
|
block_settlement_client: Option<BlockSettlementClient>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ impl SequencerCore {
|
|||||||
/// Start Sequencer from configuration and construct transaction sender
|
/// Start Sequencer from configuration and construct transaction sender
|
||||||
pub fn start_from_config(
|
pub fn start_from_config(
|
||||||
config: SequencerConfig,
|
config: SequencerConfig,
|
||||||
receiver: Receiver<BlockHash>,
|
receiver: Option<Receiver<IndexerToSequencerMessage>>,
|
||||||
) -> (Self, MemPoolHandle<EncodedTransaction>) {
|
) -> (Self, MemPoolHandle<EncodedTransaction>) {
|
||||||
let hashable_data = HashableBlockData {
|
let hashable_data = HashableBlockData {
|
||||||
block_id: config.genesis_id,
|
block_id: config.genesis_id,
|
||||||
@ -275,7 +276,6 @@ mod tests {
|
|||||||
|
|
||||||
use base58::{FromBase58, ToBase58};
|
use base58::{FromBase58, ToBase58};
|
||||||
use common::test_utils::sequencer_sign_key_for_testing;
|
use common::test_utils::sequencer_sign_key_for_testing;
|
||||||
use indexer::config::IndexerConfig;
|
|
||||||
use nssa::PrivateKey;
|
use nssa::PrivateKey;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -305,12 +305,6 @@ mod tests {
|
|||||||
initial_accounts,
|
initial_accounts,
|
||||||
initial_commitments: vec![],
|
initial_commitments: vec![],
|
||||||
signing_key: *sequencer_sign_key_for_testing().value(),
|
signing_key: *sequencer_sign_key_for_testing().value(),
|
||||||
bedrock_addr: "0.0.0.0".to_string(),
|
|
||||||
bedrock_auth: ("".to_string(), "".to_string()),
|
|
||||||
indexer_config: IndexerConfig {
|
|
||||||
resubscribe_interval: 100,
|
|
||||||
channel_id: [42; 32].into(),
|
|
||||||
},
|
|
||||||
bedrock_config: None,
|
bedrock_config: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -357,9 +351,7 @@ mod tests {
|
|||||||
async fn common_setup_with_config(
|
async fn common_setup_with_config(
|
||||||
config: SequencerConfig,
|
config: SequencerConfig,
|
||||||
) -> (SequencerCore, MemPoolHandle<EncodedTransaction>) {
|
) -> (SequencerCore, MemPoolHandle<EncodedTransaction>) {
|
||||||
let (_, receiver) = tokio::sync::mpsc::channel(100);
|
let (mut sequencer, mempool_handle) = SequencerCore::start_from_config(config, None);
|
||||||
|
|
||||||
let (mut sequencer, mempool_handle) = SequencerCore::start_from_config(config, receiver);
|
|
||||||
|
|
||||||
let tx = common::test_utils::produce_dummy_empty_transaction();
|
let tx = common::test_utils::produce_dummy_empty_transaction();
|
||||||
mempool_handle.push(tx).await.unwrap();
|
mempool_handle.push(tx).await.unwrap();
|
||||||
@ -374,9 +366,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_start_from_config() {
|
fn test_start_from_config() {
|
||||||
let config = setup_sequencer_config();
|
let config = setup_sequencer_config();
|
||||||
let (_, receiver) = tokio::sync::mpsc::channel(100);
|
let (sequencer, _mempool_handle) = SequencerCore::start_from_config(config.clone(), None);
|
||||||
let (sequencer, _mempool_handle) =
|
|
||||||
SequencerCore::start_from_config(config.clone(), receiver);
|
|
||||||
|
|
||||||
assert_eq!(sequencer.chain_height, config.genesis_id);
|
assert_eq!(sequencer.chain_height, config.genesis_id);
|
||||||
assert_eq!(sequencer.sequencer_config.max_num_tx_in_block, 10);
|
assert_eq!(sequencer.sequencer_config.max_num_tx_in_block, 10);
|
||||||
@ -435,9 +425,7 @@ mod tests {
|
|||||||
let initial_accounts = vec![initial_acc1, initial_acc2];
|
let initial_accounts = vec![initial_acc1, initial_acc2];
|
||||||
|
|
||||||
let config = setup_sequencer_config_variable_initial_accounts(initial_accounts);
|
let config = setup_sequencer_config_variable_initial_accounts(initial_accounts);
|
||||||
let (_, receiver) = tokio::sync::mpsc::channel(100);
|
let (sequencer, _mempool_handle) = SequencerCore::start_from_config(config.clone(), None);
|
||||||
let (sequencer, _mempool_handle) =
|
|
||||||
SequencerCore::start_from_config(config.clone(), receiver);
|
|
||||||
|
|
||||||
let acc1_account_id = config.initial_accounts[0]
|
let acc1_account_id = config.initial_accounts[0]
|
||||||
.account_id
|
.account_id
|
||||||
@ -773,9 +761,8 @@ mod tests {
|
|||||||
// from `acc_1` to `acc_2`. The block created with that transaction will be kept stored in
|
// from `acc_1` to `acc_2`. The block created with that transaction will be kept stored in
|
||||||
// the temporary directory for the block storage of this test.
|
// the temporary directory for the block storage of this test.
|
||||||
{
|
{
|
||||||
let (_, receiver) = tokio::sync::mpsc::channel(100);
|
|
||||||
let (mut sequencer, mempool_handle) =
|
let (mut sequencer, mempool_handle) =
|
||||||
SequencerCore::start_from_config(config.clone(), receiver);
|
SequencerCore::start_from_config(config.clone(), None);
|
||||||
let signing_key = PrivateKey::try_new([1; 32]).unwrap();
|
let signing_key = PrivateKey::try_new([1; 32]).unwrap();
|
||||||
|
|
||||||
let tx = common::test_utils::create_transaction_native_token_transfer(
|
let tx = common::test_utils::create_transaction_native_token_transfer(
|
||||||
@ -800,9 +787,7 @@ mod tests {
|
|||||||
|
|
||||||
// Instantiating a new sequencer from the same config. This should load the existing block
|
// Instantiating a new sequencer from the same config. This should load the existing block
|
||||||
// with the above transaction and update the state to reflect that.
|
// with the above transaction and update the state to reflect that.
|
||||||
let (_, receiver) = tokio::sync::mpsc::channel(100);
|
let (sequencer, _mempool_handle) = SequencerCore::start_from_config(config.clone(), None);
|
||||||
let (sequencer, _mempool_handle) =
|
|
||||||
SequencerCore::start_from_config(config.clone(), receiver);
|
|
||||||
let balance_acc_1 = sequencer.state.get_account_by_id(&acc1_account_id).balance;
|
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;
|
let balance_acc_2 = sequencer.state.get_account_by_id(&acc2_account_id).balance;
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ pub struct JsonHandler {
|
|||||||
sequencer_state: Arc<Mutex<SequencerCore>>,
|
sequencer_state: Arc<Mutex<SequencerCore>>,
|
||||||
// No functionality for now.
|
// No functionality for now.
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
indexer_state: Arc<Mutex<IndexerCore>>,
|
indexer_state: Option<Arc<Mutex<IndexerCore>>>,
|
||||||
mempool_handle: MemPoolHandle<EncodedTransaction>,
|
mempool_handle: MemPoolHandle<EncodedTransaction>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ pub fn new_http_server(
|
|||||||
config: RpcConfig,
|
config: RpcConfig,
|
||||||
seuquencer_core: Arc<Mutex<SequencerCore>>,
|
seuquencer_core: Arc<Mutex<SequencerCore>>,
|
||||||
mempool_handle: MemPoolHandle<EncodedTransaction>,
|
mempool_handle: MemPoolHandle<EncodedTransaction>,
|
||||||
indexer_core: Arc<Mutex<IndexerCore>>,
|
indexer_core: Option<Arc<Mutex<IndexerCore>>>,
|
||||||
) -> io::Result<(actix_web::dev::Server, SocketAddr)> {
|
) -> io::Result<(actix_web::dev::Server, SocketAddr)> {
|
||||||
let RpcConfig {
|
let RpcConfig {
|
||||||
addr,
|
addr,
|
||||||
|
|||||||
@ -345,7 +345,7 @@ mod tests {
|
|||||||
use indexer::{IndexerCore, config::IndexerConfig};
|
use indexer::{IndexerCore, config::IndexerConfig};
|
||||||
use sequencer_core::{
|
use sequencer_core::{
|
||||||
SequencerCore,
|
SequencerCore,
|
||||||
config::{AccountInitialData, SequencerConfig},
|
config::{AccountInitialData, BedrockConfig, SequencerConfig},
|
||||||
};
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
@ -390,31 +390,37 @@ mod tests {
|
|||||||
initial_accounts,
|
initial_accounts,
|
||||||
initial_commitments: vec![],
|
initial_commitments: vec![],
|
||||||
signing_key: *sequencer_sign_key_for_testing().value(),
|
signing_key: *sequencer_sign_key_for_testing().value(),
|
||||||
bedrock_addr: "http://127.0.0.1:8080".to_string(),
|
bedrock_config: Some(BedrockConfig {
|
||||||
bedrock_auth: ("".to_string(), "".to_string()),
|
|
||||||
indexer_config: IndexerConfig {
|
|
||||||
resubscribe_interval: 100,
|
|
||||||
channel_id: [42; 32].into(),
|
channel_id: [42; 32].into(),
|
||||||
},
|
node_url: "http://localhost:8080".to_string(),
|
||||||
bedrock_config: None,
|
user: "user".to_string(),
|
||||||
|
password: None,
|
||||||
|
indexer_config: IndexerConfig {
|
||||||
|
resubscribe_interval: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn components_for_tests() -> (JsonHandler, Vec<AccountInitialData>, EncodedTransaction) {
|
async fn components_for_tests() -> (JsonHandler, Vec<AccountInitialData>, EncodedTransaction) {
|
||||||
let config = sequencer_config_for_tests();
|
let config = sequencer_config_for_tests();
|
||||||
|
let bedrock_config = config.bedrock_config.clone().unwrap();
|
||||||
|
|
||||||
let (sender, receiver) = tokio::sync::mpsc::channel(100);
|
let (sender, receiver) = tokio::sync::mpsc::channel(100);
|
||||||
let indexer_core = IndexerCore::new(
|
let indexer_core = IndexerCore::new(
|
||||||
&config.bedrock_addr,
|
&bedrock_config.node_url,
|
||||||
Some(BasicAuthCredentials::new(
|
Some(BasicAuthCredentials::new(
|
||||||
config.bedrock_auth.0.clone(),
|
bedrock_config.user.clone(),
|
||||||
Some(config.bedrock_auth.1.clone()),
|
bedrock_config.password.clone(),
|
||||||
)),
|
)),
|
||||||
sender,
|
sender,
|
||||||
config.indexer_config.clone(),
|
bedrock_config.indexer_config.clone(),
|
||||||
|
bedrock_config.channel_id.into(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let (mut sequencer_core, mempool_handle) =
|
let (mut sequencer_core, mempool_handle) =
|
||||||
SequencerCore::start_from_config(config, receiver);
|
SequencerCore::start_from_config(config, Some(receiver));
|
||||||
let initial_accounts = sequencer_core.sequencer_config().initial_accounts.clone();
|
let initial_accounts = sequencer_core.sequencer_config().initial_accounts.clone();
|
||||||
|
|
||||||
let signing_key = nssa::PrivateKey::try_new([1; 32]).unwrap();
|
let signing_key = nssa::PrivateKey::try_new([1; 32]).unwrap();
|
||||||
@ -445,7 +451,7 @@ mod tests {
|
|||||||
(
|
(
|
||||||
JsonHandler {
|
JsonHandler {
|
||||||
sequencer_state: sequencer_core,
|
sequencer_state: sequencer_core,
|
||||||
indexer_state: indexer_core,
|
indexer_state: Some(indexer_core),
|
||||||
mempool_handle,
|
mempool_handle,
|
||||||
},
|
},
|
||||||
initial_accounts,
|
initial_accounts,
|
||||||
|
|||||||
@ -22,37 +22,51 @@ struct Args {
|
|||||||
|
|
||||||
pub async fn startup_sequencer(
|
pub async fn startup_sequencer(
|
||||||
app_config: SequencerConfig,
|
app_config: SequencerConfig,
|
||||||
) -> Result<(ServerHandle, SocketAddr, JoinHandle<Result<()>>, JoinHandle<Result<()>>)> {
|
) -> Result<(
|
||||||
|
ServerHandle,
|
||||||
|
SocketAddr,
|
||||||
|
JoinHandle<Result<()>>,
|
||||||
|
Option<JoinHandle<Result<()>>>,
|
||||||
|
)> {
|
||||||
let block_timeout = app_config.block_create_timeout_millis;
|
let block_timeout = app_config.block_create_timeout_millis;
|
||||||
let port = app_config.port;
|
let port = app_config.port;
|
||||||
|
|
||||||
// ToDo: Maybe make buffer size configurable.
|
// ToDo: Maybe make buffer size configurable.
|
||||||
let (sender, receiver) = tokio::sync::mpsc::channel(100);
|
let (indexer_core, receiver) = if let Some(bedrock_config) = app_config.bedrock_config.clone() {
|
||||||
|
let (sender, receiver) = tokio::sync::mpsc::channel(100);
|
||||||
|
|
||||||
let indexer_core = IndexerCore::new(
|
let indexer_core = IndexerCore::new(
|
||||||
&app_config.bedrock_addr,
|
&bedrock_config.node_url,
|
||||||
Some(BasicAuthCredentials::new(
|
Some(BasicAuthCredentials::new(
|
||||||
app_config.bedrock_auth.0.clone(),
|
bedrock_config.user.clone(),
|
||||||
Some(app_config.bedrock_auth.1.clone()),
|
bedrock_config.password.clone(),
|
||||||
)),
|
)),
|
||||||
sender,
|
sender,
|
||||||
app_config.indexer_config.clone(),
|
bedrock_config.indexer_config.clone(),
|
||||||
)?;
|
bedrock_config.channel_id.into(),
|
||||||
|
)?;
|
||||||
|
|
||||||
info!("Indexer core set up");
|
info!("Indexer core set up");
|
||||||
|
|
||||||
|
(Some(indexer_core), Some(receiver))
|
||||||
|
} else {
|
||||||
|
info!("Bedrock config not provided, skipping indexer setup");
|
||||||
|
|
||||||
|
(None, None)
|
||||||
|
};
|
||||||
|
|
||||||
let (sequencer_core, mempool_handle) = SequencerCore::start_from_config(app_config, receiver);
|
let (sequencer_core, mempool_handle) = SequencerCore::start_from_config(app_config, receiver);
|
||||||
|
|
||||||
info!("Sequencer core set up");
|
info!("Sequencer core set up");
|
||||||
|
|
||||||
let indexer_core_wrapped = Arc::new(Mutex::new(indexer_core));
|
let indexer_core_wrapped = indexer_core.map(|core| Arc::new(Mutex::new(core)));
|
||||||
let seq_core_wrapped = Arc::new(Mutex::new(sequencer_core));
|
let seq_core_wrapped = Arc::new(Mutex::new(sequencer_core));
|
||||||
|
|
||||||
let (http_server, addr) = new_http_server(
|
let (http_server, addr) = new_http_server(
|
||||||
RpcConfig::with_port(port),
|
RpcConfig::with_port(port),
|
||||||
Arc::clone(&seq_core_wrapped),
|
Arc::clone(&seq_core_wrapped),
|
||||||
mempool_handle,
|
mempool_handle,
|
||||||
Arc::clone(&indexer_core_wrapped),
|
indexer_core_wrapped.clone(),
|
||||||
)?;
|
)?;
|
||||||
info!("HTTP server started");
|
info!("HTTP server started");
|
||||||
let http_server_handle = http_server.handle();
|
let http_server_handle = http_server.handle();
|
||||||
@ -80,18 +94,25 @@ pub async fn startup_sequencer(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let indexer_loop_handle = tokio::spawn(async move {
|
let indexer_loop_handle = indexer_core_wrapped.map(|indexer_core_wrapped| {
|
||||||
{
|
tokio::spawn(async move {
|
||||||
let indexer_guard = indexer_core_wrapped.lock().await;
|
{
|
||||||
let res = indexer_guard.subscribe_parse_block_stream().await;
|
let indexer_guard = indexer_core_wrapped.lock().await;
|
||||||
|
let res = indexer_guard.subscribe_parse_block_stream().await;
|
||||||
|
|
||||||
info!("Indexer loop res is {res:#?}");
|
info!("Indexer loop res is {res:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok((http_server_handle, addr, main_loop_handle, indexer_loop_handle))
|
Ok((
|
||||||
|
http_server_handle,
|
||||||
|
addr,
|
||||||
|
main_loop_handle,
|
||||||
|
indexer_loop_handle,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn main_runner() -> Result<()> {
|
pub async fn main_runner() -> Result<()> {
|
||||||
@ -114,7 +135,10 @@ pub async fn main_runner() -> Result<()> {
|
|||||||
let (_, _, main_loop_handle, indexer_loop_handle) = startup_sequencer(app_config).await?;
|
let (_, _, main_loop_handle, indexer_loop_handle) = startup_sequencer(app_config).await?;
|
||||||
|
|
||||||
main_loop_handle.await??;
|
main_loop_handle.await??;
|
||||||
indexer_loop_handle.await??;
|
|
||||||
|
if indexer_loop_handle.is_some() {
|
||||||
|
indexer_loop_handle.unwrap().await??;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user