Skip to content

Commit 7475eda

Browse files
committed
add consensus.mandatory_coinbase_destination
1 parent e1ed37e commit 7475eda

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

src/chainparams.cpp

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

325+
// All non-zero coinbase outputs must go to this scriptPubKey
326+
consensus.mandatory_coinbase_destination = CScript(ParseHex(gArgs.GetArg("-con_mandatorycoinbase", ""))); // Blank script allows any coinbase destination
327+
325328
vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
326329
vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
327330

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ void SetupChainParamsBaseOptions()
2020
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
2121
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
2222
gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);
23+
gArgs.AddArg("-con_mandatorycoinbase", "All non-zero valued coinbase outputs must go to this scriptPubKey, if set.", false, OptionsCategory::CHAINPARAMS);
2324
}
2425

2526
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

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
@@ -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)