Skip to content

Commit

Permalink
Fix off-by-one in wallet when waiting for etching commitment to mature (
Browse files Browse the repository at this point in the history
#3515)

While waiting to broadcast a rune etching, take into account the fact that the
commit transaction will have an additional confirmation in the next block.
Previously we weren't, so the wallet was waiting for one confirmation too many.
  • Loading branch information
casey authored Apr 11, 2024
1 parent 56586c1 commit ead081d
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,15 @@ impl Wallet {
.into_option()?;

if let Some(transaction) = transaction {
if u32::try_from(transaction.info.confirmations).unwrap()
if u32::try_from(transaction.info.confirmations).unwrap() + 1
>= Runestone::COMMIT_CONFIRMATIONS.into()
{
let tx_out = self
.bitcoin_client()
.get_tx_out(&commit.txid(), 0, Some(true))?;

if let Some(tx_out) = tx_out {
if tx_out.confirmations >= Runestone::COMMIT_CONFIRMATIONS.into() {
if tx_out.confirmations + 1 >= Runestone::COMMIT_CONFIRMATIONS.into() {
break;
}
} else {
Expand Down
16 changes: 8 additions & 8 deletions tests/json_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,10 @@ fn get_runes() {
spacers: 0
},
symbol: Some('¢'),
timestamp: 11,
timestamp: 10,
turbo: false,
},
id: RuneId { block: 11, tx: 1 },
id: RuneId { block: 10, tx: 1 },
mintable: false,
parent: Some(InscriptionId {
txid: a.output.reveal,
Expand All @@ -568,7 +568,7 @@ fn get_runes() {
api::Runes {
entries: vec![
(
RuneId { block: 11, tx: 1 },
RuneId { block: 10, tx: 1 },
RuneEntry {
block: a.id.block,
burned: 0,
Expand All @@ -583,12 +583,12 @@ fn get_runes() {
spacers: 0
},
symbol: Some('¢'),
timestamp: 11,
timestamp: 10,
turbo: false,
}
),
(
RuneId { block: 19, tx: 1 },
RuneId { block: 17, tx: 1 },
RuneEntry {
block: b.id.block,
burned: 0,
Expand All @@ -603,12 +603,12 @@ fn get_runes() {
spacers: 0
},
symbol: Some('¢'),
timestamp: 19,
timestamp: 17,
turbo: false,
}
),
(
RuneId { block: 27, tx: 1 },
RuneId { block: 24, tx: 1 },
RuneEntry {
block: c.id.block,
burned: 0,
Expand All @@ -623,7 +623,7 @@ fn get_runes() {
spacers: 0
},
symbol: Some('¢'),
timestamp: 27,
timestamp: 24,
turbo: false,
}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn batch(core: &mockcore::Handle, ord: &TestServer, batchfile: batch::File) -> E
"Waiting for rune commitment [[:xdigit:]]{64} to mature…\n"
);

core.mine_blocks(6);
core.mine_blocks(5);

let output = spawn.run_and_deserialize_output::<Batch>();

Expand Down
18 changes: 9 additions & 9 deletions tests/runes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ fn one_rune() {
runes: vec![(
Rune(RUNE),
RuneInfo {
block: 8,
block: 7,
burned: 0,
divisibility: 0,
etching: etch.output.reveal,
id: RuneId { block: 8, tx: 1 },
id: RuneId { block: 7, tx: 1 },
terms: None,
mints: 0,
number: 0,
Expand All @@ -61,7 +61,7 @@ fn one_rune() {
},
supply: 1000,
symbol: Some('¢'),
timestamp: ord::timestamp(8),
timestamp: ord::timestamp(7),
turbo: false,
tx: 1,
}
Expand Down Expand Up @@ -92,11 +92,11 @@ fn two_runes() {
(
Rune(RUNE),
RuneInfo {
block: 8,
block: 7,
burned: 0,
divisibility: 0,
etching: a.output.reveal,
id: RuneId { block: 8, tx: 1 },
id: RuneId { block: 7, tx: 1 },
terms: None,
mints: 0,
number: 0,
Expand All @@ -107,19 +107,19 @@ fn two_runes() {
},
supply: 1000,
symbol: Some('¢'),
timestamp: ord::timestamp(8),
timestamp: ord::timestamp(7),
turbo: false,
tx: 1,
}
),
(
Rune(RUNE + 1),
RuneInfo {
block: 16,
block: 14,
burned: 0,
divisibility: 0,
etching: b.output.reveal,
id: RuneId { block: 16, tx: 1 },
id: RuneId { block: 14, tx: 1 },
terms: None,
mints: 0,
number: 1,
Expand All @@ -130,7 +130,7 @@ fn two_runes() {
},
supply: 1000,
symbol: Some('¢'),
timestamp: ord::timestamp(16),
timestamp: ord::timestamp(14),
turbo: false,
tx: 1,
}
Expand Down
8 changes: 4 additions & 4 deletions tests/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn runic_utxos_are_deducted_from_cardinal() {
.ord(&ord)
.run_and_deserialize_output::<Balance>(),
Balance {
cardinal: 50 * COIN_VALUE * 8 - 20_000,
cardinal: 50 * COIN_VALUE * 7 - 20_000,
ordinal: 10000,
runic: Some(10_000),
runes: Some(
Expand All @@ -138,7 +138,7 @@ fn runic_utxos_are_deducted_from_cardinal() {
.into_iter()
.collect()
),
total: 50 * COIN_VALUE * 8,
total: 50 * COIN_VALUE * 7,
}
);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ fn runic_utxos_are_displayed_with_decimal_amount() {
.ord(&ord)
.run_and_deserialize_output::<Balance>(),
Balance {
cardinal: 50 * COIN_VALUE * 8 - 20_000,
cardinal: 50 * COIN_VALUE * 7 - 20_000,
ordinal: 10000,
runic: Some(10_000),
runes: Some(
Expand All @@ -254,7 +254,7 @@ fn runic_utxos_are_displayed_with_decimal_amount() {
.into_iter()
.collect()
),
total: 50 * COIN_VALUE * 8,
total: 50 * COIN_VALUE * 7,
}
);
}
8 changes: 4 additions & 4 deletions tests/wallet/batch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,7 +1504,7 @@ fn batch_can_etch_rune() {
.ord(&ord)
.run_and_deserialize_output::<Balance>(),
Balance {
cardinal: 44999980000,
cardinal: 39999980000,
ordinal: 10000,
runic: Some(10000),
runes: Some(
Expand All @@ -1518,7 +1518,7 @@ fn batch_can_etch_rune() {
.into_iter()
.collect()
),
total: 450 * COIN_VALUE,
total: 400 * COIN_VALUE,
}
);
}
Expand Down Expand Up @@ -1645,11 +1645,11 @@ fn batch_can_etch_rune_without_premine() {
.ord(&ord)
.run_and_deserialize_output::<Balance>(),
Balance {
cardinal: 44999990000,
cardinal: 39999990000,
ordinal: 10000,
runic: Some(0),
runes: Some(default()),
total: 450 * COIN_VALUE,
total: 400 * COIN_VALUE,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn minting_rune_and_fails_if_after_end() {
.core(&core)
.ord(&ord)
.expected_exit_code(1)
.expected_stderr("error: rune AAAAAAAAAAAAA mint ended on block 11\n")
.expected_stderr("error: rune AAAAAAAAAAAAA mint ended on block 10\n")
.run_and_extract_stdout();
}

Expand Down

0 comments on commit ead081d

Please sign in to comment.