mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-04-30 04:35:04 +08:00
Merge pull request #312 from hirosystems/fix/reboot
fix: sequence misalignment caused in certain conditions
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
use chainhook_sdk::types::BitcoinNetwork;
|
||||
|
||||
pub mod cache;
|
||||
pub mod db;
|
||||
pub mod parser;
|
||||
pub mod verifier;
|
||||
pub mod cache;
|
||||
pub mod test_utils;
|
||||
pub mod verifier;
|
||||
|
||||
pub fn brc20_activation_height(network: &BitcoinNetwork) -> u64 {
|
||||
match network {
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
use chainhook_sdk::{types::{OrdinalInscriptionNumber, OrdinalInscriptionRevealData, OrdinalInscriptionTransferData, OrdinalInscriptionTransferDestination}, utils::Context};
|
||||
use chainhook_sdk::{
|
||||
types::{
|
||||
OrdinalInscriptionNumber, OrdinalInscriptionRevealData, OrdinalInscriptionTransferData,
|
||||
OrdinalInscriptionTransferDestination,
|
||||
},
|
||||
utils::Context,
|
||||
};
|
||||
|
||||
pub fn get_test_ctx() -> Context {
|
||||
let logger = hiro_system_kit::log::setup_logger();
|
||||
@@ -25,8 +31,8 @@ impl Brc20RevealBuilder {
|
||||
jubilee: 0,
|
||||
},
|
||||
inscriber_address: Some("324A7GHA2azecbVBAFy4pzEhcPT1GjbUAp".to_string()),
|
||||
inscription_id:
|
||||
"9bb2314d666ae0b1db8161cb373fcc1381681f71445c4e0335aa80ea9c37fcddi0".to_string(),
|
||||
inscription_id: "9bb2314d666ae0b1db8161cb373fcc1381681f71445c4e0335aa80ea9c37fcddi0"
|
||||
.to_string(),
|
||||
ordinal_number: 0,
|
||||
parent: None,
|
||||
}
|
||||
@@ -82,8 +88,7 @@ impl Brc20RevealBuilder {
|
||||
tx_index: 0,
|
||||
transfers_pre_inscription: 0,
|
||||
satpoint_post_inscription:
|
||||
"9bb2314d666ae0b1db8161cb373fcc1381681f71445c4e0335aa80ea9c37fcdd:0:0"
|
||||
.to_string(),
|
||||
"9bb2314d666ae0b1db8161cb373fcc1381681f71445c4e0335aa80ea9c37fcdd:0:0".to_string(),
|
||||
curse_type: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,13 +148,13 @@ pub fn verify_brc20_operation(
|
||||
token.tick, data.amt
|
||||
));
|
||||
}
|
||||
let Some(avail_balance) = cache.get_token_address_avail_balance(
|
||||
&token.tick,
|
||||
&inscriber_address,
|
||||
db_tx,
|
||||
ctx,
|
||||
) else {
|
||||
return Err(format!("Balance does not exist for {} transfer, attempting to transfer {}", token.tick, data.amt));
|
||||
let Some(avail_balance) =
|
||||
cache.get_token_address_avail_balance(&token.tick, &inscriber_address, db_tx, ctx)
|
||||
else {
|
||||
return Err(format!(
|
||||
"Balance does not exist for {} transfer, attempting to transfer {}",
|
||||
token.tick, data.amt
|
||||
));
|
||||
};
|
||||
if avail_balance < data.float_amt() {
|
||||
return Err(format!("Insufficient balance for {} transfer, attempting to transfer {}, only {} available", token.tick, data.amt, avail_balance));
|
||||
|
||||
@@ -139,7 +139,12 @@ pub fn compute_satpoint_post_transfer(
|
||||
SatPosition::Fee(offset) => {
|
||||
// Get Coinbase TX
|
||||
let total_offset = coinbase_subsidy + *cumulated_fees + offset;
|
||||
let outputs = coinbase_tx.metadata.outputs.iter().map(|o| o.value).collect();
|
||||
let outputs = coinbase_tx
|
||||
.metadata
|
||||
.outputs
|
||||
.iter()
|
||||
.map(|o| o.value)
|
||||
.collect();
|
||||
let post_transfer_data = compute_next_satpoint_data(
|
||||
0,
|
||||
&vec![total_offset],
|
||||
@@ -153,16 +158,14 @@ pub fn compute_satpoint_post_transfer(
|
||||
SatPosition::Output(pos) => pos,
|
||||
_ => {
|
||||
ctx.try_log(|logger| {
|
||||
info!(
|
||||
logger,
|
||||
"unable to locate satoshi in coinbase outputs",
|
||||
)
|
||||
});
|
||||
info!(logger, "unable to locate satoshi in coinbase outputs",)
|
||||
});
|
||||
(0, total_offset)
|
||||
}
|
||||
};
|
||||
|
||||
let outpoint = format_outpoint_to_watch(&coinbase_tx.transaction_identifier, output_index);
|
||||
let outpoint =
|
||||
format_outpoint_to_watch(&coinbase_tx.transaction_identifier, output_index);
|
||||
(
|
||||
outpoint,
|
||||
offset,
|
||||
|
||||
@@ -809,7 +809,7 @@ pub fn find_latest_inscription_block_height(
|
||||
ctx: &Context,
|
||||
) -> Result<Option<u64>, String> {
|
||||
let args: &[&dyn ToSql] = &[];
|
||||
let query = "SELECT block_height FROM inscriptions ORDER BY block_height DESC LIMIT 1";
|
||||
let query = "SELECT block_height FROM sequence_metadata ORDER BY block_height DESC LIMIT 1";
|
||||
let entry = perform_query_one(query, args, db_conn, ctx, |row| {
|
||||
let block_height: u64 = row.get(0).unwrap();
|
||||
block_height
|
||||
|
||||
@@ -40,8 +40,11 @@ pub fn initialize_db(config: &Config, ctx: &Context) -> DbConnections {
|
||||
DbConnections {
|
||||
ordhook: initialize_ordhook_db(&config.expected_cache_path(), ctx),
|
||||
brc20: match config.meta_protocols.brc20 {
|
||||
true => Some(initialize_brc20_db(Some(&config.expected_cache_path()), ctx)),
|
||||
false => None
|
||||
true => Some(initialize_brc20_db(
|
||||
Some(&config.expected_cache_path()),
|
||||
ctx,
|
||||
)),
|
||||
false => None,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,12 +104,10 @@ pub async fn scan_bitcoin_chainstate_via_rpc_using_predicate(
|
||||
let brc20_db_conn = match predicate_spec.predicate {
|
||||
BitcoinPredicateType::OrdinalsProtocol(OrdinalOperations::InscriptionFeed(
|
||||
ref feed_data,
|
||||
)) if feed_data.meta_protocols.is_some() => {
|
||||
Some(open_readonly_brc20_db_conn(
|
||||
&config.expected_cache_path(),
|
||||
ctx,
|
||||
)?)
|
||||
}
|
||||
)) if feed_data.meta_protocols.is_some() => Some(open_readonly_brc20_db_conn(
|
||||
&config.expected_cache_path(),
|
||||
ctx,
|
||||
)?),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ use crate::core::protocol::inscription_parsing::{
|
||||
use crate::core::protocol::inscription_sequencing::SequenceCursor;
|
||||
use crate::core::{new_traversals_lazy_cache, should_sync_ordhook_db, should_sync_rocks_db};
|
||||
use crate::db::{
|
||||
delete_data_in_ordhook_db, insert_entry_in_blocks, open_ordhook_db_conn_rocks_db_loop,
|
||||
open_readwrite_ordhook_dbs, update_ordinals_db_with_block, BlockBytesCursor,
|
||||
TransactionBytesCursor,
|
||||
delete_data_in_ordhook_db, find_latest_inscription_block_height, insert_entry_in_blocks,
|
||||
open_ordhook_db_conn_rocks_db_loop, open_readonly_ordhook_db_conn, open_readwrite_ordhook_dbs,
|
||||
update_ordinals_db_with_block, BlockBytesCursor, TransactionBytesCursor,
|
||||
};
|
||||
use crate::db::{
|
||||
find_last_block_inserted, find_missing_blocks, run_compaction,
|
||||
@@ -489,7 +489,14 @@ impl Service {
|
||||
self.config.resources.memory_available,
|
||||
&self.ctx,
|
||||
);
|
||||
let tip = find_last_block_inserted(&blocks_db);
|
||||
|
||||
let ordhook_db = open_readonly_ordhook_db_conn(
|
||||
&self.config.expected_cache_path(),
|
||||
&self.ctx,
|
||||
)
|
||||
.expect("unable to retrieve ordhook db");
|
||||
let tip = find_latest_inscription_block_height(&ordhook_db, &self.ctx)?.unwrap()
|
||||
as u32;
|
||||
info!(
|
||||
self.ctx.expect_logger(),
|
||||
"Checking database integrity up to block #{tip}",
|
||||
|
||||
@@ -6,7 +6,8 @@ use napi::threadsafe_function::{
|
||||
};
|
||||
use ordhook::chainhook_sdk::chainhooks::bitcoin::BitcoinTransactionPayload;
|
||||
use ordhook::chainhook_sdk::chainhooks::types::{
|
||||
BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType, HookAction, InscriptionFeedData, OrdinalOperations
|
||||
BitcoinChainhookFullSpecification, BitcoinChainhookNetworkSpecification, BitcoinPredicateType,
|
||||
HookAction, InscriptionFeedData, OrdinalOperations,
|
||||
};
|
||||
use ordhook::chainhook_sdk::observer::DataHandlerEvent;
|
||||
use ordhook::chainhook_sdk::utils::{BlockHeights, Context as OrdhookContext};
|
||||
@@ -184,7 +185,7 @@ impl OrdinalsIndexingRunloop {
|
||||
include_witness: None,
|
||||
predicate: BitcoinPredicateType::OrdinalsProtocol(
|
||||
OrdinalOperations::InscriptionFeed(InscriptionFeedData {
|
||||
meta_protocols: None
|
||||
meta_protocols: None,
|
||||
}),
|
||||
),
|
||||
action: HookAction::Noop,
|
||||
|
||||
Reference in New Issue
Block a user