Skip to content

Commit

Permalink
fix: jubilee block transition
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Feb 12, 2024
1 parent 698be75 commit d1b995b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::{
},
inscription_sequencing::{
augment_block_with_ordinals_inscriptions_data_and_write_to_db_tx,
get_bitcoin_network, get_jubilee_block_height,
parallelize_inscription_data_computations, SequenceCursor,
},
satoshi_tracking::augment_block_with_ordinals_transfer_data,
Expand Down Expand Up @@ -190,6 +191,13 @@ pub fn process_blocks(
ctx,
);

// Invalidate and recompute cursor when crossing the jubilee height
let jubilee_height =
get_jubilee_block_height(&get_bitcoin_network(&block.metadata.network));
if block.block_identifier.index == jubilee_height {
sequence_cursor.reset();
}

let _ = process_block(
&mut block,
&next_blocks,
Expand Down
44 changes: 23 additions & 21 deletions components/ordhook-core/src/core/protocol/inscription_sequencing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,8 @@ impl<'a> SequenceCursor<'a> {
true => self.pick_next_neg_classic(ctx),
false => self.pick_next_pos_classic(ctx),
};
let jubilee_height = match network {
Network::Bitcoin => 824544,
Network::Regtest => 110,
Network::Signet => 175392,
Network::Testnet => 2544192,
_ => unreachable!(),
};
let jubilee = if block_height >= jubilee_height {

let jubilee = if block_height >= get_jubilee_block_height(&network) {
self.pick_next_jubilee_number(ctx)
} else {
classic
Expand Down Expand Up @@ -538,6 +532,25 @@ impl<'a> SequenceCursor<'a> {
}
}

pub fn get_jubilee_block_height(network: &Network) -> u64 {
match network {
Network::Bitcoin => 824544,
Network::Regtest => 110,
Network::Signet => 175392,
Network::Testnet => 2544192,
_ => unreachable!(),
}
}

pub fn get_bitcoin_network(network: &BitcoinNetwork) -> Network {
match network {
BitcoinNetwork::Mainnet => Network::Bitcoin,
BitcoinNetwork::Regtest => Network::Regtest,
BitcoinNetwork::Testnet => Network::Testnet,
BitcoinNetwork::Signet => Network::Signet,
}
}

/// Given a `BitcoinBlockData` that have been augmented with the functions `parse_inscriptions_in_raw_tx`, `parse_inscriptions_in_standardized_tx`
/// or `parse_inscriptions_and_standardize_block`, mutate the ordinals drafted informations with actual, consensus data.
///
Expand Down Expand Up @@ -598,12 +611,7 @@ pub fn augment_block_with_ordinals_inscriptions_data(
let mut sats_overflows = VecDeque::new();
let mut any_event = false;

let network = match block.metadata.network {
BitcoinNetwork::Mainnet => Network::Bitcoin,
BitcoinNetwork::Regtest => Network::Regtest,
BitcoinNetwork::Testnet => Network::Testnet,
BitcoinNetwork::Signet => Network::Signet,
};
let network = get_bitcoin_network(&block.metadata.network);
let coinbase_subsidy = Height(block.block_identifier.index).subsidy();
let coinbase_txid = &block.transactions[0].transaction_identifier.clone();
let mut cumulated_fees = 0u64;
Expand Down Expand Up @@ -915,13 +923,7 @@ pub fn consolidate_block_with_pre_computed_ordinals_data(
include_transfers: bool,
ctx: &Context,
) {
let network = match block.metadata.network {
BitcoinNetwork::Mainnet => Network::Bitcoin,
BitcoinNetwork::Regtest => Network::Regtest,
BitcoinNetwork::Testnet => Network::Testnet,
BitcoinNetwork::Signet => Network::Signet,
};

let network = get_bitcoin_network(&block.metadata.network);
let coinbase_subsidy = Height(block.block_identifier.index).subsidy();
let coinbase_txid = &block.transactions[0].transaction_identifier.clone();
let mut cumulated_fees = 0;
Expand Down
10 changes: 3 additions & 7 deletions components/ordhook-core/src/core/protocol/satoshi_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ use crate::{
};
use rusqlite::Transaction;

use super::inscription_sequencing::get_bitcoin_network;

pub fn augment_block_with_ordinals_transfer_data(
block: &mut BitcoinBlockData,
inscriptions_db_tx: &Transaction,
Expand All @@ -27,13 +29,7 @@ pub fn augment_block_with_ordinals_transfer_data(
) -> bool {
let mut any_event = false;

let network = match block.metadata.network {
BitcoinNetwork::Mainnet => Network::Bitcoin,
BitcoinNetwork::Regtest => Network::Regtest,
BitcoinNetwork::Testnet => Network::Testnet,
BitcoinNetwork::Signet => Network::Signet,
};

let network = get_bitcoin_network(&block.metadata.network);
let coinbase_subsidy = Height(block.block_identifier.index).subsidy();
let coinbase_txid = &block.transactions[0].transaction_identifier.clone();
let mut cumulated_fees = 0;
Expand Down

0 comments on commit d1b995b

Please sign in to comment.