Skip to content

Commit

Permalink
Add etching turbo flag (#3511)
Browse files Browse the repository at this point in the history
Future runes features may be opt-in, for example, if they increase light client
validation costs, or if they are simply too degenerate.

This commit adds a "turbo" flag, which, if set, premptively opts in to such
future features.

It also sets the "turbo" flag on the genesis rune, UNCOMMON•GOODS.

Because the genesis rune is inserted into the index when it is created, the
schema version is also incremented, to force rebuilding indices created before
this commit.
  • Loading branch information
casey committed Apr 11, 2024
1 parent 5aef087 commit c403142
Show file tree
Hide file tree
Showing 23 changed files with 190 additions and 20 deletions.
7 changes: 7 additions & 0 deletions batch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ etching:
offset:
start: 1000
end: 9000
# future runes protocol changes may be opt-in. this may be for a variety of
# reasons, including that they make light client validation harder, or simply
# because they are too degenerate.
#
# setting `turbo` to `true` opts in to these future protocol changes,
# whatever they may be.
turbo: true

# inscriptions to inscribe
inscriptions:
Expand Down
1 change: 1 addition & 0 deletions crates/ordinals/src/etching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct Etching {
pub spacers: Option<u32>,
pub symbol: Option<char>,
pub terms: Option<Terms>,
pub turbo: bool,
}

impl Etching {
Expand Down
34 changes: 22 additions & 12 deletions crates/ordinals/src/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl Runestone {
Tag::OffsetEnd.take(&mut fields, |[end_offset]| u64::try_from(end_offset).ok()),
),
}),
turbo: Flag::Turbo.take(&mut flags),
});

let mint = Tag::Mint.take(&mut fields, |[block, tx]| {
Expand Down Expand Up @@ -136,6 +137,10 @@ impl Runestone {
Flag::Terms.set(&mut flags);
}

if etching.turbo {
Flag::Turbo.set(&mut flags);
}

Tag::Flags.encode([flags], &mut payload);

Tag::Rune.encode_option(etching.rune.map(|rune| rune.0), &mut payload);
Expand Down Expand Up @@ -1074,7 +1079,7 @@ mod tests {
assert_eq!(
decipher(&[
Tag::Flags.into(),
Flag::Etching.mask() | Flag::Terms.mask(),
Flag::Etching.mask() | Flag::Terms.mask() | Flag::Turbo.mask(),
Tag::Rune.into(),
4,
Tag::Divisibility.into(),
Expand Down Expand Up @@ -1110,17 +1115,18 @@ mod tests {
output: 0,
}],
etching: Some(Etching {
divisibility: Some(1),
premine: Some(8),
rune: Some(Rune(4)),
spacers: Some(5),
symbol: Some('a'),
terms: Some(Terms {
cap: Some(9),
offset: (None, Some(2)),
amount: Some(3),
height: (None, None),
}),
premine: Some(8),
divisibility: Some(1),
symbol: Some('a'),
spacers: Some(5),
turbo: true,
}),
pointer: Some(0),
mint: Some(RuneId::new(1, 1).unwrap()),
Expand Down Expand Up @@ -1433,6 +1439,7 @@ mod tests {
offset: (Some(u32::MAX.into()), Some(u32::MAX.into())),
height: (Some(u32::MAX.into()), Some(u32::MAX.into())),
}),
turbo: true,
premine: Some(u64::MAX.into()),
rune: Some(Rune(u128::MAX)),
symbol: Some('\u{10FFFF}'),
Expand Down Expand Up @@ -1704,13 +1711,14 @@ mod tests {
amount: Some(14),
offset: (Some(15), Some(16)),
}),
turbo: true,
}),
mint: Some(RuneId::new(17, 18).unwrap()),
pointer: Some(0),
},
&[
Tag::Flags.into(),
Flag::Etching.mask() | Flag::Terms.mask(),
Flag::Etching.mask() | Flag::Terms.mask() | Flag::Turbo.mask(),
Tag::Rune.into(),
9,
Tag::Divisibility.into(),
Expand Down Expand Up @@ -1754,12 +1762,13 @@ mod tests {
case(
Runestone {
etching: Some(Etching {
premine: None,
divisibility: None,
terms: None,
symbol: None,
premine: None,
rune: Some(Rune(3)),
spacers: None,
symbol: None,
terms: None,
turbo: false,
}),
..default()
},
Expand All @@ -1769,12 +1778,13 @@ mod tests {
case(
Runestone {
etching: Some(Etching {
premine: None,
divisibility: None,
terms: None,
symbol: None,
premine: None,
rune: None,
spacers: None,
symbol: None,
terms: None,
turbo: false,
}),
..default()
},
Expand Down
1 change: 1 addition & 0 deletions crates/ordinals/src/runestone/flag.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub(super) enum Flag {
Etching = 0,
Terms = 1,
Turbo = 2,
#[allow(unused)]
Cenotaph = 127,
}
Expand Down
3 changes: 2 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod updater;
#[cfg(test)]
pub(crate) mod testing;

const SCHEMA_VERSION: u64 = 24;
const SCHEMA_VERSION: u64 = 25;

define_multimap_table! { SATPOINT_TO_SEQUENCE_NUMBER, &SatPointValue, u32 }
define_multimap_table! { SAT_TO_SEQUENCE_NUMBER, u64, u32 }
Expand Down Expand Up @@ -386,6 +386,7 @@ impl Index {
spaced_rune: SpacedRune { rune, spacers: 128 },
symbol: Some('\u{29C9}'),
timestamp: 0,
turbo: true,
}
.store(),
)?;
Expand Down
8 changes: 8 additions & 0 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct RuneEntry {
pub symbol: Option<char>,
pub terms: Option<Terms>,
pub timestamp: u64,
pub turbo: bool,
}

impl RuneEntry {
Expand Down Expand Up @@ -153,6 +154,7 @@ pub(super) type RuneEntryValue = (
Option<char>, // symbol
Option<TermsEntryValue>, // terms
u64, // timestamp
bool, // turbo
);

impl Default for RuneEntry {
Expand All @@ -169,6 +171,7 @@ impl Default for RuneEntry {
symbol: None,
terms: None,
timestamp: 0,
turbo: false,
}
}
}
Expand All @@ -189,6 +192,7 @@ impl Entry for RuneEntry {
symbol,
terms,
timestamp,
turbo,
): RuneEntryValue,
) -> Self {
Self {
Expand Down Expand Up @@ -220,6 +224,7 @@ impl Entry for RuneEntry {
offset,
}),
timestamp,
turbo,
}
}

Expand Down Expand Up @@ -255,6 +260,7 @@ impl Entry for RuneEntry {
}| (cap, height, amount, offset),
),
self.timestamp,
self.turbo,
)
}
}
Expand Down Expand Up @@ -572,6 +578,7 @@ mod tests {
},
symbol: Some('a'),
timestamp: 10,
turbo: true,
};

let value = (
Expand All @@ -589,6 +596,7 @@ mod tests {
Some('a'),
Some((Some(1), (Some(2), Some(3)), Some(4), (Some(5), Some(6)))),
10,
true,
);

assert_eq!(entry.store(), value);
Expand Down
3 changes: 3 additions & 0 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> {
spaced_rune: SpacedRune { rune, spacers: 0 },
symbol: None,
timestamp: self.block_time.into(),
turbo: false,
},
Artifact::Runestone(Runestone { etching, .. }) => {
let Etching {
Expand All @@ -251,6 +252,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> {
premine,
spacers,
symbol,
turbo,
..
} = etching.unwrap();

Expand All @@ -269,6 +271,7 @@ impl<'a, 'tx, 'client> RuneUpdater<'a, 'tx, 'client> {
},
symbol,
timestamp: self.block_time.into(),
turbo,
}
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ mod tests {
divisibility: Some(1),
symbol: Some('$'),
spacers: Some(1),
turbo: true,
}),
pointer: Some(10),
..default()
Expand All @@ -868,6 +869,7 @@ mod tests {
},
symbol: None,
timestamp: id.block,
turbo: false,
},
)],
[],
Expand Down Expand Up @@ -5486,6 +5488,7 @@ mod tests {
offset: (None, None),
}),
timestamp: 0,
turbo: true,
},
)],
[],
Expand Down
3 changes: 3 additions & 0 deletions src/subcommand/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct RuneInfo {
pub symbol: Option<char>,
pub terms: Option<Terms>,
pub timestamp: DateTime<Utc>,
pub turbo: bool,
pub tx: u32,
}

Expand Down Expand Up @@ -52,6 +53,7 @@ pub(crate) fn run(settings: Settings) -> SubcommandResult {
symbol,
terms,
timestamp,
turbo,
},
)| {
(
Expand All @@ -70,6 +72,7 @@ pub(crate) fn run(settings: Settings) -> SubcommandResult {
symbol,
terms,
timestamp: crate::timestamp(timestamp),
turbo,
tx: id.tx,
},
)
Expand Down
4 changes: 4 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,7 @@ mod tests {
rune: Some(rune),
symbol: Some('%'),
premine: Some(u128::MAX),
turbo: true,
..default()
}),
..default()
Expand Down Expand Up @@ -2742,6 +2743,7 @@ mod tests {
premine: u128::MAX,
symbol: Some('%'),
timestamp: id.block,
turbo: true,
..default()
}
)]
Expand Down Expand Up @@ -2782,6 +2784,8 @@ mod tests {
<dd>0</dd>
<dt>symbol</dt>
<dd>%</dd>
<dt>turbo</dt>
<dd>true</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/{txid}>{txid}</a></dd>
<dt>parent</dt>
Expand Down
39 changes: 39 additions & 0 deletions src/templates/rune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod tests {
},
symbol: Some('%'),
timestamp: 0,
turbo: true,
},
id: RuneId { block: 10, tx: 9 },
mintable: true,
Expand Down Expand Up @@ -92,6 +93,8 @@ mod tests {
<dd>9</dd>
<dt>symbol</dt>
<dd>%</dd>
<dt>turbo</dt>
<dd>true</dd>
<dt>etching</dt>
<dd><a class=monospace href=/tx/0{64}>0{64}</a></dd>
<dt>parent</dt>
Expand Down Expand Up @@ -120,6 +123,7 @@ mod tests {
},
symbol: Some('%'),
timestamp: 0,
turbo: false,
},
id: RuneId { block: 10, tx: 9 },
mintable: false,
Expand All @@ -134,6 +138,40 @@ mod tests {
);
}

#[test]
fn display_no_turbo() {
assert_regex_match!(
RuneHtml {
entry: RuneEntry {
block: 0,
burned: 123456789123456789,
terms: None,
divisibility: 9,
etching: Txid::all_zeros(),
mints: 0,
number: 25,
premine: 0,
spaced_rune: SpacedRune {
rune: Rune(u128::MAX),
spacers: 1
},
symbol: Some('%'),
timestamp: 0,
turbo: false,
},
id: RuneId { block: 10, tx: 9 },
mintable: false,
parent: None,
},
"<h1>B•CGDENLQRQWDSLRUGSNLBTMFIJAV</h1>
<dl>.*
<dt>turbo</dt>
<dd>false</dd>
.*</dl>
"
);
}

#[test]
fn display_empty_mint() {
assert_regex_match!(
Expand All @@ -158,6 +196,7 @@ mod tests {
},
symbol: Some('%'),
timestamp: 0,
turbo: false,
},
id: RuneId { block: 10, tx: 9 },
mintable: false,
Expand Down
3 changes: 2 additions & 1 deletion src/wallet/batch/etching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ pub struct Etching {
pub rune: SpacedRune,
pub supply: Decimal,
pub symbol: char,
pub terms: Option<Terms>,
pub terms: Option<batch::Terms>,
pub turbo: bool,
}
Loading

0 comments on commit c403142

Please sign in to comment.