From 8bafd0c9fa448c3790ed2992f02b8e1245e6c56a Mon Sep 17 00:00:00 2001 From: Byron Hambly Date: Thu, 22 Feb 2024 17:51:52 +0200 Subject: [PATCH] feat: discounted fees for confidential transactions This is a mempool policy only change to enable cheaper fees for Confidential Transactions. At a feerate of 1 sat/vb for a 2 input, 3 output transaction: - explicit tx fee 326 sats - confidential tx fee 408 sats --- src/Makefile.am | 1 + src/chainparams.cpp | 20 ++- src/chainparams.h | 4 + src/core_write.cpp | 7 + src/init.cpp | 2 + src/net_processing.cpp | 4 +- src/policy/discount.h | 45 ++++++ src/policy/policy.h | 1 + src/txmempool.cpp | 10 +- src/txmempool.h | 3 + src/validation.cpp | 7 +- src/wallet/spend.cpp | 5 + test/functional/feature_discount_ct.py | 151 ++++++++++++++++++ test/functional/test_runner.py | 2 + test/util/data/blanktxv1.json | 1 + test/util/data/blanktxv2.json | 1 + test/util/data/tt-delin1-out.json | 1 + test/util/data/tt-delout1-out.json | 1 + test/util/data/tt-locktime317000-out.json | 1 + test/util/data/txcreate1.json | 1 + test/util/data/txcreate2.json | 1 + test/util/data/txcreatedata1.json | 1 + test/util/data/txcreatedata2.json | 1 + test/util/data/txcreatedata_seq0.json | 1 + test/util/data/txcreatedata_seq1.json | 1 + test/util/data/txcreatemultisig1.json | 1 + test/util/data/txcreatemultisig2.json | 1 + test/util/data/txcreatemultisig3.json | 1 + test/util/data/txcreatemultisig4.json | 1 + .../util/data/txcreatemultisig4_elements.json | 1 + test/util/data/txcreatemultisig5.json | 1 + test/util/data/txcreateoutpubkey1.json | 1 + test/util/data/txcreateoutpubkey2.json | 1 + test/util/data/txcreateoutpubkey3.json | 1 + test/util/data/txcreatescript1.json | 1 + test/util/data/txcreatescript2.json | 1 + test/util/data/txcreatescript3.json | 1 + test/util/data/txcreatescript4.json | 1 + test/util/data/txcreatesignv1.json | 1 + 39 files changed, 281 insertions(+), 6 deletions(-) create mode 100644 src/policy/discount.h create mode 100755 test/functional/feature_discount_ct.py diff --git a/src/Makefile.am b/src/Makefile.am index 7a8e53cc342..c84454e1897 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -206,6 +206,7 @@ BITCOIN_CORE_H = \ noui.h \ outputtype.h \ pegins.h \ + policy/discount.h \ policy/feerate.h \ policy/fees.h \ policy/packages.h \ diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 26c39489382..7879f646b2c 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -223,6 +223,8 @@ class CMainParams : public CChainParams { anyonecanspend_aremine = false; enforce_pak = false; multi_data_permitted = false; + accept_discount_ct = false; + create_discount_ct = false; consensus.has_parent_chain = false; g_signed_blocks = false; g_con_elementsmode = false; @@ -361,6 +363,8 @@ class CTestNetParams : public CChainParams { anyonecanspend_aremine = false; enforce_pak = false; multi_data_permitted = false; + accept_discount_ct = false; + create_discount_ct = false; consensus.has_parent_chain = false; g_signed_blocks = false; g_con_elementsmode = false; @@ -517,6 +521,8 @@ class SigNetParams : public CChainParams { anyonecanspend_aremine = false; enforce_pak = false; multi_data_permitted = false; + accept_discount_ct = false; + create_discount_ct = false; consensus.has_parent_chain = false; g_signed_blocks = false; // lol g_con_elementsmode = false; @@ -610,6 +616,8 @@ class CRegTestParams : public CChainParams { anyonecanspend_aremine = false; enforce_pak = false; multi_data_permitted = false; + accept_discount_ct = false; + create_discount_ct = false; consensus.has_parent_chain = false; g_signed_blocks = false; g_con_elementsmode = false; @@ -887,6 +895,8 @@ class CCustomParams : public CRegTestParams { const CScript default_script(CScript() << OP_TRUE); consensus.fedpegScript = StrHexToScriptWithDefault(args.GetArg("-fedpegscript", ""), default_script); consensus.start_p2wsh_script = args.GetIntArg("-con_start_p2wsh_script", consensus.start_p2wsh_script); + accept_discount_ct = args.GetBoolArg("-acceptdiscountct", false); + create_discount_ct = args.GetBoolArg("-creatediscountct", false); // Calculate pegged Bitcoin asset std::vector commit = CommitToArguments(consensus, strNetworkID); @@ -1023,7 +1033,7 @@ class CLiquidTestNetParams : public CCustomParams { */ class CLiquidV1Params : public CChainParams { public: - CLiquidV1Params() + explicit CLiquidV1Params(const ArgsManager& args) { strNetworkID = "liquidv1"; @@ -1118,6 +1128,8 @@ class CLiquidV1Params : public CChainParams { enforce_pak = true; multi_data_permitted = true; + accept_discount_ct = args.GetBoolArg("-acceptdiscountct", true); + create_discount_ct = args.GetBoolArg("-creatediscountct", false); parentGenesisBlockHash = uint256S("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"); const bool parent_genesis_is_null = parentGenesisBlockHash == uint256(); @@ -1261,7 +1273,7 @@ class CLiquidV1Params : public CChainParams { */ class CLiquidV1TestParams : public CLiquidV1Params { public: - explicit CLiquidV1TestParams(const ArgsManager& args) + explicit CLiquidV1TestParams(const ArgsManager& args) : CLiquidV1Params(args) { // Our goal here is to override ONLY the things from liquidv1 that make no sense for a test chain / which are pointless and burdensome to require people to override manually. @@ -1466,6 +1478,8 @@ class CLiquidV1TestParams : public CLiquidV1Params { enforce_pak = args.GetBoolArg("-enforce_pak", enforce_pak); multi_data_permitted = args.GetBoolArg("-multi_data_permitted", multi_data_permitted); + accept_discount_ct = args.GetBoolArg("-acceptdiscountct", accept_discount_ct); + create_discount_ct = args.GetBoolArg("-creatediscountct", create_discount_ct); if (args.IsArgSet("-parentgenesisblockhash")) { parentGenesisBlockHash = uint256S(args.GetArg("-parentgenesisblockhash", "")); @@ -1557,7 +1571,7 @@ std::unique_ptr CreateChainParams(const ArgsManager& args, c } else if (chain == CBaseChainParams::REGTEST) { return std::unique_ptr(new CRegTestParams(args)); } else if (chain == CBaseChainParams::LIQUID1) { - return std::unique_ptr(new CLiquidV1Params()); + return std::unique_ptr(new CLiquidV1Params(args)); } else if (chain == CBaseChainParams::LIQUID1TEST) { return std::unique_ptr(new CLiquidV1TestParams(args)); } else if (chain == CBaseChainParams::LIQUIDTESTNET) { diff --git a/src/chainparams.h b/src/chainparams.h index c4a7e99eab7..a80807a8eba 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -135,6 +135,8 @@ class CChainParams const std::string& ParentBlech32HRP() const { return parent_blech32_hrp; } bool GetEnforcePak() const { return enforce_pak; } bool GetMultiDataPermitted() const { return multi_data_permitted; } + bool GetAcceptDiscountCT() const { return accept_discount_ct; } + bool GetCreateDiscountCT() const { return create_discount_ct; } protected: CChainParams() {} @@ -167,6 +169,8 @@ class CChainParams std::string parent_blech32_hrp; bool enforce_pak; bool multi_data_permitted; + bool accept_discount_ct; + bool create_discount_ct; }; /** diff --git a/src/core_write.cpp b/src/core_write.cpp index 1771ebe0de4..e41b2a760ba 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -9,6 +9,7 @@ #include #include #include +#include // ELEMENTS #include