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

The Jubilee: uncurse new inscriptions after jubilee height #2656

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading