fix(sequencer_core): new zones api try

This commit is contained in:
Pravdyvy 2026-06-15 10:55:05 +03:00
parent 1cd6dedf40
commit d63584fe11
4 changed files with 108 additions and 41 deletions

54
flake.lock generated
View File

@ -20,17 +20,17 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1775835011,
"narHash": "sha256-SQDLyyRUa5J9QHjNiHbeZw4rQOZnTEo61TcaUpjtLBs=",
"lastModified": 1781004244,
"narHash": "sha256-zd4XYY+HPOMJXigHQDmXDvt7D1988YNPUwPPznhpFdA=",
"owner": "logos-blockchain",
"repo": "logos-blockchain-circuits",
"rev": "d6cf41f66500d4afc157b4f43de0f0d5bfa01443",
"rev": "2846ee7a4cfa24458bb8063412ab2e753b344d2f",
"type": "github"
},
"original": {
"owner": "logos-blockchain",
"repo": "logos-blockchain-circuits",
"rev": "d6cf41f66500d4afc157b4f43de0f0d5bfa01443",
"rev": "2846ee7a4cfa24458bb8063412ab2e753b344d2f",
"type": "github"
}
},
@ -6352,16 +6352,16 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1769461804,
"narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=",
"lastModified": 1767313136,
"narHash": "sha256-16KkgfdYqjaeRGBaYsNrhPRRENs0qzkQVUooNHtoy2w=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d",
"rev": "ac62194c3917d5f474c1a844b6fd6da2db95077d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
@ -6942,6 +6942,22 @@
"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": {
"locked": {
"lastModified": 1759036355,
@ -8570,7 +8586,8 @@
"logos-liblogos",
"nixpkgs"
],
"rust-overlay": "rust-overlay"
"rust-overlay": "rust-overlay",
"rust-rapidsnark": "rust-rapidsnark"
}
},
"rust-overlay": {
@ -8592,6 +8609,25 @@
"repo": "rust-overlay",
"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",

View File

@ -35,6 +35,7 @@ bytesize.workspace = true
hex.workspace = true
url.workspace = true
risc0-zkvm.workspace = true
futures.workspace = true
[features]
default = []

View File

@ -9,10 +9,12 @@ pub use logos_blockchain_zone_sdk::sequencer::SequencerCheckpoint;
use logos_blockchain_zone_sdk::{
CommonHttpClient,
adapter::NodeHttpClient,
sequencer::{Event, SequencerConfig as ZoneSdkSequencerConfig, SequencerHandle, ZoneSequencer},
state::{DepositInfo, FinalizedOp, InscriptionInfo},
sequencer::{
DepositInfo, Event, FinalizedOp, InscriptionInfo,
SequencerConfig as ZoneSdkSequencerConfig, ZoneSequencer,
},
};
use tokio::task::JoinHandle;
use tokio::{sync::Mutex, task::JoinHandle};
use crate::config::BedrockConfig;
@ -30,7 +32,7 @@ pub type OnDepositEventSink =
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")]
pub trait BlockPublisherTrait: Clone {
pub trait BlockPublisherTrait: Sized {
async fn new(
config: &BedrockConfig,
bedrock_signing_key: Ed25519Key,
@ -43,13 +45,15 @@ pub trait BlockPublisherTrait: Clone {
/// Fire-and-forget publish. Zone-sdk drives the actual submission and
/// 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`.
#[derive(Clone)]
//#[derive(Clone)]
pub struct ZoneSdkPublisher {
handle: SequencerHandle<NodeHttpClient>,
sequencer: Arc<Mutex<ZoneSequencer<NodeHttpClient>>>,
// Aborts the drive task when the last clone is dropped.
_drive_task: Arc<DriveTaskGuard>,
}
@ -80,23 +84,35 @@ impl BlockPublisherTrait for ZoneSdkPublisher {
..ZoneSdkSequencerConfig::default()
};
let (mut sequencer, mut handle) = ZoneSequencer::init_with_config(
let sequencer = Arc::new(Mutex::new(ZoneSequencer::init_with_config(
config.channel_id,
bedrock_signing_key,
node,
zone_sdk_config,
initial_checkpoint,
);
)));
let drive_sequencer = sequencer.clone();
let drive_task = tokio::spawn(async move {
loop {
let Some(event) = sequencer.next_event().await else {
continue;
let event = {
let mut event_guard = drive_sequencer.lock().await;
let Some(event) = event_guard.next_event().await else {
continue;
};
event
};
match event {
Event::Checkpoint { checkpoint } => on_checkpoint(checkpoint),
Event::TxsFinalized { items } => {
for op in items.into_iter().flat_map(|item| item.ops) {
Event::BlocksProcessed {
checkpoint,
channel_update: _,
finalized,
} => {
on_checkpoint(checkpoint);
for op in finalized.into_iter().flat_map(|item| item.ops) {
match op {
FinalizedOp::Inscription(inscription) => {
if let Some(block_id) = block_id_from_inscription(&inscription)
@ -111,35 +127,46 @@ impl BlockPublisherTrait for ZoneSdkPublisher {
}
}
}
Event::ChannelUpdate { .. }
| Event::Published { .. }
| Event::Readiness { .. }
| Event::TurnNotification { .. } => {}
Event::Ready | Event::TurnNotification { .. } => {}
}
}
});
handle.wait_ready().await;
Ok(Self {
handle,
sequencer,
_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_bounded = data
.try_into()
.context("Block data exceeds maximum allowed size")?;
self.handle
.publish_message(data_bounded)
.await
.context("Failed to publish block")?;
{
let mut handle_guard = self.sequencer.lock().await;
let _res = handle_guard
.handle()
.publish(data_bounded)
.context("Failed to publish block")?;
}
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`.

View File

@ -12,6 +12,7 @@ use lee::{AccountId, PublicTransaction, program::Program, public_transaction::Me
use lee_core::GENESIS_BLOCK_ID;
use log::{error, info, warn};
use logos_blockchain_key_management_system_service::keys::{ED25519_SECRET_KEY_SIZE, Ed25519Key};
use logos_blockchain_zone_sdk::sequencer::DepositInfo;
use mempool::{MemPool, MemPoolHandle};
#[cfg(feature = "mock")]
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,
bedrock_signing_key,
config.retry_pending_blocks_timeout,
@ -241,6 +242,10 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
// first publish, zone-sdk's checkpoint persistence covers further
// restarts.
if is_fresh_start {
log::info!("Waiting while BP is ready");
block_publisher.wait_ready().await;
block_publisher
.publish_block(&genesis_block)
.await
@ -472,8 +477,8 @@ impl<BP: BlockPublisherTrait> SequencerCore<BP> {
.collect())
}
pub fn block_publisher(&self) -> BP {
self.block_publisher.clone()
pub fn block_publisher(&self) -> &BP {
&self.block_publisher
}
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)
}
fn pending_deposit_event_record(
deposit: &logos_blockchain_zone_sdk::state::DepositInfo,
) -> PendingDepositEventRecord {
fn pending_deposit_event_record(deposit: &DepositInfo) -> PendingDepositEventRecord {
PendingDepositEventRecord {
deposit_op_id: HashType(deposit.op_id),
source_tx_hash: HashType(deposit.tx_hash.0),