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

[Tests] Resurrect feature_block and kill the p2p comparison test framework #2360

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b2410ae
[BUG] Fix assertion in error in assert_debug_log
random-zebra May 2, 2021
bd6e591
[Refactoring] remove SaplingActive check in GUI/RPC
random-zebra May 3, 2021
9d552f9
[Refactor][Tests] Do not change chain when not needed
random-zebra May 3, 2021
f5f72ca
[Trivial] Update some state logs (tx oversize and inputs missing/spent)
random-zebra May 2, 2021
0b670c8
[BUG] Properly recompute coinbase and sapling root hash in CreateBlock
random-zebra May 3, 2021
44a1c44
[Refactor] Option to mine mempool txes in TestChainSetup::CreateBlock
random-zebra May 3, 2021
4cf7222
[Tests] Refactor wallet_sapling_transactions_validations_tests
random-zebra May 3, 2021
93fcc2e
[Params] Fix regtest coinbase - mine it with lower diff
random-zebra May 2, 2021
d0777a7
[Refactoring] Add fPowNoRetargeting consensus param + fix regtest diff
random-zebra Apr 30, 2021
810a880
[Tests] Update PIVX specific constants bits/block-size/block-version
random-zebra May 2, 2021
b19bee9
[Refactoring][BUG] Never change chain-params after setup in unit tests
random-zebra May 3, 2021
0f0c97c
[BUG] Fix block with invalid PoW in zerocoin_rejection_tests
random-zebra May 5, 2021
030517b
[Refactoring] pass next block height to IncrementExtraNonce
random-zebra May 5, 2021
77645bf
[BUG][Tests] Add on_getblocks to P2PDataStore interface
random-zebra May 3, 2021
3633e42
[Tests] Fix and resurrect feature_block.py
random-zebra May 2, 2021
fcda6cc
[QA][Cleanup] Retire the Comparison Test Framework
random-zebra May 3, 2021
48e5d54
[Tests][Refactoring] Remove 'magic bytes' in p2p_invalid_* tests
random-zebra May 5, 2021
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
14 changes: 12 additions & 2 deletions src/blockassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,18 @@ uint256 CalculateSaplingTreeRoot(CBlock* pblock, int nHeight, const CChainParams
return UINT256_ZERO;
}

void IncrementExtraNonce(std::shared_ptr<CBlock>& pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce)
bool SolveBlock(std::shared_ptr<CBlock>& pblock, int nHeight)
{
unsigned int extraNonce = 0;
IncrementExtraNonce(pblock, nHeight, extraNonce);
while (pblock->nNonce < std::numeric_limits<uint32_t>::max() &&
!CheckProofOfWork(pblock->GetHash(), pblock->nBits)) {
++pblock->nNonce;
}
return pblock->nNonce != std::numeric_limits<uint32_t>::max();
}

void IncrementExtraNonce(std::shared_ptr<CBlock>& pblock, int nHeight, unsigned int& nExtraNonce)
{
// Update nExtraNonce
static uint256 hashPrevBlock;
Expand All @@ -492,7 +503,6 @@ void IncrementExtraNonce(std::shared_ptr<CBlock>& pblock, const CBlockIndex* pin
hashPrevBlock = pblock->hashPrevBlock;
}
++nExtraNonce;
unsigned int nHeight = pindexPrev->nHeight + 1; // Height first in coinbase required for block.version=2
CMutableTransaction txCoinbase(*pblock->vtx[0]);
txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
assert(txCoinbase.vin[0].scriptSig.size() <= 100);
Expand Down
5 changes: 3 additions & 2 deletions src/blockassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ class BlockAssembler
bool isStillDependent(CTxMemPool::txiter iter);
};

/** Modify the extranonce in a block */
void IncrementExtraNonce(std::shared_ptr<CBlock>& pblock, const CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
/** Modify the nonce/extranonce in a block */
bool SolveBlock(std::shared_ptr<CBlock>& pblock, int nHeight);
void IncrementExtraNonce(std::shared_ptr<CBlock>& pblock, int nHeight, unsigned int& nExtraNonce);
int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev);
int32_t ComputeBlockVersion(const Consensus::Params& consensusParams, int nHeight);

Expand Down
9 changes: 6 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class CMainParams : public CChainParams
assert(genesis.hashMerkleRoot == uint256S("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b"));

consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.powLimit = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimitV1 = uint256S("0x000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimitV2 = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
Expand Down Expand Up @@ -275,6 +276,7 @@ class CTestNetParams : public CChainParams
assert(genesis.hashMerkleRoot == uint256S("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b"));

consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowNoRetargeting = false;
consensus.powLimit = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimitV1 = uint256S("0x000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimitV2 = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
Expand Down Expand Up @@ -393,13 +395,14 @@ class CRegTestParams : public CChainParams
{
strNetworkID = "regtest";

genesis = CreateGenesisBlock(1454124731, 2402015, 0x1e0ffff0, 1, 250 * COIN);
genesis = CreateGenesisBlock(1454124731, 1, 0x207fffff, 1, 250 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x0000041e482b9b9691d98eefb48473405c0b8ec31b76df3797c74a78680ef818"));
assert(consensus.hashGenesisBlock == uint256S("0x7445589c4c8e52b105247b13373e5ee325856aa05d53f429e59ea46b7149ae3f"));
assert(genesis.hashMerkleRoot == uint256S("0x1b2ef6e2f28be914103a277377ae7729dcd125dfeb8bf97bd5964ba72b6dc39b"));

consensus.fPowAllowMinDifficultyBlocks = true;
consensus.powLimit = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.fPowNoRetargeting = true;
consensus.powLimit = uint256S("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimitV1 = uint256S("0x000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.posLimitV2 = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
consensus.nBudgetCycleBlocks = 144; // approx 10 cycles per day
Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct NetworkUpgrade {
struct Params {
uint256 hashGenesisBlock;
bool fPowAllowMinDifficultyBlocks;
bool fPowNoRetargeting;
uint256 powLimit;
uint256 posLimitV1;
uint256 posLimitV2;
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/tx_verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCol
static_assert(MAX_TX_SIZE_AFTER_SAPLING > MAX_ZEROCOIN_TX_SIZE, "New max TX size must be bigger than old max TX size"); // sanity
const unsigned int nMaxSize = tx.IsShieldedTx() ? MAX_TX_SIZE_AFTER_SAPLING : MAX_ZEROCOIN_TX_SIZE;
if (tx.GetTotalSize() > nMaxSize) {
return state.DoS(10, false, REJECT_INVALID, "bad-txns-oversize");
return state.DoS(10, error("tx oversize: %d > %d", tx.GetTotalSize(), nMaxSize), REJECT_INVALID, "bad-txns-oversize");
}

// Dispatch to Sapling validator
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
}

// POW - miner main
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
IncrementExtraNonce(pblock, pindexPrev->nHeight + 1, nExtraNonce);

LogPrintf("Running PIVXMiner with %u transactions in block (%u bytes)\n", pblock->vtx.size(),
::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION));
Expand Down
7 changes: 3 additions & 4 deletions src/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader* pblock)
{
if (Params().IsRegTestNet())
const Consensus::Params& consensus = Params().GetConsensus();

if (consensus.fPowNoRetargeting)
return pindexLast->nBits;

/* current difficulty formula, pivx - DarkGravity v3, written by Evan Duffield - evan@dashpay.io */
Expand All @@ -31,7 +33,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
int64_t CountBlocks = 0;
arith_uint256 PastDifficultyAverage;
arith_uint256 PastDifficultyAveragePrev;
const Consensus::Params& consensus = Params().GetConsensus();
const arith_uint256& powLimit = UintToArith256(consensus.powLimit);

if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) {
Expand Down Expand Up @@ -124,8 +125,6 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits)
bool fOverflow;
arith_uint256 bnTarget;

if (Params().IsRegTestNet()) return true;

bnTarget.SetCompact(nBits, &fNegative, &fOverflow);

// Check range
Expand Down
16 changes: 2 additions & 14 deletions src/qt/pivx/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,6 @@ void SendWidget::ProcessSend(QList<SendCoinsRecipient>& recipients, bool hasShie
// First check SPORK_20 (before unlock)
bool isShieldedTx = hasShieldedOutput || !isTransparent;
if (isShieldedTx) {
if (!walletModel->isSaplingEnforced()) {
inform(tr("Cannot perform shielded operations, v5 upgrade isn't being enforced yet!"));
return;
}

if (walletModel->isSaplingInMaintenance()) {
inform(tr("Sapling Protocol temporarily in maintenance. Shielded transactions disabled (SPORK 20)"));
return;
Expand Down Expand Up @@ -702,8 +697,8 @@ void SendWidget::onCoinControlClicked()

void SendWidget::onShieldCoinsClicked()
{
if (!walletModel->isSaplingEnforced()) {
inform(tr("Cannot perform shielded operations, v5 upgrade isn't being enforced yet!"));
if (walletModel->isSaplingInMaintenance()) {
inform(tr("Sapling Protocol temporarily in maintenance. Shielded transactions disabled (SPORK 20)"));
return;
}

Expand Down Expand Up @@ -792,13 +787,6 @@ void SendWidget::onCheckBoxChanged()
void SendWidget::onPIVSelected(bool _isTransparent)
{
isTransparent = _isTransparent;

if (!isTransparent && !walletModel->isSaplingEnforced()) {
ui->pushLeft->setChecked(true);
inform(tr("Cannot perform shielded operations, v5 upgrade isn't being enforced yet!"));
return;
}

resetChangeAddress();
resetCoinControl();
tryRefreshAmounts();
Expand Down
14 changes: 1 addition & 13 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ bool WalletModel::isSaplingInMaintenance() const
return sporkManager.IsSporkActive(SPORK_20_SAPLING_MAINTENANCE);
}

bool WalletModel::isSaplingEnforced() const
{
return Params().GetConsensus().NetworkUpgradeActive(cachedNumBlocks, Consensus::UPGRADE_V5_0);
}

bool WalletModel::isV6Enforced() const
{
return Params().GetConsensus().NetworkUpgradeActive(cachedNumBlocks, Consensus::UPGRADE_V6_0);
Expand Down Expand Up @@ -603,14 +598,6 @@ OperationResult WalletModel::PrepareShieldedTransaction(WalletModelTransaction*
bool fromTransparent,
const CCoinControl* coinControl)
{
// Basic checks first

// Check network status
int nextBlockHeight = cachedNumBlocks + 1;
if (!Params().GetConsensus().NetworkUpgradeActive(nextBlockHeight, Consensus::UPGRADE_V5_0)) {
return errorOut("Error, cannot send transaction. Sapling is not activated");
}

// Load shieldedAddrRecipients.
std::vector<SendManyRecipient> recipients;
for (const auto& recipient : modelTransaction->getRecipients()) {
Expand All @@ -630,6 +617,7 @@ OperationResult WalletModel::PrepareShieldedTransaction(WalletModelTransaction*
if (!opResult) return opResult;

// Create the operation
int nextBlockHeight = cachedNumBlocks + 1;
SaplingOperation operation(Params().GetConsensus(), nextBlockHeight, wallet);
auto operationResult = operation.setRecipients(recipients)
->setTransparentKeyChange(modelTransaction->getPossibleKeyChange())
Expand Down
1 change: 0 additions & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class WalletModel : public QObject
/** Whether cold staking is enabled or disabled in the network **/
bool isColdStakingNetworkelyEnabled() const;
bool isSaplingInMaintenance() const;
bool isSaplingEnforced() const;
bool isV6Enforced() const;
CAmount getMinColdStakingAmount() const;
/* current staking status from the miner thread **/
Expand Down
11 changes: 1 addition & 10 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ UniValue generateBlocks(const Consensus::Params& consensus,
CScript* coinbaseScript)
{
UniValue blockHashes(UniValue::VARR);
unsigned int nExtraNonce = 0;

while (nHeight < nHeightEnd && !ShutdownRequested()) {

Expand All @@ -52,16 +51,8 @@ UniValue generateBlocks(const Consensus::Params& consensus,
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>(pblocktemplate->block);

if(!fPoS) {
{
LOCK(cs_main);
IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
}
while (pblock->nNonce < std::numeric_limits<uint32_t>::max() &&
!CheckProofOfWork(pblock->GetHash(), pblock->nBits)) {
++pblock->nNonce;
}
if (ShutdownRequested()) break;
if (pblock->nNonce == std::numeric_limits<uint32_t>::max()) continue;
if (!SolveBlock(pblock, nHeight + 1)) continue;
}

CValidationState state;
Expand Down
12 changes: 2 additions & 10 deletions src/sapling/transaction_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,6 @@ std::string TransactionBuilderResult::GetError() {
}
}

// Set default values of new CMutableTransaction based on consensus rules at given height.
CMutableTransaction CreateNewContextualCMutableTransaction(const Consensus::Params& consensusParams, int nHeight)
{
CMutableTransaction mtx;
bool isSapling = consensusParams.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V5_0);
mtx.nVersion = isSapling ? CTransaction::TxVersion::SAPLING : CTransaction::TxVersion::LEGACY;
return mtx;
}

TransactionBuilder::TransactionBuilder(
const Consensus::Params& _consensusParams,
int _nHeight,
Expand All @@ -151,7 +142,8 @@ TransactionBuilder::TransactionBuilder(

void TransactionBuilder::Clear()
{
mtx = CreateNewContextualCMutableTransaction(consensusParams, nHeight);
mtx = CMutableTransaction();
mtx.nVersion = CTransaction::TxVersion::SAPLING;
spends.clear();
outputs.clear();
tIns.clear();
Expand Down
Loading