Skip to content

Commit

Permalink
Reserve runes for sequential allocation (#2831)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Dec 14, 2023
1 parent 5f3c97d commit cfc20c0
Show file tree
Hide file tree
Showing 9 changed files with 801 additions and 436 deletions.
3 changes: 2 additions & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod updater;
#[cfg(test)]
pub(crate) mod testing;

const SCHEMA_VERSION: u64 = 13;
const SCHEMA_VERSION: u64 = 14;

macro_rules! define_table {
($name:ident, $key:ty, $value:ty) => {
Expand Down Expand Up @@ -91,6 +91,7 @@ pub(crate) enum Statistic {
IndexSats,
LostSats,
OutputsTraversed,
ReservedRunes,
Runes,
SatRanges,
UnboundInscriptions,
Expand Down
30 changes: 27 additions & 3 deletions src/index/updater/rune_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,34 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
// Determine if this runestone contains a valid issuance
let mut allocation = match runestone.etching {
Some(etching) => {
// If the issuance symbol is already taken, the issuance is ignored
if etching.rune < self.minimum || self.rune_to_id.get(etching.rune.0)?.is_some() {
if etching
.rune
.map(|rune| rune < self.minimum || rune.is_reserved())
.unwrap_or_default()
|| etching
.rune
.and_then(|rune| self.rune_to_id.get(rune.0).transpose())
.transpose()?
.is_some()
{
None
} else {
let rune = if let Some(rune) = etching.rune {
rune
} else {
let reserved_runes = self
.statistic_to_count
.get(&Statistic::ReservedRunes.into())?
.map(|entry| entry.value())
.unwrap_or_default();

self
.statistic_to_count
.insert(&Statistic::ReservedRunes.into(), reserved_runes + 1)?;

Rune::reserved(reserved_runes.into())
};

let (limit, term) = match (etching.limit, etching.term) {
(None, Some(term)) => (Some(runes::MAX_LIMIT), Some(term)),
(limit, term) => (limit, term),
Expand All @@ -96,7 +120,7 @@ impl<'a, 'db, 'tx> RuneUpdater<'a, 'db, 'tx> {
limit,
divisibility: etching.divisibility,
id: u128::from(self.height) << 16 | u128::from(index),
rune: etching.rune,
rune,
symbol: etching.symbol,
end: term.map(|term| term + self.height),
}),
Expand Down
Loading

0 comments on commit cfc20c0

Please sign in to comment.