diff --git a/ord.yaml b/ord.yaml index c49ef1e6f9..12915903ab 100644 --- a/ord.yaml +++ b/ord.yaml @@ -12,7 +12,6 @@ config: /var/lib/ord/ord.yaml config_dir: /var/lib/ord cookie_file: /var/lib/bitcoin/.cookie data_dir: /var/lib/ord -first_inscription_height: 100 height_limit: 1000 hidden: - 6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0 diff --git a/src/index.rs b/src/index.rs index 8bdeab8c75..94bafd85cb 100644 --- a/src/index.rs +++ b/src/index.rs @@ -186,7 +186,6 @@ pub struct Index { database: Database, durability: redb::Durability, event_sender: Option>, - first_inscription_height: u32, genesis_block_coinbase_transaction: Transaction, genesis_block_coinbase_txid: Txid, height_limit: Option, @@ -198,6 +197,7 @@ pub struct Index { path: PathBuf, settings: Settings, started: DateTime, + first_index_height: u32, unrecoverably_reorged: AtomicBool, } @@ -420,13 +420,23 @@ impl Index { let genesis_block_coinbase_transaction = settings.chain().genesis_block().coinbase().unwrap().clone(); + let first_index_height = if index_sats || index_addresses { + 0 + } else if index_inscriptions { + settings.first_inscription_height() + } else if index_runes { + settings.first_rune_height() + } else { + u32::MAX + }; + Ok(Self { genesis_block_coinbase_txid: genesis_block_coinbase_transaction.txid(), client, database, durability, event_sender, - first_inscription_height: settings.first_inscription_height(), + first_index_height, genesis_block_coinbase_transaction, height_limit: settings.height_limit(), index_addresses, @@ -441,6 +451,10 @@ impl Index { }) } + pub fn have_full_utxo_index(&self) -> bool { + self.first_index_height == 0 + } + /// Unlike normal outpoints, which are added to index on creation and removed /// when spent, the UTXO entry for special outpoints may be updated. /// @@ -1677,7 +1691,7 @@ impl Index { Ok( outpoint != OutPoint::null() && outpoint != self.settings.chain().genesis_coinbase_outpoint() - && if self.index_sats { + && if self.have_full_utxo_index() { self .database .begin_read()? @@ -2420,9 +2434,7 @@ mod tests { } { - let context = Context::builder() - .arg("--first-inscription-height=3") - .build(); + let context = Context::builder().chain(Chain::Mainnet).build(); context.mine_blocks(1); let txid = context.core.broadcast_tx(template); let inscription_id = InscriptionId { txid, index: 0 }; @@ -3009,53 +3021,6 @@ mod tests { } } - #[test] - fn missing_inputs_are_fetched_from_bitcoin_core() { - for args in [ - ["--first-inscription-height", "2"].as_slice(), - ["--first-inscription-height", "2", "--index-sats"].as_slice(), - ] { - let context = Context::builder().args(args).build(); - context.mine_blocks(1); - - let txid = context.core.broadcast_tx(TransactionTemplate { - inputs: &[(1, 0, 0, inscription("text/plain", "hello").to_witness())], - ..default() - }); - let inscription_id = InscriptionId { txid, index: 0 }; - - context.mine_blocks(1); - - context.index.assert_inscription_location( - inscription_id, - SatPoint { - outpoint: OutPoint { txid, vout: 0 }, - offset: 0, - }, - Some(50 * COIN_VALUE), - ); - - let send_txid = context.core.broadcast_tx(TransactionTemplate { - inputs: &[(2, 0, 0, Default::default()), (2, 1, 0, Default::default())], - ..default() - }); - - context.mine_blocks(1); - - context.index.assert_inscription_location( - inscription_id, - SatPoint { - outpoint: OutPoint { - txid: send_txid, - vout: 0, - }, - offset: 50 * COIN_VALUE, - }, - Some(50 * COIN_VALUE), - ); - } - } - #[test] fn one_input_fee_spent_inscriptions_are_tracked_correctly() { for context in Context::configurations() { @@ -3231,9 +3196,7 @@ mod tests { #[test] fn lost_sats_are_tracked_correctly() { - let context = Context::builder() - .args(["--index-sats", "--first-inscription-height", "10"]) - .build(); + let context = Context::builder().args(["--index-sats"]).build(); assert_eq!(context.index.statistic(Statistic::LostSats), 0); context.mine_blocks(1); @@ -3260,9 +3223,7 @@ mod tests { #[test] fn lost_sat_ranges_are_tracked_correctly() { - let context = Context::builder() - .args(["--index-sats", "--first-inscription-height", "10"]) - .build(); + let context = Context::builder().args(["--index-sats"]).build(); let null_ranges = || { context diff --git a/src/index/updater.rs b/src/index/updater.rs index 10ae049b4f..457b5fb046 100644 --- a/src/index/updater.rs +++ b/src/index/updater.rs @@ -71,7 +71,7 @@ impl<'index> Updater<'index> { Some(progress_bar) }; - let rx = Self::fetch_blocks_from(self.index, self.height, self.index.index_sats)?; + let rx = Self::fetch_blocks_from(self.index, self.height)?; let (mut output_sender, mut txout_receiver) = Self::spawn_fetcher(self.index)?; @@ -153,16 +153,15 @@ impl<'index> Updater<'index> { fn fetch_blocks_from( index: &Index, mut height: u32, - index_sats: bool, ) -> Result> { let (tx, rx) = std::sync::mpsc::sync_channel(32); + let first_index_height = index.first_index_height; + let height_limit = index.height_limit; let client = index.settings.bitcoin_rpc_client(None)?; - let first_inscription_height = index.first_inscription_height; - thread::spawn(move || loop { if let Some(height_limit) = height_limit { if height >= height_limit { @@ -170,7 +169,7 @@ impl<'index> Updater<'index> { } } - match Self::get_block_with_retries(&client, height, index_sats, first_inscription_height) { + match Self::get_block_with_retries(&client, height, first_index_height) { Ok(Some(block)) => { if let Err(err) = tx.send(block.into()) { log::info!("Block receiver disconnected: {err}"); @@ -192,8 +191,7 @@ impl<'index> Updater<'index> { fn get_block_with_retries( client: &Client, height: u32, - index_sats: bool, - first_inscription_height: u32, + first_index_height: u32, ) -> Result> { let mut errors = 0; loop { @@ -203,7 +201,7 @@ impl<'index> Updater<'index> { .and_then(|option| { option .map(|hash| { - if index_sats || height >= first_inscription_height { + if height >= first_index_height { Ok(client.get_block(&hash)?) } else { Ok(Block { @@ -425,8 +423,8 @@ impl<'index> Updater<'index> { wtx.open_table(SEQUENCE_NUMBER_TO_INSCRIPTION_ENTRY)?; let mut transaction_id_to_transaction = wtx.open_table(TRANSACTION_ID_TO_TRANSACTION)?; - let index_inscriptions = - self.height >= self.index.first_inscription_height && self.index.index_inscriptions; + let index_inscriptions = self.height >= self.index.settings.first_inscription_height() + && self.index.index_inscriptions; // If the receiver still has inputs something went wrong in the last // block and we shouldn't recover from this and commit the last block @@ -437,7 +435,7 @@ impl<'index> Updater<'index> { ); } - if !self.index.index_sats { + if !self.index.have_full_utxo_index() { // Send all missing input outpoints to be fetched let txids = block .txdata @@ -562,7 +560,7 @@ impl<'index> Updater<'index> { entry.value().to_buf() } else { - assert!(!self.index.index_sats); + assert!(!self.index.have_full_utxo_index()); let txout = txout_receiver.blocking_recv().map_err(|err| { anyhow!( "failed to get transaction for {}: {err}", diff --git a/src/options.rs b/src/options.rs index 2a53db7f93..987a896d66 100644 --- a/src/options.rs +++ b/src/options.rs @@ -38,11 +38,6 @@ pub struct Options { pub(crate) cookie_file: Option, #[arg(long, alias = "datadir", help = "Store index in .")] pub(crate) data_dir: Option, - #[arg( - long, - help = "Don't look for inscriptions below ." - )] - pub(crate) first_inscription_height: Option, #[arg(long, help = "Limit index to blocks.")] pub(crate) height_limit: Option, #[arg(long, help = "Use index at .")] diff --git a/src/settings.rs b/src/settings.rs index ee9ca610ab..a368a97e0a 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -14,7 +14,6 @@ pub struct Settings { config_dir: Option, cookie_file: Option, data_dir: Option, - first_inscription_height: Option, height_limit: Option, hidden: Option>, http_port: Option, @@ -120,9 +119,6 @@ impl Settings { config_dir: self.config_dir.or(source.config_dir), cookie_file: self.cookie_file.or(source.cookie_file), data_dir: self.data_dir.or(source.data_dir), - first_inscription_height: self - .first_inscription_height - .or(source.first_inscription_height), height_limit: self.height_limit.or(source.height_limit), hidden: Some( self @@ -166,7 +162,6 @@ impl Settings { config_dir: options.config_dir, cookie_file: options.cookie_file, data_dir: options.data_dir, - first_inscription_height: options.first_inscription_height, height_limit: options.height_limit, hidden: None, http_port: None, @@ -255,7 +250,6 @@ impl Settings { config_dir: get_path("CONFIG_DIR"), cookie_file: get_path("COOKIE_FILE"), data_dir: get_path("DATA_DIR"), - first_inscription_height: get_u32("FIRST_INSCRIPTION_HEIGHT")?, height_limit: get_u32("HEIGHT_LIMIT")?, hidden: inscriptions("HIDDEN")?, http_port: get_u16("HTTP_PORT")?, @@ -286,7 +280,6 @@ impl Settings { config_dir: None, cookie_file: None, data_dir: Some(dir.into()), - first_inscription_height: None, height_limit: None, hidden: None, http_port: None, @@ -354,13 +347,6 @@ impl Settings { config_dir: None, cookie_file: Some(cookie_file), data_dir: Some(data_dir), - first_inscription_height: Some(if self.integration_test { - 0 - } else { - self - .first_inscription_height - .unwrap_or_else(|| chain.first_inscription_height()) - }), height_limit: self.height_limit, hidden: self.hidden, http_port: self.http_port, @@ -516,7 +502,11 @@ impl Settings { } pub fn first_inscription_height(&self) -> u32 { - self.first_inscription_height.unwrap() + if self.integration_test { + 0 + } else { + self.chain.unwrap().first_inscription_height() + } } pub fn first_rune_height(&self) -> u32 { @@ -1021,7 +1011,6 @@ mod tests { ("CONFIG_DIR", "config dir"), ("COOKIE_FILE", "cookie file"), ("DATA_DIR", "/data/dir"), - ("FIRST_INSCRIPTION_HEIGHT", "2"), ("HEIGHT_LIMIT", "3"), ("HIDDEN", "6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0 703e5f7c49d82aab99e605af306b9a30e991e57d42f982908a962a81ac439832i0"), ("HTTP_PORT", "8080"), @@ -1055,7 +1044,6 @@ mod tests { config_dir: Some("config dir".into()), cookie_file: Some("cookie file".into()), data_dir: Some("/data/dir".into()), - first_inscription_height: Some(2), height_limit: Some(3), hidden: Some( vec![ @@ -1102,7 +1090,6 @@ mod tests { "--config-dir=config dir", "--cookie-file=cookie file", "--datadir=/data/dir", - "--first-inscription-height=2", "--height-limit=3", "--index-addresses", "--index-cache-size=4", @@ -1129,7 +1116,6 @@ mod tests { config_dir: Some("config dir".into()), cookie_file: Some("cookie file".into()), data_dir: Some("/data/dir".into()), - first_inscription_height: Some(2), height_limit: Some(3), hidden: None, http_port: None, diff --git a/tests/json_api.rs b/tests/json_api.rs index d4ef4de61b..ea754efb67 100644 --- a/tests/json_api.rs +++ b/tests/json_api.rs @@ -235,11 +235,7 @@ fn get_inscriptions() { fn get_inscriptions_in_block() { let core = mockcore::spawn(); - let ord = TestServer::spawn_with_server_args( - &core, - &["--index-sats", "--first-inscription-height", "0"], - &[], - ); + let ord = TestServer::spawn_with_server_args(&core, &["--index-sats"], &[]); create_wallet(&core, &ord); diff --git a/tests/settings.rs b/tests/settings.rs index 08738ca11d..4591092611 100644 --- a/tests/settings.rs +++ b/tests/settings.rs @@ -17,7 +17,6 @@ fn default() { "config_dir": null, "cookie_file": ".*\.cookie", "data_dir": ".*", - "first_inscription_height": 767430, "height_limit": null, "hidden": \[\], "http_port": null,