Skip to content

Commit

Permalink
Merge pull request #12 from ElectraProtocol/dev
Browse files Browse the repository at this point in the history
v1.0.5.0
  • Loading branch information
Jenova7 authored Nov 20, 2023
2 parents c904cff + 5274d9e commit e22e39d
Show file tree
Hide file tree
Showing 72 changed files with 328 additions and 241 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ config.cache
config.log
config.status
configure
configure~
libtool
src/config/xep-config.h
src/config/xep-config.h.in
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
AC_PREREQ([2.69])
define(_CLIENT_VERSION_MAJOR, 1)
define(_CLIENT_VERSION_MINOR, 0)
define(_CLIENT_VERSION_REVISION, 4)
define(_CLIENT_VERSION_REVISION, 5)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_RC, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2022)
define(_COPYRIGHT_YEAR, 2023)
define(_COPYRIGHT_HOLDERS,[The %s developers])
define(_COPYRIGHT_HOLDERS_SUBSTITUTION,[[Electra Protocol]])
AC_INIT([XEP Core],m4_join([.], _CLIENT_VERSION_MAJOR, _CLIENT_VERSION_MINOR, _CLIENT_VERSION_REVISION, m4_if(_CLIENT_VERSION_BUILD, [0], [], _CLIENT_VERSION_BUILD))m4_if(_CLIENT_VERSION_RC, [0], [], [rc]_CLIENT_VERSION_RC),[https://github.com/ElectraProtocol/XEP-Core/issues],[xep],[https://www.electraprotocol.com/])
Expand Down
1 change: 0 additions & 1 deletion depends/packages/qt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ $(package)_config_opts += -no-feature-printdialog
$(package)_config_opts += -no-feature-printer
$(package)_config_opts += -no-feature-printpreviewdialog
$(package)_config_opts += -no-feature-printpreviewwidget
$(package)_config_opts += -no-feature-regularexpression
$(package)_config_opts += -no-feature-sessionmanager
$(package)_config_opts += -no-feature-sql
$(package)_config_opts += -no-feature-statemachine
Expand Down
Binary file modified doc/xep_logo_doxygen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/bench/duplicate_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static void DuplicateInputs(benchmark::Bench& bench)
coinbaseTx.vin[0].prevout.SetNull();
coinbaseTx.vout.resize(1);
coinbaseTx.vout[0].scriptPubKey = SCRIPT_PUB;
coinbaseTx.vout[0].nValue = GetBlockSubsidy(nHeight, false, 0, chainparams.GetConsensus());
coinbaseTx.vout[0].nValue = GetBlockSubsidy(nHeight, false, 0, 0, chainparams.GetConsensus());
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;


Expand Down
8 changes: 8 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class CMainParams : public CChainParams {
consensus.mTreasuryPayees.emplace(CScript() << OP_0 << ParseHex("978a5064cd1fdf8c2510fe3fcbd65eaa5e98b32d"), 100); // 10% (full reward) for ep1qj799qexdrl0ccfgslcluh4j74f0f3vedatcv0k
consensus.nTreasuryRewardPercentage = 10; // 10% of block reward goes to treasury

consensus.sBurnAddresses.emplace(CScript() << OP_DUP << OP_HASH160 << ParseHex("1fa15641f00f98b33a66054f11138a5fbe4d7058") << OP_EQUALVERIFY << OP_CHECKSIG); // PBURNomniXEPXXXXXXXXXXXXXXXXYZ2zjf

consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000004d4a27e34ba8c684ba2b");
consensus.defaultAssumeValid = uint256S("0x5fbff547e15f6ad22cad7dad4a79dd5ed893552ea809a10400cc618e52a2be91"); // 450000

Expand Down Expand Up @@ -265,6 +267,8 @@ class CTestNetParams : public CChainParams {
consensus.mTreasuryPayees.emplace(CScript() << OP_0 << ParseHex("978a5064cd1fdf8c2510fe3fcbd65eaa5e98b32d"), 100); // 10% (full reward) for ep1qj799qexdrl0ccfgslcluh4j74f0f3vedatcv0k
consensus.nTreasuryRewardPercentage = 10; // 10% of block reward goes to treasury

consensus.sBurnAddresses.emplace(CScript() << OP_DUP << OP_HASH160 << ParseHex("1fa15641f00f98b33a66054f11138a5fbe4d7058") << OP_EQUALVERIFY << OP_CHECKSIG); // PBURNomniXEPXXXXXXXXXXXXXXXXYZ2zjf

consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000000000000030d440d4400");
consensus.defaultAssumeValid = uint256S("0x4a121e7765837b21bcffad979e499ecbf7184fcbf772c34c481433059d0840f8"); // 200000

Expand Down Expand Up @@ -436,6 +440,8 @@ class SigNetParams : public CChainParams {
consensus.mTreasuryPayees.emplace(CScript() << OP_0 << ParseHex("978a5064cd1fdf8c2510fe3fcbd65eaa5e98b32d"), 100); // 10% (full reward) for ep1qj799qexdrl0ccfgslcluh4j74f0f3vedatcv0k
consensus.nTreasuryRewardPercentage = 10; // 10% of block reward goes to treasury

consensus.sBurnAddresses.emplace(CScript() << OP_DUP << OP_HASH160 << ParseHex("1fa15641f00f98b33a66054f11138a5fbe4d7058") << OP_EQUALVERIFY << OP_CHECKSIG); // PBURNomniXEPXXXXXXXXXXXXXXXXYZ2zjf

// message start is defined as the first 4 bytes of the sha256d of the block script
CHashWriter h(SER_DISK, 0);
h << consensus.signet_challenge;
Expand Down Expand Up @@ -526,6 +532,8 @@ class CRegTestParams : public CChainParams {
consensus.mTreasuryPayees.emplace(CScript() << OP_0 << ParseHex("978a5064cd1fdf8c2510fe3fcbd65eaa5e98b32d"), 100); // 10% (full reward) for ep1qj799qexdrl0ccfgslcluh4j74f0f3vedatcv0k
consensus.nTreasuryRewardPercentage = 10; // 10% of block reward goes to treasury

consensus.sBurnAddresses.emplace(CScript() << OP_DUP << OP_HASH160 << ParseHex("1fa15641f00f98b33a66054f11138a5fbe4d7058") << OP_EQUALVERIFY << OP_CHECKSIG); // PBURNomniXEPXXXXXXXXXXXXXXXXYZ2zjf

consensus.nMinimumChainWork = uint256{};
consensus.defaultAssumeValid = uint256{};

Expand Down
3 changes: 2 additions & 1 deletion src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <coins.h>

#include <chainparams.h>
#include <consensus/consensus.h>
#include <logging.h>
#include <random.h>
Expand Down Expand Up @@ -67,7 +68,7 @@ bool CCoinsViewCache::GetCoin(const COutPoint &outpoint, Coin &coin) const {

void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) {
assert(!coin.IsSpent());
if (coin.out.scriptPubKey.IsUnspendable() || coin.out.nValue == 0 || coin.out.scriptPubKey.empty()) return;
if (coin.out.scriptPubKey.IsUnspendable() || coin.out.nValue == 0 || coin.out.scriptPubKey.empty() || Params().GetConsensus().sBurnAddresses.count(coin.out.scriptPubKey)) return;
CCoinsMap::iterator it;
bool inserted;
std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>());
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <uint256.h>
#include <limits>
#include <map>
#include <set>

namespace Consensus {

Expand Down Expand Up @@ -67,6 +68,7 @@ struct Params {
int nTreasuryPaymentsCycleBlocks;
std::map<CScript, unsigned int> mTreasuryPayees;
unsigned int nTreasuryRewardPercentage;
std::set<CScript> sBurnAddresses;
/* Block hash that is excepted from BIP16 enforcement */
uint256 BIP16Exception;
/** Block height and hash at which BIP34 becomes active */
Expand Down
20 changes: 9 additions & 11 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) 2012-2020 The Peercoin developers
// Copyright (c) 2015-2019 The PIVX developers
// Copyright (c) 2018-2021 John "ComputerCraftr" Studnicka
// Copyright (c) 2018-2022 John "ComputerCraftr" Studnicka
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chain.h>
#include <chainparams.h>
#include <consensus/validation.h>
#include <hash.h>
Expand All @@ -17,8 +18,10 @@
#include <util/system.h>
#include <validation.h>

#include <unordered_map>

// Hard checkpoints of stake modifiers to ensure they are deterministic
static const std::map<int, unsigned int> mapStakeModifierCheckpoints = {
static const std::unordered_map<int, unsigned int> mapStakeModifierCheckpoints = {
{ 0, 0x0e00670bu },
{ 50000, 0xcbe5a9b4u },
{ 100000, 0xbd074053u },
Expand All @@ -31,7 +34,7 @@ static const std::map<int, unsigned int> mapStakeModifierCheckpoints = {
{ 450000, 0xc85e93eau },
};

static const std::map<int, unsigned int> mapStakeModifierTestnetCheckpoints = {
static const std::unordered_map<int, unsigned int> mapStakeModifierTestnetCheckpoints = {
{ 0, 0x0e00670bu },
{ 50000, 0x4af2e306u },
{ 100000, 0xd9e06043u },
Expand Down Expand Up @@ -573,15 +576,10 @@ bool CheckStakeKernelHash(const unsigned int& nBits, const CBlockIndex* pindexPr
// nHashDrift should be <= MAX_FUTURE_BLOCK_TIME otherwise we risk creating a block which will be rejected due to nTimeTx being too far in the future
bool fSuccess = false;
unsigned int nTryTime = 0;
const int nHeightStart = nHeightCurrent - 1;
const int iteration = params.nStakeTimestampMask + 1; // 16 second time slots for 0xf masked time
assert((nHashDrift & params.nStakeTimestampMask) == 0);
for (int i = nHashDrift; i >= 0; i -= iteration) //iterate the hashing
{
// New block came in, move on
if (::ChainActive().Height() != nHeightStart)
break;

// Hash this iteration - start at nHashDrift and work backwards to nTimeTx
nTryTime = nTimeTx + i; //nTimeTx + nHashDrift - i;
hashProofOfStake = stakeHash(nTryTime, ss, prevout.n, prevout.hash, nTimeBlockFrom, true);
Expand Down Expand Up @@ -615,7 +613,7 @@ bool CheckStakeKernelHash(const unsigned int& nBits, const CBlockIndex* pindexPr
}

// Check kernel hash target and coinstake signature
bool CheckProofOfStake(BlockValidationState& state, const CCoinsViewCache& view, const CBlockIndex* pindexPrev, const CTransactionRef& tx, const unsigned int& nBits, unsigned int nTimeTx, uint256& hashProofOfStake)
bool CheckProofOfStake(BlockValidationState& state, const CCoinsViewCache& view, const CChain& active_chain, const CBlockIndex* pindexPrev, const CTransactionRef& tx, const unsigned int& nBits, unsigned int nTimeTx, uint256& hashProofOfStake)
{
if (!tx->IsCoinStake())
return error("CheckProofOfStake() : called on non-coinstake %s", tx->GetHash().ToString());
Expand All @@ -639,15 +637,15 @@ bool CheckProofOfStake(BlockValidationState& state, const CCoinsViewCache& view,

// Read txPrev and header of its block
//const CBlockIndex* pindexFrom = LookupBlockIndex(hashBlock);
const CBlockIndex* pindexFrom = ::ChainActive()[coin.nHeight];
const CBlockIndex* pindexFrom = active_chain[coin.nHeight];
if (!pindexFrom)
return error("CheckProofOfStake() : block index not found");

// Verify signature
{
int nIn = 0;
//const CTxOut& prevTxOut = txPrev->vout[tx->vin[nIn].prevout.n];
TransactionSignatureChecker checker(&(*tx), nIn, coin.out.nValue, &::ChainActive(), PrecomputedTransactionData(*tx));
TransactionSignatureChecker checker(&(*tx), nIn, coin.out.nValue, &active_chain, PrecomputedTransactionData(*tx));
ScriptError serror = SCRIPT_ERR_OK;

if (!VerifyScript(tx->vin[nIn].scriptSig, coin.out.scriptPubKey, &(tx->vin[nIn].scriptWitness), STANDARD_CONTEXTUAL_SCRIPT_VERIFY_FLAGS, checker, &serror))
Expand Down
5 changes: 3 additions & 2 deletions src/kernel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2012-2020 The Peercoin developers
// Copyright (c) 2015-2019 The PIVX developers
// Copyright (c) 2018-2021 John "ComputerCraftr" Studnicka
// Copyright (c) 2018-2022 John "ComputerCraftr" Studnicka
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

Expand All @@ -16,6 +16,7 @@ class CBlockIndex;
class BlockValidationState;
class CBlockHeader;
class CBlock;
class CChain;


// MODIFIER_INTERVAL_RATIO:
Expand All @@ -35,7 +36,7 @@ bool CheckStakeKernelHash(const unsigned int& nBits, const CBlockIndex* pindexPr

// Check kernel hash target and coinstake signature
// Sets hashProofOfStake on success return
bool CheckProofOfStake(BlockValidationState& state, const CCoinsViewCache& view, const CBlockIndex* pindexPrev, const CTransactionRef& tx, const unsigned int& nBits, unsigned int nTimeTx, uint256& hashProofOfStake);
bool CheckProofOfStake(BlockValidationState& state, const CCoinsViewCache& view, const CChain& active_chain, const CBlockIndex* pindexPrev, const CTransactionRef& tx, const unsigned int& nBits, unsigned int nTimeTx, uint256& hashProofOfStake);

// Check whether the coinstake timestamp meets protocol
bool CheckCoinStakeTimestamp(int64_t nTimeBlock, int64_t nTimeTx);
Expand Down
32 changes: 18 additions & 14 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@
static Mutex cs_thread_containers;
static std::list<std::pair<unsigned int, std::thread>> staking_threads GUARDED_BY(cs_thread_containers);
static std::list<CThreadInterrupt> staking_thread_interrupters GUARDED_BY(cs_thread_containers);

// Forward definition with thread safety annotations
// TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
// annotation "EXCLUSIVE_LOCKS_REQUIRED(cs_main, pwallet->cs_wallet)". The
// annotation "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid having
// to split BlockAssembler::CreateNewBlock into multiple different functions.
bool CreateCoinStake(CMutableTransaction& coinstakeTx, CBlock* pblock, const std::shared_ptr<CWallet>& pwallet, const CAmount& nFees, const int& nHeight, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams) NO_THREAD_SAFETY_ANALYSIS;
#endif // ENABLE_WALLET

int64_t nLastCoinStakeSearchInterval = 0;

int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
Expand Down Expand Up @@ -119,9 +127,9 @@ void BlockAssembler::resetBlock()
nFees = 0;
}

static inline void FillTreasuryPayee(CMutableTransaction& txNew, const int nHeight, const Consensus::Params& consensusParams)
static inline void FillTreasuryPayee(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams)
{
const CAmount nTreasuryPayment = GetTreasuryPayment(nHeight, consensusParams);
const CAmount nTreasuryPayment = GetTreasuryPayment(pindexPrev, consensusParams);

if (nTreasuryPayment > 0) {
const std::map<CScript, unsigned int>& treasuryPayees = consensusParams.mTreasuryPayees;
Expand All @@ -148,13 +156,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
return nullptr;
CBlock* const pblock = &pblocktemplate->block; // pointer for convenience

const bool fProofOfStake = pwallet != nullptr;

LOCK2(cs_main, m_mempool.cs);
CBlockIndex* pindexPrev = ::ChainActive().Tip();
assert(pindexPrev != nullptr);
nHeight = pindexPrev->nHeight + 1;

const Consensus::Params &consensusParams = chainparams.GetConsensus();
const bool fProofOfStake = pwallet != nullptr;

// Create coinbase transaction.
CMutableTransaction coinbaseTx;
Expand Down Expand Up @@ -247,8 +256,8 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
m_last_block_weight = nBlockWeight;

if (!fProofOfStake) {
coinbaseTx.vout[0].nValue = GetBlockSubsidy(nHeight, false, 0, consensusParams) + (chainparams.NetworkIDString() != CBaseChainParams::MAIN ? nFees / 2 : 0);
FillTreasuryPayee(coinbaseTx, nHeight, consensusParams);
coinbaseTx.vout[0].nValue = GetBlockSubsidy(nHeight, false, 0, pindexPrev->nMoneySupply, consensusParams) + (chainparams.NetworkIDString() != CBaseChainParams::MAIN ? nFees / 2 : 0);
FillTreasuryPayee(coinbaseTx, pindexPrev, consensusParams);
}
coinbaseTx.vin[0].scriptSig = CScript() << nHeight << OP_0;
pblocktemplate->entries[0].tx = MakeTransactionRef(std::move(coinbaseTx));
Expand Down Expand Up @@ -551,8 +560,6 @@ void IncrementExtraNonce(CBlock* pblock, const CBlockIndex* pindexPrev, unsigned
#ifdef ENABLE_WALLET
bool CreateCoinStake(CMutableTransaction& coinstakeTx, CBlock* pblock, const std::shared_ptr<CWallet>& pwallet, const CAmount& nFees, const int& nHeight, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams)
{
AssertLockHeld(pwallet->cs_wallet);

const int nTargetStakeInputs = gArgs.GetArg("-targetstakeinputs", DEFAULT_TARGET_STAKE_INPUTS);
constexpr CAmount nAutomaticInputSize = 2000000 * COIN;
bool fKernelFound = false;
Expand All @@ -565,9 +572,6 @@ bool CreateCoinStake(CMutableTransaction& coinstakeTx, CBlock* pblock, const std
CAmount nCredit = 0;
CScript scriptPubKeyKernel;
for (const auto& pcoin : setCoins) {
if (::ChainActive().Height() != pindexPrev->nHeight)
break;

CCoinsViewCache view(&::ChainstateActive().CoinsTip());
const COutPoint& prevout = pcoin.outpoint;
Coin coin;
Expand Down Expand Up @@ -727,10 +731,10 @@ bool CreateCoinStake(CMutableTransaction& coinstakeTx, CBlock* pblock, const std
LogPrintf("%s : added kernel type=%s\n", __func__, GetTxnOutputType(whichType));

uint64_t nCoinAge = 0;
if (!GetCoinAge((const CTransaction)coinstakeTx, view, pblock->nTime, nHeight, nCoinAge))
if (!GetCoinAge((const CTransaction)coinstakeTx, view, ::ChainActive(), pblock->nTime, nHeight, nCoinAge))
return error("%s : failed to calculate coin age", __func__);

const CAmount nReward = GetBlockSubsidy(nHeight, true, nCoinAge, consensusParams) + (Params().NetworkIDString() != CBaseChainParams::MAIN ? nFees / 2 : 0);
const CAmount nReward = GetBlockSubsidy(nHeight, true, nCoinAge, pindexPrev->nMoneySupply, consensusParams) + (Params().NetworkIDString() != CBaseChainParams::MAIN ? nFees / 2 : 0);
// Refuse to create mint that has zero or negative reward
if (nReward < 0)
return error("%s : not creating mint with negative subsidy", __func__);
Expand Down Expand Up @@ -762,7 +766,7 @@ bool CreateCoinStake(CMutableTransaction& coinstakeTx, CBlock* pblock, const std
}

// Add treasury payment
FillTreasuryPayee(coinstakeTx, nHeight, consensusParams);
FillTreasuryPayee(coinstakeTx, pindexPrev, consensusParams);

// Sign
if (!pwallet->SignTransaction(coinstakeTx))
Expand Down Expand Up @@ -875,7 +879,7 @@ static inline void PoSMiner(const std::shared_ptr<CWallet>& pwallet, CThreadInte
std::unique_ptr<CBlockTemplate> pblocktemplate;

{
LOCK(pwallet->cs_wallet);
LOCK(pwallet->cs_wallet); // Lock cs_wallet before cs_main in CreateNewBlock

pblocktemplate = BlockAssembler(*mempool, Params()).CreateNewBlock(CScript(), pwallet, &fPoSCancel);
}
Expand Down
1 change: 0 additions & 1 deletion src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
void RegenerateCommitments(CBlock& block);

#ifdef ENABLE_WALLET
bool CreateCoinStake(CMutableTransaction& coinstakeTx, CBlock* pblock, const std::shared_ptr<CWallet>& pwallet, const CAmount& nFees, const int& nHeight, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
unsigned int CreateStakingThread(const std::shared_ptr<CWallet>& pwallet, ChainstateManager* chainman, CConnman* connman, CTxMemPool* mempool);
void StopStakingThread(const unsigned int threadNum);
void StopStakingThreads();
Expand Down
Loading

0 comments on commit e22e39d

Please sign in to comment.