Skip to content

Commit ccf40db

Browse files
committed
connect genesis block transaction outputs to coin db
1 parent 866da44 commit ccf40db

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

src/chainparams.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ class CMainParams : public CChainParams {
105105
consensus.defaultAssumeValid = uint256S("0x0000000000000000002e63058c023a9a1de233554f28c7b21380b6c9003f36a8"); //534292
106106

107107
consensus.genesis_subsidy = 50*COIN;
108+
consensus.connect_genesis_outputs = false;
108109

109110
/**
110111
* The message start string is designed to be unlikely to occur in normal data.
@@ -221,6 +222,7 @@ class CTestNetParams : public CChainParams {
221222
consensus.defaultAssumeValid = uint256S("0x0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75"); //1354312
222223

223224
consensus.genesis_subsidy = 50*COIN;
225+
consensus.connect_genesis_outputs = false;
224226

225227
pchMessageStart[0] = 0x0b;
226228
pchMessageStart[1] = 0x11;
@@ -312,6 +314,7 @@ class CRegTestParams : public CChainParams {
312314
consensus.defaultAssumeValid = uint256S("0x00");
313315

314316
consensus.genesis_subsidy = 50*COIN;
317+
consensus.connect_genesis_outputs = false;
315318

316319
pchMessageStart[0] = 0xfa;
317320
pchMessageStart[1] = 0xbf;
@@ -433,6 +436,8 @@ class CCustomParams : public CRegTestParams {
433436
std::vector<unsigned char> man_bytes = ParseHex(gArgs.GetArg("-con_mandatorycoinbase", ""));
434437
consensus.mandatory_coinbase_destination = CScript(man_bytes.begin(), man_bytes.end()); // Blank script allows any coinbase destination
435438

439+
// Custom chains connect coinbase outputs to db by default
440+
consensus.connect_genesis_outputs = gArgs.GetArg("-con_connect_coinbase", true);
436441

437442
nPruneAfterHeight = (uint64_t)args.GetArg("-npruneafterheight", nPruneAfterHeight);
438443
fDefaultConsistencyChecks = args.GetBoolArg("-fdefaultconsistencychecks", fDefaultConsistencyChecks);

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void SetupChainParamsBaseOptions()
2525
gArgs.AddArg("-con_mandatorycoinbase", "All non-zero valued coinbase outputs must go to this scriptPubKey, if set.", false, OptionsCategory::CHAINPARAMS);
2626
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);
2727
gArgs.AddArg("-con_blocksubsidy", "Defines the amount of block subsidy to start with, at genesis block.", false, OptionsCategory::CHAINPARAMS);
28+
gArgs.AddArg("-con_connect_coinbase", "Connect outputs in genesis block to utxo database.", false, OptionsCategory::CHAINPARAMS);
2829
}
2930

3031
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

src/consensus/params.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct Params {
8282
// Elements-specific chainparams
8383
CScript mandatory_coinbase_destination;
8484
CAmount genesis_subsidy;
85+
bool connect_genesis_outputs;
8586
};
8687
} // namespace Consensus
8788

src/validation.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,18 +1813,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18131813
assert(*pindex->phashBlock == block.GetHash());
18141814
int64_t nTimeStart = GetTimeMicros();
18151815

1816-
// verify that the view's current state corresponds to the previous block
1817-
const uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
1818-
assert(hashPrevBlock == view.GetBestBlock());
1819-
1820-
// Special case for the genesis block, skipping connection of its transactions
1821-
// (its coinbase is unspendable)
1822-
if (block.GetHash() == chainparams.GetConsensus().hashGenesisBlock) {
1823-
if (!fJustCheck)
1824-
view.SetBestBlock(pindex->GetBlockHash());
1825-
return true;
1826-
}
1827-
18281816
// Check it again in case a previous version let a bad block in
18291817
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
18301818
// ContextualCheckBlockHeader() here. This means that if we add a new
@@ -1848,6 +1836,25 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
18481836
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
18491837
}
18501838

1839+
// verify that the view's current state corresponds to the previous block
1840+
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
1841+
assert(hashPrevBlock == view.GetBestBlock());
1842+
1843+
const Consensus::Params& consensusParams = chainparams.GetConsensus();
1844+
// Add genesis outputs but don't validate.
1845+
if (block.GetHash() == consensusParams.hashGenesisBlock) {
1846+
if (!fJustCheck) {
1847+
if (consensusParams.connect_genesis_outputs) {
1848+
for (const auto& tx : block.vtx) {
1849+
// Directly add new coins to DB
1850+
AddCoins(view, *tx, 0);
1851+
}
1852+
}
1853+
view.SetBestBlock(pindex->GetBlockHash());
1854+
}
1855+
return true;
1856+
}
1857+
18511858
nBlocksTotal++;
18521859

18531860
// Check that all non-zero coinbase outputs pay to the required destination

test/functional/test_framework/util.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ def initialize_datadir(dirname, n, chain):
306306
f.write("listenonion=0\n")
307307
f.write("printtoconsole=0\n")
308308
f.write("con_blocksubsidy=5000000000\n")
309+
f.write("con_connect_coinbase=0\n")
309310
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
310311
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
311312
return datadir

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
'feature_notifications.py',
184184
'rpc_invalidateblock.py',
185185
'feature_rbf.py',
186+
'feature_connect_coinbase.py'
186187
]
187188

188189
# Place EXTENDED_SCRIPTS first since it has the 3 longest running tests

0 commit comments

Comments
 (0)