From eaefa09aeafda34f6ab256aa267043b62dd9bd72 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Tue, 9 Apr 2024 18:45:55 -0400 Subject: [PATCH 1/5] Lock runes commit output --- src/wallet/batch/plan.rs | 8 ++++++++ src/wallet/batch/transactions.rs | 1 + src/wallet/entry.rs | 1 + 3 files changed, 10 insertions(+) diff --git a/src/wallet/batch/plan.rs b/src/wallet/batch/plan.rs index 1f51127464..f40605b4c6 100644 --- a/src/wallet/batch/plan.rs +++ b/src/wallet/batch/plan.rs @@ -48,6 +48,7 @@ impl Plan { ) -> SubcommandResult { let Transactions { commit_tx, + commit_vout, reveal_tx, recovery_key_pair, total_fees, @@ -128,6 +129,12 @@ impl Plan { .send_raw_transaction(&signed_commit_tx)?; if let Some(ref rune_info) = rune { + // eprintln!("Locking commitment output"); + wallet.bitcoin_client().lock_unspent(&[OutPoint { + txid: commit_txid, + vout: commit_vout.try_into().unwrap(), + }])?; + let commit = consensus::encode::deserialize::(&signed_commit_tx)?; let reveal = consensus::encode::deserialize::(&signed_reveal_tx)?; @@ -656,6 +663,7 @@ impl Plan { Ok(Transactions { commit_tx: unsigned_commit_tx, + commit_vout: vout, recovery_key_pair, reveal_tx, rune, diff --git a/src/wallet/batch/transactions.rs b/src/wallet/batch/transactions.rs index 72f1416b67..28e3a1628f 100644 --- a/src/wallet/batch/transactions.rs +++ b/src/wallet/batch/transactions.rs @@ -4,6 +4,7 @@ use super::*; pub(crate) struct Transactions { pub(crate) rune: Option, pub(crate) commit_tx: Transaction, + pub(crate) commit_vout: usize, pub(crate) recovery_key_pair: TweakedKeyPair, pub(crate) reveal_tx: Transaction, pub(crate) total_fees: u64, diff --git a/src/wallet/entry.rs b/src/wallet/entry.rs index 78331754cc..ee459210e5 100644 --- a/src/wallet/entry.rs +++ b/src/wallet/entry.rs @@ -8,6 +8,7 @@ pub struct EtchingEntry { } pub(super) type EtchingEntryValue = ( + // u32, Vec, // commit Vec, // reveal Vec, // output From 3aa0924f6c0a2b77bd89d8daa764c2e90751369d Mon Sep 17 00:00:00 2001 From: raphjaph Date: Mon, 15 Apr 2024 17:04:44 -0400 Subject: [PATCH 2/5] Amend --- crates/mockcore/src/server.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/mockcore/src/server.rs b/crates/mockcore/src/server.rs index 0fc13f6745..5bdce1b819 100644 --- a/crates/mockcore/src/server.rs +++ b/crates/mockcore/src/server.rs @@ -774,11 +774,12 @@ impl Api for Server { } fn list_lock_unspent(&self) -> Result, jsonrpc_core::Error> { + let state = self.state(); Ok( - self - .state() + state .locked .iter() + .filter(|outpoint| state.utxos.contains_key(outpoint)) .map(|outpoint| (*outpoint).into()) .collect(), ) @@ -890,7 +891,7 @@ impl Api for Server { vout: output.vout, txid: output.txid, }; - assert!(state.utxos.contains_key(&output)); + // assert!(state.utxos.contains_key(&output)); assert!(state.locked.insert(output)); } From 787bbaf6df6bb243960353d746d470de66c73cab Mon Sep 17 00:00:00 2001 From: raphjaph Date: Mon, 15 Apr 2024 17:13:06 -0400 Subject: [PATCH 3/5] Amend --- src/wallet/batch/plan.rs | 2 +- tests/lib.rs | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/wallet/batch/plan.rs b/src/wallet/batch/plan.rs index 6ba911848d..06c628cfd4 100644 --- a/src/wallet/batch/plan.rs +++ b/src/wallet/batch/plan.rs @@ -129,7 +129,7 @@ impl Plan { .send_raw_transaction(&signed_commit_tx)?; if let Some(ref rune_info) = rune { - // eprintln!("Locking commitment output"); + eprintln!("Locking rune commitment output"); wallet.bitcoin_client().lock_unspent(&[OutPoint { txid: commit_txid, vout: commit_vout.try_into().unwrap(), diff --git a/tests/lib.rs b/tests/lib.rs index a2160b6670..d61c09e903 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -194,9 +194,14 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E let mut buffer = String::new(); - BufReader::new(spawn.child.stderr.as_mut().unwrap()) - .read_line(&mut buffer) - .unwrap(); + let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); + + reader.read_line(&mut buffer).unwrap(); + + assert_regex_match!(buffer, "Locking rune commitment output\n"); + + buffer.clear(); + reader.read_line(&mut buffer).unwrap(); assert_regex_match!( buffer, From c88b17195fd3e4ce44cdc5e77581c302ed7a80f0 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Mon, 15 Apr 2024 17:40:08 -0400 Subject: [PATCH 4/5] Amend --- crates/mockcore/src/server.rs | 1 - src/wallet/entry.rs | 1 - tests/wallet/resume.rs | 136 +++++++++++++++++++++++++++++----- 3 files changed, 118 insertions(+), 20 deletions(-) diff --git a/crates/mockcore/src/server.rs b/crates/mockcore/src/server.rs index 5bdce1b819..060c3c47de 100644 --- a/crates/mockcore/src/server.rs +++ b/crates/mockcore/src/server.rs @@ -891,7 +891,6 @@ impl Api for Server { vout: output.vout, txid: output.txid, }; - // assert!(state.utxos.contains_key(&output)); assert!(state.locked.insert(output)); } diff --git a/src/wallet/entry.rs b/src/wallet/entry.rs index ee459210e5..78331754cc 100644 --- a/src/wallet/entry.rs +++ b/src/wallet/entry.rs @@ -8,7 +8,6 @@ pub struct EtchingEntry { } pub(super) type EtchingEntryValue = ( - // u32, Vec, // commit Vec, // reveal Vec, // output diff --git a/tests/wallet/resume.rs b/tests/wallet/resume.rs index 2a5af822b7..5183d59781 100644 --- a/tests/wallet/resume.rs +++ b/tests/wallet/resume.rs @@ -50,11 +50,19 @@ fn wallet_resume() { let mut buffer = String::new(); - BufReader::new(spawn.child.stderr.as_mut().unwrap()) - .read_line(&mut buffer) - .unwrap(); + let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); + + reader.read_line(&mut buffer).unwrap(); + + assert_regex_match!(buffer, "Locking rune commitment output\n"); + + buffer.clear(); + reader.read_line(&mut buffer).unwrap(); - assert_regex_match!(buffer, "Waiting for rune commitment .* to mature…\n"); + assert_regex_match!( + buffer, + "Waiting for rune commitment [[:xdigit:]]{64} to mature…\n" + ); core.mine_blocks(1); @@ -88,11 +96,14 @@ fn wallet_resume() { let mut buffer = String::new(); - BufReader::new(spawn.child.stderr.as_mut().unwrap()) - .read_line(&mut buffer) - .unwrap(); + let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); - assert_regex_match!(buffer, "Waiting for rune commitment .* to mature…\n"); + reader.read_line(&mut buffer).unwrap(); + + assert_regex_match!( + buffer, + "Waiting for rune commitment [[:xdigit:]]{64} to mature…\n" + ); let output = spawn.run_and_deserialize_output::(); @@ -156,11 +167,19 @@ fn resume_suspended() { let mut buffer = String::new(); - BufReader::new(spawn.child.stderr.as_mut().unwrap()) - .read_line(&mut buffer) - .unwrap(); + let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); + + reader.read_line(&mut buffer).unwrap(); + + assert_regex_match!(buffer, "Locking rune commitment output\n"); - assert_regex_match!(buffer, "Waiting for rune commitment .* to mature…\n"); + buffer.clear(); + reader.read_line(&mut buffer).unwrap(); + + assert_regex_match!( + buffer, + "Waiting for rune commitment [[:xdigit:]]{64} to mature…\n" + ); core.mine_blocks(1); @@ -206,15 +225,93 @@ fn resume_suspended() { ) .unwrap(); - BufReader::new(spawn.child.stderr.as_mut().unwrap()) - .read_line(&mut buffer) - .unwrap(); + let mut buffer = String::new(); + let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); + reader.read_line(&mut buffer).unwrap(); assert_eq!( buffer, "Shutting down gracefully. Press again to shutdown immediately.\n" ); + buffer.clear(); + reader.read_line(&mut buffer).unwrap(); + + assert_eq!( + buffer, + "Suspending batch. Run `ord wallet resume` to continue.\n" + ); + + let output = spawn.run_and_deserialize_output::(); + + assert!(!output.etchings.first().unwrap().reveal_broadcast); +} + +#[test] +fn commitment_output_is_locked() { + let core = mockcore::builder().network(Network::Regtest).build(); + + let ord = TestServer::spawn_with_server_args(&core, &["--regtest", "--index-runes"], &[]); + + create_wallet(&core, &ord); + + core.mine_blocks(1); + + let batchfile = batch::File { + etching: Some(batch::Etching { + divisibility: 0, + rune: SpacedRune { + rune: Rune(RUNE), + spacers: 0, + }, + supply: "1000".parse().unwrap(), + premine: "1000".parse().unwrap(), + symbol: '¢', + ..default() + }), + inscriptions: vec![batch::Entry { + file: Some("inscription.jpeg".into()), + ..default() + }], + ..default() + }; + + let tempdir = Arc::new(TempDir::new().unwrap()); + + let mut spawn = + CommandBuilder::new("--regtest --index-runes wallet batch --fee-rate 0 --batch batch.yaml") + .temp_dir(tempdir.clone()) + .write("batch.yaml", serde_yaml::to_string(&batchfile).unwrap()) + .write("inscription.jpeg", "inscription") + .core(&core) + .ord(&ord) + .expected_exit_code(1) + .spawn(); + + let mut buffer = String::new(); + let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); + reader.read_line(&mut buffer).unwrap(); + + assert_regex_match!(buffer, "Locking rune commitment output\n"); + + buffer.clear(); + reader.read_line(&mut buffer).unwrap(); + + assert_regex_match!( + buffer, + "Waiting for rune commitment [[:xdigit:]]{64} to mature…\n" + ); + + let commitment = core.mempool()[0].txid(); + + core.mine_blocks(1); + + signal::kill( + Pid::from_raw(spawn.child.id().try_into().unwrap()), + Signal::SIGINT, + ) + .unwrap(); + buffer.clear(); BufReader::new(spawn.child.stderr.as_mut().unwrap()) @@ -223,10 +320,13 @@ fn resume_suspended() { assert_eq!( buffer, - "Suspending batch. Run `ord wallet resume` to continue.\n" + "Shutting down gracefully. Press again to shutdown immediately.\n" ); - let output = spawn.run_and_deserialize_output::(); + spawn.child.wait().unwrap(); - assert!(!output.etchings.first().unwrap().reveal_broadcast); + assert!(core.get_locked().contains(&OutPoint { + txid: commitment, + vout: 0 + })); } From e59c1a5c8033793da6042d47589694230c212929 Mon Sep 17 00:00:00 2001 From: raphjaph Date: Mon, 15 Apr 2024 17:51:49 -0400 Subject: [PATCH 5/5] Amend --- src/wallet/batch/plan.rs | 1 - tests/lib.rs | 11 +++-------- tests/wallet/resume.rs | 33 +++++++++------------------------ 3 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/wallet/batch/plan.rs b/src/wallet/batch/plan.rs index 06c628cfd4..26244fe31f 100644 --- a/src/wallet/batch/plan.rs +++ b/src/wallet/batch/plan.rs @@ -129,7 +129,6 @@ impl Plan { .send_raw_transaction(&signed_commit_tx)?; if let Some(ref rune_info) = rune { - eprintln!("Locking rune commitment output"); wallet.bitcoin_client().lock_unspent(&[OutPoint { txid: commit_txid, vout: commit_vout.try_into().unwrap(), diff --git a/tests/lib.rs b/tests/lib.rs index d61c09e903..a2160b6670 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -194,14 +194,9 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E let mut buffer = String::new(); - let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); - - reader.read_line(&mut buffer).unwrap(); - - assert_regex_match!(buffer, "Locking rune commitment output\n"); - - buffer.clear(); - reader.read_line(&mut buffer).unwrap(); + BufReader::new(spawn.child.stderr.as_mut().unwrap()) + .read_line(&mut buffer) + .unwrap(); assert_regex_match!( buffer, diff --git a/tests/wallet/resume.rs b/tests/wallet/resume.rs index 5183d59781..54299aac8f 100644 --- a/tests/wallet/resume.rs +++ b/tests/wallet/resume.rs @@ -50,14 +50,9 @@ fn wallet_resume() { let mut buffer = String::new(); - let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); - - reader.read_line(&mut buffer).unwrap(); - - assert_regex_match!(buffer, "Locking rune commitment output\n"); - - buffer.clear(); - reader.read_line(&mut buffer).unwrap(); + BufReader::new(spawn.child.stderr.as_mut().unwrap()) + .read_line(&mut buffer) + .unwrap(); assert_regex_match!( buffer, @@ -95,7 +90,6 @@ fn wallet_resume() { .spawn(); let mut buffer = String::new(); - let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); reader.read_line(&mut buffer).unwrap(); @@ -167,14 +161,9 @@ fn resume_suspended() { let mut buffer = String::new(); - let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); - - reader.read_line(&mut buffer).unwrap(); - - assert_regex_match!(buffer, "Locking rune commitment output\n"); - - buffer.clear(); - reader.read_line(&mut buffer).unwrap(); + BufReader::new(spawn.child.stderr.as_mut().unwrap()) + .read_line(&mut buffer) + .unwrap(); assert_regex_match!( buffer, @@ -289,13 +278,9 @@ fn commitment_output_is_locked() { .spawn(); let mut buffer = String::new(); - let mut reader = BufReader::new(spawn.child.stderr.as_mut().unwrap()); - reader.read_line(&mut buffer).unwrap(); - - assert_regex_match!(buffer, "Locking rune commitment output\n"); - - buffer.clear(); - reader.read_line(&mut buffer).unwrap(); + BufReader::new(spawn.child.stderr.as_mut().unwrap()) + .read_line(&mut buffer) + .unwrap(); assert_regex_match!( buffer,