Skip to content

Commit

Permalink
node: change rocksdb to read new Label enum
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jun 25, 2024
1 parent f3b45ab commit 7d30b9f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions node/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution> ChainSrv<N, DB, VM> {
let genesis_blk = genesis::generate_state(state);
db.write().await.update(|t| {
// Persist genesis block
t.store_block(genesis_blk.header(), &[], Label::Final)
t.store_block(genesis_blk.header(), &[], Label::Final(0))
})?;

BlockWithLabel::new_with_label(genesis_blk, Label::Final)
BlockWithLabel::new_with_label(genesis_blk, Label::Final(0))
}
};

Expand Down
2 changes: 1 addition & 1 deletion node/src/chain/acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ impl<DB: database::DB, VM: vm::VMExecution, N: Network> Acceptor<N, DB, VM> {
let prev_height = tip.inner().header().height - 1;

for height in (0..prev_height).rev() {
if let Ok(Some((hash, Label::Final))) =
if let Ok(Some((hash, Label::Final(_)))) =
v.fetch_block_label_by_height(height)
{
if let Some(blk) = v.fetch_block(&hash)? {
Expand Down
25 changes: 13 additions & 12 deletions node/src/database/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,13 +443,14 @@ impl<'db, DB: DBAccess> Ledger for DBTransaction<'db, DB> {
Ok(self
.snapshot
.get_cf(self.ledger_height_cf, height.to_le_bytes())?
.filter(|v| v.len() == HASH_LEN + 1)
.map(|h| {
let mut hash = [0u8; HASH_LEN];
hash.copy_from_slice(&h.as_slice()[0..HASH_LEN]);
let label = Label::from(h[HASH_LEN]);
(hash, label)
}))

let label_buff = h[HASH_LEN..].to_vec();
Label::read(&mut &label_buff[..]).map(|label| (hash, label))
})
.transpose()?)
}
}

Expand Down Expand Up @@ -909,7 +910,7 @@ mod tests {
txn.store_block(
b.header(),
&to_spent_txs(b.txs()),
Label::Final,
Label::Final(3),
)?;
Ok(())
})
Expand Down Expand Up @@ -956,7 +957,7 @@ mod tests {
txn.store_block(
b.header(),
&to_spent_txs(b.txs()),
Label::Final,
Label::Final(3),
)
.expect("block to be stored");
});
Expand Down Expand Up @@ -985,7 +986,7 @@ mod tests {
txn.store_block(
b.header(),
&to_spent_txs(b.txs()),
Label::Final,
Label::Final(3),
)
.unwrap();

Expand Down Expand Up @@ -1139,7 +1140,7 @@ mod tests {
txn.store_block(
b.header(),
&to_spent_txs(b.txs()),
Label::Final,
Label::Final(3),
)?;
Ok(())
})
Expand Down Expand Up @@ -1173,7 +1174,7 @@ mod tests {
txn.store_block(
b.header(),
&to_spent_txs(b.txs()),
Label::Attested,
Label::Attested(3),
)?;
Ok(())
})
Expand Down Expand Up @@ -1203,7 +1204,7 @@ mod tests {
txn.store_block(
b.header(),
&to_spent_txs(b.txs()),
Label::Attested,
Label::Attested(3),
)?;
Ok(())
})
Expand All @@ -1216,7 +1217,7 @@ mod tests {
.expect("should not return error")
.expect("should find a block")
.1
.eq(&Label::Attested));
.eq(&Label::Attested(3)));
});
});
}
Expand All @@ -1235,7 +1236,7 @@ mod tests {
ut.store_block(
b.header(),
&to_spent_txs(b.txs()),
Label::Final,
Label::Final(3),
)?;
Ok(())
})
Expand Down

0 comments on commit 7d30b9f

Please sign in to comment.