Skip to content

Commit

Permalink
Merge #958: Some minor dynafed improvements
Browse files Browse the repository at this point in the history
14a42a0 Add two missing dynafed fields to getblockchaininfo (Steven Roose)
fe03729 dynafed: Support changing mainnet dynafed activation (Steven Roose)
ce7a93d dynafed: Only verify proposed parameters if they differ from current (Steven Roose)

Pull request description:

  - support blocksigners specifying their own activation to make coordination a bit more flexible
  - don't force fedpeg script to change in order to change the block signing script

Tree-SHA512: 8dd66440261f910b083f7ed461e1930c9380350e3648f6aca44726c39dcca3bb7e62c36d36ae56c2717827fbaee2b9046c6ce0b05441c1d8d1b54f3c284bc4d7
  • Loading branch information
stevenroose committed Mar 2, 2021
2 parents a993a7c + 14a42a0 commit 3b8e407
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 40 deletions.
5 changes: 3 additions & 2 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,10 @@ class CLiquidV1Params : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;

// Not active yet.
// Activated from block 1,000,000.
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].bit = 25;
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].nStartTime = 1000000;
// Allow blocksigners to delay activation.
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].nStartTime = gArgs.GetArg("-con_dyna_deploy_start", 1000000);
consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;


Expand Down
2 changes: 2 additions & 0 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,8 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
obj.pushKV("current_signblock_asm", ScriptToAsmStr(entry.m_signblockscript));
obj.pushKV("current_signblock_hex", HexStr(entry.m_signblockscript));
obj.pushKV("max_block_witness", (uint64_t)entry.m_signblock_witness_limit);
obj.pushKV("current_fedpeg_program", HexStr(entry.m_fedpeg_program));
obj.pushKV("current_fedpeg_script", HexStr(entry.m_fedpegscript));
UniValue arr(UniValue::VARR);
for (const auto& extension : entry.m_extension_space) {
arr.push_back(HexStr(extension));
Expand Down
89 changes: 51 additions & 38 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3502,49 +3502,62 @@ static bool ContextualCheckDynaFedHeader(const CBlockHeader& block, CValidationS
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "dynamic block header's current parameters do not match expected");
}

// Lastly, enforce rules on proposals.
const DynaFedParamEntry& proposed = dynafed_params.m_proposed;
if (!proposed.IsNull()) {

// signblockscript proposals *must* be segwit versions
int block_version = 0;
std::vector<unsigned char> block_program;
if (!proposed.m_signblockscript.IsWitnessProgram(block_version, block_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed signblockscript must be native segwit scriptPubkey");
}

int fedpeg_version = 0;
std::vector<unsigned char> fedpeg_program;
if (!proposed.m_fedpeg_program.IsWitnessProgram(fedpeg_version, fedpeg_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed fedpegs program must be native segwit scriptPubkey");
}

// for v0, fedpegscript's scriptPubKey must match. v1+ is unencumbered.
if (fedpeg_version == 0) {
uint256 fedpeg_program;
CSHA256().Write(proposed.m_fedpegscript.data(), proposed.m_fedpegscript.size()).Finalize(fedpeg_program.begin());
CScript computed_program = CScript() << OP_0 << ToByteVector(fedpeg_program);
if (computed_program != proposed.m_fedpeg_program) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed v0 segwit fedpegscript must match proposed fedpeg witness program");
// Lastly, enforce rules on proposals if they make changes.
if (!dynafed_params.m_proposed.IsNull()) {
// Compare the new proposed parameters with the current full parameters.
const DynaFedParamEntry current = ComputeNextBlockFullCurrentParameters(pindexPrev, params.GetConsensus());
const DynaFedParamEntry& proposed = dynafed_params.m_proposed;

if (proposed.m_signblockscript != current.m_signblockscript) {
// signblockscript proposals *must* be segwit versions
int block_version = 0;
std::vector<unsigned char> block_program;
if (!proposed.m_signblockscript.IsWitnessProgram(block_version, block_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed",
"proposed signblockscript must be native segwit scriptPubkey"
);
}
}

// fedpegscript proposals *must not* start with OP_DEPTH
// This forbids the first Liquid watchman script which is a hack.
// Use miniscript, which doesn't even have OP_DEPTH.
// We don't encumber future segwit versions as opcodes may change.
if (!proposed.m_fedpegscript.empty() &&
proposed.m_fedpegscript.front() == OP_DEPTH) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Proposed fedpegscript starts with OP_DEPTH, which is illegal");
if (proposed.m_fedpeg_program != current.m_fedpeg_program || proposed.m_fedpegscript != current.m_fedpegscript) {
int fedpeg_version = 0;
std::vector<unsigned char> fedpeg_program;
if (!proposed.m_fedpeg_program.IsWitnessProgram(fedpeg_version, fedpeg_program)) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "proposed fedpegs program must be native segwit scriptPubkey");
}

// for v0, fedpegscript's scriptPubKey must match. v1+ is unencumbered.
if (fedpeg_version == 0) {
uint256 fedpeg_program;
CSHA256().Write(proposed.m_fedpegscript.data(), proposed.m_fedpegscript.size()).Finalize(fedpeg_program.begin());
CScript computed_program = CScript() << OP_0 << ToByteVector(fedpeg_program);
if (computed_program != proposed.m_fedpeg_program) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed",
"proposed v0 segwit fedpegscript must match proposed fedpeg witness program"
);
}

// fedpegscript proposals *must not* start with OP_DEPTH
// This forbids the first Liquid watchman script which is a hack.
// Use miniscript, which doesn't even have OP_DEPTH.
// We don't encumber future segwit versions as opcodes may change.
if (!proposed.m_fedpegscript.empty() && proposed.m_fedpegscript.front() == OP_DEPTH) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Proposed fedpegscript starts with OP_DEPTH, which is illegal");
}
}
}

// When enforcing PAK, extension_space must give non-empty PAK list when
// the vector itself is non-empty. Otherwise this means there were "junk"
// entries
if (params.GetEnforcePak()) {
if (!proposed.m_extension_space.empty() &&
CreatePAKListFromExtensionSpace(proposed.m_extension_space).IsReject()) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed", "Extension space is not list of valid PAK entries");
if (proposed.m_extension_space != current.m_extension_space) {
// When enforcing PAK, extension_space must give non-empty PAK list when
// the vector itself is non-empty. Otherwise this means there were "junk"
// entries
if (params.GetEnforcePak()) {
if (!proposed.m_extension_space.empty() &&
CreatePAKListFromExtensionSpace(proposed.m_extension_space).IsReject()) {
return state.Invalid(false, REJECT_INVALID, "invalid-dyna-fed",
"Extension space is not list of valid PAK entries"
);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions test/functional/feature_dynafed.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def set_test_params(self):
self.extra_args = [["-con_dyna_deploy_start=1000", "-enforce_pak=1", "-con_parent_chain_signblockscript=51", "-peginconfirmationdepth=1", "-parentscriptprefix=75", "-parent_bech32_hrp=ert"] for i in range(self.num_nodes)]
# second node will not mine transactions
self.extra_args[1].append("-blocksonly=1")
# Make sure nothing breaks if peers have a different activation.
self.extra_args[1][0] = "-con_dyna_deploy_start=937"

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
Expand Down

0 comments on commit 3b8e407

Please sign in to comment.