From e0711243be9a647c7415c35034a79b07450369da Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 10:42:11 +0300 Subject: [PATCH 01/45] Return error instead of assert of prevhash is not best hash --- src/main.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index f4a7eed43..08e161a19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2455,6 +2455,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); + if ( hashPrevBlock != view.GetBestBlock() ) + { + fprintf(stderr,"ConnectBlock(): hashPrevBlock != view.GetBestBlock()\n"); + return state.DoS(1, error("ConnectBlock(): hashPrevBlock != view.GetBestBlock()"), + REJECT_INVALID, "hashPrevBlock-not-bestblock"); + } assert(hashPrevBlock == view.GetBestBlock()); // Special case for the genesis block, skipping connection of its transactions From 3b2762ebc888986a21368d178afc00ca6557fd09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 10:59:16 +0300 Subject: [PATCH 02/45] Revert half the windows redundant header fix --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 08e161a19..bd684a6fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5564,7 +5564,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, vector vHeaders; int nLimit = MAX_HEADERS_RESULTS; LogPrint("net", "getheaders %d to %s from peer=%d\n", (pindex ? pindex->nHeight : -1), hashStop.ToString(), pfrom->id); - if ( pfrom->lasthdrsreq >= chainActive.Height()-MAX_HEADERS_RESULTS || pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) ) + //if ( pfrom->lasthdrsreq >= chainActive.Height()-MAX_HEADERS_RESULTS || pfrom->lasthdrsreq != (int32_t)(pindex ? pindex->nHeight : -1) ) { pfrom->lasthdrsreq = (int32_t)(pindex ? pindex->nHeight : -1); for (; pindex; pindex = chainActive.Next(pindex)) @@ -5575,12 +5575,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } pfrom->PushMessage("headers", vHeaders); } - else if ( NOTARY_PUBKEY33[0] != 0 ) + /*else if ( NOTARY_PUBKEY33[0] != 0 ) { static uint32_t counter; if ( counter++ < 3 ) fprintf(stderr,"you can ignore redundant getheaders from peer.%d %d prev.%d\n",(int32_t)pfrom->id,(int32_t)(pindex ? pindex->nHeight : -1),pfrom->lasthdrsreq); - } + }*/ } From 460945fc9ee458e90c381840f53597255b591c28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 15:03:02 +0300 Subject: [PATCH 03/45] Max future mined time -> 10 seconds --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 01817c759..7af581439 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -487,8 +487,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 ) { pblock->nTime = pindexPrev->nTime + 60; - fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60)); - while ( pblock->GetBlockTime() > GetAdjustedTime() + 60 ) + //fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60)); + while ( pblock->GetBlockTime() > GetAdjustedTime() + 10 ) sleep(1); } pblock->nSolution.clear(); From 4a953920259963a621f5924a7da859b0fe25e5bd Mon Sep 17 00:00:00 2001 From: SHossain Date: Tue, 24 Apr 2018 13:08:32 +0100 Subject: [PATCH 04/45] Update README.md --- README.md | 110 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 74425bd3c..d39f83675 100644 --- a/README.md +++ b/README.md @@ -3,36 +3,43 @@ Komodo 1.0.15 ## Komodod This software is Komodo client, generally you will use this if you want to mine KMD or setup a full node. It downloads and stores the entire history of Komodo transactions; depending on the speed of your computer and network connection, the synchronization process could take a day or more once the blockchain has reached a significant size. + ## Development Resources - Komodo Web: [https://komodoplatform.com/](https://komodoplatform.com/) -- Organization web: [https://www.supernet.org](https://www.supernet.org) -- Forum: [https://forum.supernet.org/](https://forum.supernet.org/) -- Mail: [info@supernet.org](mailto:info@supernet.org) -- Support & Guides: [https://support.supernet.org/support/home](https://support.supernet.org/support/home) +- Organization web: [https://komodoplatform.com/](https://komodoplatform.com/) +- Forum: [https://forum.komodoplatform.com/](https://forum.komodoplatform.com/) +- Mail: [info@komodoplatform.com](mailto:info@komodoplatform.com) +- Support: [https://support.komodoplatform.com/support/home](https://support.komodoplatform.com/support/home) +- Knowledgebase & How-to: [https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages) - API references: [http://docs.supernet.org/](http://docs.supernet.org/) #Not up to date. +- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/03/2018-03-12-Komodo-White-Paper-Full.pdf) - Komodo Platform public material: [Komodo Platform public material](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) + ## List of Komodo Platform Technologies -Delayed Proof of Work (dPoW) - Additional security layer. -zk-SNARKs - Komodo Platform's privacy technology -Jumblr - Decentralized tumbler for KMD and other cryptocurrencies -Assetchains - Easy way to fork Komodo coin -Pegged Assets - Chains that maintain a peg to fiat currencies -Peerchains - Scalability solution where sibling chains form a network of blockchains -More in depth covered [here](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) -Also note you receive 5% APR on your holdings. -[See this article for more details](https://supernet.org/en/resources/articles/receive-free-coins-quaranteed-kmd-interest) +- Delayed Proof of Work (dPoW) - Additional security layer. +- zk-SNARKs - Komodo Platform's privacy technology +- Jumblr - Decentralized tumbler for KMD and other cryptocurrencies +- Assetchains - Easy way to fork Komodo coin +- Pegged Assets - Chains that maintain a peg to fiat currencies +- Peerchains - Scalability solution where sibling chains form a network of blockchains +- More in depth covered [here](https://docs.google.com/document/d/1AbhWrtagu4vYdkl-vsWz-HSNyNvK-W-ZasHCqe7CZy0) +- Also note you receive 5% APR on your holdings. +[See this article for more details](https://komodoplatform.atlassian.net/wiki/spaces/KPSD/pages/20480015/Claim+KMD+Interest+in+Agama) + ## Tech Specification -Max Supply: 200 million KMD. -Block Time: 1M 2s -Block Reward: 3KMD -Mining Algorithm: Equihash +- Max Supply: 200 million KMD. +- Block Time: 1M 2s +- Block Reward: 3KMD +- Mining Algorithm: Equihash + ## About this Project Komodo is based on Zcash and has been by our innovative consensus algorithm called dPoW which utilizes Bitcoin's hashrate to store Komodo blockchain information into the Bitcoin blockchain. Other new and native Komodo features are the privacy technology called JUMBLR or our assetchain capabilities (one click plug and play blockchain solutions). More details are available under https://komodoplatform.com/. + ## Getting started Dependencies ------------ -``` +```shell #The following packages are needed: sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python python-zmq zlib1g-dev wget libcurl4-openssl-dev bsdmainutils automake curl ``` @@ -54,7 +61,7 @@ dPoW branch: autobuild into GUI installers, unix, osx, windows beta branch: notary nodes, command line unix dev branch: bleeding edge, possibly wont even compile, multiple updates per hour -``` +```shell git clone https://github.com/jl777/komodo cd komodo #you might want to: git checkout ; git pull @@ -64,7 +71,6 @@ cd komodo #This can take some time. ``` - **komodo is experimental and a work-in-progress.** Use at your own risk. Deprecation Policy @@ -76,11 +82,14 @@ time after this one year period. The automatic feature is based on block height and can be explicitly disabled. -# to update an existing version, git checkout dPoW if not on that branch already +# to update an existing version, `git checkout dPoW` if not on that branch already +```shell git pull ./zcutil/fetch-params.sh ./zcutil/build.sh -j8 -To reset the blockchain, from ~/.komodo rm -rf blocks chainstate debug.log komodostate db.log +``` +To reset the blockchain, from *~/.komodo* `rm -rf blocks chainstate debug.log komodostate db.log` + Create komodo.conf ------------------ @@ -105,7 +114,7 @@ addnode=89.248.166.91 Start mining ------------ -``` +```shell #iguana documentation shows how to get the btcpubkey and wifstrs that need to be used #bitcoin also need to be installed with txindex=1 and with rpc enabled cd ~ @@ -136,59 +145,88 @@ Both komodod and komodo-cli recognize -ac_name=option so you can create fork fro ``` ======= **Zcash is unfinished and highly experimental.** Use at your own risk. + Where do I begin? ----------------- We have a guide for joining the main Zcash network: https://github.com/zcash/zcash/wiki/1.0-User-Guide + ### Need Help? * See the documentation at the [Zcash Wiki](https://github.com/zcash/zcash/wiki) for help and more information. * Ask for help on the [Zcash](https://forum.z.cash/) forum. Participation in the Zcash project is subject to a [Code of Conduct](code_of_conduct.md). + Building -------- Build Zcash along with most dependencies from source by running -./zcutil/build.sh. Currently only Linux is officially supported. +`./zcutil/build.sh`. Currently only Linux is officially supported. + License ------- For license information see the file [COPYING](COPYING). -NOTE TO EXCHANGES: + +**NOTE TO EXCHANGES:** https://bitcointalk.org/index.php?topic=1605144.msg17732151#msg17732151 There is a small chance that an outbound transaction will give an error due to mismatched values in wallet calculations. There is a -exchange option that you can run komodod with, but make sure to have the entire transaction history under the same -exchange mode. Otherwise you will get wallet conflicts. -To change modes: -a) backup all privkeys (launch komodod with -exportdir= and dumpwallet) -b) start a totally new sync including wallet.dat, launch with same exportdir -c) stop it before it gets too far and import all the privkeys from a) using komodo-cli importwallet filename + +**To change modes:** + +a) backup all privkeys (launch komodod with `-exportdir=` and `dumpwallet`) + +b) start a totally new sync including `wallet.dat`, launch with same `exportdir` + +c) stop it before it gets too far and import all the privkeys from a) using `komodo-cli importwallet filename` + d) resume sync till it gets to chaintip + For example: +```shell ./komodod -exportdir=/tmp & ./komodo-cli dumpwallet example ./komodo-cli stop mv ~/.komodo ~/.komodo.old && mkdir ~/.komodo && cp ~/.komodo.old/komodo.conf ~/.komodo.old/peers.dat ~/.komodo ./komodod -exchange -exportdir=/tmp & ./komodo-cli importwallet /tmp/example -############## JUMBLR -komodod now has jumblr_deposit and jumblr_secret RPC calls. +``` + +## JUMBLR +komodod now has `jumblr_deposit` and `jumblr_secret` RPC calls. + Jumblr works like described previously where all the nodes with jumblr active synchronize their tx activity during the same block to maximize the mixing effect. However, unlike all other mixers/tumblers, you never give up control of your coins to anybody else. JUMBLR uses a one to many allocation of funds, ie. one deposit address and many secret addresses. You can always run multiple komodod daemons to get multiple active deposit addresses. + JUMBLR implements t -> z, z -> z and z -> t transactions to maximize privacy of the destination t (transparent) address. So while it is transparent, its first activity is funds coming from an untracable z address. + Which of the three stages is done is randomly selected at each turn. Also when there is more than one possible transaction at the selected stage, a random one is selected. This randomization prevents analyzing incoming z ->t transactions by its size to correlate it to the originating address. -jumblr_deposit designates the deposit address as the jumblr deposit address for that session. You can select an address that already has funds in it and it will immediately start jumblr process. If there are no funds, it will wait until you send funds to it. -There are three sizes of a jumblr transaction: 10 KMD, 100 KMD and 1000 KMD. There is also a fixed interval of blocks where all jumblr nodes are active. Currently it is set to be 10, but this is subject to change. Only during every 10*10 blocks are the largest 1000 KMD transactions processed, so this concentrates all the large transactions every N*N blocks. -jumblr_secret notifies JUMBLR where to send the final z -> t transactions. In order to allow larger accounts to obtain privacy, up to 777 secret addresses are supported. Whenever a z -> t stage is activated, a random secret address from the list of the then active secret addresses is selected. -Practical Advice: + +`jumblr_deposit ` designates the deposit address as the jumblr deposit address for that session. You can select an address that already has funds in it and it will immediately start jumblr process. If there are no funds, it will wait until you send funds to it. + +There are three sizes of a jumblr transaction: 10 KMD, 100 KMD and 1000 KMD. There is also a fixed interval of blocks where all jumblr nodes are active. Currently it is set to be 10, but this is subject to change. Only during every 10*10 blocks are the largest 1000 KMD transactions processed, so this concentrates all the large transactions every N*N blocks. + +`jumblr_secret ` notifies JUMBLR where to send the final z -> t transactions. In order to allow larger accounts to obtain privacy, up to 777 secret addresses are supported. Whenever a z -> t stage is activated, a random secret address from the list of the then active secret addresses is selected. + +#### Practical Advice: Obtaining privacy used to be very difficult. JUMBLR makes it as simple as issuing two command line calls. Higher level layers can be added to help manage the addresses, ie. linking them at the passphrase level. Such matters are left to each implementation. + Once obtained, it is very easy to lose all the privacy. With a single errant transaction that combines some previously used address and the secretaddress, well, the secretaddress is no longer so private. + The advice is to setup a totally separate node! + This might seem a bit drastic, but if you want to maintain privacy, it is best to make it look like all the transactions are coming from a different node. The easiest way for most people to do this is to actually have a different node. -It can be a dedicated laptop (recommended) or a VPS (for smaller amounts) with a totally fresh komodod wallet. Generate an address on this wallet and use that as the jumblr_secret address on your main node. As the JUMBLR operates funds will teleport into your secret node's address. If you are careful and never use the same IP address for both your nodes, you will be able to maintain very good privacy. + +It can be a dedicated laptop (recommended) or a VPS (for smaller amounts) with a totally fresh komodod wallet. Generate an address on this wallet and use that as the jumblr_secret address on your main node. As the JUMBLR operates funds will teleport into your secret node's address. If you are careful and never use the same IP address for both your nodes, you will be able to maintain very good privacy. + Of course, don't send emails that link the two accounts together! Dont use secret address funds for home delivery purchases! Etc. There are many ways to lose the privacy, just think about what linkages can be dont at the IP and blockchain level and that should be a useful preparation. + What if you have 100,000 KMD and you dont want others to know you are such a whale? Instead of generating 1 secret address, generate 100 and make a script file with: +```shell ./komodo-cli jumblr_secret ./komodo-cli jumblr_secret ... ./komodo-cli jumblr_secret +``` And make sure to delete all traces of this when the JUMBLR is finished. You will end up with 100 addresses that have an average of 1000 KMD each. So as long as you are careful and dont do a 10,000 KMD transaction (that will link 10 of your secret addresses together), you can appear as 100 different people each with 1000 KMD. From 12121008ff08179059c067496ae6de698780bbad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 15:38:49 +0300 Subject: [PATCH 05/45] Add validate_interest expiration to mempool removeExpired --- src/txmempool.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 2dc9a4642..58cea060b 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -261,15 +261,20 @@ void CTxMemPool::removeConflicts(const CTransaction &tx, std::list } } +int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); + void CTxMemPool::removeExpired(unsigned int nBlockHeight) { + CBlockIndex *tipindex; // Remove expired txs from the mempool LOCK(cs); list transactionsToRemove; for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); - if (IsExpiredTx(tx, nBlockHeight)) { + tipindex = chainActive.Tip(); + if (IsExpiredTx(tx, nBlockHeight) || (tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,1)) < 0) + { transactionsToRemove.push_back(tx); } } From 1d1c75f4f0f30c42fc44607e1b3fdf290585c5a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 21:57:30 +0300 Subject: [PATCH 06/45] Futureblock flag --- src/main.cpp | 6 +++++- src/main.h | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bd684a6fd..4f57483de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2449,9 +2449,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin auto verifier = libzcash::ProofVerifier::Strict(); auto disabledVerifier = libzcash::ProofVerifier::Disabled(); + int32_t futureblock; // Check it again to verify JoinSplit proofs, and in case a previous version let a bad block in - if (!CheckBlock(pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck)) //!fJustCheck, !fJustCheck)) + if (!CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, fExpensiveChecks ? verifier : disabledVerifier, fCheckPOW, !fJustCheck) || futureblock != 0 ) + { + //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; + } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); diff --git a/src/main.h b/src/main.h index cb10e0168..5c7f5835c 100644 --- a/src/main.h +++ b/src/main.h @@ -450,8 +450,8 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck = false,bool fCheckPOW = false); /** Context-independent validity checks */ -bool CheckBlockHeader(int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); -bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, +bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true); +bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, libzcash::ProofVerifier& verifier, bool fCheckPOW = true, bool fCheckMerkleRoot = true); @@ -469,8 +469,8 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex * - The only caller of AcceptBlock verifies JoinSplit proofs elsewhere. * If dbp is non-NULL, the file is known to already reside on disk */ -bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp); -bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL); +bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex **pindex, bool fRequested, CDiskBlockPos* dbp); +bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex **ppindex= NULL); From 3ae9dcb4c364a02c12db60abf89cf3c578da277b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:01:53 +0300 Subject: [PATCH 07/45] More future block --- src/main.cpp | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4f57483de..08669438e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3492,7 +3492,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne return true; } -bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& blockhdr, CValidationState& state, bool fCheckPOW) +bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, const CBlockHeader& blockhdr, CValidationState& state, bool fCheckPOW) { // Check timestamp if ( 0 ) @@ -3510,9 +3510,30 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl fprintf(stderr," <- chainTip\n"); } } + *futureblockp = 0; if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) + { + CBlockIndex *tipindex; + //fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); + if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60 + 5 ) + { + //fprintf(stderr,"it is the next block, let's wait for %d seconds\n",GetAdjustedTime() + 60 - blockhdr.GetBlockTime()); + while ( blockhdr.GetBlockTime() > GetAdjustedTime() + 60 ) + sleep(1); + //fprintf(stderr,"now its valid\n"); + } + else + { + if (blockhdr.GetBlockTime() < GetAdjustedTime() + 600) + *futureblockp = 1; + LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime()); + return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); + } + } + /*if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); - else if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) + else*/ + if ( ASSETCHAINS_STAKED != 0 && pindex != 0 && pindex->pprev != 0 && pindex->nTime <= pindex->pprev->nTime ) { fprintf(stderr,"ht.%d %u vs ht.%d %u, is not monotonic\n",pindex->nHeight,pindex->nTime,pindex->pprev->nHeight,pindex->pprev->nTime); return state.Invalid(error("CheckBlockHeader(): block timestamp needs to always increase"),REJECT_INVALID, "time-too-new"); @@ -3567,7 +3588,7 @@ int32_t komodo_reverify_blockcheck(CValidationState& state,int32_t height,CBlock return(0); } -bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, +bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state, libzcash::ProofVerifier& verifier, bool fCheckPOW, bool fCheckMerkleRoot) { @@ -3746,7 +3767,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn return true; } -bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) +bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); @@ -3796,7 +3817,7 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc return true; } -bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp) +bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, CBlockIndex** ppindex, bool fRequested, CDiskBlockPos* dbp) { const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); From af58b81e17be85d4ebf369083dc5a3d015a0d60e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:05:50 +0300 Subject: [PATCH 08/45] More --- src/main.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 08669438e..994f774dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3595,12 +3595,14 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C uint8_t pubkey33[33]; // These are checks that are independent of context. - // Check that the header is valid (particularly PoW). This is mostly - // redundant with the call in AcceptBlockHeader. - if (!CheckBlockHeader(height,pindex,block,state,fCheckPOW)) + // Check that the header is valid (particularly PoW). This is mostly redundant with the call in AcceptBlockHeader. + if (!CheckBlockHeader(futureblockp,height,pindex,block,state,fCheckPOW)) { - //fprintf(stderr,"checkblockheader error PoW.%d\n",fCheckPOW); - return false; + if ( *futureblockp == 0 ) + { + LogPrintf("CheckBlock header error"); + return false; + } } if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); From 09a409ea91f985656192469f8070be7716425e97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:10:01 +0300 Subject: [PATCH 09/45] Accept block future block changes --- src/main.cpp | 98 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 994f774dd..002320365 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3771,51 +3771,93 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidationState& state, CBlockIndex** ppindex) { + static uint256 zero; const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); + // Check for duplicate uint256 hash = block.GetHash(); BlockMap::iterator miSelf = mapBlockIndex.find(hash); CBlockIndex *pindex = NULL; - if (miSelf != mapBlockIndex.end()) { + if (miSelf != mapBlockIndex.end()) + { // Block header is already known. pindex = miSelf->second; if (ppindex) *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); + /*if ( pindex != 0 && hash == komodo_requestedhash ) + { + fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); + memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); + komodo_requestedcount = 0; + }*/ + //if ( pindex == 0 ) + // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); return true; } - - if (!CheckBlockHeader(*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) + if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) { - fprintf(stderr,"CheckBlockHeader failed\n"); - return false; + if ( *futureblockp == 0 ) + { + LogPrintf("AcceptBlockHeader CheckBlockHeader error"); + return false; + } } // Get prev block index CBlockIndex* pindexPrev = NULL; - if (hash != chainparams.GetConsensus().hashGenesisBlock) { + if (hash != chainparams.GetConsensus().hashGenesisBlock) + { BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); + //fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); + /*if ( komodo_requestedhash == zero ) + { + komodo_requestedhash = block.hashPrevBlock; + komodo_requestedcount = 0; + }*/ + LogPrintf("AcceptBlockHeader hashPrevBlock %s not found",block.hashPrevBlock.ToString().c_str()); + return(false); + //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } pindexPrev = (*mi).second; - if (pindexPrev == 0 || (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) + if (pindexPrev == 0 ) + { + /*fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str()); + if ( komodo_requestedhash == zero ) + { + komodo_requestedhash = block.hashPrevBlock; + komodo_requestedcount = 0; + }*/ + LogPrintf("AcceptBlockHeader hashPrevBlock %s no pindexPrev",block.hashPrevBlock.ToString().c_str()); + return(false); + } + if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) return state.DoS(100, error("%s: prev block invalid", __func__), REJECT_INVALID, "bad-prevblk"); } if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - //fprintf(stderr,"ContextualCheckBlockHeader failed\n"); + //fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); + LogPrintf("AcceptBlockHeader ContextualCheckBlockHeader failed"); return false; } if (pindex == NULL) { if ( (pindex= AddToBlockIndex(block)) == 0 ) - fprintf(stderr,"couldnt add to block index\n"); + { + //fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n"); + } } if (ppindex) *ppindex = pindex; + /*if ( pindex != 0 && hash == komodo_requestedhash ) + { + fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); + memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); + komodo_requestedcount = 0; + }*/ return true; } @@ -3825,14 +3867,17 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C AssertLockHeld(cs_main); CBlockIndex *&pindex = *ppindex; - if (!AcceptBlockHeader(block, state, &pindex)) + if (!AcceptBlockHeader(futureblockp,block, state, &pindex)) { - //fprintf(stderr,"AcceptBlockHeader rejected\n"); - return false; + if ( *futureblockp == 0 ) + { + LogPrintf("AcceptBlock AcceptBlockHeader error"); + return false; + } } if ( pindex == 0 ) { - //fprintf(stderr,"unexpected AcceptBlock error null pindex\n"); + LogPrintf("AcceptBlock null pindex error"); return false; } //fprintf(stderr,"acceptblockheader passed\n"); @@ -3846,10 +3891,11 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // blocks which are too close in height to the tip. Apply this test // regardless of whether pruning is enabled; it should generally be safe to // not process unrequested blocks. - bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + MIN_BLOCKS_TO_KEEP)); + bool fTooFarAhead = (pindex->nHeight > int(chainActive.Height() + BLOCK_DOWNLOAD_WINDOW)); //MIN_BLOCKS_TO_KEEP)); // TODO: deal better with return value and error conditions for duplicate // and unrequested blocks. + //fprintf(stderr,"Accept %s flags already.%d requested.%d morework.%d farahead.%d\n",pindex->GetBlockHash().ToString().c_str(),fAlreadyHave,fRequested,fHasMoreWork,fTooFarAhead); if (fAlreadyHave) return true; if (!fRequested) { // If we didn't ask for it: if (pindex->nTx != 0) return true; // This is a previously-processed block that was pruned @@ -3859,18 +3905,20 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C // See method docstring for why this is always disabled auto verifier = libzcash::ProofVerifier::Disabled(); - if ((!CheckBlock(pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) + if ((!CheckBlock(futureblockp,pindex->nHeight,pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { - if (state.IsInvalid() && !state.CorruptionPossible()) { - pindex->nStatus |= BLOCK_FAILED_VALID; - setDirtyBlockIndex.insert(pindex); + if ( *futureblockp == 0 ) + { + if (state.IsInvalid() && !state.CorruptionPossible()) { + pindex->nStatus |= BLOCK_FAILED_VALID; + setDirtyBlockIndex.insert(pindex); + } + LogPrintf("AcceptBlock CheckBlock or ContextualCheckBlock error"); + return false; } - fprintf(stderr,"CheckBlock or ContextualCheckBlock failed\n"); - return false; } int nHeight = pindex->nHeight; - // Write block to history file try { unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); @@ -3890,8 +3938,10 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if (fCheckForPruning) FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files - - return true; + if ( *futureblockp == 0 ) + return true; + LogPrintf("AcceptBlock block from future error"); + return false; } static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams) From d81711c3989f0d1dae99c22efaf38e0f48a35794 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:12:58 +0300 Subject: [PATCH 10/45] komodo_ensure, process/testblock --- src/main.cpp | 69 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 002320365..e05b074ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3958,21 +3958,49 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned void komodo_currentheight_set(int32_t height); -bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) +CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) +{ + CBlockIndex *pindex; + BlockMap::iterator miSelf = mapBlockIndex.find(hash); + if ( miSelf != mapBlockIndex.end() ) + { + if ( (pindex= miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail + { + miSelf->second = AddToBlockIndex(*pblock); + //fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); + } + /*if ( hash != chainparams.GetConsensus().hashGenesisBlock ) + { + miSelf = mapBlockIndex.find(pblock->hashPrevBlock); + if ( miSelf == mapBlockIndex.end() ) + { + miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); + fprintf(stderr,"autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } + }*/ + } +} + +bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { // Preliminary checks - bool checked; + bool checked; uint256 hash; int32_t futureblock=0; auto verifier = libzcash::ProofVerifier::Disabled(); + hash = pblock->GetHash(); + //fprintf(stderr,"process newblock %s\n",hash.ToString().c_str()); if ( chainActive.Tip() != 0 ) komodo_currentheight_set(chainActive.Tip()->nHeight); - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); - else checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); + checked = CheckBlock(&futureblock,height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); { LOCK(cs_main); - bool fRequested = MarkBlockAsReceived(pblock->GetHash()); + bool fRequested = MarkBlockAsReceived(hash); fRequested |= fForceProcessing; - if (!checked) + if ( checked != 0 && komodo_checkPOW(from_miner && ASSETCHAINS_STAKED == 0,pblock,height) < 0 ) + { + checked = 0; + fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0); + } + if (!checked && futureblock == 0) { if ( pfrom != 0 ) { @@ -3980,19 +4008,23 @@ bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBloc } return error("%s: CheckBlock FAILED", __func__); } - // Store to disk CBlockIndex *pindex = NULL; - bool ret = AcceptBlock(*pblock, state, &pindex, fRequested, dbp); + { + // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync + komodo_ensure(pblock,hash); + } + bool ret = AcceptBlock(&futureblock,*pblock, state, &pindex, fRequested, dbp); if (pindex && pfrom) { mapBlockSource[pindex->GetBlockHash()] = pfrom->GetId(); } CheckBlockIndex(); - if (!ret) + if (!ret && futureblock == 0) return error("%s: AcceptBlock FAILED", __func__); + //else fprintf(stderr,"added block %s %p\n",pindex->GetBlockHash().ToString().c_str(),pindex->pprev); } - if (!ActivateBestChain(state, pblock)) + if (futureblock == 0 && !ActivateBestChain(state, pblock)) return error("%s: ActivateBestChain failed", __func__); return true; @@ -4009,30 +4041,31 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex indexDummy.nHeight = pindexPrev->nHeight + 1; // JoinSplit proofs are verified in ConnectBlock auto verifier = libzcash::ProofVerifier::Disabled(); - // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - fprintf(stderr,"TestBlockValidity failure A\n"); + //fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW); return false; } - if (!CheckBlock(indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) + int32_t futureblock; + if (!CheckBlock(&futureblock,indexDummy.nHeight,0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { - //fprintf(stderr,"TestBlockValidity failure B\n"); + //fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); return false; } if (!ContextualCheckBlock(block, state, pindexPrev)) { - //fprintf(stderr,"TestBlockValidity failure C\n"); + //fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { - fprintf(stderr,"TestBlockValidity failure D\n"); + //fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW); return false; } assert(state.IsValid()); - + if ( futureblock != 0 ) + return(false); return true; } From ed5ef86613b684e68f79c923e258c8e44edcc29a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:15:42 +0300 Subject: [PATCH 11/45] komodo_POW --- src/main.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e05b074ac..b04a2f074 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3592,7 +3592,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C libzcash::ProofVerifier& verifier, bool fCheckPOW, bool fCheckMerkleRoot) { - uint8_t pubkey33[33]; + uint8_t pubkey33[33]; uint256 hash; // These are checks that are independent of context. // Check that the header is valid (particularly PoW). This is mostly redundant with the call in AcceptBlockHeader. @@ -3604,11 +3604,26 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C return false; } } - if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) + if ( fCheckPOW ) + { + //if ( !CheckEquihashSolution(&block, Params()) ) + // return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); + komodo_block2pubkey33(pubkey33,(CBlock *)&block); + if ( !CheckProofOfWork(height,pubkey33,hash,block.nBits,Params().GetConsensus(),block.nTime) ) + { + int32_t z; for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hash)[z]); + fprintf(stderr," failed hash ht.%d\n",height); + return state.DoS(50, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash"); + } + if ( komodo_checkPOW(1,(CBlock *)&block,height) < 0 ) // checks Equihash + return state.DoS(100, error("CheckBlock: failed slow_checkPOW"),REJECT_INVALID, "failed-slow_checkPOW"); + } + /*if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) ) return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution"); komodo_block2pubkey33(pubkey33,(CBlock *)&block); if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime) ) - return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash"); + return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash");*/ // Check the merkle root. if (fCheckMerkleRoot) { bool mutated; From b2b5381f521463467954abd33f842e2ee29f620a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:16:49 +0300 Subject: [PATCH 12/45] Add hash --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b04a2f074..a32f1d492 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3594,7 +3594,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { uint8_t pubkey33[33]; uint256 hash; // These are checks that are independent of context. - + hash = block.GetHash(); + // Check that the header is valid (particularly PoW). This is mostly redundant with the call in AcceptBlockHeader. if (!CheckBlockHeader(futureblockp,height,pindex,block,state,fCheckPOW)) { From 6bf62671eb8043b043a489f69eff109d1b4ddd58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:18:34 +0300 Subject: [PATCH 13/45] komodo_checkPOW functions --- src/komodo_bitcoind.h | 310 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 310 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3d569577f..37fc87150 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1031,3 +1031,313 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ return(0); } + +/* + komodo_checkPOW (fast) is called early in the process and should only refer to data immediately available. it is a filter to prevent bad blocks from going into the local DB. The more blocks we can filter out at this stage, the less junk in the local DB that will just get purged later on. + + komodo_checkPOW (slow) is called right before connecting blocks so all prior blocks can be assumed to be there and all checks must pass + + 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] + PoW mining on PoS chain must solve a harder diff that adjusts, but never less than KOMODO_POWMINMULT + */ +#define KOMODO_POWMINMULT 16 + +uint64_t komodo_commission(const CBlock *pblock) +{ + int32_t i,j,n=0,txn_count; uint64_t commission,total = 0; + txn_count = pblock->vtx.size(); + for (i=0; ivtx[i].vout.size(); + for (j=0; jvtx[i].vout[j].nValue; + } + } + //fprintf(stderr,"txn.%d n.%d commission total %.8f -> %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); + commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + if ( commission < 10000 ) + commission = 0; + return(commission); +} + +uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) +{ + CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + txtime = komodo_txtime(&value,txid,vout,address); + if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) + return(0); + if ( (minage= nHeight*3) > 6000 ) + minage = 6000; + if ( blocktime < prevtime+57 ) + blocktime = prevtime+57; + if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) + { + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + segid = ((nHeight + addrhash.uints[0]) & 0x3f); + pasthash = pindex->GetBlockHash(); + memcpy(hashbuf,&pasthash,sizeof(pasthash)); + memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); + //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); + for (iter=0; iter<3600; iter++) + { + diff = (iter + blocktime - txtime - minage); + if ( diff > 3600*24 ) + break; + coinage = (value * diff) * ((diff >> 16) + 1); + hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); + if ( hashval <= bnTarget ) + { + winner = 1; + if ( validateflag == 0 ) + { + blocktime += iter; + blocktime += segid * 2; + } + break; + } + if ( validateflag != 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs target "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff); + break; + } + } + //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); + if ( 0 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); + } + } + if ( nHeight < 2 ) + return(blocktime); + return(blocktime * winner); +} + +arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) +{ + CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; + *percPoSp = percPoS = 0; + if ( height < 3 ) + return(target); + sum = arith_uint256(0); + ave = sum; + for (i=n=0; i<100; i++) + { + ht = height - 100 + i; + if ( (pindex= komodo_chainactive(ht)) != 0 ) + { + bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); + bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); + hashval = UintToArith256(pindex->GetBlockHash()); + if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW + { + fprintf(stderr,"1"); + sum += hashval; + n++; + } + else + { + percPoS++; + fprintf(stderr,"0"); + } + if ( (i % 10) == 9 ) + fprintf(stderr," %d, ",percPoS); + } + } + fprintf(stderr," -> %d%% percPoS ht.%d\n",percPoS,height); + *percPoSp = percPoS; + target = (target / arith_uint256(KOMODO_POWMINMULT)); + if ( n > 0 ) + { + ave = (sum / arith_uint256(n)); + if ( ave > target ) + ave = target; + } else return(target); + if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget + { + bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((goalperc) * (goalperc)); + /*if ( height > 1165 ) + { + if ( height > 1180 ) + { + if ( height > 1230 ) + bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((goalperc) * (goalperc)); + else bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc); + } + else bnTarget = (ave * arith_uint256(goalperc * goalperc)) / arith_uint256(2 * (percPoS + goalperc) * (percPoS + goalperc)); + } else bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc);*/ + if ( 1 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," increase diff -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } + } + else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget + { + bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + if ( 1 ) + { + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); + fprintf(stderr," decrease diff -> "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," floor diff "); + for (i=31; i>=24; i--) + fprintf(stderr,"%02x",((uint8_t *)&target)[i]); + fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); + } + } + else bnTarget = ave; // recent ave is perfect + return(bnTarget); +} + +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; + txn_count = pblock->vtx.size(); + if ( txn_count > 1 ) + { + if ( prevtime == 0 ) + { + if ( (previndex= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) + prevtime = (uint32_t)previndex->nTime; + } + txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; + 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 ( 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)); + } else isPoS = 1; + } + else if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx + { + 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 return(-1); + } + return(isPoS); +} + +int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) +{ + uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; + if ( !CheckEquihashSolution(pblock, Params()) ) + { + fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); + return(-1); + } + hash = pblock->GetHash(); + bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + bhash = UintToArith256(hash); + possible = komodo_block2pubkey33(pubkey33,pblock); + //fprintf(stderr,"height.%d slowflag.%d possible.%d cmp.%d\n",height,slowflag,possible,bhash > bnTarget); + if ( height == 0 ) + { + if ( slowflag != 0 ) + return(0); + if ( (pprev= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) + height = pprev->nHeight + 1; + if ( height == 0 ) + return(0); + } + if ( (ASSETCHAINS_SYMBOL[0] != 0 || height > 792000) && bhash > bnTarget ) + { + failed = 1; + if ( height > 0 && ASSETCHAINS_SYMBOL[0] == 0 ) // for the fast case + { + if ( (n= komodo_notaries(pubkeys,height,pblock->nTime)) > 0 ) + { + for (i=0; i= 2 ) // must PoS or have at least 16x better PoW + { + if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) + { + if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! + return(-1); + else + { + if ( slowflag != 0 ) + bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); + else bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound + if ( bhash > bnTarget ) + { + for (i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bhash)[i]); + fprintf(stderr," > "); + for (i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED); + return(-1); + } + } + } else if ( is_PoSblock < 0 ) + return(-1); + } + if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + { + checktoshis = komodo_commission(pblock); + if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) + return(-1); + else if ( checktoshis != 0 ) + { + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + return(-1); + if ( pblock->vtx[0].vout[1].nValue != checktoshis ) + { + fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); + return(-1); + } + } + } + //fprintf(stderr,"komodo_checkPOW possible.%d slowflag.%d ht.%d notaryid.%d failed.%d\n",possible,slowflag,height,notaryid,failed); + if ( failed != 0 && possible == 0 && notaryid < 0 ) + return(-1); + else return(0); +} + + From 753b841f99650264f556516fa556ebf06823670e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:31:28 +0300 Subject: [PATCH 14/45] Move POW code around --- src/komodo_bitcoind.h | 6 +- src/komodo_gateway.h | 147 ------------------------------------------ src/main.cpp | 10 +-- 3 files changed, 11 insertions(+), 152 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 37fc87150..a7142de10 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -659,7 +659,7 @@ int32_t komodo_block2height(CBlock *block) return(height); } -void komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block) +int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block) { int32_t n; if ( KOMODO_LOADINGBLOCKS == 0 ) @@ -675,8 +675,12 @@ void komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block) //komodo_init(0); n = block->vtx[0].vout[0].scriptPubKey.size(); if ( n == 35 ) + { memcpy(pubkey33,ptr+1,33); + return(1); + } } + return(0); } int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 72f36a21c..0f3baf50f 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -650,153 +650,6 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) void komodo_passport_iteration(); -uint64_t komodo_commission(const CBlock &block) -{ - int32_t i,j,n=0,txn_count; uint64_t total = 0; - txn_count = block.vtx.size(); - for (i=0; i %.8f\n",txn_count,n,dstr(total),dstr((total * ASSETCHAINS_COMMISSION) / COIN)); - return((total * ASSETCHAINS_COMMISSION) / COIN); -} - -uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) -{ - CBlockIndex *pindex; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - txtime = komodo_txtime(&value,txid,vout,address); - if ( value == 0 || txtime == 0 ) - return(0); - if ( (minage= nHeight*3) > 6000 ) - minage = 6000; - if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) - { - vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); - segid = ((nHeight + addrhash.uints[0]) & 0x3f); - pasthash = pindex->GetBlockHash(); - memcpy(hashbuf,&pasthash,sizeof(pasthash)); - memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash)); - vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); - //fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime); - for (iter=0; iter<3600; iter++) - { - diff = (iter + blocktime - txtime - minage); - if ( diff > 3600*24 ) - break; - coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); - if ( hashval <= bnTarget ) - { - winner = 1; - if ( validateflag == 0 ) - { - blocktime += iter; - blocktime += segid * 2; - } - break; - } - if ( validateflag != 0 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs target "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff); - break; - } - } - //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff); - } - } - if ( nHeight < 2 ) - return(blocktime); - return(blocktime * winner); -} - -#define KOMODO_POWMINMULT 16 -arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) -{ - CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff; - *percPoSp = percPoS = 0; - sum = arith_uint256(0); - ave = sum; - for (i=n=0; i<100; i++) - { - ht = height - 100 + i; - if ( (pindex= komodo_chainactive(ht)) != 0 ) - { - bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); - bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); - hashval = UintToArith256(pindex->GetBlockHash()); - if ( hashval <= bnTarget ) // PoW is never as easy as PoS/64, some PoS will be counted as PoW - { - sum += hashval; - n++; - } else percPoS++; - } - } - *percPoSp = percPoS; - target = (target / arith_uint256(KOMODO_POWMINMULT)); - if ( n > 0 ) - { - ave = (sum / arith_uint256(n)); - if ( ave > target ) - ave = target; - } else return(target); - if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget - { - bnTarget = (ave * arith_uint256(goalperc)) / arith_uint256(percPoS + goalperc); - if ( 1 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," increase diff -> "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&target)[i]); - fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); - } - } - else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget - { - bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); - if ( 1 ) - { - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); - fprintf(stderr," decrease diff -> "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," floor diff "); - for (i=31; i>=24; i--) - fprintf(stderr,"%02x",((uint8_t *)&target)[i]); - fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); - } - } - else bnTarget = ave; // recent ave is perfect - return(bnTarget); -} - int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; diff --git a/src/main.cpp b/src/main.cpp index a32f1d492..b4f8ae091 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,7 +55,7 @@ CCriticalSection cs_main; extern uint8_t NOTARY_PUBKEY33[33]; extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN; int32_t KOMODO_NEWBLOCKS; -void komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); +int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); BlockMap mapBlockIndex; CChain chainActive; @@ -4473,7 +4473,8 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth if (!ReadBlockFromDisk(block, pindex)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 1: verify block validity - if (nCheckLevel >= 1 && !CheckBlock(pindex->nHeight,pindex,block, state, verifier,0)) + int32_t futureblock; + if (nCheckLevel >= 1 && !CheckBlock(&futureblock,pindex->nHeight,pindex,block, state, verifier,0)) return error("VerifyDB(): *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 2: verify undo validity if (nCheckLevel >= 2 && pindex) { @@ -5870,9 +5871,10 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, Misbehaving(pfrom->GetId(), 20); return error("non-continuous headers sequence"); } - if (!AcceptBlockHeader(header, state, &pindexLast)) { + int32_t futureblock; + if (!AcceptBlockHeader(&futureblock,header, state, &pindexLast)) { int nDoS; - if (state.IsInvalid(nDoS)) + if (state.IsInvalid(nDoS) && futureblock == 0) { if (nDoS > 0) Misbehaving(pfrom->GetId(), nDoS/nDoS); From bab6d6ab0c9abe69abb267d8098eb17cc31dd53e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:32:56 +0300 Subject: [PATCH 15/45] Update check deposit code --- src/komodo_gateway.h | 57 ++------------------------------------------ 1 file changed, 2 insertions(+), 55 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0f3baf50f..ab114e892 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -707,7 +707,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( overflow != 0 || total > COIN/10 ) { - //fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); + fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); if ( height >= activation ) return(-1); } @@ -720,65 +720,12 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } else { - if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) - { - arith_uint256 bnTarget,hashval; int32_t PoSperc; bool fNegative,fOverflow; CBlockIndex *previndex; uint32_t eligible,isPoS = 0; - bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow); - if ( txn_count > 1 ) - { - if ( prevtime == 0 ) - { - if ( (previndex= mapBlockIndex[block.hashPrevBlock]) != 0 ) - prevtime = (uint32_t)previndex->nTime; - } - eligible = komodo_stake(1,bnTarget,height,block.vtx[txn_count-1].vin[0].prevout.hash,block.vtx[txn_count-1].vin[0].prevout.n,block.nTime,prevtime,(char *)""); - if ( eligible == 0 || eligible > block.nTime ) - { - fprintf(stderr,"PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)block.nTime,(int32_t)(eligible - block.nTime)); - } else isPoS = 1; - } - if ( isPoS == 0 && height > 100 ) - { - if ( ASSETCHAINS_STAKED == 100 ) - { - fprintf(stderr,"ht.%d 100%% PoS after height 100 rule violated for -ac_staking=100\n",height); - return(-1); - } - // check PoW - bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - hashval = UintToArith256(block.GetHash()); - if ( hashval > bnTarget ) - { - /*for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," > "); - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," ht.%d PoW diff violation PoSperc.%d vs goalperc.%d\n",height,PoSperc,(int32_t)ASSETCHAINS_STAKED);*/ - return(-1); - } - } - } - if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) - { - script = (uint8_t *)block.vtx[0].vout[1].scriptPubKey.data(); - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) - return(-1); - if ( (checktoshis = komodo_commission(block)) != 0 ) - { - if ( block.vtx[0].vout[1].nValue != checktoshis ) - { - fprintf(stderr,"checktoshis %.8f vs actual vout[1] %.8f\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue)); - return(-1); - } else return(0); - } - } if ( overflow != 0 || total > 0 ) return(-1); } return(0); } -/* + /* //fprintf(stderr,"ht.%d n.%d nValue %.8f (%d %d %d)\n",height,n,dstr(block.vtx[0].vout[1].nValue),KOMODO_PAX,komodo_isrealtime(&ht),KOMODO_PASSPORT_INITDONE); offset += komodo_scriptitemlen(&opretlen,&script[offset]); //printf("offset.%d opretlen.%d [%02x %02x %02x %02x]\n",offset,opretlen,script[0],script[1],script[2],script[3]); From b8d0ed28eacf064ae1c40ad1c213699fa252e795 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:37:06 +0300 Subject: [PATCH 16/45] Fix --- src/main.cpp | 2 +- src/miner.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b4f8ae091..a0fdd7c7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2608,7 +2608,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && block.vtx[0].vout.size() > 1 ) { uint64_t checktoshis; - if ( (checktoshis = komodo_commission(block)) != 0 ) + if ( (checktoshis= komodo_commission((const CBlock *)&block)) != 0 ) { if ( block.vtx[0].vout.size() == 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; diff --git a/src/miner.cpp b/src/miner.cpp index 7af581439..b79a1dccd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -119,7 +119,7 @@ int32_t komodo_is_issuer(); int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t tokomodo); int32_t komodo_isrealtime(int32_t *kmdheightp); int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); -uint64_t komodo_commission(const CBlock &block); +uint64_t komodo_commission(const CBlock *block); int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) @@ -454,7 +454,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) }*/ pblock->vtx[0] = txNew; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission(pblocktemplate->block)) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock *)pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); From b04e28042ddca99fcc3fb8081f14f3fdd795dc38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:38:24 +0300 Subject: [PATCH 17/45] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index b79a1dccd..f29f18ccf 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -454,7 +454,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) }*/ pblock->vtx[0] = txNew; - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock *)pblocktemplate->block)) != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock *)&pblocktemplate->block)) != 0 ) { int32_t i; uint8_t *ptr; txNew.vout.resize(2); From 70c6301c924bd7b332b501ac9782037cc2676eb1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 22:58:35 +0300 Subject: [PATCH 18/45] Syntax --- src/main.cpp | 6 +++--- src/main.h | 2 +- src/miner.cpp | 2 +- src/rpcmining.cpp | 4 ++-- src/test/miner_tests.cpp | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a0fdd7c7b..537fbfae9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4809,7 +4809,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) // process in case the block isn't known yet if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) { CValidationState state; - if (ProcessNewBlock(0,state, NULL, &block, true, dbp)) + if (ProcessNewBlock(0,0,state, NULL, &block, true, dbp)) nLoaded++; if (state.IsError()) break; @@ -4831,7 +4831,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp) LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(), head.ToString()); CValidationState dummy; - if (ProcessNewBlock(0,dummy, NULL, &block, true, &it->second)) + if (ProcessNewBlock(0,0,dummy, NULL, &block, true, &it->second)) { nLoaded++; queue.push_back(block.GetHash()); @@ -5917,7 +5917,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // Such an unrequested block may still be processed, subject to the // conditions in AcceptBlock(). bool forceProcessing = pfrom->fWhitelisted && !IsInitialBlockDownload(); - ProcessNewBlock(0,state, pfrom, &block, forceProcessing, NULL); + ProcessNewBlock(0,0,state, pfrom, &block, forceProcessing, NULL); int nDoS; if (state.IsInvalid(nDoS)) { pfrom->PushMessage("reject", strCommand, state.GetRejectCode(), diff --git a/src/main.h b/src/main.h index 5c7f5835c..0f1ad0d03 100644 --- a/src/main.h +++ b/src/main.h @@ -183,7 +183,7 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals); * @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location. * @return True if state.IsValid() */ -bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp); +bool ProcessNewBlock(int32_t from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp); /** Check whether enough disk space is available for an incoming block */ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); /** Open a block file (blk?????.dat) */ diff --git a/src/miner.cpp b/src/miner.cpp index f29f18ccf..8a56b72d1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -655,7 +655,7 @@ static bool ProcessBlockFound(CBlock* pblock) // Process this block the same as if we had received it from another node CValidationState state; - if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index d141c42c4..4bc37041a 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -267,7 +267,7 @@ UniValue generate(const UniValue& params, bool fHelp) } endloop: CValidationState state; - if (!ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); ++nHeight; blockHashes.push_back(pblock->GetHash().GetHex()); @@ -807,7 +807,7 @@ UniValue submitblock(const UniValue& params, bool fHelp) CValidationState state; submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - bool fAccepted = ProcessNewBlock(chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); + bool fAccepted = ProcessNewBlock(1,0,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); UnregisterValidationInterface(&sc); if (fBlockPresent) { diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 9b8674f04..7866d3ac1 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -242,7 +242,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) CValidationState state; - if (ProcessNewBlock(state, NULL, pblock, true, NULL) && state.IsValid()) { + if (ProcessNewBlock(1,0,state, NULL, pblock, true, NULL) && state.IsValid()) { goto foundit; } @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) */ CValidationState state; - BOOST_CHECK(ProcessNewBlock(state, NULL, pblock, true, NULL)); + BOOST_CHECK(ProcessNewBlock(1,0,state, NULL, pblock, true, NULL)); BOOST_CHECK_MESSAGE(state.IsValid(), state.GetRejectReason()); pblock->hashPrevBlock = pblock->GetHash(); From 8a1b1894bca4c730457434ef8e1a3a801b93ffc7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 23:01:03 +0300 Subject: [PATCH 19/45] Test --- src/rpcmining.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 4bc37041a..aea5694f2 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -807,7 +807,7 @@ UniValue submitblock(const UniValue& params, bool fHelp) CValidationState state; submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - bool fAccepted = ProcessNewBlock(1,0,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); + bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); UnregisterValidationInterface(&sc); if (fBlockPresent) { From c1029e9df4e32c84e744a0a532b8a3edcf591e52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 23:07:12 +0300 Subject: [PATCH 20/45] Test --- src/main.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.h b/src/main.h index 0f1ad0d03..4035de136 100644 --- a/src/main.h +++ b/src/main.h @@ -183,7 +183,7 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals); * @param[out] dbp If pblock is stored to disk (or already there), this will be set to its location. * @return True if state.IsValid() */ -bool ProcessNewBlock(int32_t from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp); +bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp); /** Check whether enough disk space is available for an incoming block */ bool CheckDiskSpace(uint64_t nAdditionalBytes = 0); /** Open a block file (blk?????.dat) */ From 9ffe5e947bd34404ca94930a30bac7339a757acf Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 23:15:57 +0300 Subject: [PATCH 21/45] Latest pindex autocrat --- src/main.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 537fbfae9..71988b129 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3526,7 +3526,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, { if (blockhdr.GetBlockTime() < GetAdjustedTime() + 600) *futureblockp = 1; - LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime()); + LogPrintf("CheckBlockHeader block from future %d error\n",blockhdr.GetBlockTime() - GetAdjustedTime()); return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); } } @@ -3601,7 +3601,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { if ( *futureblockp == 0 ) { - LogPrintf("CheckBlock header error"); + LogPrintf("CheckBlock header error\n"); return false; } } @@ -3817,7 +3817,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat { if ( *futureblockp == 0 ) { - LogPrintf("AcceptBlockHeader CheckBlockHeader error"); + LogPrintf("AcceptBlockHeader CheckBlockHeader error\n"); return false; } } @@ -3834,7 +3834,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; }*/ - LogPrintf("AcceptBlockHeader hashPrevBlock %s not found",block.hashPrevBlock.ToString().c_str()); + LogPrintf("AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); } @@ -3847,7 +3847,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat komodo_requestedhash = block.hashPrevBlock; komodo_requestedcount = 0; }*/ - LogPrintf("AcceptBlockHeader hashPrevBlock %s no pindexPrev",block.hashPrevBlock.ToString().c_str()); + LogPrintf("AcceptBlockHeader hashPrevBlock %s no pindexPrev\n",block.hashPrevBlock.ToString().c_str()); return(false); } if ( (pindexPrev->nStatus & BLOCK_FAILED_MASK) ) @@ -3856,7 +3856,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { //fprintf(stderr,"AcceptBlockHeader ContextualCheckBlockHeader failed\n"); - LogPrintf("AcceptBlockHeader ContextualCheckBlockHeader failed"); + LogPrintf("AcceptBlockHeader ContextualCheckBlockHeader failed\n"); return false; } if (pindex == NULL) @@ -3887,14 +3887,18 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C { if ( *futureblockp == 0 ) { - LogPrintf("AcceptBlock AcceptBlockHeader error"); + LogPrintf("AcceptBlock AcceptBlockHeader error\n"); return false; } } if ( pindex == 0 ) { - LogPrintf("AcceptBlock null pindex error"); - return false; + *ppindex = pindex = AddToBlockIndex(block); + if ( pindex == 0 ) + { + LogPrintf("AcceptBlock null pindex error\n"); + return false; + } } //fprintf(stderr,"acceptblockheader passed\n"); // Try to process all requested blocks that we don't have, but only @@ -3929,7 +3933,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C pindex->nStatus |= BLOCK_FAILED_VALID; setDirtyBlockIndex.insert(pindex); } - LogPrintf("AcceptBlock CheckBlock or ContextualCheckBlock error"); + LogPrintf("AcceptBlock CheckBlock or ContextualCheckBlock error\n"); return false; } } @@ -3956,7 +3960,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files if ( *futureblockp == 0 ) return true; - LogPrintf("AcceptBlock block from future error"); + LogPrintf("AcceptBlock block from future error\n"); return false; } @@ -3985,15 +3989,15 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) miSelf->second = AddToBlockIndex(*pblock); //fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); } - /*if ( hash != chainparams.GetConsensus().hashGenesisBlock ) - { - miSelf = mapBlockIndex.find(pblock->hashPrevBlock); - if ( miSelf == mapBlockIndex.end() ) - { - miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); - fprintf(stderr,"autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); - } - }*/ + if ( hash != Params().GetConsensus().hashGenesisBlock ) + { + miSelf = mapBlockIndex.find(pblock->hashPrevBlock); + if ( miSelf == mapBlockIndex.end() ) + { + miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); + LogPrintf("autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } + } } } From e0ed9dca91c48fa07e24fab56e0def411f9d8b85 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 23:18:08 +0300 Subject: [PATCH 22/45] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 71988b129..9f5d23ff9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4233,7 +4233,7 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) while ( fread(ignore,1,incr,file) == incr ) fprintf(stderr,"."); free(ignore); - fprintf(stderr,"blk.%d loaded %ld bytes set fpos.%ld loading.%d\n",(int)pos.nFile,(long)ftell(file),(long)fpos,KOMODO_LOADINGBLOCKS); + //fprintf(stderr,"blk.%d loaded %ld bytes set fpos.%ld loading.%d\n",(int)pos.nFile,(long)ftell(file),(long)fpos,KOMODO_LOADINGBLOCKS); } } fseek(file,fpos,SEEK_SET); From 12c4543d51ebacaae60824a54f394d091f3ec565 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 23:50:45 +0300 Subject: [PATCH 23/45] Fix komodo_ensure --- src/main.cpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9f5d23ff9..63afcc656 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3893,12 +3893,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C } if ( pindex == 0 ) { - *ppindex = pindex = AddToBlockIndex(block); - if ( pindex == 0 ) - { - LogPrintf("AcceptBlock null pindex error\n"); - return false; - } + LogPrintf("AcceptBlock null pindex error\n"); + return false; } //fprintf(stderr,"acceptblockheader passed\n"); // Try to process all requested blocks that we don't have, but only @@ -3980,25 +3976,42 @@ void komodo_currentheight_set(int32_t height); CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) { - CBlockIndex *pindex; + CBlockIndex *pindex=0,*previndex=0; BlockMap::iterator miSelf = mapBlockIndex.find(hash); - if ( miSelf != mapBlockIndex.end() ) + if ( miSelf == mapBlockIndex.end() ) { - if ( (pindex= miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail + pindex = InsertBlockIndex(hash); + LogPrintf("autocreate pindex %s\n",hash.ToString().c_str()); + } + if ( (miSelf= mapBlockIndex.find(hash)) != mapBlockIndex.end() ) + { + if ( miSelf->second == 0 ) // create pindex so first Accept block doesnt fail { - miSelf->second = AddToBlockIndex(*pblock); - //fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); + if ( pindex == 0 ) + pindex = AddToBlockIndex(*pblock); + if ( pindex != 0 ) + { + miSelf->second = pindex; + LogPrintf("Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); + } else LogPrintf("komodo_ensure unexpected null pindex\n"); } if ( hash != Params().GetConsensus().hashGenesisBlock ) { miSelf = mapBlockIndex.find(pblock->hashPrevBlock); if ( miSelf == mapBlockIndex.end() ) + previndex = InsertBlockIndex(pblock->hashPrevBlock); + if ( (miSelf= mapBlockIndex.find(pblock->hashPrevBlock)) != mapBlockIndex.end() ) { - miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); - LogPrintf("autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); - } + if ( previndex == 0 ) + previndex = InsertBlockIndex(pblock->hashPrevBlock); + if ( previndex != 0 ) + { + miSelf->second = previndex; + LogPrintf("autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } else LogPrintf("komodo_ensure unexpected null previndex\n"); + } else LogPrintf("komodo_ensure unexpected null miprev\n"); } - } + } else LogPrintf("komodo_ensure unexpected error creating pindex %s\n",hash.ToString().c_str()); } bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) From 223fbb65cb19d61e5facac30cdba280dd8f72aee Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 24 Apr 2018 23:56:42 +0300 Subject: [PATCH 24/45] Fix komodo_ensure --- src/komodo_gateway.h | 2 +- src/main.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ab114e892..ce51746f7 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1772,7 +1772,7 @@ void komodo_passport_iteration() if ( expired == 0 && KOMODO_PASSPORT_INITDONE == 0 ) { KOMODO_PASSPORT_INITDONE = 1; - printf("done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid); + printf("READY for RPC calls at %u! done PASSPORT %s refid.%d\n",(uint32_t)time(NULL),ASSETCHAINS_SYMBOL,refid); } } diff --git a/src/main.cpp b/src/main.cpp index 63afcc656..214831fe7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4002,13 +4002,16 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) previndex = InsertBlockIndex(pblock->hashPrevBlock); if ( (miSelf= mapBlockIndex.find(pblock->hashPrevBlock)) != mapBlockIndex.end() ) { - if ( previndex == 0 ) - previndex = InsertBlockIndex(pblock->hashPrevBlock); - if ( previndex != 0 ) + if ( miSelf->second == 0 ) // create pindex so first Accept block doesnt fail { - miSelf->second = previndex; - LogPrintf("autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); - } else LogPrintf("komodo_ensure unexpected null previndex\n"); + if ( previndex == 0 ) + previndex = InsertBlockIndex(pblock->hashPrevBlock); + if ( previndex != 0 ) + { + miSelf->second = previndex; + LogPrintf("autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } else LogPrintf("komodo_ensure unexpected null previndex\n"); + } } else LogPrintf("komodo_ensure unexpected null miprev\n"); } } else LogPrintf("komodo_ensure unexpected error creating pindex %s\n",hash.ToString().c_str()); From 6b619d6edfe755d53ba8e1a1a97474610597b37d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 00:20:58 +0300 Subject: [PATCH 25/45] Test --- src/main.cpp | 65 ++++++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 214831fe7..0653c6d59 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3977,44 +3977,45 @@ void komodo_currentheight_set(int32_t height); CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) { CBlockIndex *pindex=0,*previndex=0; + if ( (pindex= mapBlockIndex[hash]) == 0 ) + pindex = InsertBlockIndex(hash); BlockMap::iterator miSelf = mapBlockIndex.find(hash); if ( miSelf == mapBlockIndex.end() ) { - pindex = InsertBlockIndex(hash); - LogPrintf("autocreate pindex %s\n",hash.ToString().c_str()); + LogPrintf("komodo_ensure unexpected missing hash %s\n",hash.ToString().c_str()); + return(0); } - if ( (miSelf= mapBlockIndex.find(hash)) != mapBlockIndex.end() ) + if ( miSelf->second == 0 ) // create pindex so first Accept block doesnt fail { - if ( miSelf->second == 0 ) // create pindex so first Accept block doesnt fail + if ( pindex == 0 ) + pindex = AddToBlockIndex(*pblock); + if ( pindex != 0 ) { - if ( pindex == 0 ) - pindex = AddToBlockIndex(*pblock); - if ( pindex != 0 ) - { - miSelf->second = pindex; - LogPrintf("Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); - } else LogPrintf("komodo_ensure unexpected null pindex\n"); - } - if ( hash != Params().GetConsensus().hashGenesisBlock ) - { - miSelf = mapBlockIndex.find(pblock->hashPrevBlock); - if ( miSelf == mapBlockIndex.end() ) - previndex = InsertBlockIndex(pblock->hashPrevBlock); - if ( (miSelf= mapBlockIndex.find(pblock->hashPrevBlock)) != mapBlockIndex.end() ) - { - if ( miSelf->second == 0 ) // create pindex so first Accept block doesnt fail - { - if ( previndex == 0 ) - previndex = InsertBlockIndex(pblock->hashPrevBlock); - if ( previndex != 0 ) - { - miSelf->second = previndex; - LogPrintf("autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); - } else LogPrintf("komodo_ensure unexpected null previndex\n"); - } - } else LogPrintf("komodo_ensure unexpected null miprev\n"); - } - } else LogPrintf("komodo_ensure unexpected error creating pindex %s\n",hash.ToString().c_str()); + miSelf->second = pindex; + LogPrintf("Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); + } else LogPrintf("komodo_ensure unexpected null pindex\n"); + } + /*if ( hash != Params().GetConsensus().hashGenesisBlock ) + { + miSelf = mapBlockIndex.find(pblock->hashPrevBlock); + if ( miSelf == mapBlockIndex.end() ) + previndex = InsertBlockIndex(pblock->hashPrevBlock); + if ( (miSelf= mapBlockIndex.find(pblock->hashPrevBlock)) != mapBlockIndex.end() ) + { + if ( miSelf->second == 0 ) // create pindex so first Accept block doesnt fail + { + if ( previndex == 0 ) + previndex = InsertBlockIndex(pblock->hashPrevBlock); + if ( previndex != 0 ) + { + miSelf->second = previndex; + LogPrintf("autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } else LogPrintf("komodo_ensure unexpected null previndex\n"); + } + } else LogPrintf("komodo_ensure unexpected null miprev\n"); + } + }*/ + return(pindex); } bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) From 6fa7fd0c164fb6023fd8804275faadf97b95c664 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 00:35:20 +0300 Subject: [PATCH 26/45] Test --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0653c6d59..0fea9553a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3978,7 +3978,13 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) { CBlockIndex *pindex=0,*previndex=0; if ( (pindex= mapBlockIndex[hash]) == 0 ) - pindex = InsertBlockIndex(hash); + { + pindex = new CBlockIndex(); + if (!pindex) + throw runtime_error("komodo_ensure: new CBlockIndex failed"); + mi = mapBlockIndex.insert(make_pair(hash, pindexN)).first; + pindex->phashBlock = &((*mi).first); + } BlockMap::iterator miSelf = mapBlockIndex.find(hash); if ( miSelf == mapBlockIndex.end() ) { @@ -3988,7 +3994,10 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) if ( miSelf->second == 0 ) // create pindex so first Accept block doesnt fail { if ( pindex == 0 ) + { pindex = AddToBlockIndex(*pblock); + fprintf(stderr,"ensure call addtoblockindex, got %p\n",pindex); + } if ( pindex != 0 ) { miSelf->second = pindex; From 4cbd837c0b0b5343afbd32929384e279c379d2e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 00:40:07 +0300 Subject: [PATCH 27/45] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0fea9553a..a606d9c0b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3982,7 +3982,7 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) pindex = new CBlockIndex(); if (!pindex) throw runtime_error("komodo_ensure: new CBlockIndex failed"); - mi = mapBlockIndex.insert(make_pair(hash, pindexN)).first; + mi = mapBlockIndex.insert(make_pair(hash, pindex)).first; pindex->phashBlock = &((*mi).first); } BlockMap::iterator miSelf = mapBlockIndex.find(hash); From 9a26ff906cd46925036ba9e44131207d4edf232a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 00:42:36 +0300 Subject: [PATCH 28/45] Test --- src/main.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a606d9c0b..182a2cfee 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3982,7 +3982,7 @@ CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) pindex = new CBlockIndex(); if (!pindex) throw runtime_error("komodo_ensure: new CBlockIndex failed"); - mi = mapBlockIndex.insert(make_pair(hash, pindex)).first; + BlockMap::iterator mi = mapBlockIndex.insert(make_pair(hash, pindex)).first; pindex->phashBlock = &((*mi).first); } BlockMap::iterator miSelf = mapBlockIndex.find(hash); @@ -5732,12 +5732,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } pfrom->PushMessage("headers", vHeaders); } - /*else if ( NOTARY_PUBKEY33[0] != 0 ) - { - static uint32_t counter; - if ( counter++ < 3 ) - fprintf(stderr,"you can ignore redundant getheaders from peer.%d %d prev.%d\n",(int32_t)pfrom->id,(int32_t)(pindex ? pindex->nHeight : -1),pfrom->lasthdrsreq); - }*/ } From cfd2492e38ea8b874a231c0cc1042f966e774a29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 00:49:55 +0300 Subject: [PATCH 29/45] Skip ensure --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 182a2cfee..95d15c8c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4056,6 +4056,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo } // Store to disk CBlockIndex *pindex = NULL; + if ( 0 ) { // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); From 537cfef7d9d0801802684e5c6714b2fa780ef461 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 00:59:58 +0300 Subject: [PATCH 30/45] +error --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 95d15c8c8..3351e77c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1603,7 +1603,7 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos) if (filein.IsNull()) { //fprintf(stderr,"readblockfromdisk err A\n"); - return false;//error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString()); + return error("ReadBlockFromDisk: OpenBlockFile failed for %s", pos.ToString()); } // Read block From d60fb8fa36d569313217f930cf403bfe0b15dcd3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 01:10:52 +0300 Subject: [PATCH 31/45] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3351e77c7..3f568df7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3798,7 +3798,8 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat if (miSelf != mapBlockIndex.end()) { // Block header is already known. - pindex = miSelf->second; + if ( (pindex= miSelf->second) == 0 ) + pindex = AddToBlockIndex(block); if (ppindex) *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) From 695ffea8de213eeeea7fbf42bc5583e4826e6c10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 01:30:28 +0300 Subject: [PATCH 32/45] +ensure --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3f568df7c..e28f9a4c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4057,7 +4057,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo } // Store to disk CBlockIndex *pindex = NULL; - if ( 0 ) + if ( 1 ) { // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); From ab158faa6de1016a703ea4fb1ecdb09e8a72e672 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 01:49:01 +0300 Subject: [PATCH 33/45] Simplify ensure --- src/main.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e28f9a4c0..3563dc253 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3976,6 +3976,32 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned void komodo_currentheight_set(int32_t height); CBlockIndex *komodo_ensure(CBlock *pblock,uint256 hash) +{ + CBlockIndex *pindex; + BlockMap::iterator miSelf = mapBlockIndex.find(hash); + if ( miSelf != mapBlockIndex.end() ) + { + if ( (pindex= miSelf->second) == 0 ) // create pindex so first Accept block doesnt fail + { + miSelf->second = AddToBlockIndex(*pblock); + //fprintf(stderr,"Block header %s is already known, but without pindex -> ensured %p\n",hash.ToString().c_str(),miSelf->second); + } + if ( hash != Params().GetConsensus().hashGenesisBlock ) + { + miSelf = mapBlockIndex.find(pblock->hashPrevBlock); + if ( miSelf != mapBlockIndex.end() ) + { + if ( miSelf->second == 0 ) + { + miSelf->second = InsertBlockIndex(pblock->hashPrevBlock); + fprintf(stderr,"autocreate previndex %s\n",pblock->hashPrevBlock.ToString().c_str()); + } + } + } + } +} + +CBlockIndex *oldkomodo_ensure(CBlock *pblock,uint256 hash) { CBlockIndex *pindex=0,*previndex=0; if ( (pindex= mapBlockIndex[hash]) == 0 ) @@ -4057,7 +4083,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo } // Store to disk CBlockIndex *pindex = NULL; - if ( 1 ) + if ( 0 ) { // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); From 27113a317e430deea764e880e6c947470adc4d03 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 02:30:59 +0300 Subject: [PATCH 34/45] Miself update --- src/main.cpp | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3563dc253..95ecb37b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3799,19 +3799,11 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat { // Block header is already known. if ( (pindex= miSelf->second) == 0 ) - pindex = AddToBlockIndex(block); + miSelf->second = pindex = AddToBlockIndex(block); if (ppindex) *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); - /*if ( pindex != 0 && hash == komodo_requestedhash ) - { - fprintf(stderr,"AddToBlockIndex A komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); - memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); - komodo_requestedcount = 0; - }*/ - //if ( pindex == 0 ) - // fprintf(stderr,"accepthdr %s already known but no pindex\n",hash.ToString().c_str()); return true; } if (!CheckBlockHeader(futureblockp,*ppindex!=0?(*ppindex)->nHeight:0,*ppindex, block, state,0)) @@ -3829,12 +3821,6 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi == mapBlockIndex.end()) { - //fprintf(stderr,"AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); - /*if ( komodo_requestedhash == zero ) - { - komodo_requestedhash = block.hashPrevBlock; - komodo_requestedcount = 0; - }*/ LogPrintf("AcceptBlockHeader hashPrevBlock %s not found\n",block.hashPrevBlock.ToString().c_str()); return(false); //return state.DoS(10, error("%s: prev block not found", __func__), 0, "bad-prevblk"); @@ -3842,12 +3828,6 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat pindexPrev = (*mi).second; if (pindexPrev == 0 ) { - /*fprintf(stderr,"AcceptBlockHeader failed no pindexPrev %s\n",block.hashPrevBlock.ToString().c_str()); - if ( komodo_requestedhash == zero ) - { - komodo_requestedhash = block.hashPrevBlock; - komodo_requestedcount = 0; - }*/ LogPrintf("AcceptBlockHeader hashPrevBlock %s no pindexPrev\n",block.hashPrevBlock.ToString().c_str()); return(false); } @@ -3862,19 +3842,16 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat } if (pindex == NULL) { - if ( (pindex= AddToBlockIndex(block)) == 0 ) + if ( (pindex= AddToBlockIndex(block)) != 0 ) { + miSelf = mapBlockIndex.find(hash); + if (miSelf != mapBlockIndex.end()) + miSelf->second = pindex; //fprintf(stderr,"AcceptBlockHeader couldnt add to block index\n"); } } if (ppindex) *ppindex = pindex; - /*if ( pindex != 0 && hash == komodo_requestedhash ) - { - fprintf(stderr,"AddToBlockIndex komodo_requestedhash %s\n",komodo_requestedhash.ToString().c_str()); - memset(&komodo_requestedhash,0,sizeof(komodo_requestedhash)); - komodo_requestedcount = 0; - }*/ return true; } From 8771059f5b11291e3a609eb180488fb9f795456b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 02:32:54 +0300 Subject: [PATCH 35/45] Mi->second = index --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 95ecb37b6..8ab156077 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3336,7 +3336,8 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) pindexBestHeader = pindexNew; setDirtyBlockIndex.insert(pindexNew); - + mi->second = pindexNew; + return pindexNew; } From 9376e387dbacefe086f60e9f9a8bd57648fe6cbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 02:47:30 +0300 Subject: [PATCH 36/45] +ensure --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8ab156077..c7192673d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4061,7 +4061,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo } // Store to disk CBlockIndex *pindex = NULL; - if ( 0 ) + if ( 1 ) { // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); From 6cc888dd992bd9c3ebd2043dd63c61896f78b1f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 02:55:40 +0300 Subject: [PATCH 37/45] Set second --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c7192673d..af92dc85a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3312,8 +3312,10 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) uint256 hash = block.GetHash(); BlockMap::iterator it = mapBlockIndex.find(hash); if (it != mapBlockIndex.end()) - return it->second; - + { + if ( it->second != 0 ) + return it->second; + } // Construct new block index object CBlockIndex* pindexNew = new CBlockIndex(block); assert(pindexNew); From c9fbb1a741f9504a65da07d25ac3d4981e05736f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 25 Apr 2018 03:00:53 +0300 Subject: [PATCH 38/45] Sync addtoblockindex --- src/main.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index af92dc85a..3a7bcdeba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3311,10 +3311,20 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) // Check for duplicate uint256 hash = block.GetHash(); BlockMap::iterator it = mapBlockIndex.find(hash); + BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); if (it != mapBlockIndex.end()) { - if ( it->second != 0 ) + if ( it->second != 0 ) // vNodes.size() >= KOMODO_LIMITED_NETWORKSIZE, change behavior to allow komodo_ensure to work + { + // this is the strange case where somehow the hash is in the mapBlockIndex via as yet undetermined process, but the pindex for the hash is not there. Theoretically it is due to processing the block headers, but I have seen it get this case without having received it from the block headers or anywhere else... jl777 + //fprintf(stderr,"addtoblockindex already there %p\n",it->second); return it->second; + } + if ( miPrev != mapBlockIndex.end() && (*miPrev).second == 0 ) + { + //fprintf(stderr,"edge case of both block and prevblock in the strange state\n"); + return(0); // return here to avoid the state of pindex->nHeight not set and pprev NULL + } } // Construct new block index object CBlockIndex* pindexNew = new CBlockIndex(block); @@ -3325,11 +3335,11 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) pindexNew->nSequenceId = 0; BlockMap::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first; pindexNew->phashBlock = &((*mi).first); - BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock); if (miPrev != mapBlockIndex.end()) { - pindexNew->pprev = (*miPrev).second; - pindexNew->nHeight = pindexNew->pprev->nHeight + 1; + if ( (pindexNew->pprev= (*miPrev).second) != 0 ) + pindexNew->nHeight = pindexNew->pprev->nHeight + 1; + else fprintf(stderr,"unexpected null pprev %s\n",hash.ToString().c_str()); pindexNew->BuildSkip(); } pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew); @@ -3338,8 +3348,8 @@ CBlockIndex* AddToBlockIndex(const CBlockHeader& block) pindexBestHeader = pindexNew; setDirtyBlockIndex.insert(pindexNew); + //fprintf(stderr,"added to block index %s %p\n",hash.ToString().c_str(),pindexNew); mi->second = pindexNew; - return pindexNew; } From 57023d5b91caf5062ca9d1dcedf843edb95f4aa0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 May 2018 17:45:09 +0300 Subject: [PATCH 39/45] Monthly cap on active user reward --- src/komodo_interest.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 07b12cfe1..581592566 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -80,13 +80,15 @@ uint64_t komodo_moneysupply(int32_t height) } #endif -uint64_t _komodo_interestnew(uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) +uint64_t _komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime) { int32_t minutes; uint64_t interest = 0; if ( nLockTime >= LOCKTIME_THRESHOLD && tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= 60 ) { if ( minutes > 365 * 24 * 60 ) minutes = 365 * 24 * 60; + if ( txheight >= 1000000 && minutes > 31 * 24 * 60 ) + minutes = 31 * 24 * 60; minutes -= 59; interest = ((nValue / 10512000) * minutes); } @@ -97,7 +99,7 @@ uint64_t komodo_interestnew(int32_t txheight,uint64_t nValue,uint32_t nLockTime, { uint64_t interest = 0; if ( txheight < KOMODO_ENDOFERA && nLockTime >= LOCKTIME_THRESHOLD && tiptime != 0 && nLockTime < tiptime && nValue >= 10*COIN ) //komodo_moneysupply(txheight) < MAX_MONEY && - interest = _komodo_interestnew(nValue,nLockTime,tiptime); + interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); return(interest); } @@ -151,21 +153,21 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin else if ( txheight < 1000000 ) { interest = (numerator * minutes) / ((uint64_t)365 * 24 * 60); - interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + interestnew = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); if ( interest < interestnew ) printf("pathA current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } - else interest = _komodo_interestnew(nValue,nLockTime,tiptime); + else interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); } else if ( txheight < 1000000 ) { numerator = (nValue * KOMODO_INTEREST); interest = (numerator / denominator) / COIN; - interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + interestnew = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); if ( interest < interestnew ) printf("pathB current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } - else interest = _komodo_interestnew(nValue,nLockTime,tiptime); + else interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); } else { @@ -187,11 +189,11 @@ uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uin numerator = (nValue / 20); // assumes 5%! interest = ((numerator * minutes) / ((uint64_t)365 * 24 * 60)); //fprintf(stderr,"interest %llu %.8f <- numerator.%llu minutes.%d\n",(long long)interest,(double)interest/COIN,(long long)numerator,(int32_t)minutes); - interestnew = _komodo_interestnew(nValue,nLockTime,tiptime); + interestnew = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); if ( interest < interestnew ) fprintf(stderr,"pathC current interest %.8f vs new %.8f for ht.%d %.8f locktime.%u tiptime.%u\n",dstr(interest),dstr(interestnew),txheight,dstr(nValue),nLockTime,tiptime); } - else interest = _komodo_interestnew(nValue,nLockTime,tiptime); + else interest = _komodo_interestnew(txheight,nValue,nLockTime,tiptime); } if ( 0 && numerator == (nValue * KOMODO_INTEREST) ) fprintf(stderr,"komodo_interest.%d %lld %.8f nLockTime.%u tiptime.%u minutes.%d interest %lld %.8f (%llu / %llu) prod.%llu\n",txheight,(long long)nValue,(double)nValue/COIN,nLockTime,tiptime,minutes,(long long)interest,(double)interest/COIN,(long long)numerator,(long long)denominator,(long long)(numerator * minutes)); From be5f41cd904c437702a004074e7547491c3a6d24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 13:00:24 +0300 Subject: [PATCH 40/45] Prevent rebroadcast of expired tx --- src/wallet/wallet.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index eadf7f36d..e4f13e749 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2102,12 +2102,21 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) LOCK(cs_wallet); // Sort them in chronological order multimap mapSorted; + uint32_t now = (uint32_t)time(NULL); BOOST_FOREACH(PAIRTYPE(const uint256, CWalletTx)& item, mapWallet) { CWalletTx& wtx = item.second; // Don't rebroadcast if newer than nTime: if (wtx.nTimeReceived > nTime) continue; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + { + if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME ) + { + LogPrintf("skip Relaying wtx %s nLockTime %u vs now.%u\n", wtx.GetHash().ToString(),(uint32_t)wtx.nLockTime,now); + continue; + } + } mapSorted.insert(make_pair(wtx.nTimeReceived, &wtx)); } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) From d014b5bd1c3665e2a399797d1efc913399b6ded5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 13:14:42 +0300 Subject: [PATCH 41/45] Change url for gmplib --- depends/packages/libgmp.mk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/depends/packages/libgmp.mk b/depends/packages/libgmp.mk index f06e4a6c4..496a2751e 100644 --- a/depends/packages/libgmp.mk +++ b/depends/packages/libgmp.mk @@ -18,7 +18,8 @@ $(package)_dependencies= $(package)_config_opts=--enable-cxx --disable-shared else $(package)_version=6.1.1 -$(package)_download_path=https://gmplib.org/download/gmp/ +$(package)_download_path=https://supernetorg.bintray.com/misc + $(package)_file_name=gmp-$($(package)_version).tar.bz2 $(package)_sha256_hash=a8109865f2893f1373b0a8ed5ff7429de8db696fc451b1036bd7bdf95bbeffd6 $(package)_dependencies= From cfc16d5ca461a709e8898e5f03c0b98db0f56c2a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 17:52:55 +0300 Subject: [PATCH 42/45] KOMODO_MAXMEMPOOLTIME --- src/komodo_defs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index db792c44e..6cd297c49 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -5,5 +5,6 @@ #define KOMODO_ELECTION_GAP 2000 #define ROUNDROBIN_DELAY 61 #define KOMODO_ASSETCHAIN_MAXLEN 65 +#define KOMODO_MAXMEMPOOLTIME 3600 #endif From a7322d7720e139d33e2dc5b81217af354be339d0 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 12 May 2018 12:51:39 +0300 Subject: [PATCH 43/45] rename zcash to komodo in cli examples --- src/amount.cpp | 2 +- src/rpcblockchain.cpp | 14 ++-- src/rpcmining.cpp | 8 +-- src/rpcmisc.cpp | 32 ++++----- src/rpcnet.cpp | 2 +- src/rpcrawtransaction.cpp | 12 ++-- src/wallet/rpcdump.cpp | 28 ++++---- src/wallet/rpcwallet.cpp | 136 +++++++++++++++++++------------------- 8 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/amount.cpp b/src/amount.cpp index f658c4a28..4e32ff45b 100644 --- a/src/amount.cpp +++ b/src/amount.cpp @@ -7,7 +7,7 @@ #include "tinyformat.h" -const std::string CURRENCY_UNIT = "ZEC"; +const std::string CURRENCY_UNIT = "KMD"; CFeeRate::CFeeRate(const CAmount& nFeePaid, size_t nSize) { diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index de3f55077..93feb57c6 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -626,7 +626,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp) ret.push_back(Pair("kmdendi",kmdendi)); } } else ret.push_back(Pair("error",(char *)"no MoM for height")); - + return ret; } @@ -654,7 +654,7 @@ UniValue txMoMproof(const UniValue& params, bool fHelp) if (!depth) throw runtime_error("notarisation not found"); - + // index of block in MoM leaves nIndex = notarisedHeight - blockIndex->nHeight; } @@ -709,7 +709,7 @@ UniValue txMoMproof(const UniValue& params, bool fHelp) } // Check the proof - if (MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) + if (MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed validating MoM"); // Encode and return @@ -808,14 +808,14 @@ UniValue notaries(const UniValue& params, bool fHelp) for (j=0; j<33; j++) sprintf(&hexstr[j*2],"%02x",pubkeys[i][j]); item.push_back(Pair("pubkey", hex)); - + bitcoin_address(btcaddr,0,pubkeys[i],33); m = (int32_t)strlen(btcaddr); btcaddress.resize(m); ptr = (char *)btcaddress.data(); memcpy(ptr,btcaddr,m); item.push_back(Pair("BTCaddress", btcaddress)); - + bitcoin_address(kmdaddr,60,pubkeys[i],33); m = (int32_t)strlen(kmdaddr); kmdaddress.resize(m); @@ -963,8 +963,8 @@ UniValue gettxout(const UniValue& params, bool fHelp) " \"hex\" : \"hex\", (string) \n" " \"reqSigs\" : n, (numeric) Number of required signatures\n" " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n" - " \"addresses\" : [ (array of string) array of Zcash addresses\n" - " \"zcashaddress\" (string) Zcash address\n" + " \"addresses\" : [ (array of string) array of Komodo addresses\n" + " \"komodoaddress\" (string) Komodo address\n" " ,...\n" " ]\n" " },\n" diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index aea5694f2..bd9c45f5d 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -182,7 +182,7 @@ UniValue generate(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Wallet disabled and -mineraddress not set"); } #else - throw JSONRPCError(RPC_METHOD_NOT_FOUND, "zcashd compiled without wallet and -mineraddress not set"); + throw JSONRPCError(RPC_METHOD_NOT_FOUND, "komodod compiled without wallet and -mineraddress not set"); #endif } if (!Params().MineBlocksOnDemand()) @@ -304,7 +304,7 @@ UniValue setgenerate(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Wallet disabled and -mineraddress not set"); } #else - throw JSONRPCError(RPC_METHOD_NOT_FOUND, "zcashd compiled without wallet and -mineraddress not set"); + throw JSONRPCError(RPC_METHOD_NOT_FOUND, "komodod compiled without wallet and -mineraddress not set"); #endif } if (Params().MineBlocksOnDemand()) @@ -506,7 +506,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Wallet disabled and -mineraddress not set"); } #else - throw JSONRPCError(RPC_METHOD_NOT_FOUND, "zcashd compiled without wallet and -mineraddress not set"); + throw JSONRPCError(RPC_METHOD_NOT_FOUND, "komodod compiled without wallet and -mineraddress not set"); #endif } @@ -563,7 +563,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode"); if (vNodes.empty()) - throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Zcash is not connected!"); + throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Komodo is not connected!"); //if (IsInitialBlockDownload()) // throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Zcash is downloading blocks..."); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index cf7967cb7..682298485 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -66,7 +66,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) " \"version\": xxxxx, (numeric) the server version\n" " \"protocolversion\": xxxxx, (numeric) the protocol version\n" " \"walletversion\": xxxxx, (numeric) the wallet version\n" - " \"balance\": xxxxxxx, (numeric) the total Zcash balance of the wallet\n" + " \"balance\": xxxxxxx, (numeric) the total Komodo balance of the wallet\n" " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" " \"timeoffset\": xxxxx, (numeric) the time offset\n" " \"connections\": xxxxx, (numeric) the number of connections\n" @@ -254,14 +254,14 @@ UniValue validateaddress(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( - "validateaddress \"zcashaddress\"\n" - "\nReturn information about the given Zcash address.\n" + "validateaddress \"komodoaddress\"\n" + "\nReturn information about the given Komodo address.\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address to validate\n" + "1. \"komodoaddress\" (string, required) The Komodo address to validate\n" "\nResult:\n" "{\n" " \"isvalid\" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.\n" - " \"address\" : \"zcashaddress\", (string) The Zcash address validated\n" + " \"address\" : \"komodoaddress\", (string) The Komodo address validated\n" " \"scriptPubKey\" : \"hex\", (string) The hex encoded scriptPubKey generated by the address\n" " \"ismine\" : true|false, (boolean) If the address is yours or not\n" " \"isscript\" : true|false, (boolean) If the key is a script\n" @@ -270,8 +270,8 @@ UniValue validateaddress(const UniValue& params, bool fHelp) " \"account\" : \"account\" (string) DEPRECATED. The account associated with the address, \"\" is the default account\n" "}\n" "\nExamples:\n" - + HelpExampleCli("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") - + HelpExampleRpc("validateaddress", "\"1PSSGeFHDnKNxiEyFrD1wcEaHr9hrQDDWc\"") + + HelpExampleCli("validateaddress", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\"") + + HelpExampleRpc("validateaddress", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\"") ); #ifdef ENABLE_WALLET @@ -445,9 +445,9 @@ UniValue createmultisig(const UniValue& params, bool fHelp) "\nArguments:\n" "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n" - "2. \"keys\" (string, required) A json array of keys which are Zcash addresses or hex-encoded public keys\n" + "2. \"keys\" (string, required) A json array of keys which are Komodo addresses or hex-encoded public keys\n" " [\n" - " \"key\" (string) Zcash address or hex-encoded public key\n" + " \"key\" (string) Komodo address or hex-encoded public key\n" " ,...\n" " ]\n" @@ -459,9 +459,9 @@ UniValue createmultisig(const UniValue& params, bool fHelp) "\nExamples:\n" "\nCreate a multisig address from 2 addresses\n" - + HelpExampleCli("createmultisig", "2 \"[\\\"t16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"t171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + + + HelpExampleCli("createmultisig", "2 \"[\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\",\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\"]\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("createmultisig", "2, \"[\\\"t16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"t171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + + HelpExampleRpc("createmultisig", "2, \"[\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\",\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\"]\"") ; throw runtime_error(msg); } @@ -482,10 +482,10 @@ UniValue verifymessage(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 3) throw runtime_error( - "verifymessage \"zcashaddress\" \"signature\" \"message\"\n" + "verifymessage \"komodoaddress\" \"signature\" \"message\"\n" "\nVerify a signed message\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address to use for the signature.\n" + "1. \"komodoaddress\" (string, required) The Komodo address to use for the signature.\n" "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n" "3. \"message\" (string, required) The message that was signed.\n" "\nResult:\n" @@ -494,11 +494,11 @@ UniValue verifymessage(const UniValue& params, bool fHelp) "\nUnlock the wallet for 30 seconds\n" + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + "\nCreate the signature\n" - + HelpExampleCli("signmessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" \"my message\"") + + + HelpExampleCli("signmessage", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\" \"my message\"") + "\nVerify the signature\n" - + HelpExampleCli("verifymessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" \"signature\" \"my message\"") + + + HelpExampleCli("verifymessage", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\" \"signature\" \"my message\"") + "\nAs json rpc\n" - + HelpExampleRpc("verifymessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\", \"signature\", \"my message\"") + + HelpExampleRpc("verifymessage", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\", \"signature\", \"my message\"") ); LOCK(cs_main); diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index a7a4bf051..79f2b0cdd 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -291,7 +291,7 @@ UniValue getaddednodeinfo(const UniValue& params, bool fHelp) " \"connected\" : true|false, (boolean) If connected\n" " \"addresses\" : [\n" " {\n" - " \"address\" : \"192.168.0.201:8233\", (string) The Zcash server host and port\n" + " \"address\" : \"192.168.0.201:8233\", (string) The Komodo server host and port\n" " \"connected\" : \"outbound\" (string) connection, inbound or outbound\n" " }\n" " ,...\n" diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index e918df2c9..7bfe1269a 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -233,7 +233,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp) " \"reqSigs\" : n, (numeric) The required sigs\n" " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" " \"addresses\" : [ (json array of string)\n" - " \"zcashaddress\" (string) Zcash address\n" + " \"komodoaddress\" (string) Komodo address\n" " ,...\n" " ]\n" " }\n" @@ -488,7 +488,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) " ]\n" "2. \"addresses\" (string, required) a json object with addresses as keys and amounts as values\n" " {\n" - " \"address\": x.xxx (numeric, required) The key is the Zcash address, the value is the " + CURRENCY_UNIT + " amount\n" + " \"address\": x.xxx (numeric, required) The key is the Komodo address, the value is the " + CURRENCY_UNIT + " amount\n" " ,...\n" " }\n" @@ -509,7 +509,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) int nextBlockHeight = chainActive.Height() + 1; CMutableTransaction rawTx = CreateNewContextualCMutableTransaction( Params().GetConsensus(), nextBlockHeight); - + if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { rawTx.nExpiryHeight = nextBlockHeight + expiryDelta; if (rawTx.nExpiryHeight >= TX_EXPIRY_HEIGHT_THRESHOLD){ @@ -539,7 +539,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp) BOOST_FOREACH(const string& name_, addrList) { CBitcoinAddress address(name_); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Zcash address: ")+name_); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Komodo address: ")+name_); if (setAddress.count(address)) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_); @@ -595,7 +595,7 @@ UniValue decoderawtransaction(const UniValue& params, bool fHelp) " \"reqSigs\" : n, (numeric) The required sigs\n" " \"type\" : \"pubkeyhash\", (string) The type, eg 'pubkeyhash'\n" " \"addresses\" : [ (json array of string)\n" - " \"t12tvKAXCxZjSmdNbao16dKXC8tRWfcF5oc\" (string) zcash address\n" + " \"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" (string) komodo address\n" " ,...\n" " ]\n" " }\n" @@ -665,7 +665,7 @@ UniValue decodescript(const UniValue& params, bool fHelp) " \"type\":\"type\", (string) The output type\n" " \"reqSigs\": n, (numeric) The required signatures\n" " \"addresses\": [ (json array of string)\n" - " \"address\" (string) Zcash address\n" + " \"address\" (string) Komodo address\n" " ,...\n" " ],\n" " \"p2sh\",\"address\" (string) script address\n" diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 33dc90bb3..15caad846 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -64,7 +64,7 @@ std::string DecodeDumpString(const std::string &str) { for (unsigned int pos = 0; pos < str.length(); pos++) { unsigned char c = str[pos]; if (c == '%' && pos+2 < str.length()) { - c = (((str[pos+1]>>6)*9+((str[pos+1]-'0')&15)) << 4) | + c = (((str[pos+1]>>6)*9+((str[pos+1]-'0')&15)) << 4) | ((str[pos+2]>>6)*9+((str[pos+2]-'0')&15)); pos += 2; } @@ -77,13 +77,13 @@ UniValue importprivkey(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - + if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( - "importprivkey \"zcashprivkey\" ( \"label\" rescan )\n" + "importprivkey \"komodoprivkey\" ( \"label\" rescan )\n" "\nAdds a private key (as returned by dumpprivkey) to your wallet.\n" "\nArguments:\n" - "1. \"zcashprivkey\" (string, required) The private key (see dumpprivkey)\n" + "1. \"komodoprivkey\" (string, required) The private key (see dumpprivkey)\n" "2. \"label\" (string, optional, default=\"\") An optional label\n" "3. rescan (boolean, optional, default=true) Rescan the wallet for transactions\n" "\nNote: This call can take minutes to complete if rescan is true.\n" @@ -152,7 +152,7 @@ UniValue importaddress(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - + if (fHelp || params.size() < 1 || params.size() > 3) throw runtime_error( "importaddress \"address\" ( \"label\" rescan )\n" @@ -248,7 +248,7 @@ UniValue importwallet(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - + if (fHelp || params.size() != 1) throw runtime_error( "importwallet \"filename\"\n" @@ -385,14 +385,14 @@ UniValue dumpprivkey(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - + if (fHelp || params.size() != 1) throw runtime_error( - "dumpprivkey \"zcashaddress\"\n" - "\nReveals the private key corresponding to 'zcashaddress'.\n" + "dumpprivkey \"komodoaddress\"\n" + "\nReveals the private key corresponding to 'komodoaddress'.\n" "Then the importprivkey can be used with this output\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The zcash address for the private key\n" + "1. \"komodoaddress\" (string, required) The komodo address for the private key\n" "\nResult:\n" "\"key\" (string) The private key\n" "\nExamples:\n" @@ -424,13 +424,13 @@ UniValue z_exportwallet(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - + if (fHelp || params.size() != 1) throw runtime_error( "z_exportwallet \"filename\"\n" "\nExports all wallet keys, for taddr and zaddr, in a human-readable format. Overwriting an existing file is not permitted.\n" "\nArguments:\n" - "1. \"filename\" (string, required) The filename, saved in folder set by zcashd -exportdir option\n" + "1. \"filename\" (string, required) The filename, saved in folder set by komodod -exportdir option\n" "\nResult:\n" "\"path\" (string) The full path of the destination file\n" "\nExamples:\n" @@ -451,7 +451,7 @@ UniValue dumpwallet(const UniValue& params, bool fHelp) "dumpwallet \"filename\"\n" "\nDumps taddr wallet keys in a human-readable format. Overwriting an existing file is not permitted.\n" "\nArguments:\n" - "1. \"filename\" (string, required) The filename, saved in folder set by zcashd -exportdir option\n" + "1. \"filename\" (string, required) The filename, saved in folder set by komodod -exportdir option\n" "\nResult:\n" "\"path\" (string) The full path of the destination file\n" "\nExamples:\n" @@ -475,7 +475,7 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys) throw JSONRPCError(RPC_INTERNAL_ERROR, e.what()); } if (exportdir.empty()) { - throw JSONRPCError(RPC_WALLET_ERROR, "Cannot export wallet until the zcashd -exportdir option has been set"); + throw JSONRPCError(RPC_WALLET_ERROR, "Cannot export wallet until the komodod -exportdir option has been set"); } std::string unclean = params[0].get_str(); std::string clean = SanitizeFilename(unclean); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 347c15f2d..ecc2b5d40 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -126,7 +126,7 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) "\nArguments:\n" "1. \"account\" (string, optional) DEPRECATED. If provided, it MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "\nResult:\n" - "\"zcashaddress\" (string) The new Zcash address\n" + "\"komodoaddress\" (string) The new Komodo address\n" "\nExamples:\n" + HelpExampleCli("getnewaddress", "") + HelpExampleRpc("getnewaddress", "") @@ -203,7 +203,7 @@ UniValue getaccountaddress(const UniValue& params, bool fHelp) "\nArguments:\n" "1. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "\nResult:\n" - "\"zcashaddress\" (string) The account Zcash address\n" + "\"komodoaddress\" (string) The account Komodo address\n" "\nExamples:\n" + HelpExampleCli("getaccountaddress", "") + HelpExampleCli("getaccountaddress", "\"\"") @@ -265,14 +265,14 @@ UniValue setaccount(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "setaccount \"zcashaddress\" \"account\"\n" + "setaccount \"komodoaddress\" \"account\"\n" "\nDEPRECATED. Sets the account associated with the given address.\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address to be associated with an account.\n" + "1. \"komodoaddress\" (string, required) The Komodo address to be associated with an account.\n" "2. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "\nExamples:\n" - + HelpExampleCli("setaccount", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" \"tabby\"") - + HelpExampleRpc("setaccount", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\", \"tabby\"") + + HelpExampleCli("setaccount", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\" \"tabby\"") + + HelpExampleRpc("setaccount", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\", \"tabby\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -311,15 +311,15 @@ UniValue getaccount(const UniValue& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( - "getaccount \"zcashaddress\"\n" + "getaccount \"komodoaddress\"\n" "\nDEPRECATED. Returns the account associated with the given address.\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address for account lookup.\n" + "1. \"komodoaddress\" (string, required) The Komodo address for account lookup.\n" "\nResult:\n" "\"accountname\" (string) the account address\n" "\nExamples:\n" - + HelpExampleCli("getaccount", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\"") - + HelpExampleRpc("getaccount", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\"") + + HelpExampleCli("getaccount", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\"") + + HelpExampleRpc("getaccount", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -349,7 +349,7 @@ UniValue getaddressesbyaccount(const UniValue& params, bool fHelp) "1. \"account\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "\nResult:\n" "[ (json array of string)\n" - " \"zcashaddress\" (string) a Zcash address associated with the given account\n" + " \"komodoaddress\" (string) a Komodo address associated with the given account\n" " ,...\n" "]\n" "\nExamples:\n" @@ -425,11 +425,11 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() < 2 || params.size() > 5) throw runtime_error( - "sendtoaddress \"zcashaddress\" amount ( \"comment\" \"comment-to\" subtractfeefromamount )\n" + "sendtoaddress \"komodoaddress\" amount ( \"comment\" \"comment-to\" subtractfeefromamount )\n" "\nSend an amount to a given address. The amount is a real and is rounded to the nearest 0.00000001\n" + HelpRequiringPassphrase() + "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address to send to.\n" + "1. \"komodoaddress\" (string, required) The Komodo address to send to.\n" "2. \"amount\" (numeric, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" "3. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" " This is not part of the transaction, just kept in your wallet.\n" @@ -437,14 +437,14 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) " to which you're sending the transaction. This is not part of the \n" " transaction, just kept in your wallet.\n" "5. subtractfeefromamount (boolean, optional, default=false) The fee will be deducted from the amount being sent.\n" - " The recipient will receive less Zcash than you enter in the amount field.\n" + " The recipient will receive less Komodo than you enter in the amount field.\n" "\nResult:\n" "\"transactionid\" (string) The transaction id.\n" "\nExamples:\n" - + HelpExampleCli("sendtoaddress", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1") - + HelpExampleCli("sendtoaddress", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"donation\" \"seans outpost\"") - + HelpExampleCli("sendtoaddress", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.1 \"\" \"\" true") - + HelpExampleRpc("sendtoaddress", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.1, \"donation\", \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" 0.1") + + HelpExampleCli("sendtoaddress", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" 0.1 \"donation\" \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" 0.1 \"\" \"\" true") + + HelpExampleRpc("sendtoaddress", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\", 0.1, \"donation\", \"seans outpost\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -712,7 +712,7 @@ UniValue listaddressgroupings(const UniValue& params, bool fHelp) "[\n" " [\n" " [\n" - " \"zcashaddress\", (string) The zcash address\n" + " \"komodoaddress\", (string) The komodo address\n" " amount, (numeric) The amount in " + CURRENCY_UNIT + "\n" " \"account\" (string, optional) The account (DEPRECATED)\n" " ]\n" @@ -755,11 +755,11 @@ UniValue signmessage(const UniValue& params, bool fHelp) if (fHelp || params.size() != 2) throw runtime_error( - "signmessage \"zcashaddress\" \"message\"\n" + "signmessage \"komodoaddress\" \"message\"\n" "\nSign a message with the private key of an address" + HelpRequiringPassphrase() + "\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address to use for the private key.\n" + "1. \"komodoaddress\" (string, required) The Komodo address to use for the private key.\n" "2. \"message\" (string, required) The message to create a signature of.\n" "\nResult:\n" "\"signature\" (string) The signature of the message encoded in base 64\n" @@ -767,11 +767,11 @@ UniValue signmessage(const UniValue& params, bool fHelp) "\nUnlock the wallet for 30 seconds\n" + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + "\nCreate the signature\n" - + HelpExampleCli("signmessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" \"my message\"") + + + HelpExampleCli("signmessage", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\" \"my message\"") + "\nVerify the signature\n" - + HelpExampleCli("verifymessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" \"signature\" \"my message\"") + + + HelpExampleCli("verifymessage", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\" \"signature\" \"my message\"") + "\nAs json rpc\n" - + HelpExampleRpc("signmessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\", \"my message\"") + + HelpExampleRpc("signmessage", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\", \"my message\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -811,22 +811,22 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "getreceivedbyaddress \"zcashaddress\" ( minconf )\n" - "\nReturns the total amount received by the given Zcash address in transactions with at least minconf confirmations.\n" + "getreceivedbyaddress \"komodoaddress\" ( minconf )\n" + "\nReturns the total amount received by the given Komodo address in transactions with at least minconf confirmations.\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address for transactions.\n" + "1. \"komodoaddress\" (string, required) The Komodo address for transactions.\n" "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" "\nResult:\n" "amount (numeric) The total amount in " + CURRENCY_UNIT + " received at this address.\n" "\nExamples:\n" "\nThe amount from transactions with at least 1 confirmation\n" - + HelpExampleCli("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\"") + + + HelpExampleCli("getreceivedbyaddress", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\"") + "\nThe amount including unconfirmed transactions, zero confirmations\n" - + HelpExampleCli("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" 0") + + + HelpExampleCli("getreceivedbyaddress", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\" 0") + "\nThe amount with at least 6 confirmations, very safe\n" - + HelpExampleCli("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" 6") + + + HelpExampleCli("getreceivedbyaddress", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\" 6") + "\nAs a json rpc call\n" - + HelpExampleRpc("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\", 6") + + HelpExampleRpc("getreceivedbyaddress", "\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\", 6") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1119,13 +1119,13 @@ UniValue sendfrom(const UniValue& params, bool fHelp) if (fHelp || params.size() < 3 || params.size() > 6) throw runtime_error( - "sendfrom \"fromaccount\" \"tozcashaddress\" amount ( minconf \"comment\" \"comment-to\" )\n" - "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a Zcash address.\n" + "sendfrom \"fromaccount\" \"tokomodoaddress\" amount ( minconf \"comment\" \"comment-to\" )\n" + "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a Komodo address.\n" "The amount is a real and is rounded to the nearest 0.00000001." + HelpRequiringPassphrase() + "\n" "\nArguments:\n" "1. \"fromaccount\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" - "2. \"tozcashaddress\" (string, required) The Zcash address to send funds to.\n" + "2. \"tokomodoaddress\" (string, required) The Komodo address to send funds to.\n" "3. amount (numeric, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n" "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" "5. \"comment\" (string, optional) A comment used to store what the transaction is for. \n" @@ -1137,11 +1137,11 @@ UniValue sendfrom(const UniValue& params, bool fHelp) "\"transactionid\" (string) The transaction id.\n" "\nExamples:\n" "\nSend 0.01 " + CURRENCY_UNIT + " from the default account to the address, must have at least 1 confirmation\n" - + HelpExampleCli("sendfrom", "\"\" \"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01") + + + HelpExampleCli("sendfrom", "\"\" \"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" 0.01") + "\nSend 0.01 from the tabby account to the given address, funds must have at least 6 confirmations\n" - + HelpExampleCli("sendfrom", "\"tabby\" \"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 0.01 6 \"donation\" \"seans outpost\"") + + + HelpExampleCli("sendfrom", "\"tabby\" \"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" 0.01 6 \"donation\" \"seans outpost\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("sendfrom", "\"tabby\", \"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", 0.01, 6, \"donation\", \"seans outpost\"") + + HelpExampleRpc("sendfrom", "\"tabby\", \"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\", 0.01, 6, \"donation\", \"seans outpost\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1191,14 +1191,14 @@ UniValue sendmany(const UniValue& params, bool fHelp) "1. \"fromaccount\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "2. \"amounts\" (string, required) A json object with addresses and amounts\n" " {\n" - " \"address\":amount (numeric) The Zcash address is the key, the numeric amount in " + CURRENCY_UNIT + " is the value\n" + " \"address\":amount (numeric) The Komodo address is the key, the numeric amount in " + CURRENCY_UNIT + " is the value\n" " ,...\n" " }\n" "3. minconf (numeric, optional, default=1) Only use the balance confirmed at least this many times.\n" "4. \"comment\" (string, optional) A comment\n" "5. subtractfeefromamount (string, optional) A json array with addresses.\n" " The fee will be equally deducted from the amount of each selected address.\n" - " Those recipients will receive less Zcash than you enter in their corresponding amount field.\n" + " Those recipients will receive less Komodo than you enter in their corresponding amount field.\n" " If no addresses are specified here, the sender pays the fee.\n" " [\n" " \"address\" (string) Subtract fee from this address\n" @@ -1209,13 +1209,13 @@ UniValue sendmany(const UniValue& params, bool fHelp) " the number of addresses.\n" "\nExamples:\n" "\nSend two amounts to two different addresses:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\\\":0.01,\\\"t1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\":0.01,\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\":0.02}\"") + "\nSend two amounts to two different addresses setting the confirmation and comment:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\\\":0.01,\\\"t1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 6 \"testing\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\":0.01,\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\":0.02}\" 6 \"testing\"") + "\nSend two amounts to two different addresses, subtract fee from amount:\n" - + HelpExampleCli("sendmany", "\"\" \"{\\\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\\\":0.01,\\\"t1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\" 1 \"\" \"[\\\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\\\",\\\"t1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\"]\"") + + + HelpExampleCli("sendmany", "\"\" \"{\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\":0.01,\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\":0.02}\" 1 \"\" \"[\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\",\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\"]\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("sendmany", "\"\", \"{\\\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\\\":0.01,\\\"t1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\", 6, \"testing\"") + + HelpExampleRpc("sendmany", "\"\", \"{\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\":0.01,\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\":0.02}\", 6, \"testing\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1306,21 +1306,21 @@ UniValue addmultisigaddress(const UniValue& params, bool fHelp) "\nArguments:\n" "1. nrequired (numeric, required) The number of required signatures out of the n keys or addresses.\n" - "2. \"keysobject\" (string, required) A json array of Zcash addresses or hex-encoded public keys\n" + "2. \"keysobject\" (string, required) A json array of Komodo addresses or hex-encoded public keys\n" " [\n" - " \"address\" (string) Zcash address or hex-encoded public key\n" + " \"address\" (string) Komodo address or hex-encoded public key\n" " ...,\n" " ]\n" "3. \"account\" (string, optional) DEPRECATED. If provided, MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" "\nResult:\n" - "\"zcashaddress\" (string) A Zcash address associated with the keys.\n" + "\"komodoaddress\" (string) A Komodo address associated with the keys.\n" "\nExamples:\n" "\nAdd a multisig address from 2 addresses\n" - + HelpExampleCli("addmultisigaddress", "2 \"[\\\"t16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"t171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + + + HelpExampleCli("addmultisigaddress", "2 \"[\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\",\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\"]\"") + "\nAs json rpc call\n" - + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"t16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"t171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\\\",\\\"RNKiEBduBru6Siv1cZRVhp4fkZNyPska6z\\\"]\"") ; throw runtime_error(msg); } @@ -1669,7 +1669,7 @@ UniValue listtransactions(const UniValue& params, bool fHelp) " {\n" " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. \n" " It will be \"\" for the default account.\n" - " \"address\":\"zcashaddress\", (string) The Zcash address of the transaction. Not present for \n" + " \"address\":\"komodoaddress\", (string) The Komodo address of the transaction. Not present for \n" " move transactions (category = move).\n" " \"category\":\"send|receive|move\", (string) The transaction category. 'move' is a local (off blockchain)\n" " transaction between accounts, and not associated with an address,\n" @@ -1869,7 +1869,7 @@ UniValue listsinceblock(const UniValue& params, bool fHelp) "{\n" " \"transactions\": [\n" " \"account\":\"accountname\", (string) DEPRECATED. The account name associated with the transaction. Will be \"\" for the default account.\n" - " \"address\":\"zcashaddress\", (string) The Zcash address of the transaction. Not present for move transactions (category = move).\n" + " \"address\":\"komodoaddress\", (string) The Komodo address of the transaction. Not present for move transactions (category = move).\n" " \"category\":\"send|receive\", (string) The transaction category. 'send' has negative amounts, 'receive' has positive amounts.\n" " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the 'move' category for moves \n" " outbound. It is positive for the 'receive' category, and for the 'move' category for inbound funds.\n" @@ -1968,7 +1968,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp) " \"details\" : [\n" " {\n" " \"account\" : \"accountname\", (string) DEPRECATED. The account name involved in the transaction, can be \"\" for the default account.\n" - " \"address\" : \"zcashaddress\", (string) The Zcash address involved in the transaction\n" + " \"address\" : \"komodoaddress\", (string) The Komodo address involved in the transaction\n" " \"category\" : \"send|receive\", (string) The category, either 'send' or 'receive'\n" " \"amount\" : x.xxx (numeric) The amount in " + CURRENCY_UNIT + "\n" " \"vout\" : n, (numeric) the vout value\n" @@ -2128,7 +2128,7 @@ UniValue walletpassphrase(const UniValue& params, bool fHelp) throw runtime_error( "walletpassphrase \"passphrase\" timeout\n" "\nStores the wallet decryption key in memory for 'timeout' seconds.\n" - "This is needed prior to performing transactions related to private keys such as sending Zcash\n" + "This is needed prior to performing transactions related to private keys such as sending Komodo\n" "\nArguments:\n" "1. \"passphrase\" (string, required) The wallet passphrase\n" "2. timeout (numeric, required) The time to keep the decryption key in seconds.\n" @@ -2242,7 +2242,7 @@ UniValue walletlock(const UniValue& params, bool fHelp) "\nSet the passphrase for 2 minutes to perform a transaction\n" + HelpExampleCli("walletpassphrase", "\"my pass phrase\" 120") + "\nPerform a send (requires passphrase set)\n" - + HelpExampleCli("sendtoaddress", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" 1.0") + + + HelpExampleCli("sendtoaddress", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" 1.0") + "\nClear the passphrase since we are done before 2 minutes is up\n" + HelpExampleCli("walletlock", "") + "\nAs json rpc call\n" @@ -2293,10 +2293,10 @@ UniValue encryptwallet(const UniValue& params, bool fHelp) "\nExamples:\n" "\nEncrypt you wallet\n" + HelpExampleCli("encryptwallet", "\"my pass phrase\"") + - "\nNow set the passphrase to use the wallet, such as for signing or sending Zcash\n" + "\nNow set the passphrase to use the wallet, such as for signing or sending Komodo\n" + HelpExampleCli("walletpassphrase", "\"my pass phrase\"") + "\nNow we can so something like sign\n" - + HelpExampleCli("signmessage", "\"zcashaddress\" \"test message\"") + + + HelpExampleCli("signmessage", "\"komodoaddress\" \"test message\"") + "\nNow lock the wallet again by removing the passphrase\n" + HelpExampleCli("walletlock", "") + "\nAs a json rpc call\n" @@ -2344,7 +2344,7 @@ UniValue lockunspent(const UniValue& params, bool fHelp) "lockunspent unlock [{\"txid\":\"txid\",\"vout\":n},...]\n" "\nUpdates list of temporarily unspendable outputs.\n" "Temporarily lock (unlock=false) or unlock (unlock=true) specified transaction outputs.\n" - "A locked transaction output will not be chosen by automatic coin selection, when spending Zcash.\n" + "A locked transaction output will not be chosen by automatic coin selection, when spending Komodo.\n" "Locks are stored in memory only. Nodes start with zero locked outputs, and the locked output list\n" "is always cleared (by virtue of process exit) when a node stops or fails.\n" "Also see the listunspent call\n" @@ -2579,9 +2579,9 @@ UniValue listunspent(const UniValue& params, bool fHelp) "\nArguments:\n" "1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n" "2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n" - "3. \"addresses\" (string) A json array of Zcash addresses to filter\n" + "3. \"addresses\" (string) A json array of Komodo addresses to filter\n" " [\n" - " \"address\" (string) Zcash address\n" + " \"address\" (string) Komodo address\n" " ,...\n" " ]\n" "\nResult\n" @@ -2590,7 +2590,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) " \"txid\" : \"txid\", (string) the transaction id \n" " \"vout\" : n, (numeric) the vout value\n" " \"generated\" : true|false (boolean) true if txout is a coinbase transaction output\n" - " \"address\" : \"address\", (string) the Zcash address\n" + " \"address\" : \"address\", (string) the Komodo address\n" " \"account\" : \"account\", (string) DEPRECATED. The associated account, or \"\" for the default account\n" " \"scriptPubKey\" : \"key\", (string) the script key\n" " \"amount\" : x.xxx, (numeric) the transaction amount in " + CURRENCY_UNIT + "\n" @@ -3230,7 +3230,7 @@ UniValue z_getnewaddress(const UniValue& params, bool fHelp) "\nReturns a new zaddr for receiving payments.\n" "\nArguments:\n" "\nResult:\n" - "\"zcashaddress\" (string) The new zaddr\n" + "\"komodoaddress\" (string) The new zaddr\n" "\nExamples:\n" + HelpExampleCli("z_getnewaddress", "") + HelpExampleRpc("z_getnewaddress", "") @@ -3669,8 +3669,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) "\nResult:\n" "\"operationid\" (string) An operationid to pass to z_getoperationstatus to get the result of the operation.\n" "\nExamples:\n" - + HelpExampleCli("z_sendmany", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" '[{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]'") - + HelpExampleRpc("z_sendmany", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", [{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]") + + HelpExampleCli("z_sendmany", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" '[{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]'") + + HelpExampleRpc("z_sendmany", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\", [{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -3828,7 +3828,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) CMutableTransaction contextualTx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), nextBlockHeight); bool isShielded = !fromTaddr || zaddrRecipients.size() > 0; if (contextualTx.nVersion == 1 && isShielded) { - contextualTx.nVersion = 2; // Tx format should support vjoinsplits + contextualTx.nVersion = 2; // Tx format should support vjoinsplits } if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { contextualTx.nExpiryHeight = nextBlockHeight + expiryDelta; @@ -3889,8 +3889,8 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp) " \"opid\": xxx (string) An operationid to pass to z_getoperationstatus to get the result of the operation.\n" "}\n" "\nExamples:\n" - + HelpExampleCli("z_shieldcoinbase", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") - + HelpExampleRpc("z_shieldcoinbase", "\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\", \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") + + HelpExampleCli("z_shieldcoinbase", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\" \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") + + HelpExampleRpc("z_shieldcoinbase", "\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\", \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4023,7 +4023,7 @@ UniValue z_shieldcoinbase(const UniValue& params, bool fHelp) CMutableTransaction contextualTx = CreateNewContextualCMutableTransaction( Params().GetConsensus(), nextBlockHeight); if (contextualTx.nVersion == 1) { - contextualTx.nVersion = 2; // Tx format should support vjoinsplits + contextualTx.nVersion = 2; // Tx format should support vjoinsplits } if (NetworkUpgradeActive(nextBlockHeight, Params().GetConsensus(), Consensus::UPGRADE_OVERWINTER)) { contextualTx.nExpiryHeight = nextBlockHeight + expiryDelta; @@ -4107,8 +4107,8 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) " \"opid\": xxx (string) An operationid to pass to z_getoperationstatus to get the result of the operation.\n" "}\n" "\nExamples:\n" - + HelpExampleCli("z_mergetoaddress", "'[\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"]' ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf") - + HelpExampleRpc("z_mergetoaddress", "[\"t1M72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"], \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") + + HelpExampleCli("z_mergetoaddress", "'[\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\"]' ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf") + + HelpExampleRpc("z_mergetoaddress", "[\"RTZMZHDFSTFQst8XmX2dR4DaH87cEUs3gC\"], \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") ); if (!fEnableMergeToAddress) { From a6c06faf32de1c103b51945f48324b309240eee4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 May 2018 00:42:21 -1100 Subject: [PATCH 44/45] Synchronize with dev --- src/komodo_gateway.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index ce51746f7..cd23c0c3c 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -686,15 +686,18 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim script = (uint8_t *)block.vtx[0].vout[n-1].scriptPubKey.data(); //if ( n <= 2 || script[0] != 0x6a ) { - int64_t val,prevtotal = 0; int32_t overflow = 0; + int64_t val,prevtotal = 0; int32_t strangeout=0,overflow = 0; total = 0; for (i=1; i= MAX_MONEY ) { overflow = 1; break; } + if ( i > 1 && script[0] != 0x6a && val < 5000 ) + strangeout++; total += val; if ( total < prevtotal || (val != 0 && total == prevtotal) ) { @@ -707,9 +710,12 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( overflow != 0 || total > COIN/10 ) { - fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); if ( height >= activation ) + { + if ( height > 800000 ) + fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); return(-1); + } } else if ( block.nBits == KOMODO_MINDIFF_NBITS && total > 0 ) // to deal with fee stealing { @@ -717,11 +723,27 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( height > KOMODO_NOTARIES_HEIGHT1 ) return(-1); } + if ( strangeout != 0 || notmatched != 0 ) + { + if ( 0 && strcmp(NOTARY_PUBKEY.c_str(),"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828") == 0 ) + fprintf(stderr,">>>>>>>>>>>>> DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",height,strangeout,notmatched); + if ( height > 1000000 && strangeout != 0 ) + return(-1); + } + else if ( height > 814000 ) + { + script = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); + return(-1 * (komodo_electednotary(&num,script+1,height,0) >= 0) * (height > 1000000)); + } } else { - if ( overflow != 0 || total > 0 ) + if ( overflow != 0 || total > 0 || strangeout != 0 ) + { + if ( strangeout != 0 ) + fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched); return(-1); + } } return(0); } From 885d458054bff7267170713a2dc893802b660ae6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 May 2018 00:53:43 -1100 Subject: [PATCH 45/45] Fix syntax --- src/komodo_gateway.h | 315 +------------------------------------------ 1 file changed, 6 insertions(+), 309 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index cd23c0c3c..5897484e5 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -653,7 +653,7 @@ void komodo_passport_iteration(); int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime) // verify above block is valid pax pricing { static uint256 array[64]; static int32_t numbanned,indallvouts; - int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; + int32_t i,j,k,n,ht,baseid,txn_count,activation,num,opretlen,offset=1,errs=0,notmatched=0,matched=0,kmdheights[256],otherheights[256]; uint256 hash,txids[256]; char symbol[KOMODO_ASSETCHAIN_MAXLEN],base[KOMODO_ASSETCHAIN_MAXLEN]; uint16_t vouts[256]; int8_t baseids[256]; uint8_t *script,opcode,rmd160s[256*20]; uint64_t total,subsidy,available,deposited,issued,withdrawn,approved,redeemed,checktoshis,seed; int64_t values[256],srcvalues[256]; struct pax_transaction *pax; struct komodo_state *sp; CTransaction tx; activation = 235300; if ( *(int32_t *)&array[0] == 0 ) numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); @@ -668,6 +668,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { for (i=0; i 1 && block.vtx[txn_count-1].vout.size() > 0 && block.vtx[txn_count-1].vout[0].nValue == 5000 ) + { + if ( block.vtx[txn_count-1].vin.size() == 1 && GetTransaction(block.vtx[txn_count-1].vin[0].prevout.hash,tx,hash,false) && block.vtx[0].vout[0].scriptPubKey == tx.vout[block.vtx[txn_count-1].vin[0].prevout.n].scriptPubKey ) + notmatched = 1; + } n = block.vtx[i].vin.size(); for (j=0; j= 235300 ) - return(-1); - strcpy(symbol,(char *)"KMD"); - if ( komodo_isrealtime(&ht) == 0 || KOMODO_PASSPORT_INITDONE == 0 ) // init time already in DB - return(0); - } - else - { - strcpy(symbol,ASSETCHAINS_SYMBOL); - opcode = 'I'; - if ( (baseid= komodo_baseid(symbol)) < 0 ) - { - if ( block.vtx[0].vout.size() != 1 ) - { - printf("%s has more than one coinbase?\n",symbol); - return(-1); - } - return(0); - } - while ( KOMODO_PASSPORT_INITDONE == 0 ) - komodo_passport_iteration(); - komodo_passport_iteration(); - // grandfathering preexisting - if ( height < 777 ) - return(0); - if ( baseid == USD ) // 6820 in balance calcs - { - if ( height <= 6821 || height <= 2000 || height == 2968 || height == 2960 || height == 2649 || height == 3275 || height == 3282 || height == 3328 || height == 3468 ) - return(0); - } - else if ( baseid == EUR ) - { - if ( height < 1200 || height == 1408 || height == 1111 || height == 1094 || height == 1092 || height == 1080 || height == 1053 || height == 1005 || height == 822 || height == 821 || height == 810 || height == 797 || height == 790 || height == 787 || height == 785 || height == 1313 || height == 1288 || height == 1263 || height == 1262 || height <= 211 || height == 210 || height == 188 || height == 185 || height == 182 || height == 181 || height == 171 || height == 170 || height == 169 || height == 168 || height == 167 || height == 166 || height == 165 || height == 164 || height == 163 || height == 162 ) - return(0); - } - else if ( baseid == JPY ) - { - if ( height == 1038 || height == 1039 || height == 1040 || height == 1041 || height == 1014 || height == 998 || height == 973 || height == 139 || height == 971 || height == 141 || height == 816 || height == 814 || height == 803 || height == 142 || height == 782 || height == 145 || height == 181 || height == 186 || height == 192 || height == 190 || height == 189 || height == 255 || height == 218 || height == 233 || height == 259 || height == 278 || height == 361 || height == 367 || height == 733 || height == 688 || height == 468 ) - return(0); - } - else if ( baseid == GBP ) - { - if ( height == 1025 || height == 1026 || height == 1027 || height == 1028 || height == 997 || height == 970 || height == 953 || height == 951 || height == 803 || height == 800 || height == 786 || height == 123 || height == 771 || height == 137 || height == 139 || height == 140 || height == 146 || height == 194 || height == 200 || height == 202 || height == 203 || height == 205 || height == 210 || height == 216 || height == 271 || height == 233 || height == 294 ) - return(0); - } - else if ( baseid == AUD ) - { - if ( height == 1012 || height == 1013 || height == 1014 || height == 985 || height == 958 || height == 936 || height == 933 || height == 790 || height == 788 || height == 778 || height == 124 || height == 777 || height == 122 || height == 140 || height == 142 || height == 143 || height == 186 || height == 196 || height == 198 || height == 201 || height == 210 || height == 192 ) - return(0); - } - else if ( baseid == CAD ) - { - if ( height < 1000 || height == 836 || height == 781 || height == 779 || height == 798 || height == 794 || height == 1181 || height == 1179 || height == 1159 || height == 1134 || height == 1132 || height == 121 || height == 970 || height == 119 || height == 299 || height == 302 || height == 303 || height == 306 || height == 308 || height == 355 || height == 362 || height == 367 || height == 363 || height == 364 || height == 380 || height == 373 || height == 390 || height == 437 || height == 777 ) - return(0); - } - else if ( baseid == CHF ) - { - if ( height == 987 || height == 988 || height == 989 || height == 960 || height == 931 || height == 914 || height == 122 || height == 912 || height == 141 || height == 780 || height == 145 || height == 777 || height == 151 || height == 775 || height == 765 || height == 195 || height == 764 || height == 737 || height == 194 || height == 193 || height == 198 || height == 207 || height == 216 || height == 227 || height == 256 || height == 260 || height == 276 || height == 289 || height == 292 || height == 349 ) - return(0); - } - else if ( baseid == NZD ) - { - if ( height < 1000 || height == 787 || height == 786 || height == 784 || height == 785 || height == 777 || height == 1113 || height == 1083 || height == 1067 || height == 265 || height == 1064 || height == 920 || height == 913 || height == 124 || height == 911 || height == 903 || height == 900 || height == 879 || height == 122 || height == 266 || height == 269 || height == 270 || height == 278 || height == 307 || height == 318 || height == 322 || height == 335 || height == 395 || height == 406 || height == 314 ) - return(0); - } - else if ( baseid == CNY ) - { - if ( height == 987 || height == 988 || height == 989 || height == 982 || height == 957 || height == 931 || height == 119 || height == 929 || height == 134 || height == 782 || height == 137 || height == 775 || height == 143 || height == 772 || height == 186 || height == 763 || height == 761 || height == 734 || height == 183 || height == 190 || height == 192 || height == 211 || height == 203 || height == 226 || height == 263 || height == 264 || height == 277 || height == 342 || height == 613 || height == 525 ) - return(0); - } - else if ( baseid == RUB ) - { - if ( height == 819 || height == 812 || height == 810 || height == 802 || height == 801 || height == 1074 || height == 1040 || height == 1014 || height == 163 || height == 1013 || height == 877 || height == 867 || height == 863 || height == 834 || height == 158 || height == 126 || height == 106 || height == 105 || height == 174 || height == 175 || height == 176 || height == 177 || height == 181 || height == 183 || height == 184 || height == 187 ) - return(0); - } - else if ( baseid == MXN ) - { - if ( height == 1079 || height == 1080 || height == 1081 || height == 1069 || height == 1048 || height == 1028 || height == 121 || height == 1027 || height == 146 || height == 894 || height == 891 || height == 148 || height == 882 || height == 879 || height == 151 || height == 856 || height == 158 || height == 822 || height == 197 || height == 203 || height == 207 || height == 209 || height == 213 || height == 217 || height == 218 || height == 226 || height == 283 || height == 302 || height == 319 || height == 318 || height == 569 ) - return(0); - } - else if ( baseid == BRL ) - { - if ( height == 1003 || height == 1004 || height == 1005 || height == 972 || height == 943 || height == 922 || height == 118 || height == 920 || height == 145 || height == 787 || height == 783 || height == 147 || height == 781 || height == 774 || height == 148 || height == 771 || height == 154 || height == 751 || height == 156 || height == 188 || height == 193 || height == 195 || height == 199 || height == 203 || height == 225 || height == 230 || height == 262 || height == 266 || height == 284 || height == 300 || height == 640 ) - return(0); - } - else if ( baseid == INR ) - { - if ( height == 998 || height == 999 || height == 1000 || height == 788 || height == 786 || height == 775 || height == 753 || height == 125 || height == 153 || height == 155 || height == 159 || height == 204 || height == 206 || height == 211 || height == 217 || height == 220 || height == 229 || height == 265 || height == 292 || height == 300 ) - return(0); - } - else if ( baseid == PLN ) - { - if ( height == 1029 || height == 1030 || height == 1031 || height == 1009 || height == 984 || height == 960 || height == 959 || height == 798 || height == 794 || height == 792 || height == 782 || height == 775 || height == 755 || height == 122 || height == 120 || height == 158 || height == 160 || height == 163 || height == 225 || height == 217 || height == 219 || height == 229 || height == 234 || height == 286 || height == 231 || height == 292 ) - return(0); - } - else if ( baseid == HKD ) - { - if ( height == 1013 || height == 1014 || height == 1015 || height == 1002 || height == 979 || height == 947 || height == 123 || height == 946 || height == 153 || height == 811 || height == 808 || height == 806 || height == 155 || height == 795 || height == 157 || height == 773 || height == 205 || height == 208 || height == 210 || height == 211 || height == 215 || height == 221 || height == 231 || height == 255 || height == 273 || height == 293 || height == 310 || height == 654 ) - return(0); - } - else if ( baseid == TRY ) - { - if ( height == 1022 || height == 1023 || height == 1051 || height == 991 || height == 974 || height == 949 || height == 141 || height == 948 || height == 783 || height == 153 || height == 781 || height == 779 || height == 776 || height == 768 || height == 765 || height == 121 || height == 142 || height == 144 || height == 143 || height == 149 || height == 204 || height == 210 || height == 216 || height == 229 || height == 280 || height == 145 ) - return(0); - } - else if ( baseid == NOK ) - { - if ( height == 987 || height == 988 || height == 989 || height == 962 || height == 911 || height == 907 || height == 125 || height == 765 || height == 150 || height == 762 || height == 760 || height == 753 || height == 152 || height == 751 || height == 151 || height == 154 || height == 160 || height == 195 || height == 203 || height == 207 || height == 211 || height == 220 || height == 236 || height == 253 || height == 278 || height == 283 ) - return(0); - } - else if ( baseid == ZAR ) - { - if ( height == 979 || height == 980 || height == 981 || height == 956 || height == 937 || height == 906 || height == 905 || height == 122 || height == 756 || height == 754 || height == 752 || height == 749 || height == 742 || height == 739 || height == 120 || height == 151 || height == 153 || height == 157 || height == 159 || height == 206 || height == 213 || height == 216 || height == 222 || height == 277 || height == 287 || height == 215 ) - return(0); - } - else if ( baseid == SEK ) - { - if ( height == 960 || height == 961 || height == 962 || height == 943 || height == 925 || height == 896 || height == 147 || height == 894 || height == 759 || height == 751 || height == 749 || height == 742 || height == 740 || height == 716 || height == 123 || height == 148 || height == 150 || height == 151 || height == 157 || height == 199 || height == 200 || height == 201 || height == 206 || height == 256 || height == 257 || height == 268 ) - return(0); - } - else if ( baseid == CZK ) - { - if ( height < 1000 || height == 1084 || height == 1085 || height == 1086 || height == 778 || height == 1079 || height == 1054 || height == 1032 || height == 121 || height == 1030 || height == 182 || height == 876 || height == 873 || height == 871 || height == 184 || height == 862 || height == 185 || height == 861 || height == 186 || height == 838 || height == 238 || height == 242 || height == 246 || height == 248 || height == 250 || height == 251 || height == 256 || height == 282 || height == 322 || height == 343 || height == 433 || height == 323 || height == 276 ) - return(0); - } - else if ( baseid == HUF ) - { - if ( height < 2200 || height == 1531 || height == 1528 || height == 1530 || height == 1451 || height == 1448 || height == 1442 || height == 1418 || height == 1407 || height == 1406 || height == 1392 || height == 1391 || height == 1387 || height == 1383 || height == 1335 || height == 1337 || height == 1338 || height == 1649 || height == 2378 || height == 2376 || height == 2371 || height == 1330 || height == 2326 || height == 1344 || height == 2305 || height == 2304 || height == 2171 || height == 2168 || height == 2166 || height == 2156 || height == 2135 || height == 1343 || height == 1342 || height == 1341 || height == 1340 || height == 1339 || height == 1336 || height == 1334 || height == 1333 || height == 1346 || height == 1400 || height == 1525 || height == 1509 ) - return(0); - } - else if ( baseid == DKK ) - { - if ( height == 1241 || height == 945 || height == 898 || height == 894 || height == 892 || height == 866 || height == 857 || height == 853 || height == 834 || height == 812 || height == 792 || height == 784 || height == 778 || height == 783 || height == 1214 || height == 1186 || height == 1158 || height == 126 || height == 1156 || height == 329 || height == 1021 || height == 1016 || height == 1014 || height == 333 || height == 1003 || height == 1002 || height == 978 || height == 332 || height == 337 || height == 381 || height == 390 || height == 386 || height == 401 || height == 389 || height == 396 || height == 428 || height == 473 || height == 490 || height == 493 ) - return(0); - } - else if ( baseid == ILS ) - { - if ( height == 1017 || height == 1018 || height == 1019 || height == 1010 || height == 985 || height == 954 || height == 120 || height == 952 || height == 143 || height == 819 || height == 817 || height == 808 || height == 145 || height == 786 || height == 155 || height == 753 || height == 151 || height == 149 || height == 199 || height == 193 || height == 201 || height == 209 || height == 284 || height == 305 || height == 676 || height == 702 || height == 406 ) - return(0); - } - else if ( baseid == MYR ) - { - if ( height == 1020 || height == 1021 || height == 1022 || height == 1015 || height == 984 || height == 950 || height == 949 || height == 823 || height == 820 || height == 818 || height == 812 || height == 809 || height == 126 || height == 789 || height == 144 || height == 746 || height == 146 || height == 147 || height == 148 || height == 150 || height == 205 || height == 210 || height == 215 || height == 219 || height == 222 || height == 290 || height == 242 || height == 312 ) - return(0); - } - else if ( baseid == PHP ) - { - if ( height == 859 || height == 817 || height == 812 || height == 811 || height == 792 || height == 779 || height == 778 || height == 781 || height == 1154 || height == 1114 || height == 1077 || height == 1076 || height == 931 || height == 927 || height == 925 || height == 918 || height == 891 || height == 127 || height == 125 || height == 272 || height == 275 || height == 276 || height == 278 || height == 328 || height == 330 || height == 335 || height == 344 || height == 315 ) - return(0); - } - else if ( baseid == KRW ) - { - if ( height == 1021 || height == 1022 || height == 1023 || height == 1010 || height == 950 || height == 916 || height == 138 || height == 914 || height == 140 || height == 785 || height == 782 || height == 781 || height == 142 || height == 775 || height == 148 || height == 772 || height == 751 || height == 147 || height == 146 || height == 159 || height == 175 || height == 181 || height == 184 || height == 186 || height == 188 || height == 196 || height == 209 || height == 238 ) - return(0); - } - else if ( baseid == RON ) - { - if ( height == 1008 || height == 1009 || height == 1010 || height == 1003 || height == 973 || height == 940 || height == 939 || height == 806 || height == 802 || height == 800 || height == 793 || height == 789 || height == 768 || height == 123 || height == 141 || height == 143 || height == 144 || height == 150 || height == 197 || height == 200 || height == 202 || height == 217 || height == 240 || height == 276 ) - return(0); - } - else if ( baseid == SGD ) - { - if ( height == 1016 || height == 1017 || height == 1018 || height == 1010 || height == 984 || height == 951 || height == 950 || height == 801 || height == 798 || height == 792 || height == 788 || height == 122 || height == 769 || height == 120 || height == 158 || height == 160 || height == 164 || height == 169 || height == 229 || height == 234 || height == 246 || height == 297 || height == 299 || height == 316 || height == 233 ) - return(0); - } - else if ( baseid == THB ) - { - if ( height == 977 || height == 978 || height == 968 || height == 933 || height == 898 || height == 897 || height == 788 || height == 786 || height == 779 || height == 777 || height == 757 || height == 119 || height == 140 || height == 142 || height == 146 || height == 152 || height == 196 || height == 200 || height == 214 || height == 260 || height == 263 ) - return(0); - } - else if ( baseid == BGN ) - { - if ( height == 1044 || height == 1045 || height == 1046 || height == 1030 || height == 995 || height == 960 || height == 959 || height == 830 || height == 822 || height == 819 || height == 810 || height == 809 || height == 781 || height == 124 || height == 122 || height == 189 || height == 193 || height == 200 || height == 194 || height == 250 || height == 256 || height == 260 || height == 280 ) - return(0); - } - else if ( baseid == HRK ) - { - if ( height == 1027 || height == 1028 || height == 1029 || height == 1022 || height == 999 || height == 969 || height == 967 || height == 832 || height == 829 || height == 827 || height == 817 || height == 792 || height == 754 || height == 125 || height == 123 || height == 184 || height == 186 || height == 187 || height == 227 || height == 230 || height == 235 || height == 240 || height == 242 || height == 261 || height == 336 ) - return(0); - } - else if ( baseid == IDR ) - { - if ( height == 836 || height == 1036 || height == 837 || height == 720 || height == 715 || height == 714 || height == 696 || height == 695 || height == 694 || height == 693 || height == 119 || height == 689 || height == 120 || height == 669 || height == 123 || height == 662 || height == 122 || height == 634 || height == 121 || height == 609 || height == 124 || height == 174 || height == 603 || height == 595 || height == 166 || height == 176 || height == 589 || height == 172 || height == 587 || height == 179 || height == 239 || height == 175 || height == 245 || height == 260 ) - return(0); - } - } - if ( script[offset] == opcode && opretlen < block.vtx[0].vout[n-1].scriptPubKey.size() ) - { - if ( (num= komodo_issued_opreturn(base,txids,vouts,values,srcvalues,kmdheights,otherheights,baseids,rmd160s,&script[offset],opretlen,opcode == 'X')) > 0 ) - { - for (i=1; iRTmask & (1LL << 32)) == 0 ) - { - if ( rtflag == 0 ) - printf("[%s] skip checkdeposit.%s not RT %llx\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]],(long long)sp->RTmask); - sleep(60); - rtflag = 1; - //matched++; - //continue; - } - if ( rtflag != 0 ) - printf("[%s] %s reached RT\n",ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]); - } - if ( (pax= komodo_paxfinds(txids[i-1],vouts[i-1])) != 0 ) // finds... make sure right one - { - pax->type = opcode; - if ( opcode == 'I' && (pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,symbol) != 0 || available < pax->fiatoshis) ) - { - printf("checkdeposit.[%s.%d]: skip %s %.8f when avail %.8f deposited %.8f, issued %.8f withdrawn %.8f approved %.8f redeemed %.8f\n",ASSETCHAINS_SYMBOL,height,symbol,dstr(pax->fiatoshis),dstr(available),dstr(deposited),dstr(issued),dstr(withdrawn),dstr(approved),dstr(redeemed)); - return(-1); - } - if ( pax->fiatoshis == block.vtx[0].vout[i].nValue ) - { - matched++; - if ( pax->marked != 0 && height >= 80820 ) - { - printf(">>>>>>>>>>> %c errs.%d i.%d match %.8f vs %.8f paxmarked.%d kht.%d ht.%d [%s].%d\n",opcode,errs,i,dstr(opcode == 'I' ? pax->fiatoshis : pax->komodoshis),dstr(block.vtx[0].vout[i].nValue),pax->marked,pax->height,pax->otherheight,ASSETCHAINS_SYMBOL,height); - } - else - { - } - if ( strcmp(ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]) == 0 ) - { - //check deposit validates AUD.1047 [3] 0.14585530 -> 0.01000000 (0.14585530 0.01000000 0.01000000) - char destaddr[64],coinaddr[64]; uint8_t pubkey33[33]; - checktoshis = PAX_fiatdest(&seed,0,destaddr,pubkey33,coinaddr,pax->height,CURRENCIES[baseids[i-1]],pax->fiatoshis); - //checktoshis = komodo_paxprice(&seed,pax->height,CURRENCIES[baseids[i-1]],(char *)"KMD",(uint64_t)pax->komodoshis); - if ( komodo_paxcmp(CURRENCIES[baseids[i-1]],pax->height,pax->komodoshis,checktoshis,seed) < 0 ) - { - printf("paxcmp FAIL when check deposit validates %s.%d [%d] %.8f -> %.8f (%.8f %.8f %.8f)\n",CURRENCIES[baseids[i-1]],height,i,dstr(srcvalues[i-1]),dstr(values[i-1]),dstr(pax->komodoshis),dstr(pax->fiatoshis),dstr(block.vtx[0].vout[i].nValue)); - return(-1); - } //else printf("check deposit validates %s.%d [%d] %.8f -> %.8f (%.8f %.8f %.8f)\n",CURRENCIES[baseids[i-1]],height,i,dstr(srcvalues[i-1]),dstr(values[i-1]),dstr(pax->komodoshis),dstr(pax->fiatoshis),dstr(block.vtx[0].vout[i].nValue)); - } - } - else if ( strcmp(ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]) == 0 ) - { - for (j=0; j<32; j++) - printf("%02x",((uint8_t *)&txids[i-1])[j]); - printf(" cant paxfind %c txid [%d]\n",opcode,height); - printf(">>>>>>>>>>> %c errs.%d i.%d match %.8f vs %.8f pax.%p [%s] ht.%d\n",opcode,errs,i,dstr(opcode == 'I' ? pax->fiatoshis : pax->komodoshis),dstr(block.vtx[0].vout[i].nValue),pax,ASSETCHAINS_SYMBOL,height); - return(-1); - } - } - else //if ( kmdheights[i-1] > 0 && otherheights[i-1] > 0 ) - { - hash = block.GetHash(); - for (j=0; j= activation ) - return(-1); - } - } - if ( ASSETCHAINS_SYMBOL[0] == 0 ) - { - //if ( height > 0 && (height < chainActive.Tip()->nHeight || (height >= chainActive.Tip()->nHeight && komodo_isrealtime(&ht) != 0)) && matched != num ) - //{ - // printf("WOULD REJECT %s: ht.%d (%c) matched.%d vs num.%d tip.%d isRT.%d\n",symbol,height,opcode,matched,num,(int32_t)chainActive.Tip()->nHeight,komodo_isrealtime(&ht)); - // can easily happen depending on order of loading - //if ( height > 200000 ) - //{ - // printf("REJECT: ht.%d (%c) matched.%d vs num.%d\n",height,opcode,matched,num); - // return(-1); - //} - //} // disabled 'X' path - } - else - { - if ( height > 0 && (height < chainActive.Tip()->nHeight || (height >= chainActive.Tip()->nHeight && komodo_isrealtime(&ht) != 0)) && matched != num ) - { - printf("REJECT %s: ht.%d (%c) matched.%d vs num.%d tip.%d isRT.%d\n",symbol,height,opcode,matched,num,(int32_t)chainActive.Tip()->nHeight,komodo_isrealtime(&ht)); - return(-1); - } - } - } - else - { - for (i=0; i= activation ) - return(-1); - } - //printf("opretlen.%d num.%d\n",opretlen,num); - } - else - { - for (i=0; i