mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Resolve #245
This commit is contained in:
parent
79655672ef
commit
9676584ffe
4 changed files with 23 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue