mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-08-10 06:53:13 +00:00
fix(sequencer_core): new zones api try
This commit is contained in:
parent
1cd6dedf40
commit
d63584fe11
54
flake.lock
generated
54
flake.lock
generated
@ -20,17 +20,17 @@
|
|||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1775835011,
|
"lastModified": 1781004244,
|
||||||
"narHash": "sha256-SQDLyyRUa5J9QHjNiHbeZw4rQOZnTEo61TcaUpjtLBs=",
|
"narHash": "sha256-zd4XYY+HPOMJXigHQDmXDvt7D1988YNPUwPPznhpFdA=",
|
||||||
"owner": "logos-blockchain",
|
"owner": "logos-blockchain",
|
||||||
"repo": "logos-blockchain-circuits",
|
"repo": "logos-blockchain-circuits",
|
||||||
"rev": "d6cf41f66500d4afc157b4f43de0f0d5bfa01443",
|
"rev": "2846ee7a4cfa24458bb8063412ab2e753b344d2f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "logos-blockchain",
|
"owner": "logos-blockchain",
|
||||||
"repo": "logos-blockchain-circuits",
|
"repo": "logos-blockchain-circuits",
|
||||||
"rev": "d6cf41f66500d4afc157b4f43de0f0d5bfa01443",
|
"rev": "2846ee7a4cfa24458bb8063412ab2e753b344d2f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -6352,16 +6352,16 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1769461804,
|
"lastModified": 1767313136,
|
||||||
"narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=",
|
"narHash": "sha256-16KkgfdYqjaeRGBaYsNrhPRRENs0qzkQVUooNHtoy2w=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d",
|
"rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-unstable",
|
"ref": "nixos-25.05",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
@ -6942,6 +6942,22 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nixpkgs_132": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1767313136,
|
||||||
|
"narHash": "sha256-16KkgfdYqjaeRGBaYsNrhPRRENs0qzkQVUooNHtoy2w=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-25.05",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs_14": {
|
"nixpkgs_14": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1759036355,
|
"lastModified": 1759036355,
|
||||||
@ -8570,7 +8586,8 @@
|
|||||||
"logos-liblogos",
|
"logos-liblogos",
|
||||||
"nixpkgs"
|
"nixpkgs"
|
||||||
],
|
],
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay",
|
||||||
|
"rust-rapidsnark": "rust-rapidsnark"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-overlay": {
|
"rust-overlay": {
|
||||||
@ -8592,6 +8609,25 @@
|
|||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"rust-rapidsnark": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs_132"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1781090841,
|
||||||
|
"narHash": "sha256-A1wVkHRw3/xpV30JUgWxvfW5PgcyrxQxk7b4So5vXNs=",
|
||||||
|
"owner": "logos-blockchain",
|
||||||
|
"repo": "logos-blockchain-rust-rapidsnark",
|
||||||
|
"rev": "e91187f8ccb5bbfc7bb00dac88169112428da78f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "logos-blockchain",
|
||||||
|
"repo": "logos-blockchain-rust-rapidsnark",
|
||||||
|
"rev": "e91187f8ccb5bbfc7bb00dac88169112428da78f",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": "root",
|
"root": "root",
|
||||||
|
|||||||
@ -35,6 +35,7 @@ bytesize.workspace = true
|
|||||||
hex.workspace = true
|
hex.workspace = true
|
||||||
url.workspace = true
|
url.workspace = true
|
||||||
risc0-zkvm.workspace = true
|
risc0-zkvm.workspace = true
|
||||||
|
futures.workspace = true
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
@ -9,10 +9,12 @@ pub use logos_blockchain_zone_sdk::sequencer::SequencerCheckpoint;
|
|||||||
use logos_blockchain_zone_sdk::{
|
use logos_blockchain_zone_sdk::{
|
||||||
CommonHttpClient,
|
CommonHttpClient,
|
||||||
adapter::NodeHttpClient,
|
adapter::NodeHttpClient,
|
||||||
sequencer::{Event, SequencerConfig as ZoneSdkSequencerConfig, SequencerHandle, ZoneSequencer},
|
sequencer::{
|
||||||
state::{DepositInfo, FinalizedOp, InscriptionInfo},
|
DepositInfo, Event, FinalizedOp, InscriptionInfo,
|
||||||
|
SequencerConfig as ZoneSdkSequencerConfig, ZoneSequencer,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use tokio::task::JoinHandle;
|
use tokio::{sync::Mutex, task::JoinHandle};
|
||||||
|
|
||||||
use crate::config::BedrockConfig;
|
use crate::config::BedrockConfig;
|
||||||
|
|
||||||
@ -30,7 +32,7 @@ pub type OnDepositEventSink =
|
|||||||
Box<dyn Fn(DepositInfo) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + 'static>;
|
Box<dyn Fn(DepositInfo) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + 'static>;
|
||||||
|
|
||||||
#[expect(async_fn_in_trait, reason = "We don't care about Send/Sync here")]
|
#[expect(async_fn_in_trait, reason = "We don't care about Send/Sync here")]
|
||||||
pub trait BlockPublisherTrait: Clone {
|
pub trait BlockPublisherTrait: Sized {
|
||||||
async fn new(
|
async fn new(
|
||||||
config: &BedrockConfig,
|
config: &BedrockConfig,
|
||||||
bedrock_signing_key: Ed25519Key,
|
bedrock_signing_key: Ed25519Key,
|
||||||
@ -43,13 +45,15 @@ pub trait BlockPublisherTrait: Clone {
|
|||||||
|
|
||||||
/// Fire-and-forget publish. Zone-sdk drives the actual submission and
|
/// Fire-and-forget publish. Zone-sdk drives the actual submission and
|
||||||
/// retries internally; this just hands the payload off.
|
/// retries internally; this just hands the payload off.
|
||||||
async fn publish_block(&self, block: &Block) -> Result<()>;
|
async fn publish_block(&mut self, block: &Block) -> Result<()>;
|
||||||
|
|
||||||
|
async fn wait_ready(&self);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Real block publisher backed by zone-sdk's `ZoneSequencer`.
|
/// Real block publisher backed by zone-sdk's `ZoneSequencer`.
|
||||||
#[derive(Clone)]
|
//#[derive(Clone)]
|
||||||
pub struct ZoneSdkPublisher {
|
pub struct ZoneSdkPublisher {
|
||||||
handle: SequencerHandle<NodeHttpClient>,
|
sequencer: Arc<Mutex<ZoneSequencer<NodeHttpClient>>>,
|
||||||
// Aborts the drive task when the last clone is dropped.
|
// Aborts the drive task when the last clone is dropped.
|
||||||
_drive_task: Arc<DriveTaskGuard>,
|
_drive_task: Arc<DriveTaskGuard>,
|
||||||
}
|
}
|
||||||
@ -80,23 +84,35 @@ impl BlockPublisherTrait for ZoneSdkPublisher {
|
|||||||
..ZoneSdkSequencerConfig::default()
|
..ZoneSdkSequencerConfig::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (mut sequencer, mut handle) = ZoneSequencer::init_with_config(
|
let sequencer = Arc::new(Mutex::new(ZoneSequencer::init_with_config(
|
||||||
config.channel_id,
|
config.channel_id,
|
||||||
bedrock_signing_key,
|
bedrock_signing_key,
|
||||||
node,
|
node,
|
||||||
zone_sdk_config,
|
zone_sdk_config,
|
||||||
initial_checkpoint,
|
initial_checkpoint,
|
||||||
);
|
)));
|
||||||
|
|
||||||
|
let drive_sequencer = sequencer.clone();
|
||||||
|
|
||||||
let drive_task = tokio::spawn(async move {
|
let drive_task = tokio::spawn(async move {
|
||||||
loop {
|
loop {
|
||||||
let Some(event) = sequencer.next_event().await else {
|
let event = {
|
||||||
continue;
|
let mut event_guard = drive_sequencer.lock().await;
|
||||||
|
|
||||||
|
let Some(event) = event_guard.next_event().await else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
event
|
||||||
};
|
};
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::Checkpoint { checkpoint } => on_checkpoint(checkpoint),
|
Event::BlocksProcessed {
|
||||||
Event::TxsFinalized { items } => {
|
checkpoint,
|
||||||
for op in items.into_iter().flat_map(|item| item.ops) {
|
channel_update: _,
|
||||||
|
finalized,
|
||||||
|
} => {
|
||||||
|
on_checkpoint(checkpoint);
|
||||||
|
for op in finalized.into_iter().flat_map(|item| item.ops) {
|
||||||
match op {
|
match op {
|
||||||
FinalizedOp::Inscription(inscription) => {
|
FinalizedOp::Inscription(inscription) => {
|
||||||
if let Some(block_id) = block_id_from_inscription(&inscription)
|
if let Some(block_id) = block_id_from_inscription(&inscription)
|
||||||
@ -111,35 +127,46 @@ impl BlockPublisherTrait for ZoneSdkPublisher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Event::ChannelUpdate { .. }
|
Event::Ready | Event::TurnNotification { .. } => {}
|
||||||
| Event::Published { .. }
|
|
||||||
| Event::Readiness { .. }
|
|
||||||
| Event::TurnNotification { .. } => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
handle.wait_ready().await;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
handle,
|
sequencer,
|
||||||
_drive_task: Arc::new(DriveTaskGuard(drive_task)),
|
_drive_task: Arc::new(DriveTaskGuard(drive_task)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn publish_block(&self, block: &Block) -> Result<()> {
|
async fn publish_block(&mut self, block: &Block) -> Result<()> {
|
||||||
let data = borsh::to_vec(block).context("Failed to serialize block")?;
|
let data = borsh::to_vec(block).context("Failed to serialize block")?;
|
||||||
let data_bounded = data
|
let data_bounded = data
|
||||||
.try_into()
|
.try_into()
|
||||||
.context("Block data exceeds maximum allowed size")?;
|
.context("Block data exceeds maximum allowed size")?;
|
||||||
|
|
||||||
self.handle
|
{
|
||||||
.publish_message(data_bounded)
|
let mut handle_guard = self.sequencer.lock().await;
|
||||||
.await
|
|
||||||
.context("Failed to publish block")?;
|
let _res = handle_guard
|
||||||
|
.handle()
|
||||||
|
.publish(data_bounded)
|
||||||
|
.context("Failed to publish block")?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn wait_ready(&self) {
|
||||||
|
{
|
||||||
|
let ready_guard = self.sequencer.lock().await;
|
||||||
|
|
||||||
|
ready_guard
|
||||||
|
.subscribe_ready()
|
||||||
|
.wait_for(|val| *val)
|
||||||
|
.await
|
||||||
|
.expect("Channel should be alive");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserialize inscription payload as a `Block` and return it's`block_id`.
|
/// Deserialize inscription payload as a `Block` and return it's`block_id`.
|
||||||
|
|||||||
@ -12,6 +12,7 @@ use lee::{AccountId, PublicTransaction, program::Program, public_transaction::Me
|
|||||||
use lee_core::GENESIS_BLOCK_ID;
|
use lee_core::GENESIS_BLOCK_ID;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use logos_blockchain_key_management_system_service::keys::{ED25519_SECRET_KEY_SIZE, Ed25519Key};
|
use logos_blockchain_key_management_system_service::keys::{ED25519_SECRET_KEY_SIZE, Ed25519Key};
|
||||||
|
use logos_blockchain_zone_sdk::sequencer::DepositInfo;
|
||||||
use mempool::{MemPool, MemPoolHandle};
|
use mempool::{MemPool, MemPoolHandle};
|
||||||
#[cfg(feature = "mock")]
|
#[cfg(feature = "mock")]
|
||||||
pub use mock::SequencerCoreWithMockClients;
|
pub use mock::SequencerCoreWithMockClients;
|
||||||
@ -224,7 +225,7 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let block_publisher = BP::new(
|
let mut block_publisher = BP::new(
|
||||||
&config.bedrock_config,
|
&config.bedrock_config,
|
||||||
bedrock_signing_key,
|
bedrock_signing_key,
|
||||||
config.retry_pending_blocks_timeout,
|
config.retry_pending_blocks_timeout,
|
||||||
@ -241,6 +242,10 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
|
|||||||
// first publish, zone-sdk's checkpoint persistence covers further
|
// first publish, zone-sdk's checkpoint persistence covers further
|
||||||
// restarts.
|
// restarts.
|
||||||
if is_fresh_start {
|
if is_fresh_start {
|
||||||
|
log::info!("Waiting while BP is ready");
|
||||||
|
|
||||||
|
block_publisher.wait_ready().await;
|
||||||
|
|
||||||
block_publisher
|
block_publisher
|
||||||
.publish_block(&genesis_block)
|
.publish_block(&genesis_block)
|
||||||
.await
|
.await
|
||||||
@ -472,8 +477,8 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
|
|||||||
.collect())
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_publisher(&self) -> BP {
|
pub fn block_publisher(&self) -> &BP {
|
||||||
self.block_publisher.clone()
|
&self.block_publisher
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_block_id(&self) -> u64 {
|
fn next_block_id(&self) -> u64 {
|
||||||
@ -611,9 +616,7 @@ fn build_supply_bridge_account_genesis_transaction(balance: u128) -> PublicTrans
|
|||||||
PublicTransaction::new(message, witness_set)
|
PublicTransaction::new(message, witness_set)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pending_deposit_event_record(
|
fn pending_deposit_event_record(deposit: &DepositInfo) -> PendingDepositEventRecord {
|
||||||
deposit: &logos_blockchain_zone_sdk::state::DepositInfo,
|
|
||||||
) -> PendingDepositEventRecord {
|
|
||||||
PendingDepositEventRecord {
|
PendingDepositEventRecord {
|
||||||
deposit_op_id: HashType(deposit.op_id),
|
deposit_op_id: HashType(deposit.op_id),
|
||||||
source_tx_hash: HashType(deposit.tx_hash.0),
|
source_tx_hash: HashType(deposit.tx_hash.0),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user