Skip to content

Commit

Permalink
fix: db resize issues (#5863)
Browse files Browse the repository at this point in the history
Description
---
Fixes a resize issue with horizon sync mode

Motivation and Context
---
Lmdb only resizes on transactions, and not pure table changes in our
code, this changes the tip smt to always use the transactions, as this
call might be large.

How Has This Been Tested?
---
manual
  • Loading branch information
SWvheerden committed Nov 2, 2023
1 parent 934fdec commit 2302562
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 18 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -598,17 +598,20 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
);
let root = FixedHash::try_from(output_smt.hash().as_slice())?;
if root != to_header.output_mr {
warn!(
target: LOG_TARGET,
"Final target root(#{}) did not match expected (#{})",
to_header.output_mr.to_hex(),
root.to_hex(),
);
return Err(HorizonSyncError::InvalidMrRoot {
mr_tree: "UTXO SMT".to_string(),
at_height: to_header.height,
expected_hex: to_header.output_mr.to_hex(),
actual_hex: root.to_hex(),
});
}

db.set_tip_smt(output_smt).await?;
self.check_latency(sync_peer.node_id(), &avg_latency)?;

Ok(())
}

Expand Down
2 changes: 0 additions & 2 deletions base_layer/core/src/chain_storage/blockchain_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,4 @@ pub trait BlockchainBackend: Send + Sync {
) -> Result<Vec<TemplateRegistrationEntry>, ChainStorageError>;
/// Returns the tip utxo smt
fn fetch_tip_smt(&self) -> Result<OutputSmt, ChainStorageError>;
/// Sets the tip utxo smt
fn set_tip_smt(&self, smt: OutputSmt) -> Result<(), ChainStorageError>;
}
6 changes: 4 additions & 2 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,10 @@ where B: BlockchainBackend
}

pub fn set_tip_smt(&self, smt: OutputSmt) -> Result<(), ChainStorageError> {
let db = self.db_write_access()?;
db.set_tip_smt(smt)
let mut db = self.db_write_access()?;
let mut txn = DbTransaction::new();
txn.insert_tip_smt(smt);
db.write(txn)
}

/// Fetches the last header that was added, might be past the tip, as the block body between this last header and
Expand Down
5 changes: 0 additions & 5 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2300,11 +2300,6 @@ impl BlockchainBackend for LMDBDatabase {
}),
}
}

fn set_tip_smt(&self, smt: OutputSmt) -> Result<(), ChainStorageError> {
let txn = self.write_transaction()?;
self.insert_tip_smt(&txn, &smt)
}
}

// Fetch the chain metadata
Expand Down
4 changes: 0 additions & 4 deletions base_layer/core/src/test_helpers/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,6 @@ impl BlockchainBackend for TempDatabase {
fn fetch_tip_smt(&self) -> Result<OutputSmt, ChainStorageError> {
self.db.as_ref().unwrap().fetch_tip_smt()
}

fn set_tip_smt(&self, smt: OutputSmt) -> Result<(), ChainStorageError> {
self.db.as_ref().unwrap().set_tip_smt(smt)
}
}

pub async fn create_chained_blocks<T: Into<BlockSpecs>>(
Expand Down
1 change: 0 additions & 1 deletion base_layer/mmr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ borsh = "0.10"
digest = "0.10"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0.119"
croaring = { version = "0.9", optional = true }

[dev-dependencies]
Expand Down

0 comments on commit 2302562

Please sign in to comment.