Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Nov 17, 2020

Equating 0==None and ""==None is confusing, unneeded and undocumented

@jonatack
Copy link
Member

jonatack commented Nov 17, 2020

Would this change not disable using fee_rate as a positional argument?

The RPCExamples for sendtoaddress and send would need to be updated if this change is made, as the positional fee_rate usage is documented in them.

@maflcko
Copy link
Member Author

maflcko commented Nov 17, 2020

You can pass JSON-None if you'd like to use positional args

@DrahtBot
Copy link
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko
Copy link
Member Author

maflcko commented Nov 17, 2020

Oh, it looks like bitcoin-cli can not properly pass JSON-None? Sounds like a bug

@achow101
Copy link
Member

Oh, it looks like bitcoin-cli can not properly pass JSON-None? Sounds like a bug

You can just use null. It's worked for me before.

@jonatack
Copy link
Member

An example? I haven't managed to make it work via the CLI.

@maflcko
Copy link
Member Author

maflcko commented Nov 18, 2020

It doesn't work for strings because cli will convert null to "null" (string), not Null (null-type)

@maflcko
Copy link
Member Author

maflcko commented Nov 18, 2020

The RPCExamples for sendtoaddress and send would need to be updated

Thanks, done.

@maflcko maflcko force-pushed the 2011-rpcWalletNoneType branch from fa4120f to fa31347 Compare November 18, 2020 07:34
@jonatack
Copy link
Member

Building and testing.

@maflcko maflcko added this to the 0.21.0 milestone Nov 18, 2020
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and the code and CLI examples look good. Perhaps keep the placeholder test coverage but with conf_target=None.

@laanwj
Copy link
Member

laanwj commented Nov 19, 2020

It doesn't work for strings because cli will convert null to "null" (string), not Null (null-type)

Yes, in that case you cannot pass any other kind of JSON type except strings. It's kind of annoying, but there is no non-ambigious way of doing so because every argument is a valid string. Special-casing the string "null" in bitcoin-cli would be awful. At least named arguments can achieve this.

@maflcko maflcko force-pushed the 2011-rpcWalletNoneType branch from fa31347 to fa7df9b Compare November 19, 2020 10:37
@jonatack
Copy link
Member

Tested ACK fa7df9be0d1034d2bbbde19a45b1e706368b4c1b

@jonatack
Copy link
Member

A separate issue I found while testing this: in the as-yet unreleased send RPC, it seems impossible to use "options" as a positional arg, as there is no no-op value for the "fee_rate" arg. So the third example should either be removed, or updated if we fix this via either allowing "fee_rate" to have a no-op value or, more likely, by moving "fee_rate" to after "options" in the args order. I can do this in a fee_rate follow-up PR if not done here.

@maflcko
Copy link
Member Author

maflcko commented Nov 19, 2020

Do you have steps to reproduce? This works fine locally:

$ ./src/bitcoin-cli  send '{"bcrt1q0pqmg4cvjf80x7l7xsrhp65fchg2fw9zk39m74":0.1}'  null "unset" null '{"fee_rate":1.234}'
{
  "txid": "3bda2cb650a3937b676782214837fea6313158a156113e059bd9cad118717ecb",
  "complete": true
}

@jonatack
Copy link
Member

Oh good, thanks, sorry for noise. One of my "null"s was spelled "nul". I think the third week of full lockdown and lack of my usual balance from outdoor sport are getting to me...

$ ./src/bitcoin-cli -signet -rpcwallet="" send '{"tb1qn84cdagw67kpqaz4ugmw76tlhqgdp2jk9zz94j": 0.05}' null "unset" null '{"fee_rate": 1}'
{
  "txid": "25d0924beac73778566909c0658698a4602d2f9444895542f85726e7b5f22465",
  "complete": true
}

@jonatack
Copy link
Member

jonatack commented Nov 19, 2020

This send example was incorrect and needs to be updated:

Send 0.2 BTC with a fee rate of 1 sat/vB using the options argument
> bitcoin-cli send '{"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl": 0.2}' '{"fee_rate": 1}'

@maflcko maflcko force-pushed the 2011-rpcWalletNoneType branch from fa7df9b to fa69c2c Compare November 19, 2020 12:53
@maflcko
Copy link
Member Author

maflcko commented Nov 19, 2020

Good catch. Didn't realize the example was wrong, too. Now fixed.

@jonatack
Copy link
Member

ACK fa69c2c

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK fa69c2c modulo unset

I don't think treating ""==None is particularly ambiguous, but null is not too bad.

* if a fee_rate is present, "" is allowed here as a no-op positional placeholder
* @param[in] fee_rate UniValue real; fee rate in sat/vB;
* if a fee_rate is present, both conf_target and estimate_mode must either be null, or no-op
* if present, both conf_target and estimate_mode must either be null, or "unset"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estimate_mode can't be null for send and sendtoaddress. It will throw Cannot specify both estimate_mode and fee_rate. It does if you add it to client.cpp, but then unset and "unset" throw error: Error parsing JSON: unset.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that comment is a bit ambiguous; IIRC null is only for conf_target and unset only for estimate_mode.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

estimate_mode can't be null for send and sendtoaddress. It will throw Cannot specify both estimate_mode and fee_rate.

This comment is in the server code, where it can be null, not in the client code. You can trivially check with this diff, so I think the comment is correct:

diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py
index ac4a6e4948..17c013d26a 100755
--- a/test/functional/wallet_basic.py
+++ b/test/functional/wallet_basic.py
@@ -235,7 +235,7 @@ class WalletTest(BitcoinTestFramework):
         fee_rate_btc_kvb = fee_rate_sat_vb * 1e3 / 1e8
         explicit_fee_rate_btc_kvb = Decimal(fee_rate_btc_kvb) / 1000
 
-        txid = self.nodes[2].sendmany(amounts={address: 10}, fee_rate=fee_rate_sat_vb)
+        txid = self.nodes[2].sendmany(amounts={address: 10}, fee_rate=fee_rate_sat_vb, estimate_mode=None)
         self.nodes[2].generate(1)
         self.sync_all(self.nodes[0:3])
         balance = self.nodes[2].getbalance()
@@ -406,7 +406,7 @@ class WalletTest(BitcoinTestFramework):
             fee_rate_sat_vb = 2
             fee_rate_btc_kvb = fee_rate_sat_vb * 1e3 / 1e8
 
-            txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=fee_rate_sat_vb)
+            txid = self.nodes[2].sendtoaddress(address=address, amount=amount, fee_rate=fee_rate_sat_vb, estimate_mode=None)
             tx_size = self.get_vsize(self.nodes[2].gettransaction(txid)['hex'])
             self.nodes[0].generate(1)
             self.sync_all(self.nodes[0:3])

@maflcko
Copy link
Member Author

maflcko commented Nov 23, 2020

I don't think treating ""==None is particularly ambiguous

Fair enough, but it wasn't documented in the RPCArg help. I think keeping the already existing "unset" is sufficient and adding more alternative strings to do the same thing isn't going to help.

@achow101
Copy link
Member

ACK fa69c2c

@maflcko
Copy link
Member Author

maflcko commented Nov 25, 2020

Backported in #20485

maflcko pushed a commit that referenced this pull request Nov 25, 2020
…es as None-type

fa69c2c wallet: Do not treat default constructed types as None-type (MarcoFalke)
fac4e13 refactor: Change pointer to reference because it can not be null (MarcoFalke)

Pull request description:

  Github-Pull: #20410
  Rebased-From: fac4e13

  Github-Pull: #20410
  Rebased-From: fa69c2c

Top commit has no ACKs.

Tree-SHA512: 05c3fe29677710b57dcc482fd529b0ab79475519f60f9cfde19f956c4e2212d09b042af458ec4f1272c581360ce841b735dca4df144e0798b3ccf16547de9cd0
@maflcko maflcko deleted the 2011-rpcWalletNoneType branch November 25, 2020 10:28
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 25, 2020
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants