| 5 | #include <node/context.h> |
| 6 | |
| 7 | bool NextBlockIsParameterTransition(const CBlockIndex* pindexPrev, const Consensus::Params& consensus, DynaFedParamEntry& winning_entry) |
| 8 | { |
| 9 | uint32_t next_height = pindexPrev->nHeight + 1; |
| 10 | assert(consensus.dynamic_epoch_length != 0); |
| 11 | if (next_height % consensus.dynamic_epoch_length != 0) { |
| 12 | winning_entry.SetNull(); |
| 13 | return false; |
| 14 | } |
| 15 | std::map<uint256, uint32_t> vote_tally; |
| 16 | assert(next_height >= consensus.dynamic_epoch_length); |
| 17 | for (int32_t height = next_height - 1; height >= (int32_t)(next_height - consensus.dynamic_epoch_length); --height) { |
| 18 | const CBlockIndex* p_epoch_walk = pindexPrev->GetAncestor(height); |
| 19 | assert(p_epoch_walk); |
| 20 | if (node::fTrimHeaders) { |
| 21 | LOCK(cs_main); |
| 22 | ForceUntrimHeader(p_epoch_walk); |
| 23 | } |
| 24 | const DynaFedParamEntry& proposal = p_epoch_walk->dynafed_params().m_proposed; |
| 25 | const uint256 proposal_root = proposal.CalculateRoot(); |
| 26 | vote_tally[proposal_root]++; |
| 27 | // Short-circuit once 4/5 threshold is reached |
| 28 | if (!proposal_root.IsNull() && vote_tally[proposal_root] >= |
| 29 | (consensus.dynamic_epoch_length*4)/5) { |
| 30 | winning_entry = proposal; |
| 31 | return true; |
| 32 | } |
| 33 | } |
| 34 | winning_entry.SetNull(); |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | DynaFedParamEntry ComputeNextBlockFullCurrentParameters(const CBlockIndex* pindexPrev, const Consensus::Params& consensus) |
| 39 | { |
no test coverage detected