Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port major consensus rules from ldoge into peercoin #1

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ crypto_libbitcoin_crypto_base_la_SOURCES = \
crypto/muhash.cpp \
crypto/ripemd160.cpp \
crypto/ripemd160.h \
crypto/scrypt.cpp \
crypto/scrypt.h \
crypto/sha1.cpp \
crypto/sha1.h \
crypto/sha256.cpp \
Expand Down
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;
}
25 changes: 11 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 @@ -327,6 +322,11 @@ class CBlockIndex
return *phashBlock;
}

uint256 GetBlockPoWHash() const
{
return GetBlockHeader().GetPoWHash();
}

/**
* Check whether this block's and all previous blocks' transactions have been
* downloaded (and stored to disk) at some point.
Expand Down Expand Up @@ -512,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
28 changes: 15 additions & 13 deletions src/chainparamsseeds.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@
* 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,0x89,0xb8,0x2d,0x9b,0x42,0x76,
0x01,0x04,0x8f,0xf4,0xd1,0xa2,0x42,0x76,
0x01,0x04,0xb9,0x06,0x7b,0x84,0x42,0x76,
0x01,0x04,0xd9,0xf1,0x37,0xfb,0x42,0x76,
0x01,0x04,0x29,0x81,0x06,0x1d,0x42,0x76,
0x01,0x04,0x2d,0xf3,0xb7,0xf9,0x42,0x76,
0x01,0x04,0x2d,0xf3,0xbb,0x64,0x42,0x76,
0x01,0x04,0x2d,0xf3,0xc8,0xca,0x42,0x76,
0x01,0x04,0x2d,0xf3,0x3e,0xad,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,0x46,0x10,0x2a,0x69,0x42,0x76,
0x01,0x04,0x47,0x54,0x17,0x84,0x42,0x76,
0x01,0x04,0x55,0xa6,0x3c,0xdb,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
Loading