mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Miner support for signed blocks
This commit is contained in:
parent
0e473228e0
commit
0d7e0f9898
2 changed files with 26 additions and 7 deletions
|
|
@ -25,6 +25,9 @@
|
|||
#include <utilmoneystr.h>
|
||||
#include <validationinterface.h>
|
||||
|
||||
// ELEMENTS
|
||||
#include <block_proof.h> // ResetProof, ResetChallenge
|
||||
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
|
|
@ -96,8 +99,9 @@ void BlockAssembler::resetBlock()
|
|||
nFees = 0;
|
||||
}
|
||||
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx)
|
||||
std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx, int min_tx_age)
|
||||
{
|
||||
assert(min_tx_age >= 0);
|
||||
int64_t nTimeStart = GetTimeMicros();
|
||||
|
||||
resetBlock();
|
||||
|
|
@ -142,9 +146,18 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
|||
// transaction (which in most cases can be a no-op).
|
||||
fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus()) && fMineWitnessTx;
|
||||
|
||||
if (g_signed_blocks) {
|
||||
// Pad block weight by block proof fields (including upper-bound of signature)
|
||||
nBlockWeight += chainparams.GetConsensus().signblockscript.size() * WITNESS_SCALE_FACTOR;
|
||||
nBlockWeight += chainparams.GetConsensus().max_block_signature_size * WITNESS_SCALE_FACTOR;
|
||||
// Reset block proof
|
||||
ResetProof(*pblock);
|
||||
ResetChallenge(*pblock, *pindexPrev, chainparams.GetConsensus());
|
||||
}
|
||||
|
||||
int nPackagesSelected = 0;
|
||||
int nDescendantsUpdated = 0;
|
||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated);
|
||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated, min_tx_age);
|
||||
|
||||
int64_t nTime1 = GetTimeMicros();
|
||||
|
||||
|
|
@ -168,10 +181,10 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
|||
// Fill in header
|
||||
pblock->hashPrevBlock = pindexPrev->GetBlockHash();
|
||||
UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev);
|
||||
pblock->nBits = g_signed_blocks ? 0 : GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
|
||||
if (g_con_blockheightinheader) {
|
||||
pblock->block_height = nHeight;
|
||||
}
|
||||
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, chainparams.GetConsensus());
|
||||
pblock->nNonce = 0;
|
||||
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
|
||||
|
||||
|
|
@ -306,7 +319,7 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
|
|||
// Each time through the loop, we compare the best transaction in
|
||||
// mapModifiedTxs with the next transaction in the mempool to decide what
|
||||
// transaction package to work on next.
|
||||
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated)
|
||||
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, int min_tx_age)
|
||||
{
|
||||
// mapModifiedTx will store sorted packages after they are modified
|
||||
// because some of their txs are already in the block
|
||||
|
|
@ -362,6 +375,12 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
|
|||
}
|
||||
}
|
||||
|
||||
// Skip transactions that are under X seconds in mempool
|
||||
// min_tx_age value of 0 is considered "inactive", in case of mocktime
|
||||
if (min_tx_age > 0 && iter->GetTime() > GetTime() - min_tx_age) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We skip mapTx entries that are inBlock, and mapModifiedTx shouldn't
|
||||
// contain anything that is inBlock.
|
||||
assert(!inBlock.count(iter));
|
||||
|
|
|
|||
|
|
@ -156,8 +156,8 @@ public:
|
|||
explicit BlockAssembler(const CChainParams& params);
|
||||
BlockAssembler(const CChainParams& params, const Options& options);
|
||||
|
||||
/** Construct a new block template with coinbase to scriptPubKeyIn */
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true);
|
||||
/** Construct a new block template with coinbase to scriptPubKeyIn. min_tx_age is in seconds */
|
||||
std::unique_ptr<CBlockTemplate> CreateNewBlock(const CScript& scriptPubKeyIn, bool fMineWitnessTx=true, int min_tx_age=0);
|
||||
|
||||
private:
|
||||
// utility functions
|
||||
|
|
@ -170,7 +170,7 @@ private:
|
|||
/** Add transactions based on feerate including unconfirmed ancestors
|
||||
* Increments nPackagesSelected / nDescendantsUpdated with corresponding
|
||||
* statistics from the package selection (for logging statistics). */
|
||||
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
|
||||
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, int required_wait=0) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
|
||||
|
||||
// helper functions for addPackageTxs()
|
||||
/** Remove confirmed (inBlock) entries from given set */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue