This commit is contained in:
Luke Parker 2023-04-16 01:03:32 -04:00
parent 79655672ef
commit 9676584ffe
No known key found for this signature in database
4 changed files with 23 additions and 1 deletions

View file

@ -197,6 +197,13 @@ impl BlockTrait<Bitcoin> for Block {
hash.reverse();
hash
}
fn parent(&self) -> Self::Id {
let mut hash = *self.header.prev_blockhash.as_raw_hash().as_byte_array();
hash.reverse();
hash
}
fn median_fee(&self) -> Fee {
// TODO
Fee(20)

View file

@ -175,6 +175,7 @@ pub trait Block<C: Coin>: Send + Sync + Sized + Clone + Debug {
// This is currently bounded to being 32-bytes.
type Id: 'static + Id;
fn id(&self) -> Self::Id;
fn parent(&self) -> Self::Id;
fn median_fee(&self) -> C::Fee;
}

View file

@ -142,6 +142,10 @@ impl BlockTrait<Monero> for Block {
self.0
}
fn parent(&self) -> Self::Id {
self.1.header.previous
}
fn median_fee(&self) -> Fee {
// TODO
Fee { per_weight: 80000, mask: 10000 }

View file

@ -395,12 +395,22 @@ impl<C: Coin, D: Db> Scanner<C, D> {
let block_id = block.id();
if let Some(id) = ScannerDb::<C, D>::block(&scanner.db.0, i) {
// TODO2: Also check this block builds off the previous block
if id != block_id {
panic!("reorg'd from finalized {} to {}", hex::encode(id), hex::encode(block_id));
}
} else {
info!("Found new block: {}", hex::encode(&block_id));
if let Some(id) = ScannerDb::<C, D>::block(&scanner.db.0, i.saturating_sub(1)) {
if id != block.parent() {
panic!(
"block {} doesn't build off expected parent {}",
hex::encode(block_id),
hex::encode(id),
);
}
}
let mut txn = scanner.db.0.txn();
ScannerDb::<C, D>::save_block(&mut txn, i, &block_id);
txn.commit();