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",
"log",
"logos-blockchain-common-http-client",
"logos-blockchain-core",
"nssa",
"nssa_core",
"reqwest",

View File

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

View File

@ -1,10 +1,10 @@
use borsh::{BorshDeserialize, BorshSerialize};
use logos_blockchain_core::mantle::ops::channel::MsgId;
use sha2::{Digest, Sha256, digest::FixedOutput};
use crate::transaction::EncodedTransaction;
pub type HashType = [u8; 32];
pub type MantleMsgId = [u8; 32];
#[derive(Debug, Clone)]
/// Our own hasher.
@ -50,11 +50,7 @@ pub struct Block {
pub header: BlockHeader,
pub body: BlockBody,
pub bedrock_status: BedrockStatus,
#[borsh(
serialize_with = "borsh_msg_id::serialize",
deserialize_with = "borsh_msg_id::deserialize"
)]
pub bedrock_parent_id: MsgId,
pub bedrock_parent_id: MantleMsgId,
}
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
@ -69,7 +65,7 @@ impl HashableBlockData {
pub fn into_pending_block(
self,
signing_key: &nssa::PrivateKey,
bedrock_parent_id: MsgId,
bedrock_parent_id: MantleMsgId,
) -> Block {
let data_bytes = borsh::to_vec(&self).unwrap();
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)]
mod tests {
use crate::{block::HashableBlockData, test_utils};

View File

@ -1,5 +1,3 @@
use logos_blockchain_core::mantle::ops::channel::MsgId;
use crate::{
block::{Block, HashableBlockData},
transaction::{EncodedTransaction, NSSATransaction},
@ -32,7 +30,7 @@ pub fn produce_dummy_block(
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 {

View File

@ -606,7 +606,7 @@ impl TryFrom<common::block::Block> for Block {
header: header.into(),
body: body.try_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()?,
body: body.try_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 {
channel_id: self.bedrock_channel_id,
inscription: inscription_data,
parent: block.bedrock_parent_id,
parent: block.bedrock_parent_id.into(),
signer: verifying_key,
};
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)]
mod tests {
use common::{block::HashableBlockData, test_utils::sequencer_sign_key_for_testing};
use logos_blockchain_core::mantle::ops::channel::MsgId;
use tempfile::tempdir;
use super::*;
@ -127,8 +126,7 @@ mod tests {
transactions: vec![],
};
let genesis_block =
genesis_block_hashable_data.into_pending_block(&signing_key, MsgId::from([0; 32]));
let genesis_block = genesis_block_hashable_data.into_pending_block(&signing_key, [0; 32]);
// Start an empty node store
let mut node_store =
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::{
HashType,
block::{BedrockStatus, Block, HashableBlockData},
block::{BedrockStatus, Block, HashableBlockData, MantleMsgId},
transaction::{EncodedTransaction, NSSATransaction},
};
use config::SequencerConfig;
use log::{info, warn};
use logos_blockchain_core::mantle::ops::channel::MsgId;
use mempool::{MemPool, MemPoolHandle};
use serde::{Deserialize, Serialize};
@ -27,7 +26,7 @@ pub struct SequencerCore {
sequencer_config: SequencerConfig,
chain_height: u64,
block_settlement_client: Option<BlockSettlementClient>,
last_bedrock_msg_id: MsgId,
last_bedrock_msg_id: MantleMsgId,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -59,7 +58,7 @@ impl SequencerCore {
};
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);
// Sequencer should panic if unable to open db,
@ -91,7 +90,7 @@ impl SequencerCore {
acc.program_owner =
nssa::program::Program::authenticated_transfer_program().id();
nssa_core::Commitment::new(&npk, &acc)
nssa_core::Commitment::new(npk, &acc)
})
.collect();
@ -152,7 +151,7 @@ impl SequencerCore {
let block =
block_data.into_pending_block(self.store.signing_key(), self.last_bedrock_msg_id);
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");
}