use own type MantleMsgId

This commit is contained in:
Sergio Chouhy 2026-01-29 15:21:15 -03:00
parent 476dc50482
commit de54744893
8 changed files with 13 additions and 40 deletions

1
Cargo.lock generated
View File

@ -1341,7 +1341,6 @@ dependencies = [
"hex", "hex",
"log", "log",
"logos-blockchain-common-http-client", "logos-blockchain-common-http-client",
"logos-blockchain-core",
"nssa", "nssa",
"nssa_core", "nssa_core",
"reqwest", "reqwest",

View File

@ -17,6 +17,5 @@ log.workspace = true
hex.workspace = true hex.workspace = true
borsh.workspace = true borsh.workspace = true
base64.workspace = true base64.workspace = true
logos-blockchain-core.workspace = true
url.workspace = true url.workspace = true
logos-blockchain-common-http-client.workspace = true logos-blockchain-common-http-client.workspace = true

View File

@ -1,10 +1,10 @@
use borsh::{BorshDeserialize, BorshSerialize}; use borsh::{BorshDeserialize, BorshSerialize};
use logos_blockchain_core::mantle::ops::channel::MsgId;
use sha2::{Digest, Sha256, digest::FixedOutput}; use sha2::{Digest, Sha256, digest::FixedOutput};
use crate::transaction::EncodedTransaction; use crate::transaction::EncodedTransaction;
pub type HashType = [u8; 32]; pub type HashType = [u8; 32];
pub type MantleMsgId = [u8; 32];
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
/// Our own hasher. /// Our own hasher.
@ -50,11 +50,7 @@ pub struct Block {
pub header: BlockHeader, pub header: BlockHeader,
pub body: BlockBody, pub body: BlockBody,
pub bedrock_status: BedrockStatus, pub bedrock_status: BedrockStatus,
#[borsh( pub bedrock_parent_id: MantleMsgId,
serialize_with = "borsh_msg_id::serialize",
deserialize_with = "borsh_msg_id::deserialize"
)]
pub bedrock_parent_id: MsgId,
} }
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)] #[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
@ -69,7 +65,7 @@ impl HashableBlockData {
pub fn into_pending_block( pub fn into_pending_block(
self, self,
signing_key: &nssa::PrivateKey, signing_key: &nssa::PrivateKey,
bedrock_parent_id: MsgId, bedrock_parent_id: MantleMsgId,
) -> Block { ) -> Block {
let data_bytes = borsh::to_vec(&self).unwrap(); let data_bytes = borsh::to_vec(&self).unwrap();
let signature = nssa::Signature::new(signing_key, &data_bytes); let signature = nssa::Signature::new(signing_key, &data_bytes);
@ -106,22 +102,6 @@ impl From<Block> for HashableBlockData {
} }
} }
mod borsh_msg_id {
use std::io::{Read, Write};
use logos_blockchain_core::mantle::ops::channel::MsgId;
pub fn serialize<W: Write>(v: &MsgId, w: &mut W) -> std::io::Result<()> {
w.write_all(v.as_ref())
}
pub fn deserialize<R: Read>(r: &mut R) -> std::io::Result<MsgId> {
let mut buf = [0u8; 32];
r.read_exact(&mut buf)?;
Ok(MsgId::from(buf))
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{block::HashableBlockData, test_utils}; use crate::{block::HashableBlockData, test_utils};

View File

@ -1,5 +1,3 @@
use logos_blockchain_core::mantle::ops::channel::MsgId;
use crate::{ use crate::{
block::{Block, HashableBlockData}, block::{Block, HashableBlockData},
transaction::{EncodedTransaction, NSSATransaction}, transaction::{EncodedTransaction, NSSATransaction},
@ -32,7 +30,7 @@ pub fn produce_dummy_block(
transactions, transactions,
}; };
block_data.into_pending_block(&sequencer_sign_key_for_testing(), MsgId::from([0; 32])) block_data.into_pending_block(&sequencer_sign_key_for_testing(), [0; 32])
} }
pub fn produce_dummy_empty_transaction() -> EncodedTransaction { pub fn produce_dummy_empty_transaction() -> EncodedTransaction {

View File

@ -606,7 +606,7 @@ impl TryFrom<common::block::Block> for Block {
header: header.into(), header: header.into(),
body: body.try_into()?, body: body.try_into()?,
bedrock_status: bedrock_status.into(), bedrock_status: bedrock_status.into(),
bedrock_parent_id: bedrock_parent_id.into(), bedrock_parent_id: MsgId(bedrock_parent_id),
}) })
} }
} }
@ -626,7 +626,7 @@ impl TryFrom<Block> for common::block::Block {
header: header.try_into()?, header: header.try_into()?,
body: body.try_into()?, body: body.try_into()?,
bedrock_status: bedrock_status.into(), bedrock_status: bedrock_status.into(),
bedrock_parent_id: bedrock_parent_id.into(), bedrock_parent_id: bedrock_parent_id.0,
}) })
} }
} }

View File

@ -47,7 +47,7 @@ impl BlockSettlementClient {
let inscribe_op = InscriptionOp { let inscribe_op = InscriptionOp {
channel_id: self.bedrock_channel_id, channel_id: self.bedrock_channel_id,
inscription: inscription_data, inscription: inscription_data,
parent: block.bedrock_parent_id, parent: block.bedrock_parent_id.into(),
signer: verifying_key, signer: verifying_key,
}; };
let inscribe_op_id = inscribe_op.id(); let inscribe_op_id = inscribe_op.id();

View File

@ -108,7 +108,6 @@ pub(crate) fn block_to_transactions_map(block: &Block) -> HashMap<HashType, u64>
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use common::{block::HashableBlockData, test_utils::sequencer_sign_key_for_testing}; use common::{block::HashableBlockData, test_utils::sequencer_sign_key_for_testing};
use logos_blockchain_core::mantle::ops::channel::MsgId;
use tempfile::tempdir; use tempfile::tempdir;
use super::*; use super::*;
@ -127,8 +126,7 @@ mod tests {
transactions: vec![], transactions: vec![],
}; };
let genesis_block = let genesis_block = genesis_block_hashable_data.into_pending_block(&signing_key, [0; 32]);
genesis_block_hashable_data.into_pending_block(&signing_key, MsgId::from([0; 32]));
// Start an empty node store // Start an empty node store
let mut node_store = let mut node_store =
SequencerStore::open_db_with_genesis(path, Some(genesis_block), signing_key).unwrap(); SequencerStore::open_db_with_genesis(path, Some(genesis_block), signing_key).unwrap();

View File

@ -5,12 +5,11 @@ use anyhow::Result;
use common::PINATA_BASE58; use common::PINATA_BASE58;
use common::{ use common::{
HashType, HashType,
block::{BedrockStatus, Block, HashableBlockData}, block::{BedrockStatus, Block, HashableBlockData, MantleMsgId},
transaction::{EncodedTransaction, NSSATransaction}, transaction::{EncodedTransaction, NSSATransaction},
}; };
use config::SequencerConfig; use config::SequencerConfig;
use log::{info, warn}; use log::{info, warn};
use logos_blockchain_core::mantle::ops::channel::MsgId;
use mempool::{MemPool, MemPoolHandle}; use mempool::{MemPool, MemPoolHandle};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -27,7 +26,7 @@ pub struct SequencerCore {
sequencer_config: SequencerConfig, sequencer_config: SequencerConfig,
chain_height: u64, chain_height: u64,
block_settlement_client: Option<BlockSettlementClient>, block_settlement_client: Option<BlockSettlementClient>,
last_bedrock_msg_id: MsgId, last_bedrock_msg_id: MantleMsgId,
} }
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -59,7 +58,7 @@ impl SequencerCore {
}; };
let signing_key = nssa::PrivateKey::try_new(config.signing_key).unwrap(); let signing_key = nssa::PrivateKey::try_new(config.signing_key).unwrap();
let channel_genesis_msg_id = MsgId::from([0; 32]); let channel_genesis_msg_id = [0; 32];
let genesis_block = hashable_data.into_pending_block(&signing_key, channel_genesis_msg_id); let genesis_block = hashable_data.into_pending_block(&signing_key, channel_genesis_msg_id);
// Sequencer should panic if unable to open db, // Sequencer should panic if unable to open db,
@ -91,7 +90,7 @@ impl SequencerCore {
acc.program_owner = acc.program_owner =
nssa::program::Program::authenticated_transfer_program().id(); nssa::program::Program::authenticated_transfer_program().id();
nssa_core::Commitment::new(&npk, &acc) nssa_core::Commitment::new(npk, &acc)
}) })
.collect(); .collect();
@ -152,7 +151,7 @@ impl SequencerCore {
let block = let block =
block_data.into_pending_block(self.store.signing_key(), self.last_bedrock_msg_id); block_data.into_pending_block(self.store.signing_key(), self.last_bedrock_msg_id);
let msg_id = client.submit_block_to_bedrock(&block).await?; let msg_id = client.submit_block_to_bedrock(&block).await?;
self.last_bedrock_msg_id = msg_id; self.last_bedrock_msg_id = msg_id.into();
log::info!("Posted block data to Bedrock"); log::info!("Posted block data to Bedrock");
} }