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

fix!: lmdb flag set wrong on database #5916

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 @@ -356,6 +356,10 @@ impl<'a, B: BlockchainBackend + 'static> BlockSynchronizer<'a, B> {
block.header().pow_algo(),
block.block().body.to_counts_string(),
);
trace!(
target: LOG_TARGET,
"{}",block
);

let timer = Instant::now();
self.db
Expand Down
6 changes: 3 additions & 3 deletions base_layer/core/src/chain_storage/blockchain_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ pub trait BlockchainBackend: Send + Sync {
spend_status_at_header: Option<FixedHash>,
) -> Result<Vec<(TransactionOutput, bool)>, ChainStorageError>;

/// Fetch a specific output. Returns the output and the leaf index in the output MMR
/// Fetch a specific output. Returns the output
fn fetch_output(&self, output_hash: &HashOutput) -> Result<Option<OutputMinedInfo>, ChainStorageError>;

/// Fetch a specific input. Returns the output and the leaf index in the output MMR
fn fetch_input(&self, input_hash: &HashOutput) -> Result<Option<InputMinedInfo>, ChainStorageError>;
/// Fetch a specific input. Returns the input
fn fetch_input(&self, output_hash: &HashOutput) -> Result<Option<InputMinedInfo>, ChainStorageError>;

/// Returns the unspent TransactionOutput output that matches the given commitment if it exists in the current UTXO
/// set, otherwise None is returned.
Expand Down
2 changes: 0 additions & 2 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,6 @@ fn fetch_block<T: BlockchainBackend>(db: &T, height: u64, compact: bool) -> Resu
})
.collect::<Result<Vec<TransactionInput>, _>>()?;

// let inputs = db.fetch_inputs_in_block(&accumulated_data.hash)?;

let block = header
.into_builder()
.add_inputs(inputs)
Expand Down
39 changes: 26 additions & 13 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,35 @@ where
V: Serialize + Debug,
{
let val_buf = serialize(val)?;
trace!(target: LOG_TARGET, "LMDB: {} bytes inserted", val_buf.len());
match txn.access().put(db, key, &val_buf, put::NOOVERWRITE) {
Ok(_) => Ok(()),
Err(lmdb_zero::Error::Code(lmdb_zero::error::KEYEXIST)) => Err(ChainStorageError::KeyExists {
table_name,
key: to_hex(key.as_lmdb_bytes()),
}),
Err(lmdb_zero::Error::Code(lmdb_zero::error::MAP_FULL)) => Err(ChainStorageError::DbResizeRequired),
Err(e) => {
Ok(_) => {
trace!(
target: LOG_TARGET, "Inserted {} bytes with key '{}' into '{}'",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name
);
Ok(())
},
err @ Err(lmdb_zero::Error::Code(lmdb_zero::error::KEYEXIST)) => {
error!(
target: LOG_TARGET,
"Could not insert value into lmdb {} ({}/{:?}): {:?}",
target: LOG_TARGET, "Could not insert {} bytes with key '{}' into '{}' ({:?})",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name, err
);
Err(ChainStorageError::KeyExists {
table_name,
to_hex(key.as_lmdb_bytes()),
val,
e,
key: to_hex(key.as_lmdb_bytes()),
})
},
err @ Err(lmdb_zero::Error::Code(lmdb_zero::error::MAP_FULL)) => {
error!(
target: LOG_TARGET, "Could not insert {} bytes with key '{}' into '{}' ({:?})",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name, err
);
Err(ChainStorageError::DbResizeRequired)
},
Err(e) => {
error!(
target: LOG_TARGET, "Could not insert {} bytes with key '{}' into '{}' ({:?})",
val_buf.len(), to_hex(key.as_lmdb_bytes()), table_name, e
);
Err(ChainStorageError::InsertError {
table: table_name,
Expand Down
23 changes: 8 additions & 15 deletions base_layer/core/src/chain_storage/lmdb_db/lmdb_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub fn create_lmdb_database<P: AsRef<Path>>(
.add_database(LMDB_DB_UTXO_COMMITMENT_INDEX, flags)
.add_database(LMDB_DB_UNIQUE_ID_INDEX, flags)
.add_database(LMDB_DB_CONTRACT_ID_INDEX, flags)
.add_database(LMDB_DB_DELETED_TXO_HASH_TO_HEADER_INDEX, flags | db::INTEGERKEY)
.add_database(LMDB_DB_DELETED_TXO_HASH_TO_HEADER_INDEX, flags)
.add_database(LMDB_DB_ORPHANS, flags)
.add_database(LMDB_DB_ORPHAN_HEADER_ACCUMULATED_DATA, flags)
.add_database(LMDB_DB_MONERO_SEED_HEIGHT, flags)
Expand Down Expand Up @@ -620,22 +620,15 @@ impl LMDBDatabase {
&self.utxo_commitment_index,
input.commitment()?.as_bytes(),
"utxo_commitment_index",
)
.or_else(|err| match err {
// The commitment may not yet be included in the DB in the 0-conf transaction case
ChainStorageError::ValueNotFound { .. } => Ok(()),
_ => Err(err),
})?;
// do I need to look into changing this index to be input.hash -> header hash
// does the key need to include the mmr pos
// make index safe key
)?;

let hash = input.canonical_hash();
let output_hash = input.output_hash();
let key = InputKey::new(header_hash, &hash)?;
lmdb_insert(
txn,
&self.deleted_txo_hash_to_header_index,
&output_hash.to_vec(),
output_hash.as_slice(),
&(key.clone().convert_to_comp_key().to_vec()),
"deleted_txo_hash_to_header_index",
)?;
Expand Down Expand Up @@ -912,7 +905,7 @@ impl LMDBDatabase {
lmdb_delete(
txn,
&self.deleted_txo_hash_to_header_index,
&output_hash.to_vec(),
output_hash.as_slice(),
"deleted_txo_hash_to_header_index",
)?;
if output_rows.iter().any(|r| r.hash == output_hash) {
Expand Down Expand Up @@ -1884,10 +1877,10 @@ impl BlockchainBackend for LMDBDatabase {
self.fetch_output_in_txn(&txn, output_hash.as_slice())
}

fn fetch_input(&self, input_hash: &HashOutput) -> Result<Option<InputMinedInfo>, ChainStorageError> {
debug!(target: LOG_TARGET, "Fetch input: {}", input_hash.to_hex());
fn fetch_input(&self, output_hash: &HashOutput) -> Result<Option<InputMinedInfo>, ChainStorageError> {
debug!(target: LOG_TARGET, "Fetch input: {}", output_hash.to_hex());
let txn = self.read_transaction()?;
self.fetch_input_in_txn(&txn, input_hash.as_slice())
self.fetch_input_in_txn(&txn, output_hash.as_slice())
}

fn fetch_unspent_output_hash_by_commitment(
Expand Down
4 changes: 2 additions & 2 deletions base_layer/core/src/test_helpers/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ impl BlockchainBackend for TempDatabase {
self.db.as_ref().unwrap().fetch_output(output_hash)
}

fn fetch_input(&self, input_hash: &HashOutput) -> Result<Option<InputMinedInfo>, ChainStorageError> {
self.db.as_ref().unwrap().fetch_input(input_hash)
fn fetch_input(&self, output_hash: &HashOutput) -> Result<Option<InputMinedInfo>, ChainStorageError> {
self.db.as_ref().unwrap().fetch_input(output_hash)
}

fn fetch_unspent_output_hash_by_commitment(
Expand Down
Loading