From 3526d22ab1ed1e200708b16e035133473f4356ba Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sat, 11 May 2019 22:42:51 +0000 Subject: [PATCH 01/15] Replace consensus values with Dogecoin equivalents * Replace chain parameters with Dogecoin values * Update maximum coins to match Dogecoin * Disable version 2 block requirement * Update coinbase maturity to match Dogecoin --- src/amount.h | 2 +- src/chainparams.cpp | 2 +- src/protocol.cpp | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/amount.h b/src/amount.h index bf50e372c78..4eafde1c362 100644 --- a/src/amount.h +++ b/src/amount.h @@ -23,7 +23,7 @@ static const CAmount CENT = 1000000; * critical; in unusual circumstances like a(nother) overflow bug that allowed * for the creation of coins out of thin air modification could lead to a fork. * */ -static const CAmount MAX_MONEY = 1000000000 * COIN; // Dogecoin: maximum of 100B coins (given some randomness), max transaction 10,000,000,000 +static const CAmount MAX_MONEY = 10000000000 * COIN; // Dogecoin: maximum of 100B coins (given some randomness), max transaction 10,000,000,000 inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); } #endif // BITCOIN_AMOUNT_H diff --git a/src/chainparams.cpp b/src/chainparams.cpp index ca0ed39827c..eaba5a9aafc 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -313,7 +313,7 @@ class CRegTestParams : public CChainParams { consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT; consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1; consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE; - consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT; + consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 0; // Disabled // The best chain should have at least this much work. consensus.nMinimumChainWork = uint256S("0x00"); diff --git a/src/protocol.cpp b/src/protocol.cpp index b4fc9def1fd..6223604ad93 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -131,9 +131,13 @@ bool CMessageHeader::IsValid(const MessageStartChars& pchMessageStartIn) const ServiceFlags GetDesirableServiceFlags(ServiceFlags services) { if ((services & NODE_NETWORK_LIMITED) && g_initial_block_download_completed) { - return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS); + // Dogecoin: Disable segwit + // return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS); + return ServiceFlags(NODE_NETWORK_LIMITED); } - return ServiceFlags(NODE_NETWORK | NODE_WITNESS); + // Dogecoin: Disable segwit + // return ServiceFlags(NODE_NETWORK | NODE_WITNESS); + return ServiceFlags(NODE_NETWORK); } void SetServiceFlagsIBDCache(bool state) { From 2af4ea6fa786cf1ef01aa81c5d8353c4023912ea Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Tue, 26 Dec 2017 00:22:51 +0000 Subject: [PATCH 02/15] Stop sending a Bitcoin alert to Dogecoin clients --- src/net_processing.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index bf6cb77c13f..ed2c644a879 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1783,12 +1783,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr AddTimeData(pfrom->addr, nTimeOffset); // If the peer is old enough to have the old alert system, send it the final alert. - // XXX: Decide how to handle alert migration in Dogecoin and either make this a Dogecoin - // alert or re-introduce the system - if (pfrom->nVersion <= 70012) { + /* if (pfrom->nVersion <= 70012) { + // TODO: Replace this with a valid Dogecoin alert + // Disabled meantime as the remote client considers the nonsense alert a hack and drops the connection CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION); connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert)); - } + } */ // Feeler connections exist only to verify if address is online. if (pfrom->fFeeler) { From 1daa143020df4aff1d4ec39014c4ab9a219752ef Mon Sep 17 00:00:00 2001 From: Max K Date: Thu, 28 Dec 2017 22:41:29 +0100 Subject: [PATCH 03/15] Fix 1.14 unit tests (#1408) * Fix BlockEncodings test by setting a legacy block version * Fix RPC test by adding missing RPC call * Add missing regtest genesis hashes --- src/test/blockencodings_tests.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index 3af169250c7..c9aa54a3505 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -30,9 +30,8 @@ static CBlock BuildBlockTestCase() { block.vtx.resize(3); block.vtx[0] = MakeTransactionRef(tx); - block.nVersion = 42; + block.nVersion = 1; block.hashPrevBlock = InsecureRand256(); - block.nBits = 0x207fffff; tx.vin[0].prevout.hash = InsecureRand256(); tx.vin[0].prevout.n = 0; @@ -289,7 +288,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest) CBlock block; block.vtx.resize(1); block.vtx[0] = MakeTransactionRef(std::move(coinbase)); - block.nVersion = 42; + block.nVersion = 1; block.hashPrevBlock = InsecureRand256(); block.nBits = 0x207fffff; From 3c30bd24427207a351df60bf83d48f15665132f5 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 1 Jan 2018 16:29:58 +0000 Subject: [PATCH 04/15] Update dogecoin-tx tests (#1409) Update Python test address and key values to match Dogecoin format --- test/util/data/bitcoin-util-test.json | 32 +++++++++++------------ test/util/data/tt-delin1-out.json | 4 +-- test/util/data/tt-delout1-out.json | 2 +- test/util/data/tt-locktime317000-out.json | 4 +-- test/util/data/txcreate1.json | 4 +-- test/util/data/txcreatedata1.json | 2 +- test/util/data/txcreatedata2.json | 2 +- test/util/data/txcreatedata_seq0.json | 2 +- test/util/data/txcreatedata_seq1.json | 2 +- test/util/data/txcreatemultisig1.json | 6 ++--- test/util/data/txcreatemultisig2.json | 2 +- test/util/data/txcreatemultisig4.json | 2 +- test/util/data/txcreateoutpubkey1.json | 2 +- test/util/data/txcreateoutpubkey3.json | 2 +- test/util/data/txcreatescript2.json | 2 +- test/util/data/txcreatescript4.json | 2 +- test/util/data/txcreatesignv1.json | 2 +- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json index f2213f4f2e3..edf5f3446f2 100644 --- a/test/util/data/bitcoin-util-test.json +++ b/test/util/data/bitcoin-util-test.json @@ -157,8 +157,8 @@ "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0", "in=bf829c6bcf84579331337659d31f89dfd138f7f7785802d5501c92333145ca7c:18", "in=22a6f904655d53ae2ff70e701a0bbd90aa3975c0f40bfc6cc996a9049e31cdfc:1", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o", - "outaddr=4:1P8yWvZW8jVihP1bzHeqfE4aoXNX8AVa46"], + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd", + "outaddr=4:DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U"], "output_cmp": "txcreate1.hex", "description": "Creates a new transaction with three inputs and two outputs" }, @@ -169,8 +169,8 @@ "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0", "in=bf829c6bcf84579331337659d31f89dfd138f7f7785802d5501c92333145ca7c:18", "in=22a6f904655d53ae2ff70e701a0bbd90aa3975c0f40bfc6cc996a9049e31cdfc:1", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o", - "outaddr=4:1P8yWvZW8jVihP1bzHeqfE4aoXNX8AVa46"], + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd", + "outaddr=4:DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U"], "output_cmp": "txcreate1.json", "description": "Creates a new transaction with three inputs and two outputs (output in json)" }, @@ -238,10 +238,10 @@ "args": ["-create", "nversion=1", "in=4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485:0", - "set=privatekeys:[\"5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf\"]", + "set=privatekeys:[\"6J8csdv3eDrnJcpSEb4shfjMh2JTiG9MKzC1Yfge4Y4GyUsjdM6\"]", "set=prevtxs:[{\"txid\":\"4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485\",\"vout\":0,\"scriptPubKey\":\"76a91491b24bf9f5288532960ac687abb035127b1d28a588ac\"}]", "sign=ALL", - "outaddr=0.001:193P6LtvS4nCnkDvM9uXn1gsSRqh4aDAz7"], + "outaddr=0.001:DDBUdbqZjUgVKkQX5ju6KmrUKZZzPu2aZc"], "output_cmp": "txcreatesignv1.hex", "description": "Creates a new v1 transaction with a single input and a single output, and then signs the transaction" }, @@ -250,10 +250,10 @@ ["-json", "-create", "nversion=1", "in=4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485:0", - "set=privatekeys:[\"5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf\"]", + "set=privatekeys:[\"6J8csdv3eDrnJcpSEb4shfjMh2JTiG9MKzC1Yfge4Y4GyUsjdM6\"]", "set=prevtxs:[{\"txid\":\"4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485\",\"vout\":0,\"scriptPubKey\":\"76a91491b24bf9f5288532960ac687abb035127b1d28a588ac\"}]", "sign=ALL", - "outaddr=0.001:193P6LtvS4nCnkDvM9uXn1gsSRqh4aDAz7"], + "outaddr=0.001:DDBUdbqZjUgVKkQX5ju6KmrUKZZzPu2aZc"], "output_cmp": "txcreatesignv1.json", "description": "Creates a new v1 transaction with a single input and a single output, and then signs the transaction (output in json)" }, @@ -261,10 +261,10 @@ "args": ["-create", "in=4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485:0", - "set=privatekeys:[\"5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf\"]", + "set=privatekeys:[\"6J8csdv3eDrnJcpSEb4shfjMh2JTiG9MKzC1Yfge4Y4GyUsjdM6\"]", "set=prevtxs:[{\"txid\":\"4d49a71ec9da436f71ec4ee231d04f292a29cd316f598bb7068feccabdc59485\",\"vout\":0,\"scriptPubKey\":\"76a91491b24bf9f5288532960ac687abb035127b1d28a588ac\"}]", "sign=ALL", - "outaddr=0.001:193P6LtvS4nCnkDvM9uXn1gsSRqh4aDAz7"], + "outaddr=0.001:DDBUdbqZjUgVKkQX5ju6KmrUKZZzPu2aZc"], "output_cmp": "txcreatesignv2.hex", "description": "Creates a new transaction with a single input and a single output, and then signs the transaction" }, @@ -345,7 +345,7 @@ "args": ["-create", "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o", + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd", "outdata=4:54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"], "output_cmp": "txcreatedata1.hex", "description": "Creates a new transaction with one input, one address output and one data output" @@ -355,7 +355,7 @@ ["-json", "-create", "nversion=1", "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o", + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd", "outdata=4:54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"], "output_cmp": "txcreatedata1.json", "description": "Creates a new v1 transaction with one input, one address output and one data output (output in json)" @@ -364,7 +364,7 @@ "args": ["-create", "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o", + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd", "outdata=54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"], "output_cmp": "txcreatedata2.hex", "description": "Creates a new transaction with one input, one address output and one data (zero value) output" @@ -374,7 +374,7 @@ ["-json", "-create", "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o", + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd", "outdata=54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e"], "output_cmp": "txcreatedata2.json", "description": "Creates a new transaction with one input, one address output and one data (zero value) output (output in json)" @@ -383,7 +383,7 @@ "args": ["-create", "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:4294967293", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o"], + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd"], "output_cmp": "txcreatedata_seq0.hex", "description": "Creates a new transaction with one input with sequence number and one address output" }, @@ -392,7 +392,7 @@ ["-json", "-create", "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0:4294967293", - "outaddr=0.18:13tuJJDR2RgArmgfv6JScSdreahzgc4T6o"], + "outaddr=0.18:D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd"], "output_cmp": "txcreatedata_seq0.json", "description": "Creates a new transaction with one input with sequence number and one address output (output in json)" }, diff --git a/test/util/data/tt-delin1-out.json b/test/util/data/tt-delin1-out.json index 9fc2ddc376e..9fe18ea0068 100644 --- a/test/util/data/tt-delin1-out.json +++ b/test/util/data/tt-delin1-out.json @@ -198,7 +198,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o" + "DJFXow7CYcBWKVjwe1VH4or5f6YetLH1hw" ] } }, @@ -211,7 +211,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "1AtWkdmfmYkErU16d3KYykJUbEp9MAj9Sb" + "DF2cHtiK4xeXPUBhMdK7XWU5UNYSg2KFvt" ] } } diff --git a/test/util/data/tt-delout1-out.json b/test/util/data/tt-delout1-out.json index 922d0489009..14a448b3d98 100644 --- a/test/util/data/tt-delout1-out.json +++ b/test/util/data/tt-delout1-out.json @@ -207,7 +207,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o" + "DJFXow7CYcBWKVjwe1VH4or5f6YetLH1hw" ] } } diff --git a/test/util/data/tt-locktime317000-out.json b/test/util/data/tt-locktime317000-out.json index c97206f1ead..2af021d3ab6 100644 --- a/test/util/data/tt-locktime317000-out.json +++ b/test/util/data/tt-locktime317000-out.json @@ -207,7 +207,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o" + "DJFXow7CYcBWKVjwe1VH4or5f6YetLH1hw" ] } }, @@ -220,7 +220,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "1AtWkdmfmYkErU16d3KYykJUbEp9MAj9Sb" + "DF2cHtiK4xeXPUBhMdK7XWU5UNYSg2KFvt" ] } } diff --git a/test/util/data/txcreate1.json b/test/util/data/txcreate1.json index ca9eacd5469..118416eb24f 100644 --- a/test/util/data/txcreate1.json +++ b/test/util/data/txcreate1.json @@ -45,7 +45,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "13tuJJDR2RgArmgfv6JScSdreahzgc4T6o" + "D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd" ] } }, @@ -58,7 +58,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "1P8yWvZW8jVihP1bzHeqfE4aoXNX8AVa46" + "DTH54BW9S9Q1EPCCiseQCzEBgf6pTRZv3U" ] } } diff --git a/test/util/data/txcreatedata1.json b/test/util/data/txcreatedata1.json index 39909c2e3fb..eb666b3c5a1 100644 --- a/test/util/data/txcreatedata1.json +++ b/test/util/data/txcreatedata1.json @@ -27,7 +27,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "13tuJJDR2RgArmgfv6JScSdreahzgc4T6o" + "D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd" ] } }, diff --git a/test/util/data/txcreatedata2.json b/test/util/data/txcreatedata2.json index 2958006e588..043e5d91931 100644 --- a/test/util/data/txcreatedata2.json +++ b/test/util/data/txcreatedata2.json @@ -27,7 +27,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "13tuJJDR2RgArmgfv6JScSdreahzgc4T6o" + "D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd" ] } }, diff --git a/test/util/data/txcreatedata_seq0.json b/test/util/data/txcreatedata_seq0.json index a6656b5ad51..9f6449cf267 100644 --- a/test/util/data/txcreatedata_seq0.json +++ b/test/util/data/txcreatedata_seq0.json @@ -27,7 +27,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "13tuJJDR2RgArmgfv6JScSdreahzgc4T6o" + "D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd" ] } } diff --git a/test/util/data/txcreatedata_seq1.json b/test/util/data/txcreatedata_seq1.json index e5980427b19..f5d6a0e3d34 100644 --- a/test/util/data/txcreatedata_seq1.json +++ b/test/util/data/txcreatedata_seq1.json @@ -36,7 +36,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "13tuJJDR2RgArmgfv6JScSdreahzgc4T6o" + "D82zqZA4KqaTPmsGegJ1ACoTXiSJ21NcZd" ] } } diff --git a/test/util/data/txcreatemultisig1.json b/test/util/data/txcreatemultisig1.json index c32e755db1c..8b6b599eddd 100644 --- a/test/util/data/txcreatemultisig1.json +++ b/test/util/data/txcreatemultisig1.json @@ -18,9 +18,9 @@ "reqSigs": 2, "type": "multisig", "addresses": [ - "1FoG2386FG2tAJS9acMuiDsKy67aGg9MKz", - "1FXtz9KU8JNmQDyHdiEm5HDiALuP3zdHvV", - "14LuavcBbXZYJ6Tsz3cAUQj9SuQoL2xCQX" + "DKwMZJ4jYfwAhJckKCMUFz2vrDqscXPMxB", + "DKfzXQG7RiH3wE9tNJEKd3PK3UdgQshoTP", + "D8V18BYptwTpq6eUidbj2AtkL396fFAR4Y" ] } } diff --git a/test/util/data/txcreatemultisig2.json b/test/util/data/txcreatemultisig2.json index f97d265894e..aa39e674260 100644 --- a/test/util/data/txcreatemultisig2.json +++ b/test/util/data/txcreatemultisig2.json @@ -18,7 +18,7 @@ "reqSigs": 1, "type": "scripthash", "addresses": [ - "34HNh57oBCRKkxNyjTuWAJkTbuGh6jg2Ms" + "9u2dRvBhFGJDfKkT9bZvQSNqJUejBBgsLa" ] } } diff --git a/test/util/data/txcreatemultisig4.json b/test/util/data/txcreatemultisig4.json index a00dbe3f5d0..5f80e14819a 100644 --- a/test/util/data/txcreatemultisig4.json +++ b/test/util/data/txcreatemultisig4.json @@ -18,7 +18,7 @@ "reqSigs": 1, "type": "scripthash", "addresses": [ - "3BoFUz1StqcNcgUTZE5cC1eFhuYFzj3fGH" + "A2YWDq5LxuVGX3qvyMk2S9GdQUvJ8zaCmF" ] } } diff --git a/test/util/data/txcreateoutpubkey1.json b/test/util/data/txcreateoutpubkey1.json index 32097b3ebe2..7a7ee1aa258 100644 --- a/test/util/data/txcreateoutpubkey1.json +++ b/test/util/data/txcreateoutpubkey1.json @@ -18,7 +18,7 @@ "reqSigs": 1, "type": "pubkey", "addresses": [ - "1FoG2386FG2tAJS9acMuiDsKy67aGg9MKz" + "DKwMZJ4jYfwAhJckKCMUFz2vrDqscXPMxB" ] } } diff --git a/test/util/data/txcreateoutpubkey3.json b/test/util/data/txcreateoutpubkey3.json index 4d904df3c8a..f79ec8f5918 100644 --- a/test/util/data/txcreateoutpubkey3.json +++ b/test/util/data/txcreateoutpubkey3.json @@ -18,7 +18,7 @@ "reqSigs": 1, "type": "scripthash", "addresses": [ - "3GnzN8FqgvYGYdhj8NW6UNxxVv3Uj1ApQn" + "A7YF6yKjkzRAT15CYWAWiWbLCVRWprcqiC" ] } } diff --git a/test/util/data/txcreatescript2.json b/test/util/data/txcreatescript2.json index 32dd644579a..beba364f184 100644 --- a/test/util/data/txcreatescript2.json +++ b/test/util/data/txcreatescript2.json @@ -18,7 +18,7 @@ "reqSigs": 1, "type": "scripthash", "addresses": [ - "3C5QarEGh9feKbDJ3QbMf2YNjnMoiPDhNp" + "A2pfKhJAmDYYDxamTYFmuAAkSMjqqvitJd" ] } } diff --git a/test/util/data/txcreatescript4.json b/test/util/data/txcreatescript4.json index 2271ecfa0ac..5cec05c80eb 100644 --- a/test/util/data/txcreatescript4.json +++ b/test/util/data/txcreatescript4.json @@ -18,7 +18,7 @@ "reqSigs": 1, "type": "scripthash", "addresses": [ - "3BNQbeFeJJGMAyDxPwWPuqxPMrjsFLjk3f" + "A27fLVKYNN9F5LbRp5Ap9yam4S7uJt2jsu" ] } } diff --git a/test/util/data/txcreatesignv1.json b/test/util/data/txcreatesignv1.json index 7a06aa9ffea..1b0ba87b085 100644 --- a/test/util/data/txcreatesignv1.json +++ b/test/util/data/txcreatesignv1.json @@ -27,7 +27,7 @@ "reqSigs": 1, "type": "pubkeyhash", "addresses": [ - "193P6LtvS4nCnkDvM9uXn1gsSRqh4aDAz7" + "DDBUdbqZjUgVKkQX5ju6KmrUKZZzPu2aZc" ] } } From ea4c76b00362ca16341bca9abbed5a425465797e Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 8 Jan 2018 19:32:01 +0000 Subject: [PATCH 05/15] Check only the base block version (#1411) Check only the base block version when looking for unexpected version numbers --- src/chain.h | 10 +++++++++- src/validation.cpp | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/chain.h b/src/chain.h index ca10f4449a5..902b25cb92d 100644 --- a/src/chain.h +++ b/src/chain.h @@ -347,12 +347,20 @@ class CBlockIndex CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; + /** + * Check if the auxpow flag is set in the version. + * @return True if this block version is marked as auxpow. + */ + inline bool IsAuxpow() const + { + return nVersion & CPureBlockHeader::VERSION_AUXPOW; + } + /* Analyse the block version. */ inline int GetBaseVersion() const { return CPureBlockHeader::GetBaseVersion(nVersion); } - }; arith_uint256 GetBlockProof(const CBlockIndex& block); diff --git a/src/validation.cpp b/src/validation.cpp index 0086d391142..6a026f063b4 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2287,7 +2287,7 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar for (int i = 0; i < 100 && pindex != nullptr; i++) { int32_t nExpectedVersion = ComputeBlockVersion(pindex->pprev, chainParams.GetConsensus()); - if (pindex->nVersion > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->nVersion & ~nExpectedVersion) != 0) + if (pindex->GetBaseVersion() > VERSIONBITS_LAST_OLD_BLOCK_VERSION && (pindex->GetBaseVersion() & ~nExpectedVersion) != 0) ++nUpgraded; pindex = pindex->pprev; } From 74a563136db67ea9326cd366733009189c7dd031 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Thu, 11 Jan 2018 21:04:33 +0000 Subject: [PATCH 06/15] Load AuxPoW blocks from index correctly (#1443) Load AuxPoW blocks from index correctly, by setting the version on the block before trying to check if it's AuxPoW. Previously the AuxPoW part of the block was never loaded because the check always failed. --- src/chain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chain.cpp b/src/chain.cpp index 5cb09f6fc68..992c4e1e4a4 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -14,6 +14,8 @@ CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParam { CBlockHeader block; + block.nVersion = nVersion; + /* The CBlockIndex object's block header is missing the auxpow. So if this is an auxpow block, read it from disk instead. We only have to read the actual *header*, not the full block. */ @@ -23,7 +25,6 @@ CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParam return block; } - block.nVersion = nVersion; if (pprev) block.hashPrevBlock = pprev->GetBlockHash(); block.hashMerkleRoot = hashMerkleRoot; From da77071af31761c78deeb5a96e1c9936d1b68be0 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Thu, 18 Oct 2018 20:50:16 +0000 Subject: [PATCH 07/15] Correct Dogecoin Digishield and AuxPoW switch-over * Correct block height when determining when to recalculate difficulty * Correct AuxPoW height on testnet --- src/chainparams.cpp | 2 +- src/dogecoin.cpp | 6 ------ src/pow.cpp | 4 ++-- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index eaba5a9aafc..f4e17f600f2 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -229,7 +229,7 @@ class CTestNetParams : public CChainParams { consensus.nAuxpowStartHeight = 158100; consensus.fStrictChainId = false; - consensus.nLegacyBlocksBefore = -1; + consensus.nLegacyBlocksBefore = 158100; pchMessageStart[0] = 0xfc; pchMessageStart[1] = 0xc1; diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index 396c4cbc4f1..9f5be13adc9 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -85,12 +85,6 @@ unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, in if (bnNew > bnPowLimit) bnNew = bnPowLimit; - /// debug print - LogPrintf("GetNextWorkRequired RETARGET\n"); - LogPrintf("params.nPowTargetTimespan = %d nActualTimespan = %d\n", params.nPowTargetTimespan, nActualTimespan); - LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString()); - LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString()); - return bnNew.GetCompact(); } diff --git a/src/pow.cpp b/src/pow.cpp index 09e38cef017..6774b46c27d 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -28,7 +28,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead } // Only change once per difficulty adjustment interval - bool fNewDifficultyProtocol = (pindexLast->nHeight >= 145000); + bool fNewDifficultyProtocol = (pindexLast->nHeight+1 >= 145000); const int64_t difficultyAdjustmentInterval = fNewDifficultyProtocol ? 1 : params.DifficultyAdjustmentInterval(); @@ -45,7 +45,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { // Return the last non-special-min-difficulty-rules-block const CBlockIndex* pindex = pindexLast; - while (pindex->pprev && pindex->nHeight % params.DifficultyAdjustmentInterval() != 0 && pindex->nBits == nProofOfWorkLimit) + while (pindex->pprev && pindex->nHeight % difficultyAdjustmentInterval != 0 && pindex->nBits == nProofOfWorkLimit) pindex = pindex->pprev; return pindex->nBits; } From f92b9f7073be90fb0ea7d1a9ee01e62aea47395f Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 21 Apr 2019 00:51:58 +0000 Subject: [PATCH 08/15] Add infrastructure for Dogecoin fees Add calculation logic for Dogecoin fees. This does not disable smart fees, which requires a further patch. --- src/dogecoin.cpp | 32 +++++++++++++++++++++++ src/dogecoin.h | 5 ++++ src/interfaces/wallet.cpp | 6 +++-- src/interfaces/wallet.h | 8 ++++-- src/qt/coincontroldialog.cpp | 2 +- src/qt/sendcoinsdialog.cpp | 3 ++- src/test/script_p2sh_tests.cpp | 4 +-- src/validation.cpp | 2 +- src/validation.h | 8 +++--- src/wallet/feebumper.cpp | 4 +-- src/wallet/fees.cpp | 22 +++++++++++++--- src/wallet/fees.h | 11 ++++++-- src/wallet/test/wallet_tests.cpp | 45 ++++++++++++++++++++++++++++++++ src/wallet/wallet.cpp | 6 +++-- src/wallet/wallet.h | 8 +++--- 15 files changed, 140 insertions(+), 26 deletions(-) diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index 9f5be13adc9..b12b9936f03 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -9,6 +9,7 @@ #include #include #include +#include int static generateMTRandom(unsigned int s, int range) { @@ -149,3 +150,34 @@ CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusP return 10000 * COIN; } } + +unsigned int GetDogecoinTxSize(const unsigned int nTxBytes) +{ + // Dogecoin: Round TX bytes up to the next 1,000 bytes + unsigned int nMod = nTxBytes % 1000; + if (nMod > 0) { + return nTxBytes + 1000 - nMod; + } else { + return nTxBytes; + } +} + +CAmount GetDogecoinMinRelayFee(const CTransaction& tx, unsigned int nSize) +{ + CAmount nMinFee = ::minRelayTxFee.GetFee(nSize); + nMinFee += GetDogecoinDustFee(tx.vout, ::minRelayTxFee); + if (!MoneyRange(nMinFee)) + nMinFee = MAX_MONEY; + return nMinFee; +} + +CAmount GetDogecoinDustFee(const std::vector &vout, const CFeeRate &baseFeeRate) { + CAmount nFee = 0; + + // To limit dust spam, add base fee for each output less than a COIN + for (const CTxOut& txout: vout) + if (txout.nValue < COIN) + nFee += baseFeeRate.GetFeePerK(); + + return nFee; +} diff --git a/src/dogecoin.h b/src/dogecoin.h index 403673da5e2..68e74e513ae 100644 --- a/src/dogecoin.h +++ b/src/dogecoin.h @@ -5,6 +5,7 @@ #include "amount.h" #include "chain.h" #include "chainparams.h" +#include "policy/feerate.h" bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, uint256 prevHash); @@ -17,3 +18,7 @@ unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, in * @return True iff the PoW is correct. */ bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params& params); + +unsigned int GetDogecoinTxSize(const unsigned int nTxBytes); +CAmount GetDogecoinMinRelayFee(const CTransaction& tx, unsigned int nSize); +CAmount GetDogecoinDustFee(const std::vector &vout, const CFeeRate &baseFeeRate); diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp index 55a6f771e55..d410c667c03 100644 --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -412,14 +412,16 @@ class WalletImpl : public Wallet return result; } CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(m_wallet, tx_bytes); } - CAmount getMinimumFee(unsigned int tx_bytes, + CAmount getRequiredFee(const CTransaction& tx, unsigned int tx_bytes) override { return GetRequiredFee(m_wallet, tx, tx_bytes); } + CAmount getMinimumFee(const CTransaction& tx, + unsigned int tx_bytes, const CCoinControl& coin_control, int* returned_target, FeeReason* reason) override { FeeCalculation fee_calc; CAmount result; - result = GetMinimumFee(m_wallet, tx_bytes, coin_control, ::mempool, ::feeEstimator, &fee_calc); + result = GetMinimumFee(m_wallet, tx, tx_bytes, coin_control, ::mempool, ::feeEstimator, &fee_calc); if (returned_target) *returned_target = fee_calc.returnedTarget; if (reason) *reason = fee_calc.reason; return result; diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index ae54d424426..1e85468b9e2 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -221,11 +221,15 @@ class Wallet //! Return wallet transaction output information. virtual std::vector getCoins(const std::vector& outputs) = 0; - //! Get required fee. + //! Get required fee without taking into account dust charges virtual CAmount getRequiredFee(unsigned int tx_bytes) = 0; + //! Get required fee. + virtual CAmount getRequiredFee(const CTransaction& tx, unsigned int tx_bytes) = 0; + //! Get minimum fee. - virtual CAmount getMinimumFee(unsigned int tx_bytes, + virtual CAmount getMinimumFee(const CTransaction& tx, + unsigned int tx_bytes, const CCoinControl& coin_control, int* returned_target, FeeReason* reason) = 0; diff --git a/src/qt/coincontroldialog.cpp b/src/qt/coincontroldialog.cpp index ca3598334d7..781a2282d92 100644 --- a/src/qt/coincontroldialog.cpp +++ b/src/qt/coincontroldialog.cpp @@ -499,7 +499,7 @@ void CoinControlDialog::updateLabels(WalletModel *model, QDialog* dialog) nBytes -= 34; // Fee - nPayFee = model->wallet().getMinimumFee(nBytes, *coinControl(), nullptr /* returned_target */, nullptr /* reason */); + nPayFee = model->wallet().getMinimumFee(txDummy, nBytes, *coinControl(), nullptr /* returned_target */, nullptr /* reason */); if (nPayAmount > 0) { diff --git a/src/qt/sendcoinsdialog.cpp b/src/qt/sendcoinsdialog.cpp index da155f872c4..63d26ae960f 100644 --- a/src/qt/sendcoinsdialog.cpp +++ b/src/qt/sendcoinsdialog.cpp @@ -694,7 +694,8 @@ void SendCoinsDialog::updateSmartFeeLabel() coin_control.m_feerate.reset(); // Explicitly use only fee estimation rate for smart fee labels int returned_target; FeeReason reason; - CFeeRate feeRate = CFeeRate(model->wallet().getMinimumFee(1000, coin_control, &returned_target, &reason)); + CTransaction txDummy; + CFeeRate feeRate = CFeeRate(model->wallet().getMinimumFee(txDummy, 1000, coin_control, &returned_target, &reason)); ui->labelSmartFee->setText(BitcoinUnits::formatWithUnit(model->getOptionsModel()->getDisplayUnit(), feeRate.GetFeePerK()) + "/kB"); diff --git a/src/test/script_p2sh_tests.cpp b/src/test/script_p2sh_tests.cpp index 5b10935302a..af49f8b5b3a 100644 --- a/src/test/script_p2sh_tests.cpp +++ b/src/test/script_p2sh_tests.cpp @@ -182,7 +182,7 @@ BOOST_AUTO_TEST_CASE(set) for (int i = 0; i < 4; i++) { txFrom.vout[i].scriptPubKey = outer[i]; - txFrom.vout[i].nValue = CENT; + txFrom.vout[i].nValue = COIN; } BOOST_CHECK(IsStandardTx(txFrom, reason)); @@ -193,7 +193,7 @@ BOOST_AUTO_TEST_CASE(set) txTo[i].vout.resize(1); txTo[i].vin[0].prevout.n = i; txTo[i].vin[0].prevout.hash = txFrom.GetHash(); - txTo[i].vout[0].nValue = 1*CENT; + txTo[i].vout[0].nValue = 1*COIN; txTo[i].vout[0].scriptPubKey = inner[i]; BOOST_CHECK_MESSAGE(IsMine(keystore, txFrom.vout[i].scriptPubKey), strprintf("IsMine %d", i)); } diff --git a/src/validation.cpp b/src/validation.cpp index 6a026f063b4..e8fe075d76e 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -735,7 +735,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool } // No transactions are allowed below minRelayTxFee except from disconnected blocks - if (!bypass_limits && nModifiedFees < ::minRelayTxFee.GetFee(nSize)) { + if (!bypass_limits && nModifiedFees < GetDogecoinMinRelayFee(tx, nSize)) { return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "min relay fee not met", false, strprintf("%d < %d", nModifiedFees, ::minRelayTxFee.GetFee(nSize))); } diff --git a/src/validation.h b/src/validation.h index acfbadd18c0..e36e50b1fb9 100644 --- a/src/validation.h +++ b/src/validation.h @@ -51,13 +51,13 @@ static const bool DEFAULT_WHITELISTRELAY = true; /** Default for -whitelistforcerelay. */ static const bool DEFAULT_WHITELISTFORCERELAY = true; /** Default for -minrelaytxfee, minimum relay fee for transactions */ -static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000; +static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = COIN; //! -maxtxfee default -static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.1 * COIN; +static const CAmount DEFAULT_TRANSACTION_MAXFEE = 400 * COIN; //! Discourage users to set fees higher than this amount (in satoshis) per kB -static const CAmount HIGH_TX_FEE_PER_KB = 0.01 * COIN; +static const CAmount HIGH_TX_FEE_PER_KB = 25 * COIN; //! -maxtxfee will warn if called with a higher fee than this amount (in satoshis) -static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB; +static const CAmount HIGH_MAX_TX_FEE = 10 * HIGH_TX_FEE_PER_KB; /** Default for -limitancestorcount, max number of in-mempool ancestors */ static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25; /** Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors */ diff --git a/src/wallet/feebumper.cpp b/src/wallet/feebumper.cpp index d5d40213059..52951a2e833 100644 --- a/src/wallet/feebumper.cpp +++ b/src/wallet/feebumper.cpp @@ -134,7 +134,7 @@ Result CreateTransaction(const CWallet* wallet, const uint256& txid, const CCoin FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxNewTxSize)), FormatMoney(::incrementalRelayFee.GetFee(maxNewTxSize)))); return Result::INVALID_PARAMETER; } - CAmount requiredFee = GetRequiredFee(*wallet, maxNewTxSize); + CAmount requiredFee = GetRequiredFee(*wallet, *wtx.tx, maxNewTxSize); if (total_fee < requiredFee) { errors.push_back(strprintf("Insufficient totalFee (cannot be less than required fee %s)", FormatMoney(requiredFee))); @@ -143,7 +143,7 @@ Result CreateTransaction(const CWallet* wallet, const uint256& txid, const CCoin new_fee = total_fee; nNewFeeRate = CFeeRate(total_fee, maxNewTxSize); } else { - new_fee = GetMinimumFee(*wallet, maxNewTxSize, coin_control, mempool, ::feeEstimator, nullptr /* FeeCalculation */); + new_fee = GetMinimumFee(*wallet, *wtx.tx, maxNewTxSize, coin_control, mempool, ::feeEstimator, nullptr /* FeeCalculation */); nNewFeeRate = CFeeRate(new_fee, maxNewTxSize); // New fee rate must be at least old rate + minimum incremental relay rate diff --git a/src/wallet/fees.cpp b/src/wallet/fees.cpp index d620e25f2bc..82906318956 100644 --- a/src/wallet/fees.cpp +++ b/src/wallet/fees.cpp @@ -6,22 +6,38 @@ #include #include +#include #include #include #include #include #include - CAmount GetRequiredFee(const CWallet& wallet, unsigned int nTxBytes) { + // Dogecoin: Round TX bytes up to the next 1,000 bytes + nTxBytes = GetDogecoinTxSize(nTxBytes); + + // Dogecoin: We don't take into account dust fees here, so this is only useful for estimates return GetRequiredFeeRate(wallet).GetFee(nTxBytes); } +CAmount GetRequiredFee(const CWallet& wallet, const CTransaction& tx, unsigned int nTxBytes) +{ + // Dogecoin: Round TX bytes up to the next 1,000 bytes + nTxBytes = GetDogecoinTxSize(nTxBytes); -CAmount GetMinimumFee(const CWallet& wallet, unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation* feeCalc) + // Dogecoin: Add an increased fee for each dust output + return GetRequiredFeeRate(wallet).GetFee(nTxBytes) + GetDogecoinDustFee(tx.vout, wallet.m_min_fee); +} + + +CAmount GetMinimumFee(const CWallet& wallet, const CTransaction& tx, unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation* feeCalc) { - CAmount fee_needed = GetMinimumFeeRate(wallet, coin_control, pool, estimator, feeCalc).GetFee(nTxBytes); + // Dogecoin: Round TX bytes up to the next 1,000 bytes + nTxBytes = GetDogecoinTxSize(nTxBytes); + + CAmount fee_needed = GetMinimumFeeRate(wallet, coin_control, pool, estimator, feeCalc).GetFee(nTxBytes) + GetDogecoinDustFee(tx.vout, wallet.m_min_fee); // Always obey the maximum if (fee_needed > maxTxFee) { fee_needed = maxTxFee; diff --git a/src/wallet/fees.h b/src/wallet/fees.h index 6bfee456c05..d547a866200 100644 --- a/src/wallet/fees.h +++ b/src/wallet/fees.h @@ -6,6 +6,7 @@ #ifndef BITCOIN_WALLET_FEES_H #define BITCOIN_WALLET_FEES_H +#include #include class CBlockPolicyEstimator; @@ -17,15 +18,21 @@ struct FeeCalculation; /** * Return the minimum required absolute fee for this size - * based on the required fee rate + * based on the required fee rate, without taking into account dust fees */ CAmount GetRequiredFee(const CWallet& wallet, unsigned int nTxBytes); +/** + * Return the minimum required absolute fee for this size + * based on the required fee rate + */ +CAmount GetRequiredFee(const CWallet& wallet, const CTransaction& tx, unsigned int nTxBytes); + /** * Estimate the minimum fee considering user set parameters * and the required fee */ -CAmount GetMinimumFee(const CWallet& wallet, unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation* feeCalc); +CAmount GetMinimumFee(const CWallet& wallet, const CTransaction& tx, unsigned int nTxBytes, const CCoinControl& coin_control, const CTxMemPool& pool, const CBlockPolicyEstimator& estimator, FeeCalculation* feeCalc); /** * Return the minimum required feerate taking into account the diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index fb60ccc4e65..cad415d8b42 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -421,4 +423,47 @@ BOOST_FIXTURE_TEST_CASE(dummy_input_size_test, TestChain240Setup) BOOST_CHECK_EQUAL(CalculateNestedKeyhashInputSize(true), DUMMY_NESTED_P2WPKH_INPUT_SIZE); } +BOOST_AUTO_TEST_CASE(GetMinimumFee_test) +{ + CWallet wallet("dummy", WalletDatabase::CreateDummy()); + CBlockPolicyEstimator feeEstimator; + const CCoinControl coin_control; + FeeCalculation calculation; + uint64_t value = 1000 * COIN; // 1,000 DOGE + + CMutableTransaction tx; + const CTxMemPool pool(&feeEstimator); + CTxOut txout1(value, CScript() << OP_1); + tx.vout.push_back(txout1); + + int64_t nMinTxFee = COIN; + + BOOST_CHECK_EQUAL(GetMinimumFee(wallet, tx, 250U, coin_control, pool, feeEstimator, &calculation), nMinTxFee); + BOOST_CHECK_EQUAL(GetMinimumFee(wallet, tx, 1000U, coin_control, pool, feeEstimator, &calculation), nMinTxFee); + BOOST_CHECK_EQUAL(GetMinimumFee(wallet, tx, 1999U, coin_control, pool, feeEstimator, &calculation), 2 * nMinTxFee); +} + +BOOST_AUTO_TEST_CASE(GetMinimumFee_dust_test) +{ + CWallet wallet("dummy", WalletDatabase::CreateDummy()); + // Derived from main net TX 3d6ec3ae2aca3ae0a6c65074fd8ee888cd7ed262f2cbaa25d33861989324a14e + CMutableTransaction tx; + CBlockPolicyEstimator feeEstimator; + const CCoinControl coin_control; + FeeCalculation calculation; + const CTxMemPool pool(&feeEstimator); + CTxOut txout1(139496846, CScript() << OP_1); // Regular output + CTxOut txout2(15499649, CScript() << OP_1); // Dust output + tx.vout.push_back(txout1); + tx.vout.push_back(txout2); + + int64_t nMinTxFee = COIN; + + // Confirm dust penalty fees are added on + + BOOST_CHECK_EQUAL(GetMinimumFee(wallet, tx, 963U, coin_control, pool, feeEstimator, &calculation), 2 * nMinTxFee); + BOOST_CHECK_EQUAL(GetMinimumFee(wallet, tx, 1000U, coin_control, pool, feeEstimator, &calculation), 2 * nMinTxFee); + BOOST_CHECK_EQUAL(GetMinimumFee(wallet, tx, 1999U, coin_control, pool, feeEstimator, &calculation), 3 * nMinTxFee); +} + BOOST_AUTO_TEST_SUITE_END() diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 060325921f5..cc7c8dc9f02 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2901,13 +2901,15 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CTransac return false; } - nFeeNeeded = GetMinimumFee(*this, nBytes, coin_control, ::mempool, ::feeEstimator, &feeCalc); + nFeeNeeded = GetMinimumFee(*this, txNew, nBytes, coin_control, ::mempool, ::feeEstimator, &feeCalc); if (feeCalc.reason == FeeReason::FALLBACK && !m_allow_fallback_fee) { // eventually allow a fallback fee strFailReason = _("Fee estimation failed. Fallbackfee is disabled. Wait a few blocks or enable -fallbackfee."); return false; } + nFeeNeeded = GetMinimumFee(*this, txNew, nBytes, coin_control, ::mempool, ::feeEstimator, &feeCalc); + // If we made it here and we aren't even able to meet the relay fee on the next pass, give up // because we must be at the maximum allowed fee. if (nFeeNeeded < ::minRelayTxFee.GetFee(nBytes)) @@ -2929,7 +2931,7 @@ bool CWallet::CreateTransaction(const std::vector& vecSend, CTransac // change output. Only try this once. if (nChangePosInOut == -1 && nSubtractFeeFromAmount == 0 && pick_new_inputs) { unsigned int tx_size_with_change = nBytes + coin_selection_params.change_output_size + 2; // Add 2 as a buffer in case increasing # of outputs changes compact size - CAmount fee_needed_with_change = GetMinimumFee(*this, tx_size_with_change, coin_control, ::mempool, ::feeEstimator, nullptr); + CAmount fee_needed_with_change = GetMinimumFee(*this, txNew, tx_size_with_change, coin_control, ::mempool, ::feeEstimator, nullptr); CAmount minimum_value_for_change = GetDustThreshold(change_prototype_txout, discard_rate); if (nFeeRet >= fee_needed_with_change + minimum_value_for_change) { pick_new_inputs = false; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index ae5de3e85d2..edeaaa28d3b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -45,13 +45,13 @@ static const unsigned int DEFAULT_KEYPOOL_SIZE = 1000; //! -paytxfee default constexpr CAmount DEFAULT_PAY_TX_FEE = 0; //! -fallbackfee default -static const CAmount DEFAULT_FALLBACK_FEE = 20000; +static const CAmount DEFAULT_FALLBACK_FEE = COIN; //! -discardfee default -static const CAmount DEFAULT_DISCARD_FEE = 10000; +static const CAmount DEFAULT_DISCARD_FEE = COIN / 2; //! -mintxfee default -static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000; +static const CAmount DEFAULT_TRANSACTION_MINFEE = COIN; //! minimum recommended increment for BIP 125 replacement txs -static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000; +static const CAmount WALLET_INCREMENTAL_RELAY_FEE = COIN * 5; //! Default for -spendzeroconfchange static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true; //! Default for -walletrejectlongchains From 09af29bf19c72de26454af4fe86bcb1fb7cb305f Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 21 Apr 2019 03:39:54 +0000 Subject: [PATCH 09/15] Replace hardcoded heights with chain parameters This patch replaces height-aware consensus. * Correct implementation of simplified rewards in parameters * Use base block version in IsSuperMajority() instead of full version * Correct mining of blocks in AuxPoW tests * Add in missing pre-AuxPoW consensus checks --- src/chainparams.cpp | 13 +++++++++++++ src/consensus/params.h | 5 +++++ src/dogecoin.cpp | 8 +++----- src/pow.cpp | 16 ++++++++++++++++ src/test/auxpow_tests.cpp | 8 ++++---- src/test/blockencodings_tests.cpp | 4 ++++ src/test/dogecoin_tests.cpp | 2 +- 7 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index f4e17f600f2..b983aa380ab 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -109,6 +109,10 @@ class CMainParams : public CChainParams { // By default assume that the signatures in ancestors of this block are valid. consensus.defaultAssumeValid = uint256S("0x0000000000000000002e63058c023a9a1de233554f28c7b21380b6c9003f36a8"); //534292 + consensus.nDigiShieldStartHeight = 145000; + consensus.nDigishieldMinDifficultyHeight = 0; + consensus.nDigiShieldTargetTimespan = 60; + consensus.nAuxpowChainId = 0x0062; // 98 - Josh Wise! consensus.nAuxpowStartHeight = 371337; consensus.fStrictChainId = true; @@ -227,6 +231,10 @@ class CTestNetParams : public CChainParams { // By default assume that the signatures in ancestors of this block are valid. consensus.defaultAssumeValid = uint256S("0x0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75"); //1354312 + consensus.nDigiShieldStartHeight = 145000; + consensus.nDigishieldMinDifficultyHeight = 157500; // Testnet enables target reset at block 157500 + consensus.nDigiShieldTargetTimespan = 60; + consensus.nAuxpowStartHeight = 158100; consensus.fStrictChainId = false; consensus.nLegacyBlocksBefore = 158100; @@ -321,8 +329,13 @@ class CRegTestParams : public CChainParams { // By default assume that the signatures in ancestors of this block are valid. consensus.defaultAssumeValid = uint256S("0x00"); + consensus.nDigiShieldStartHeight = 145000; + consensus.nDigishieldMinDifficultyHeight = 0; + consensus.nDigiShieldTargetTimespan = 60; + consensus.fStrictChainId = true; consensus.nLegacyBlocksBefore = 0; + pchMessageStart[0] = 0xfa; pchMessageStart[1] = 0xbf; pchMessageStart[2] = 0xb5; diff --git a/src/consensus/params.h b/src/consensus/params.h index ff90b13043f..25f7187b2b5 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -76,6 +76,11 @@ struct Params { uint256 nMinimumChainWork; uint256 defaultAssumeValid; + /** DigiShield parameters */ + int nDigiShieldStartHeight; + int nDigishieldMinDifficultyHeight; + int64_t nDigiShieldTargetTimespan; + /** Auxpow parameters */ int32_t nAuxpowChainId; int nAuxpowStartHeight; diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index b12b9936f03..8b09ab5dba5 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -28,8 +28,7 @@ bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const C return false; // check if the chain allows minimum difficulty blocks on recalc blocks - if (pindexLast->nHeight < 157500) - // if (!params.fPowAllowDigishieldMinDifficultyBlocks) + if (pindexLast->nHeight < params.nDigishieldMinDifficultyHeight) return false; // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing @@ -39,9 +38,8 @@ bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const C unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params) { int nHeight = pindexLast->nHeight + 1; - bool fNewDifficultyProtocol = (nHeight >= 145000); - // bool fNewDifficultyProtocol = (nHeight >= params.GetDigiShieldForkBlock()); - const int64_t retargetTimespan = fNewDifficultyProtocol ? 60 // params.DigiShieldTargetTimespan() + bool fNewDifficultyProtocol = (nHeight >= params.nDigiShieldStartHeight); + const int64_t retargetTimespan = fNewDifficultyProtocol ? params.nDigiShieldTargetTimespan : params.nPowTargetTimespan; diff --git a/src/pow.cpp b/src/pow.cpp index 6774b46c27d..f7c8e38bde6 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -13,6 +13,22 @@ #include #include +// Determine if the for the given block, a min difficulty setting applies +bool AllowMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) +{ + // check if the chain allows minimum difficulty blocks + if (!params.fPowAllowMinDifficultyBlocks) + return false; + + // Dogecoin: Magic number at which reset protocol switches + // check if we allow minimum difficulty at this block-height + if (pindexLast->nHeight < 157500) + return false; + + // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing + return (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2); +} + unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { assert(pindexLast != nullptr); diff --git a/src/test/auxpow_tests.cpp b/src/test/auxpow_tests.cpp index 6447ef9fdfc..a587bff15c8 100644 --- a/src/test/auxpow_tests.cpp +++ b/src/test/auxpow_tests.cpp @@ -383,9 +383,9 @@ mineBlock(CBlockHeader& block, bool ok, int nBits = -1) target.SetCompact(nBits); block.nNonce = 0; - while (true) + while (true) { - const bool nowOk = (UintToArith256(block.GetHash()) <= target); + const bool nowOk = (UintToArith256(block.GetPoWHash()) <= target); if ((ok && nowOk) || (!ok && !nowOk)) break; @@ -393,9 +393,9 @@ mineBlock(CBlockHeader& block, bool ok, int nBits = -1) } if (ok) - BOOST_CHECK(CheckProofOfWork(block.GetHash(), nBits, Params().GetConsensus())); + BOOST_CHECK(CheckProofOfWork(block.GetPoWHash(), nBits, Params().GetConsensus())); else - BOOST_CHECK(!CheckProofOfWork(block.GetHash(), nBits, Params().GetConsensus())); + BOOST_CHECK(!CheckProofOfWork(block.GetPoWHash(), nBits, Params().GetConsensus())); } BOOST_FIXTURE_TEST_CASE (auxpow_pow, BasicTestingSetup) diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp index c9aa54a3505..e5e9b0ac69f 100644 --- a/src/test/blockencodings_tests.cpp +++ b/src/test/blockencodings_tests.cpp @@ -104,6 +104,7 @@ BOOST_AUTO_TEST_CASE(SimpleRoundTripTest) BOOST_CHECK(block.hashMerkleRoot != BlockMerkleRoot(block2, &mutated)); CBlock block3; + // FIXME: Somehow this seems to be broken by adding chain ID to RegTest BOOST_CHECK(partialBlock.FillBlock(block3, {block.vtx[1]}) == READ_STATUS_OK); BOOST_CHECK_EQUAL(block.GetHash().ToString(), block3.GetHash().ToString()); BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block3, &mutated).ToString()); @@ -209,6 +210,7 @@ BOOST_AUTO_TEST_CASE(NonCoinbasePreforwardRTTest) CBlock block3; PartiallyDownloadedBlock partialBlockCopy = partialBlock; + // FIXME: Somehow this seems to be broken by adding chain ID to RegTest BOOST_CHECK(partialBlock.FillBlock(block3, {block.vtx[0]}) == READ_STATUS_OK); BOOST_CHECK_EQUAL(block.GetHash().ToString(), block3.GetHash().ToString()); BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block3, &mutated).ToString()); @@ -262,6 +264,7 @@ BOOST_AUTO_TEST_CASE(SufficientPreforwardRTTest) CBlock block2; PartiallyDownloadedBlock partialBlockCopy = partialBlock; + // FIXME: Somehow this seems to be broken by adding chain ID to RegTest BOOST_CHECK(partialBlock.FillBlock(block2, {}) == READ_STATUS_OK); BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString()); bool mutated; @@ -313,6 +316,7 @@ BOOST_AUTO_TEST_CASE(EmptyBlockRoundTripTest) CBlock block2; std::vector vtx_missing; + // FIXME: Somehow this seems to be broken by adding chain ID to RegTest BOOST_CHECK(partialBlock.FillBlock(block2, vtx_missing) == READ_STATUS_OK); BOOST_CHECK_EQUAL(block.GetHash().ToString(), block2.GetHash().ToString()); BOOST_CHECK_EQUAL(block.hashMerkleRoot.ToString(), BlockMerkleRoot(block2, &mutated).ToString()); diff --git a/src/test/dogecoin_tests.cpp b/src/test/dogecoin_tests.cpp index b5d7716d5ba..0097f53a136 100644 --- a/src/test/dogecoin_tests.cpp +++ b/src/test/dogecoin_tests.cpp @@ -95,7 +95,7 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) BOOST_CHECK(nSum >= lowerlimit); // Test reward at 600k+ is constant - CAmount nConstantSubsidy = GetDogecoinBlockSubsidy(600000, params, prevHash); + CAmount nConstantSubsidy = GetDogecoinBlockSubsidy(nHeight, params, prevHash); BOOST_CHECK_EQUAL(nConstantSubsidy, 10000 * COIN); nConstantSubsidy = GetDogecoinBlockSubsidy(700000, params, prevHash); From 664016eaaeed7c0c88a15c388daf9052e6d2fdfd Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Sun, 21 Apr 2019 05:22:11 +0000 Subject: [PATCH 10/15] Update checkpoints and chain work * Update checkpoints and chain work * Correct timestamp of last checkpoint block --- src/chainparams.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index b983aa380ab..17fbb7c3a5a 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -174,13 +174,14 @@ class CMainParams : public CChainParams { {1750000, uint256S("5c8e7327984f0d6f59447d89d143e5f6eafc524c82ad95d176c5cec082ae2001")}, {2000000, uint256S("9914f0e82e39bbf21950792e8816620d71b9965bdbbc14e72a95e3ab9618fea8")}, {2031142, uint256S("893297d89afb7599a3c571ca31a3b80e8353f4cf39872400ad0f57d26c4c5d42")}, + {2691755, uint256S("658a69f81e264291b5d58cb4c51a5aa1778d3d3d52359e53c48a0ea0820aa5de")}, } }; chainTxData = ChainTxData{ // Data from rpc: getchaintxstats 4096 0000000000000000002e63058c023a9a1de233554f28c7b21380b6c9003f36a8 - /* nTime */ 1514549787, - /* nTxCount */ 32796624, + /* nTime */ 1555823202, + /* nTxCount */ 46882258, /* dTxRate */ 0.04 }; @@ -278,14 +279,17 @@ class CTestNetParams : public CChainParams { {591117, uint256S("5f6b93b2c28cedf32467d900369b8be6700f0649388a7dbfd3ebd4a01b1ffad8")}, {658924, uint256S("ed6c8324d9a77195ee080f225a0fca6346495e08ded99bcda47a8eea5a8a620b")}, {703635, uint256S("839fa54617adcd582d53030a37455c14a87a806f6615aa8213f13e196230ff7f")}, + {1000000, uint256S("1fe4d44ea4d1edb031f52f0d7c635db8190dc871a190654c41d2450086b8ef0e")}, + {1202214, uint256S("a2179767a87ee4e95944703976fee63578ec04fa3ac2fc1c9c2c83587d096977")}, + {1855459, uint256S("8f66489d4531ee118ee7e6d28750d5e136301836b32ed4d7854e0fa71f8b57f9")}, } }; chainTxData = ChainTxData{ - // Data from rpc: getchaintxstats 4096 0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75 - /* nTime */ 1440601451, - /* nTxCount */ 1119061, - /* dTxRate */ 0.01 + // Data from rpc: getchaintxstats 4096 8f66489d4531ee118ee7e6d28750d5e136301836b32ed4d7854e0fa71f8b57f9 + /* nTime */ 1550901172, + /* nTxCount */ 2860626, + /* dTxRate */ 0.025 }; /* enable fallback fee on testnet */ From 4ec01156a972ea9b583e033b41bc6cb712b97f23 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 1 Jan 2018 16:24:14 +0000 Subject: [PATCH 11/15] Change count type used by `gettxoutsetinfo` (#1415) changing CAmount (is a int64_t) to arith_uint256 for nTotalAmount in CCoinsStats to prevent overflow --- src/core_io.h | 2 ++ src/core_write.cpp | 11 +++++++++++ src/rpc/blockchain.cpp | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core_io.h b/src/core_io.h index ee323a22eed..494ff12e324 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -8,6 +8,7 @@ #include #include +#include #include class CBlock; @@ -30,6 +31,7 @@ int ParseSighashString(const UniValue& sighash); // core_write.cpp UniValue ValueFromAmount(const CAmount& amount); +UniValue ValueFromAmount(const arith_uint256& amount); std::string FormatScript(const CScript& script); std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0); std::string SighashToStr(unsigned char sighash_type); diff --git a/src/core_write.cpp b/src/core_write.cpp index 6331a3d880d..32dc99f0eac 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include