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 12, 2023
1 parent 5b4f4d1 commit 1742f86
Show file tree
Hide file tree
Showing 22 changed files with 228 additions and 399 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;
}
11 changes: 3 additions & 8 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
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
4 changes: 2 additions & 2 deletions src/consensus/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
/** 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;
Expand Down
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
12 changes: 10 additions & 2 deletions src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,22 @@ 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 nFee = (GetMinFee(tx, nTimeTx) < PERKB_TX_FEE) ? 0 : (GetMinFee(tx, nTimeTx) - PERKB_TX_FEE);
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)
CAmount nExpectedStakeReward = GetProofOfStakeReward(nCoinAge, nFee);
if (nMoneySupply && nStakeReward > nExpectedStakeReward) {
LogPrintf("expected %llu found %llu\n", nExpectedStakeReward, nStakeReward);
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-coinstake-too-large");
}
*/
}
else
{
Expand Down
Loading

0 comments on commit 1742f86

Please sign in to comment.