From 5a7fd132cf5080d572423a48e761e90fc499f6ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 09:54:28 -1100 Subject: [PATCH 1/9] Fix estimate PoS perc --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9076ef125..1c0a6414d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1269,6 +1269,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else { + n++; percPoS++; if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"0"); diff --git a/src/miner.cpp b/src/miner.cpp index 9ca979e07..c837268f9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -784,7 +784,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED == 0 ) { //fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height); - sleep(3); + //sleep(3); } #ifdef ENABLE_WALLET CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1,gpucount); @@ -976,11 +976,11 @@ void static BitcoinMiner() { while ( B.nTime-57 > GetAdjustedTime() ) sleep(1); - if ( Mining_height < 6000 ) + /*if ( Mining_height < 6000 ) { while ( B.nTime > GetAdjustedTime() ) sleep(1); - } + }*/ uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From d5a38d16a8866207cb96ab96f6a99befd3bb8c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 11:17:30 -1100 Subject: [PATCH 2/9] +print --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c837268f9..8824959e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -939,7 +939,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - /*for (z=31; z>=16; z--) + for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -947,7 +947,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n");*/ + fprintf(stderr," POW\n"); if ( h > hashTarget ) return false; if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) From 1cdb961ba26865efb46b30eb1daa61327d7cea28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 02:51:42 -1100 Subject: [PATCH 3/9] Fix PoW mining in mixed PoS/PoW, fix orphaned stake tx --- src/chain.h | 26 ++++++++++++++++++++++++++ src/komodo_bitcoind.h | 15 +++++++++------ src/main.cpp | 28 ++++++++++++++++++++++------ src/miner.cpp | 4 ++-- src/validationinterface.cpp | 4 ++++ src/validationinterface.h | 1 + src/wallet/wallet.cpp | 12 ++++++++++++ src/wallet/wallet.h | 1 + 8 files changed, 77 insertions(+), 14 deletions(-) diff --git a/src/chain.h b/src/chain.h index a28e4e44a..e2b03c4df 100644 --- a/src/chain.h +++ b/src/chain.h @@ -16,6 +16,7 @@ #include +uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr); static const int SPROUT_VALUE_VERSION = 1001400; struct CDiskBlockPos @@ -321,6 +322,31 @@ public: //! Efficiently find an ancestor of this block. CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; + + bool IsPOSBlock() const + { + if ( ASSETCHAINS_STAKED != 0 ) + { + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + const CBlockIndex *pindex = this; + if ( (n= pindex->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + { + txid = pblock->vtx[n-1].vin[0].prevout.hash; + vout = pblock->vtx[n-1].vin[0].prevout.n; + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pindex->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pindex->vtx[n-1].vout[0].nValue == value ) + { + fprintf(stderr,"is PoS block!\n"); + return(true); + } + } + } + } + return(false); + } }; /** Used to marshal pointers into hashes for db storage. */ diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1c0a6414d..2c27589cc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1328,7 +1328,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); txn_count = pblock->vtx.size(); @@ -1343,7 +1343,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) { - eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); + if ( pblock->IsPOSBlock() != 0 ) + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); @@ -1351,14 +1352,16 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { - txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( pblock->IsPOSBlock() != 0 ) + isPoS = 1; + /*txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].nValue == value ) isPoS = 1; // close enough for a pre-filter //else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); - } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); + } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height);*/ } //else return(-1); } //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); @@ -1443,10 +1446,10 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { + if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target + return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - else if ( height > 100 ) - bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound if ( bhash > bnTarget ) { for (i=31; i>=16; i--) diff --git a/src/main.cpp b/src/main.cpp index d4dfae7ae..bd6aef8ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3252,13 +3252,17 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) return false; - if (!fBare) { + if (!fBare) + { // Resurrect mempool transactions from the disconnected block. - BOOST_FOREACH(const CTransaction &tx, block.vtx) { + //BOOST_FOREACH(const CTransaction &tx, block.vtx) { + for (int i = 0; i < block.vtx.size(); i++) + { + CTransaction &tx = block.vtx[i]; // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3275,11 +3279,23 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), newTree)); // Let wallets know transactions went from 1-confirmed to // 0-confirmed or conflicted: - BOOST_FOREACH(const CTransaction &tx, block.vtx) { - SyncWithWallets(tx, NULL); - } + //BOOST_FOREACH(const CTransaction &tx, block.vtx) { + // SyncWithWallets(tx, NULL); + //} // Update cached incremental witnesses //fprintf(stderr,"chaintip false\n"); + for (int i = 0; i < block.vtx.size(); i++) + { + CTransaction &tx = block.vtx[i]; + if (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) + { + EraseFromWallets(tx.GetHash()); + } + else + { + SyncWithWallets(tx, NULL); + } + } GetMainSignals().ChainTip(pindexDelete, &block, newTree, false); return true; } diff --git a/src/miner.cpp b/src/miner.cpp index 8824959e1..c837268f9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -939,7 +939,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - for (z=31; z>=16; z--) + /*for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -947,7 +947,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n"); + fprintf(stderr," POW\n");*/ if ( h > hashTarget ) return false; if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index cd3e30f3d..a8e15db99 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -51,3 +51,7 @@ void UnregisterAllValidationInterfaces() { void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) { g_signals.SyncTransaction(tx, pblock); } + +void EraseFromWallets(const uint256 &hash) { + g_signals.EraseTransaction(hash); +} diff --git a/src/validationinterface.h b/src/validationinterface.h index 1855dacd7..a1f111753 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -28,6 +28,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn); void UnregisterAllValidationInterfaces(); /** Push an updated transaction to all registered wallets */ void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL); +void EraseFromWallets(const uint256 &hash); class CValidationInterface { protected: diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 10bf93598..1cf52d1b4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1358,6 +1358,18 @@ bool CWallet::IsFromMe(const uint256& nullifier) const return false; } +void CWallet::EraseFromWallet(const uint256 &hash) +{ + if (!fFileBacked) + return; + { + LOCK(cs_wallet); + if (mapWallet.erase(hash)) + CWalletDB(strWalletFile).EraseTx(hash); + } + return; +} + void CWallet::GetNoteWitnesses(std::vector notes, std::vector>& witnesses, uint256 &final_anchor) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f77a55a04..f6c8563ef 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -995,6 +995,7 @@ public: bool UpdateNullifierNoteMap(); void UpdateNullifierNoteMapWithTx(const CWalletTx& wtx); bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb); + void EraseFromWallet(const uint256 &hash); void SyncTransaction(const CTransaction& tx, const CBlock* pblock); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); void EraseFromWallet(const uint256 &hash); From d1db09204a50e47ea882160c8bf1634a8900d42a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 02:58:41 -1100 Subject: [PATCH 4/9] Syntax --- src/chain.h | 25 ------------------------- src/komodo_bitcoind.h | 32 ++++++++++++++++++++++++++++---- src/main.cpp | 4 ++-- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/chain.h b/src/chain.h index e2b03c4df..41cf28652 100644 --- a/src/chain.h +++ b/src/chain.h @@ -16,7 +16,6 @@ #include -uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr); static const int SPROUT_VALUE_VERSION = 1001400; struct CDiskBlockPos @@ -323,30 +322,6 @@ public: CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; - bool IsPOSBlock() const - { - if ( ASSETCHAINS_STAKED != 0 ) - { - int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; - const CBlockIndex *pindex = this; - if ( (n= pindex->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) - { - txid = pblock->vtx[n-1].vin[0].prevout.hash; - vout = pblock->vtx[n-1].vin[0].prevout.n; - txtime = komodo_txtime(&value,txid,vout,destaddr); - if ( ExtractDestination(pindex->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) - { - strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); - if ( strcmp(destaddr,voutaddr) == 0 && pindex->vtx[n-1].vout[0].nValue == value ) - { - fprintf(stderr,"is PoS block!\n"); - return(true); - } - } - } - } - return(false); - } }; /** Used to marshal pointers into hashes for db storage. */ diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2c27589cc..ab7bad30f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -606,6 +606,30 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) return(txtime); } +int32_t komodo_isPoS(CBlock *pblock) +{ + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + if ( ASSETCHAINS_STAKED != 0 ) + { + if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + { + txid = pblock->vtx[n-1].vin[0].prevout.hash; + vout = pblock->vtx[n-1].vin[0].prevout.n; + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) + { + fprintf(stderr,"is PoS block!\n"); + return(1); + } + } + } + } + return(0); +} + void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; @@ -1151,13 +1175,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; ivtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) { - if ( pblock->IsPOSBlock() != 0 ) + if ( komodo_isPoS(pblock) != 0 ) eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { @@ -1352,7 +1376,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { - if ( pblock->IsPOSBlock() != 0 ) + if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; /*txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) diff --git a/src/main.cpp b/src/main.cpp index bd6aef8ce..ea18662aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3262,7 +3262,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3287,7 +3287,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - if (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) + if (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) { EraseFromWallets(tx.GetHash()); } From 72953c8342459633b16e6a8f33523a0ba7099f83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:00:38 -1100 Subject: [PATCH 5/9] Syntax --- src/wallet/wallet.cpp | 12 ------------ src/wallet/wallet.h | 1 - 2 files changed, 13 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1cf52d1b4..10bf93598 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1358,18 +1358,6 @@ bool CWallet::IsFromMe(const uint256& nullifier) const return false; } -void CWallet::EraseFromWallet(const uint256 &hash) -{ - if (!fFileBacked) - return; - { - LOCK(cs_wallet); - if (mapWallet.erase(hash)) - CWalletDB(strWalletFile).EraseTx(hash); - } - return; -} - void CWallet::GetNoteWitnesses(std::vector notes, std::vector>& witnesses, uint256 &final_anchor) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f6c8563ef..0c6a90840 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -998,7 +998,6 @@ public: void EraseFromWallet(const uint256 &hash); void SyncTransaction(const CTransaction& tx, const CBlock* pblock); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); - void EraseFromWallet(const uint256 &hash); void WitnessNoteCommitment( std::vector commitments, std::vector>& witnesses, From 333cf46c477808757d82ddd319b9730faf649d6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:16:21 -1100 Subject: [PATCH 6/9] Accept duplicate height 1 --- src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ea18662aa..7529a9d98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3262,7 +3262,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3287,7 +3287,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - if (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) + if ( (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 ) { EraseFromWallets(tx.GetHash()); } @@ -4094,7 +4094,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) + { + CBlockIndex *heightblock = chainActive[nHeight]; + if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) + return true; return(false); + } if ( nHeight != 0 ) { if ( pcheckpoint != 0 && nHeight < pcheckpoint->nHeight ) From 42bbeb4f4db3b9850f93ced9b6edc52d763e75ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:21:28 -1100 Subject: [PATCH 7/9] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7529a9d98..5f51a47c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4098,7 +4098,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) return true; - return(false); + return state.DoS(1, error("%s: trying to change height 1 forbidden", __func__)); } if ( nHeight != 0 ) { From 8808427254f402bcba651ae3838437bdd23470a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:26:47 -1100 Subject: [PATCH 8/9] -print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ab7bad30f..366011db6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -621,7 +621,7 @@ int32_t komodo_isPoS(CBlock *pblock) strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) { - fprintf(stderr,"is PoS block!\n"); + //fprintf(stderr,"is PoS block!\n"); return(1); } } @@ -1181,7 +1181,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) { memcpy(prevhashbuf,hashbuf,100); prevheight = height; - fprintf(stderr,"segids.%d\n",height); + fprintf(stderr,"prevsegids.%d\n",height+n); } } } From 6789cd6db6fcdbbc7a6d483e7ebfe64d33e4b191 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:28:12 -1100 Subject: [PATCH 9/9] -print --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 366011db6..25bd2b831 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1175,13 +1175,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]);