diff --git a/doc/release-notes-16884.md b/doc/release-notes-16884.md new file mode 100644 index 0000000000..e721080397 --- /dev/null +++ b/doc/release-notes-16884.md @@ -0,0 +1,2 @@ +The wallet now by default uses bech32 addresses when using RPC, and creates native segwit +change outputs. diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index fcff234687..caeb938543 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -201,7 +201,6 @@ public: return GuessVerificationProgress(tip, Params().GetConsensus().nPowTargetSpacing); } bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); } - bool isAddressTypeSet() override { return !::gArgs.GetArg("-addresstype", "").empty(); } bool getReindex() override { return ::fReindex; } bool getImporting() override { return ::fImporting; } void setNetworkActive(bool active) override diff --git a/src/interfaces/node.h b/src/interfaces/node.h index 2f4f396e72..688ff434ba 100644 --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -155,9 +155,6 @@ public: //! Is initial block download. virtual bool isInitialBlockDownload() = 0; - //! Is -addresstype set. - virtual bool isAddressTypeSet() = 0; - //! Get reindex. virtual bool getReindex() = 0; diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index d92b7b826a..8130d82864 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -103,16 +102,10 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model) columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this); #endif - if (model->node().isAddressTypeSet()) { - // user explicitly set the type, use it - if (model->wallet().getDefaultAddressType() == OutputType::BECH32) { - ui->useBech32->setCheckState(Qt::Checked); - } else { - ui->useBech32->setCheckState(Qt::Unchecked); - } - } else { - // Always fall back to bech32 in the gui + if (model->wallet().getDefaultAddressType() == OutputType::BECH32) { ui->useBech32->setCheckState(Qt::Checked); + } else { + ui->useBech32->setCheckState(Qt::Unchecked); } // Set the button to be enabled or disabled based on whether the wallet can give out new addresses. diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index d2c92e85e1..7978bf4af6 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -121,7 +121,7 @@ enum WalletFeature }; //! Default for -addresstype -constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::P2SH_SEGWIT}; +constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32}; //! Default for -changetype constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO}; diff --git a/test/functional/feature_bip68_sequence.py b/test/functional/feature_bip68_sequence.py index c60d1ee53d..eff4598fc5 100755 --- a/test/functional/feature_bip68_sequence.py +++ b/test/functional/feature_bip68_sequence.py @@ -30,9 +30,10 @@ NOT_FINAL_ERROR = "non-BIP68-final (code 64)" class BIP68Test(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 + # TODO remove output type argument and fix resulting "tx-size-small" errors self.extra_args = [ - ["-acceptnonstdtxn=1"], - ["-acceptnonstdtxn=0"], + ["-acceptnonstdtxn=1", "-addresstype=p2sh-segwit"], + ["-acceptnonstdtxn=0", "-addresstype=p2sh-segwit"], ] def skip_test_if_missing_module(self): diff --git a/test/functional/feature_confidential_transactions.py b/test/functional/feature_confidential_transactions.py index 82608a1172..dde2eb9fe7 100755 --- a/test/functional/feature_confidential_transactions.py +++ b/test/functional/feature_confidential_transactions.py @@ -683,7 +683,7 @@ class CTTest (BitcoinTestFramework): found_burn = True if output["asset"] != self.nodes[0].dumpassetlabels()["bitcoin"]: raise Exception("Burn should have been bitcoin(policyAsset)") - if output["scriptPubKey"]["type"] == "scripthash": + if output["scriptPubKey"]["type"] == "witness_v0_keyhash": found_pay = True assert found_pay and found_burn @@ -697,7 +697,7 @@ class CTTest (BitcoinTestFramework): found_burn = True if output["asset"] != "deadbeef"*8: raise Exception("Burn should have been deadbeef") - if output["scriptPubKey"]["type"] == "scripthash": + if output["scriptPubKey"]["type"] == "witness_v0_keyhash": found_pay = True assert found_pay and found_burn diff --git a/test/functional/feature_rbf.py b/test/functional/feature_rbf.py index 2f060fa256..e3c912952c 100755 --- a/test/functional/feature_rbf.py +++ b/test/functional/feature_rbf.py @@ -73,6 +73,7 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])): class ReplaceByFeeTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 + # TODO remove output type argument and fix resulting "tx-size-small" errors self.extra_args = [ [ "-acceptnonstdtxn=1", @@ -81,6 +82,7 @@ class ReplaceByFeeTest(BitcoinTestFramework): "-limitancestorsize=101", "-limitdescendantcount=200", "-limitdescendantsize=101", + "-addresstype=p2sh-segwit", ], ] diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 0df7406fd5..c8d2fdc79c 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -185,11 +185,11 @@ class PSBTTest(BitcoinTestFramework): assert(self.num_blinded_outputs(hex_tx) > 0) self.nodes[1].sendrawtransaction(hex_tx) - # feeRate of 0.085 BTC / KB produces a total fee slightly below -maxtxfee (~0.05210000): + # feeRate of 0.1 BTC / KB produces a total fee slightly below -maxtxfee (~0.05420000): if confidential: fee_rate = 0.04 else: - fee_rate = 0.085 + fee_rate = 0.1 res = self.nodes[1].walletcreatefundedpsbt([{"txid":txid,"vout":p2wpkh_pos},{"txid":txid,"vout":p2sh_p2wpkh_pos},{"txid":txid,"vout":p2pkh_pos}], {self.nodes[1].getnewaddress():29.99}, 0, {"feeRate": fee_rate}) assert_greater_than(res["fee"], 0.05) assert_greater_than(0.06, res["fee"]) diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py index 105662dd47..1f6d338a82 100755 --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -470,12 +470,12 @@ class RawTransactionsTest(BitcoinTestFramework): self.sync_all() inputs = [{ "txid" : txId, "vout" : vout['n'] }] - # Fee 4,000,000 satoshis, (1 - (4000000 sat * 0.00000001 BTC/sat)) = 0.96 - outputs = { self.nodes[0].getnewaddress() : Decimal("0.96000000"), "fee": Decimal("0.04") } + # Fee 3,000,000 satoshis, (1 - (3000000 sat * 0.00000001 BTC/sat)) = 0.97 + outputs = { self.nodes[0].getnewaddress() : Decimal("0.97000000"), "fee": Decimal("0.03") } rawTx = self.nodes[2].createrawtransaction(inputs, outputs) rawTxSigned = self.nodes[2].signrawtransactionwithwallet(rawTx) assert_equal(rawTxSigned['complete'], True) - # 4,000,000 sat fee, ~200 wt transaction, fee rate should land around 20,000 sat/b = 0.20000000 BTC/kB + # 3,000,000 sat fee, fee rate should land around 20,000 sat/b = 0.20000000 BTC/kB # Thus, testmempoolaccept should reject testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']])[0] assert_equal(testres['allowed'], False) diff --git a/test/functional/wallet_address_types.py b/test/functional/wallet_address_types.py index 629beb8cb8..b026157ac9 100755 --- a/test/functional/wallet_address_types.py +++ b/test/functional/wallet_address_types.py @@ -350,7 +350,7 @@ class AddressTypeTest(BitcoinTestFramework): self.sync_blocks() assert_equal(self.nodes[4].getbalance()['bitcoin'], 1) - self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output") + self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output (unless changetype is set otherwise):") self.test_change_output_type(0, [to_address_bech32_1], 'legacy') self.log.info("Nodes with addresstype=p2sh-segwit only use a P2WPKH change output if any destination address is bech32:") diff --git a/test/functional/wallet_balance.py b/test/functional/wallet_balance.py index 7d9da4bf6b..6508cbafcf 100755 --- a/test/functional/wallet_balance.py +++ b/test/functional/wallet_balance.py @@ -193,8 +193,8 @@ class WalletTest(BitcoinTestFramework): struct.pack(">q", 98 * 10**8).hex(), ) tx_replace = tx_replace.replace( ## is there something less fragile we can do here? - struct.pack(">q", 7480).hex(), - struct.pack(">q", 7480 + 10**8).hex(), + struct.pack(">q", 6520).hex(), + struct.pack(">q", 6520 + 10**8).hex(), ) tx_replace = self.nodes[0].signrawtransactionwithwallet(tx_replace)['hex'] # Total balance is given by the sum of outputs of the tx diff --git a/test/functional/wallet_basic.py b/test/functional/wallet_basic.py index 860fc5a918..30e1d6e33a 100755 --- a/test/functional/wallet_basic.py +++ b/test/functional/wallet_basic.py @@ -320,7 +320,7 @@ class WalletTest(BitcoinTestFramework): assert_raises_rpc_error(-5, "Invalid private key encoding", self.nodes[0].importprivkey, "invalid") # This will raise an exception for importing an address with the PS2H flag - temp_address = self.nodes[1].getnewaddress() + temp_address = self.nodes[1].getnewaddress("", "p2sh-segwit") assert_raises_rpc_error(-5, "Cannot use the p2sh flag with an address - use a script instead", self.nodes[0].importaddress, temp_address, "label", False, True) # This will raise an exception for attempting to dump the private key of an address you do not own diff --git a/test/functional/wallet_bumpfee.py b/test/functional/wallet_bumpfee.py index 3a1720bcef..71cab44b3e 100755 --- a/test/functional/wallet_bumpfee.py +++ b/test/functional/wallet_bumpfee.py @@ -39,6 +39,7 @@ class BumpFeeTest(BitcoinTestFramework): "-walletrbf={}".format(i), "-mintxfee=0.00002", "-deprecatedrpc=totalFee", + "-addresstype=p2sh-segwit", # TODO update constants in test and remove ] for i in range(self.num_nodes)] def skip_test_if_missing_module(self): diff --git a/test/functional/wallet_import_with_label.py b/test/functional/wallet_import_with_label.py index a623b75606..2a9051b1e8 100755 --- a/test/functional/wallet_import_with_label.py +++ b/test/functional/wallet_import_with_label.py @@ -100,8 +100,8 @@ class ImportWithLabel(BitcoinTestFramework): "Test importprivkey won't label new dests with the same " "label as others labeled dests for the same key." ) - self.log.info("Import a watch-only legacy address with a label.") - address4 = self.nodes[0].getnewaddress() + self.log.info("Import a watch-only p2sh-segwit address with a label.") + address4 = self.nodes[0].getnewaddress("", "p2sh-segwit") label4_addr = "Test Label 4 for importaddress" self.nodes[1].importaddress(address4, label4_addr) test_address(self.nodes[1],