Skip to content

Commit

Permalink
Require --fee-rate for wallet inscribe to implement ordinals#1767
Browse files Browse the repository at this point in the history
  • Loading branch information
veryordinally committed Feb 16, 2023
1 parent 3b49ab2 commit 587b0c9
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 38 deletions.
37 changes: 36 additions & 1 deletion docs/src/guides/inscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ This guide covers:
5. Creating inscriptions with `ord wallet inscribe`
6. Sending inscriptions with `ord wallet send`
7. Receiving inscriptions with `ord wallet receive`
8. Picking a suitable fee rate for transactions

Getting Help
------------
Expand Down Expand Up @@ -166,7 +167,7 @@ Creating Inscriptions
To create an inscription with the contents of `FILE`, run:

```
ord wallet inscribe FILE
ord wallet inscribe --fee-rate <FEE_RATE> <FILE>
```

Ord will output two transactions IDs, one for the commit transaction, and one
Expand Down Expand Up @@ -246,3 +247,37 @@ Once the send transaction confirms, you can can confirm receipt by running:
```
ord wallet inscriptions
```

Picking a suitable fee rate for transactions
---------------------------------------------

Both `ord wallet inscribe` and `ord wallet send` require you to specify a fee
rate for the Bitcoin transaction created. The fee rate determines the fee paid
to miners to include your transaction in the blockchain. Bitcoin transactions
with higher fees are prioritized by miners and are typically processed faster
than transactions with lower fees. The fee rate is the amount of satoshis (the
smallest unit of Bitcoin) per byte of transaction data that you are willing to pay.

The appropriate fee rate depends on several factors, including the current
transaction backlog in the mempool, the size of your transaction, and the
urgency of the transaction. Here are some steps to help you select an appropriate
fee rate:

Check the current transaction backlog. You can use online resources like
[mempool.space](https://mempool.space/) to get an estimate of the current fee
rate needed for a transaction to be processed in a timely manner.

Decide how urgent your transaction is: If you need your transaction to be
processed quickly, you may want to choose a higher fee rate to ensure that
it is included in the next block. If your transaction can wait, you can choose
a lower fee rate.

It's important to note that selecting a fee rate that is too low may result
in your transaction being stuck in the mempool (the list of unconfirmed
transactions) for a long time. The ord wallet does not yet support fee bumping,
so it is important to select an appropriate fee rate when you initially submit
the transaction.

If you want to dive deeper into this topic
[this guide](https://river.com/learn/how-bitcoin-fees-work/) provides a good
starting point.
6 changes: 1 addition & 5 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ struct Output {
pub(crate) struct Inscribe {
#[clap(long, help = "Inscribe <SATPOINT>")]
pub(crate) satpoint: Option<SatPoint>,
#[clap(
long,
default_value = "1.0",
help = "Use fee rate of <FEE_RATE> sats/vB"
)]
#[clap(long, help = "Use fee rate of <FEE_RATE> sats/vB")]
pub(crate) fee_rate: FeeRate,
#[clap(
long,
Expand Down
2 changes: 1 addition & 1 deletion tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Inscribe {
fn inscribe(rpc_server: &test_bitcoincore_rpc::Handle) -> Inscribe {
rpc_server.mine_blocks(1);

let output = CommandBuilder::new("wallet inscribe foo.txt")
let output = CommandBuilder::new("wallet inscribe --fee-rate 1 foo.txt")
.write("foo.txt", "FOO")
.rpc_server(rpc_server)
.output();
Expand Down
85 changes: 54 additions & 31 deletions tests/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn inscribe_works_with_huge_expensive_inscriptions() {
fn inscribe_fails_if_bitcoin_core_is_too_old() {
let rpc_server = test_bitcoincore_rpc::builder().version(230000).build();

CommandBuilder::new("wallet inscribe hello.txt")
CommandBuilder::new("wallet inscribe --fee-rate 1 hello.txt")
.expected_exit_code(1)
.expected_stderr("error: Bitcoin Core 24.0.0 or newer required, current version is 23.0.0\n")
.rpc_server(&rpc_server)
Expand All @@ -57,7 +57,7 @@ fn inscribe_no_backup() {
create_wallet(&rpc_server);
assert_eq!(rpc_server.descriptors().len(), 2);

CommandBuilder::new("wallet inscribe hello.txt --no-backup")
CommandBuilder::new("wallet inscribe --fee-rate 1 hello.txt --no-backup")
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.output::<Inscribe>();
Expand All @@ -71,7 +71,7 @@ fn inscribe_unknown_file_extension() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("wallet inscribe pepe.xyz")
CommandBuilder::new("wallet inscribe --fee-rate 1 pepe.xyz")
.write("pepe.xyz", [1; 520])
.rpc_server(&rpc_server)
.expected_exit_code(1)
Expand All @@ -87,7 +87,7 @@ fn inscribe_exceeds_chain_limit() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("--chain signet wallet inscribe degenerate.png")
CommandBuilder::new("--chain signet wallet inscribe --fee-rate 1 degenerate.png")
.write("degenerate.png", [1; 1025])
.rpc_server(&rpc_server)
.expected_exit_code(1)
Expand Down Expand Up @@ -120,7 +120,7 @@ fn mainnet_has_no_content_size_limit() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("wallet inscribe degenerate.png")
CommandBuilder::new("wallet inscribe --fee-rate 1 degenerate.png")
.write("degenerate.png", [1; 1025])
.rpc_server(&rpc_server)
.stdout_regex(".*")
Expand Down Expand Up @@ -155,12 +155,14 @@ fn refuse_to_reinscribe_sats() {

rpc_server.mine_blocks_with_subsidy(1, 100);

CommandBuilder::new(format!("wallet inscribe --satpoint {reveal}:0:0 hello.txt"))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr(format!("error: sat at {reveal}:0:0 already inscribed\n"))
.run();
CommandBuilder::new(format!(
"wallet inscribe --fee-rate 1 --satpoint {reveal}:0:0 hello.txt"
))
.write("hello.txt", "HELLOWORLD")
.rpc_server(&rpc_server)
.expected_exit_code(1)
.expected_stderr(format!("error: sat at {reveal}:0:0 already inscribed\n"))
.run();
}

#[test]
Expand Down Expand Up @@ -197,11 +199,12 @@ fn inscribe_with_optional_satpoint_arg() {
create_wallet(&rpc_server);
let txid = rpc_server.mine_blocks(1)[0].txdata[0].txid();

let Inscribe { inscription, .. } =
CommandBuilder::new(format!("wallet inscribe foo.txt --satpoint {txid}:0:0"))
.write("foo.txt", "FOO")
.rpc_server(&rpc_server)
.output();
let Inscribe { inscription, .. } = CommandBuilder::new(format!(
"wallet inscribe --fee-rate 1 foo.txt --satpoint {txid}:0:0"
))
.write("foo.txt", "FOO")
.rpc_server(&rpc_server)
.output();

rpc_server.mine_blocks(1);

Expand Down Expand Up @@ -261,10 +264,12 @@ fn inscribe_with_commit_fee_rate() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("--index-sats wallet inscribe degenerate.png --commit-fee-rate 2.0")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();
CommandBuilder::new(
"--index-sats wallet inscribe --fee-rate 1 degenerate.png --commit-fee-rate 2.0",
)
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();

let tx1 = &rpc_server.mempool()[0];
let mut fee = 0;
Expand Down Expand Up @@ -306,7 +311,7 @@ fn inscribe_with_wallet_named_foo() {

rpc_server.mine_blocks(1);

CommandBuilder::new("--wallet foo wallet inscribe degenerate.png")
CommandBuilder::new("--wallet foo wallet inscribe --fee-rate 1 degenerate.png")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();
Expand All @@ -318,14 +323,14 @@ fn inscribe_with_dry_run_flag() {
create_wallet(&rpc_server);
rpc_server.mine_blocks(1);

CommandBuilder::new("wallet inscribe --dry-run degenerate.png")
CommandBuilder::new("wallet inscribe --fee-rate 1 --dry-run degenerate.png")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();

assert!(rpc_server.mempool().is_empty());

CommandBuilder::new("wallet inscribe degenerate.png")
CommandBuilder::new("wallet inscribe --fee-rate 1 degenerate.png")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>();
Expand All @@ -334,19 +339,20 @@ fn inscribe_with_dry_run_flag() {
}

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

let total_fee_dry_run = CommandBuilder::new("wallet inscribe --dry-run degenerate.png")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>()
.fees;
let total_fee_dry_run =
CommandBuilder::new("wallet inscribe --fee-rate 1 --dry-run degenerate.png")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>()
.fees;

let total_fee_normal =
CommandBuilder::new("wallet inscribe --dry-run degenerate.png --fee-rate 1.1")
CommandBuilder::new("wallet inscribe --fee-rate 1 --dry-run degenerate.png --fee-rate 1.1")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.output::<Inscribe>()
Expand All @@ -362,7 +368,24 @@ fn inscribe_with_no_limit() {
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")
CommandBuilder::new("wallet inscribe --fee-rate 1 --no-limit degenerate.png")
.write("degenerate.png", four_megger)
.rpc_server(&rpc_server);
}

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

CommandBuilder::new("wallet inscribe --fee-rate 1 degenerate.png")
.write("degenerate.png", [1; 520])
.rpc_server(&rpc_server)
.expected_exit_code(2)
.stderr_regex(
".*error: The following required arguments were not provided:
.*--fee-rate <FEE_RATE>.*",
)
.run();
}

0 comments on commit 587b0c9

Please sign in to comment.