Don't assume mainchain is Bitcoin

This commit is contained in:
Steven Roose 2019-03-21 12:39:57 +00:00
parent cf77a238de
commit ade539cbb4
5 changed files with 19 additions and 19 deletions

View file

@ -529,12 +529,12 @@ void SetupServerArgs()
std::vector<std::string> 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"}; std::vector<std::string> 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("-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", "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("-validatepegin", "Validate peg-in claims. An RPC connection will be attempted to the trusted mainchain daemon using the `mainchain*` settings below. All functionaries must run this enabled. (default: true if chain has federated peg)", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-mainchainrpchost=<host>", "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("-mainchainrpchost=<host>", "The address which the daemon will try to connect to the trusted mainchain daemon to validate peg-ins, if enabled. (default: 127.0.0.1)", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-mainchainrpcport=<n>", 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("-mainchainrpcport=<n>", strprintf("The port which the daemon will try to connect to the trusted mainchain daemon to validate peg-ins, if enabled. (default: %u)", defaultBaseParams->MainchainRPCPort()), false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-mainchainrpcuser=<user>", "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); gArgs.AddArg("-mainchainrpcuser=<user>", "The rpc username that the daemon will use to connect to the trusted mainchain daemon to validate peg-ins, if enabled. (default: cookie auth)", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-mainchainrpcpassword=<pwd>", "The rpc password which the daemon will use to connect to the trusted bitcoind to validate peg-ins, if enabled. (default: cookie auth)", false, OptionsCategory::ELEMENTS); gArgs.AddArg("-mainchainrpcpassword=<pwd>", "The rpc password which the daemon will use to connect to the trusted mainchain daemon to validate peg-ins, if enabled. (default: cookie auth)", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-mainchainrpccookiefile=<file>", "The bitcoind cookie auth path which the daemon will use to connect to the trusted bitcoind to validate peg-ins. (default: `<datadir>/regtest/.cookie`)", false, OptionsCategory::ELEMENTS); gArgs.AddArg("-mainchainrpccookiefile=<file>", "The bitcoind cookie auth path which the daemon will use to connect to the trusted mainchain daemon to validate peg-ins. (default: `<datadir>/regtest/.cookie`)", false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-mainchainrpctimeout=<n>", strprintf("Timeout in seconds during mainchain RPC requests, or 0 for no timeout. (default: %d)", DEFAULT_HTTP_CLIENT_TIMEOUT), false, OptionsCategory::ELEMENTS); gArgs.AddArg("-mainchainrpctimeout=<n>", strprintf("Timeout in seconds during mainchain RPC requests, or 0 for no timeout. (default: %d)", DEFAULT_HTTP_CLIENT_TIMEOUT), false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-peginconfirmationdepth=<n>", strprintf("Pegin claims must be this deep to be considered valid. (default: %d)", DEFAULT_PEGIN_CONFIRMATION_DEPTH), false, OptionsCategory::ELEMENTS); gArgs.AddArg("-peginconfirmationdepth=<n>", strprintf("Pegin claims must be this deep to be considered valid. (default: %d)", DEFAULT_PEGIN_CONFIRMATION_DEPTH), false, OptionsCategory::ELEMENTS);
gArgs.AddArg("-recheckpeginblockinterval=<n>", strprintf("The interval in seconds at which a peg-in witness failing block is re-evaluated in case of intermittent peg-in witness failure. 0 means never. (default: %u)", 120), false, OptionsCategory::ELEMENTS); gArgs.AddArg("-recheckpeginblockinterval=<n>", strprintf("The interval in seconds at which a peg-in witness failing block is re-evaluated in case of intermittent peg-in witness failure. 0 means never. (default: %u)", 120), false, OptionsCategory::ELEMENTS);
@ -1866,14 +1866,14 @@ bool AppInitMain()
SetRPCWarmupFinished(); SetRPCWarmupFinished();
// ELEMENTS: // ELEMENTS:
CScheduler::Function f2 = boost::bind(&BitcoindRPCCheck, false); CScheduler::Function f2 = boost::bind(&MainchainRPCCheck, false);
unsigned int check_rpc_every = gArgs.GetArg("-recheckpeginblockinterval", 120); unsigned int check_rpc_every = gArgs.GetArg("-recheckpeginblockinterval", 120);
if (check_rpc_every) { if (check_rpc_every) {
scheduler.scheduleEvery(f2, check_rpc_every); scheduler.scheduleEvery(f2, check_rpc_every);
} }
uiInterface.InitMessage(_("Awaiting bitcoind RPC warmup")); uiInterface.InitMessage(_("Awaiting mainchain RPC warmup"));
if (!BitcoindRPCCheck(true)) { //Initial check, fail immediately if (!MainchainRPCCheck(true)) { //Initial check, fail immediately
return InitError(_("ERROR: elementsd is set to verify pegins but cannot get valid response from bitcoind. Please check debug.log for more information.")); return InitError(_("ERROR: elementsd is set to verify pegins but cannot get valid response from the mainchain daemon. Please check debug.log for more information."));
} }
uiInterface.InitMessage(_("Done loading")); uiInterface.InitMessage(_("Done loading"));

View file

@ -177,10 +177,10 @@ bool IsConfirmedBitcoinBlock(const uint256& hash, const int nMinConfirmationDept
} }
} }
} catch (CConnectionFailed& e) { } catch (CConnectionFailed& e) {
LogPrintf("ERROR: Lost connection to bitcoind RPC, you will want to restart after fixing this!\n"); LogPrintf("ERROR: Lost connection to mainchain daemon RPC, you will want to restart after fixing this!\n");
return false; return false;
} catch (...) { } catch (...) {
LogPrintf("ERROR: Failure connecting to bitcoind RPC, you will want to restart after fixing this!\n"); LogPrintf("ERROR: Failure connecting to mainchain daemon RPC, you will want to restart after fixing this!\n");
return false; return false;
} }
return true; return true;

View file

@ -5107,7 +5107,7 @@ public:
* from the perspective of peg-in witness validation. Blocks are * from the perspective of peg-in witness validation. Blocks are
* added to this queue in ConnectTip based on the error code returned. * added to this queue in ConnectTip based on the error code returned.
*/ */
bool BitcoindRPCCheck(const bool init) bool MainchainRPCCheck(const bool init)
{ {
// First, we can clear out any blocks thatsomehow are now deemed valid // First, we can clear out any blocks thatsomehow are now deemed valid
// eg reconsiderblock rpc call manually // eg reconsiderblock rpc call manually
@ -5144,7 +5144,7 @@ bool BitcoindRPCCheck(const bool init)
continue; continue;
} }
else { else {
LogPrintf("ERROR: Bitcoind RPC check returned 'error' response.\n"); LogPrintf("ERROR: Mainchain daemon RPC check returned 'error' response.\n");
return false; return false;
} }
} }
@ -5160,7 +5160,7 @@ bool BitcoindRPCCheck(const bool init)
reply = CallMainChainRPC("getblockhash", params); reply = CallMainChainRPC("getblockhash", params);
error = reply["error"]; error = reply["error"];
if (!error.isNull()) { if (!error.isNull()) {
LogPrintf("ERROR: Bitcoind RPC check returned 'error' response.\n"); LogPrintf("ERROR: Mainchain daemon RPC check returned 'error' response.\n");
return false; return false;
} }
result = reply["result"]; result = reply["result"];
@ -5169,7 +5169,7 @@ bool BitcoindRPCCheck(const bool init)
return false; return false;
} }
} catch (const std::runtime_error& re) { } catch (const std::runtime_error& re) {
LogPrintf("ERROR: Failure connecting to bitcoind RPC: %s\n", std::string(re.what())); LogPrintf("ERROR: Failure connecting to mainchain daemon RPC: %s\n", std::string(re.what()));
return false; return false;
} }
// Success // Success

View file

@ -506,6 +506,6 @@ inline bool IsBlockPruned(const CBlockIndex* pblockindex)
// ELEMENTS: // ELEMENTS:
/** Check if bitcoind connection via RPC is correctly working*/ /** Check if bitcoind connection via RPC is correctly working*/
bool BitcoindRPCCheck(bool init); bool MainchainRPCCheck(bool init);
#endif // BITCOIN_VALIDATION_H #endif // BITCOIN_VALIDATION_H

View file

@ -5065,7 +5065,7 @@ static UniValue createrawpegin(const JSONRPCRequest& request, T_tx_ref& txBTCRef
"If a transaction is not relayed it may require manual addition to a functionary mempool in order for it to be mined.\n" "If a transaction is not relayed it may require manual addition to a functionary mempool in order for it to be mined.\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"bitcoinTx\" (string, required) The raw bitcoin transaction (in hex) depositing bitcoin to the mainchain_address generated by getpeginaddress\n" "1. \"bitcoinTx\" (string, required) The raw bitcoin transaction (in hex) depositing bitcoin to the mainchain_address generated by getpeginaddress\n"
"2. \"txoutproof\" (string, required) A rawtxoutproof (in hex) generated by bitcoind's `gettxoutproof` containing a proof of only bitcoinTx\n" "2. \"txoutproof\" (string, required) A rawtxoutproof (in hex) generated by the mainchain daemon's `gettxoutproof` containing a proof of only bitcoinTx\n"
"3. \"claim_script\" (string, optional) The witness program generated by getpeginaddress. Only needed if not in wallet.\n" "3. \"claim_script\" (string, optional) The witness program generated by getpeginaddress. Only needed if not in wallet.\n"
"\nResult:\n" "\nResult:\n"
"{\n" "{\n"
@ -5280,7 +5280,7 @@ UniValue claimpegin(const JSONRPCRequest& request)
"If a transaction is not relayed it may require manual addition to a functionary mempool in order for it to be mined.\n" "If a transaction is not relayed it may require manual addition to a functionary mempool in order for it to be mined.\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"bitcoinTx\" (string, required) The raw bitcoin transaction (in hex) depositing bitcoin to the mainchain_address generated by getpeginaddress\n" "1. \"bitcoinTx\" (string, required) The raw bitcoin transaction (in hex) depositing bitcoin to the mainchain_address generated by getpeginaddress\n"
"2. \"txoutproof\" (string, required) A rawtxoutproof (in hex) generated by bitcoind's `gettxoutproof` containing a proof of only bitcoinTx\n" "2. \"txoutproof\" (string, required) A rawtxoutproof (in hex) generated by the mainchain daemon's `gettxoutproof` containing a proof of only bitcoinTx\n"
"3. \"claim_script\" (string, optional) The witness program generated by getpeginaddress. Only needed if not in wallet.\n" "3. \"claim_script\" (string, optional) The witness program generated by getpeginaddress. Only needed if not in wallet.\n"
"\nResult:\n" "\nResult:\n"
"\"txid\" (string) Txid of the resulting sidechain transaction\n" "\"txid\" (string) Txid of the resulting sidechain transaction\n"