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

Add option to skip indexing inscriptions #2900

Merged
merged 2 commits into from
Dec 24, 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
49 changes: 49 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,6 +1986,55 @@ mod tests {
}
}

#[test]
fn inscriptions_are_not_indexed_if_no_index_inscriptions_flag_is_set() {
let inscription = inscription("text/plain;charset=utf-8", "hello");
let template = TransactionTemplate {
inputs: &[(1, 0, 0, inscription.to_witness())],
..Default::default()
};

{
let context = Context::builder().build();
context.mine_blocks(1);
let txid = context.rpc_server.broadcast_tx(template.clone());
let inscription_id = InscriptionId { txid, index: 0 };
context.mine_blocks(1);

assert_eq!(
context.index.get_inscription_by_id(inscription_id).unwrap(),
Some(inscription)
);

assert_eq!(
context
.index
.get_inscription_satpoint_by_id(inscription_id)
.unwrap(),
Some(SatPoint {
outpoint: OutPoint { txid, vout: 0 },
offset: 0,
})
);
}

{
let context = Context::builder().arg("--no-index-inscriptions").build();
context.mine_blocks(1);
let txid = context.rpc_server.broadcast_tx(template);
let inscription_id = InscriptionId { txid, index: 0 };
context.mine_blocks(1);

assert_eq!(
context
.index
.get_inscription_satpoint_by_id(inscription_id)
.unwrap(),
None,
);
}
}

#[test]
fn list_first_coinbase_transaction() {
let context = Context::builder().arg("--index-sats").build();
Expand Down
5 changes: 3 additions & 2 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ impl<'index> Updater<'_> {

let mut outpoint_to_value = wtx.open_table(OUTPOINT_TO_VALUE)?;

let index_inscriptions = self.height >= index.first_inscription_height;
let index_inscriptions =
self.height >= index.first_inscription_height && !index.options.no_index_inscriptions;

if index_inscriptions {
// Send all missing input outpoints to be fetched right away
Expand Down Expand Up @@ -535,7 +536,7 @@ impl<'index> Updater<'_> {

outpoint_to_sat_ranges.insert(&OutPoint::null().store(), lost_sat_ranges.as_slice())?;
}
} else {
} else if index_inscriptions {
for (tx, txid) in block.txdata.iter().skip(1).chain(block.txdata.first()) {
inscription_updater.index_envelopes(tx, *txid, None)?;
}
Expand Down
7 changes: 7 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ pub(crate) struct Options {
pub(crate) index_runes: bool,
#[arg(long, help = "Track location of all satoshis.")]
pub(crate) index_sats: bool,
#[arg(
long,
short,
alias = "noindex_inscriptions",
help = "Do not index inscriptions."
)]
pub(crate) no_index_inscriptions: bool,
#[arg(long, short, help = "Use regtest. Equivalent to `--chain regtest`.")]
pub(crate) regtest: bool,
#[arg(long, help = "Connect to Bitcoin Core RPC at <RPC_URL>.")]
Expand Down
Loading