Skip to content

Commit 606d5e5

Browse files
committed
add consensus.mandatory_coinbase_destination
1 parent de842cb commit 606d5e5

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/chainparams.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class CRegTestParams : public CChainParams {
321321
assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
322322
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
323323

324+
324325
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
325326
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
326327

@@ -420,6 +421,11 @@ class CCustomParams : public CRegTestParams {
420421
consensus.nMinimumChainWork = uint256S(args.GetArg("-con_nminimumchainwork", "0x0"));
421422
consensus.defaultAssumeValid = uint256S(args.GetArg("-con_defaultassumevalid", "0x00"));
422423

424+
// All non-zero coinbase outputs must go to this scriptPubKey
425+
std::vector<unsigned char> man_bytes = ParseHex(gArgs.GetArg("-con_mandatorycoinbase", ""));
426+
consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination
427+
428+
423429
nPruneAfterHeight = (uint64_t)args.GetArg("-npruneafterheight", nPruneAfterHeight);
424430
fDefaultConsistencyChecks = args.GetBoolArg("-fdefaultconsistencychecks", fDefaultConsistencyChecks);
425431
fMineBlocksOnDemand = args.GetBoolArg("-fmineblocksondemand", fMineBlocksOnDemand);

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void SetupChainParamsBaseOptions()
2222
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
2323
gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);
2424
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest or custom only)", true, OptionsCategory::CHAINPARAMS);
25+
gArgs.AddArg("-con_mandatorycoinbase", "All non-zero valued coinbase outputs must go to this scriptPubKey, if set.", false, OptionsCategory::CHAINPARAMS);
2526
gArgs.AddArg("-seednode=<ip>", "Use specified node as seed node. This option can be specified multiple times to connect to multiple nodes. (custom only)", true, OptionsCategory::CHAINPARAMS);
2627
}
2728

src/consensus/params.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <map>
1212
#include <string>
1313

14+
#include <script/script.h> // mandatory_coinbase_destination
15+
1416
namespace Consensus {
1517

1618
enum DeploymentPos
@@ -75,6 +77,9 @@ struct Params {
7577
int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
7678
uint256 nMinimumChainWork;
7779
uint256 defaultAssumeValid;
80+
81+
// Elements-specific chainparams
82+
CScript mandatory_coinbase_destination;
7883
};
7984
} // namespace Consensus
8085

src/validation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,17 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18501850

18511851
nBlocksTotal++;
18521852

1853+
// Check that all non-zero coinbase outputs pay to the required destination
1854+
const CScript& mandatory_coinbase_destination = chainparams.GetConsensus().mandatory_coinbase_destination;
1855+
if (mandatory_coinbase_destination != CScript()) {
1856+
for (auto& txout : block.vtx[0]->vout) {
1857+
if (txout.scriptPubKey != mandatory_coinbase_destination && txout.nValue != 0) {
1858+
return state.DoS(100, error("ConnectBlock(): Coinbase outputs didnt match required scriptPubKey"),
1859+
REJECT_INVALID, "bad-coinbase-txos");
1860+
}
1861+
}
1862+
}
1863+
18531864
bool fScriptChecks = true;
18541865
if (!hashAssumeValid.IsNull()) {
18551866
// We've been configured with the hash of a block which has been externally verified to have a valid history.

0 commit comments

Comments
 (0)