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

Unrecognized even tag unbound and negative #2359

Merged
merged 13 commits into from
Aug 29, 2023
Prev Previous commit
Next Next commit
quick fix
  • Loading branch information
raphjaph committed Aug 23, 2023
commit 605e7112813b9b7d7b72eba6175c3e58e91a7023
208 changes: 104 additions & 104 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2552,110 +2552,110 @@ mod tests {
}
}

// #[test]
// fn unrecognized_even_field_inscriptions_are_cursed_and_unbound() {
// for context in Context::configurations() {
// context.mine_blocks(1);
//
// let witness = envelope(&[
// b"ord",
// &[1],
// b"text/plain;charset=utf-8",
// &[2],
// b"bar",
// &[4],
// b"ord",
// ]);
//
// let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
// inputs: &[(1, 0, 0)],
// witness,
// ..Default::default()
// });
//
// let inscription_id = InscriptionId { txid, index: 0 };
//
// context.mine_blocks(1);
//
// context.index.assert_inscription_location(
// inscription_id,
// SatPoint {
// outpoint: unbound_outpoint(),
// offset: 0,
// },
// None,
// );
//
// assert_eq!(
// context
// .index
// .get_inscription_entry(inscription_id)
// .unwrap()
// .unwrap()
// .number,
// -1
// );
// }
// }

// #[test]
// fn cursed_inscriptions_assigned_negative_numbers() {
// for context in Context::configurations() {
// context.mine_blocks(1);
//
// let witness = envelope(&[
// b"ord",
// &[1],
// b"text/plain;charset=utf-8",
// &[2],
// b"bar",
// &[4],
// b"ord",
// ]);
//
// let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
// inputs: &[(1, 0, 0)],
// witness,
// ..Default::default()
// });
//
// let inscription_id = InscriptionId { txid, index: 0 };
//
// context.mine_blocks(1);
//
// assert_eq!(
// context
// .index
// .get_inscription_entry(inscription_id)
// .unwrap()
// .unwrap()
// .number,
// -1
// );
//
// let witness = envelope(&[b"ord", &[1], b"text/plain;charset=utf-8", &[66], b"zoo"]);
//
// 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
// .index
// .get_inscription_entry(inscription_id)
// .unwrap()
// .unwrap()
// .number,
// -2
// );
// }
// }
#[test]
fn unrecognized_even_field_inscriptions_are_cursed_and_unbound() {
for context in Context::configurations() {
context.mine_blocks(1);

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

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

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

context.mine_blocks(1);

context.index.assert_inscription_location(
inscription_id,
SatPoint {
outpoint: unbound_outpoint(),
offset: 0,
},
None,
);

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

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

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

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

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

context.mine_blocks(1);

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

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

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
.index
.get_inscription_entry(inscription_id)
.unwrap()
.unwrap()
.number,
-2
);
}
}

#[test]
// https://github.com/ordinals/ord/issues/2062
Expand Down
6 changes: 4 additions & 2 deletions src/index/updater/inscription_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
index: id_counter,
};

let curse = if inscription.tx_in_index != 0 {
let curse = if inscription.inscription.unrecognized_even_field {
Some(Curse::UnrecognizedEvenField)
} else if inscription.tx_in_index != 0 {
Some(Curse::NotInFirstInput)
} else if inscription.tx_in_offset != 0 {
Some(Curse::NotAtOffsetZero)
Expand Down Expand Up @@ -214,7 +216,7 @@ impl<'a, 'db, 'tx> InscriptionUpdater<'a, 'db, 'tx> {
curse.is_some()
};

let unbound = input_value == 0 || inscription.tx_in_offset != 0;
let unbound = input_value == 0 || inscription.tx_in_offset != 0 || curse == Some(Curse::UnrecognizedEvenField);

if curse.is_some() || unbound {
log::info!(
Expand Down
32 changes: 26 additions & 6 deletions src/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ pub(crate) enum Curse {
NotInFirstInput,
NotAtOffsetZero,
Reinscription,
UnrecognizedEvenField,
}

#[derive(Debug, PartialEq, Clone)]
pub struct Inscription {
body: Option<Vec<u8>>,
content_type: Option<Vec<u8>>,
pub(crate) unrecognized_even_field: bool,
}

#[derive(Debug, PartialEq, Clone)]
Expand All @@ -38,7 +40,7 @@ pub(crate) struct TransactionInscription {
impl Inscription {
#[cfg(test)]
pub(crate) fn new(content_type: Option<Vec<u8>>, body: Option<Vec<u8>>) -> Self {
Self { content_type, body }
Self { content_type, body, unrecognized_even_field: false }
}

pub(crate) fn from_transaction(tx: &Transaction) -> Vec<TransactionInscription> {
Expand Down Expand Up @@ -79,6 +81,7 @@ impl Inscription {
Ok(Self {
body: Some(body),
content_type: Some(content_type.into()),
unrecognized_even_field: false,
})
}

Expand Down Expand Up @@ -158,7 +161,7 @@ pub(crate) enum InscriptionError {
KeyPathSpend,
NoInscription,
Script(script::Error),
UnrecognizedEvenField,
UnrecognizedEvenField(Inscription),
}

type Result<T, E = InscriptionError> = std::result::Result<T, E>;
Expand Down Expand Up @@ -248,12 +251,20 @@ impl<'a> InscriptionParser<'a> {
for tag in fields.keys() {
if let Some(lsb) = tag.first() {
if lsb % 2 == 0 {
return Err(InscriptionError::UnrecognizedEvenField);
return Ok(Inscription {
body,
content_type,
unrecognized_even_field: true,
});
}
}
}

Ok(Inscription { body, content_type })
Ok(Inscription {
body,
content_type,
unrecognized_even_field: false,
})
}

fn advance(&mut self) -> Result<Instruction<'a>> {
Expand Down Expand Up @@ -411,6 +422,7 @@ mod tests {
Ok(vec![Inscription {
content_type: Some(b"text/plain;charset=utf-8".to_vec()),
body: None,
unrecognized_even_field: false,
}]),
);
}
Expand All @@ -422,6 +434,7 @@ mod tests {
Ok(vec![Inscription {
content_type: None,
body: Some(b"foo".to_vec()),
unrecognized_even_field: false,
}]),
);
}
Expand Down Expand Up @@ -752,6 +765,7 @@ mod tests {
&Inscription {
content_type: None,
body: None,
unrecognized_even_field: false,
}
.append_reveal_script(script::Builder::new()),
);
Expand All @@ -763,6 +777,7 @@ mod tests {
vec![Inscription {
content_type: None,
body: None,
unrecognized_even_field: false,
}]
);
}
Expand All @@ -774,15 +789,20 @@ mod tests {
Ok(vec![Inscription {
content_type: None,
body: None,
unrecognized_even_field: false,
}]),
);
}

#[test]
fn unknown_even_fields_are_valid_but_unbound() {
fn unknown_even_fields() {
assert_eq!(
InscriptionParser::parse(&envelope(&[b"ord", &[2], &[0]])),
Err(InscriptionError::UnrecognizedEvenField),
Ok(vec![Inscription {
content_type: None,
body: None,
unrecognized_even_field: true,
}]),
);
}
}