Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Edge Cases in Cursed Inscription Numbering Leading to rare Off-by-One-Bug #2209

Merged
merged 16 commits into from
Jun 23, 2023
Prev Previous commit
Next Next commit
Make era height chain dependent
  • Loading branch information
ordinally committed Jun 22, 2023
commit daa0c6d40dc9e17bf9752e1ea64ee22bb69a57e4
11 changes: 11 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ impl Chain {
}
}

pub(crate) fn cursed_era_start_height(self) -> u64 {
// deployment block height for ord 0.6.0 introducing cursed inscriptions on ordinals.com - everything before that is precursed.
// TODO: this is mainnet only, need to make this configurable
match self {
Self::Mainnet => 792_876,
Self::Regtest => 11,
Self::Signet => 38332, // FIXME
Self::Testnet => 18332,
}
}

pub(crate) fn inscription_content_size_limit(self) -> Option<usize> {
match self {
Self::Mainnet | Self::Regtest => None,
Expand Down
4 changes: 4 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ impl Index {
})
}

pub(crate) fn chain(&self) -> Chain {
self.options.chain()
}

pub(crate) fn get_unspent_outputs(&self, _wallet: Wallet) -> Result<BTreeMap<OutPoint, Amount>> {
let mut utxos = BTreeMap::new();
utxos.extend(
Expand Down
3 changes: 3 additions & 0 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) struct Updater {
outputs_cached: u64,
outputs_inserted_since_flush: u64,
outputs_traversed: u64,
chain: Chain,
}

impl Updater {
Expand Down Expand Up @@ -69,6 +70,7 @@ impl Updater {
outputs_cached: 0,
outputs_inserted_since_flush: 0,
outputs_traversed: 0,
chain: index.chain(),
};

updater.update_index(index, wtx)
Expand Down Expand Up @@ -437,6 +439,7 @@ impl Updater {
block.header.time,
unbound_inscriptions,
value_cache,
self.chain,
)?;

if self.index_sats {
Expand Down
9 changes: 5 additions & 4 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ pub(super) struct InscriptionUpdater<'a, 'db, 'tx> {
timestamp: u32,
pub(super) unbound_inscriptions: u64,
value_cache: &'a mut HashMap<OutPoint, u64>,
chain: Chain,
}

impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
const CURSED_ERA_START_HEIGHT: u64 = 792_876; // deployment block height for ord 0.6.0 introducing cursed inscriptions on ordinals.com - everything before that is precursed.
// TODO: this is mainnet only, need to make this configurable

pub(super) fn new(
height: u64,
id_to_satpoint: &'a mut Table<'db, 'tx, &'static InscriptionIdValue, &'static SatPointValue>,
Expand All @@ -63,6 +61,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
timestamp: u32,
unbound_inscriptions: u64,
value_cache: &'a mut HashMap<OutPoint, u64>,
chain: Chain,
) -> Result<Self> {
let next_cursed_number = number_to_id
.iter()?
Expand Down Expand Up @@ -95,6 +94,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
timestamp,
unbound_inscriptions,
value_cache,
chain,
})
}

Expand Down Expand Up @@ -199,7 +199,8 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
match self.id_to_entry.get(&inscription_id.store()) {
Ok(option) => option.map(|entry| {
let loaded_entry = InscriptionEntry::load(entry.value());
loaded_entry.number < 0 && loaded_entry.height < Self::CURSED_ERA_START_HEIGHT
loaded_entry.number < 0
&& loaded_entry.height < self.chain.cursed_era_start_height()
}),
Err(_) => None,
}
Expand Down