-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Fix importmulti bug when importing an already imported key #11483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/wallet/rpcdump.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since when success is false returns the associated error, in this situation since there's no associated error, success should be true. Just like calling n times the importprivkey RPC for a given private key: it does not throw any error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but maybe that behaviour is wrong? Search for throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, all previous exit points are exceptions, this is the only early return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but maybe that behaviour is wrong? Search for throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
Right, so we can keep it consistent with the rest of the importmulti logic by throwing that error.
|
This seems like a good change, but why are you calling it a bugfix? Can you add a description of the bug? |
It's a bug because we should receive an array of JSON responses. ❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]'
[ { "success": true } ]
❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]' '{ "rescan": false }'
[ false ] # expected [{ "success": false }] |
5e3c7c4 to
21f75f9
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditional ACK 21f75f90cceeea23995436e6d0f107e265e224ec if new 'Should not import an already imported address' test is either removed or moved to a separate commit, or explained in relation to the bugfix.
test/functional/importmulti.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test below ("Should not import an address with private key if is already imported") seems good, but this test ("Should not import an already imported address") is confusing to me.
For one thing, it doesn't seem to have anything to do with the bug, because it passes both before and after the bugfix. But also the description seems misleading because it is checking that success is true while claiming the address shouldn't be imported.
Would suggest either dropping this new test, or moving it to a separate commit where it is clear this has nothing to do with the bugfix. And the test description should be clarified it it will be kept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm dropping this test.
f4e9446 to
637a338
Compare
637a338 to
a44a215
Compare
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! utACK a44a215. Only changed is dropped test.
|
Any thoughts when this can be merged? |
|
Looks ready to me. Mentioning @laanwj to maybe include in the next batch of merges. |
|
utACK a44a215 |
|
utACK a44a215 |
Github-Pull: bitcoin#11483 Rebased-From: a44a215
a44a215 Fix importmulti bug when importing an already imported key (Pedro Branco) Pull request description: This PR fixes a bug in `importmulti` RPC call where it returns an invalid response when importing an already imported key. Before: ```sh ❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]' [{ "success": true }] ❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]' '{ "rescan": false }' [ false ] ❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]' '{ "rescan": true }' error code: -1 error message: JSON value is not a boolean as expected ``` After this fix: ```sh ❯ bitcoin-cli -rpcuser=u -rpcpassword=p -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655139 }]' [{ "success": true }] ❯ bitcoin-cli -rpcuser=u -rpcpassword=p -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655139 }]' [{ "success": false, "error": { "code": -4, "message": "The wallet already contains the private key for this address or script" } }] ``` Tree-SHA512: 4acebdfb7d0ebd7cd48e943b93ed1cec072db1ace5c42b3f5cc225603764b6e804e4b823b0710965826aafc2f0c615c53d5aefcfdb9bc9c379f5221b798a318c
|
utACK a44a215
(Backport label can be removed)
|
|
utACK a44a215. |
…ported key a44a215 Fix importmulti bug when importing an already imported key (Pedro Branco) Pull request description: This PR fixes a bug in `importmulti` RPC call where it returns an invalid response when importing an already imported key. Before: ```sh ❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]' [{ "success": true }] ❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]' '{ "rescan": false }' [ false ] ❯ bitcoin-cli -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655239 }]' '{ "rescan": true }' error code: -1 error message: JSON value is not a boolean as expected ``` After this fix: ```sh ❯ bitcoin-cli -rpcuser=u -rpcpassword=p -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655139 }]' [{ "success": true }] ❯ bitcoin-cli -rpcuser=u -rpcpassword=p -regtest importmulti '[{ "keys": ["cNcMUunXhVK1dXJ5riixtpYSxPXZnUAMGS4vpzwChdKmYY3Rz99v"], "scriptPubKey": { "address": "n4YZAf4WE2XF3t4BfeYS2nHAhb8CVx91BR" }, "timestamp": 1507655139 }]' [{ "success": false, "error": { "code": -4, "message": "The wallet already contains the private key for this address or script" } }] ``` Tree-SHA512: 4acebdfb7d0ebd7cd48e943b93ed1cec072db1ace5c42b3f5cc225603764b6e804e4b823b0710965826aafc2f0c615c53d5aefcfdb9bc9c379f5221b798a318c
This PR fixes a bug in
importmultiRPC call where it returns an invalid response when importing an already imported key.Before:
After this fix: