Skip to content

Commit

Permalink
Merge pull request #22 from jmjatlanta/jmj_testutils_wallet
Browse files Browse the repository at this point in the history
Make TestWallet derive from CWallet
  • Loading branch information
jmjatlanta authored May 20, 2022
2 parents cf6af36 + 76bad69 commit 770f6eb
Show file tree
Hide file tree
Showing 24 changed files with 885 additions and 353 deletions.
2 changes: 2 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ class CRegTestParams : public CChainParams {
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nProtocolVersion = 170006;
consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight =
Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
originalCoinbaseMaturity = 1;
coinbaseMaturity = 1;

pchMessageStart[0] = 0xaa;
pchMessageStart[1] = 0x8e;
Expand Down
5 changes: 5 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ class CChainParams
void SetNValue(uint64_t n) { nEquihashN = n; }
void SetKValue(uint64_t k) { nEquihashK = k; }
void SetMiningRequiresPeers(bool flag) { fMiningRequiresPeers = flag; }
uint32_t CoinbaseMaturity() const { return coinbaseMaturity; }
void SetCoinbaseMaturity(uint32_t in) const { coinbaseMaturity = in; }
void ResetCoinbaseMaturity() const { coinbaseMaturity = originalCoinbaseMaturity; }

//void setnonce(uint32_t nonce) { memcpy(&genesis.nNonce,&nonce,sizeof(nonce)); }
//void settimestamp(uint32_t timestamp) { genesis.nTime = timestamp; }
Expand Down Expand Up @@ -156,6 +159,8 @@ class CChainParams
bool fTestnetToBeDeprecatedFieldRPC = false;
CCheckpointData checkpointData;
std::vector<std::string> vFoundersRewardAddress;
mutable uint32_t coinbaseMaturity = 100;
uint32_t originalCoinbaseMaturity = 100;
};

/**
Expand Down
2 changes: 0 additions & 2 deletions src/consensus/consensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ extern unsigned int MAX_BLOCK_SIGOPS;
/** The maximum size of a transaction (network rule) */
static const unsigned int MAX_TX_SIZE_BEFORE_SAPLING = 100000;
static const unsigned int MAX_TX_SIZE_AFTER_SAPLING = (2 * MAX_TX_SIZE_BEFORE_SAPLING); //MAX_BLOCK_SIZE;
/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
extern int COINBASE_MATURITY;
/** The minimum value which is invalid for expiry height, used by CTransaction and CMutableTransaction */
static constexpr uint32_t TX_EXPIRY_HEIGHT_THRESHOLD = 500000000;

Expand Down
1 change: 0 additions & 1 deletion src/komodo_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#define ASSETCHAINS_STAKED_BLOCK_FUTURE_MAX 57
#define ASSETCHAINS_STAKED_BLOCK_FUTURE_HALF 27
#define ASSETCHAINS_STAKED_MIN_POW_DIFF 536900000 // 537000000 537300000
#define _COINBASE_MATURITY 100
#define _ASSETCHAINS_TIMELOCKOFF 0xffffffffffffffff

// KMD Notary Seasons
Expand Down
4 changes: 1 addition & 3 deletions src/komodo_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ struct knotaries_entry *Pubkeys;

struct komodo_state KOMODO_STATES[34];

#define _COINBASE_MATURITY 100
int COINBASE_MATURITY = _COINBASE_MATURITY;//100;
unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10;
unsigned int WITNESS_CACHE_SIZE = 100+10; // coinbase maturity plus 10
uint256 KOMODO_EARLYTXID;

bool IS_KOMODO_NOTARY;
Expand Down
7 changes: 3 additions & 4 deletions src/komodo_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1796,7 +1796,6 @@ void komodo_args(char *argv0)
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
int32_t komodo_baseid(char *origbase);
extern int COINBASE_MATURITY;
if ( strcmp(ASSETCHAINS_SYMBOL,"KMD") == 0 )
{
fprintf(stderr,"cant have assetchain named KMD\n");
Expand All @@ -1807,10 +1806,10 @@ void komodo_args(char *argv0)
else komodo_configfile(ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT + 1);

if (ASSETCHAINS_CBMATURITY != 0)
COINBASE_MATURITY = ASSETCHAINS_CBMATURITY;
Params().SetCoinbaseMaturity(ASSETCHAINS_CBMATURITY);
else if (ASSETCHAINS_LASTERA == 0 || is_STAKED(ASSETCHAINS_SYMBOL) != 0)
COINBASE_MATURITY = 1;
if (COINBASE_MATURITY < 1)
Params().SetCoinbaseMaturity(1);
if (Params().CoinbaseMaturity() < 1)
{
fprintf(stderr,"ac_cbmaturity must be >0, shutting down\n");
StartShutdown();
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa
if (pool.mapNextTx.count(outpoint))
{
// Disable replacement feature for now
return false;
return state.Invalid(false, REJECT_INVALID, "mempool conflict");
}
}
BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) {
Expand Down Expand Up @@ -2797,9 +2797,9 @@ namespace Consensus {
}

// Ensure that coinbases are matured, no DoS as retry may work later
if (nSpendHeight - coins->nHeight < COINBASE_MATURITY) {
if (nSpendHeight - coins->nHeight < ::Params().CoinbaseMaturity()) {
return state.Invalid(
error("CheckInputs(): tried to spend coinbase at depth %d/%d", nSpendHeight - coins->nHeight, (int32_t)COINBASE_MATURITY),
error("CheckInputs(): tried to spend coinbase at depth %d/%d", nSpendHeight - coins->nHeight, (int32_t)::Params().CoinbaseMaturity()),
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase");
}

Expand Down
3 changes: 1 addition & 2 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class PrecomputedTransactionData;

struct CNodeStateStats;
#define DEFAULT_MEMPOOL_EXPIRY 1
#define _COINBASE_MATURITY 100

/** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/
static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 2000000;//MAX_BLOCK_SIZE;
Expand All @@ -78,7 +77,7 @@ static const bool DEFAULT_ALERTS = true;
/** Minimum alert priority for enabling safe mode. */
static const int ALERT_PRIORITY_SAFE_MODE = 4000;
/** Maximum reorg length we will accept before we shut down and alert the user. */
static unsigned int MAX_REORG_LENGTH = _COINBASE_MATURITY - 1;
static unsigned int MAX_REORG_LENGTH = 100 - 1; // based on COINBASE_MATURITY
/** Maximum number of signature check operations in an IsStandard() P2SH script */
static const unsigned int MAX_P2SH_SIGOPS = 15;
/** The maximum number of sigops we're willing to relay/mine in a single tx */
Expand Down
2 changes: 1 addition & 1 deletion src/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ int printMetrics(size_t cols, bool mining)
subsidy -= subsidy/5;
}

if ((std::max(0, COINBASE_MATURITY - (tipHeight - height)) > 0) ||
if ((std::max( 0U, Params().CoinbaseMaturity() - (tipHeight - height)) > 0) ||
(tipHeight < komodo_block_unlocktime(height) && subsidy >= ASSETCHAINS_TIMELOCKGTE)) {
immature += subsidy;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
if (wtx.IsCoinBase())
{
extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
if ( ASSETCHAINS_SYMBOL[0] == 0 )
COINBASE_MATURITY = _COINBASE_MATURITY;
quint32 numBlocksToMaturity = COINBASE_MATURITY + 1;
//if ( ASSETCHAINS_SYMBOL[0] == 0 )
//COINBASE_MATURITY = _COINBASE_MATURITY;
quint32 numBlockToMaturity = 100 + 1; // COINBASE_MATURITY + 1
strHTML += "<br>" + tr("Generated coins must mature %1 blocks and have any applicable time locks open before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.").arg(QString::number(numBlocksToMaturity)) + "<br>";
// we need to display any possible CLTV lock time
}
Expand Down
37 changes: 37 additions & 0 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,43 @@ bool CalcPoW(CBlock *pblock)
return false;
}

/****
* @brief Generate 1 block
* @param wallet the wallet that should be used
* @returns the block created or nullptr if there was a problem
*/
std::shared_ptr<CBlock> generateBlock(CWallet* wallet, CValidationState* validationState)
{
CReserveKey reservekey(wallet);
int nHeight;

{ // Don't keep cs_main locked
LOCK(cs_main);
nHeight = chainActive.Height();
}

std::unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey,nHeight,KOMODO_MAXGPUCOUNT));
if (pblocktemplate == nullptr)
return nullptr;

CBlock *pblock = &pblocktemplate->block;
{
unsigned int nExtraNonce = 0;
LOCK(cs_main);
IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce);
}

CalcPoW(pblock); // add PoW
CValidationState state;
if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL))
{
if (validationState != nullptr)
(*validationState) = state;
return nullptr;
}
return std::shared_ptr<CBlock>( new CBlock(*pblock) );
}

//Value generate(const Array& params, bool fHelp)
UniValue generate(const UniValue& params, bool fHelp, const CPubKey& mypk)
{
Expand Down
11 changes: 11 additions & 0 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,17 @@ SigVersion SignatureHashVersion(const CTransaction& txTo)
}
}

/*****
* Generate a signature hash
* @param scriptCode the scriptPubKey
* @param txTo the transaction we are trying to create
* @param nIn the index of the vIn that has the data to sign
* @param nHashType the hash type (i.e. SIGHASH_ALL)
* @param amount the amount (for hidden txs)
* @param consensusBranchId the branch id
* @param cache additional data
* @returns the signature
*/
uint256 SignatureHash(
const CScript& scriptCode,
const CTransaction& txTo,
Expand Down
Loading

0 comments on commit 770f6eb

Please sign in to comment.