diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c3ffa3f..7855e25 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -73,12 +73,9 @@ public: consensus.BIP66Height = 29000; consensus.CSVHeight = 29000; consensus.SegwitHeight = 29000; + consensus.MinBIP9WarningHeight = 29540; // segwit activation height + miner confirmation window - - - consensus.nAuxpowStartHeight = 310000; - consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); consensus.nPowTargetTimespan = 24 * 60 * 60; // 86400 seconds @@ -202,9 +199,8 @@ public: consensus.SegwitHeight = 834624; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca consensus.MinBIP9WarningHeight = 836640; // segwit activation height + miner confirmation window consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - consensus.nAuxpowStartHeight = 1; - consensus.nPowTargetTimespan = 24 * 60 * 60; // two weeks - consensus.nPowTargetSpacing = 2 * 60; + consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks + consensus.nPowTargetSpacing = 10 * 60; consensus.fPowAllowMinDifficultyBlocks = true; consensus.fPowNoRetargeting = false; consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains diff --git a/src/consensus/params.h b/src/consensus/params.h index aed7438..7cc7890 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -1,22 +1,16 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto -// Copyright (c) 2009-2019 The Palladium Core developers // Jahr angepasst +// Copyright (c) 2009-2019 The Palladium Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef PALLADIUM_CONSENSUS_PARAMS_H // Guard angepasst +#ifndef PALLADIUM_CONSENSUS_PARAMS_H #define PALLADIUM_CONSENSUS_PARAMS_H #include #include -#include -#include namespace Consensus { -// --- Maximale Blockhöhe für Fork-Planung --- -static constexpr int MAX_BLOCK_HEIGHT = std::numeric_limits::max(); - - enum DeploymentPos { DEPLOYMENT_TESTDUMMY, @@ -30,16 +24,18 @@ enum DeploymentPos struct BIP9Deployment { /** Bit position to select the particular bit in nVersion. */ int bit; - /** Start MedianTime for version bits signalling. */ + /** Start MedianTime for version bits miner confirmation. Can be a date in the past */ int64_t nStartTime; - /** Timeout MedianTime for version bits signalling. */ + /** Timeout/expiry MedianTime for the deployment attempt. */ int64_t nTimeout; /** Constant for nTimeout very far in the future. */ static constexpr int64_t NO_TIMEOUT = std::numeric_limits::max(); /** Special value for nStartTime indicating that the deployment is always active. - * This is useful for testing, regression testing and informational deployments. */ + * This is useful for testing, as it means tests don't need to deal with the activation + * process (which takes at least 3 BIP9 intervals). Only tests that specifically test the + * behaviour during activation cannot use this. */ static constexpr int64_t ALWAYS_ACTIVE = -1; }; @@ -49,71 +45,44 @@ struct BIP9Deployment { struct Params { uint256 hashGenesisBlock; int nSubsidyHalvingInterval; - /** Block height and hash at which BIP16 becomes active */ - // int BIP16Height; // Oft 0 in neueren Chains, P2SH immer aktiv? Prüfen! - uint256 BIP16Exception; // Genesis hash if BIP16 active from start - /** Block height at which BIP34 becomes active */ + /* Block hash that is excepted from BIP16 enforcement */ + uint256 BIP16Exception; + /** Block height and hash at which BIP34 becomes active */ int BIP34Height; - uint256 BIP34Hash; // Not needed if height-based + uint256 BIP34Hash; /** Block height at which BIP65 becomes active */ int BIP65Height; /** Block height at which BIP66 becomes active */ int BIP66Height; /** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */ int CSVHeight; - /** Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active. */ + /** Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active. + * Note that segwit v0 script rules are enforced on all blocks except the + * BIP 16 exception blocks. */ int SegwitHeight; - /** Don't warn about unknown BIP 9 activations below this height. */ + /** Don't warn about unknown BIP 9 activations below this height. + * This prevents us from warning about the CSV and segwit activations. */ int MinBIP9WarningHeight; - /** BIP9 deployment parameters */ + /** + * Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period, + * (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments. + * Examples: 1916 for 95%, 1512 for testchains. + */ uint32_t nRuleChangeActivationThreshold; uint32_t nMinerConfirmationWindow; BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]; /** Proof of work parameters */ uint256 powLimit; + bool fPowAllowMinDifficultyBlocks; bool fPowNoRetargeting; int64_t nPowTargetSpacing; - int64_t nPowTargetSpacingV2; // Für LWMA / neue Blockzeit + int64_t nPowTargetSpacingV2; int64_t nPowTargetTimespan; - // DifficultyAdjustmentInterval angepasst, um korrekten Wert nach LWMA-Aktivierung zu liefern - int DifficultyAdjustmentInterval(int nHeight) const { - // Prüfe, ob LWMA aktiv ist (Block >= 29000). Wenn ja, ist das klassische Intervall irrelevant. - // Falls wir das Fenster für BIP9 brauchen, muss es anders berechnet werden. - // Nehmen wir an, nMinerConfirmationWindow ist jetzt der relevante Wert für BIP9. - // Die alte Berechnung ist nur für den alten Algo (< 29000) relevant. - if (nHeight < 29000) { // Beispiel: Blockhöhe anpassen, falls LWMA anders aktiviert wurde - return nPowTargetTimespan / nPowTargetSpacing; - } else { - // Für BIP9 wird nMinerConfirmationWindow verwendet. - // Gib hier einen sinnvollen Wert zurück oder passe die Verwendung an. - // Bitcoin Core verwendet hier oft einen festen Wert (z.B. 2016) - // oder leitet ihn aus Timespan/Spacing ab. - // Da LWMA das Timespan ignoriert, ist es sauberer, nMinerConfirmationWindow direkt zu verwenden. - // return nMinerConfirmationWindow; // Oder die alte Berechnung, wenn sie noch irgendwo gebraucht wird - return nPowTargetTimespan / nPowTargetSpacingV2; // Behalte Timespan/Spacing Logik bei - } - } + int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } uint256 nMinimumChainWork; uint256 defaultAssumeValid; - - // --- AuxPoW Start --- - /** Block height at which Auxiliary Proof of Work (AuxPoW) becomes active */ - int nAuxpowStartHeight; - // --- AuxPoW Ende --- - - // Constructor to initialize members - WICHTIG: Alle neuen Member hier initialisieren! - Params() : hashGenesisBlock(), nSubsidyHalvingInterval(0), /*BIP16Height(0),*/ BIP16Exception(), - BIP34Height(0), BIP34Hash(), BIP65Height(0), BIP66Height(0), CSVHeight(0), SegwitHeight(0), - MinBIP9WarningHeight(0), nRuleChangeActivationThreshold(0), nMinerConfirmationWindow(0), - vDeployments{}, powLimit(), fPowAllowMinDifficultyBlocks(false), fPowNoRetargeting(false), - nPowTargetSpacing(0), nPowTargetSpacingV2(0), nPowTargetTimespan(0), - nMinimumChainWork(), defaultAssumeValid() - // --- AuxPoW Start --- - , nAuxpowStartHeight(MAX_BLOCK_HEIGHT) // Standardmäßig deaktiviert - // --- AuxPoW Ende --- - {} }; } // namespace Consensus -#endif // PALLADIUM_CONSENSUS_PARAMS_H \ No newline at end of file +#endif // PALLADIUM_CONSENSUS_PARAMS_H diff --git a/src/miner.cpp b/src/miner.cpp index b0e6ea5..35554d1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -24,10 +24,6 @@ #include #include - -#include - - int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { int64_t nOldTime = pblock->nTime; @@ -428,107 +424,6 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda } } - -// Method to compute block version -// Currently just returns BASE_VERSION, needs update for BIP9 signaling if used -// static int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params) -// { - // Implement BIP9 version bit signaling logic here if needed - // ... -// return CBlockHeader::BASE_VERSION; // Return base version for now -// } - -std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& scriptPubKeyIn) -{ - int64_t nTimeStart = GetTimeMicros(); - - ResetBlock(); - - pblocktemplate = std::make_unique(); - pblock = &pblocktemplate->block; // pointer for convenience - - // Add dummy coinbase tx as first transaction - pblock->vtx.emplace_back(); - pblocktemplate->vTxFees.push_back(-1); // updated at end - pblocktemplate->vTxSigOpsCost.push_back(-1); // updated at end - - LOCK2(cs_main, m_mempool.cs); - CBlockIndex* pindexPrev = ::ChainActive().Tip(); - assert(pindexPrev != nullptr); - nHeight = pindexPrev->nHeight + 1; - - // --- AuxPoW Start --- - // Set base version first - pblock->nVersion = CBlockHeader::BASE_VERSION; // ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); - // Add AuxPoW version bit if fork is active - const Consensus::Params& consensusParams = chainparams.GetConsensus(); - if (nHeight >= consensusParams.nAuxpowStartHeight) { - pblock->nVersion |= CBlockHeader::AUXPOW_VERSION_BIT; - LogPrintf("CreateNewBlock: Setting AuxPoW version bit for block height %d\n", nHeight); - } - // --- AuxPoW Ende --- - - // -regtest only: allow overriding block.nVersion with - // -blockversion=N to test forking scenarios - if (chainparams.MineBlocksOnDemand()) - pblock->nVersion = gArgs.GetArg("-blockversion", pblock->nVersion); - - pblock->nTime = GetAdjustedTime(); - const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); - - nLockTimeCutoff = (STANDARD_LOCKTIME_VERIFY_FLAGS & LOCKTIME_MEDIAN_TIME_PAST) - ? nMedianTimePast - : pblock->GetBlockTime(); - - // Decide whether to include witness transactions - // Typically based on Segwit activation height - bool fIncludeWitness = IsWitnessEnabled(pindexPrev, consensusParams); - - int nPackagesSelected = 0; - int nDescendantsUpdated = 0; - addPackageTxs(nPackagesSelected, nDescendantsUpdated); - - int64_t nTime1 = GetTimeMicros(); - - m_last_block_num_txs = nBlockTx; - m_last_block_weight = nBlockWeight; - - // Create coinbase transaction. - CMutableTransaction coinbaseTx; - coinbaseTx.vin.resize(1); - coinbaseTx.vin[0].prevout.SetNull(); - coinbaseTx.vout.resize(1); - coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; - coinbaseTx.vout[0].nValue = nFees + GetBlockSubsidy(nHeight, consensusParams); - coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0; // OP_0 statt nExtraNonce? Prüfe Coinbase-Regeln - // nExtraNonce logic seems missing or different in this base code? Add if needed. - // If nExtraNonce is used, it should be part of scriptSig generation. - - pblock->vtx[0] = MakeTransactionRef(std::move(coinbaseTx)); - pblocktemplate->vchCoinbaseCommitment = GenerateCoinbaseCommitment(*pblock, pindexPrev, consensusParams); - pblocktemplate->vTxFees[0] = -nFees; - - LogPrintf("CreateNewBlock(): block weight: %u txs: %u fees: %ld sigops_cost: %d\n", - GetBlockWeight(*pblock), nBlockTx, nFees, nBlockSigOpsCost); - - // Fill in header - pblock->hashPrevBlock = pindexPrev->GetBlockHash(); - UpdateTime(pblock, consensusParams, pindexPrev); - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, consensusParams); - pblock->nNonce = 0; // Nonce wird vom Miner gesetzt - pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]); - - CValidationState state; - if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) { - throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString())); - } - int64_t nTime2 = GetTimeMicros(); - - LogPrint(BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart)); - - return std::move(pblocktemplate); -} - void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce) { // Update nExtraNonce diff --git a/src/pow.cpp b/src/pow.cpp index 802aa80..29dfb97 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -9,68 +9,34 @@ #include #include #include -#include // Für error() - -// --- AuxPoW Start --- -#include // Für ParseHex -#include