From aba54b3f9280447cf765420970abd5225fe76fe9 Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Thu, 21 Mar 2019 14:39:45 +0000 Subject: [PATCH] Make validatepegin default to true if has parent chain --- src/init.cpp | 2 +- src/pegins.cpp | 2 +- src/script/script.h | 2 -- src/test/test_bitcoin.cpp | 1 + src/validation.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- test/bitcoin_functional/functional/test_framework/util.py | 2 ++ test/functional/test_framework/util.py | 1 + 8 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 1578271710..b2dd803832 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -529,7 +529,7 @@ void SetupServerArgs() std::vector elements_hidden_args = {"-con_fpowallowmindifficultyblocks", "-con_fpownoretargeting", "-con_nsubsidyhalvinginterval", "-con_bip16exception", "-con_bip34height", "-con_bip65height", "-con_bip66height", "-con_npowtargettimespan", "-con_npowtargetspacing", "-con_nrulechangeactivationthreshold", "-con_nminerconfirmationwindow", "-con_powlimit", "-con_bip34hash", "-con_nminimumchainwork", "-con_defaultassumevalid", "-npruneafterheight", "-fdefaultconsistencychecks", "-fmineblocksondemand", "-fallback_fee_enabled", "-pchmessagestart"}; gArgs.AddArg("-initialfreecoins", strprintf("The amount of OP_TRUE coins created in the genesis block. Primarily for testing. (default: %d)", 0), true, OptionsCategory::DEBUG_TEST); - gArgs.AddArg("-validatepegin", strprintf("Validate peg-in claims. An RPC connection will be attempted to the trusted bitcoind using the `mainchain*` settings below. All functionaries must run this enabled. (default: %u)", DEFAULT_VALIDATE_PEGIN), false, OptionsCategory::ELEMENTS); + gArgs.AddArg("-validatepegin", "Validate peg-in claims. An RPC connection will be attempted to the trusted bitcoind using the `mainchain*` settings below. All functionaries must run this enabled. (default: true if chain has federated peg)", false, OptionsCategory::ELEMENTS); gArgs.AddArg("-mainchainrpchost=", "The address which the daemon will try to connect to the trusted bitcoind to validate peg-ins, if enabled. (default: 127.0.0.1)", false, OptionsCategory::ELEMENTS); gArgs.AddArg("-mainchainrpcport=", strprintf("The port which the daemon will try to connect to the trusted bitcoind to validate peg-ins, if enabled. (default: %u)", defaultBaseParams->MainchainRPCPort()), false, OptionsCategory::ELEMENTS); gArgs.AddArg("-mainchainrpcuser=", "The rpc username that the daemon will use to connect to the trusted bitcoind to validate peg-ins, if enabled. (default: cookie auth)", false, OptionsCategory::ELEMENTS); diff --git a/src/pegins.cpp b/src/pegins.cpp index 7ac516f596..19ef359e1f 100644 --- a/src/pegins.cpp +++ b/src/pegins.cpp @@ -353,7 +353,7 @@ bool IsValidPeginWitness(const CScriptWitness& pegin_witness, const COutPoint& p } // Finally, validate peg-in via rpc call - if (check_depth && gArgs.GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN)) { + if (check_depth && gArgs.GetBoolArg("-validatepegin", Params().GetConsensus().has_parent_chain)) { if (!IsConfirmedBitcoinBlock(block_hash, Params().GetConsensus().pegin_min_depth, num_txs)) { err_msg = "Needs more confirmations."; return false; diff --git a/src/script/script.h b/src/script/script.h index c6abd04e4c..215223d606 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -43,8 +43,6 @@ static const int MAX_STACK_SIZE = 1000; static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC // ELEMENTS: -// Validate pegin proof by checking Bitcoin transaction inclusion in mainchain. -static const bool DEFAULT_VALIDATE_PEGIN = false; // Number of confirms on parent chain required to confirm on sidechain. static const unsigned int DEFAULT_PEGIN_CONFIRMATION_DEPTH = 8; diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 101f086eaa..e9d5aee7e6 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -67,6 +67,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::st if (!fedpegscript.empty()) { gArgs.SoftSetArg("-fedpegscript", fedpegscript); gArgs.SoftSetBoolArg("-con_has_parent_chain", true); + gArgs.SoftSetBoolArg("-validatepegin", false); } // CreateAndProcessBlock() does not support building SegWit blocks, so don't activate in these tests. // TODO: fix the code to support SegWit blocks. diff --git a/src/validation.cpp b/src/validation.cpp index 2e54069292..05ee3d65c4 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -5128,7 +5128,7 @@ bool BitcoindRPCCheck(const bool init) pblocktree->WriteInvalidBlockQueue(vblocksToReconsider); // Next, check for working and valid rpc - if (gArgs.GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN)) { + if (gArgs.GetBoolArg("-validatepegin", Params().GetConsensus().has_parent_chain)) { // During init try until a non-RPC_IN_WARMUP result while (true) { try { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e2f8afe7f1..989a967dd9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5239,7 +5239,7 @@ static UniValue createrawpegin(const JSONRPCRequest& request, T_tx_ref& txBTCRef ret.pushKV("hex", strHex); // Additional block lee-way to avoid bitcoin block races - if (gArgs.GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN)) { + if (gArgs.GetBoolArg("-validatepegin", Params().GetConsensus().has_parent_chain)) { ret.pushKV("mature", IsConfirmedBitcoinBlock(merkleBlock.header.GetHash(), Params().GetConsensus().pegin_min_depth+2, merkleBlock.txn.GetNumTransactions())); } diff --git a/test/bitcoin_functional/functional/test_framework/util.py b/test/bitcoin_functional/functional/test_framework/util.py index 5c279c3ff1..e6351897fd 100644 --- a/test/bitcoin_functional/functional/test_framework/util.py +++ b/test/bitcoin_functional/functional/test_framework/util.py @@ -305,6 +305,8 @@ def initialize_datadir(dirname, n, chain): # Elements: f.write("con_blocksubsidy=5000000000\n") f.write("con_connect_coinbase=0\n") + f.write("con_has_parent_chain=0\n") + f.write("parentgenesisblockhash=0\n") f.write("anyonecanspendaremine=0\n") f.write("con_blockheightinheader=0\n") f.write("con_elementsmode=0\n") diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index ce9fdf03ef..99f60909ef 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -319,6 +319,7 @@ def initialize_datadir(dirname, n, chain): f.write("listenonion=0\n") f.write("printtoconsole=0\n") # Elements: + f.write("validatepegin=0\n") f.write("con_parent_pegged_asset=" + BITCOIN_ASSET + "\n") f.write("con_blocksubsidy=5000000000\n") f.write("con_connect_coinbase=0\n")