Skip to content

Commit

Permalink
Unlock runes over the next halving
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Dec 12, 2023
1 parent 6115eca commit 65cd861
Show file tree
Hide file tree
Showing 17 changed files with 333 additions and 317 deletions.
10 changes: 10 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ impl Chain {
}
}

pub(crate) fn first_rune_height(self) -> u32 {
SUBSIDY_HALVING_INTERVAL
* match self {
Self::Mainnet => 4,
Self::Regtest => 0,
Self::Signet => 0,
Self::Testnet => 12,
}
}

pub(crate) fn jubilee_height(self) -> u32 {
match self {
Self::Mainnet => 824544,
Expand Down
5 changes: 4 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ impl Index {
height,
inscriptions: blessed_inscriptions + cursed_inscriptions,
lost_sats: statistic(Statistic::LostSats)?,
minimum_rune_for_next_block: Rune::minimum_at_height(Height(next_height)),
minimum_rune_for_next_block: Rune::minimum_at_height(
self.options.chain(),
Height(next_height),
),
rune_index: statistic(Statistic::IndexRunes)? != 0,
runes: statistic(Statistic::Runes)?,
sat_index: statistic(Statistic::IndexSats)? != 0,
Expand Down
5 changes: 5 additions & 0 deletions src/index/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ impl ContextBuilder {
self
}

pub(crate) fn chain(mut self, chain: Chain) -> Self {
self.chain = chain;
self
}

pub(crate) fn tempdir(mut self, tempdir: TempDir) -> Self {
self.tempdir = Some(tempdir);
self
Expand Down
4 changes: 2 additions & 2 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl<'index> Updater<'_> {
&inscription_updater.unbound_inscriptions,
)?;

if index.index_runes {
if index.index_runes && self.height >= self.index.options.first_rune_height() {
let mut outpoint_to_rune_balances = wtx.open_table(OUTPOINT_TO_RUNE_BALANCES)?;
let mut rune_id_to_rune_entry = wtx.open_table(RUNE_ID_TO_RUNE_ENTRY)?;
let mut rune_to_rune_id = wtx.open_table(RUNE_TO_RUNE_ID)?;
Expand All @@ -586,7 +586,7 @@ impl<'index> Updater<'_> {
height: self.height,
id_to_entry: &mut rune_id_to_rune_entry,
inscription_id_to_sequence_number: &mut inscription_id_to_sequence_number,
minimum: Rune::minimum_at_height(Height(self.height)),
minimum: Rune::minimum_at_height(self.index.options.chain(), Height(self.height)),
outpoint_to_balances: &mut outpoint_to_rune_balances,
rune_to_id: &mut rune_to_rune_id,
runes,
Expand Down
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use {
bitcoin::{
address::{Address, NetworkUnchecked},
blockdata::constants::COIN_VALUE,
blockdata::constants::{DIFFCHANGE_INTERVAL, SUBSIDY_HALVING_INTERVAL},
consensus::{self, Decodable, Encodable},
hash_types::BlockHash,
hashes::Hash,
Expand Down Expand Up @@ -140,8 +141,6 @@ mod wallet;

type Result<T = (), E = Error> = std::result::Result<T, E>;

const DIFFCHANGE_INTERVAL: u32 = bitcoin::blockdata::constants::DIFFCHANGE_INTERVAL;
const SUBSIDY_HALVING_INTERVAL: u32 = bitcoin::blockdata::constants::SUBSIDY_HALVING_INTERVAL;
const CYCLE_EPOCHS: u32 = 6;

static SHUTTING_DOWN: AtomicBool = AtomicBool::new(false);
Expand Down
37 changes: 20 additions & 17 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) struct Options {
long,
help = "Track location of runes. RUNES ARE IN AN UNFINISHED PRE-ALPHA STATE AND SUBJECT TO CHANGE AT ANY TIME."
)]
pub(crate) index_runes_pre_alpha_i_agree_to_get_rekt: bool,
pub(crate) index_runes: bool,
#[arg(long, help = "Track location of all satoshis.")]
pub(crate) index_sats: bool,
#[arg(long, short, help = "Use regtest. Equivalent to `--chain regtest`.")]
Expand Down Expand Up @@ -75,9 +75,7 @@ impl Options {
}

pub(crate) fn first_inscription_height(&self) -> u32 {
if self.chain() == Chain::Regtest {
self.first_inscription_height.unwrap_or(0)
} else if integration_test() {
if integration_test() {
0
} else {
self
Expand All @@ -86,8 +84,16 @@ impl Options {
}
}

pub(crate) fn first_rune_height(&self) -> u32 {
if integration_test() {
0
} else {
self.chain().first_rune_height()
}
}

pub(crate) fn index_runes(&self) -> bool {
self.index_runes_pre_alpha_i_agree_to_get_rekt && self.chain() != Chain::Mainnet
self.index_runes && self.chain() != Chain::Mainnet
}

pub(crate) fn rpc_url(&self) -> String {
Expand Down Expand Up @@ -805,26 +811,23 @@ mod tests {
assert!(Arguments::try_parse_from([
"ord",
"--chain=signet",
"--index-runes-pre-alpha-i-agree-to-get-rekt",
"--index-runes",
"index",
"update"
])
.unwrap()
.options
.index_runes(),);
assert!(!Arguments::try_parse_from([
"ord",
"--index-runes-pre-alpha-i-agree-to-get-rekt",
"index",
"update"
])
.unwrap()
.options
.index_runes(),);
.index_runes());
assert!(
!Arguments::try_parse_from(["ord", "--index-runes", "index", "update"])
.unwrap()
.options
.index_runes()
);
assert!(!Arguments::try_parse_from(["ord", "index", "update"])
.unwrap()
.options
.index_runes(),);
.index_runes());
}

#[test]
Expand Down
Loading

0 comments on commit 65cd861

Please sign in to comment.