Add support for signed-blocks parent chains

This commit is contained in:
Steven Roose 2018-12-20 12:32:29 +01:00
parent b56f7da6d6
commit d8885400fb
8 changed files with 37 additions and 28 deletions

View file

@ -56,6 +56,11 @@ bool CheckProof(const CBlockHeader& block, const Consensus::Params& params)
} }
} }
bool CheckProofSignedParent(const CBlockHeader& block, const Consensus::Params& params)
{
return CheckProofGeneric(block, params, params.parent_chain_signblockscript);
}
void ResetProof(CBlockHeader& block) void ResetProof(CBlockHeader& block)
{ {
block.proof.solution.clear(); block.proof.solution.clear();

View file

@ -19,6 +19,7 @@ class CScript;
/** Check on header proof, depending on chain type, PoW or signed **/ /** Check on header proof, depending on chain type, PoW or signed **/
bool CheckProof(const CBlockHeader& block, const Consensus::Params&); bool CheckProof(const CBlockHeader& block, const Consensus::Params&);
bool CheckProofSignedParent(const CBlockHeader& block, const Consensus::Params&);
void ResetProof(CBlockHeader& block); void ResetProof(CBlockHeader& block);
bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&); bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&);
void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&); void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&);

View file

@ -547,6 +547,7 @@ class CCustomParams : public CRegTestParams {
const bool parent_genesis_is_null = parentGenesisBlockHash == uint256(); const bool parent_genesis_is_null = parentGenesisBlockHash == uint256();
assert(consensus.has_parent_chain != parent_genesis_is_null); assert(consensus.has_parent_chain != parent_genesis_is_null);
consensus.parentChainPowLimit = uint256S(args.GetArg("-con_parentpowlimit", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); consensus.parentChainPowLimit = uint256S(args.GetArg("-con_parentpowlimit", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
consensus.parent_chain_signblockscript = StrHexToScriptWithDefault(args.GetArg("-con_parent_chain_signblockscript", ""), CScript());
consensus.pegin_min_depth = args.GetArg("-peginconfirmationdepth", DEFAULT_PEGIN_CONFIRMATION_DEPTH); consensus.pegin_min_depth = args.GetArg("-peginconfirmationdepth", DEFAULT_PEGIN_CONFIRMATION_DEPTH);
const CScript default_script(CScript() << OP_TRUE); const CScript default_script(CScript() << OP_TRUE);

View file

@ -35,6 +35,7 @@ void SetupChainParamsBaseOptions()
gArgs.AddArg("-con_has_parent_chain", "Whether or not there is a parent chain.", false, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-con_has_parent_chain", "Whether or not there is a parent chain.", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-parentgenesisblockhash", "The genesis blockhash of the parent chain.", false, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-parentgenesisblockhash", "The genesis blockhash of the parent chain.", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-con_parentpowlimit", "The proof-of-work limit value for the parent chain.", false, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-con_parentpowlimit", "The proof-of-work limit value for the parent chain.", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-con_parent_chain_signblockscript", "Whether parent chain uses pow or signed blocks. If the parent chain uses signed blocks, the challenge (scriptPubKey) script. If not, an empty string. (default: empty script [ie parent uses pow])", false, OptionsCategory::CHAINPARAMS);
gArgs.AddArg("-fedpegscript", "The script for the federated peg.", false, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-fedpegscript", "The script for the federated peg.", false, OptionsCategory::CHAINPARAMS);
} }

View file

@ -87,7 +87,7 @@ struct Params {
bool has_parent_chain; bool has_parent_chain;
uint256 parentChainPowLimit; uint256 parentChainPowLimit;
uint32_t pegin_min_depth; uint32_t pegin_min_depth;
CScript parent_chain_signblockscript; //TODO(rebase) change when implementing parents with signed blocks CScript parent_chain_signblockscript;
bool ParentChainHasPow() const { return parent_chain_signblockscript == CScript();} bool ParentChainHasPow() const { return parent_chain_signblockscript == CScript();}
CScript fedpegScript; CScript fedpegScript;
// g_con_blockheightinheader global hack instead of proper arg due to circular dep // g_con_blockheightinheader global hack instead of proper arg due to circular dep

View file

@ -11,6 +11,7 @@
#include <consensus/consensus.h> #include <consensus/consensus.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <mainchainrpc.h> #include <mainchainrpc.h>
#include <merkleblock.h>
#include <pow.h> #include <pow.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <primitives/bitcoin/merkleblock.h> #include <primitives/bitcoin/merkleblock.h>
@ -299,22 +300,21 @@ bool IsValidPeginWitness(const CScriptWitness& pegin_witness, const COutPoint& p
num_txs = merkle_block_pow.txn.GetNumTransactions(); num_txs = merkle_block_pow.txn.GetNumTransactions();
} else { } else {
//TODO(rebase) parent signed blocks CMerkleBlock merkle_block;
//CMerkleBlock merkle_block; if (!GetBlockAndTxFromMerkleBlock(block_hash, tx_hash, merkle_block, stack[5])) {
//if (!GetBlockAndTxFromMerkleBlock(block_hash, tx_hash, merkle_block, stack[5])) { return false;
// return false; }
//}
//if (!CheckProofSignedParent(merkle_block.header, Params().GetConsensus())) { if (!CheckProofSignedParent(merkle_block.header, Params().GetConsensus())) {
// return false; return false;
//} }
//CTransactionRef pegtx; CTransactionRef pegtx;
//if (!CheckPeginTx(stack[4], pegtx, prevout, value, claim_script)) { if (!CheckPeginTx(stack[4], pegtx, prevout, value, claim_script)) {
// return false; return false;
//} }
//num_txs = merkle_block.txn.GetNumTransactions(); num_txs = merkle_block.txn.GetNumTransactions();
} }
// Check that the merkle proof corresponds to the txid // Check that the merkle proof corresponds to the txid

View file

@ -2249,12 +2249,12 @@ UniValue getsidechaininfo(const JSONRPCRequest& request)
obj.pushKV("min_peg_diff", consensus.parentChainPowLimit.GetHex()); obj.pushKV("min_peg_diff", consensus.parentChainPowLimit.GetHex());
obj.pushKV("parent_blockhash", parent_blockhash.GetHex()); obj.pushKV("parent_blockhash", parent_blockhash.GetHex());
obj.pushKV("parent_chain_has_pow", consensus.ParentChainHasPow()); obj.pushKV("parent_chain_has_pow", consensus.ParentChainHasPow());
//TODO(rebase) signed blocks if (!consensus.ParentChainHasPow()) {
//if (!consensus.ParentChainHasPow()) { obj.pushKV("parent_chain_signblockscript_asm", ScriptToAsmStr(consensus.parent_chain_signblockscript));
// obj.pushKV("parent_chain_signblockscript_asm", ScriptToAsmStr(consensus.parent_chain_signblockscript)); obj.pushKV("parent_chain_signblockscript_hex", HexStr(consensus.parent_chain_signblockscript));
// obj.pushKV("parent_chain_signblockscript_hex", HexStr(consensus.parent_chain_signblockscript)); //TODO(stevenroose) rebase CA
// obj.pushKV("parent_pegged_asset", HexStr(consensus.parent_pegged_asset)); //obj.pushKV("parent_pegged_asset", HexStr(consensus.parent_pegged_asset));
//} }
return obj; return obj;
} }

View file

@ -4,6 +4,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <amount.h> #include <amount.h>
#include <block_proof.h>
#include <chain.h> #include <chain.h>
#include <consensus/validation.h> #include <consensus/validation.h>
#include <core_io.h> #include <core_io.h>
@ -11,6 +12,7 @@
#include <validation.h> #include <validation.h>
#include <key_io.h> #include <key_io.h>
#include <mainchainrpc.h> #include <mainchainrpc.h>
#include <merkleblock.h>
#include <net.h> #include <net.h>
#include <outputtype.h> #include <outputtype.h>
#include <pegins.h> #include <pegins.h>
@ -5197,14 +5199,13 @@ UniValue createrawpegin(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof"); throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof");
} }
} else { } else {
//TODO(rebase) parent signed blocks CTransactionRef txBTCRef;
//CTransactionRef txBTCRef; CTransaction tx_aux;
//CTransaction tx_aux; CMerkleBlock merkleBlock;
//CMerkleBlock merkleBlock; ret = createrawpegin(request, txBTCRef, tx_aux, merkleBlock);
//ret = createrawpegin(request, txBTCRef, tx_aux, merkleBlock); if (!CheckProofSignedParent(merkleBlock.header, Params().GetConsensus())) {
//if (!CheckProofSignedParent(merkleBlock.header, Params().GetConsensus())) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof");
// throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof"); }
//}
} }
return ret; return ret;
} }