Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show progress for etching #3673

Merged
merged 28 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6102409
init: show progress for etching
twosatsmaxi Apr 24, 2024
158ec4d
lint
twosatsmaxi Apr 24, 2024
a78dd33
lint more
twosatsmaxi Apr 24, 2024
4c3dc90
Display commitment maturation progress
twosatsmaxi Apr 24, 2024
e7efb09
change the order of checks
twosatsmaxi Apr 24, 2024
0104448
format
twosatsmaxi Apr 24, 2024
513b467
making the progress bar fancier
twosatsmaxi Apr 24, 2024
6bc5ee4
making the progress bar cooler
twosatsmaxi Apr 24, 2024
4cb9511
Merge branch 'master' into ft-etching-progress
twosatsmaxi Apr 24, 2024
ebde87d
Use existing constants
twosatsmaxi Apr 25, 2024
10d9cb3
Merge branch 'master' into ft-etching-progress
twosatsmaxi Apr 30, 2024
3ac8ea3
Merge branch 'master' of github.com:ordinals/ord into ft-etching-prog…
raphjaph Apr 30, 2024
376f8a6
Make error type and simplify
raphjaph Apr 30, 2024
1040289
Amend
raphjaph Apr 30, 2024
8646fe8
Amend
raphjaph Apr 30, 2024
5cb8598
i instead of index
raphjaph Apr 30, 2024
dba63e9
Merge branch 'master' of github.com:ordinals/ord into ft-etching-prog…
raphjaph May 2, 2024
348574d
Make enum
raphjaph May 2, 2024
5bff593
check_maturity
raphjaph May 3, 2024
966e8a0
add rest of arms for maturity check
twosatsmaxi May 4, 2024
09cb044
rename to is_above_minimum_at_height
twosatsmaxi May 4, 2024
861c477
remove unwrap and propogate error
twosatsmaxi May 4, 2024
cf272a3
type checks for corner cases when resume is run after longer period
twosatsmaxi May 4, 2024
f38bdf4
Amend
twosatsmaxi May 4, 2024
d8eb0d1
replace with block chars
twosatsmaxi May 4, 2024
bbc43fb
remove explicit error type
twosatsmaxi May 4, 2024
c7c927f
remove unnecessary import
raphjaph May 4, 2024
304e04c
clear etching
raphjaph May 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/subcommand/wallet/resume.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::*;
use {super::*, crate::wallet::Maturity};

#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
pub struct ResumeOutput {
Expand All @@ -18,7 +18,7 @@ impl Resume {
break;
}

for (rune, entry) in wallet.pending_etchings()? {
for (i, (rune, entry)) in wallet.pending_etchings()?.iter().enumerate() {
if self.dry_run {
etchings.push(batch::Output {
reveal_broadcast: false,
Expand All @@ -27,8 +27,13 @@ impl Resume {
continue;
};

if wallet.is_mature(rune, &entry.commit)? {
etchings.push(wallet.send_etching(rune, &entry)?);
match wallet.is_mature(*rune, &entry.commit)? {
Maturity::Mature => etchings.push(wallet.send_etching(*rune, entry)?),
Maturity::CommitmentSpent(txid) => {
eprintln!("Commitment for rune etching {rune} spent in {txid}");
etchings.remove(i);
}
_ => continue,
}
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
93 changes: 65 additions & 28 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ impl From<Statistic> for u64 {
}
}

#[derive(Debug, PartialEq)]
pub(crate) enum Maturity {
Mature,
Immature,
BelowMinimumHeight(u64),
ConfirmationsPending(u16),
CommitmentSpent(Txid),
}

pub(crate) struct Wallet {
bitcoin_client: Client,
database: Database,
Expand Down Expand Up @@ -280,37 +289,42 @@ impl Wallet {
self.settings.integration_test()
}

pub(crate) fn is_mature(&self, rune: Rune, commit: &Transaction) -> Result<bool> {
let transaction = self
.bitcoin_client()
.get_transaction(&commit.txid(), Some(true))
.into_option()?;
fn is_after_minimum_height(&self, rune: Rune) -> bool {
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
rune
>= Rune::minimum_at_height(
self.chain().network(),
Height(u32::try_from(self.bitcoin_client().get_block_count().unwrap() + 1).unwrap()),
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
)
}

if let Some(transaction) = transaction {
if u32::try_from(transaction.info.confirmations).unwrap() + 1
>= Runestone::COMMIT_CONFIRMATIONS.into()
&& rune
>= Rune::minimum_at_height(
self.chain().network(),
Height(u32::try_from(self.bitcoin_client().get_block_count()? + 1).unwrap()),
)
pub(crate) fn is_mature(&self, rune: Rune, commit: &Transaction) -> Result<Maturity> {
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
Ok(
if let Some(commit_tx) = self
.bitcoin_client()
.get_transaction(&commit.txid(), Some(true))
.into_option()?
{
let tx_out = self
.bitcoin_client()
.get_tx_out(&commit.txid(), 0, Some(true))?;
let current_confirmations = u16::try_from(commit_tx.info.confirmations).unwrap();
raphjaph marked this conversation as resolved.
Show resolved Hide resolved

if let Some(tx_out) = tx_out {
if tx_out.confirmations + 1 >= Runestone::COMMIT_CONFIRMATIONS.into() {
return Ok(true);
}
if self
.bitcoin_client()
.get_tx_out(&commit.txid(), 0, Some(true))?
.is_none()
{
Maturity::CommitmentSpent(commit_tx.info.txid)
} else if !self.is_after_minimum_height(rune) {
Maturity::BelowMinimumHeight(self.bitcoin_client().get_block_count()? + 1)
} else if current_confirmations + 1 < Runestone::COMMIT_CONFIRMATIONS {
Maturity::ConfirmationsPending(
Runestone::COMMIT_CONFIRMATIONS - current_confirmations - 1,
)
} else {
self.clear_etching(rune)?;
bail!("rune commitment spent, can't send reveal tx");
Maturity::Mature
}
}
}

Ok(false)
} else {
Maturity::Immature
},
)
}

pub(crate) fn wait_for_maturation(&self, rune: Rune) -> Result<batch::Output> {
Expand All @@ -324,14 +338,37 @@ impl Wallet {
entry.commit.txid()
);

let mut pending_confirmations = Runestone::COMMIT_CONFIRMATIONS;

let pb = ProgressBar::new(pending_confirmations.into()).with_style(
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
ProgressStyle::default_bar()
.template("Maturing in...[{eta}] {spinner:.green} [{bar:40.cyan/blue}] {pos}/{len}")
.unwrap()
.progress_chars("#>-"),
);

loop {
if SHUTTING_DOWN.load(atomic::Ordering::Relaxed) {
eprintln!("Suspending batch. Run `ord wallet resume` to continue.");
return Ok(entry.output);
}

if self.is_mature(rune, &entry.commit)? {
break;
match self.is_mature(rune, &entry.commit)? {
Maturity::Mature => {
pb.finish_with_message("Rune matured, submitting...");
break;
}
Maturity::ConfirmationsPending(remaining) => {
if remaining < pending_confirmations {
pending_confirmations = remaining;
pb.inc(1);
}
}
Maturity::CommitmentSpent(txid) => {
self.clear_etching(rune)?;
bail!("rune commitment {} spent, can't send reveal tx", txid);
}
_ => {}
}

if !self.integration_test() {
Expand Down
Loading