Skip to content

Commit

Permalink
feat: better handling of blessed inscription turning cursed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludo Galabru committed Jul 31, 2023
1 parent f86b184 commit f11509a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
50 changes: 46 additions & 4 deletions components/hord-cli/src/hord/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,8 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data_tx(

for (tx_index, new_tx) in block.transactions.iter_mut().skip(1).enumerate() {
let mut ordinals_events_indexes_to_discard = VecDeque::new();
let mut ordinals_events_indexes_to_curse = VecDeque::new();

// Have a new inscription been revealed, if so, are looking at a re-inscription
for (ordinal_event_index, ordinal_event) in
new_tx.metadata.ordinal_operations.iter_mut().enumerate()
Expand All @@ -1649,7 +1651,7 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data_tx(
OrdinalOperation::InscriptionTransferred(_) => continue,
};

let inscription_number = if is_cursed {
let mut inscription_number = if is_cursed {
latest_cursed_inscription_number = if !latest_cursed_inscription_loaded {
latest_cursed_inscription_loaded = true;
match find_latest_cursed_inscription_number_at_block_height(
Expand Down Expand Up @@ -1749,16 +1751,35 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data_tx(
find_inscription_with_ordinal_number(&traversal.ordinal_number, &transaction, &ctx)
{
ctx.try_log(|logger| {
slog::warn!(
info!(
logger,
"Transaction {} in block {} is overriding an existing inscription {}",
new_tx.transaction_identifier.hash,
block.block_identifier.index,
traversal.ordinal_number
);
});
ordinals_events_indexes_to_discard.push_front(ordinal_event_index);
continue;

inscription_number = if !latest_cursed_inscription_loaded {
latest_cursed_inscription_loaded = true;
match find_latest_cursed_inscription_number_at_block_height(
&block.block_identifier.index,
&inscription_height_hint.cursed,
&transaction,
&ctx,
)? {
None => -1,
Some(inscription_number) => inscription_number - 1,
}
} else {
latest_cursed_inscription_number - 1
};
inscription.curse_type = Some(OrdinalInscriptionCurseType::Reinscription);

if !is_cursed {
ordinals_events_indexes_to_curse.push_front(ordinal_event_index);
latest_blessed_inscription_number += 1;
}
}

inscription.inscription_number = inscription_number;
Expand All @@ -1782,6 +1803,27 @@ pub fn update_storage_and_augment_bitcoin_block_with_inscription_reveal_data_tx(
storage_updated = true;
}

for index in ordinals_events_indexes_to_curse.into_iter() {
match new_tx.metadata.ordinal_operations.remove(index) {
OrdinalOperation::InscriptionRevealed(inscription_data)
| OrdinalOperation::CursedInscriptionRevealed(inscription_data) => {
ctx.try_log(|logger| {
slog::info!(
logger,
"Inscription {} (#{}) transitioned from blessed to cursed",
inscription_data.inscription_id,
inscription_data.inscription_number,
);
});
new_tx.metadata.ordinal_operations.insert(
index,
OrdinalOperation::CursedInscriptionRevealed(inscription_data),
);
}
_ => unreachable!(),
}
}

for index in ordinals_events_indexes_to_discard.into_iter() {
new_tx.metadata.ordinal_operations.remove(index);
}
Expand Down
13 changes: 8 additions & 5 deletions components/hord-cli/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ mod runloops;
use crate::cli::fetch_and_standardize_block;
use crate::config::{Config, PredicatesApi, PredicatesApiConfig};
use crate::db::{
find_all_inscriptions_in_block, format_satpoint_to_watch, insert_entry_in_locations,
open_readwrite_hord_db_conn, open_readwrite_hord_dbs, parse_satpoint_to_watch,
rebuild_rocks_db, remove_entries_from_locations_at_block_height, open_readwrite_hord_db_conn_rocks_db, delete_data_in_hord_db,
delete_data_in_hord_db, find_all_inscriptions_in_block, format_satpoint_to_watch,
insert_entry_in_locations, open_readwrite_hord_db_conn, open_readwrite_hord_db_conn_rocks_db,
open_readwrite_hord_dbs, parse_satpoint_to_watch, rebuild_rocks_db,
remove_entries_from_locations_at_block_height,
};
use crate::hord::ordinals::start_ordinals_number_processor;
use crate::hord::{
Expand Down Expand Up @@ -67,8 +68,10 @@ impl Service {

// Force rebuild
{
let blocks_db =
open_readwrite_hord_db_conn_rocks_db(&self.config.expected_cache_path(), &self.ctx)?;
let blocks_db = open_readwrite_hord_db_conn_rocks_db(
&self.config.expected_cache_path(),
&self.ctx,
)?;
let inscriptions_db_conn_rw =
open_readwrite_hord_db_conn(&self.config.expected_cache_path(), &self.ctx)?;

Expand Down

0 comments on commit f11509a

Please sign in to comment.