Skip to content
Draft
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
12 changes: 6 additions & 6 deletions contrib/testgen/gen_base58_test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from binascii import b2a_hex

# key types
PUBKEY_ADDRESS = 76
SCRIPT_ADDRESS = 16
PUBKEY_ADDRESS_TEST = 140
SCRIPT_ADDRESS_TEST = 19
PRIVKEY = 204
PRIVKEY_TEST = 239
PUBKEY_ADDRESS = 30
SCRIPT_ADDRESS = 10
PUBKEY_ADDRESS_TEST = 30
SCRIPT_ADDRESS_TEST = 10
PRIVKEY = 140
PRIVKEY_TEST = 158

metadata_keys = ['isPrivkey', 'isTestnet', 'addrType', 'isCompressed']
# templates for valid sequences
Expand Down
8 changes: 4 additions & 4 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class CMainParams : public CChainParams
startNewChain = false;
nSwitchDifficultyBlock = 795350; // approx: September 22, 2021

genesis = CreateGenesisBlock(1513619300, 626614, UintToArith256(consensus.powLimit).GetCompact(), 1, (1 * COIN));
genesis = CreateGenesisBlock(1513619300, 626614, 0x1e0fffff, 1, (1 * COIN));
if (startNewChain == true) {
MineGenesis(genesis, consensus.powLimit, true);
}
Expand Down Expand Up @@ -346,7 +346,7 @@ class CTestNetParams : public CChainParams
startNewChain = false;
nSwitchDifficultyBlock = 5000; // ~ 1 week

genesis = CreateGenesisBlock(1515641597, 747, UintToArith256(consensus.powLimit).GetCompact(), 1, (1 * COIN));
genesis = CreateGenesisBlock(1515641597, 747, 0x2000ffff, 1, (1 * COIN));
if (startNewChain == true) {
MineGenesis(genesis, consensus.powLimit, true);
}
Expand Down Expand Up @@ -480,7 +480,7 @@ class CRegTestParams : public CChainParams
startNewChain = false;
nSwitchDifficultyBlock = 500;

genesis = CreateGenesisBlock(1513619951, 1754, UintToArith256(consensus.powLimit).GetCompact(), 1, (1 * COIN));
genesis = CreateGenesisBlock(1513619951, 1754, 0x1f0fffff, 1, (1 * COIN));
if (startNewChain == true) {
MineGenesis(genesis, consensus.powLimit, true);
}
Expand Down Expand Up @@ -609,7 +609,7 @@ class CPrivateNetParams : public CChainParams
startNewChain = false;
nSwitchDifficultyBlock = 500000;

genesis = CreateGenesisBlock(1559867972, 60883, UintToArith256(consensus.powLimit).GetCompact(), 1, (1 * COIN));
genesis = CreateGenesisBlock(1559867972, 60883, 0x1f00ffff, 1, (1 * COIN));
if (startNewChain == true) {
MineGenesis(genesis, consensus.powLimit, true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/dynode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void CDynodePayments::FillBlockPayee(CMutableTransaction& txNew, int nBlockHeigh

// make sure it's not filled yet
txoutDynodeRet = CTxOut();
CAmount dynodePayment = GetFluidDynodeReward(nBlockHeight);
CAmount dynodePayment = GetFluidDynodeReward(nBlockHeight, Params().GetConsensus());

// split reward between miner ...
txoutDynodeRet = CTxOut(dynodePayment, payee);
Expand Down Expand Up @@ -593,7 +593,7 @@ bool CDynodeBlockPayees::IsTransactionValid(const CTransaction& txNew, const int

int nMaxSignatures = 0;
std::string strPayeesPossible = "";
CAmount nDynodePayment = GetFluidDynodeReward(nHeight);
CAmount nDynodePayment = GetFluidDynodeReward(nHeight, Params().GetConsensus());

//require at least DNPAYMENTS_SIGNATURES_REQUIRED signatures

Expand Down
2 changes: 1 addition & 1 deletion src/dynode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void CDynode::UpdateLastPaid(const CBlockIndex* pindex, int nMaxBlocksToScanBack
if (!ReadBlockFromDisk(block, BlockReading, Params().GetConsensus())) // shouldn't really happen
continue;

CAmount nDynodePayment = GetFluidDynodeReward(BlockReading->nHeight);
CAmount nDynodePayment = GetFluidDynodeReward(BlockReading->nHeight, Params().GetConsensus());

for (const auto& txout : block.vtx[0]->vout)
if (dnpayee == txout.scriptPubKey && nDynodePayment == txout.nValue) {
Expand Down
18 changes: 9 additions & 9 deletions src/fluid/fluid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ bool CFluid::ParseMintKey(const int64_t& nTime, CDynamicAddress& destination, CA
return true;
}

bool GetFluidBlock(const CBlockIndex* pblockindex, CBlock& block)
bool GetFluidBlock(const CBlockIndex* pblockindex, CBlock& block, const Consensus::Params& consensusParams)
{
if (pblockindex != nullptr) {
// Check for invalid block position and file.
const CDiskBlockPos pos = pblockindex->GetBlockPos();
if (pos.nFile > -1 && pos.nPos > 0) {
if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) {
if (!ReadBlockFromDisk(block, pblockindex, consensusParams)) {
LogPrintf("Unable to read from disk! Highly unlikely but has occured, may be bug or damaged blockchain copy!\n");
return false;
}
Expand All @@ -502,10 +502,10 @@ bool GetFluidBlock(const CBlockIndex* pblockindex, CBlock& block)
return true;
}

bool CFluid::GetMintingInstructions(const CBlockIndex* pblockindex, CDynamicAddress& toMintAddress, CAmount& mintAmount)
bool CFluid::GetMintingInstructions(const CBlockIndex* pblockindex, CDynamicAddress& toMintAddress, CAmount& mintAmount, const Consensus::Params& consensusParams)
{
CBlock block;
if (GetFluidBlock(pblockindex, block)) {
if (GetFluidBlock(pblockindex, block, consensusParams)) {
for (const CTransactionRef& tx : block.vtx) {
for (const CTxOut& txout : tx->vout) {
if (txout.scriptPubKey.IsProtocolInstruction(MINT_TX)) {
Expand Down Expand Up @@ -542,25 +542,25 @@ bool CFluid::CheckTransactionInRecord(const CScript& fluidInstruction, CBlockInd
return false;
}

CAmount GetStandardPoWBlockPayment(const int& nHeight)
CAmount GetStandardPoWBlockPayment(const int& nHeight, const Consensus::Params& consensusParams)
{
if (nHeight == 1) {
CAmount nSubsidy = INITIAL_SUPERBLOCK_PAYMENT;
LogPrint("superblock creation", "GetStandardPoWBlockPayment() : create=%s nSubsidy=%d\n", FormatMoney(nSubsidy), nSubsidy);
return nSubsidy;
} else if (nHeight > 1 && nHeight <= Params().GetConsensus().nRewardsStart) {
} else if (nHeight > 1 && nHeight <= consensusParams.nRewardsStart) {
LogPrint("zero-reward block creation", "GetStandardPoWBlockPayment() : create=%s nSubsidy=%d\n", FormatMoney(BLOCKCHAIN_INIT_REWARD), BLOCKCHAIN_INIT_REWARD);
return BLOCKCHAIN_INIT_REWARD; // Burn transaction fees
} else if (nHeight > Params().GetConsensus().nRewardsStart) {
} else if (nHeight > consensusParams.nRewardsStart) {
LogPrint("creation", "GetStandardPoWBlockPayment() : create=%s PoW Reward=%d\n", FormatMoney(PHASE_1_POW_REWARD), PHASE_1_POW_REWARD);
return PHASE_1_POW_REWARD; // 1 DYN and burn transaction fees
} else
return BLOCKCHAIN_INIT_REWARD; // Burn transaction fees
}

CAmount GetStandardDynodePayment(const int& nHeight)
CAmount GetStandardDynodePayment(const int& nHeight, const Consensus::Params& consensusParams)
{
if (nHeight > Params().GetConsensus().nDynodePaymentsStartBlock) {
if (nHeight > consensusParams.nDynodePaymentsStartBlock) {
LogPrint("fluid", "GetStandardDynodePayment() : create=%s DN Payment=%d\n", FormatMoney(PHASE_2_DYNODE_PAYMENT), PHASE_2_DYNODE_PAYMENT);
return PHASE_2_DYNODE_PAYMENT; // 1.618 DYN
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/fluid/fluid.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CFluid : public CFluidParameters, public COperations
bool ParseMintKey(const int64_t& nTime, CDynamicAddress& destination, CAmount& coinAmount, const std::string& uniqueIdentifier, const bool txCheckPurpose = false);
bool ProcessFluidToken(const std::string& consentToken, std::vector<std::string>& ptrs, const int& strVecNo);

bool GetMintingInstructions(const CBlockIndex* pblockindex, CDynamicAddress& toMintAddress, CAmount& mintAmount);
bool GetMintingInstructions(const CBlockIndex* pblockindex, CDynamicAddress& toMintAddress, CAmount& mintAmount, const Consensus::Params& consensusParams);
bool ValidationProcesses(CValidationState& state, const CScript& txOut, const CAmount& txValue);

bool CheckTransactionToBlock(const CTransaction& transaction, const CBlockHeader& blockHeader);
Expand All @@ -77,8 +77,8 @@ class CFluid : public CFluidParameters, public COperations
};

/** Standard Reward Payment Determination Functions */
CAmount GetStandardPoWBlockPayment(const int& nHeight);
CAmount GetStandardDynodePayment(const int& nHeight);
CAmount GetStandardPoWBlockPayment(const int& nHeight, const Consensus::Params& consensusParams);
CAmount GetStandardDynodePayment(const int& nHeight, const Consensus::Params& consensusParams);

void BuildFluidInformationIndex(CBlockIndex* pindex, CAmount& nExpectedBlockValue, bool fDynodePaid);
bool IsTransactionFluid(const CScript& txOut);
Expand All @@ -88,7 +88,7 @@ int GetFluidOpCode(const CScript& fluidScript);
std::vector<unsigned char> CharVectorFromString(const std::string& str);
std::string StringFromCharVector(const std::vector<unsigned char>& vch);
std::vector<unsigned char> FluidScriptToCharVector(const CScript& fluidScript);
bool GetFluidBlock(const CBlockIndex* pblockindex, CBlock& block);
bool GetFluidBlock(const CBlockIndex* pblockindex, CBlock& block, const Consensus::Params& consensusParams);

extern CFluid fluid;

Expand Down
24 changes: 12 additions & 12 deletions src/fluid/fluiddb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,47 @@
#include "fluidmint.h"
#include "fluidsovereign.h"

CAmount GetFluidDynodeReward(const int nHeight)
CAmount GetFluidDynodeReward(const int nHeight, const Consensus::Params& consensusParams)
{
if (fluid.FLUID_ACTIVATE_HEIGHT > nHeight)
return GetStandardDynodePayment(nHeight);
return GetStandardDynodePayment(nHeight, consensusParams);

if (!CheckFluidDynodeDB())
return GetStandardDynodePayment(nHeight);
return GetStandardDynodePayment(nHeight, consensusParams);

if (pFluidDynodeDB->IsEmpty())
return GetStandardDynodePayment(nHeight);
return GetStandardDynodePayment(nHeight, consensusParams);

CFluidDynode lastDynodeRecord;
if (!pFluidDynodeDB->GetLastFluidDynodeRecord(lastDynodeRecord, nHeight)) {
return GetStandardDynodePayment(nHeight);
return GetStandardDynodePayment(nHeight, consensusParams);
}
if (lastDynodeRecord.DynodeReward > 0) {
return lastDynodeRecord.DynodeReward;
} else {
return GetStandardDynodePayment(nHeight);
return GetStandardDynodePayment(nHeight, consensusParams);
}
}

CAmount GetFluidMiningReward(const int nHeight)
CAmount GetFluidMiningReward(const int nHeight, const Consensus::Params& consensusParams)
{
if (fluid.FLUID_ACTIVATE_HEIGHT > nHeight)
return GetStandardPoWBlockPayment(nHeight);
return GetStandardPoWBlockPayment(nHeight, consensusParams);

if (!CheckFluidMiningDB())
return GetStandardPoWBlockPayment(nHeight);
return GetStandardPoWBlockPayment(nHeight, consensusParams);

if (pFluidMiningDB->IsEmpty())
return GetStandardPoWBlockPayment(nHeight);
return GetStandardPoWBlockPayment(nHeight, consensusParams);

CFluidMining lastMiningRecord;
if (!pFluidMiningDB->GetLastFluidMiningRecord(lastMiningRecord, nHeight)) {
return GetStandardPoWBlockPayment(nHeight);
return GetStandardPoWBlockPayment(nHeight, consensusParams);
}
if (lastMiningRecord.MiningReward > 0) {
return lastMiningRecord.MiningReward;
} else {
return GetStandardPoWBlockPayment(nHeight);
return GetStandardPoWBlockPayment(nHeight, consensusParams);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/fluid/fluiddb.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
#define FLUID_DB_H

#include "amount.h"
#include "consensus/params.h"

class CDynamicAddress;
class CFluidDynode;
class CFluidMining;
class CFluidMint;
class CFluidSovereign;

CAmount GetFluidDynodeReward(const int nHeight);
CAmount GetFluidMiningReward(const int nHeight);
CAmount GetFluidDynodeReward(const int nHeight, const Consensus::Params& consensusParams);
CAmount GetFluidMiningReward(const int nHeight, const Consensus::Params& consensusParams);
bool GetMintingInstructions(const int nHeight, CFluidMint& fluidMint);
bool IsSovereignAddress(const CDynamicAddress& inputAddress);
bool GetAllFluidDynodeRecords(std::vector<CFluidDynode>& dynodeEntries);
Expand Down
26 changes: 9 additions & 17 deletions src/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,14 @@ void BIP32Hash(const ChainCode& chainCode, unsigned int nChild, unsigned char he

#define ROTL(x, b) (uint64_t)(((x) << (b)) | ((x) >> (64 - (b))))

#define SIPROUND \
do { \
v0 += v1; \
v1 = ROTL(v1, 13); \
v1 ^= v0; \
v0 = ROTL(v0, 32); \
v2 += v3; \
v3 = ROTL(v3, 16); \
v3 ^= v2; \
v0 += v3; \
v3 = ROTL(v3, 21); \
v3 ^= v0; \
v2 += v1; \
v1 = ROTL(v1, 17); \
v1 ^= v2; \
v2 = ROTL(v2, 32); \
} while (0)
#define SIPROUND do { \
v0 += v1; v1 = ROTL(v1, 13); v1 ^= v0; \
v0 = ROTL(v0, 32); \
v2 += v3; v3 = ROTL(v3, 16); v3 ^= v2; \
v0 += v3; v3 = ROTL(v3, 21); v3 ^= v0; \
v2 += v1; v1 = ROTL(v1, 17); v1 ^= v2; \
v2 = ROTL(v2, 32); \
} while (0)

CSipHasher::CSipHasher(uint64_t k0, uint64_t k1)
{
Expand All @@ -113,6 +104,7 @@ CSipHasher::CSipHasher(uint64_t k0, uint64_t k1)
v[2] = 0x6c7967656e657261ULL ^ k0;
v[3] = 0x7465646279746573ULL ^ k1;
count = 0;
tmp = 0;
}

CSipHasher& CSipHasher::Write(uint64_t data)
Expand Down
2 changes: 1 addition & 1 deletion src/miner/miner-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ std::unique_ptr<CBlockTemplate> CreateNewBlock(const CChainParams& chainparams,
}
}

CAmount blockReward = GetFluidMiningReward(nHeight);
CAmount blockReward = GetFluidMiningReward(nHeight, chainparams.GetConsensus());
CDynamicAddress mintAddress;
CAmount fluidIssuance = 0;
CFluidMint fluidMint;
Expand Down
4 changes: 2 additions & 2 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&

// Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
return error("CheckProofOfWork(): nBits below minimum work");
return error("CheckProofOfWork(): nBits below minimum work, nBits: 0x%x, minWork: 0x%x", bnTarget.GetCompact(), UintToArith256(params.powLimit).GetCompact());

// Check proof of work matches claimed amount
if (UintToArith256(hash) > bnTarget)
return error("CheckProofOfWork(): hash doesn't match nBits");
return error("CheckProofOfWork(): hash doesn't match nBits, hash: 0x%x, bnTarget: 0x%x", UintToArith256(hash).GetCompact(), bnTarget.GetCompact());

return true;
}
8 changes: 4 additions & 4 deletions src/rpc/fluid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,10 @@ UniValue getfluidhistoryraw(const JSONRPCRequest& request)
obj.push_back(Pair("total_minted", FormatMoney(totalMintedCoins)));
obj.push_back(Pair("total_fluid_fee_cost", FormatMoney(totalFluidTxCost)));

CAmount dynodeReward = GetFluidDynodeReward(chainActive.Tip()->nHeight);
CAmount dynodeReward = GetFluidDynodeReward(chainActive.Tip()->nHeight, Params().GetConsensus());
obj.push_back(Pair("current_dynode_reward", FormatMoney(dynodeReward)));

CAmount miningAmount = GetFluidMiningReward(chainActive.Tip()->nHeight);
CAmount miningAmount = GetFluidMiningReward(chainActive.Tip()->nHeight, Params().GetConsensus());
obj.push_back(Pair("current_mining_reward", FormatMoney(miningAmount)));

obj.push_back(Pair("total_fluid_transactions", nTotal));
Expand Down Expand Up @@ -621,10 +621,10 @@ UniValue getfluidhistory(const JSONRPCRequest& request)
obj.push_back(Pair("total_minted", FormatMoney(totalMintedCoins)));
obj.push_back(Pair("total_fluid_fee_cost", FormatMoney(totalFluidTxCost)));

CAmount dynodeReward = GetFluidDynodeReward(chainActive.Tip()->nHeight);
CAmount dynodeReward = GetFluidDynodeReward(chainActive.Tip()->nHeight, Params().GetConsensus());
obj.push_back(Pair("current_dynode_reward", FormatMoney(dynodeReward)));

CAmount miningAmount = GetFluidMiningReward(chainActive.Tip()->nHeight);
CAmount miningAmount = GetFluidMiningReward(chainActive.Tip()->nHeight, Params().GetConsensus());
obj.push_back(Pair("current_mining_reward", FormatMoney(miningAmount)));

obj.push_back(Pair("total_fluid_transactions", nTotal));
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request)
CScript scriptMint;
if (areWeMinting) {
// Add minting output to superblock payments
CAmount fluidIssuance = nCoinbaseValue - GetFluidDynodeReward(nHeight) - GetFluidMiningReward(nHeight);
CAmount fluidIssuance = nCoinbaseValue - GetFluidDynodeReward(nHeight, Params().GetConsensus()) - GetFluidMiningReward(nHeight, Params().GetConsensus());
if (fluidIssuance > 0) {
UniValue entry(UniValue::VOBJ);
CDynamicAddress mintAddress = fluidMint.GetDestinationAddress();
Expand Down Expand Up @@ -1150,7 +1150,7 @@ UniValue getsubsidy(const JSONRPCRequest& request)
if (nHeight < 0)
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");

return (uint64_t)GetFluidDynodeReward(nHeight) + GetFluidMiningReward(nHeight);
return (uint64_t)GetFluidDynodeReward(nHeight, Params().GetConsensus()) + GetFluidMiningReward(nHeight, Params().GetConsensus());
}

static const CRPCCommand commands[] =
Expand Down
6 changes: 3 additions & 3 deletions src/test/addrman_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ BOOST_AUTO_TEST_CASE(addrman_select)
BOOST_CHECK(addrman.size() == 7);

// Test 12: Select pulls from new and tried regardless of port number.
BOOST_CHECK(addrman.Select().ToString() == "250.4.6.6:8333");
BOOST_CHECK(addrman.Select().ToString() == "250.1.1.1:8333");
BOOST_CHECK(addrman.Select().ToString() == "250.3.2.2:33300");
BOOST_CHECK(addrman.Select().ToString() == "250.3.3.3:33300");
BOOST_CHECK(addrman.Select().ToString() == "250.4.4.4:8333");
BOOST_CHECK(addrman.Select().ToString() == "250.3.1.1:8333");
BOOST_CHECK(addrman.Select().ToString() == "250.1.1.1:8333");
}

BOOST_AUTO_TEST_CASE(addrman_new_collisions)
Expand Down
2 changes: 2 additions & 0 deletions src/test/alert_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <boost/foreach.hpp>
#include <boost/test/unit_test.hpp>

#ifdef ENABLE_ALERT_TESTS
//
// Sign a CAlert and serialize it
//
Expand Down Expand Up @@ -234,3 +235,4 @@ BOOST_AUTO_TEST_CASE(AlertNotify)
}

BOOST_AUTO_TEST_SUITE_END()
#endif // ENABLE_ALERT_TESTS
Loading