From 3028d884e531765a4f02b5be21b91cf324690fa2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Sun, 16 Dec 2018 23:04:45 +0800 Subject: [PATCH] Major rebase and fix staking. --- src/komodo_bitcoind.h | 1 - src/komodo_notary.h | 78 +++++++++++++++++++--------------------- src/komodo_utils.h | 2 +- src/main.cpp | 70 ++++++++++++------------------------ src/wallet/rpcwallet.cpp | 4 +-- src/wallet/walletdb.cpp | 5 +-- 6 files changed, 63 insertions(+), 97 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 882292032..a342bb459 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1112,7 +1112,6 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ commission must be in coinbase.vout[1] and must be >= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] */ -extern int32_t ASSETCHAINS_FOUNDERS_PERIOD; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 96497b755..58bc3bffa 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -207,59 +207,55 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam int32_t i,htind,n; uint64_t mask = 0; struct knotary_entry *kp,*tmp; if ( timestamp == 0 && ASSETCHAINS_SYMBOL[0] != 0 ) - timestamp = komodo_heightstamp(height); + timestamp = komodo_heightstamp(height); else if ( ASSETCHAINS_SYMBOL[0] == 0 ) - timestamp = 0; + timestamp = 0; // If this chain is not a staked chain, use the normal Komodo logic to determine notaries. This allows KMD to still sync and use its proper pubkeys for dPoW. if (is_STAKED(ASSETCHAINS_SYMBOL) == 0) { - if ( height >= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) - { - if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) ) - { - if ( did0 == 0 ) - { - n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); - for (i=0; i= KOMODO_NOTARIES_HARDCODED || ASSETCHAINS_SYMBOL[0] != 0 ) + timestamp = 0; + if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP1) || (ASSETCHAINS_SYMBOL[0] == 0 && height <= KOMODO_NOTARIES_HEIGHT1) ) + { + if ( did0 == 0 ) + { + n0 = (int32_t)(sizeof(Notaries_elected0)/sizeof(*Notaries_elected0)); + for (i=0; i= KOMODO_MAXBLOCKS / KOMODO_ELECTION_GAP ) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 6af8af4cc..c4c26e0c7 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1711,7 +1711,7 @@ void komodo_args(char *argv0) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); } - if ( name.c_str()[0] != 0 ) + if ( name.c_str()[0] != 0 ) { std::string selectedAlgo = GetArg("-ac_algo", std::string(ASSETCHAINS_ALGORITHMS[0])); diff --git a/src/main.cpp b/src/main.cpp index 17ff3cbb8..1385ab69b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1244,7 +1244,8 @@ int32_t komodo_isnotaryvout(char *coinaddr) // from ac_private chains only { if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 ) { - if ( NOTARYADDRS[0][0] != 0 && NUM_NOTARIES != 0 ) { + if ( NOTARYADDRS[0][0] != 0 && NUM_NOTARIES != 0 ) + { for (int32_t i=0; i<=NUM_NOTARIES; i++) if ( strcmp(coinaddr,NOTARYADDRS[i]) == 0 ) return(1); @@ -1764,8 +1765,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = true; //fprintf(stderr,"missing inputs\n"); - return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing"); - return(false); + if (!fSkipExpiry) + return state.DoS(0, error("AcceptToMemoryPool: tx inputs not found"),REJECT_INVALID, "bad-txns-inputs-missing"); + else + return(false); } } @@ -1773,7 +1776,10 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (!view.HaveInputs(tx)) { //fprintf(stderr,"accept failure.1\n"); - return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent"); + if (!fSkipExpiry) + return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent"); + else + return(false); } } // are the joinsplit's requirements met? @@ -3302,7 +3308,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if (!view.HaveInputs(tx)) { - return state.DoS(100, error("ConnectBlock(): inputs missing/spent"), + return state.DoS(100, error("ConnectBlock(): inputs missing/spent %s",tx.GetHash().ToString().c_str()), REJECT_INVALID, "bad-txns-inputs-missingorspent"); } // are the JoinSplit's requirements met? @@ -3846,8 +3852,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if ((i == (block.vtx.size() - 1)) && (ASSETCHAINS_STAKED != 0 && (komodo_isPoS((CBlock *)&block) != 0))) { #ifdef ENABLE_WALLET - TxToRemove.push_back(tx.GetHash()); - //pwalletMain->EraseFromWallet(tx.GetHash()); + pwalletMain->EraseFromWallet(tx.GetHash()); #endif } else @@ -3855,25 +3860,6 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { SyncWithWallets(tx, NULL); } } - if ( ASSETCHAINS_STAKED != 0 ) // If Staked chain, scan wallet for orphaned txs and delete them. - { - LOCK2(cs_main, pwalletMain->cs_wallet); - for (map::iterator it = pwalletMain->mapWallet.begin(); it != pwalletMain->mapWallet.end(); ++it) - { - CTransaction tx; - uint256 hashBlock; - if (!GetTransaction((*it).first,tx,hashBlock,true)) - { - fprintf(stderr, "TX Does Not Exist: %s\n",(*it).first.ToString().c_str()); - TxToRemove.push_back((*it).first); - } - } - BOOST_FOREACH (uint256& hash, TxToRemove) - { - pwalletMain->EraseFromWallet(hash); - fprintf(stderr, "Erased %s from wallet.\n",hash.ToString().c_str()); - } - } // Update cached incremental witnesses GetMainSignals().ChainTip(pindexDelete, &block, newSproutTree, newSaplingTree, false); return true; @@ -6601,32 +6587,20 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, CAddress addrFrom; uint64_t nNonce = 1; int nVersion; // use temporary for version, don't set version number until validated as connected + int minVersion = MIN_PEER_PROTO_VERSION; + if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 ) + minVersion = STAKEDMIN_PEER_PROTO_VERSION; vRecv >> nVersion >> pfrom->nServices >> nTime >> addrMe; if (nVersion == 10300) nVersion = 300; - if ( is_STAKED(ASSETCHAINS_SYMBOL) != 0 ) + if (nVersion < minVersion) { - if (nVersion < STAKEDMIN_PEER_PROTO_VERSION) - { - // disconnect from peers older than this proto version - LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion); - pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, - strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION)); - pfrom->fDisconnect = true; - return false; - } - } - else - { - if (nVersion < MIN_PEER_PROTO_VERSION) - { - // disconnect from peers older than this proto version - LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion); - pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, - strprintf("Version must be %d or greater", MIN_PEER_PROTO_VERSION)); - pfrom->fDisconnect = true; - return false; - } + // disconnect from peers older than this proto version + LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->id, pfrom->nVersion); + pfrom->PushMessage("reject", strCommand, REJECT_OBSOLETE, + strprintf("Version must be %d or greater", minVersion)); + pfrom->fDisconnect = true; + return false; } // Reject incoming connections from nodes that don't know about the current epoch diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1771e6abb..2f6455701 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5317,7 +5317,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt counter++; if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) { - //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); + fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } CAmount nValue = out.tx->vout[out.i].nValue; @@ -5388,7 +5388,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } - if ( numkp < 10000 && array != 0 ) + if ( numkp < 1000 && array != 0 ) { free(array); array = 0; diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 52c815ce2..4dedab834 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -867,8 +867,6 @@ static bool IsKeyType(string strType) strType == "mkey" || strType == "ckey"); } -extern uint64_t ASSETCHAINS_STAKED; - DBErrors CWalletDB::LoadWallet(CWallet* pwallet) { pwallet->vchDefaultKey = CPubKey(); @@ -920,9 +918,8 @@ DBErrors CWalletDB::LoadWallet(CWallet* pwallet) { // Leave other errors alone, if we try to fix them we might make things worse. fNoncriticalErrors = true; // ... but do warn the user there is something wrong. - if (strType == "tx" && ASSETCHAINS_STAKED == 0 ) + if (strType == "tx" ) // Rescan if there is a bad transaction record.. - // But dont on staked chains! SoftSetBoolArg("-rescan", true); } }