Skip to content

Commit

Permalink
consensus: update main consensus/hashing rules
Browse files Browse the repository at this point in the history
  • Loading branch information
barrystyle committed Dec 18, 2023
1 parent 5b4f4d1 commit c5a9f39
Show file tree
Hide file tree
Showing 22 changed files with 260 additions and 437 deletions.
2 changes: 1 addition & 1 deletion src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ const CBlockIndex* LastCommonAncestor(const CBlockIndex* pa, const CBlockIndex*
// peercoin: find last block index up to pindex
const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfStake)
{
while (pindex && pindex->pprev && (pindex->IsProofOfStake() != fProofOfStake))
while (pindex && pindex->pprev && ((pindex->nNonce == 0) != fProofOfStake))
pindex = pindex->pprev;
return pindex;
}
20 changes: 6 additions & 14 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,17 @@ class CBlockIndex

bool IsProofOfWork() const
{
return !(nFlags & BLOCK_PROOF_OF_STAKE);
return !IsProofOfStake();
}

bool IsProofOfStake() const
{
return (nFlags & BLOCK_PROOF_OF_STAKE);
}

void SetProofOfStake()
{
nFlags |= BLOCK_PROOF_OF_STAKE;
return nNonce == 0;
}

unsigned int GetStakeEntropyBit() const
{
return ((nFlags & BLOCK_STAKE_ENTROPY) >> 1);
return ((GetBlockHash().GetLow64()) & 1llu);
}

bool SetStakeEntropyBit(unsigned int nEntropyBit)
Expand Down Expand Up @@ -517,12 +512,9 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(obj.nMoneySupply);
READWRITE(obj.nFlags);
READWRITE(obj.nStakeModifier);
if (obj.nFlags & BLOCK_PROOF_OF_STAKE)
{
READWRITE(obj.prevoutStake);
READWRITE(obj.nStakeTime);
READWRITE(obj.hashProofOfStake);
}
READWRITE(obj.prevoutStake);
READWRITE(obj.nStakeTime);
READWRITE(obj.hashProofOfStake);

// block header
READWRITE(obj.nVersion);
Expand Down
26 changes: 13 additions & 13 deletions src/chainparamsseeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
* Each line contains a BIP155 serialized (networkID, addr, port) tuple.
*/
static const uint8_t chainparams_seed_main[] = {
0x01,0x04,0x87,0xb5,0xa4,0xbd,0x26,0xad,
0x01,0x04,0x57,0x62,0xb9,0xf4,0x26,0xad,
0x01,0x04,0x8b,0x3b,0x81,0xb3,0x26,0xad,
0x01,0x04,0x2f,0xce,0x58,0x12,0x26,0xad,
0x01,0x04,0x05,0x80,0x57,0x7e,0x26,0xad,
0x01,0x04,0xd5,0x9f,0x51,0xe5,0x26,0xad,
0x01,0x04,0x2e,0x65,0x4b,0x98,0x26,0xad,
0x01,0x04,0xb2,0x72,0xe9,0x28,0x26,0xad,
0x01,0x04,0x80,0xc7,0x28,0x23,0x26,0xad,
0x01,0x04,0x44,0xb7,0xcf,0xaf,0x26,0xad,
0x01,0x04,0xbc,0xa6,0x0c,0x61,0x26,0xad,
0x01,0x04,0x9f,0x45,0x25,0x11,0x26,0xad,
0x01,0x04,0x4a,0x2c,0xcf,0xa3,0x26,0xad,
0x01,0x04,0xad,0x45,0x86,0xfa,0x42,0x76,
0x01,0x04,0xb8,0x67,0x55,0xe0,0x42,0x76,
0x01,0x04,0xbd,0xa5,0xe1,0x8c,0x42,0x76,
0x01,0x04,0x18,0x87,0x04,0xca,0x42,0x76,
0x01,0x04,0x41,0x6d,0x1f,0xbb,0x42,0x76,
0x01,0x04,0x5f,0xd9,0x4d,0xd1,0x42,0x76,
0x01,0x04,0x89,0xb8,0x2d,0x9b,0x42,0x76,
0x01,0x04,0x8f,0xf4,0xd1,0xa2,0x42,0x76,
0x01,0x04,0x05,0xb4,0x19,0x56,0x42,0x76,
0x01,0x04,0x05,0xb4,0x19,0x57,0x42,0x76,
0x01,0x04,0x42,0x81,0x9c,0xb3,0x42,0x76,
0x01,0x04,0x52,0x12,0xd1,0xf1,0x42,0x76,
0x01,0x04,0x55,0xa6,0x1c,0x37,0x42,0x76,
};

static const uint8_t chainparams_seed_test[] = {
Expand Down
9 changes: 5 additions & 4 deletions src/consensus/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
#define BITCOIN_CONSENSUS_AMOUNT_H

#include <cstdint>
#include <limits>
#include <string>

/** Amount in satoshis (Can be negative) */
typedef int64_t CAmount;

static constexpr CAmount COIN = 1000000;
static constexpr CAmount CENT = 10000;
static constexpr CAmount COIN = 100000000;
static constexpr CAmount CENT = 1000000;

static const CAmount MIN_TX_FEE_PREV7 = CENT;
static const CAmount MIN_TX_FEE = CENT / 10;
static const CAmount PERKB_TX_FEE = CENT;
static const CAmount MIN_TXOUT_AMOUNT = CENT;
static const CAmount MAX_MINT_PROOF_OF_WORK = 9999 * COIN;
static const CAmount MAX_MINT_PROOF_OF_WORK_V10 = 50 * COIN;
static const std::string CURRENCY_UNIT = "PPC";
static const std::string CURRENCY_UNIT = "LDOGE";
static const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value unit

/** No amount larger than this (in satoshi) is valid.
Expand All @@ -33,7 +34,7 @@ static const std::string CURRENCY_ATOM = "sat"; // One indivisible minimum value
* critical; in unusual circumstances like a(nother) overflow bug that allowed
* for the creation of coins out of thin air modification could lead to a fork.
* */
static constexpr CAmount MAX_MONEY = 21000000 * COIN;
static constexpr CAmount MAX_MONEY = std::numeric_limits<int64_t>::max();
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

#endif // BITCOIN_CONSENSUS_AMOUNT_H
7 changes: 4 additions & 3 deletions src/consensus/tx_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ bool CheckTransaction(const CTransaction& tx, TxValidationState& state)
nValueOut += txout.nValue;
if (!MoneyRange(nValueOut))
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-txouttotal-toolarge");

// peercoin: enforce minimum output amount
if ((!txout.IsEmpty()) && txout.nValue < MIN_TXOUT_AMOUNT &&
(tx.nVersion < 3 && !(IsZeroAllowed(tx.nTime) && (txout.nValue == 0))))
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-txoutvalue-belowminimum");
//if ((!txout.IsEmpty()) && txout.nValue < MIN_TXOUT_AMOUNT &&
// (tx.nVersion < 3 && !(IsZeroAllowed(tx.nTime) && (txout.nValue == 0))))
// return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-txoutvalue-belowminimum");
}

// Check for duplicate inputs (see CVE-2018-17144)
Expand Down
16 changes: 4 additions & 12 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,10 @@ bool Consensus::CheckTxInputs(const CTransaction& tx, TxValidationState& state,
}
}

if (tx.IsCoinStake())
{
// peercoin: coin stake tx earns reward instead of paying fee
uint64_t nCoinAge;
if (!GetCoinAge(tx, inputs, nCoinAge, nTimeTx))
return state.Invalid(TxValidationResult::TX_CONSENSUS, "unable to get coin age for coinstake");
CAmount nStakeReward = tx.GetValueOut() - nValueIn;
CAmount nCoinstakeCost = (GetMinFee(tx, nTimeTx) < PERKB_TX_FEE) ? 0 : (GetMinFee(tx, nTimeTx) - PERKB_TX_FEE);
if (nMoneySupply && nStakeReward > GetProofOfStakeReward(nCoinAge, nTimeTx, nMoneySupply) - nCoinstakeCost)
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-coinstake-too-large");
}
else
// stake amount validation has been moved to validation.cpp/ConnectBlock as LiteDoge's
// functions arent purely contextual (height)

if (!tx.IsCoinStake())
{
const CAmount value_out = tx.GetValueOut();
if (nValueIn < value_out) {
Expand Down
Loading

0 comments on commit c5a9f39

Please sign in to comment.