Skip to content

Commit

Permalink
Bless cursed inscriptions after Jubilee height (#2656)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Nov 30, 2023
1 parent 3cbbdce commit 78f10da
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ impl Chain {
}
}

pub(crate) fn jubilee_height(self) -> u32 {
match self {
Self::Mainnet => 824544,
Self::Regtest => 110,
Self::Signet => 175392,
Self::Testnet => 2544192,
}
}

pub(crate) fn genesis_block(self) -> Block {
bitcoin::blockdata::constants::genesis_block(self.network())
}
Expand Down
57 changes: 57 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3043,6 +3043,63 @@ mod tests {
}
}

#[test]
fn inscriptions_are_uncursed_after_jubilee() {
for context in Context::configurations() {
context.mine_blocks(108);

let witness = envelope(&[
b"ord",
&[1],
b"text/plain;charset=utf-8",
&[1],
b"text/plain;charset=utf-8",
]);

let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0, witness.clone())],
..Default::default()
});

let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

assert_eq!(context.rpc_server.height(), 109);

assert_eq!(
context
.index
.get_inscription_entry(inscription_id)
.unwrap()
.unwrap()
.inscription_number,
-1
);

let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(2, 0, 0, witness)],
..Default::default()
});

let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

assert_eq!(context.rpc_server.height(), 110);

assert_eq!(
context
.index
.get_inscription_entry(inscription_id)
.unwrap()
.unwrap()
.inscription_number,
0
);
}
}

#[test]
fn duplicate_field_inscriptions_are_cursed() {
for context in Context::configurations() {
Expand Down
1 change: 1 addition & 0 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ impl<'index> Updater<'_> {

let mut inscription_updater = InscriptionUpdater {
blessed_inscription_count,
chain: self.index.options.chain(),
cursed_inscription_count,
flotsam: Vec::new(),
height: self.height,
Expand Down
5 changes: 4 additions & 1 deletion src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum Origin {

pub(super) struct InscriptionUpdater<'a, 'db, 'tx> {
pub(super) blessed_inscription_count: u64,
pub(super) chain: Chain,
pub(super) cursed_inscription_count: u64,
pub(super) flotsam: Vec<Flotsam>,
pub(super) height: u32,
Expand Down Expand Up @@ -135,7 +136,9 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {

let inscribed_offset = inscribed_offsets.get(&offset);

let curse = if inscription.payload.unrecognized_even_field {
let curse = if self.height >= self.chain.jubilee_height() {
None
} else if inscription.payload.unrecognized_even_field {
Some(Curse::UnrecognizedEvenField)
} else if inscription.payload.duplicate_field {
Some(Curse::DuplicateField)
Expand Down
4 changes: 4 additions & 0 deletions test-bitcoincore-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ impl Handle {
self.state().broadcast_tx(template)
}

pub fn height(&self) -> u64 {
u64::try_from(self.state().blocks.len()).unwrap() - 1
}

pub fn invalidate_tip(&self) -> BlockHash {
self.state().pop_block()
}
Expand Down

0 comments on commit 78f10da

Please sign in to comment.