Skip to content

Commit f277ec5

Browse files
committed
Add miner ability to make dynafed blocks
1 parent f5e4632 commit f277ec5

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/miner.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <util/system.h>
2626
#include <validationinterface.h>
2727

28+
#include <dynafed.h>
2829

2930
#include <algorithm>
3031
#include <queue>
@@ -101,7 +102,7 @@ void BlockAssembler::resetBlock()
101102
Optional<int64_t> BlockAssembler::m_last_block_num_txs{nullopt};
102103
Optional<int64_t> BlockAssembler::m_last_block_weight{nullopt};
103104

104-
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, int min_tx_age)
105+
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, int min_tx_age, ConsensusParamEntry* proposed_entry)
105106
{
106107
assert(min_tx_age >= 0);
107108
int64_t nTimeStart = GetTimeMicros();
@@ -165,7 +166,16 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
165166
// transaction (which in most cases can be a no-op).
166167
fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus());
167168

168-
if (g_signed_blocks) {
169+
if (IsDynaFedEnabled(pindexPrev, chainparams.GetConsensus())) {
170+
ConsensusParamEntry current_params = ComputeNextBlockCurrentParameters(chainActive.Tip(), chainparams.GetConsensus());
171+
DynaFedParams block_params(current_params, proposed_entry ? *proposed_entry : ConsensusParamEntry());
172+
pblock->m_dyna_params = block_params;
173+
nBlockWeight += ::GetSerializeSize(block_params, PROTOCOL_VERSION)*WITNESS_SCALE_FACTOR;
174+
nBlockWeight += current_params.m_sbs_wit_limit; // Note witness discount
175+
assert(pblock->proof.IsNull());
176+
177+
} else if (g_signed_blocks) {
178+
// Old style signed blocks
169179
// Pad block weight by block proof fields (including upper-bound of signature)
170180
nBlockWeight += chainparams.GetConsensus().signblockscript.size() * WITNESS_SCALE_FACTOR;
171181
nBlockWeight += chainparams.GetConsensus().max_block_signature_size * WITNESS_SCALE_FACTOR;

src/miner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class BlockAssembler
159159
BlockAssembler(const CChainParams& params, const Options& options);
160160

161161
/** Construct a new block template with coinbase to scriptPubKeyIn. min_tx_age is in seconds */
162-
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, int min_tx_age=0);
162+
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, int min_tx_age=0, ConsensusParamEntry* = nullptr);
163163

164164
static Optional<int64_t> m_last_block_num_txs;
165165
static Optional<int64_t> m_last_block_weight;

0 commit comments

Comments
 (0)