MCPcopy Create free account
hub / github.com/ElementsProject/elements / ComputeNextBlockFullCurrentParameters

Function ComputeNextBlockFullCurrentParameters

src/dynafed.cpp:38–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36}
37
38DynaFedParamEntry ComputeNextBlockFullCurrentParameters(const CBlockIndex* pindexPrev, const Consensus::Params& consensus)
39{
40 assert(pindexPrev);
41
42 uint32_t next_height = pindexPrev->nHeight+1;
43 const uint32_t epoch_length = consensus.dynamic_epoch_length;
44 uint32_t epoch_age = next_height % epoch_length;
45
46 DynaFedParamEntry winning_proposal;
47 // Early return when there is a winning proposal
48 if (NextBlockIsParameterTransition(pindexPrev, consensus, winning_proposal)) {
49 assert(epoch_age == 0);
50 return winning_proposal;
51 }
52
53 // Since no transition took place, find most recent epoch start
54
55 // If next block is start of new epoch, walk backwards one epoch
56 uint32_t epoch_start_height = next_height - epoch_age;
57 if (epoch_age == 0) {
58 epoch_start_height -= epoch_length;
59 }
60
61 if (consensus.genesis_style == "elements" && epoch_start_height == 0 && next_height > 1 && consensus.vDeployments[Consensus::DEPLOYMENT_DYNA_FED].nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE) {
62 // when starting in dynafed mode, the full parameters are stored in block 1 instead of 0
63 epoch_start_height = 1;
64 }
65 // We need to put in place the previous epoch's current which
66 // may be pre-dynafed params
67 const CBlockIndex* p_epoch_start = pindexPrev->GetAncestor(epoch_start_height);
68 assert(p_epoch_start);
69 if (node::fTrimHeaders) {
70 LOCK(cs_main);
71 ForceUntrimHeader(p_epoch_start);
72 }
73 if (p_epoch_start->dynafed_params().IsNull()) {
74 // We need to construct the "full" current parameters of pre-dynafed
75 // consensus
76
77 // Convert signblockscript to P2WSH
78 uint256 signblock_witness_program;
79 CSHA256().Write(p_epoch_start->get_proof().challenge.data(), p_epoch_start->get_proof().challenge.size()).Finalize(signblock_witness_program.begin());
80 CScript p2wsh_signblock_script = CScript() << OP_0 << ToByteVector(signblock_witness_program);
81
82 // Make P2SH-P2WSH-ness of non-dynafed fedpegscript explicit
83 uint256 fedpegscript_redeemscript;
84 CSHA256().Write(consensus.fedpegScript.data(), consensus.fedpegScript.size()).Finalize(fedpegscript_redeemscript.begin());
85 CScript fedpeg_p2sw = CScript() << OP_0 << ToByteVector(fedpegscript_redeemscript);
86 if (consensus.start_p2wsh_script) {
87 winning_proposal = DynaFedParamEntry(p2wsh_signblock_script, consensus.max_block_signature_size, fedpeg_p2sw, consensus.fedpegScript, consensus.first_extension_space);
88 } else {
89 uint160 fedpeg_p2sh(Hash160(fedpeg_p2sw));
90 CScript sh_wsh_fedpeg_program = CScript() << OP_HASH160 << ToByteVector(fedpeg_p2sh) << OP_EQUAL;
91
92 // Put them in winning proposal
93 winning_proposal = DynaFedParamEntry(p2wsh_signblock_script, consensus.max_block_signature_size, sh_wsh_fedpeg_program, consensus.fedpegScript, consensus.first_extension_space);
94 }
95 } else {

Callers 5

GetValidFedpegScriptsFunction · 0.85
getblockchaininfoFunction · 0.85
GetActivePAKListFunction · 0.85

Calls 13

CSHA256Class · 0.85
ToByteVectorFunction · 0.85
Hash160Function · 0.85
GetAncestorMethod · 0.80
CScriptClass · 0.70
DynaFedParamEntryClass · 0.50
IsNullMethod · 0.45
FinalizeMethod · 0.45
WriteMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected