mirror of
https://github.com/serai-dex/serai.git
synced 2025-03-21 06:38:56 +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.reverse();
|
||||||
hash
|
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 {
|
fn median_fee(&self) -> Fee {
|
||||||
// TODO
|
// TODO
|
||||||
Fee(20)
|
Fee(20)
|
||||||
|
|
|
@ -175,6 +175,7 @@ pub trait Block<C: Coin>: Send + Sync + Sized + Clone + Debug {
|
||||||
// This is currently bounded to being 32-bytes.
|
// This is currently bounded to being 32-bytes.
|
||||||
type Id: 'static + Id;
|
type Id: 'static + Id;
|
||||||
fn id(&self) -> Self::Id;
|
fn id(&self) -> Self::Id;
|
||||||
|
fn parent(&self) -> Self::Id;
|
||||||
fn median_fee(&self) -> C::Fee;
|
fn median_fee(&self) -> C::Fee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,6 +142,10 @@ impl BlockTrait<Monero> for Block {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parent(&self) -> Self::Id {
|
||||||
|
self.1.header.previous
|
||||||
|
}
|
||||||
|
|
||||||
fn median_fee(&self) -> Fee {
|
fn median_fee(&self) -> Fee {
|
||||||
// TODO
|
// TODO
|
||||||
Fee { per_weight: 80000, mask: 10000 }
|
Fee { per_weight: 80000, mask: 10000 }
|
||||||
|
|
|
@ -395,12 +395,22 @@ impl<C: Coin, D: Db> Scanner<C, D> {
|
||||||
let block_id = block.id();
|
let block_id = block.id();
|
||||||
|
|
||||||
if let Some(id) = ScannerDb::<C, D>::block(&scanner.db.0, i) {
|
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 {
|
if id != block_id {
|
||||||
panic!("reorg'd from finalized {} to {}", hex::encode(id), hex::encode(block_id));
|
panic!("reorg'd from finalized {} to {}", hex::encode(id), hex::encode(block_id));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("Found new block: {}", hex::encode(&block_id));
|
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();
|
let mut txn = scanner.db.0.txn();
|
||||||
ScannerDb::<C, D>::save_block(&mut txn, i, &block_id);
|
ScannerDb::<C, D>::save_block(&mut txn, i, &block_id);
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
|
Loading…
Reference in a new issue