Skip to content

Commit 9897b5e

Browse files
committed
add consensus.mandatory_coinbase_destination
1 parent 9ab8390 commit 9897b5e

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/chainparams.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ class CRegTestParams : public CChainParams {
334334
assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
335335
assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
336336

337+
// All non-zero coinbase outputs must go to this scriptPubKey
338+
consensus.mandatory_coinbase_destination = StrHexToScriptWithDefault(gArgs.GetArg("-con_mandatorycoinbase", ""), CScript()); // Blank script allows any coinbase destination
339+
337340
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
338341
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
339342

src/consensus/params.h

+5
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

+11
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,17 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18471847

18481848
nBlocksTotal++;
18491849

1850+
// Check that all non-zero coinbase outputs pay to the required destination
1851+
const CScript& mandatory_coinbase_destination = chainparams.GetConsensus().mandatory_coinbase_destination;
1852+
if (mandatory_coinbase_destination != CScript()) {
1853+
for (auto& txout : block.vtx[0]->vout) {
1854+
if (txout.scriptPubKey != mandatory_coinbase_destination && txout.nValue != 0) {
1855+
return state.DoS(100, error("ConnectBlock(): Coinbase outputs didnt match required scriptPubKey"),
1856+
REJECT_INVALID, "bad-coinbase-txos");
1857+
}
1858+
}
1859+
}
1860+
18501861
bool fScriptChecks = true;
18511862
if (!hashAssumeValid.IsNull()) {
18521863
// 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)