Skip to content

Commit

Permalink
node: adjust hash to id function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Neotamandua committed Dec 20, 2024
1 parent 8133760 commit b480d9a
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions node/src/database/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'db, DB: DBAccess> Ledger for DBTransaction<'db, DB> {
LightBlock {
header: header.clone(),
transactions_ids: txs.iter().map(|t| t.inner.id()).collect(),
faults_ids: faults.iter().map(|f| f.hash()).collect(),
faults_ids: faults.iter().map(|f| f.id()).collect(),
}
.write(&mut buf)?;

Expand Down Expand Up @@ -349,7 +349,7 @@ impl<'db, DB: DBAccess> Ledger for DBTransaction<'db, DB> {
for f in faults {
let mut d = vec![];
f.write(&mut d)?;
self.put_cf(cf, f.hash(), d)?;
self.put_cf(cf, f.id(), d)?;
}
}
self.store_block_label(header.height, &header.hash, label)?;
Expand Down Expand Up @@ -410,7 +410,7 @@ impl<'db, DB: DBAccess> Ledger for DBTransaction<'db, DB> {
self.inner.delete_cf(self.ledger_txs_cf, tx.id())?;
}
for f in b.faults() {
self.inner.delete_cf(self.ledger_faults_cf, f.hash())?;
self.inner.delete_cf(self.ledger_faults_cf, f.id())?;
}

self.inner.delete_cf(self.ledger_cf, b.header().hash)?;
Expand Down Expand Up @@ -1206,7 +1206,7 @@ impl node_data::Serializable for LightBlock {
let len = self.faults_ids.len() as u32;
w.write_all(&len.to_le_bytes())?;

// Write faults hashes
// Write faults id
for f_id in &self.faults_ids {
w.write_all(f_id)?;
}
Expand Down Expand Up @@ -1236,7 +1236,7 @@ impl node_data::Serializable for LightBlock {
// Read faults count
let len = Self::read_u32_le(r)?;

// Read faults hashes
// Read faults ids
let mut faults_ids = vec![];
for _ in 0..len {
let mut f_id = [0u8; 32];
Expand Down Expand Up @@ -1299,10 +1299,7 @@ mod tests {
// Assert all faults are fully fetched from ledger as
// well.
for pos in 0..b.faults().len() {
assert_eq!(
db_blk.faults()[pos].hash(),
b.faults()[pos].hash()
);
assert_eq!(db_blk.faults()[pos].id(), b.faults()[pos].id());
}
});

Expand Down

0 comments on commit b480d9a

Please sign in to comment.