Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: move kernel MMR position to u64 #5956

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -373,11 +373,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
));
}

let mmr_position_u32 = u32::try_from(mmr_position).map_err(|_| HorizonSyncError::InvalidMmrPosition {
at_height: current_header.height(),
mmr_position,
})?;
txn.insert_kernel_via_horizon_sync(kernel, *current_header.hash(), mmr_position_u32);
txn.insert_kernel_via_horizon_sync(kernel, *current_header.hash(), mmr_position);
if mmr_position == current_header.header().kernel_mmr_size - 1 {
let num_kernels = kernel_hashes.len();
debug!(
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/chain_storage/async_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ impl<'a, B: BlockchainBackend + 'static> AsyncDbTransaction<'a, B> {
&mut self,
kernel: TransactionKernel,
header_hash: HashOutput,
mmr_position: u32,
mmr_position: u64,
) -> &mut Self {
self.transaction.insert_kernel(kernel, header_hash, mmr_position);
self
Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/chain_storage/db_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl DbTransaction {
&mut self,
kernel: TransactionKernel,
header_hash: HashOutput,
mmr_position: u32,
mmr_position: u64,
) -> &mut Self {
self.operations.push(WriteOperation::InsertKernel {
header_hash,
Expand Down Expand Up @@ -279,7 +279,7 @@ pub enum WriteOperation {
InsertKernel {
header_hash: HashOutput,
kernel: Box<TransactionKernel>,
mmr_position: u32,
mmr_position: u64,
},
InsertOutput {
header_hash: HashOutput,
Expand Down
14 changes: 6 additions & 8 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ const LMDB_DB_VALIDATOR_NODES_MAPPING: &str = "validator_nodes_mapping";
const LMDB_DB_TEMPLATE_REGISTRATIONS: &str = "template_registrations";
const LMDB_DB_TIP_UTXO_SMT: &str = "tip_utxo_smt";

/// HeaderHash(32), mmr_pos(4), hash(32)
type KernelKey = CompositeKey<68>;
/// HeaderHash(32), mmr_pos(8), hash(32)
type KernelKey = CompositeKey<72>;
/// Height(8), Hash(32)
type ValidatorNodeRegistrationKey = CompositeKey<40>;

Expand Down Expand Up @@ -566,7 +566,7 @@ impl LMDBDatabase {
txn: &WriteTransaction<'_>,
header_hash: &HashOutput,
kernel: &TransactionKernel,
mmr_position: u32,
mmr_position: u64,
) -> Result<(), ChainStorageError> {
let hash = kernel.hash();
let key = KernelKey::try_from_parts(&[
Expand Down Expand Up @@ -1131,15 +1131,13 @@ impl LMDBDatabase {

for kernel in kernels {
total_kernel_sum = &total_kernel_sum + &kernel.excess;
let pos = kernel_mmr.push(kernel.hash().to_vec())?;
let pos =
u64::try_from(kernel_mmr.push(kernel.hash().to_vec())?).map_err(|_| ChainStorageError::OutOfRange)?;
trace!(
target: LOG_TARGET,
"Inserting kernel `{}`",
kernel.excess_sig.get_signature().to_hex()
);
let pos = u32::try_from(pos).map_err(|_| {
ChainStorageError::InvalidOperation(format!("Kernel MMR node count ({}) is greater than u32::MAX", pos))
})?;
self.insert_kernel(txn, &block_hash, &kernel, pos)?;
}
let k = MetadataKey::TipSmt;
Expand Down Expand Up @@ -1815,7 +1813,7 @@ impl BlockchainBackend for LMDBDatabase {
key.extend(excess_sig.get_public_nonce().as_bytes());
key.extend(excess_sig.get_signature().as_bytes());
if let Some((header_hash, mmr_position, hash)) =
lmdb_get::<_, (HashOutput, u32, HashOutput)>(&txn, &self.kernel_excess_sig_index, key.as_slice())?
lmdb_get::<_, (HashOutput, u64, HashOutput)>(&txn, &self.kernel_excess_sig_index, key.as_slice())?
{
let key = KernelKey::try_from_parts(&[
header_hash.as_slice(),
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/chain_storage/lmdb_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) struct TransactionInputRowData {
pub(crate) struct TransactionKernelRowData {
pub kernel: TransactionKernel,
pub header_hash: HashOutput,
pub mmr_position: u32,
pub mmr_position: u64,
pub hash: HashOutput,
}

Expand Down
Loading