Skip to content

Commit

Permalink
Change --index-ordinals to --index-satoshis (ordinals#942)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 12, 2022
1 parent 0b25c9f commit d67a1df
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 95 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
`ord`
=====

`ord` is an ordinal index, block explorer, and command-line ordinal wallet.
`ord` is an index, block explorer, and command-line wallet.

Ordinals are serial numbers for satoshis, assigned in the order in which they
are mined, and preserved across transactions.
Expand Down Expand Up @@ -140,15 +140,6 @@ so be prepared to delete and re-sync the index.
$ RUST_LOG=info cargo run server
```

Index
-----

The mainnet ordinal index is currently 50 GiB, and will increase in size in the
future, both as the Bitcoin blockchain grows, and as additional tables are
added to the index.

The signet ordinal index is much smaller, clocking in at 1.3 GiB.

Reorgs
------

Expand Down
2 changes: 1 addition & 1 deletion deploy/ord-dev.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ExecStart=/usr/local/bin/ord-dev \
--bitcoin-data-dir /var/lib/bitcoind \
--chain ${CHAIN} \
--data-dir /var/lib/ord-dev \
--index-ordinals \
--index-satoshis \
server \
--http-port 8080
Group=ord
Expand Down
2 changes: 1 addition & 1 deletion deploy/ord.service
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ExecStart=/usr/local/bin/ord \
--bitcoin-data-dir /var/lib/bitcoind \
--data-dir /var/lib/ord \
--chain ${CHAIN} \
--index-ordinals \
--index-satoshis \
server \
--acme-contact mailto:[email protected] \
--http \
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guides/ordinal-hunting.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Ordinal Hunting
===============

*This guide is out of date. Since it was written, the `ord` binary was changed
to only build the full ordinal index when the `--ordinal-index` flag is
to only build the full satoshi index when the `--index-satoshis` flag is
supplied. Additionally, `ord` now has a built-in wallet that wraps a Bitcoin
Core wallet. See `ord wallet --help`.*

Expand Down
46 changes: 23 additions & 23 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ impl Index {
tx.open_table(STATISTIC_TO_COUNT)?;
tx.open_table(WRITE_TRANSACTION_STARTING_BLOCK_COUNT_TO_TIMESTAMP)?;

if options.index_ordinals {
if options.index_satoshis {
tx.open_table(OUTPOINT_TO_ORDINAL_RANGES)?;
}

Expand Down Expand Up @@ -238,17 +238,17 @@ impl Index {
})
}

pub(crate) fn has_ordinal_index(&self) -> Result<bool> {
pub(crate) fn has_satoshi_index(&self) -> Result<bool> {
match self.begin_read()?.0.open_table(OUTPOINT_TO_ORDINAL_RANGES) {
Ok(_) => Ok(true),
Err(redb::Error::TableDoesNotExist(_)) => Ok(false),
Err(err) => Err(err.into()),
}
}

fn require_ordinal_index(&self, feature: &str) -> Result {
if !self.has_ordinal_index()? {
bail!("{feature} requires index created with `--index-ordinals` flag")
fn require_satoshi_index(&self, feature: &str) -> Result {
if !self.has_satoshi_index()? {
bail!("{feature} requires index created with `--index-satoshis` flag")
}

Ok(())
Expand Down Expand Up @@ -385,7 +385,7 @@ impl Index {
}

pub(crate) fn rare_ordinal_satpoints(&self) -> Result<Option<Vec<(Ordinal, SatPoint)>>> {
if self.has_ordinal_index()? {
if self.has_satoshi_index()? {
let mut result = Vec::new();

let rtx = self.database.begin_read()?;
Expand Down Expand Up @@ -484,7 +484,7 @@ impl Index {
}

pub(crate) fn find(&self, ordinal: u64) -> Result<Option<SatPoint>> {
self.require_ordinal_index("find")?;
self.require_satoshi_index("find")?;

let rtx = self.begin_read()?;

Expand Down Expand Up @@ -524,7 +524,7 @@ impl Index {
}

pub(crate) fn list(&self, outpoint: OutPoint) -> Result<Option<List>> {
self.require_ordinal_index("list")?;
self.require_satoshi_index("list")?;

let outpoint_encoded = encode_outpoint(outpoint);

Expand Down Expand Up @@ -662,7 +662,7 @@ mod tests {

#[test]
fn list_first_coinbase_transaction() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
assert_eq!(
context
.index
Expand All @@ -679,7 +679,7 @@ mod tests {

#[test]
fn list_second_coinbase_transaction() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
let txid = context.rpc_server.mine_blocks(1)[0].txdata[0].txid();
context.index.update().unwrap();
assert_eq!(
Expand All @@ -690,7 +690,7 @@ mod tests {

#[test]
fn list_split_ranges_are_tracked_correctly() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");

context.rpc_server.mine_blocks(1);
let split_coinbase_output = TransactionTemplate {
Expand All @@ -716,7 +716,7 @@ mod tests {

#[test]
fn list_merge_ranges_are_tracked_correctly() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");

context.rpc_server.mine_blocks(2);
let merge_coinbase_outputs = TransactionTemplate {
Expand All @@ -740,7 +740,7 @@ mod tests {

#[test]
fn list_fee_paying_transaction_range() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");

context.rpc_server.mine_blocks(1);
let fee_paying_tx = TransactionTemplate {
Expand Down Expand Up @@ -774,7 +774,7 @@ mod tests {

#[test]
fn list_two_fee_paying_transaction_range() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");

context.rpc_server.mine_blocks(2);
let first_fee_paying_tx = TransactionTemplate {
Expand Down Expand Up @@ -809,7 +809,7 @@ mod tests {

#[test]
fn list_null_output() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");

context.rpc_server.mine_blocks(1);
let no_value_output = TransactionTemplate {
Expand All @@ -829,7 +829,7 @@ mod tests {

#[test]
fn list_null_input() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");

context.rpc_server.mine_blocks(1);
let no_value_output = TransactionTemplate {
Expand Down Expand Up @@ -857,7 +857,7 @@ mod tests {

#[test]
fn list_spent_output() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
context.rpc_server.mine_blocks(1);
context.rpc_server.broadcast_tx(TransactionTemplate {
input_slots: &[(1, 0, 0)],
Expand All @@ -875,7 +875,7 @@ mod tests {

#[test]
fn list_unknown_output() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");

assert_eq!(
context
Expand All @@ -892,7 +892,7 @@ mod tests {

#[test]
fn find_first_ordinal() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
assert_eq!(
context.index.find(0).unwrap().unwrap(),
SatPoint {
Expand All @@ -906,7 +906,7 @@ mod tests {

#[test]
fn find_second_ordinal() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
assert_eq!(
context.index.find(1).unwrap().unwrap(),
SatPoint {
Expand All @@ -920,7 +920,7 @@ mod tests {

#[test]
fn find_first_ordinal_of_second_block() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
context.rpc_server.mine_blocks(1);
context.index.update().unwrap();
assert_eq!(
Expand All @@ -936,13 +936,13 @@ mod tests {

#[test]
fn find_unmined_ordinal() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
assert_eq!(context.index.find(50 * COIN_VALUE).unwrap(), None);
}

#[test]
fn find_first_satoshi_spent_in_second_block() {
let context = Context::with_args("--index-ordinals");
let context = Context::with_args("--index-satoshis");
context.rpc_server.mine_blocks(1);
let spend_txid = context.rpc_server.broadcast_tx(TransactionTemplate {
input_slots: &[(1, 0, 0)],
Expand Down
14 changes: 7 additions & 7 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl From<Block> for BlockData {
pub struct Updater {
cache: HashMap<OutPointArray, Vec<u8>>,
height: u64,
index_ordinals: bool,
index_satoshis: bool,
ordinal_ranges_since_flush: u64,
outputs_cached: u64,
outputs_inserted_since_flush: u64,
Expand Down Expand Up @@ -56,7 +56,7 @@ impl Updater {
let mut updater = Self {
cache: HashMap::new(),
height,
index_ordinals: index.has_ordinal_index()?,
index_satoshis: index.has_satoshi_index()?,
ordinal_ranges_since_flush: 0,
outputs_cached: 0,
outputs_inserted_since_flush: 0,
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Updater {
Some(progress_bar)
};

let rx = Self::fetch_blocks_from(index, self.height, self.index_ordinals)?;
let rx = Self::fetch_blocks_from(index, self.height, self.index_satoshis)?;

let mut uncommitted = 0;
loop {
Expand Down Expand Up @@ -157,7 +157,7 @@ impl Updater {
fn fetch_blocks_from(
index: &Index,
mut height: u64,
index_ordinals: bool,
index_satoshis: bool,
) -> Result<mpsc::Receiver<BlockData>> {
let (tx, rx) = mpsc::sync_channel(32);

Expand All @@ -166,7 +166,7 @@ impl Updater {
let client =
Client::new(&index.rpc_url, index.auth.clone()).context("failed to connect to RPC URL")?;

let with_transactions = index_ordinals || index.chain != Chain::Mainnet;
let with_transactions = index_satoshis || index.chain != Chain::Mainnet;

thread::spawn(move || loop {
if let Some(height_limit) = height_limit {
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Updater {
let mut inscription_id_to_satpoint = wtx.open_table(INSCRIPTION_ID_TO_SATPOINT)?;
let mut satpoint_to_inscription_id = wtx.open_table(SATPOINT_TO_INSCRIPTION_ID)?;

if self.index_ordinals {
if self.index_satoshis {
let mut ordinal_to_inscription_id = wtx.open_table(ORDINAL_TO_INSCRIPTION_ID)?;
let mut ordinal_to_satpoint = wtx.open_table(ORDINAL_TO_SATPOINT)?;
let mut outpoint_to_ordinal_ranges = wtx.open_table(OUTPOINT_TO_ORDINAL_RANGES)?;
Expand Down Expand Up @@ -504,7 +504,7 @@ impl Updater {
self.outputs_cached
);

if self.index_ordinals {
if self.index_satoshis {
log::info!(
"Flushing {} entries ({:.1}% resulting from {} insertions) from memory to database",
self.cache.len(),
Expand Down
4 changes: 2 additions & 2 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub(crate) struct Options {
pub(crate) height_limit: Option<u64>,
#[clap(long, help = "Use index at <INDEX>.")]
pub(crate) index: Option<PathBuf>,
#[clap(long, help = "Index ordinal ranges.")]
pub(crate) index_ordinals: bool,
#[clap(long, help = "Index current location of all satoshis.")]
pub(crate) index_satoshis: bool,
#[clap(long, help = "Connect to Bitcoin Core RPC at <RPC_URL>.")]
rpc_url: Option<String>,
}
Expand Down
Loading

0 comments on commit d67a1df

Please sign in to comment.