Skip to content

Commit

Permalink
Merge pull request #312 from hirosystems/fix/reboot
Browse files Browse the repository at this point in the history
fix: sequence misalignment caused in certain conditions
  • Loading branch information
Ludo Galabru committed Jun 11, 2024
2 parents 26d8ed9 + a76a037 commit 2b235d2
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 36 deletions.
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
## [2.2.0](https://github.com/hirosystems/ordhook/compare/v2.1.0...v2.2.0) (2024-05-24)


### Features

* add BRC-20 indexing ([#284](https://github.com/hirosystems/ordhook/issues/284)) ([729affb](https://github.com/hirosystems/ordhook/commit/729affb699d5cddaf6e2e41690d071ae9c4009fa))


### Bug Fixes

* issue [#296](https://github.com/hirosystems/ordhook/issues/296) ([#300](https://github.com/hirosystems/ordhook/issues/300)) ([7a8dca5](https://github.com/hirosystems/ordhook/commit/7a8dca53c116fb76e1e7d026c7cdf6863cd74ccd))

## [2.1.0](https://github.com/hirosystems/ordhook/compare/v2.0.1...v2.1.0) (2024-02-12)


### Features

* confirm before deleting blocks ([a5fee25](https://github.com/hirosystems/ordhook/commit/a5fee2520c23e6374d86d7effbbcbf304551f817))
* display git-commit ([3256427](https://github.com/hirosystems/ordhook/commit/3256427632e3443c988a3a096ad6208bfbaf58d4))
* extract additional data ([4141fd6](https://github.com/hirosystems/ordhook/commit/4141fd6cca2b742bb6f491f002a6bd1f9260d602))
* improve queue management ([d57ac75](https://github.com/hirosystems/ordhook/commit/d57ac758e143ae902bb7d92827c3a3a41bcea1da))
* improve transfers handling ([21ce9ca](https://github.com/hirosystems/ordhook/commit/21ce9caabdd3ce51874dc27775267048094c05f4))
* introduce stream-indexing flag ([9c9e2a5](https://github.com/hirosystems/ordhook/commit/9c9e2a57a529775baf73dd6095fde90f98926c51))
* locations are now ordinal_number centric (instead of inscription_id) ([d667958](https://github.com/hirosystems/ordhook/commit/d6679588fac9f7335e3072103882eb6a42c5d561))
* migrate to tcmalloc ([7d048a3](https://github.com/hirosystems/ordhook/commit/7d048a3128fc4809950c2aca85c7b139119a05c1))
* revisit config files ([1c80b67](https://github.com/hirosystems/ordhook/commit/1c80b67658a27057b12874e1d7ebfbc0d84dd287))


### Bug Fixes

* add unicity constraints, cascade changes ([4b81d1e](https://github.com/hirosystems/ordhook/commit/4b81d1ebe49cf544d51ed158feb75b414faa1c65))
* additional adjustments on pointers ([faacfc5](https://github.com/hirosystems/ordhook/commit/faacfc53ac5f798bf267feadfdcaf2bcb35bbe39))
* consider end_block when scanning ([2feb512](https://github.com/hirosystems/ordhook/commit/2feb5128a1c2c659e758616f36b93d336afa5a16))
* git-commit ENV ([203cfa3](https://github.com/hirosystems/ordhook/commit/203cfa39d024188fd6e151607b519bd3b04183dd))
* handle inscription pointers ([3ce1932](https://github.com/hirosystems/ordhook/commit/3ce1932a5465624379646e11329eb53a7eb5e4c7))
* imitate overflow behavior ([306f850](https://github.com/hirosystems/ordhook/commit/306f850e7f679b14161b9940a117507037adf0bd))
* jubilee block transition ([d1b995b](https://github.com/hirosystems/ordhook/commit/d1b995b460ebe857abf00debbadea3dc5cd7f724))
* jubilee increment ([4222d46](https://github.com/hirosystems/ordhook/commit/4222d46b164400e9d877ecbeb2c8e2fb47f145ae))
* observers.sqlite code path missing ([5076275](https://github.com/hirosystems/ordhook/commit/5076275153cc1e838931863469a0a04c407d35e5))
* ordinal_number data type ([0b54537](https://github.com/hirosystems/ordhook/commit/0b54537003132b07d86a0cb06de8d1583057467f))
* pointer ignored ([2db6f1f](https://github.com/hirosystems/ordhook/commit/2db6f1fb449e7f014cd5590bb95fb9f3c7b30712))
* satoshis computations duplicates ([22eb729](https://github.com/hirosystems/ordhook/commit/22eb729f33ee73432a1a6c0674bf27a605684b3c))
* simulate ord numbering bug ([5828f82](https://github.com/hirosystems/ordhook/commit/5828f820a717c447ed263bc9be893419834273cf))
* tests ([869b17e](https://github.com/hirosystems/ordhook/commit/869b17e1701dddc7fac8248f9c4ac98329d3a8eb))
* transfer duplicates ([0416cd8](https://github.com/hirosystems/ordhook/commit/0416cd8e50270ecb4b6f810f20947945b1b49fcb))
* transfer offset ([1c3a5dd](https://github.com/hirosystems/ordhook/commit/1c3a5ddae423b7d03a5e78182eed378cd847cf0e))
* transfer tracking ([8098673](https://github.com/hirosystems/ordhook/commit/80986734c8a59aca5247000e4c1af3ad624a46f7))
* typo ([eca79f0](https://github.com/hirosystems/ordhook/commit/eca79f0e92ae82843f55d2e270a02874ad4e1120))

## [2.0.1](https://github.com/hirosystems/ordhook/compare/v2.0.0...v2.0.1) (2024-01-08)


Expand Down
4 changes: 2 additions & 2 deletions components/ordhook-core/src/core/meta_protocols/brc20/mod.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
17 changes: 10 additions & 7 deletions components/ordhook-core/src/core/protocol/satoshi_tracking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/ordhook-core/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions components/ordhook-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
10 changes: 4 additions & 6 deletions components/ordhook-core/src/scan/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
15 changes: 11 additions & 4 deletions components/ordhook-core/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}",
Expand Down
5 changes: 3 additions & 2 deletions components/ordhook-sdk-js/src/ordinals_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -184,7 +185,7 @@ impl OrdinalsIndexingRunloop {
include_witness: None,
predicate: BitcoinPredicateType::OrdinalsProtocol(
OrdinalOperations::InscriptionFeed(InscriptionFeedData {
meta_protocols: None
meta_protocols: None,
}),
),
action: HookAction::Noop,
Expand Down

0 comments on commit 2b235d2

Please sign in to comment.