Skip to content

Commit

Permalink
Add --no-limit flag to bypass MAX_STANDARD_TX_WEIGHT check to allow f…
Browse files Browse the repository at this point in the history
…our meggers (#1571)
  • Loading branch information
raphjaph authored Feb 8, 2023
1 parent a9f9e70 commit cc8f4ff
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl Preview {
no_backup: true,
satpoint: None,
dry_run: false,
no_limit: false,
},
)),
}
Expand Down
42 changes: 41 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ pub(crate) struct Inscribe {
pub(crate) file: PathBuf,
#[clap(long, help = "Do not back up recovery key.")]
pub(crate) no_backup: bool,
#[clap(
long,
help = "Do not check that transactions are equal to or below the MAX_STANDARD_TX_WEIGHT of 400,000 weight units. Transactions over this limit are currently nonstandard and will not be relayed by bitcoind in its default configuration. Do not use this flag unless you understand the implications."
)]
pub(crate) no_limit: bool,
#[clap(long, help = "Don't sign or broadcast transactions.")]
pub(crate) dry_run: bool,
}
Expand Down Expand Up @@ -77,6 +82,7 @@ impl Inscribe {
reveal_tx_destination,
self.commit_fee_rate.unwrap_or(self.fee_rate),
self.fee_rate,
self.no_limit,
)?;

utxos.insert(
Expand Down Expand Up @@ -140,6 +146,7 @@ impl Inscribe {
destination: Address,
commit_fee_rate: FeeRate,
reveal_fee_rate: FeeRate,
no_limit: bool,
) -> Result<(Transaction, Transaction, TweakedKeyPair)> {
let satpoint = if let Some(satpoint) = satpoint {
satpoint
Expand Down Expand Up @@ -282,7 +289,7 @@ impl Inscribe {

let reveal_weight = reveal_tx.weight();

if reveal_weight > MAX_STANDARD_TX_WEIGHT.try_into().unwrap() {
if !no_limit && reveal_weight > MAX_STANDARD_TX_WEIGHT.try_into().unwrap() {
bail!(
"reveal transaction weight greater than {MAX_STANDARD_TX_WEIGHT} (MAX_STANDARD_TX_WEIGHT): {reveal_weight}"
);
Expand Down Expand Up @@ -377,6 +384,7 @@ mod tests {
reveal_address,
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
)
.unwrap();

Expand Down Expand Up @@ -407,6 +415,7 @@ mod tests {
reveal_address,
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
)
.unwrap();

Expand Down Expand Up @@ -441,6 +450,7 @@ mod tests {
reveal_address,
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
)
.unwrap_err()
.to_string();
Expand Down Expand Up @@ -482,6 +492,7 @@ mod tests {
reveal_address,
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
)
.is_ok())
}
Expand Down Expand Up @@ -517,6 +528,7 @@ mod tests {
reveal_address,
FeeRate::try_from(fee_rate).unwrap(),
FeeRate::try_from(fee_rate).unwrap(),
false,
)
.unwrap();

Expand Down Expand Up @@ -578,6 +590,7 @@ mod tests {
reveal_address,
FeeRate::try_from(commit_fee_rate).unwrap(),
FeeRate::try_from(fee_rate).unwrap(),
false,
)
.unwrap();

Expand Down Expand Up @@ -626,6 +639,7 @@ mod tests {
reveal_address,
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
false,
)
.unwrap_err()
.to_string();
Expand All @@ -636,4 +650,30 @@ mod tests {
error
);
}

#[test]
fn inscribe_with_no_max_standard_tx_weight() {
let utxos = vec![(outpoint(1), Amount::from_sat(50 * COIN_VALUE))];

let inscription = inscription("text/plain", [0; MAX_STANDARD_TX_WEIGHT as usize]);
let satpoint = None;
let commit_address = change(0);
let reveal_address = recipient();

let (_commit_tx, reveal_tx, _private_key) = Inscribe::create_inscription_transactions(
satpoint,
inscription,
BTreeMap::new(),
Network::Bitcoin,
utxos.into_iter().collect(),
[commit_address, change(1)],
reveal_address,
FeeRate::try_from(1.0).unwrap(),
FeeRate::try_from(1.0).unwrap(),
true,
)
.unwrap();

assert!(reveal_tx.size() >= MAX_STANDARD_TX_WEIGHT as usize);
}
}
12 changes: 12 additions & 0 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,15 @@ fn inscribe_with_dry_run_flag_fees_inscrease() {

assert!(total_fee_dry_run < total_fee_normal);
}

#[test]
fn inscribe_with_no_limit() {
let rpc_server = test_bitcoincore_rpc::spawn();
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

let four_megger = std::iter::repeat(0).take(4_000_000).collect::<Vec<u8>>();
CommandBuilder::new("wallet inscribe --no-limit degenerate.png")
.write("degenerate.png", four_megger)
.rpc_server(&rpc_server);
}

0 comments on commit cc8f4ff

Please sign in to comment.