From e0711243be9a647c7415c35034a79b07450369da Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 21 Apr 2018 10:42:11 +0300 Subject: [PATCH 0001/1123] 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 9764030cd4d1201b9b3e1d390d318bc94b7971c1 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sat, 21 Apr 2018 18:52:52 +0200 Subject: [PATCH 0002/1123] update librustzcash update librustzcash - experimental! --- depends/packages/librustzcash.mk | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/depends/packages/librustzcash.mk b/depends/packages/librustzcash.mk index bfd8fef1e..3628bc48e 100644 --- a/depends/packages/librustzcash.mk +++ b/depends/packages/librustzcash.mk @@ -3,10 +3,9 @@ $(package)_version=0.1 $(package)_download_path=https://github.com/zcash/$(package)/archive/ $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz -$(package)_sha256_hash=a5760a90d4a1045c8944204f29fa2a3cf2f800afee400f88bf89bbfe2cce1279 -$(package)_git_commit=91348647a86201a9482ad4ad68398152dc3d635e -$(package)_dependencies=rust - +$(package)_sha256_hash=b63ba98d569d332764f27706038c04d03ac7e2c836dc15dc4eaa24b04b8c7f4a +$(package)_git_commit=6cc1813ae3bb1e42224fd8ca0a8977b95c576738 +$(package)_dependencies=rust $(rust_crates) ifeq ($(host_os),mingw32) define $(package)_build_cmds From 696460ce86a3567e7a951ac6e4090a5e66dc2823 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sat, 21 Apr 2018 19:42:22 +0200 Subject: [PATCH 0003/1123] revert librustzcash update --- depends/packages/librustzcash.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/depends/packages/librustzcash.mk b/depends/packages/librustzcash.mk index 3628bc48e..20126776a 100644 --- a/depends/packages/librustzcash.mk +++ b/depends/packages/librustzcash.mk @@ -3,9 +3,9 @@ $(package)_version=0.1 $(package)_download_path=https://github.com/zcash/$(package)/archive/ $(package)_file_name=$(package)-$($(package)_git_commit).tar.gz $(package)_download_file=$($(package)_git_commit).tar.gz -$(package)_sha256_hash=b63ba98d569d332764f27706038c04d03ac7e2c836dc15dc4eaa24b04b8c7f4a -$(package)_git_commit=6cc1813ae3bb1e42224fd8ca0a8977b95c576738 -$(package)_dependencies=rust $(rust_crates) +$(package)_sha256_hash=a5760a90d4a1045c8944204f29fa2a3cf2f800afee400f88bf89bbfe2cce1279 +$(package)_git_commit=91348647a86201a9482ad4ad68398152dc3d635e +$(package)_dependencies=rust ifeq ($(host_os),mingw32) define $(package)_build_cmds From 3b2762ebc888986a21368d178afc00ca6557fd09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 23 Apr 2018 10:59:16 +0300 Subject: [PATCH 0004/1123] 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 0005/1123] 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 0006/1123] 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 0007/1123] 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 0008/1123] 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 0009/1123] 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 0010/1123] 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 0011/1123] 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 0012/1123] 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 0013/1123] 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 0014/1123] 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 0015/1123] 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 0016/1123] 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 0017/1123] 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 0018/1123] 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 0019/1123] 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 0020/1123] 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 0021/1123] 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 0022/1123] 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 0023/1123] 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 0024/1123] -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 0025/1123] 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 0026/1123] 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 0027/1123] 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 0028/1123] 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 0029/1123] 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 0030/1123] 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 0031/1123] 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 0032/1123] +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 0033/1123] 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 0034/1123] +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 0035/1123] 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 0036/1123] 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 0037/1123] 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 0038/1123] +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 0039/1123] 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 0040/1123] 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 0cb91a8d209db6d64578df7bed760994523c18c0 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 16 Apr 2018 22:57:35 -0500 Subject: [PATCH 0041/1123] wip --- migratecoin.md | 61 ++++++ src/Makefile.am | 5 +- src/Makefile.ktest.include | 2 + src/cc/betprotocol.cpp | 146 +++++++++++++++ src/cc/betprotocol.h | 12 +- src/cc/disputepayout.cpp | 84 --------- src/cc/eval.cpp | 37 ++++ src/cc/eval.h | 43 ++++- src/cc/importcoin.cpp | 147 +++++++++++++++ src/cc/importcoin.h | 33 ++++ src/cc/importpayout.cpp | 76 -------- src/chainparams.cpp | 16 +- src/coins.cpp | 11 +- src/coins.h | 5 + src/main.cpp | 91 +++++---- src/miner.cpp | 86 +++++---- src/primitives/transaction.h | 10 + src/rpcblockchain.cpp | 4 +- src/script/interpreter.cpp | 5 +- src/script/interpreter.h | 1 - src/script/script.cpp | 13 ++ src/script/script.h | 1 + src/test-komodo/main.cpp | 7 + src/test-komodo/test_coinimport.cpp | 206 +++++++++++++++++++++ src/test-komodo/test_cryptoconditions.cpp | 10 - src/test-komodo/test_eval_bet.cpp | 6 +- src/test-komodo/test_eval_notarisation.cpp | 24 ++- src/test-komodo/testutils.cpp | 129 +++++++++++++ src/test-komodo/testutils.h | 14 +- src/txmempool.cpp | 6 +- 30 files changed, 1002 insertions(+), 289 deletions(-) create mode 100644 migratecoin.md delete mode 100644 src/cc/disputepayout.cpp create mode 100644 src/cc/importcoin.cpp create mode 100644 src/cc/importcoin.h delete mode 100644 src/cc/importpayout.cpp create mode 100644 src/test-komodo/test_coinimport.cpp create mode 100644 src/test-komodo/testutils.cpp diff --git a/migratecoin.md b/migratecoin.md new file mode 100644 index 000000000..7859bdff2 --- /dev/null +++ b/migratecoin.md @@ -0,0 +1,61 @@ +# MigrateCoin protocol + + + +## ExportCoins tx: + + + +``` + +vin: + + [ any ] + +vout: + + - amount: {burnAmount} + + script: OP_RETURN "send to ledger {id} {voutsHash}" + +``` + + + +* ExportCoin is a standard tx which burns coins in an OP_RETURN + + + +## ImportCoins tx: + + + +``` + +vin: + + - txid: 0000000000000000000000000000000000000000000000000000000000000000 + + idx: 0 + + script: CC_EVAL(EVAL_IMPORTCOINS, {momoProof},{exportCoin}) OP_CHECKCRYPTOCONDITION_UNILATERAL + +vout: + + - [ vouts matching voutsHash in exportCoin ] + +``` + + + +* ImportCoin transaction has no signature + +* ImportCoin is non malleable + +* ImportCoin satisfies tx.IsCoinBase() + +* ImportCoin uses a new opcode which allows a one sided check (no scriptPubKey) + +* ImportCoin must contain CC opcode EVAL_IMPORTCOINS + +* ImportCoin fees are equal to the difference between burnAmount in exportCoins and the sum of outputs. diff --git a/src/Makefile.am b/src/Makefile.am index a1232968d..231386c96 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -256,8 +256,7 @@ libbitcoin_server_a_SOURCES = \ asyncrpcqueue.cpp \ bloom.cpp \ cc/eval.cpp \ - cc/importpayout.cpp \ - cc/disputepayout.cpp \ + cc/importcoin.cpp \ cc/betprotocol.cpp \ chain.cpp \ checkpoints.cpp \ @@ -605,7 +604,7 @@ endif libzcashconsensus_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) libzcashconsensus_la_LIBADD = $(LIBSECP256K1) -libzcashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL +libzcashconsensus_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -I$(srcdir)/cryptoconditions/include -DBUILD_BITCOIN_INTERNAL libzcashconsensus_la_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) endif diff --git a/src/Makefile.ktest.include b/src/Makefile.ktest.include index 06aab54dc..a6d2d1829 100644 --- a/src/Makefile.ktest.include +++ b/src/Makefile.ktest.include @@ -5,7 +5,9 @@ bin_PROGRAMS += komodo-test # tool for generating our public parameters komodo_test_SOURCES = \ test-komodo/main.cpp \ + test-komodo/testutils.cpp \ test-komodo/test_cryptoconditions.cpp \ + test-komodo/test_coinimport.cpp \ test-komodo/test_eval_bet.cpp \ test-komodo/test_eval_notarisation.cpp diff --git a/src/cc/betprotocol.cpp b/src/cc/betprotocol.cpp index 53b79176c..c3be8be8f 100644 --- a/src/cc/betprotocol.cpp +++ b/src/cc/betprotocol.cpp @@ -1,5 +1,8 @@ #include +#include "hash.h" +#include "main.h" +#include "chain.h" #include "streams.h" #include "script/cc.h" #include "cc/eval.h" @@ -137,3 +140,146 @@ bool GetOpReturnHash(CScript script, uint256 &hash) hash = uint256(vHash); return true; } + + +/* + * Crypto-Condition EVAL method that verifies a payout against a transaction + * notarised on another chain. + * + * IN: params - condition params + * IN: importTx - Payout transaction on value chain (KMD) + * IN: nIn - index of input of stake + * + * importTx: Spends stakeTx with payouts from asset chain + * + * in 0: Spends Stake TX and contains ImportPayout CC + * out 0: OP_RETURN MomProof, disputeTx + * out 1-: arbitrary payouts + * + * disputeTx: Spends sessionTx.0 (opener on asset chain) + * + * in 0: spends sessionTx.0 + * in 1-: anything + * out 0: OP_RETURN hash of payouts + * out 1-: anything + */ +bool Eval::ImportPayout(const std::vector params, const CTransaction &importTx, unsigned int nIn) +{ + if (importTx.vout.size() == 0) return Invalid("no-vouts"); + + // load data from vout[0] + MoMProof proof; + CTransaction disputeTx; + { + std::vector vopret; + GetOpReturnData(importTx.vout[0].scriptPubKey, vopret); + if (!E_UNMARSHAL(vopret, ss >> proof; ss >> disputeTx)) + return Invalid("invalid-payload"); + } + + // Check disputeTx.0 shows correct payouts + { + uint256 givenPayoutsHash; + GetOpReturnHash(disputeTx.vout[0].scriptPubKey, givenPayoutsHash); + std::vector payouts(importTx.vout.begin() + 1, importTx.vout.end()); + if (givenPayoutsHash != SerializeHash(payouts)) + return Invalid("wrong-payouts"); + } + + // Check disputeTx spends sessionTx.0 + // condition ImportPayout params is session ID from other chain + { + uint256 sessionHash; + if (!E_UNMARSHAL(params, ss >> sessionHash)) + return Invalid("malformed-params"); + if (disputeTx.vin[0].prevout != COutPoint(sessionHash, 0)) + return Invalid("wrong-session"); + } + + // Check disputeTx solves momproof from vout[0] + { + NotarisationData data; + if (!GetNotarisationData(proof.notarisationHash, data)) + return Invalid("coudnt-load-mom"); + + if (data.MoM != proof.branch.Exec(disputeTx.GetHash())) + return Invalid("mom-check-fail"); + } + + return Valid(); +} + + +/* + * Crypto-Condition EVAL method that resolves a dispute of a session + * + * IN: vm - AppVM virtual machine to verify states + * IN: params - condition params + * IN: disputeTx - transaction attempting to resolve dispute + * IN: nIn - index of input of dispute tx + * + * disputeTx: attempt to resolve a dispute + * + * in 0: Spends Session TX first output, reveals DisputeHeader + * out 0: OP_RETURN hash of payouts + */ +bool Eval::DisputePayout(AppVM &vm, std::vector params, const CTransaction &disputeTx, unsigned int nIn) +{ + if (disputeTx.vout.size() == 0) return Invalid("no-vouts"); + + // get payouts hash + uint256 payoutHash; + if (!GetOpReturnHash(disputeTx.vout[0].scriptPubKey, payoutHash)) + return Invalid("invalid-payout-hash"); + + // load params + uint16_t waitBlocks; + std::vector vmParams; + if (!E_UNMARSHAL(params, ss >> VARINT(waitBlocks); ss >> vmParams)) + return Invalid("malformed-params"); + + // ensure that enough time has passed + { + CTransaction sessionTx; + CBlockIndex sessionBlock; + + // if unconformed its too soon + if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock)) + return Error("couldnt-get-parent"); + + if (GetCurrentHeight() < sessionBlock.nHeight + waitBlocks) + return Invalid("dispute-too-soon"); // Not yet + } + + // get spends + std::vector spends; + if (!GetSpendsConfirmed(disputeTx.vin[0].prevout.hash, spends)) + return Error("couldnt-get-spends"); + + // verify result from VM + int maxLength = -1; + uint256 bestPayout; + for (int i=1; i vmState; + if (spends[i].vout.size() == 0) continue; + if (!GetOpReturnData(spends[i].vout[0].scriptPubKey, vmState)) continue; + auto out = vm.evaluate(vmParams, vmState); + uint256 resultHash = SerializeHash(out.second); + if (out.first > maxLength) { + maxLength = out.first; + bestPayout = resultHash; + } + // The below means that if for any reason there is a draw, the first dispute wins + else if (out.first == maxLength) { + if (bestPayout != payoutHash) { + fprintf(stderr, "WARNING: VM has multiple solutions of same length\n"); + bestPayout = resultHash; + } + } + } + + if (maxLength == -1) return Invalid("no-evidence"); + + return bestPayout == payoutHash ? Valid() : Invalid("wrong-payout"); +} diff --git a/src/cc/betprotocol.h b/src/cc/betprotocol.h index b08783b85..fad33f7ed 100644 --- a/src/cc/betprotocol.h +++ b/src/cc/betprotocol.h @@ -3,7 +3,6 @@ #include "cc/eval.h" #include "pubkey.h" -#include "primitives/block.h" #include "primitives/transaction.h" #include "cryptoconditions/include/cryptoconditions.h" @@ -11,25 +10,18 @@ class MoMProof { public: - int nIndex; - std::vector branch; + MerkleBranch branch; uint256 notarisationHash; - - MoMProof() {} - MoMProof(int i, std::vector b, uint256 n) : notarisationHash(n), nIndex(i), branch(b) {} - uint256 Exec(uint256 hash) const { return CBlock::CheckMerkleBranch(hash, branch, nIndex); } - ADD_SERIALIZE_METHODS; - template inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(VARINT(nIndex)); READWRITE(branch); READWRITE(notarisationHash); } }; + class BetProtocol { protected: diff --git a/src/cc/disputepayout.cpp b/src/cc/disputepayout.cpp deleted file mode 100644 index 610342274..000000000 --- a/src/cc/disputepayout.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include - -#include "hash.h" -#include "chain.h" -#include "version.h" -#include "script/cc.h" -#include "cc/eval.h" -#include "cc/betprotocol.h" -#include "primitives/transaction.h" - - -/* - * Crypto-Condition EVAL method that resolves a dispute of a session - * - * IN: vm - AppVM virtual machine to verify states - * IN: params - condition params - * IN: disputeTx - transaction attempting to resolve dispute - * IN: nIn - index of input of dispute tx - * - * disputeTx: attempt to resolve a dispute - * - * in 0: Spends Session TX first output, reveals DisputeHeader - * out 0: OP_RETURN hash of payouts - */ -bool Eval::DisputePayout(AppVM &vm, std::vector params, const CTransaction &disputeTx, unsigned int nIn) -{ - if (disputeTx.vout.size() == 0) return Invalid("no-vouts"); - - // get payouts hash - uint256 payoutHash; - if (!GetOpReturnHash(disputeTx.vout[0].scriptPubKey, payoutHash)) - return Invalid("invalid-payout-hash"); - - // load params - uint16_t waitBlocks; - std::vector vmParams; - if (!E_UNMARSHAL(params, ss >> VARINT(waitBlocks); ss >> vmParams)) - return Invalid("malformed-params"); - - // ensure that enough time has passed - { - CTransaction sessionTx; - CBlockIndex sessionBlock; - - // if unconformed its too soon - if (!GetTxConfirmed(disputeTx.vin[0].prevout.hash, sessionTx, sessionBlock)) - return Error("couldnt-get-parent"); - - if (GetCurrentHeight() < sessionBlock.nHeight + waitBlocks) - return Invalid("dispute-too-soon"); // Not yet - } - - // get spends - std::vector spends; - if (!GetSpendsConfirmed(disputeTx.vin[0].prevout.hash, spends)) - return Error("couldnt-get-spends"); - - // verify result from VM - int maxLength = -1; - uint256 bestPayout; - for (int i=1; i vmState; - if (spends[i].vout.size() == 0) continue; - if (!GetOpReturnData(spends[i].vout[0].scriptPubKey, vmState)) continue; - auto out = vm.evaluate(vmParams, vmState); - uint256 resultHash = SerializeHash(out.second); - if (out.first > maxLength) { - maxLength = out.first; - bestPayout = resultHash; - } - // The below means that if for any reason there is a draw, the first dispute wins - else if (out.first == maxLength) { - if (bestPayout != payoutHash) { - fprintf(stderr, "WARNING: VM has multiple solutions of same length\n"); - bestPayout = resultHash; - } - } - } - - if (maxLength == -1) return Invalid("no-evidence"); - - return bestPayout == payoutHash ? Valid() : Invalid("wrong-payout"); -} diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 3c53f9866..e98b0dc6b 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -49,6 +49,10 @@ bool Eval::Dispatch(const CC *cond, const CTransaction &txTo, unsigned int nIn) return ImportPayout(vparams, txTo, nIn); } + if (ecode == EVAL_IMPORTCOIN) { + return ImportCoin(vparams, txTo, nIn); + } + return Invalid("invalid-code"); } @@ -143,6 +147,12 @@ bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t t } +uint32_t Eval::GetCurrentLedgerID() const +{ + return -1; // TODO +} + + /* * Get MoM from a notarisation tx hash */ @@ -157,6 +167,11 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data) return true; } +bool Eval::GetNotarisationData(int notarisationHeight, NotarisationData &data, bool verifyCanonical) const +{ + return false; +} + /* * Notarisation data, ie, OP_RETURN payload in notarisation transactions @@ -202,4 +217,26 @@ std::string EvalToStr(EvalCode c) char s[10]; sprintf(s, "0x%x", c); return std::string(s); + +} + + +uint256 SafeCheckMerkleBranch(uint256 hash, const std::vector& vMerkleBranch, int nIndex) +{ + if (nIndex == -1) + return uint256(); + for (auto it(vMerkleBranch.begin()); it != vMerkleBranch.end(); ++it) + { + if (nIndex & 1) { + if (*it == hash) { + // non canonical. hash may be equal to node but never on the right. + return uint256(); + } + hash = Hash(BEGIN(*it), END(*it), BEGIN(hash), END(hash)); + } + else + hash = Hash(BEGIN(hash), END(hash), BEGIN(*it), END(*it)); + nIndex >>= 1; + } + return hash; } diff --git a/src/cc/eval.h b/src/cc/eval.h index f998c9f3d..c65e5f863 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -20,8 +20,10 @@ * a possible code is EVAL_BITCOIN_SCRIPT, where the entire binary * after the code is interpreted as a bitcoin script. */ -#define FOREACH_EVAL(EVAL) \ - EVAL(EVAL_IMPORTPAYOUT, 0xe1) +#define FOREACH_EVAL(EVAL) \ + EVAL(EVAL_IMPORTPAYOUT, 0xe1) \ + EVAL(EVAL_IMPORTCOIN, 0xe2) + typedef uint8_t EvalCode; @@ -54,6 +56,11 @@ public: */ bool ImportPayout(std::vector params, const CTransaction &importTx, unsigned int nIn); + /* + * Import coin from another chain with same symbol + */ + bool ImportCoin(std::vector params, const CTransaction &importTx, unsigned int nIn); + /* * IO functions */ @@ -64,7 +71,10 @@ public: virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const; virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const; virtual bool GetNotarisationData(uint256 notarisationHash, NotarisationData &data) const; + virtual bool GetNotarisationData(int notarisationHeight, NotarisationData &data, + bool verifyCanonical) const; virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const; + virtual uint32_t GetCurrentLedgerID() const; }; @@ -87,7 +97,6 @@ public: evaluate(std::vector header, std::vector body) = 0; }; - /* * Data from notarisation OP_RETURN */ @@ -99,6 +108,8 @@ public: char symbol[64]; uint256 MoM; uint32_t MoMDepth; + uint256 MoMoM; + uint32_t MoMoMDepth; bool Parse(CScript scriptPubKey); }; @@ -140,4 +151,30 @@ bool DeserializeF(const std::vector vIn, T f) } +/* + * Merkle stuff + */ +uint256 SafeCheckMerkleBranch(uint256 hash, const std::vector& vMerkleBranch, int nIndex); + + +class MerkleBranch +{ +public: + int nIndex; + std::vector branch; + + MerkleBranch() {} + MerkleBranch(int i, std::vector b) : nIndex(i), branch(b) {} + uint256 Exec(uint256 hash) const { return SafeCheckMerkleBranch(hash, branch, nIndex); } + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(VARINT(nIndex)); + READWRITE(branch); + } +}; + + #endif /* CC_EVAL_H */ diff --git a/src/cc/importcoin.cpp b/src/cc/importcoin.cpp new file mode 100644 index 000000000..4c9331e73 --- /dev/null +++ b/src/cc/importcoin.cpp @@ -0,0 +1,147 @@ +#include "cc/importcoin.h" +#include "hash.h" +#include "script/cc.h" +#include "primitives/transaction.h" + + +/* + * Generate ImportCoin transaction. + * + * Contains an empty OP_RETURN as first output; this is critical for preventing a double + * import. If it doesn't contain this it's invalid. The empty OP_RETURN will hang around + * in the UTXO set and the transaction will be detected as a duplicate. + */ +CTransaction MakeImportCoinTransaction(const MomoProof proof, const CTransaction burnTx, const std::vector payouts) +{ + std::vector payload = + E_MARSHAL(ss << EVAL_IMPORTCOIN; ss << proof; ss << burnTx); + CMutableTransaction mtx; + mtx.vin.resize(1); + mtx.vin[0].scriptSig << payload; + mtx.vin[0].prevout.n = 10e8; + mtx.vout = payouts; + return CTransaction(mtx); +} + +CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector payouts) +{ + std::vector opret = E_MARSHAL(ss << VARINT(targetChain); ss << SerializeHash(payouts)); + return CTxOut(value, CScript() << OP_RETURN << opret); +} + + +/* + * CC Eval method for import coin. + * + * This method has to control *every* parameter of the ImportCoin transaction, so that the legal + * importTx for a valid burnTx is 1:1. There can be no two legal importTx transactions for a burnTx + * on another chain. + */ +bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) +{ + if (importTx.vout.size() == 0) return Invalid("no-vouts"); + + // params + MomoProof proof; + CTransaction burnTx; + if (!E_UNMARSHAL(params, ss >> proof; ss >> burnTx)) + return Invalid("invalid-params"); + + // Control all aspects of this transaction + // It must not be at all malleable + if (MakeImportCoinTransaction(proof, burnTx, importTx.vout).GetHash() != importTx.GetHash()) + return Invalid("non-canonical"); + + // burn params + uint32_t chain; // todo + uint256 payoutsHash; + std::vector burnOpret; + if (burnTx.vout.size() == 0) return Invalid("invalid-burn-outputs"); + GetOpReturnData(burnTx.vout[0].scriptPubKey, burnOpret); + if (!E_UNMARSHAL(burnOpret, ss >> VARINT(chain); ss >> payoutsHash)) + return Invalid("invalid-burn-params"); + + // check chain + if (chain != GetCurrentLedgerID()) + return Invalid("importcoin-wrong-chain"); + + // check burn amount + { + uint64_t burnAmount = burnTx.vout[0].nValue; + if (burnAmount == 0) + return Invalid("invalid-burn-amount"); + uint64_t totalOut = 0; + for (int i=0; i burnAmount) + return Invalid("payout-too-high"); + } + + // Check burntx shows correct outputs hash + if (payoutsHash != SerializeHash(importTx.vout)) + return Invalid("wrong-payouts"); + + // Check proof confirms existance of burnTx + { + NotarisationData data; + if (!GetNotarisationData(proof.notarisationHeight, data, true)) + return Invalid("coudnt-load-momom"); + + if (data.MoMoM != proof.branch.Exec(burnTx.GetHash())) + return Invalid("momom-check-fail"); + } + + return Valid(); +} + + +/* + * Required by main + */ +CAmount GetCoinImportValue(const CTransaction &tx) +{ + CScript scriptSig = tx.vin[0].scriptSig; + auto pc = scriptSig.begin(); + opcodetype opcode; + std::vector evalScript; + if (!scriptSig.GetOp(pc, opcode, evalScript)) + return false; + if (pc != scriptSig.end()) + return false; + EvalCode code; + MomoProof proof; + CTransaction burnTx; + if (!E_UNMARSHAL(evalScript, ss >> proof; ss >> burnTx)) + return 0; + return burnTx.vout.size() ? burnTx.vout[0].nValue : 0; +} + + +/* + * CoinImport is different enough from normal script execution that it's not worth + * making all the mods neccesary in the interpreter to do the dispatch correctly. + */ +bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& checker, CValidationState &state) +{ + auto pc = scriptSig.begin(); + opcodetype opcode; + std::vector evalScript; + + auto f = [&] () { + if (!scriptSig.GetOp(pc, opcode, evalScript)) + return false; + if (pc != scriptSig.end()) + return false; + if (evalScript.size() == 0) + return false; + if (evalScript.begin()[0] != EVAL_IMPORTCOIN) + return false; + // Ok, all looks good so far... + CC *cond = CCNewEval(evalScript); + bool out = checker.CheckEvalCondition(cond); + cc_free(cond); + return out; + }; + + return f() ? true : state.Invalid(false, 0, "invalid-coin-import"); +} diff --git a/src/cc/importcoin.h b/src/cc/importcoin.h new file mode 100644 index 000000000..8773b09a7 --- /dev/null +++ b/src/cc/importcoin.h @@ -0,0 +1,33 @@ +#ifndef CC_IMPORTCOIN_H +#define CC_IMPORTCOIN_H + +#include "cc/eval.h" +#include "primitives/transaction.h" +#include "script/interpreter.h" +#include + + +class MomoProof +{ +public: + MerkleBranch branch; + int notarisationHeight; + ADD_SERIALIZE_METHODS; + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(branch); + READWRITE(notarisationHeight); + } +}; + +CAmount GetCoinImportValue(const CTransaction &tx); + +CTransaction MakeImportCoinTransaction(const MomoProof proof, + const CTransaction burnTx, const std::vector payouts); + +CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector payouts); + +bool VerifyCoinImport(const CScript& scriptSig, + TransactionSignatureChecker& checker, CValidationState &state); + +#endif /* CC_IMPORTCOIN_H */ diff --git a/src/cc/importpayout.cpp b/src/cc/importpayout.cpp deleted file mode 100644 index 1363eb924..000000000 --- a/src/cc/importpayout.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#include "main.h" -#include "chain.h" -#include "streams.h" -#include "cc/eval.h" -#include "cc/betprotocol.h" -#include "primitives/transaction.h" - - -/* - * Crypto-Condition EVAL method that verifies a payout against a transaction - * notarised on another chain. - * - * IN: params - condition params - * IN: importTx - Payout transaction on value chain (KMD) - * IN: nIn - index of input of stake - * - * importTx: Spends stakeTx with payouts from asset chain - * - * in 0: Spends Stake TX and contains ImportPayout CC - * out 0: OP_RETURN MomProof, disputeTx - * out 1-: arbitrary payouts - * - * disputeTx: Spends sessionTx.0 (opener on asset chain) - * - * in 0: spends sessionTx.0 - * in 1-: anything - * out 0: OP_RETURN hash of payouts - * out 1-: anything - */ -bool Eval::ImportPayout(const std::vector params, const CTransaction &importTx, unsigned int nIn) -{ - if (importTx.vout.size() == 0) return Invalid("no-vouts"); - - // load data from vout[0] - MoMProof proof; - CTransaction disputeTx; - { - std::vector vopret; - GetOpReturnData(importTx.vout[0].scriptPubKey, vopret); - if (!E_UNMARSHAL(vopret, ss >> proof; ss >> disputeTx)) - return Invalid("invalid-payload"); - } - - // Check disputeTx.0 shows correct payouts - { - uint256 givenPayoutsHash; - GetOpReturnHash(disputeTx.vout[0].scriptPubKey, givenPayoutsHash); - std::vector payouts(importTx.vout.begin() + 1, importTx.vout.end()); - if (givenPayoutsHash != SerializeHash(payouts)) - return Invalid("wrong-payouts"); - } - - // Check disputeTx spends sessionTx.0 - // condition ImportPayout params is session ID from other chain - { - uint256 sessionHash; - if (!E_UNMARSHAL(params, ss >> sessionHash)) - return Invalid("malformed-params"); - if (disputeTx.vin[0].prevout != COutPoint(sessionHash, 0)) - return Invalid("wrong-session"); - } - - // Check disputeTx solves momproof from vout[0] - { - NotarisationData data; - if (!GetNotarisationData(proof.notarisationHash, data)) - return Invalid("coudnt-load-mom"); - - if (data.MoM != proof.Exec(disputeTx.GetHash())) - return Invalid("mom-check-fail"); - } - - return Valid(); -} diff --git a/src/chainparams.cpp b/src/chainparams.cpp index df258d782..cd8c2b451 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -532,11 +532,19 @@ public: BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); nEquihashN = N; nEquihashK = K; - genesis.nTime = 1296688602; - genesis.nBits = KOMODO_MINDIFF_NBITS; - genesis.nNonce = uint256S("0x0000000000000000000000000000000000000000000000000000000000000021"); - genesis.nSolution = ParseHex("0f2a976db4c4263da10fd5d38eb1790469cf19bdb4bf93450e09a72fdff17a3454326399"); + + + genesis = CreateGenesisBlock( + 1296688602, + uint256S("0x0000000000000000000000000000000000000000000000000000000000000009"), + ParseHex("01936b7db1eb4ac39f151b8704642d0a8bda13ec547d54cd5e43ba142fc6d8877cab07b3"), + 0x200f0f0f, 4, 0); + consensus.hashGenesisBlock = genesis.GetHash(); + + assert(consensus.hashGenesisBlock == uint256S("0x029f11d80ef9765602235e1bc9727e3eb6ba20839319f761fee920d63401e327")); + assert(genesis.hashMerkleRoot == uint256S("0xc4eaa58879081de3c24a7b117ed2b28300e7ec4c4c1dff1d3f1268b7857a4ddb")); + nDefaultPort = 17779; nPruneAfterHeight = 1000; diff --git a/src/coins.cpp b/src/coins.cpp index bb40af9cc..b8f5ffe2c 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -9,6 +9,7 @@ #include "version.h" #include "policy/fees.h" #include "komodo_defs.h" +#include "cc/importcoin.h" #include @@ -392,11 +393,13 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTransaction& tx,uint32_t tiptime) const { + CAmount value,nResult = 0; if ( interestp != 0 ) *interestp = 0; + if ( tx.IsCoinImport() ) + return GetCoinImportValue(tx); if ( tx.IsCoinBase() != 0 ) return 0; - CAmount value,nResult = 0; for (unsigned int i = 0; i < tx.vin.size(); i++) { value = GetOutputFor(tx.vin[i]).nValue; @@ -421,6 +424,7 @@ CAmount CCoinsViewCache::GetValueIn(int32_t nHeight,int64_t *interestp,const CTr return nResult; } + bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const { boost::unordered_map intermediates; @@ -457,7 +461,7 @@ bool CCoinsViewCache::HaveJoinSplitRequirements(const CTransaction& tx) const bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const { - if (!tx.IsCoinBase()) { + if (!tx.IsMint()) { for (unsigned int i = 0; i < tx.vin.size(); i++) { const COutPoint &prevout = tx.vin[i].prevout; const CCoins* coins = AccessCoins(prevout.hash); @@ -482,6 +486,9 @@ double CCoinsViewCache::GetPriority(const CTransaction &tx, int nHeight) const if (tx.vjoinsplit.size() > 0) { return MAX_PRIORITY; } + if (tx.IsCoinImport()) { + return MAX_PRIORITY; + } double dResult = 0.0; BOOST_FOREACH(const CTxIn& txin, tx.vin) diff --git a/src/coins.h b/src/coins.h index fcc32caae..9cee20712 100644 --- a/src/coins.h +++ b/src/coins.h @@ -97,6 +97,11 @@ public: nVersion = tx.nVersion; //nLockTime = tx.nLockTime; ClearUnspendable(); + + // This must live forever + if (tx.IsCoinImport()) { + vout.insert(vout.begin(), CTxOut(0, CScript() << OP_NOP << OP_RETURN)); + } } //! construct a CCoins from a CTransaction, at a given height diff --git a/src/main.cpp b/src/main.cpp index ab27a998f..104540419 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #include "addrman.h" #include "alert.h" #include "arith_uint256.h" +#include "cc/importcoin.h" #include "chainparams.h" #include "checkpoints.h" #include "checkqueue.h" @@ -21,6 +22,7 @@ #include "metrics.h" #include "net.h" #include "pow.h" +#include "script/interpreter.h" #include "txdb.h" #include "txmempool.h" #include "ui_interface.h" @@ -817,7 +819,10 @@ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, { if (tx.IsCoinBase()) return true; // Coinbases don't use vin normally - + + if (tx.IsCoinImport()) + return tx.vin[0].scriptSig.IsCoinImport(); + for (unsigned int i = 0; i < tx.vin.size(); i++) { const CTxOut& prev = mapInputs.GetOutputFor(tx.vin[i]); @@ -888,7 +893,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx) unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& inputs) { - if (tx.IsCoinBase()) + if (tx.IsCoinBase() || tx.IsCoinImport()) return 0; unsigned int nSigOps = 0; @@ -945,8 +950,8 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state, return state.DoS(dosLevel, error("ContextualCheckTransaction(): transaction is expired"), REJECT_INVALID, "tx-overwinter-expired"); } } - - if (!(tx.IsCoinBase() || tx.vjoinsplit.empty())) { + + if (!(tx.IsMint() || tx.vjoinsplit.empty())) { auto consensusBranchId = CurrentEpochBranchId(nHeight, Params().GetConsensus()); // Empty output script. CScript scriptCode; @@ -1001,7 +1006,7 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state, if (!CheckTransactionWithoutProofVerification(tx, state)) { return false; } else { - // Ensure that zk-SNARKs verify + // Ensure that zk-SNARKs v|| y BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { if (!joinsplit.Verify(*pzcashParams, verifier, tx.joinSplitPubKey)) { return state.DoS(100, error("CheckTransaction(): joinsplit does not verify"), @@ -1059,6 +1064,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio // Transactions can contain empty `vin` and `vout` so long as // `vjoinsplit` is non-empty. + // Migrations may also have empty `vin` if (tx.vin.empty() && tx.vjoinsplit.empty()) return state.DoS(10, error("CheckTransaction(): vin empty"), REJECT_INVALID, "bad-txns-vin-empty"); @@ -1167,7 +1173,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio } } - if (tx.IsCoinBase()) + if (tx.IsMint()) { // There should be no joinsplits in a coinbase transaction if (tx.vjoinsplit.size() > 0) @@ -1284,7 +1290,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pool.exists(hash)) { fprintf(stderr,"already in mempool\n"); - return false; + return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); } // Check for conflicts with in-memory transactions @@ -1326,31 +1332,36 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa view.SetBackend(viewMemPool); // do we already have it? + // This is what stops coin import transactions from being double spent; they + // grow the UTXO set size slightly if (view.HaveCoins(hash)) { fprintf(stderr,"view.HaveCoins(hash) error\n"); - return false; + return state.Invalid(false, REJECT_DUPLICATE, "already have coins"); } - // do all inputs exist? - // Note that this does not check for the presence of actual outputs (see the next check for that), - // and only helps with filling in pfMissingInputs (to determine missing vs spent). - BOOST_FOREACH(const CTxIn txin, tx.vin) + if (!tx.IsCoinImport()) { - if (!view.HaveCoins(txin.prevout.hash)) + // do all inputs exist? + // Note that this does not check for the presence of actual outputs (see the next check for that), + // and only helps with filling in pfMissingInputs (to determine missing vs spent). + BOOST_FOREACH(const CTxIn txin, tx.vin) { - if (pfMissingInputs) - *pfMissingInputs = true; - //fprintf(stderr,"missing inputs\n"); - return false; + if (!view.HaveCoins(txin.prevout.hash)) + { + if (pfMissingInputs) + *pfMissingInputs = true; + //fprintf(stderr,"missing inputs\n"); + return false; + } + } + + // are the actual inputs available? + if (!view.HaveInputs(tx)) + { + //fprintf(stderr,"accept failure.1\n"); + return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent"); } - } - - // are the actual inputs available? - if (!view.HaveInputs(tx)) - { - //fprintf(stderr,"accept failure.1\n"); - return state.Invalid(error("AcceptToMemoryPool: inputs already spent"),REJECT_DUPLICATE, "bad-txns-inputs-spent"); } // are the joinsplit's requirements met? if (!view.HaveJoinSplitRequirements(tx)) @@ -1393,11 +1404,13 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Keep track of transactions that spend a coinbase, which we re-scan // during reorgs to ensure COINBASE_MATURITY is still met. bool fSpendsCoinbase = false; - BOOST_FOREACH(const CTxIn &txin, tx.vin) { - const CCoins *coins = view.AccessCoins(txin.prevout.hash); - if (coins->IsCoinBase()) { - fSpendsCoinbase = true; - break; + if (!tx.IsCoinImport()) { + BOOST_FOREACH(const CTxIn &txin, tx.vin) { + const CCoins *coins = view.AccessCoins(txin.prevout.hash); + if (coins->IsCoinBase()) { + fSpendsCoinbase = true; + break; + } } } @@ -1478,6 +1491,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // There is a similar check in CreateNewBlock() to prevent creating // invalid blocks, however allowing such transactions into the mempool // can be exploited as a DoS attack. + // XXX: is this neccesary for CryptoConditions? if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { fprintf(stderr,"accept failure.10\n"); @@ -1967,7 +1981,7 @@ void static InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txundo, int nHeight) { - if (!tx.IsCoinBase()) // mark inputs spent + if (!tx.IsMint()) // mark inputs spent { txundo.vprevout.reserve(tx.vin.size()); BOOST_FOREACH(const CTxIn &txin, tx.vin) { @@ -2003,7 +2017,8 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight) bool CScriptCheck::operator()() { const CScript &scriptSig = ptxTo->vin[nIn].scriptSig; - if (!VerifyScript(scriptSig, scriptPubKey, nFlags, ServerTransactionSignatureChecker(ptxTo, nIn, amount, cacheStore, *txdata), consensusBranchId, &error)) { + ServerTransactionSignatureChecker checker(ptxTo, nIn, amount, cacheStore, *txdata); + if (!VerifyScript(scriptSig, scriptPubKey, nFlags, checker, consensusBranchId, &error)) { return ::error("CScriptCheck(): %s:%d VerifySignature failed: %s", ptxTo->GetHash().ToString(), nIn, ScriptErrorString(error)); } return true; @@ -2113,7 +2128,7 @@ bool ContextualCheckInputs( uint32_t consensusBranchId, std::vector *pvChecks) { - if (!tx.IsCoinBase()) + if (!tx.IsMint()) { if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs), consensusParams)) { return false; @@ -2165,7 +2180,13 @@ bool ContextualCheckInputs( } } } - + + if (tx.IsCoinImport()) + { + ServerTransactionSignatureChecker checker(&tx, 0, 0, false, txdata); + return VerifyCoinImport(tx.vin[0].scriptSig, checker, state); + } + return true; } @@ -2400,7 +2421,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } // restore inputs - if (i > 0) { // not coinbases + if (!tx.IsMint()) { const CTxUndo &txundo = blockUndo.vtxundo[i-1]; if (txundo.vprevout.size() != tx.vin.size()) return error("DisconnectBlock(): transaction and undo data inconsistent"); @@ -2681,7 +2702,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock(): too many sigops"), REJECT_INVALID, "bad-blk-sigops"); //fprintf(stderr,"ht.%d vout0 t%u\n",pindex->nHeight,tx.nLockTime); - if (!tx.IsCoinBase()) + if (!tx.IsMint()) { if (!view.HaveInputs(tx)) return state.DoS(100, error("ConnectBlock(): inputs missing/spent"), diff --git a/src/miner.cpp b/src/miner.cpp index 59d1b8a11..f57b53d98 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -11,6 +11,7 @@ #include "amount.h" #include "base58.h" #include "chainparams.h" +#include "cc/importcoin.h" #include "consensus/consensus.h" #include "consensus/upgrades.h" #include "consensus/validation.h" @@ -224,48 +225,55 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) double dPriority = 0; CAmount nTotalIn = 0; bool fMissingInputs = false; - BOOST_FOREACH(const CTxIn& txin, tx.vin) + if (tx.IsCoinImport()) { - // Read prev transaction - if (!view.HaveCoins(txin.prevout.hash)) - { - // This should never happen; all transactions in the memory - // pool should connect to either transactions in the chain - // or other transactions in the memory pool. - if (!mempool.mapTx.count(txin.prevout.hash)) - { - LogPrintf("ERROR: mempool transaction missing input\n"); - if (fDebug) assert("mempool transaction missing input" == 0); - fMissingInputs = true; - if (porphan) - vOrphan.pop_back(); - break; - } - - // Has to wait for dependencies - if (!porphan) - { - // Use list for automatic deletion - vOrphan.push_back(COrphan(&tx)); - porphan = &vOrphan.back(); - } - mapDependers[txin.prevout.hash].push_back(porphan); - porphan->setDependsOn.insert(txin.prevout.hash); - nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue; - continue; - } - const CCoins* coins = view.AccessCoins(txin.prevout.hash); - assert(coins); - - CAmount nValueIn = coins->vout[txin.prevout.n].nValue; + CAmount nValueIn = GetCoinImportValue(tx); nTotalIn += nValueIn; - - int nConf = nHeight - coins->nHeight; - - dPriority += (double)nValueIn * nConf; + dPriority += (double)nValueIn * 1000; // flat multiplier + } else { + BOOST_FOREACH(const CTxIn& txin, tx.vin) + { + // Read prev transaction + if (!view.HaveCoins(txin.prevout.hash)) + { + // This should never happen; all transactions in the memory + // pool should connect to either transactions in the chain + // or other transactions in the memory pool. + if (!mempool.mapTx.count(txin.prevout.hash)) + { + LogPrintf("ERROR: mempool transaction missing input\n"); + if (fDebug) assert("mempool transaction missing input" == 0); + fMissingInputs = true; + if (porphan) + vOrphan.pop_back(); + break; + } + + // Has to wait for dependencies + if (!porphan) + { + // Use list for automatic deletion + vOrphan.push_back(COrphan(&tx)); + porphan = &vOrphan.back(); + } + mapDependers[txin.prevout.hash].push_back(porphan); + porphan->setDependsOn.insert(txin.prevout.hash); + nTotalIn += mempool.mapTx.find(txin.prevout.hash)->GetTx().vout[txin.prevout.n].nValue; + continue; + } + const CCoins* coins = view.AccessCoins(txin.prevout.hash); + assert(coins); + + CAmount nValueIn = coins->vout[txin.prevout.n].nValue; + nTotalIn += nValueIn; + + int nConf = nHeight - coins->nHeight; + + dPriority += (double)nValueIn * nConf; + } + nTotalIn += tx.GetJoinSplitValueIn(); } - nTotalIn += tx.GetJoinSplitValueIn(); - + if (fMissingInputs) continue; // Priority is sum(valuein * age) / modified_txsize diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 35c12abc8..cdaba66c2 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -452,11 +452,21 @@ public: // Compute modified tx size for priority calculation (optionally given tx size) unsigned int CalculateModifiedSize(unsigned int nTxSize=0) const; + bool IsMint() const + { + return (vin.size() == 1 && vin[0].prevout.hash.IsNull()); + } + bool IsCoinBase() const { return (vin.size() == 1 && vin[0].prevout.IsNull()); } + bool IsCoinImport() const + { + return IsMint() && vin[0].prevout.n == 10e8; + } + friend bool operator==(const CTransaction& a, const CTransaction& b) { return a.hash == b.hash; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d9cc072e5..d09479008 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -9,7 +9,7 @@ #include "checkpoints.h" #include "base58.h" #include "consensus/validation.h" -#include "cc/betprotocol.h" +#include "cc/eval.h" #include "main.h" #include "primitives/transaction.h" #include "rpcserver.h" @@ -1011,7 +1011,7 @@ UniValue txMoMproof(const UniValue& params, bool fHelp) // Encode and return CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION); - ssProof << MoMProof(nIndex, branch, notarisationHash); + ssProof << std::make_pair(notarisationHash, MerkleBranch(nIndex, branch)); return HexStr(ssProof.begin(), ssProof.end()); } diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index 5438102c3..4a2eac2bc 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -3,17 +3,20 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include + #include "interpreter.h" #include "consensus/upgrades.h" #include "primitives/transaction.h" +#include "cc/eval.h" #include "crypto/ripemd160.h" #include "crypto/sha1.h" #include "crypto/sha256.h" #include "pubkey.h" #include "script/script.h" #include "uint256.h" -#include "cryptoconditions/include/cryptoconditions.h" + using namespace std; diff --git a/src/script/interpreter.h b/src/script/interpreter.h index 7aa0d5099..b4c537a2d 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -186,5 +186,4 @@ bool VerifyScript( const BaseSignatureChecker& checker, uint32_t consensusBranchId, ScriptError* serror = NULL); - #endif // BITCOIN_SCRIPT_INTERPRETER_H diff --git a/src/script/script.cpp b/src/script/script.cpp index a130df4aa..160c57016 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -8,8 +8,10 @@ #include "tinyformat.h" #include "utilstrencodings.h" #include "script/cc.h" +#include "cc/eval.h" #include "cryptoconditions/include/cryptoconditions.h" + namespace { inline std::string ValueString(const std::vector& vch) { @@ -266,6 +268,17 @@ bool CScript::MayAcceptCryptoCondition() const return out; } +bool CScript::IsCoinImport() const +{ + const_iterator pc = this->begin(); + vector data; + opcodetype opcode; + if (this->GetOp(pc, opcode, data)) + if (opcode > OP_0 && opcode <= OP_PUSHDATA4) + return data.begin()[0] == EVAL_IMPORTCOIN; + return false; +} + bool CScript::IsPushOnly() const { const_iterator pc = begin(); diff --git a/src/script/script.h b/src/script/script.h index e5328cf06..864a92f1f 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -570,6 +570,7 @@ public: bool IsPayToScriptHash() const; bool IsPayToCryptoCondition() const; + bool IsCoinImport() const; bool MayAcceptCryptoCondition() const; /** Called by IsStandardTx and P2SH/BIP62 VerifyScript (which makes it consensus-critical). */ diff --git a/src/test-komodo/main.cpp b/src/test-komodo/main.cpp index 527d7666e..0ce8740b3 100644 --- a/src/test-komodo/main.cpp +++ b/src/test-komodo/main.cpp @@ -1,7 +1,9 @@ #include "key.h" +#include "base58.h" #include "chainparams.h" #include "gtest/gtest.h" #include "crypto/common.h" +#include "testutils.h" int main(int argc, char **argv) { @@ -9,6 +11,11 @@ int main(int argc, char **argv) { ECC_Start(); SelectParams(CBaseChainParams::REGTEST); + CBitcoinSecret vchSecret; + // this returns false due to network prefix mismatch but works anyway + vchSecret.SetString(notarySecret); + notaryKey = vchSecret.GetKey(); + testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp new file mode 100644 index 000000000..6379aac7f --- /dev/null +++ b/src/test-komodo/test_coinimport.cpp @@ -0,0 +1,206 @@ + +#include +#include + +#include "cc/importcoin.h" +#include "cc/eval.h" +#include "base58.h" +#include "core_io.h" +#include "key.h" +#include "main.h" +#include "script/cc.h" +#include "primitives/transaction.h" +#include "script/interpreter.h" +#include "script/serverchecker.h" +#include "txmempool.h" + +#include "testutils.h" + + +extern Eval* EVAL_TEST; + +namespace TestCoinImport { + + +static uint8_t testNum = 0; + +class TestCoinImport : public ::testing::Test, public Eval { +public: + CMutableTransaction burnTx; + std::vector payouts; + MomoProof proof; + uint256 MoMoM; + CMutableTransaction importTx; + uint32_t chainId = 2; + CAmount amount = 100; + + void SetImportTx() { + CTxOut burnOutput = MakeBurnOutput(amount, chainId, payouts); + burnTx.vout.push_back(burnOutput); + MoMoM = burnTx.GetHash(); // TODO: an actual branch + importTx = CMutableTransaction(MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts)); + } + + uint32_t GetCurrentLedgerID() const { return chainId; } + + bool GetNotarisationData(int notarisationHeight, NotarisationData &data, bool verifyCanonical) const + { + if (MoMoM.IsNull()) return false; + data.MoMoM = MoMoM; + return true; + } + +protected: + static void SetUpTestCase() { setupChain(); } + virtual void SetUp() { + ASSETCHAINS_CC = 1; + EVAL_TEST = this; + + std::vector fakepk; + fakepk.resize(33); + fakepk.begin()[0] = testNum++; + payouts.push_back(CTxOut(amount, CScript() << fakepk << OP_CHECKSIG)); + SetImportTx(); + } + + + void TestRunCCEval(CMutableTransaction mtx) + { + CTransaction importTx(mtx); + PrecomputedTransactionData txdata(importTx); + ServerTransactionSignatureChecker checker(&importTx, 0, 0, false, txdata); + CValidationState verifystate; + if (!VerifyCoinImport(importTx.vin[0].scriptSig, checker, verifystate)) + printf("TestRunCCEval: %s\n", verifystate.GetRejectReason().data()); + } +}; + + +TEST_F(TestCoinImport, testProcessImportThroughPipeline) +{ + CValidationState mainstate; + CTransaction tx(importTx); + + // first should work + acceptTxFail(tx); + + // should fail in mempool + ASSERT_FALSE(acceptTx(tx, mainstate)); + EXPECT_EQ("already in mempool", mainstate.GetRejectReason()); + + // should fail in persisted UTXO set + generateBlock(); + ASSERT_FALSE(acceptTx(tx, mainstate)); + EXPECT_EQ("already have coins", mainstate.GetRejectReason()); + ASSERT_TRUE(pcoinsTip->HaveCoins(tx.GetHash())); + + // Now disconnect the block + CValidationState invalstate; + if (!InvalidateBlock(invalstate, chainActive.Tip())) { + FAIL() << invalstate.GetRejectReason(); + } + ASSERT_FALSE(pcoinsTip->HaveCoins(tx.GetHash())); + + // should be back in mempool + ASSERT_FALSE(acceptTx(tx, mainstate)); + EXPECT_EQ("already in mempool", mainstate.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testNoVouts) +{ + importTx.vout.resize(0); + TestRunCCEval(importTx); + EXPECT_EQ("no-vouts", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testInvalidParams) +{ + std::vector payload = E_MARSHAL(ss << EVAL_IMPORTCOIN; ss << 'a'); + importTx.vin[0].scriptSig = CScript() << payload; + TestRunCCEval(importTx); + EXPECT_EQ("invalid-params", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testNonCanonical) +{ + importTx.nLockTime = 10; + TestRunCCEval(importTx); + EXPECT_EQ("non-canonical", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testInvalidBurnOutputs) +{ + burnTx.vout.resize(0); + MoMoM = burnTx.GetHash(); // TODO: an actual branch + CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts); + TestRunCCEval(tx); + EXPECT_EQ("invalid-burn-outputs", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testInvalidBurnParams) +{ + burnTx.vout[0].scriptPubKey = CScript() << OP_RETURN << E_MARSHAL(ss << VARINT(chainId)); + MoMoM = burnTx.GetHash(); // TODO: an actual branch + CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts); + TestRunCCEval(tx); + EXPECT_EQ("invalid-burn-params", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testWrongChainId) +{ + chainId = 0; + TestRunCCEval(importTx); + EXPECT_EQ("importcoin-wrong-chain", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testInvalidBurnAmount) +{ + burnTx.vout[0].nValue = 0; + MoMoM = burnTx.GetHash(); // TODO: an actual branch + CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts); + TestRunCCEval(tx); + EXPECT_EQ("invalid-burn-amount", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testPayoutTooHigh) +{ + importTx.vout[0].nValue = 101; + TestRunCCEval(importTx); + EXPECT_EQ("payout-too-high", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testInvalidPayouts) +{ + importTx.vout[0].nValue = 40; + importTx.vout.push_back(importTx.vout[0]); + TestRunCCEval(importTx); + EXPECT_EQ("wrong-payouts", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testCouldntLoadMomom) +{ + MoMoM.SetNull(); + TestRunCCEval(importTx); + EXPECT_EQ("coudnt-load-momom", state.GetRejectReason()); +} + + +TEST_F(TestCoinImport, testMomomCheckFail) +{ + MoMoM.SetNull(); + MoMoM.begin()[0] = 1; + TestRunCCEval(importTx); + EXPECT_EQ("momom-check-fail", state.GetRejectReason()); +} + +} /* namespace TestCoinImport */ diff --git a/src/test-komodo/test_cryptoconditions.cpp b/src/test-komodo/test_cryptoconditions.cpp index f1037a2ae..4fddf9c55 100644 --- a/src/test-komodo/test_cryptoconditions.cpp +++ b/src/test-komodo/test_cryptoconditions.cpp @@ -12,11 +12,6 @@ #include "testutils.h" -CKey notaryKey; - -std::string pubkey = "0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47"; -std::string secret = "UxFWWxsf1d7w7K5TvAWSkeX4H95XQKwdwGv49DXwWUTzPTTjHBbU"; - class CCTest : public ::testing::Test { public: @@ -32,11 +27,6 @@ protected: virtual void SetUp() { // enable CC ASSETCHAINS_CC = 1; - // Notary key - CBitcoinSecret vchSecret; - // this returns false due to network prefix mismatch but works anyway - vchSecret.SetString(secret); - notaryKey = vchSecret.GetKey(); } }; diff --git a/src/test-komodo/test_eval_bet.cpp b/src/test-komodo/test_eval_bet.cpp index 6f41608b9..4dfcf1cab 100644 --- a/src/test-komodo/test_eval_bet.cpp +++ b/src/test-komodo/test_eval_bet.cpp @@ -208,7 +208,7 @@ public: int nIndex = 5; std::vector vBranch; vBranch.resize(3); - return MoMProof(nIndex, vBranch, EvalMock::NotarisationHash()); + return {MerkleBranch(nIndex, vBranch), EvalMock::NotarisationHash()}; } CMutableTransaction ImportPayoutTx() @@ -237,7 +237,7 @@ public: eval.currentHeight = currentHeight; MoMProof proof = GetMoMProof(); - eval.MoM = proof.Exec(DisputeTx(Player2).GetHash()); + eval.MoM = proof.branch.Exec(DisputeTx(Player2).GetHash()); EVAL_TEST = &eval; return eval; @@ -585,7 +585,7 @@ TEST_F(TestBet, testImportPayoutMomFail) EvalMock eval = ebet.SetEvalMock(12); MoMProof proof = ebet.GetMoMProof(); - proof.nIndex ^= 1; + proof.branch.nIndex ^= 1; CMutableTransaction importTx = ebet.bet.MakeImportPayoutTx( ebet.Payouts(Player2), ebet.DisputeTx(Player2), uint256(), proof); diff --git a/src/test-komodo/test_eval_notarisation.cpp b/src/test-komodo/test_eval_notarisation.cpp index 86d5f58c4..f0ce45358 100644 --- a/src/test-komodo/test_eval_notarisation.cpp +++ b/src/test-komodo/test_eval_notarisation.cpp @@ -15,7 +15,6 @@ #include "testutils.h" -extern Eval* EVAL_TEST; extern int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); @@ -61,7 +60,7 @@ static auto noop = [&](CMutableTransaction &mtx){}; template -void SetEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify) +void SetupEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify) { eval.nNotaries = komodo_notaries(eval.notaries, 780060, 1522946781); @@ -80,8 +79,6 @@ void SetEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify) eval.txs[notary.GetHash()] = CTransaction(notary); eval.blocks[notary.GetHash()].nHeight = 780060; eval.blocks[notary.GetHash()].nTime = 1522946781; - - EVAL_TEST = &eval; } @@ -94,12 +91,12 @@ static bool init = DecodeHexTx(notaryTx, rawNotaryTx); static uint256 proofTxHash = uint256S("37f76551a16093fbb0a92ee635bbd45b3460da8fd00cf7d5a6b20d93e727fe4c"); static auto vMomProof = ParseHex("0303faecbdd4b3da128c2cd2701bb143820a967069375b2ec5b612f39bbfe78a8611978871c193457ab1e21b9520f4139f113b8d75892eb93ee247c18bccfd067efed7eacbfcdc8946cf22de45ad536ec0719034fb9bc825048fe6ab61fee5bd6e9aae0bb279738d46673c53d68eb2a72da6dbff215ee41a4d405a74ff7cd355805b"); // $ fiat/bots txMoMproof $proofTxHash - +/* TEST(TestEvalNotarisation, testGetNotarisation) { EvalMock eval; CMutableTransaction notary(notaryTx); - SetEval(eval, notary, noop); + SetupEval(eval, notary, noop); NotarisationData data; ASSERT_TRUE(eval.GetNotarisationData(notary.GetHash(), data)); @@ -111,7 +108,7 @@ TEST(TestEvalNotarisation, testGetNotarisation) MoMProof proof; E_UNMARSHAL(vMomProof, ss >> proof); - EXPECT_EQ(data.MoM, proof.Exec(proofTxHash)); + EXPECT_EQ(data.MoM, proof.branch.Exec(proofTxHash)); } @@ -119,13 +116,14 @@ TEST(TestEvalNotarisation, testInvalidNotaryPubkey) { EvalMock eval; CMutableTransaction notary(notaryTx); - SetEval(eval, notary, noop); + SetupEval(eval, notary, noop); memset(eval.notaries[10], 0, 33); NotarisationData data; ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data)); } +*/ TEST(TestEvalNotarisation, testInvalidNotarisationBadOpReturn) @@ -134,7 +132,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationBadOpReturn) CMutableTransaction notary(notaryTx); notary.vout[1].scriptPubKey = CScript() << OP_RETURN << 0; - SetEval(eval, notary, noop); + SetupEval(eval, notary, noop); NotarisationData data; ASSERT_FALSE(eval.GetNotarisationData(notary.GetHash(), data)); @@ -146,7 +144,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationTxNotEnoughSigs) EvalMock eval; CMutableTransaction notary(notaryTx); - SetEval(eval, notary, [](CMutableTransaction &tx) { + SetupEval(eval, notary, [](CMutableTransaction &tx) { tx.vin.resize(10); }); @@ -160,7 +158,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationTxDoesntExist) EvalMock eval; CMutableTransaction notary(notaryTx); - SetEval(eval, notary, noop); + SetupEval(eval, notary, noop); NotarisationData data; ASSERT_FALSE(eval.GetNotarisationData(uint256(), data)); @@ -172,7 +170,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationDupeNotary) EvalMock eval; CMutableTransaction notary(notaryTx); - SetEval(eval, notary, [](CMutableTransaction &tx) { + SetupEval(eval, notary, [](CMutableTransaction &tx) { tx.vin[1] = tx.vin[3]; }); @@ -186,7 +184,7 @@ TEST(TestEvalNotarisation, testInvalidNotarisationInputNotCheckSig) EvalMock eval; CMutableTransaction notary(notaryTx); - SetEval(eval, notary, [&](CMutableTransaction &tx) { + SetupEval(eval, notary, [&](CMutableTransaction &tx) { int i = 1; CMutableTransaction txIn; txIn.vout.resize(1); diff --git a/src/test-komodo/testutils.cpp b/src/test-komodo/testutils.cpp new file mode 100644 index 000000000..c3baf4fb6 --- /dev/null +++ b/src/test-komodo/testutils.cpp @@ -0,0 +1,129 @@ +#include +#include +#include + +#include "core_io.h" +#include "key.h" +#include "main.h" +#include "miner.h" +#include "random.h" +#include "rpcserver.h" +#include "rpcprotocol.h" +#include "txdb.h" +#include "util.h" +#include "utilstrencodings.h" +#include "utiltime.h" +#include "consensus/validation.h" +#include "primitives/transaction.h" +#include "script/cc.h" +#include "script/interpreter.h" + +#include "testutils.h" + + +std::string notaryPubkey = "0205a8ad0c1dbc515f149af377981aab58b836af008d4d7ab21bd76faf80550b47"; +std::string notarySecret = "UxFWWxsf1d7w7K5TvAWSkeX4H95XQKwdwGv49DXwWUTzPTTjHBbU"; +CKey notaryKey; + + +/* + * We need to have control of clock, + * otherwise block production can fail. + */ +int64_t nMockTime; + +extern uint32_t USE_EXTERNAL_PUBKEY; + +void setupChain() +{ + SelectParams(CBaseChainParams::REGTEST); + + // Settings to get block reward + //NOTARY_PUBKEY = _NOTARY_PUBKEY; + USE_EXTERNAL_PUBKEY = 1; + mapArgs["-mineraddress"] = "bogus"; + COINBASE_MATURITY = 1; + // Global mock time + nMockTime = GetTime(); + + // Init blockchain + ClearDatadirCache(); + auto pathTemp = GetTempPath() / strprintf("test_komodo_%li_%i", GetTime(), GetRand(100000)); + boost::filesystem::create_directories(pathTemp); + mapArgs["-datadir"] = pathTemp.string(); + pblocktree = new CBlockTreeDB(1 << 20, true); + CCoinsViewDB *pcoinsdbview = new CCoinsViewDB(1 << 23, true); + pcoinsTip = new CCoinsViewCache(pcoinsdbview); + InitBlockIndex(); +} + + +void generateBlock(CBlock *block) +{ + UniValue params; + params.setArray(); + params.push_back(1); + uint256 blockId; + + SetMockTime(nMockTime++); // CreateNewBlock can fail if not enough time passes + + try { + UniValue out = generate(params, false); + blockId.SetHex(out[0].getValStr()); + } catch (const UniValue& e) { + FAIL() << "failed to create block: " << e.write().data(); + } + if (block) ASSERT_TRUE(ReadBlockFromDisk(*block, mapBlockIndex[blockId])); +} + + +void acceptTxFail(const CTransaction tx) +{ + CValidationState state; + if (!acceptTx(tx, state)) FAIL() << state.GetRejectReason(); +} + + +bool acceptTx(const CTransaction tx, CValidationState &state) +{ + LOCK(cs_main); + return AcceptToMemoryPool(mempool, state, tx, false, NULL); +} + + +static CMutableTransaction spendTx(const CTransaction &txIn, int nOut=0) +{ + CMutableTransaction mtx; + mtx.vin.resize(1); + mtx.vin[0].prevout.hash = txIn.GetHash(); + mtx.vin[0].prevout.n = nOut; + mtx.vout.resize(1); + mtx.vout[0].nValue = txIn.vout[nOut].nValue - 1000; + return mtx; +} + + +/* + * In order to do tests there needs to be inputs to spend. + * This method creates a block and returns a transaction that spends the coinbase. + */ +void getInputTx(CScript scriptPubKey, CTransaction &txIn) +{ + // Get coinbase + CBlock block; + generateBlock(&block); + CTransaction coinbase = block.vtx[0]; + + // Create tx + auto mtx = spendTx(coinbase); + mtx.vout[0].scriptPubKey = scriptPubKey; + uint256 hash = SignatureHash(coinbase.vout[0].scriptPubKey, mtx, 0, SIGHASH_ALL, 0, 0); + std::vector vchSig; + notaryKey.Sign(hash, vchSig); + vchSig.push_back((unsigned char)SIGHASH_ALL); + mtx.vin[0].scriptSig << vchSig; + + // Accept + acceptTxFail(mtx); + txIn = CTransaction(mtx); +} diff --git a/src/test-komodo/testutils.h b/src/test-komodo/testutils.h index df8e88cd9..92d28b587 100644 --- a/src/test-komodo/testutils.h +++ b/src/test-komodo/testutils.h @@ -1,7 +1,7 @@ #ifndef TESTUTILS_H #define TESTUTILS_H -#include "script/cc.h" +#include "main.h" #define VCH(a,b) std::vector(a, a + b) @@ -12,4 +12,16 @@ static char ccjsonerr[1000] = "\0"; if (!o) FAIL() << "bad json: " << ccjsonerr; +extern std::string notaryPubkey; +extern std::string notarySecret; +extern CKey notaryKey; + + +void setupChain(); +void generateBlock(CBlock *block=NULL); +bool acceptTx(const CTransaction tx, CValidationState &state); +void acceptTxFail(const CTransaction tx); +void getInputTx(CScript scriptPubKey, CTransaction &txIn); + + #endif /* TESTUTILS_H */ diff --git a/src/txmempool.cpp b/src/txmempool.cpp index dd985f500..9527dd854 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -104,8 +104,10 @@ bool CTxMemPool::addUnchecked(const uint256& hash, const CTxMemPoolEntry &entry, LOCK(cs); mapTx.insert(entry); const CTransaction& tx = mapTx.find(hash)->GetTx(); - for (unsigned int i = 0; i < tx.vin.size(); i++) - mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i); + if (!tx.IsCoinImport()) { + for (unsigned int i = 0; i < tx.vin.size(); i++) + mapNextTx[tx.vin[i].prevout] = CInPoint(&tx, i); + } BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { mapNullifiers[nf] = &tx; From 3c7604133e7c5f9153f4c990d7b5f59b993f1809 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 17 Apr 2018 08:40:02 -0500 Subject: [PATCH 0042/1123] tombstone for import --- src/cc/importcoin.cpp | 63 +++++++++++++++++++++-------- src/cc/importcoin.h | 6 +++ src/coins.h | 5 --- src/main.cpp | 21 ++++++++-- src/primitives/transaction.h | 4 +- src/test-komodo/test_coinimport.cpp | 39 ++++++++++++++++-- 6 files changed, 109 insertions(+), 29 deletions(-) diff --git a/src/cc/importcoin.cpp b/src/cc/importcoin.cpp index 4c9331e73..d5f626683 100644 --- a/src/cc/importcoin.cpp +++ b/src/cc/importcoin.cpp @@ -1,4 +1,5 @@ #include "cc/importcoin.h" +#include "coins.h" #include "hash.h" #include "script/cc.h" #include "primitives/transaction.h" @@ -16,9 +17,7 @@ CTransaction MakeImportCoinTransaction(const MomoProof proof, const CTransaction std::vector payload = E_MARSHAL(ss << EVAL_IMPORTCOIN; ss << proof; ss << burnTx); CMutableTransaction mtx; - mtx.vin.resize(1); - mtx.vin[0].scriptSig << payload; - mtx.vin[0].prevout.n = 10e8; + mtx.vin.push_back(CTxIn(COutPoint(burnTx.GetHash(), 10e8), CScript() << payload)); mtx.vout = payouts; return CTransaction(mtx); } @@ -95,25 +94,33 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp } -/* - * Required by main - */ -CAmount GetCoinImportValue(const CTransaction &tx) +static bool UnmarshalImportTx(const CTransaction &importTx, MomoProof &proof, CTransaction &burnTx) { - CScript scriptSig = tx.vin[0].scriptSig; + CScript scriptSig = importTx.vin[0].scriptSig; auto pc = scriptSig.begin(); opcodetype opcode; std::vector evalScript; - if (!scriptSig.GetOp(pc, opcode, evalScript)) - return false; - if (pc != scriptSig.end()) - return false; - EvalCode code; + int code; + bool out = false; + if (scriptSig.GetOp(pc, opcode, evalScript)) + if (pc == scriptSig.end()) + out = E_UNMARSHAL(evalScript, ss >> VARINT(code); ss >> proof; ss >> burnTx); + return code == EVAL_IMPORTCOIN && out; +} + + +/* + * Required by main + * TODO: test + */ +CAmount GetCoinImportValue(const CTransaction &tx) +{ MomoProof proof; CTransaction burnTx; - if (!E_UNMARSHAL(evalScript, ss >> proof; ss >> burnTx)) - return 0; - return burnTx.vout.size() ? burnTx.vout[0].nValue : 0; + if (UnmarshalImportTx(tx, proof, burnTx)) { + return burnTx.vout.size() ? burnTx.vout[0].nValue : 0; + } + return 0; } @@ -145,3 +152,27 @@ bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& che return f() ? true : state.Invalid(false, 0, "invalid-coin-import"); } + + +void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, int nHeight) +{ + uint256 burnHash = importTx.vin[0].prevout.hash; + CCoinsModifier modifier = inputs.ModifyCoins(burnHash); + modifier->nHeight = nHeight; + modifier->nVersion = 1; + modifier->vout.push_back(CTxOut(0, CScript() << OP_0)); +} + + +void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs) +{ + uint256 burnHash = importTx.vin[0].prevout.hash; + inputs.ModifyCoins(burnHash)->Clear(); +} + + +int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &inputs) +{ + uint256 burnHash = importTx.vin[0].prevout.hash; + return inputs.HaveCoins(burnHash); +} diff --git a/src/cc/importcoin.h b/src/cc/importcoin.h index 8773b09a7..13fefd513 100644 --- a/src/cc/importcoin.h +++ b/src/cc/importcoin.h @@ -2,6 +2,7 @@ #define CC_IMPORTCOIN_H #include "cc/eval.h" +#include "coins.h" #include "primitives/transaction.h" #include "script/interpreter.h" #include @@ -30,4 +31,9 @@ CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& checker, CValidationState &state); + +void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, int nHeight); +void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs); +int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &inputs); + #endif /* CC_IMPORTCOIN_H */ diff --git a/src/coins.h b/src/coins.h index 9cee20712..fcc32caae 100644 --- a/src/coins.h +++ b/src/coins.h @@ -97,11 +97,6 @@ public: nVersion = tx.nVersion; //nLockTime = tx.nLockTime; ClearUnspendable(); - - // This must live forever - if (tx.IsCoinImport()) { - vout.insert(vout.begin(), CTxOut(0, CScript() << OP_NOP << OP_RETURN)); - } } //! construct a CCoins from a CTransaction, at a given height diff --git a/src/main.cpp b/src/main.cpp index 104540419..67220e891 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1332,15 +1332,19 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa view.SetBackend(viewMemPool); // do we already have it? - // This is what stops coin import transactions from being double spent; they - // grow the UTXO set size slightly if (view.HaveCoins(hash)) { fprintf(stderr,"view.HaveCoins(hash) error\n"); return state.Invalid(false, REJECT_DUPLICATE, "already have coins"); } - if (!tx.IsCoinImport()) + if (tx.IsCoinImport()) + { + // Inverse of normal case; if input exists, it's been spent + if (ExistsImportTombstone(tx, view)) + return state.Invalid(false, REJECT_DUPLICATE, "import tombstone exists"); + } + else { // do all inputs exist? // Note that this does not check for the presence of actual outputs (see the next check for that), @@ -2007,6 +2011,13 @@ void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, CTxUndo &txund } } inputs.ModifyCoins(tx.GetHash())->FromTx(tx, nHeight); // add outputs + + // Unorthodox state + if (tx.IsCoinImport()) { + // add a tombstone for the burnTx + AddImportTombstone(tx, inputs, nHeight); + } + } void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight) @@ -2465,6 +2476,10 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } } } + else if (tx.IsCoinImport()) + { + RemoveImportTombstone(tx, view); + } } // set the old best anchor back diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index cdaba66c2..88ee9a312 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -454,7 +454,7 @@ public: bool IsMint() const { - return (vin.size() == 1 && vin[0].prevout.hash.IsNull()); + return IsCoinImport() || IsCoinBase(); } bool IsCoinBase() const @@ -464,7 +464,7 @@ public: bool IsCoinImport() const { - return IsMint() && vin[0].prevout.n == 10e8; + return (vin.size() == 1 && vin[0].prevout.n == 10e8); } friend bool operator==(const CTransaction& a, const CTransaction& b) diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index 6379aac7f..96543d80b 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -35,8 +35,8 @@ public: CAmount amount = 100; void SetImportTx() { - CTxOut burnOutput = MakeBurnOutput(amount, chainId, payouts); - burnTx.vout.push_back(burnOutput); + burnTx.vout.resize(0); + burnTx.vout.push_back(MakeBurnOutput(amount, chainId, payouts)); MoMoM = burnTx.GetHash(); // TODO: an actual branch importTx = CMutableTransaction(MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts)); } @@ -88,7 +88,7 @@ TEST_F(TestCoinImport, testProcessImportThroughPipeline) ASSERT_FALSE(acceptTx(tx, mainstate)); EXPECT_EQ("already in mempool", mainstate.GetRejectReason()); - // should fail in persisted UTXO set + // should be in persisted UTXO set generateBlock(); ASSERT_FALSE(acceptTx(tx, mainstate)); EXPECT_EQ("already have coins", mainstate.GetRejectReason()); @@ -107,6 +107,39 @@ TEST_F(TestCoinImport, testProcessImportThroughPipeline) } +TEST_F(TestCoinImport, testImportTombstone) +{ + CValidationState mainstate; + // By setting an unspendable output, there will be no addition to UTXO + // Nonetheless, we dont want to be able to import twice + payouts[0].scriptPubKey = CScript() << OP_RETURN; + SetImportTx(); + MoMoM = burnTx.GetHash(); // TODO: an actual branch + CTransaction tx(importTx); + + // first should work + acceptTxFail(tx); + + // should be in persisted UTXO set + generateBlock(); + ASSERT_FALSE(acceptTx(tx, mainstate)); + EXPECT_EQ("import tombstone exists", mainstate.GetRejectReason()); + ASSERT_TRUE(pcoinsTip->HaveCoins(burnTx.GetHash())); + + // Now disconnect the block + CValidationState invalstate; + if (!InvalidateBlock(invalstate, chainActive.Tip())) { + FAIL() << invalstate.GetRejectReason(); + } + // Tombstone should be gone from utxo set + ASSERT_FALSE(pcoinsTip->HaveCoins(burnTx.GetHash())); + + // should be back in mempool + ASSERT_FALSE(acceptTx(tx, mainstate)); + EXPECT_EQ("already in mempool", mainstate.GetRejectReason()); +} + + TEST_F(TestCoinImport, testNoVouts) { importTx.vout.resize(0); From ea5071d27f11dc3cfa692794bd97b8e35c51c69b Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Tue, 1 May 2018 15:13:47 +0700 Subject: [PATCH 0043/1123] Reorder assetchain params for better readability --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index 517687097..61eca28e0 100755 --- a/src/assetchains +++ b/src/assetchains @@ -21,7 +21,7 @@ function komodo_asset () supply=" " fi - $komodo_binary -pubkey=$pubkey -ac_name=$1 $supply -addnode=$seed_ip $gen $args & + $komodo_binary -ac_name=$1 $gen $supply $args -pubkey=$pubkey -addnode=$seed_ip & sleep $delay } From 57023d5b91caf5062ca9d1dcedf843edb95f4aa0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 4 May 2018 17:45:09 +0300 Subject: [PATCH 0044/1123] 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 20c3ac51c21777c3f98cd1f3ad9223f943a18874 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 9 May 2018 16:17:28 -0300 Subject: [PATCH 0045/1123] wip --- .gitignore | 1 + src/Makefile.am | 5 +- src/Makefile.ktest.include | 3 +- src/cc/betprotocol.cpp | 3 +- src/cc/eval.cpp | 48 ++--- src/cc/eval.h | 105 ++++++++--- src/cc/import.cpp | 70 ++++++++ src/cc/utils.cpp | 0 src/cc/utils.h | 34 ++++ src/coins.cpp | 2 +- src/crosschain.cpp | 217 ++++++++++++++++++++++ src/crosschain.h | 21 +++ src/{cc => }/importcoin.cpp | 68 +------ src/{cc => }/importcoin.h | 6 +- src/init.cpp | 4 + src/main.cpp | 12 +- src/miner.cpp | 2 +- src/notarisationdb.cpp | 46 +++++ src/notarisationdb.h | 26 +++ src/primitives/block.cpp | 30 +++- src/primitives/block.h | 4 + src/rpcblockchain.cpp | 103 +++-------- src/script/cc.h | 3 +- src/test-komodo/main.cpp | 1 + src/test-komodo/test_coinimport.cpp | 4 +- src/test-komodo/test_crosschain.cpp | 267 ++++++++++++++++++++++++++++ src/test-komodo/testutils.cpp | 25 ++- src/test-komodo/testutils.h | 2 + 28 files changed, 884 insertions(+), 228 deletions(-) create mode 100644 src/cc/import.cpp create mode 100644 src/cc/utils.cpp create mode 100644 src/cc/utils.h create mode 100644 src/crosschain.cpp create mode 100644 src/crosschain.h rename src/{cc => }/importcoin.cpp (61%) rename src/{cc => }/importcoin.h (93%) create mode 100644 src/notarisationdb.cpp create mode 100644 src/notarisationdb.h create mode 100644 src/test-komodo/test_crosschain.cpp diff --git a/.gitignore b/.gitignore index bebcef932..3916d4e87 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,4 @@ src/komodo-cli src/komodod src/komodo-tx src/komodo-test +src/wallet-utility diff --git a/src/Makefile.am b/src/Makefile.am index 231386c96..fa475b4e1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -256,10 +256,11 @@ libbitcoin_server_a_SOURCES = \ asyncrpcqueue.cpp \ bloom.cpp \ cc/eval.cpp \ - cc/importcoin.cpp \ + cc/import.cpp \ cc/betprotocol.cpp \ chain.cpp \ checkpoints.cpp \ + crosschain.cpp \ deprecation.cpp \ httprpc.cpp \ httpserver.cpp \ @@ -271,6 +272,7 @@ libbitcoin_server_a_SOURCES = \ miner.cpp \ net.cpp \ noui.cpp \ + notarisationdb.cpp \ paymentdisclosure.cpp \ paymentdisclosuredb.cpp \ policy/fees.cpp \ @@ -384,6 +386,7 @@ libbitcoin_common_a_SOURCES = \ core_read.cpp \ core_write.cpp \ hash.cpp \ + importcoin.cpp \ key.cpp \ keystore.cpp \ netbase.cpp \ diff --git a/src/Makefile.ktest.include b/src/Makefile.ktest.include index a6d2d1829..93d3460e2 100644 --- a/src/Makefile.ktest.include +++ b/src/Makefile.ktest.include @@ -9,7 +9,8 @@ komodo_test_SOURCES = \ test-komodo/test_cryptoconditions.cpp \ test-komodo/test_coinimport.cpp \ test-komodo/test_eval_bet.cpp \ - test-komodo/test_eval_notarisation.cpp + test-komodo/test_eval_notarisation.cpp \ + test-komodo/test_crosschain.cpp komodo_test_CPPFLAGS = $(komodod_CPPFLAGS) diff --git a/src/cc/betprotocol.cpp b/src/cc/betprotocol.cpp index c3be8be8f..1b4834767 100644 --- a/src/cc/betprotocol.cpp +++ b/src/cc/betprotocol.cpp @@ -5,8 +5,9 @@ #include "chain.h" #include "streams.h" #include "script/cc.h" -#include "cc/eval.h" #include "cc/betprotocol.h" +#include "cc/eval.h" +#include "cc/utils.h" #include "primitives/transaction.h" diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index e98b0dc6b..6dc72f2a0 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -1,9 +1,11 @@ #include #include +#include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" #include "cc/eval.h" +#include "cc/utils.h" #include "main.h" #include "chain.h" #include "core_io.h" @@ -14,9 +16,7 @@ Eval* EVAL_TEST = 0; bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) { - Eval eval_; - Eval *eval = EVAL_TEST; - if (!eval) eval = &eval_; + EvalRef eval; bool out = eval->Dispatch(cond, tx, nIn); assert(eval->state.IsValid() == out); @@ -162,8 +162,7 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data) CBlockIndex block; if (!GetTxConfirmed(notaryHash, notarisationTx, block)) return false; if (!CheckNotaryInputs(notarisationTx, block.nHeight, block.nTime)) return false; - if (notarisationTx.vout.size() < 2) return false; - if (!data.Parse(notarisationTx.vout[1].scriptPubKey)) return false; + if (!ParseNotarisationOpReturn(notarisationTx, data)) return false; return true; } @@ -176,34 +175,13 @@ bool Eval::GetNotarisationData(int notarisationHeight, NotarisationData &data, b /* * Notarisation data, ie, OP_RETURN payload in notarisation transactions */ -extern char ASSETCHAINS_SYMBOL[16]; - -bool NotarisationData::Parse(const CScript scriptPK) +bool ParseNotarisationOpReturn(const CTransaction &tx, NotarisationData &data) { - *this = NotarisationData(); - + if (tx.vout.size() < 2) return false; std::vector vdata; - if (!GetOpReturnData(scriptPK, vdata)) return false; - - CDataStream ss(vdata, SER_NETWORK, PROTOCOL_VERSION); - - try { - ss >> blockHash; - ss >> height; - if (ASSETCHAINS_SYMBOL[0]) - ss >> txHash; - - char *nullPos = (char*) memchr(&ss[0], 0, ss.size()); - if (!nullPos) return false; - ss.read(symbol, nullPos-&ss[0]+1); - - if (ss.size() < 36) return false; - ss >> MoM; - ss >> MoMDepth; - } catch (...) { - return false; - } - return true; + if (!GetOpReturnData(tx.vout[1].scriptPubKey, vdata)) return false; + bool out = E_UNMARSHAL(vdata, ss >> data); + return out; } @@ -240,3 +218,11 @@ uint256 SafeCheckMerkleBranch(uint256 hash, const std::vector& vMerkleB } return hash; } + + +uint256 GetMerkleRoot(const std::vector& vLeaves) +{ + bool fMutated; + std::vector vMerkleTree; + return BuildMerkleTree(&fMutated, vLeaves, vMerkleTree); +} diff --git a/src/cc/eval.h b/src/cc/eval.h index c65e5f863..1bbf68f65 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -3,6 +3,7 @@ #include +#include "cc/utils.h" #include "chain.h" #include "streams.h" #include "version.h" @@ -78,6 +79,23 @@ public: }; +extern Eval* EVAL_TEST; + + +/* + * Get a pointer to an Eval to use + */ +typedef std::unique_ptr EvalRef_; +class EvalRef : public EvalRef_ +{ +public: + EvalRef() : EvalRef_( + EVAL_TEST ? EVAL_TEST : new Eval(), + [](Eval* e){if (e!=EVAL_TEST) delete e;}) { } +}; + + + bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn); @@ -97,24 +115,68 @@ public: evaluate(std::vector header, std::vector body) = 0; }; + +extern char ASSETCHAINS_SYMBOL[65]; + + /* - * Data from notarisation OP_RETURN + * Data from notarisation OP_RETURN from chain being notarised */ -class NotarisationData { +class NotarisationData +{ public: + bool IsBackNotarisation = 0; uint256 blockHash; uint32_t height; uint256 txHash; // Only get this guy in asset chains not in KMD - char symbol[64]; + char symbol[64] = "\0"; uint256 MoM; uint32_t MoMDepth; + uint32_t ccId; uint256 MoMoM; uint32_t MoMoMDepth; - bool Parse(CScript scriptPubKey); + NotarisationData(bool IsBack=0) : IsBackNotarisation(IsBack) {} + + ADD_SERIALIZE_METHODS; + + template + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(blockHash); + READWRITE(height); + if (IsBackNotarisation || (!ser_action.ForRead() && !txHash.IsNull())) + READWRITE(txHash); + SerSymbol(s, ser_action); + READWRITE(MoM); + READWRITE(MoMDepth); + if (s.size() == 0) return; + READWRITE(ccId); + if (IsBackNotarisation) { + READWRITE(MoMoM); + READWRITE(MoMoMDepth); + } + } + + template + void SerSymbol(Stream& s, CSerActionSerialize act) + { + s.write(symbol, strlen(symbol)+1); + } + + template + void SerSymbol(Stream& s, CSerActionUnserialize act) + { + char *nullPos = (char*) memchr(&s[0], 0, s.size()); + if (!nullPos) + throw std::ios_base::failure("couldn't parse symbol"); + s.read(symbol, nullPos-&s[0]+1); + } }; +bool ParseNotarisationOpReturn(const CTransaction &tx, NotarisationData &data); + + /* * Eval code utilities. */ @@ -126,31 +188,6 @@ FOREACH_EVAL(EVAL_GENERATE_DEF); std::string EvalToStr(EvalCode c); -/* - * Serialisation boilerplate - */ -#define E_MARSHAL(body) SerializeF([&] (CDataStream &ss) {body;}) -template -std::vector SerializeF(const T f) -{ - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - f(ss); - return std::vector(ss.begin(), ss.end()); -} - -#define E_UNMARSHAL(params, body) DeserializeF(params, [&] (CDataStream &ss) {body;}) -template -bool DeserializeF(const std::vector vIn, T f) -{ - CDataStream ss(vIn, SER_NETWORK, PROTOCOL_VERSION); - try { - f(ss); - if (ss.eof()) return true; - } catch(...) {} - return false; -} - - /* * Merkle stuff */ @@ -167,6 +204,13 @@ public: MerkleBranch(int i, std::vector b) : nIndex(i), branch(b) {} uint256 Exec(uint256 hash) const { return SafeCheckMerkleBranch(hash, branch, nIndex); } + MerkleBranch& operator<<(MerkleBranch append) + { + nIndex += append.nIndex << branch.size(); + branch.insert(branch.end(), append.branch.begin(), append.branch.end()); + return *this; + } + ADD_SERIALIZE_METHODS; template @@ -177,4 +221,7 @@ public: }; +uint256 GetMerkleRoot(const std::vector& vLeaves); + + #endif /* CC_EVAL_H */ diff --git a/src/cc/import.cpp b/src/cc/import.cpp new file mode 100644 index 000000000..be4929b94 --- /dev/null +++ b/src/cc/import.cpp @@ -0,0 +1,70 @@ +#include "cc/eval.h" +#include "cc/utils.h" +#include "importcoin.h" +#include "primitives/transaction.h" + + +/* + * CC Eval method for import coin. + * + * This method should control every parameter of the ImportCoin transaction, since it has no signature + * to protect it from malleability. + */ +bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) +{ + if (importTx.vout.size() == 0) return Invalid("no-vouts"); + + // params + MomoProof proof; + CTransaction burnTx; + if (!E_UNMARSHAL(params, ss >> proof; ss >> burnTx)) + return Invalid("invalid-params"); + + // Control all aspects of this transaction + // It must not be at all malleable + if (MakeImportCoinTransaction(proof, burnTx, importTx.vout).GetHash() != importTx.GetHash()) + return Invalid("non-canonical"); + + // burn params + uint32_t chain; // todo + uint256 payoutsHash; + std::vector burnOpret; + if (burnTx.vout.size() == 0) return Invalid("invalid-burn-outputs"); + GetOpReturnData(burnTx.vout[0].scriptPubKey, burnOpret); + if (!E_UNMARSHAL(burnOpret, ss >> VARINT(chain); ss >> payoutsHash)) + return Invalid("invalid-burn-params"); + + // check chain + if (chain != GetCurrentLedgerID()) + return Invalid("importcoin-wrong-chain"); + + // check burn amount + { + uint64_t burnAmount = burnTx.vout[0].nValue; + if (burnAmount == 0) + return Invalid("invalid-burn-amount"); + uint64_t totalOut = 0; + for (int i=0; i burnAmount) + return Invalid("payout-too-high"); + } + + // Check burntx shows correct outputs hash + if (payoutsHash != SerializeHash(importTx.vout)) + return Invalid("wrong-payouts"); + + // Check proof confirms existance of burnTx + { + NotarisationData data; + if (!GetNotarisationData(proof.notarisationHeight, data, true)) + return Invalid("coudnt-load-momom"); + + if (data.MoMoM != proof.branch.Exec(burnTx.GetHash())) + return Invalid("momom-check-fail"); + } + + return Valid(); +} + + diff --git a/src/cc/utils.cpp b/src/cc/utils.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/src/cc/utils.h b/src/cc/utils.h new file mode 100644 index 000000000..5704016e4 --- /dev/null +++ b/src/cc/utils.h @@ -0,0 +1,34 @@ +#ifndef CC_UTILS_H +#define CC_UTILS_H + +#include "streams.h" +#include "version.h" + + +/* + * Serialisation boilerplate + */ + +template +std::vector SerializeF(const T f) +{ + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + f(ss); + return std::vector(ss.begin(), ss.end()); +} + +template +bool DeserializeF(const std::vector vIn, T f) +{ + CDataStream ss(vIn, SER_NETWORK, PROTOCOL_VERSION); + try { + f(ss); + if (ss.eof()) return true; + } catch(...) {} + return false; +} + +#define E_MARSHAL(body) SerializeF([&] (CDataStream &ss) {body;}) +#define E_UNMARSHAL(params, body) DeserializeF(params, [&] (CDataStream &ss) {body;}) + +#endif /* CC_UTILS_H */ diff --git a/src/coins.cpp b/src/coins.cpp index b8f5ffe2c..8b5af804c 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -9,7 +9,7 @@ #include "version.h" #include "policy/fees.h" #include "komodo_defs.h" -#include "cc/importcoin.h" +#include "importcoin.h" #include diff --git a/src/crosschain.cpp b/src/crosschain.cpp new file mode 100644 index 000000000..069a53f38 --- /dev/null +++ b/src/crosschain.cpp @@ -0,0 +1,217 @@ +#include "cc/eval.h" +#include "main.h" +#include "notarisationdb.h" + + +/* On KMD */ +uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, int* assetChainHeight) +{ + /* + * Notaries don't wait for confirmation on KMD before performing a backnotarisation, + * but we need a determinable range that will encompass all merkle roots. Include MoMs + * including the block height of the last notarisation until the height before the + * previous notarisation. + */ + if (targetCCid <= 1) + return uint256(); + + int seenOwnNotarisations = 0; + + // TODO: test height out of range + // TODO: Make sure that boundary for moms is notarisation tx not block + + for (int i=0; i<1440; i++) { + if (i > kmdHeight) break; + NotarisationsInBlock notarisations; + uint256 blockHash = *chainActive[kmdHeight-i]->phashBlock; + if (!pnotarisations->Read(blockHash, notarisations)) + continue; + BOOST_FOREACH(Notarisation& nota, notarisations) { + NotarisationData& data = nota.second; + if (data.ccId != targetCCid) + continue; + if (strcmp(data.symbol, symbol) == 0) + { + seenOwnNotarisations++; + if (seenOwnNotarisations == 2) + goto end; + if (seenOwnNotarisations == 1) + *assetChainHeight = data.height; // TODO: Needed? + continue; // Don't include own MoMs + } + if (seenOwnNotarisations == 1) + moms.push_back(data.MoM); + } + } + +end: + return GetMerkleRoot(moms); +} + + +/* On KMD */ +std::pair GetCrossChainProof(uint256 txid, char* targetSymbol, + uint32_t targetCCid, uint256 notarisationTxid, MerkleBranch assetChainProof) +{ + /* + * Here we are given a proof generated by an assetchain A which goes from given txid to + * an assetchain MoM. We need to go from the notarisationTxid for A to the MoMoM range of the + * backnotarisation for B (given by kmdheight of notarisation), find the MoM within the MoMs for + * that range, and finally extend the proof to lead to the MoMoM (proof root). + */ + EvalRef eval; + uint256 MoM = assetChainProof.Exec(txid); + + // Get a kmd height for given notarisation Txid + int kmdHeight; + { + CTransaction sourceNotarisation; + uint256 hashBlock; + CBlockIndex blockIdx; + if (eval->GetTxConfirmed(notarisationTxid, sourceNotarisation, blockIdx)) + kmdHeight = blockIdx.nHeight; + else if (eval->GetTxUnconfirmed(notarisationTxid, sourceNotarisation, hashBlock)) + kmdHeight = chainActive.Tip()->nHeight; + else + throw std::runtime_error("Notarisation not found"); + } + + // Get MoMs for kmd height and symbol + std::vector moms; + int targetChainStartHeight; + uint256 MoMoM = GetProofRoot(targetSymbol, targetCCid, kmdHeight, moms, &targetChainStartHeight); + if (MoMoM.IsNull()) + throw std::runtime_error("No MoMs found"); + + // Find index of source MoM in MoMoM + int nIndex; + for (nIndex=0; nIndex newBranch; + { + CBlock fakeBlock; + for (int i=0; i + */ +std::pair GetAssetchainProof(uint256 hash) +{ + uint256 notarisationHash, MoM,MoMoM; int32_t notarisedHeight, depth; CBlockIndex* blockIndex; + std::vector branch; + int nIndex,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; + + { + uint256 blockHash; + CTransaction tx; + if (!GetTransaction(hash, tx, blockHash, true)) + throw std::runtime_error("cannot find transaction"); + + blockIndex = mapBlockIndex[blockHash]; + + depth = komodo_MoM(¬arisedHeight, &MoM, ¬arisationHash, blockIndex->nHeight,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi); + + if (!depth) + throw std::runtime_error("notarisation not found"); + + // index of block in MoM leaves + nIndex = notarisedHeight - blockIndex->nHeight; + } + + // build merkle chain from blocks to MoM + { + // since the merkle branch code is tied up in a block class + // and we want to make a merkle branch for something that isnt transactions + CBlock fakeBlock; + for (int i=0; ihashMerkleRoot; + CTransaction fakeTx; + // first value in CTransaction memory is it's hash + memcpy((void*)&fakeTx, mRoot.begin(), 32); + fakeBlock.vtx.push_back(fakeTx); + } + branch = fakeBlock.GetMerkleBranch(nIndex); + + // Check branch + if (MoM != CBlock::CheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex)) + throw std::runtime_error("Failed merkle block->MoM"); + } + + // Now get the tx merkle branch + { + CBlock block; + + if (fHavePruned && !(blockIndex->nStatus & BLOCK_HAVE_DATA) && blockIndex->nTx > 0) + throw std::runtime_error("Block not available (pruned data)"); + + if(!ReadBlockFromDisk(block, blockIndex,1)) + throw std::runtime_error("Can't read block from disk"); + + // Locate the transaction in the block + int nTxIndex; + for (nTxIndex = 0; nTxIndex < (int)block.vtx.size(); nTxIndex++) + if (block.vtx[nTxIndex].GetHash() == hash) + break; + + if (nTxIndex == (int)block.vtx.size()) + throw std::runtime_error("Error locating tx in block"); + + std::vector txBranch = block.GetMerkleBranch(nTxIndex); + + // Check branch + if (block.hashMerkleRoot != CBlock::CheckMerkleBranch(hash, txBranch, nTxIndex)) + throw std::runtime_error("Failed merkle tx->block"); + + // concatenate branches + nIndex = (nIndex << txBranch.size()) + nTxIndex; + branch.insert(branch.begin(), txBranch.begin(), txBranch.end()); + } + + // Check the proof + if (MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) + throw std::runtime_error("Failed validating MoM"); + + // All done! + CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION); + return std::make_pair(notarisationHash, MerkleBranch(nIndex, branch)); +} diff --git a/src/crosschain.h b/src/crosschain.h new file mode 100644 index 000000000..25fe50e5f --- /dev/null +++ b/src/crosschain.h @@ -0,0 +1,21 @@ +#ifndef CROSSCHAIN_H +#define CROSSCHAIN_H + +#include "cc/eval.h" + + +/* On assetchain */ +std::pair GetAssetchainProof(uint256 hash); + +/* On KMD */ +uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, int* assetChainHeight); + +/* On KMD */ +std::pair GetCrossChainProof(uint256 txid, char* targetSymbol, + uint32_t targetCCid, uint256 notarisationTxid, MerkleBranch assetChainProof); + +/* On assetchain */ +bool ValidateCrossChainProof(uint256 txid, int notarisationHeight, MerkleBranch proof); + + +#endif /* CROSSCHAIN_H */ diff --git a/src/cc/importcoin.cpp b/src/importcoin.cpp similarity index 61% rename from src/cc/importcoin.cpp rename to src/importcoin.cpp index d5f626683..3874ed7d6 100644 --- a/src/cc/importcoin.cpp +++ b/src/importcoin.cpp @@ -1,4 +1,5 @@ -#include "cc/importcoin.h" +#include "importcoin.h" +#include "cc/utils.h" #include "coins.h" #include "hash.h" #include "script/cc.h" @@ -29,71 +30,6 @@ CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector } -/* - * CC Eval method for import coin. - * - * This method has to control *every* parameter of the ImportCoin transaction, so that the legal - * importTx for a valid burnTx is 1:1. There can be no two legal importTx transactions for a burnTx - * on another chain. - */ -bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) -{ - if (importTx.vout.size() == 0) return Invalid("no-vouts"); - - // params - MomoProof proof; - CTransaction burnTx; - if (!E_UNMARSHAL(params, ss >> proof; ss >> burnTx)) - return Invalid("invalid-params"); - - // Control all aspects of this transaction - // It must not be at all malleable - if (MakeImportCoinTransaction(proof, burnTx, importTx.vout).GetHash() != importTx.GetHash()) - return Invalid("non-canonical"); - - // burn params - uint32_t chain; // todo - uint256 payoutsHash; - std::vector burnOpret; - if (burnTx.vout.size() == 0) return Invalid("invalid-burn-outputs"); - GetOpReturnData(burnTx.vout[0].scriptPubKey, burnOpret); - if (!E_UNMARSHAL(burnOpret, ss >> VARINT(chain); ss >> payoutsHash)) - return Invalid("invalid-burn-params"); - - // check chain - if (chain != GetCurrentLedgerID()) - return Invalid("importcoin-wrong-chain"); - - // check burn amount - { - uint64_t burnAmount = burnTx.vout[0].nValue; - if (burnAmount == 0) - return Invalid("invalid-burn-amount"); - uint64_t totalOut = 0; - for (int i=0; i burnAmount) - return Invalid("payout-too-high"); - } - - // Check burntx shows correct outputs hash - if (payoutsHash != SerializeHash(importTx.vout)) - return Invalid("wrong-payouts"); - - // Check proof confirms existance of burnTx - { - NotarisationData data; - if (!GetNotarisationData(proof.notarisationHeight, data, true)) - return Invalid("coudnt-load-momom"); - - if (data.MoMoM != proof.branch.Exec(burnTx.GetHash())) - return Invalid("momom-check-fail"); - } - - return Valid(); -} - - static bool UnmarshalImportTx(const CTransaction &importTx, MomoProof &proof, CTransaction &burnTx) { CScript scriptSig = importTx.vin[0].scriptSig; diff --git a/src/cc/importcoin.h b/src/importcoin.h similarity index 93% rename from src/cc/importcoin.h rename to src/importcoin.h index 13fefd513..6f712a1e9 100644 --- a/src/cc/importcoin.h +++ b/src/importcoin.h @@ -1,5 +1,5 @@ -#ifndef CC_IMPORTCOIN_H -#define CC_IMPORTCOIN_H +#ifndef IMPORTCOIN_H +#define IMPORTCOIN_H #include "cc/eval.h" #include "coins.h" @@ -36,4 +36,4 @@ void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, i void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs); int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &inputs); -#endif /* CC_IMPORTCOIN_H */ +#endif /* IMPORTCOIN_H */ diff --git a/src/init.cpp b/src/init.cpp index aa55d1782..52c919421 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -21,6 +21,7 @@ #include "httpserver.h" #include "httprpc.h" #include "key.h" +#include "notarisationdb.h" #include "main.h" #include "metrics.h" #include "miner.h" @@ -1413,11 +1414,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) delete pcoinsdbview; delete pcoinscatcher; delete pblocktree; + delete pnotarisations; pblocktree = new CBlockTreeDB(nBlockTreeDBCache, false, fReindex, dbCompression, dbMaxOpenFiles); pcoinsdbview = new CCoinsViewDB(nCoinDBCache, false, fReindex); pcoinscatcher = new CCoinsViewErrorCatcher(pcoinsdbview); pcoinsTip = new CCoinsViewCache(pcoinscatcher); + pnotarisations = new NotarisationDB(100*1024*1024, false, fReindex); + if (fReindex) { pblocktree->WriteReindexing(true); diff --git a/src/main.cpp b/src/main.cpp index 67220e891..a3bd0f515 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,7 @@ #include "addrman.h" #include "alert.h" #include "arith_uint256.h" -#include "cc/importcoin.h" +#include "importcoin.h" #include "chainparams.h" #include "checkpoints.h" #include "checkqueue.h" @@ -20,6 +20,7 @@ #include "init.h" #include "merkleblock.h" #include "metrics.h" +#include "notarisationdb.h" #include "net.h" #include "pow.h" #include "script/interpreter.h" @@ -2598,6 +2599,7 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const } } + static int64_t nTimeVerify = 0; static int64_t nTimeConnect = 0; static int64_t nTimeIndex = 0; @@ -2833,6 +2835,14 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin vPos.push_back(std::make_pair(tx.GetHash(), pos)); pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); } + + + // Record Notarisations + NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight); + pnotarisations->Write(block.GetHash(), notarisations); + WriteBackNotarisations(notarisations); // Very important to disconnect this + // TODO: Disconnect? + view.PushAnchor(tree); if (!fJustCheck) { diff --git a/src/miner.cpp b/src/miner.cpp index f57b53d98..4fdca90bd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -11,7 +11,7 @@ #include "amount.h" #include "base58.h" #include "chainparams.h" -#include "cc/importcoin.h" +#include "importcoin.h" #include "consensus/consensus.h" #include "consensus/upgrades.h" #include "consensus/validation.h" diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp new file mode 100644 index 000000000..6daa5a132 --- /dev/null +++ b/src/notarisationdb.cpp @@ -0,0 +1,46 @@ +#include "leveldbwrapper.h" +#include "notarisationdb.h" +#include "uint256.h" +#include "cc/eval.h" + +#include + + +NotarisationDB *pnotarisations; + + +NotarisationDB::NotarisationDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "notarisations", nCacheSize, fMemory, fWipe, false, 64) { +} + +NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight) +{ + EvalRef eval; + NotarisationsInBlock vNotarisations; + bool IsBackNotarisation = ASSETCHAINS_SYMBOL[0] != 0; + + for (unsigned int i = 0; i < block.vtx.size(); i++) { + CTransaction tx = block.vtx[i]; + if (eval->CheckNotaryInputs(tx, nHeight, block.nTime)) { + NotarisationData data(IsBackNotarisation); + if (ParseNotarisationOpReturn(tx, data)) + vNotarisations.push_back(std::make_pair(tx.GetHash(), data)); + else + fprintf(stderr, "Warning: Couldn't parse notarisation for tx: %s at height %i\n", + tx.GetHash().GetHex().data(), nHeight); + } + } + return vNotarisations; +} + + +/* + * Write an index of KMD notarisation id -> backnotarisation + */ +void WriteBackNotarisations(NotarisationsInBlock notarisations) +{ + BOOST_FOREACH(Notarisation &n, notarisations) + { + if (n.second.IsBackNotarisation) + pnotarisations->Write(n.second.txHash, n); + } +} diff --git a/src/notarisationdb.h b/src/notarisationdb.h new file mode 100644 index 000000000..bd2c15685 --- /dev/null +++ b/src/notarisationdb.h @@ -0,0 +1,26 @@ +#ifndef NOTARISATIONDB_H +#define NOTARISATIONDB_H + +#include "uint256.h" +#include "leveldbwrapper.h" +#include "cc/eval.h" + + +class NotarisationDB : public CLevelDBWrapper +{ +public: + NotarisationDB(size_t nCacheSize, bool fMemory = false, bool fWipe = false); +}; + + +extern NotarisationDB *pnotarisations; + + +typedef std::pair Notarisation; +typedef std::vector NotarisationsInBlock; + +NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight); + +void WriteBackNotarisations(NotarisationsInBlock notarisations); + +#endif /* NOTARISATIONDB_H */ diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index c2300c82a..106216284 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -15,7 +15,9 @@ uint256 CBlockHeader::GetHash() const return SerializeHash(*this); } -uint256 CBlock::BuildMerkleTree(bool* fMutated) const + +uint256 BuildMerkleTree(bool* fMutated, const std::vector leaves, + std::vector &vMerkleTree) { /* WARNING! If you're reading this because you're learning about crypto and/or designing a new system that will use merkle trees, keep in mind @@ -28,10 +30,10 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const transactions leading to the same merkle root. For example, these two trees: - A A - / \ / \ - B C B C - / \ | / \ / \ + A A + / \ / \ + B C B C + / \ \ / \ / \ D E F D E F F / \ / \ / \ / \ / \ / \ / \ 1 2 3 4 5 6 1 2 3 4 5 6 5 6 @@ -52,13 +54,14 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const known ways of changing the transactions without affecting the merkle root. */ + vMerkleTree.clear(); - vMerkleTree.reserve(vtx.size() * 2 + 16); // Safe upper bound for the number of total nodes. - for (std::vector::const_iterator it(vtx.begin()); it != vtx.end(); ++it) - vMerkleTree.push_back(it->GetHash()); + vMerkleTree.reserve(leaves.size() * 2 + 16); // Safe upper bound for the number of total nodes. + for (std::vector::const_iterator it(leaves.begin()); it != leaves.end(); ++it) + vMerkleTree.push_back(*it); int j = 0; bool mutated = false; - for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2) + for (int nSize = leaves.size(); nSize > 1; nSize = (nSize + 1) / 2) { for (int i = 0; i < nSize; i += 2) { @@ -78,6 +81,15 @@ uint256 CBlock::BuildMerkleTree(bool* fMutated) const return (vMerkleTree.empty() ? uint256() : vMerkleTree.back()); } + +uint256 CBlock::BuildMerkleTree(bool* fMutated) const +{ + std::vector leaves; + for (int i=0; i CBlock::GetMerkleBranch(int nIndex) const { if (vMerkleTree.empty()) diff --git a/src/primitives/block.h b/src/primitives/block.h index 6b3f13a86..2d3c0cfe4 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -139,6 +139,10 @@ public: }; +uint256 BuildMerkleTree(bool* fMutated, const std::vector leaves, + std::vector &vMerkleTree); + + /** * Custom serializer for CBlockHeader that omits the nonce and solution, for use * as input to Equihash. diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d09479008..75454497d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -7,6 +7,7 @@ #include "chain.h" #include "chainparams.h" #include "checkpoints.h" +#include "crosschain.h" #include "base58.h" #include "consensus/validation.h" #include "cc/eval.h" @@ -934,87 +935,35 @@ UniValue txMoMproof(const UniValue& params, bool fHelp) int nIndex,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; // parse params and get notarisation data for tx - { - if ( fHelp || params.size() != 1) - throw runtime_error("txMoMproof needs a txid"); + if ( fHelp || params.size() != 1) + throw runtime_error("txMoMproof needs a txid"); - hash = uint256S(params[0].get_str()); + hash = uint256S(params[0].get_str()); - uint256 blockHash; - CTransaction tx; - if (!GetTransaction(hash, tx, blockHash, true)) - throw runtime_error("cannot find transaction"); - - blockIndex = mapBlockIndex[blockHash]; - - depth = komodo_MoM(¬arisedHeight, &MoM, ¬arisationHash, blockIndex->nHeight,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi); - - if (!depth) - throw runtime_error("notarisation not found"); - - // index of block in MoM leaves - nIndex = notarisedHeight - blockIndex->nHeight; - } - - // build merkle chain from blocks to MoM - { - // since the merkle branch code is tied up in a block class - // and we want to make a merkle branch for something that isnt transactions - CBlock fakeBlock; - for (int i=0; ihashMerkleRoot; - CTransaction fakeTx; - // first value in CTransaction memory is it's hash - memcpy((void*)&fakeTx, mRoot.begin(), 32); - fakeBlock.vtx.push_back(fakeTx); - } - branch = fakeBlock.GetMerkleBranch(nIndex); - - // Check branch - if (MoM != CBlock::CheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex)) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed merkle block->MoM"); - } - - // Now get the tx merkle branch - { - CBlock block; - - if (fHavePruned && !(blockIndex->nStatus & BLOCK_HAVE_DATA) && blockIndex->nTx > 0) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); - - if(!ReadBlockFromDisk(block, blockIndex,1)) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); - - // Locate the transaction in the block - int nTxIndex; - for (nTxIndex = 0; nTxIndex < (int)block.vtx.size(); nTxIndex++) - if (block.vtx[nTxIndex].GetHash() == hash) - break; - - if (nTxIndex == (int)block.vtx.size()) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Error locating tx in block"); - - std::vector txBranch = block.GetMerkleBranch(nTxIndex); - - // Check branch - if (block.hashMerkleRoot != CBlock::CheckMerkleBranch(hash, txBranch, nTxIndex)) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed merkle tx->block"); - - // concatenate branches - nIndex = (nIndex << txBranch.size()) + nTxIndex; - branch.insert(branch.begin(), txBranch.begin(), txBranch.end()); - } - - // Check the proof - if (MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) - throw JSONRPCError(RPC_INTERNAL_ERROR, "Failed validating MoM"); - - // Encode and return - CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION); - ssProof << std::make_pair(notarisationHash, MerkleBranch(nIndex, branch)); - return HexStr(ssProof.begin(), ssProof.end()); + std::vector proofData = E_MARSHAL(ss << GetAssetchainProof(hash)); + return HexStr(proofData); } + +UniValue getproofroot(const UniValue& params, bool fHelp) +{ + std::string symbol; + int kmdHeight; + + + // parse params and get notarisation data for tx + if ( fHelp || params.size() != 2) + throw runtime_error("getproofroot needs a symbol and a kmdHeight"); + symbol = params[0].get_str(); + kmdHeight = atoi(params[0].get_str().c_str()); + if (kmdHeight <= 0) + throw runtime_error("Invalid kmdHeight"); + + UniValue ret(UniValue::VOBJ); + return ret; +} + + UniValue minerids(const UniValue& params, bool fHelp) { uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); uint8_t minerids[2000],pubkeys[65][33]; int32_t i,j,n,numnotaries,tally[129]; diff --git a/src/script/cc.h b/src/script/cc.h index dc019beba..246f19052 100644 --- a/src/script/cc.h +++ b/src/script/cc.h @@ -1,6 +1,8 @@ #ifndef SCRIPT_CC_H #define SCRIPT_CC_H +#include + #include "pubkey.h" #include "script/script.h" #include "cryptoconditions/include/cryptoconditions.h" @@ -79,5 +81,4 @@ bool GetPushData(const CScript &sig, std::vector &data); */ bool GetOpReturnData(const CScript &sig, std::vector &data); - #endif /* SCRIPT_CC_H */ diff --git a/src/test-komodo/main.cpp b/src/test-komodo/main.cpp index 0ce8740b3..1adb729b4 100644 --- a/src/test-komodo/main.cpp +++ b/src/test-komodo/main.cpp @@ -9,6 +9,7 @@ int main(int argc, char **argv) { assert(init_and_check_sodium() != -1); ECC_Start(); + ECCVerifyHandle handle; // Inits secp256k1 verify context SelectParams(CBaseChainParams::REGTEST); CBitcoinSecret vchSecret; diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index 96543d80b..fe2f3ce96 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -2,14 +2,14 @@ #include #include -#include "cc/importcoin.h" #include "cc/eval.h" +#include "importcoin.h" #include "base58.h" #include "core_io.h" #include "key.h" #include "main.h" -#include "script/cc.h" #include "primitives/transaction.h" +#include "script/cc.h" #include "script/interpreter.h" #include "script/serverchecker.h" #include "txmempool.h" diff --git a/src/test-komodo/test_crosschain.cpp b/src/test-komodo/test_crosschain.cpp new file mode 100644 index 000000000..f7f7d47ab --- /dev/null +++ b/src/test-komodo/test_crosschain.cpp @@ -0,0 +1,267 @@ +#include +#include +#include +#include +#include + +#include +#include + +#include "cc/eval.h" +#include "importcoin.h" +#include "base58.h" +#include "core_io.h" +#include "crosschain.h" +#include "key.h" +#include "main.h" +#include "primitives/block.h" +#include "primitives/transaction.h" +#include "script/cc.h" +#include "script/interpreter.h" +#include "script/serverchecker.h" +#include "txmempool.h" +#include "crosschain.h" + +#include "testutils.h" + + +extern uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); + + +/* + * Tests for the whole process of creating and validating notary proofs + * using proof roots (MoMoMs). This is to support coin imports. + */ + +namespace TestCrossChainProof { + + +class TestCrossChain : public ::testing::Test, public Eval { +public: + bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const + { + NotarisationData data; + return ParseNotarisationOpReturn(tx, data); + } +protected: + static void SetUpTestCase() { } + virtual void SetUp() { + ASSETCHAINS_CC = 1; + EVAL_TEST = this; + } +}; + + + +TEST_F(TestCrossChain, testCreateAndValidateImportProof) +{ + /* + * This tests the full process of creation of a cross chain proof. + * For the purposes of the test we will use one assetchain and a KMD chain. + * + * In order to do this test, we need 2 blockchains, so we'll fork and make a socket + * for IPC. + */ + + int childPid = fork(); + void *ctx = zmq_ctx_new(); + void *socket = zmq_socket(ctx, ZMQ_PAIR); + setupChain(); + std::vector blocks; + blocks.resize(10); + NotarisationData a2kmd, kmd2a(true); + + + auto SendIPC = [&] (std::vector v) { + assert(v.size() == zmq_send(socket, v.data(), v.size(), 0)); + }; + + auto RecvIPC = [&] () { + std::vector out; + out.resize(100000); + int len = zmq_recv(socket, out.data(), out.size(), 0); + assert(len != -1); + out.resize(len); + return out; + }; + + auto RecordNotarisation = [&] (CTransaction inputTx, NotarisationData data) { + CMutableTransaction mtx = spendTx(inputTx); + mtx.vout.resize(2); + mtx.vout[0].scriptPubKey << VCH(notaryKey.GetPubKey().begin(), 33) << OP_CHECKSIG; + mtx.vout[1].scriptPubKey << OP_RETURN << E_MARSHAL(ss << data); + mtx.vout[1].nValue = 0; + mtx.vin[0].scriptSig << getSig(mtx, inputTx.vout[0].scriptPubKey); + + acceptTxFail(CTransaction(mtx)); + printf("accept %snotarisation: %s\n", data.IsBackNotarisation ? "back" : "", + mtx.GetHash().GetHex().data()); + return mtx.GetHash(); + }; + + auto RunTestAssetchain = [&] () + { + NotarisationData back(1); + strcpy(ASSETCHAINS_SYMBOL, "symbolA"); + strcpy(a2kmd.symbol, "symbolA"); + a2kmd.ccId = 2; + + /* + * Notarisation 1 + */ + generateBlock(&blocks[1]); + generateBlock(&blocks[2]); + a2kmd.blockHash = blocks[2].GetHash(); + a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2); + SendIPC(E_MARSHAL(ss << a2kmd)); + E_UNMARSHAL(RecvIPC(), ss >> back); + RecordNotarisation(blocks[1].vtx[0], back); + + /* + * Notarisation 2 + */ + generateBlock(&blocks[3]); + generateBlock(&blocks[4]); + a2kmd.blockHash = blocks[4].GetHash(); + a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2); + SendIPC(E_MARSHAL(ss << a2kmd)); + E_UNMARSHAL(RecvIPC(), ss >> back); + RecordNotarisation(blocks[3].vtx[0], back); + + /* + * Generate proof + */ + generateBlock(&blocks[5]); + uint256 txid = blocks[3].vtx[0].GetHash(); + std::pair assetChainProof = GetAssetchainProof(txid); + SendIPC(E_MARSHAL(ss << txid; ss << assetChainProof)); + }; + + auto RunTestKmd = [&] () + { + NotarisationData n; + + /* + * Notarisation 1 + */ + E_UNMARSHAL(RecvIPC(), ss >> n); + // Grab a coinbase input to fund notarisation + generateBlock(&blocks[1]); + n.txHash = RecordNotarisation(blocks[1].vtx[0], a2kmd); + n.height = chainActive.Height(); + SendIPC(E_MARSHAL(ss << n)); + + /* + * Notarisation 2 + */ + E_UNMARSHAL(RecvIPC(), ss >> n); + // Grab a coinbase input to fund notarisation + generateBlock(&blocks[2]); + n.txHash = RecordNotarisation(blocks[2].vtx[0], a2kmd); + n.height = chainActive.Height(); + SendIPC(E_MARSHAL(ss << n)); + + /* + * Extend proof + */ + std::pair assetChainProof; + uint256 txid; + // Extend proof to MoMoM + assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> kmd2a)); + std::pair ccProof = GetCrossChainProof(txid, (char*)"symbolA", + 2, assetChainProof.first, assetChainProof.second); + }; + + const char endpoint[] = "ipc://tmpKomodoTestCrossChainSock"; + + if (!childPid) { + assert(0 == zmq_connect(socket, endpoint)); + usleep(20000); + RunTestAssetchain(); + exit(0); + } + else { + assert(0 == zmq_bind(socket, endpoint)); + RunTestKmd(); + int returnStatus; + waitpid(childPid, &returnStatus, 0); + unlink("tmpKomodoTestCrossChainSock"); + ASSERT_EQ(0, returnStatus); + } + + + + /* + + * + * Assetchain notarisation 2 + * + + ON_ASSETCHAIN { + a2kmd.blockHash = blocks[4].GetHash(); + a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2); + SendIPC(E_MARSHAL(ss << a2kmd)); + } + + ON_KMD { + assert(E_UNMARSHAL(RecvIPC(), ss >> a2kmd)); + // Grab a coinbase input to fund notarisation + RecordNotarisation(blocks[2].vtx[0], a2kmd); + } + + generateBlock(&blocks[5]); + generateBlock(&blocks[6]); + + * + * Backnotarisation + * + * This is what will contain the MoMoM which allows us to prove across chains + * + std::vector moms; + int assetChainHeight; + + ON_KMD { + memset(kmd2a.txHash.begin(), 1, 32); // Garbage but non-null + kmd2a.symbol[0] = 0; // KMD + kmd2a.MoMoM = GetProofRoot((char*)"symbolA", 2, chainActive.Height(), moms, &assetChainHeight); + kmd2a.MoMoMDepth = 0; // Needed? + SendIPC(E_MARSHAL(ss << kmd2a)); + } + + ON_ASSETCHAIN { + assert(E_UNMARSHAL(RecvIPC(), ss >> kmd2a)); + RecordNotarisation(blocks[1].vtx[0], kmd2a); + } + + + * + * We can now prove a tx from A on A, via a merkle root backpropagated from KMD. + * + * The transaction that we'll try to prove is the coinbase from the 3rd block. + * We should be able to start with only that transaction ID, and generate a merkle + * proof. + * + + std::pair assetChainProof; + uint256 txid; + + ON_ASSETCHAIN { + txid = blocks[2].vtx[0].GetHash(); + + // First thing to do is get the proof from the assetchain + assetChainProof = GetAssetchainProof(txid); + SendIPC(E_MARSHAL(ss << txid; ss << assetChainProof)); + } + + ON_KMD { + // Extend proof to MoMoM + assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> kmd2a)); + std::pair ccProof = GetCrossChainProof(txid, (char*)"symbolA", + 2, assetChainProof.first, assetChainProof.second); + } + + */ +} + + +} /* namespace TestCrossChainProof */ diff --git a/src/test-komodo/testutils.cpp b/src/test-komodo/testutils.cpp index c3baf4fb6..caf805499 100644 --- a/src/test-komodo/testutils.cpp +++ b/src/test-komodo/testutils.cpp @@ -6,6 +6,7 @@ #include "key.h" #include "main.h" #include "miner.h" +#include "notarisationdb.h" #include "random.h" #include "rpcserver.h" #include "rpcprotocol.h" @@ -33,13 +34,14 @@ CKey notaryKey; int64_t nMockTime; extern uint32_t USE_EXTERNAL_PUBKEY; +extern std::string NOTARY_PUBKEY; void setupChain() { SelectParams(CBaseChainParams::REGTEST); // Settings to get block reward - //NOTARY_PUBKEY = _NOTARY_PUBKEY; + NOTARY_PUBKEY = notaryPubkey; USE_EXTERNAL_PUBKEY = 1; mapArgs["-mineraddress"] = "bogus"; COINBASE_MATURITY = 1; @@ -54,6 +56,7 @@ void setupChain() pblocktree = new CBlockTreeDB(1 << 20, true); CCoinsViewDB *pcoinsdbview = new CCoinsViewDB(1 << 23, true); pcoinsTip = new CCoinsViewCache(pcoinsdbview); + pnotarisations = new NotarisationDB(1 << 20, true); InitBlockIndex(); } @@ -65,15 +68,19 @@ void generateBlock(CBlock *block) params.push_back(1); uint256 blockId; - SetMockTime(nMockTime++); // CreateNewBlock can fail if not enough time passes + SetMockTime(nMockTime+=100); // CreateNewBlock can fail if not enough time passes + + char symbolPrefix = ASSETCHAINS_SYMBOL[0]; + ASSETCHAINS_SYMBOL[0] = 0; // generate block fails otherwise try { UniValue out = generate(params, false); blockId.SetHex(out[0].getValStr()); + ASSETCHAINS_SYMBOL[0] = symbolPrefix; + if (block) ASSERT_TRUE(ReadBlockFromDisk(*block, mapBlockIndex[blockId], false)); } catch (const UniValue& e) { FAIL() << "failed to create block: " << e.write().data(); } - if (block) ASSERT_TRUE(ReadBlockFromDisk(*block, mapBlockIndex[blockId])); } @@ -91,7 +98,7 @@ bool acceptTx(const CTransaction tx, CValidationState &state) } -static CMutableTransaction spendTx(const CTransaction &txIn, int nOut=0) +CMutableTransaction spendTx(const CTransaction &txIn, int nOut) { CMutableTransaction mtx; mtx.vin.resize(1); @@ -103,6 +110,16 @@ static CMutableTransaction spendTx(const CTransaction &txIn, int nOut=0) } +std::vector getSig(const CMutableTransaction mtx, CScript inputPubKey, int nIn) +{ + uint256 hash = SignatureHash(inputPubKey, mtx, nIn, SIGHASH_ALL, 0, 0); + std::vector vchSig; + notaryKey.Sign(hash, vchSig); + vchSig.push_back((unsigned char)SIGHASH_ALL); + return vchSig; +} + + /* * In order to do tests there needs to be inputs to spend. * This method creates a block and returns a transaction that spends the coinbase. diff --git a/src/test-komodo/testutils.h b/src/test-komodo/testutils.h index 92d28b587..bbf702f26 100644 --- a/src/test-komodo/testutils.h +++ b/src/test-komodo/testutils.h @@ -22,6 +22,8 @@ void generateBlock(CBlock *block=NULL); bool acceptTx(const CTransaction tx, CValidationState &state); void acceptTxFail(const CTransaction tx); void getInputTx(CScript scriptPubKey, CTransaction &txIn); +CMutableTransaction spendTx(const CTransaction &txIn, int nOut=0); +std::vector getSig(const CMutableTransaction mtx, CScript inputPubKey, int nIn=0); #endif /* TESTUTILS_H */ From bd070d8bcec0d2b42e561085e629357fa304f43e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 12:55:14 +0300 Subject: [PATCH 0046/1123] Prevent relaying expired tx --- src/komodo_bitcoind.h | 6 +++--- src/komodo_defs.h | 1 + src/komodo_interest.h | 4 ++-- src/wallet/wallet.cpp | 13 ++++++++++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8ca20d329..c434e33a3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1033,16 +1033,16 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( txheight < 247205 ) cmptime -= 16000; - if ( (int64_t)tx.nLockTime < cmptime-3600 ) + if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { if ( tx.nLockTime != 1477258935 && dispflag != 0 ) { - fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-KOMODO_MAXMEMPOOLTIME)),(uint32_t)tx.nLockTime,cmptime); } return(-1); } if ( 0 && dispflag != 0 ) - fprintf(stderr,"validateinterest.%d accept.%d [%d] locktime %u cmp2.%u\n",dispflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest.%d accept.%d [%d] locktime %u cmp2.%u\n",dispflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-KOMODO_MAXMEMPOOLTIME)),(int32_t)tx.nLockTime,cmptime); } } return(0); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 3f8b498fa..a1b219e80 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -6,5 +6,6 @@ #define ROUNDROBIN_DELAY 61 #define KOMODO_ASSETCHAIN_MAXLEN 65 #define KOMODO_LIMITED_NETWORKSIZE 4 +#define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus #endif diff --git a/src/komodo_interest.h b/src/komodo_interest.h index 8fd6becea..3141532fa 100644 --- a/src/komodo_interest.h +++ b/src/komodo_interest.h @@ -83,13 +83,13 @@ uint64_t komodo_moneysupply(int32_t height) 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 ( nLockTime >= LOCKTIME_THRESHOLD && tiptime > nLockTime && (minutes= (tiptime - nLockTime) / 60) >= (KOMODO_MAXMEMPOOLTIME/60) ) { if ( minutes > 365 * 24 * 60 ) minutes = 365 * 24 * 60; if ( txheight >= 1000000 && minutes > 31 * 24 * 60 ) minutes = 31 * 24 * 60; - minutes -= 59; + minutes -= ((KOMODO_MAXMEMPOOLTIME/60) - 1); interest = ((nValue / 10512000) * minutes); } return(interest); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 77a27c69a..49b3e0c26 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1887,7 +1887,9 @@ bool CWalletTx::RelayWalletTransaction() assert(pwallet->GetBroadcastTransactions()); if (!IsCoinBase()) { - if (GetDepthInMainChain() == 0) { + if (GetDepthInMainChain() == 0) + { + // if tx is expired, dont relay LogPrintf("Relaying wtx %s\n", GetHash().ToString()); RelayTransaction((CTransaction)*this); return true; @@ -2102,12 +2104,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", 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 a5b7fef44b5b4cd93ed2aefd4bd82e8516593383 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 12:56:52 +0300 Subject: [PATCH 0047/1123] Test --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 49b3e0c26..550cba683 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2115,7 +2115,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) { if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME ) { - LogPrintf("skip Relaying wtx %s nLockTime %u vs now.%u\n", GetHash().ToString(),(uint32_t)wtx.nLockTime,now); + LogPrintf("skip Relaying wtx %s nLockTime %u vs now.%u\n", wtx.GetHash().ToString(),(uint32_t)wtx.nLockTime,now); continue; } } From 0d664409909a25a1b1ee4caa141f4fe2d4fdc5d1 Mon Sep 17 00:00:00 2001 From: ca333 Date: Thu, 10 May 2018 11:58:13 +0200 Subject: [PATCH 0048/1123] update libgmp using our own CDN --- depends/packages/libgmp.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/libgmp.mk b/depends/packages/libgmp.mk index f06e4a6c4..d8e41573a 100644 --- a/depends/packages/libgmp.mk +++ b/depends/packages/libgmp.mk @@ -18,7 +18,7 @@ $(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 be5f41cd904c437702a004074e7547491c3a6d24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 13:00:24 +0300 Subject: [PATCH 0049/1123] 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 e39069257675a3cb7d73fd59f5ea1f01133ea03f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 13:08:25 +0300 Subject: [PATCH 0050/1123] Display invalidateblock, reconsiderblock, resendwallettransactions --- src/rpcserver.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 4eb2270fb..86a7aed86 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -358,12 +358,12 @@ static const CRPCCommand vRPCCommands[] = { "util", "jumblr_pause", &jumblr_pause, true }, { "util", "jumblr_resume", &jumblr_resume, true }, + { "util", "invalidateblock", &invalidateblock, true }, + { "util", "reconsiderblock", &reconsiderblock, true }, /* Not shown in help */ - { "hidden", "invalidateblock", &invalidateblock, true }, - { "hidden", "reconsiderblock", &reconsiderblock, true }, { "hidden", "setmocktime", &setmocktime, true }, #ifdef ENABLE_WALLET - { "hidden", "resendwallettransactions", &resendwallettransactions, true}, + { "wallet", "resendwallettransactions", &resendwallettransactions, true}, #endif #ifdef ENABLE_WALLET From 4017d7c4f58fdab25e0d5fee9c06472b37eb5131 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 13:13:49 +0300 Subject: [PATCH 0051/1123] Change libgmp path to supernetorg --- depends/packages/libgmp.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/libgmp.mk b/depends/packages/libgmp.mk index f06e4a6c4..d8e41573a 100644 --- a/depends/packages/libgmp.mk +++ b/depends/packages/libgmp.mk @@ -18,7 +18,7 @@ $(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 d014b5bd1c3665e2a399797d1efc913399b6ded5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 May 2018 13:14:42 +0300 Subject: [PATCH 0052/1123] 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 0053/1123] 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 87ae91727714cfaf30415fedbd0954573d9faec3 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 11 May 2018 11:38:31 +0700 Subject: [PATCH 0054/1123] Remove vote2018 from `fiat-cli` --- src/fiat-cli | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fiat-cli b/src/fiat-cli index ce2e7a51d..76f219c83 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -22,7 +22,6 @@ echo etomic; fiat/etomic $1 $2 $3 $4 echo btch; fiat/btch $1 $2 $3 $4 echo pizza; fiat/pizza $1 $2 $3 $4 echo beer; fiat/beer $1 $2 $3 $4 -echo vote2018; fiat/vote2018 $1 $2 $3 $4 echo ninja; fiat/ninja $1 $2 $3 $4 echo oot; fiat/oot $1 $2 $3 $4 echo bntn; fiat/bntn $1 $2 $3 $4 From 7be54a7fa36d2594eef8e3b9e657f2045b153ffa Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 11 May 2018 11:59:49 +0700 Subject: [PATCH 0055/1123] Remove VOTE2018 from `dpowassets` --- src/dpowassets | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dpowassets b/src/dpowassets index a144eab28..c2ede0884 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -27,7 +27,6 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHAIN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VOTE2018\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NINJA\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" From ae3f3fea6c0b98a3278151d96a32ceef63a03417 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 11 May 2018 16:28:52 +0300 Subject: [PATCH 0056/1123] +GAME sanitize listunspent interest calc --- src/dpowassets | 4 +++- src/rest.cpp | 1 - src/rpcblockchain.cpp | 2 -- src/rpcrawtransaction.cpp | 8 ++++---- src/wallet/rpcwallet.cpp | 10 ++++------ 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/dpowassets b/src/dpowassets index a144eab28..642881532 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -22,7 +22,6 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AXO\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" @@ -32,3 +31,6 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" + +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":10,\"pubkey\":\"$pubkey\"}" diff --git a/src/rest.cpp b/src/rest.cpp index 44d1de533..8e2e4d1e6 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -563,7 +563,6 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) utxo.push_back(Pair("txvers", (int32_t)coin.nTxVer)); utxo.push_back(Pair("height", (int32_t)coin.nHeight)); utxo.push_back(Pair("value", ValueFromAmount(coin.out.nValue))); - //utxo.push_back(Pair("interest", ValueFromAmount(komodo_interest(coin.out.nValue,coin.nLockTime,chainActive.Tip()->nTime)))); // include the script in a json output UniValue o(UniValue::VOBJ); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index d9cc072e5..3774f1bb5 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -752,12 +752,10 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp) #define KOMODO_KVDURATION 1440 #define KOMODO_KVBINARY 2 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume); int32_t komodo_paxprices(int32_t *heights,uint64_t *prices,int32_t max,char *base,char *rel); int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestamp); char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,int32_t len); -//uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip); diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 8b722e931..018361513 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -57,7 +57,6 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fInclud out.push_back(Pair("addresses", a)); } - UniValue TxJoinSplitToJSON(const CTransaction& tx) { UniValue vjoinsplit(UniValue::VARR); for (unsigned int i = 0; i < tx.vjoinsplit.size(); i++) { @@ -115,7 +114,7 @@ UniValue TxJoinSplitToJSON(const CTransaction& tx) { return vjoinsplit; } -uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); +uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, int nHeight = 0, int nConfirmations = 0, int nBlockTime = 0) { @@ -176,9 +175,10 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( pindex != 0 && tx.nLockTime > 500000000 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 ) { - interest = komodo_interest(pindex->nHeight,txout.nValue,tx.nLockTime,tipindex->nTime); + int64_t interest; int32_t txheight; uint32_t locktime; + interest = komodo_accrued_interest(&txheight,&locktime,txout.hash,i,0,txout.nValue,(int32_t)tipindex->nHeight); out.push_back(Pair("interest", ValueFromAmount(interest))); } out.push_back(Pair("valueZat", txout.nValue)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4cc79cfdb..b96064221 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -76,7 +76,6 @@ void EnsureWalletIsUnlocked() } uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight); -uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) { @@ -2562,8 +2561,6 @@ UniValue resendwallettransactions(const UniValue& params, bool fHelp) return result; } -uint64_t komodo_interest(int32_t txheight,uint64_t nValue,uint32_t nLockTime,uint32_t tiptime); - UniValue listunspent(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) @@ -2678,8 +2675,8 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t interest; uint32_t locktime; int32_t txheight; if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { - komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); - interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); + interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); + //interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); @@ -2708,7 +2705,8 @@ uint64_t komodo_interestsum() CBlockIndex *tipindex,*pindex = it->second; if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) { - interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); + interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); + //interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); sum += interest; } } From 316a563c50026029dfc1c2b8bb235ffed26926a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 11 May 2018 16:34:25 +0300 Subject: [PATCH 0057/1123] Test --- src/rpcrawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 018361513..123e0bbb9 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -178,7 +178,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; - interest = komodo_accrued_interest(&txheight,&locktime,txout.hash,i,0,txout.nValue,(int32_t)tipindex->nHeight); + interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->nHeight); out.push_back(Pair("interest", ValueFromAmount(interest))); } out.push_back(Pair("valueZat", txout.nValue)); From 09511571afa3d7e19075abb7610e0cfed6793b96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 11 May 2018 16:36:21 +0300 Subject: [PATCH 0058/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b96064221..c87f6b2dd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2691,7 +2691,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { - uint64_t interest,sum = 0; + uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; vector vecOutputs; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); From a7322d7720e139d33e2dc5b81217af354be339d0 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sat, 12 May 2018 12:51:39 +0300 Subject: [PATCH 0059/1123] 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 39c15c681f35d536076962c252a9e94a0f72bf1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 14 May 2018 16:53:59 +0300 Subject: [PATCH 0060/1123] -GAME for now --- src/dpowassets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpowassets b/src/dpowassets index 642881532..b8e2583e8 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -33,4 +33,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":10,\"pubkey\":\"$pubkey\"}" +#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":10,\"pubkey\":\"$pubkey\"}" From 221cc791c35aa1a8d3b3927a34ce97f5e60b8562 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 15 May 2018 22:45:16 +0300 Subject: [PATCH 0061/1123] Change notary sig to CRYPTO output --- src/komodo_defs.h | 1 + src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index a1b219e80..1d7351638 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -7,5 +7,6 @@ #define KOMODO_ASSETCHAIN_MAXLEN 65 #define KOMODO_LIMITED_NETWORKSIZE 4 #define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus +#define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" #endif diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c87f6b2dd..174b9a99a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4519,7 +4519,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) // ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; txNew.vin[0].prevout.hash = utxotxid; //revtxid; txNew.vin[0].prevout.n = utxovout; - txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].scriptPubKey = CScript() << ParseHex(CRYPTO777_PUBSECPSTR) << OP_CHECKSIG; txNew.vout[0].nValue = utxovalue - txfee; CTransaction txNewConst(txNew); signSuccess = ProduceSignature(TransactionSignatureCreator(&keystore, &txNewConst, 0, utxovalue, SIGHASH_ALL), best_scriptPubKey, sigdata, consensusBranchId); From 06c960d2b7eaa380461762bc0baa7db664221992 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 15 May 2018 22:27:10 -0300 Subject: [PATCH 0062/1123] m3 test proven --- src/cc/betprotocol.cpp | 2 +- src/cc/eval.h | 17 +- src/cc/import.cpp | 2 +- src/crosschain.cpp | 55 ++++-- src/crosschain.h | 4 +- src/komodo_bitcoind.h | 1 + src/komodo_notary.h | 19 +- src/notarisationdb.cpp | 11 +- src/rpcblockchain.cpp | 3 +- src/test-komodo/test_crosschain.cpp | 212 +++++++++------------ src/test-komodo/test_eval_notarisation.cpp | 150 +++++++-------- src/test-komodo/testutils.cpp | 4 +- 12 files changed, 249 insertions(+), 231 deletions(-) diff --git a/src/cc/betprotocol.cpp b/src/cc/betprotocol.cpp index 1b4834767..9fe9a567d 100644 --- a/src/cc/betprotocol.cpp +++ b/src/cc/betprotocol.cpp @@ -199,7 +199,7 @@ bool Eval::ImportPayout(const std::vector params, const CTransaction &i // Check disputeTx solves momproof from vout[0] { - NotarisationData data; + NotarisationData data(0); if (!GetNotarisationData(proof.notarisationHash, data)) return Invalid("coudnt-load-mom"); diff --git a/src/cc/eval.h b/src/cc/eval.h index 1bbf68f65..0625a47e8 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -124,11 +124,18 @@ extern char ASSETCHAINS_SYMBOL[65]; */ class NotarisationData { + bool IsBack() + { + if (IsBackNotarisation == 2) { + return ASSETCHAINS_SYMBOL[0] != 0; + } + return (bool) IsBackNotarisation; + } public: - bool IsBackNotarisation = 0; + int IsBackNotarisation = 0; uint256 blockHash; uint32_t height; - uint256 txHash; // Only get this guy in asset chains not in KMD + uint256 txHash; char symbol[64] = "\0"; uint256 MoM; uint32_t MoMDepth; @@ -136,7 +143,7 @@ public: uint256 MoMoM; uint32_t MoMoMDepth; - NotarisationData(bool IsBack=0) : IsBackNotarisation(IsBack) {} + NotarisationData(int IsBack=2) : IsBackNotarisation(IsBack) {} ADD_SERIALIZE_METHODS; @@ -144,14 +151,14 @@ public: inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { READWRITE(blockHash); READWRITE(height); - if (IsBackNotarisation || (!ser_action.ForRead() && !txHash.IsNull())) + if (IsBack()) READWRITE(txHash); SerSymbol(s, ser_action); READWRITE(MoM); READWRITE(MoMDepth); if (s.size() == 0) return; READWRITE(ccId); - if (IsBackNotarisation) { + if (IsBack()) { READWRITE(MoMoM); READWRITE(MoMoMDepth); } diff --git a/src/cc/import.cpp b/src/cc/import.cpp index be4929b94..9d9daddc0 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -56,7 +56,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp // Check proof confirms existance of burnTx { - NotarisationData data; + NotarisationData data(1); if (!GetNotarisationData(proof.notarisationHeight, data, true)) return Invalid("coudnt-load-momom"); diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 069a53f38..bb2717515 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -1,6 +1,7 @@ #include "cc/eval.h" #include "main.h" #include "notarisationdb.h" +#include "komodo_structs.h" /* On KMD */ @@ -12,6 +13,8 @@ uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vect * including the block height of the last notarisation until the height before the * previous notarisation. */ + *assetChainHeight = -1; + if (targetCCid <= 1) return uint256(); @@ -33,24 +36,31 @@ uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vect if (strcmp(data.symbol, symbol) == 0) { seenOwnNotarisations++; + printf("seenOwnNotarisations:%i\n", seenOwnNotarisations); if (seenOwnNotarisations == 2) goto end; if (seenOwnNotarisations == 1) *assetChainHeight = data.height; // TODO: Needed? - continue; // Don't include own MoMs } - if (seenOwnNotarisations == 1) + if (seenOwnNotarisations == 1) { moms.push_back(data.MoM); + printf("Pushed a MoM@%i:%s\n", kmdHeight-i, data.MoM.GetHex().data()); + } } } end: + printf("GetProofRoot {\n"); + printf(" CC:%i S:%s H:%i\n", targetCCid, symbol, kmdHeight); + for (int i=0; i GetCrossChainProof(uint256 txid, char* targetSymbol, +MerkleBranch GetCrossChainProof(uint256 txid, char* targetSymbol, uint32_t targetCCid, uint256 notarisationTxid, MerkleBranch assetChainProof) { /* @@ -79,15 +89,18 @@ std::pair GetCrossChainProof(uint256 txid, char* targetSym // Get MoMs for kmd height and symbol std::vector moms; int targetChainStartHeight; + printf("Getting Proof Root\n"); uint256 MoMoM = GetProofRoot(targetSymbol, targetCCid, kmdHeight, moms, &targetChainStartHeight); if (MoMoM.IsNull()) throw std::runtime_error("No MoMs found"); // Find index of source MoM in MoMoM int nIndex; - for (nIndex=0; nIndex */ -std::pair GetAssetchainProof(uint256 hash) +std::pair GetAssetchainProof(uint256 hash, int &npIdx) { - uint256 notarisationHash, MoM,MoMoM; int32_t notarisedHeight, depth; CBlockIndex* blockIndex; + int nIndex; + CBlockIndex* blockIndex; + struct notarized_checkpoint* np; std::vector branch; - int nIndex,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; { uint256 blockHash; @@ -148,14 +169,12 @@ std::pair GetAssetchainProof(uint256 hash) throw std::runtime_error("cannot find transaction"); blockIndex = mapBlockIndex[blockHash]; - - depth = komodo_MoM(¬arisedHeight, &MoM, ¬arisationHash, blockIndex->nHeight,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi); - - if (!depth) + if (!(np = komodo_npptr_for_height(blockIndex->nHeight, &npIdx))) throw std::runtime_error("notarisation not found"); // index of block in MoM leaves - nIndex = notarisedHeight - blockIndex->nHeight; + printf("notarised at: %i\n", np->notarized_height); + nIndex = np->notarized_height - blockIndex->nHeight; } // build merkle chain from blocks to MoM @@ -163,8 +182,8 @@ std::pair GetAssetchainProof(uint256 hash) // since the merkle branch code is tied up in a block class // and we want to make a merkle branch for something that isnt transactions CBlock fakeBlock; - for (int i=0; ihashMerkleRoot; + for (int i=0; iMoMdepth; i++) { + uint256 mRoot = chainActive[np->notarized_height - i]->hashMerkleRoot; CTransaction fakeTx; // first value in CTransaction memory is it's hash memcpy((void*)&fakeTx, mRoot.begin(), 32); @@ -173,7 +192,7 @@ std::pair GetAssetchainProof(uint256 hash) branch = fakeBlock.GetMerkleBranch(nIndex); // Check branch - if (MoM != CBlock::CheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex)) + if (np->MoM != CBlock::CheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex)) throw std::runtime_error("Failed merkle block->MoM"); } @@ -208,10 +227,10 @@ std::pair GetAssetchainProof(uint256 hash) } // Check the proof - if (MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) + if (np->MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) throw std::runtime_error("Failed validating MoM"); // All done! CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION); - return std::make_pair(notarisationHash, MerkleBranch(nIndex, branch)); + return std::make_pair(np->notarized_desttxid, MerkleBranch(nIndex, branch)); } diff --git a/src/crosschain.h b/src/crosschain.h index 25fe50e5f..e490fbd0e 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -5,13 +5,13 @@ /* On assetchain */ -std::pair GetAssetchainProof(uint256 hash); +std::pair GetAssetchainProof(uint256 hash, int &npIdx); /* On KMD */ uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, int* assetChainHeight); /* On KMD */ -std::pair GetCrossChainProof(uint256 txid, char* targetSymbol, +MerkleBranch GetCrossChainProof(uint256 txid, char* targetSymbol, uint32_t targetCCid, uint256 notarisationTxid, MerkleBranch assetChainProof); /* On assetchain */ diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2174a8d80..cf72a0715 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1268,6 +1268,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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; + return 1; // TODO: obviously cant commit this if ( !CheckEquihashSolution(pblock, Params()) ) { fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 3c81f5115..a28699d8b 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -384,18 +384,35 @@ int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33, //struct komodo_state *komodo_stateptr(char *symbol,char *dest); -struct notarized_checkpoint *komodo_npptr(int32_t height) +struct notarized_checkpoint *komodo_npptr_for_height(int32_t height, int *idx) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; int32_t i; struct komodo_state *sp; struct notarized_checkpoint *np = 0; if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) { for (i=sp->NUM_NPOINTS-1; i>=0; i--) { + *idx = i; np = &sp->NPOINTS[i]; if ( np->MoMdepth > 0 && height > np->notarized_height-np->MoMdepth && height <= np->notarized_height ) return(np); } } + *idx = -1; + return(0); +} + +struct notarized_checkpoint *komodo_npptr(int32_t height) +{ + int idx; + return komodo_npptr_for_height(height, &idx); +} + +struct notarized_checkpoint *komodo_npptr_at(int idx) +{ + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; + if ( (sp= komodo_stateptr(symbol,dest)) != 0 ) + if (idx < sp->NUM_NPOINTS) + return &sp->NPOINTS[idx]; return(0); } diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 6daa5a132..b16968614 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -9,19 +9,18 @@ NotarisationDB *pnotarisations; -NotarisationDB::NotarisationDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "notarisations", nCacheSize, fMemory, fWipe, false, 64) { -} +NotarisationDB::NotarisationDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "notarisations", nCacheSize, fMemory, fWipe, false, 64) { } + NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight) { EvalRef eval; NotarisationsInBlock vNotarisations; - bool IsBackNotarisation = ASSETCHAINS_SYMBOL[0] != 0; for (unsigned int i = 0; i < block.vtx.size(); i++) { CTransaction tx = block.vtx[i]; if (eval->CheckNotaryInputs(tx, nHeight, block.nTime)) { - NotarisationData data(IsBackNotarisation); + NotarisationData data; if (ParseNotarisationOpReturn(tx, data)) vNotarisations.push_back(std::make_pair(tx.GetHash(), data)); else @@ -40,7 +39,9 @@ void WriteBackNotarisations(NotarisationsInBlock notarisations) { BOOST_FOREACH(Notarisation &n, notarisations) { - if (n.second.IsBackNotarisation) + if (n.second.IsBackNotarisation) { pnotarisations->Write(n.second.txHash, n); + printf("WriteBackNotarisations {\n m3:%s\n}\n", n.second.MoMoM.GetHex().data()); + } } } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 75454497d..99584c7bb 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -940,7 +940,8 @@ UniValue txMoMproof(const UniValue& params, bool fHelp) hash = uint256S(params[0].get_str()); - std::vector proofData = E_MARSHAL(ss << GetAssetchainProof(hash)); + int npIdx; + std::vector proofData = E_MARSHAL(ss << GetAssetchainProof(hash, npIdx)); return HexStr(proofData); } diff --git a/src/test-komodo/test_crosschain.cpp b/src/test-komodo/test_crosschain.cpp index f7f7d47ab..ebf52fa13 100644 --- a/src/test-komodo/test_crosschain.cpp +++ b/src/test-komodo/test_crosschain.cpp @@ -13,7 +13,9 @@ #include "core_io.h" #include "crosschain.h" #include "key.h" +#include "komodo_structs.h" #include "main.h" +#include "notarisationdb.h" #include "primitives/block.h" #include "primitives/transaction.h" #include "script/cc.h" @@ -26,6 +28,7 @@ extern uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); +extern struct notarized_checkpoint *komodo_npptr_at(int idx); /* @@ -40,8 +43,8 @@ class TestCrossChain : public ::testing::Test, public Eval { public: bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const { - NotarisationData data; - return ParseNotarisationOpReturn(tx, data); + NotarisationData data(2); + return ParseNotarisationOpReturn(tx, data); // If it parses it's valid } protected: static void SetUpTestCase() { } @@ -52,6 +55,15 @@ protected: }; +uint256 endianHash(uint256 h) +{ + uint256 out; + for (int i=0; i<32; i++) { + out.begin()[31-i] = h.begin()[i]; + } + return out; +} + TEST_F(TestCrossChain, testCreateAndValidateImportProof) { @@ -66,10 +78,13 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) int childPid = fork(); void *ctx = zmq_ctx_new(); void *socket = zmq_socket(ctx, ZMQ_PAIR); + if (!childPid) + strcpy(ASSETCHAINS_SYMBOL, "PIZZA"); setupChain(); std::vector blocks; - blocks.resize(10); - NotarisationData a2kmd, kmd2a(true); + blocks.resize(1000); + NotarisationData a2kmd(0), kmd2a(1); + int numTestNotarisations = 10; auto SendIPC = [&] (std::vector v) { @@ -101,75 +116,93 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) auto RunTestAssetchain = [&] () { - NotarisationData back(1); - strcpy(ASSETCHAINS_SYMBOL, "symbolA"); - strcpy(a2kmd.symbol, "symbolA"); - a2kmd.ccId = 2; - - /* - * Notarisation 1 - */ - generateBlock(&blocks[1]); - generateBlock(&blocks[2]); - a2kmd.blockHash = blocks[2].GetHash(); - a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2); - SendIPC(E_MARSHAL(ss << a2kmd)); - E_UNMARSHAL(RecvIPC(), ss >> back); - RecordNotarisation(blocks[1].vtx[0], back); + NotarisationData n(0), back(1); + strcpy(n.symbol, "PIZZA"); + n.ccId = 2; + int height = 0; /* - * Notarisation 2 + * Send notarisations and write backnotarisations */ - generateBlock(&blocks[3]); - generateBlock(&blocks[4]); - a2kmd.blockHash = blocks[4].GetHash(); - a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2); - SendIPC(E_MARSHAL(ss << a2kmd)); - E_UNMARSHAL(RecvIPC(), ss >> back); - RecordNotarisation(blocks[3].vtx[0], back); + for (int ni=0; ni> back)); + RecordNotarisation(blocks[height].vtx[0], back); + } /* * Generate proof */ - generateBlock(&blocks[5]); - uint256 txid = blocks[3].vtx[0].GetHash(); - std::pair assetChainProof = GetAssetchainProof(txid); - SendIPC(E_MARSHAL(ss << txid; ss << assetChainProof)); + uint256 txid = blocks[7].vtx[0].GetHash(); + int npIdx; + std::pair proof = GetAssetchainProof(txid, npIdx); + SendIPC(E_MARSHAL(ss << txid; ss << proof)); + + /* + * Test proof + */ + std::pair ccProof; + E_UNMARSHAL(RecvIPC(), ss >> ccProof); + + // Now we have the branch with the hash of the notarisation on KMD + // What we'd like is the notarised height on PIZZA so we can go forward + // to the next backnotarisation, and then to the next, to get the M3. + uint256 result = ccProof.second.Exec(txid); + printf("result m3: %s\n", result.GetHex().data()); + struct notarized_checkpoint* np = komodo_npptr_at(npIdx+1); + std::pair b; + pnotarisations->Read(np->notarized_desttxid, b); + printf("m3@1: %s\n", b.second.MoMoM.GetHex().data()); + + { + printf("RunTestAssetChain.test {\n txid: %s\n momom: %s\n", txid.GetHex().data(), b.second.MoMoM.GetHex().data()); + printf(" idx: %i\n", ccProof.second.nIndex); + for (int i=0; i> n); - // Grab a coinbase input to fund notarisation - generateBlock(&blocks[1]); - n.txHash = RecordNotarisation(blocks[1].vtx[0], a2kmd); - n.height = chainActive.Height(); - SendIPC(E_MARSHAL(ss << n)); - - /* - * Notarisation 2 - */ - E_UNMARSHAL(RecvIPC(), ss >> n); - // Grab a coinbase input to fund notarisation - generateBlock(&blocks[2]); - n.txHash = RecordNotarisation(blocks[2].vtx[0], a2kmd); - n.height = chainActive.Height(); - SendIPC(E_MARSHAL(ss << n)); + for (int ni=0; ni> n); + // Grab a coinbase input to fund notarisation + generateBlock(&blocks[++height]); + n.txHash = RecordNotarisation(blocks[height].vtx[0], n); + { + std::vector moms; + int assetChainHeight; + n.MoMoM = GetProofRoot(n.symbol, 2, height, moms, &assetChainHeight); + } + printf("RunTestKmd {\n kmdnotid:%s\n momom:%s\n}\n", n.txHash.GetHex().data(), n.MoMoM.GetHex().data()); + n.IsBackNotarisation = 1; + SendIPC(E_MARSHAL(ss << n)); + } /* * Extend proof */ - std::pair assetChainProof; + std::pair proof; uint256 txid; // Extend proof to MoMoM - assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> kmd2a)); - std::pair ccProof = GetCrossChainProof(txid, (char*)"symbolA", - 2, assetChainProof.first, assetChainProof.second); + assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> proof)); + proof.second = GetCrossChainProof(txid, (char*)"PIZZA", 2, proof.first, proof.second); + SendIPC(E_MARSHAL(ss << proof)); }; const char endpoint[] = "ipc://tmpKomodoTestCrossChainSock"; @@ -177,8 +210,9 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) if (!childPid) { assert(0 == zmq_connect(socket, endpoint)); usleep(20000); - RunTestAssetchain(); - exit(0); + int out = RunTestAssetchain(); + if (!out) printf("Assetchain success\n"); + exit(out); } else { assert(0 == zmq_bind(socket, endpoint)); @@ -190,77 +224,13 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) } - /* - - * - * Assetchain notarisation 2 - * - - ON_ASSETCHAIN { - a2kmd.blockHash = blocks[4].GetHash(); - a2kmd.MoM = komodo_calcMoM(a2kmd.height = chainActive.Height(), a2kmd.MoMDepth = 2); - SendIPC(E_MARSHAL(ss << a2kmd)); - } - - ON_KMD { - assert(E_UNMARSHAL(RecvIPC(), ss >> a2kmd)); - // Grab a coinbase input to fund notarisation - RecordNotarisation(blocks[2].vtx[0], a2kmd); - } - - generateBlock(&blocks[5]); - generateBlock(&blocks[6]); - - * - * Backnotarisation - * - * This is what will contain the MoMoM which allows us to prove across chains - * - std::vector moms; - int assetChainHeight; - - ON_KMD { - memset(kmd2a.txHash.begin(), 1, 32); // Garbage but non-null - kmd2a.symbol[0] = 0; // KMD - kmd2a.MoMoM = GetProofRoot((char*)"symbolA", 2, chainActive.Height(), moms, &assetChainHeight); - kmd2a.MoMoMDepth = 0; // Needed? - SendIPC(E_MARSHAL(ss << kmd2a)); - } - - ON_ASSETCHAIN { - assert(E_UNMARSHAL(RecvIPC(), ss >> kmd2a)); - RecordNotarisation(blocks[1].vtx[0], kmd2a); - } - - - * * We can now prove a tx from A on A, via a merkle root backpropagated from KMD. - * + * * The transaction that we'll try to prove is the coinbase from the 3rd block. * We should be able to start with only that transaction ID, and generate a merkle * proof. - * - - std::pair assetChainProof; - uint256 txid; - - ON_ASSETCHAIN { - txid = blocks[2].vtx[0].GetHash(); - - // First thing to do is get the proof from the assetchain - assetChainProof = GetAssetchainProof(txid); - SendIPC(E_MARSHAL(ss << txid; ss << assetChainProof)); - } - - ON_KMD { - // Extend proof to MoMoM - assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> kmd2a)); - std::pair ccProof = GetCrossChainProof(txid, (char*)"symbolA", - 2, assetChainProof.first, assetChainProof.second); - } - - */ + */ } diff --git a/src/test-komodo/test_eval_notarisation.cpp b/src/test-komodo/test_eval_notarisation.cpp index f0ce45358..68da7d990 100644 --- a/src/test-komodo/test_eval_notarisation.cpp +++ b/src/test-komodo/test_eval_notarisation.cpp @@ -21,84 +21,84 @@ extern int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t t namespace TestEvalNotarisation { -class EvalMock : public Eval -{ -public: - uint32_t nNotaries; - uint8_t notaries[64][33]; - std::map txs; - std::map blocks; - - int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const + class EvalMock : public Eval { - memcpy(pubkeys, notaries, sizeof(notaries)); - return nNotaries; - } + public: + uint32_t nNotaries; + uint8_t notaries[64][33]; + std::map txs; + std::map blocks; - bool GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const - { - auto r = txs.find(hash); - if (r != txs.end()) { - txOut = r->second; - if (blocks.count(hash) > 0) - hashBlock = hash; - return true; + int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const + { + memcpy(pubkeys, notaries, sizeof(notaries)); + return nNotaries; + } + + bool GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const + { + auto r = txs.find(hash); + if (r != txs.end()) { + txOut = r->second; + if (blocks.count(hash) > 0) + hashBlock = hash; + return true; + } + return false; + } + + bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const + { + auto r = blocks.find(hash); + if (r == blocks.end()) return false; + blockIdx = r->second; + return true; + } + }; + + static auto noop = [&](CMutableTransaction &mtx){}; + + + template + void SetupEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify) + { + eval.nNotaries = komodo_notaries(eval.notaries, 780060, 1522946781); + + // make fake notary inputs + notary.vin.resize(11); + for (int i=0; isecond; - return true; - } -}; - -static auto noop = [&](CMutableTransaction &mtx){}; -template -void SetupEval(EvalMock &eval, CMutableTransaction ¬ary, Modifier modify) -{ - eval.nNotaries = komodo_notaries(eval.notaries, 780060, 1522946781); - - // make fake notary inputs - notary.vin.resize(11); - for (int i=0; i Date: Fri, 18 May 2018 16:56:44 +0300 Subject: [PATCH 0063/1123] Enable zmergetoaddress by default --- src/komodo_gateway.h | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 018baa675..7b642746a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -729,7 +729,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } if ( strangeout != 0 || notmatched != 0 ) { - if ( strcmp(NOTARY_PUBKEY.c_str(),"03b7621b44118017a16043f19b30cc8a4cfe068ac4e42417bae16ba460c80f3828") == 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); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 174b9a99a..fa2937005 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4067,7 +4067,7 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - auto fEnableMergeToAddress = fExperimentalMode && GetBoolArg("-zmergetoaddress", false); + auto fEnableMergeToAddress = true; //fExperimentalMode && GetBoolArg("-zmergetoaddress", false); std::string strDisabledMsg = ""; if (!fEnableMergeToAddress) { strDisabledMsg = "\nWARNING: z_mergetoaddress is DISABLED but can be enabled as an experimental feature.\n"; From e4f943d86dcc57df25d7843bfca6e2a483d9eda6 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Fri, 18 May 2018 19:29:33 -0300 Subject: [PATCH 0064/1123] cross chain rpc methods --- src/Makefile.am | 1 + src/cc/eval.cpp | 8 +- src/cc/eval.h | 6 +- src/cc/import.cpp | 8 +- src/crosschain.cpp | 92 +++++++-------- src/crosschain.h | 11 +- src/importcoin.cpp | 6 +- src/importcoin.h | 15 +-- src/notarisationdb.cpp | 16 ++- src/notarisationdb.h | 4 +- src/rpcblockchain.cpp | 168 ---------------------------- src/rpcclient.cpp | 1 - src/rpccrosschain.cpp | 158 ++++++++++++++++++++++++++ src/rpcserver.cpp | 12 +- src/rpcserver.h | 4 +- src/test-komodo/test_coinimport.cpp | 2 +- src/test-komodo/test_crosschain.cpp | 53 ++------- src/test-komodo/testutils.cpp | 4 - 18 files changed, 264 insertions(+), 305 deletions(-) create mode 100644 src/rpccrosschain.cpp diff --git a/src/Makefile.am b/src/Makefile.am index fa475b4e1..f9b19978b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -279,6 +279,7 @@ libbitcoin_server_a_SOURCES = \ pow.cpp \ rest.cpp \ rpcblockchain.cpp \ + rpccrosschain.cpp \ rpcmining.cpp \ rpcmisc.cpp \ rpcnet.cpp \ diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 6dc72f2a0..8ed29da9d 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -154,7 +154,7 @@ uint32_t Eval::GetCurrentLedgerID() const /* - * Get MoM from a notarisation tx hash + * Get MoM from a notarisation tx hash (on KMD) */ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data) const { @@ -166,9 +166,11 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data) return true; } -bool Eval::GetNotarisationData(int notarisationHeight, NotarisationData &data, bool verifyCanonical) const +/* + * Get MoMoM corresponding to a notarisation tx hash (on assetchain) + */ +bool Eval::GetProofRoot(uint256 kmdNotarisationHash, uint256 &momom) const { - return false; } diff --git a/src/cc/eval.h b/src/cc/eval.h index 0625a47e8..2a30bba90 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -72,8 +72,7 @@ public: virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const; virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const; virtual bool GetNotarisationData(uint256 notarisationHash, NotarisationData &data) const; - virtual bool GetNotarisationData(int notarisationHeight, NotarisationData &data, - bool verifyCanonical) const; + virtual bool GetProofRoot(uint256 kmdNotarisationHash, uint256 &momom) const; virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const; virtual uint32_t GetCurrentLedgerID() const; }; @@ -228,6 +227,9 @@ public: }; +typedef std::pair TxProof; + + uint256 GetMerkleRoot(const std::vector& vLeaves); diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 9d9daddc0..202d75468 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -15,7 +15,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp if (importTx.vout.size() == 0) return Invalid("no-vouts"); // params - MomoProof proof; + TxProof proof; CTransaction burnTx; if (!E_UNMARSHAL(params, ss >> proof; ss >> burnTx)) return Invalid("invalid-params"); @@ -56,11 +56,11 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp // Check proof confirms existance of burnTx { - NotarisationData data(1); - if (!GetNotarisationData(proof.notarisationHeight, data, true)) + uint256 momom; + if (!GetProofRoot(proof.first, momom)) return Invalid("coudnt-load-momom"); - if (data.MoMoM != proof.branch.Exec(burnTx.GetHash())) + if (momom != proof.second.Exec(burnTx.GetHash())) return Invalid("momom-check-fail"); } diff --git a/src/crosschain.cpp b/src/crosschain.cpp index bb2717515..b68b77b33 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -5,29 +5,33 @@ /* On KMD */ -uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, int* assetChainHeight) +uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, + std::vector &moms, uint256 &destNotarisationTxid) { /* * Notaries don't wait for confirmation on KMD before performing a backnotarisation, * but we need a determinable range that will encompass all merkle roots. Include MoMs * including the block height of the last notarisation until the height before the * previous notarisation. + * + * kmdHeight notarisations-0 notarisations-1 + * | |********************| + * > scan backwards > */ - *assetChainHeight = -1; if (targetCCid <= 1) return uint256(); - int seenOwnNotarisations = 0; + if (kmdHeight < 0 || kmdHeight > chainActive.Height()) + return uint256(); - // TODO: test height out of range - // TODO: Make sure that boundary for moms is notarisation tx not block + int seenOwnNotarisations = 0; for (int i=0; i<1440; i++) { if (i > kmdHeight) break; NotarisationsInBlock notarisations; uint256 blockHash = *chainActive[kmdHeight-i]->phashBlock; - if (!pnotarisations->Read(blockHash, notarisations)) + if (!GetBlockNotarisations(blockHash, notarisations)) continue; BOOST_FOREACH(Notarisation& nota, notarisations) { NotarisationData& data = nota.second; @@ -36,32 +40,24 @@ uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vect if (strcmp(data.symbol, symbol) == 0) { seenOwnNotarisations++; - printf("seenOwnNotarisations:%i\n", seenOwnNotarisations); if (seenOwnNotarisations == 2) goto end; if (seenOwnNotarisations == 1) - *assetChainHeight = data.height; // TODO: Needed? + destNotarisationTxid = nota.first; } - if (seenOwnNotarisations == 1) { + if (seenOwnNotarisations == 1) moms.push_back(data.MoM); - printf("Pushed a MoM@%i:%s\n", kmdHeight-i, data.MoM.GetHex().data()); - } } } end: - printf("GetProofRoot {\n"); - printf(" CC:%i S:%s H:%i\n", targetCCid, symbol, kmdHeight); - for (int i=0; iGetTxConfirmed(notarisationTxid, sourceNotarisation, blockIdx)) + if (eval->GetTxConfirmed(assetChainProof.first, sourceNotarisation, blockIdx)) kmdHeight = blockIdx.nHeight; - else if (eval->GetTxUnconfirmed(notarisationTxid, sourceNotarisation, hashBlock)) + else if (eval->GetTxUnconfirmed(assetChainProof.first, sourceNotarisation, hashBlock)) kmdHeight = chainActive.Tip()->nHeight; else throw std::runtime_error("Notarisation not found"); @@ -88,16 +84,14 @@ MerkleBranch GetCrossChainProof(uint256 txid, char* targetSymbol, // Get MoMs for kmd height and symbol std::vector moms; - int targetChainStartHeight; - printf("Getting Proof Root\n"); - uint256 MoMoM = GetProofRoot(targetSymbol, targetCCid, kmdHeight, moms, &targetChainStartHeight); + uint256 targetChainNotarisationTxid; + uint256 MoMoM = CalculateProofRoot(targetSymbol, targetCCid, kmdHeight, moms, targetChainNotarisationTxid); if (MoMoM.IsNull()) throw std::runtime_error("No MoMs found"); // Find index of source MoM in MoMoM int nIndex; for (nIndex=0; nIndex newBranch; + std::vector vBranch; { CBlock fakeBlock; for (int i=0; i &out) { /* - * Here we are given a notarisation txid, and a proof. - * We go from the notarisation to get the backnotarisation, and verify the proof - * against the MoMoM it contains. + * Here we are given a txid, and a proof. + * We go from the KMD notarisation txid to the backnotarisation, + * then jump to the next backnotarisation, which contains the corresponding MoMoM. */ + Notarisation bn; + if (!GetBackNotarisation(kmdNotarisationTxid, bn)) + return false; + + int npIdx; + struct notarized_checkpoint* np = komodo_npptr_for_height(bn.second.height, &npIdx); + if (!(np = komodo_npptr_at(npIdx+1))) + return false; + + return GetBackNotarisation(np->notarized_desttxid, out); + throw std::runtime_error("Can't get backnotarisation"); } - -struct notarized_checkpoint* komodo_npptr_for_height(int32_t height, int *idx); +struct notarized_checkpoint* komodo_npptr(int32_t height); int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip); @@ -155,7 +158,7 @@ int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_ * in: txid * out: pair */ -std::pair GetAssetchainProof(uint256 hash, int &npIdx) +TxProof GetAssetchainProof(uint256 hash) { int nIndex; CBlockIndex* blockIndex; @@ -169,11 +172,10 @@ std::pair GetAssetchainProof(uint256 hash, int &npIdx) throw std::runtime_error("cannot find transaction"); blockIndex = mapBlockIndex[blockHash]; - if (!(np = komodo_npptr_for_height(blockIndex->nHeight, &npIdx))) + if (!(np = komodo_npptr(blockIndex->nHeight))) throw std::runtime_error("notarisation not found"); // index of block in MoM leaves - printf("notarised at: %i\n", np->notarized_height); nIndex = np->notarized_height - blockIndex->nHeight; } diff --git a/src/crosschain.h b/src/crosschain.h index e490fbd0e..64bacb759 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -5,17 +5,18 @@ /* On assetchain */ -std::pair GetAssetchainProof(uint256 hash, int &npIdx); +TxProof GetAssetchainProof(uint256 hash); /* On KMD */ -uint256 GetProofRoot(char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, int* assetChainHeight); +uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, + std::vector &moms, uint256 &destNotarisationTxid); /* On KMD */ -MerkleBranch GetCrossChainProof(uint256 txid, char* targetSymbol, - uint32_t targetCCid, uint256 notarisationTxid, MerkleBranch assetChainProof); +TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid, + const TxProof assetChainProof); /* On assetchain */ -bool ValidateCrossChainProof(uint256 txid, int notarisationHeight, MerkleBranch proof); +bool GetNextBacknotarisation(uint256 txid, std::pair &bn); #endif /* CROSSCHAIN_H */ diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 3874ed7d6..e0c260916 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -13,7 +13,7 @@ * import. If it doesn't contain this it's invalid. The empty OP_RETURN will hang around * in the UTXO set and the transaction will be detected as a duplicate. */ -CTransaction MakeImportCoinTransaction(const MomoProof proof, const CTransaction burnTx, const std::vector payouts) +CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts) { std::vector payload = E_MARSHAL(ss << EVAL_IMPORTCOIN; ss << proof; ss << burnTx); @@ -30,7 +30,7 @@ CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector } -static bool UnmarshalImportTx(const CTransaction &importTx, MomoProof &proof, CTransaction &burnTx) +static bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx) { CScript scriptSig = importTx.vin[0].scriptSig; auto pc = scriptSig.begin(); @@ -51,7 +51,7 @@ static bool UnmarshalImportTx(const CTransaction &importTx, MomoProof &proof, CT */ CAmount GetCoinImportValue(const CTransaction &tx) { - MomoProof proof; + TxProof proof; CTransaction burnTx; if (UnmarshalImportTx(tx, proof, burnTx)) { return burnTx.vout.size() ? burnTx.vout[0].nValue : 0; diff --git a/src/importcoin.h b/src/importcoin.h index 6f712a1e9..f59851c44 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -8,22 +8,9 @@ #include -class MomoProof -{ -public: - MerkleBranch branch; - int notarisationHeight; - ADD_SERIALIZE_METHODS; - template - inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { - READWRITE(branch); - READWRITE(notarisationHeight); - } -}; - CAmount GetCoinImportValue(const CTransaction &tx); -CTransaction MakeImportCoinTransaction(const MomoProof proof, +CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts); CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector payouts); diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index b16968614..7ef5a0cf8 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -32,6 +32,18 @@ NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight) } +bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs) +{ + return pnotarisations->Read(blockHash, nibs); +} + + +bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n) +{ + return pnotarisations->Read(notarisationHash, n); +} + + /* * Write an index of KMD notarisation id -> backnotarisation */ @@ -39,9 +51,7 @@ void WriteBackNotarisations(NotarisationsInBlock notarisations) { BOOST_FOREACH(Notarisation &n, notarisations) { - if (n.second.IsBackNotarisation) { + if (n.second.IsBackNotarisation) pnotarisations->Write(n.second.txHash, n); - printf("WriteBackNotarisations {\n m3:%s\n}\n", n.second.MoMoM.GetHex().data()); - } } } diff --git a/src/notarisationdb.h b/src/notarisationdb.h index bd2c15685..0e3d48c00 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -15,12 +15,12 @@ public: extern NotarisationDB *pnotarisations; - typedef std::pair Notarisation; typedef std::vector NotarisationsInBlock; NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight); - +bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs); +bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); void WriteBackNotarisations(NotarisationsInBlock notarisations); #endif /* NOTARISATIONDB_H */ diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 99584c7bb..7f191a2b3 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -761,10 +761,6 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160, //uint32_t komodo_interest_args(int32_t *txheightp,uint32_t *tiptimep,uint64_t *valuep,uint256 hash,int32_t n); int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width); int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen); -int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip); -int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height); -struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi); -uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); UniValue kvsearch(const UniValue& params, bool fHelp) { @@ -801,170 +797,6 @@ UniValue kvsearch(const UniValue& params, bool fHelp) return ret; } -UniValue allMoMs(const UniValue& params, bool fHelp) -{ - struct komodo_ccdata_entry *allMoMs; uint256 MoMoM; int32_t num,i,kmdstarti,kmdendi; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); - if ( fHelp || params.size() != 2 ) - throw runtime_error("allMoMs kmdstarti kmdendi\n"); - LOCK(cs_main); - kmdstarti = atoi(params[0].get_str().c_str()); - kmdendi = atoi(params[1].get_str().c_str()); - ret.push_back(Pair("kmdstarti",kmdstarti)); - ret.push_back(Pair("kmdendi",kmdendi)); - if ( (allMoMs= komodo_allMoMs(&num,&MoMoM,kmdstarti,kmdendi)) != 0 ) - { - for (i=0; i= height ) - throw runtime_error("calc_MoM illegal height or MoMdepth\n"); - //fprintf(stderr,"height_MoM height.%d\n",height); - MoM = komodo_calcMoM(height,MoMdepth); - ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("height",height)); - ret.push_back(Pair("MoMdepth",MoMdepth)); - ret.push_back(Pair("MoM",MoM.GetHex())); - return ret; -} - -UniValue height_MoM(const UniValue& params, bool fHelp) -{ - int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); - if ( fHelp || params.size() != 1 ) - throw runtime_error("height_MoM height\n"); - LOCK(cs_main); - height = atoi(params[0].get_str().c_str()); - if ( height <= 0 ) - { - if ( chainActive.Tip() == 0 ) - { - ret.push_back(Pair("error",(char *)"no active chain yet")); - return(ret); - } - height = chainActive.Tip()->nHeight; - } - //fprintf(stderr,"height_MoM height.%d\n",height); - depth = komodo_MoM(¬arized_height,&MoM,&kmdtxid,height,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi); - ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("height",height)); - ret.push_back(Pair("timestamp",(uint64_t)timestamp)); - if ( depth > 0 ) - { - ret.push_back(Pair("depth",depth)); - ret.push_back(Pair("notarized_height",notarized_height)); - ret.push_back(Pair("MoM",MoM.GetHex())); - ret.push_back(Pair("kmdtxid",kmdtxid.GetHex())); - if ( ASSETCHAINS_SYMBOL[0] != 0 ) - { - ret.push_back(Pair("MoMoM",MoMoM.GetHex())); - ret.push_back(Pair("MoMoMoffset",MoMoMoffset)); - ret.push_back(Pair("MoMoMdepth",MoMoMdepth)); - ret.push_back(Pair("kmdstarti",kmdstarti)); - ret.push_back(Pair("kmdendi",kmdendi)); - } - } else ret.push_back(Pair("error",(char *)"no MoM for height")); - - return ret; -} - -UniValue txMoMproof(const UniValue& params, bool fHelp) -{ - uint256 hash, notarisationHash, MoM,MoMoM; int32_t notarisedHeight, depth; CBlockIndex* blockIndex; - std::vector branch; - int nIndex,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; - - // parse params and get notarisation data for tx - if ( fHelp || params.size() != 1) - throw runtime_error("txMoMproof needs a txid"); - - hash = uint256S(params[0].get_str()); - - int npIdx; - std::vector proofData = E_MARSHAL(ss << GetAssetchainProof(hash, npIdx)); - return HexStr(proofData); -} - - -UniValue getproofroot(const UniValue& params, bool fHelp) -{ - std::string symbol; - int kmdHeight; - - - // parse params and get notarisation data for tx - if ( fHelp || params.size() != 2) - throw runtime_error("getproofroot needs a symbol and a kmdHeight"); - symbol = params[0].get_str(); - kmdHeight = atoi(params[0].get_str().c_str()); - if (kmdHeight <= 0) - throw runtime_error("Invalid kmdHeight"); - - UniValue ret(UniValue::VOBJ); - return ret; -} - - UniValue minerids(const UniValue& params, bool fHelp) { uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); uint8_t minerids[2000],pubkeys[65][33]; int32_t i,j,n,numnotaries,tally[129]; diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index 5b3f0c9eb..e421feb4c 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -136,7 +136,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "notaries", 2 }, { "height_MoM", 1 }, { "MoMoMdata", 3 }, - { "allMoMs", 2 }, { "txMoMproof", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp new file mode 100644 index 000000000..a7bb49d2e --- /dev/null +++ b/src/rpccrosschain.cpp @@ -0,0 +1,158 @@ +#include "amount.h" +#include "chain.h" +#include "chainparams.h" +#include "checkpoints.h" +#include "crosschain.h" +#include "base58.h" +#include "consensus/validation.h" +#include "cc/eval.h" +#include "main.h" +#include "primitives/transaction.h" +#include "rpcserver.h" +#include "sync.h" +#include "util.h" +#include "script/script.h" +#include "script/script_error.h" +#include "script/sign.h" +#include "script/standard.h" + +#include + +#include + +#include + +using namespace std; + +int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip); +int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height); +struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi); +uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); + + +UniValue assetchainproof(const UniValue& params, bool fHelp) +{ + uint256 hash; + + // parse params and get notarisation data for tx + if ( fHelp || params.size() != 1) + throw runtime_error("assetchainproof needs a txid"); + + hash = uint256S(params[0].get_str()); + + auto proof = GetAssetchainProof(hash); + auto proofData = E_MARSHAL(ss << proof); + return HexStr(proofData); +} + + +UniValue crosschainproof(const UniValue& params, bool fHelp) +{ + + +} + + +UniValue getproofroot(const UniValue& params, bool fHelp) +{ + std::string symbol; + int kmdHeight; + + // parse params and get notarisation data for tx + if ( fHelp || params.size() != 2) + throw runtime_error("getproofroot needs a symbol and a kmdHeight"); + symbol = params[0].get_str(); + kmdHeight = atoi(params[0].get_str().c_str()); + if (kmdHeight <= 0) + throw runtime_error("Invalid kmdHeight"); + + UniValue ret(UniValue::VOBJ); + return ret; +} + + +UniValue height_MoM(const UniValue& params, bool fHelp) +{ + int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); + if ( fHelp || params.size() != 1 ) + throw runtime_error("height_MoM height\n"); + LOCK(cs_main); + height = atoi(params[0].get_str().c_str()); + if ( height <= 0 ) + { + if ( chainActive.Tip() == 0 ) + { + ret.push_back(Pair("error",(char *)"no active chain yet")); + return(ret); + } + height = chainActive.Tip()->nHeight; + } + //fprintf(stderr,"height_MoM height.%d\n",height); + depth = komodo_MoM(¬arized_height,&MoM,&kmdtxid,height,&MoMoM,&MoMoMoffset,&MoMoMdepth,&kmdstarti,&kmdendi); + ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); + ret.push_back(Pair("height",height)); + ret.push_back(Pair("timestamp",(uint64_t)timestamp)); + if ( depth > 0 ) + { + ret.push_back(Pair("depth",depth)); + ret.push_back(Pair("notarized_height",notarized_height)); + ret.push_back(Pair("MoM",MoM.GetHex())); + ret.push_back(Pair("kmdtxid",kmdtxid.GetHex())); + if ( ASSETCHAINS_SYMBOL[0] != 0 ) + { + ret.push_back(Pair("MoMoM",MoMoM.GetHex())); + ret.push_back(Pair("MoMoMoffset",MoMoMoffset)); + ret.push_back(Pair("MoMoMdepth",MoMoMdepth)); + ret.push_back(Pair("kmdstarti",kmdstarti)); + ret.push_back(Pair("kmdendi",kmdendi)); + } + } else ret.push_back(Pair("error",(char *)"no MoM for height")); + + return ret; +} + +UniValue MoMoMdata(const UniValue& params, bool fHelp) +{ + if ( fHelp || params.size() != 3 ) + throw runtime_error("MoMoMdata symbol kmdheight ccid\n"); + UniValue ret(UniValue::VOBJ); + char* symbol = (char *)params[0].get_str().c_str(); + int kmdheight = atoi(params[1].get_str().c_str()); + int ccid = atoi(params[2].get_str().c_str()); + ret.push_back(Pair("coin",symbol)); + ret.push_back(Pair("kmdheight",kmdheight)); + ret.push_back(Pair("ccid", ccid)); + + uint256 destNotarisationTxid; + std::vector moms; + uint256 MoMoM = CalculateProofRoot(symbol, ccid, kmdheight, moms, destNotarisationTxid); + + UniValue valMoms(UniValue::VARR); + for (int i=0; i= height ) + throw runtime_error("calc_MoM illegal height or MoMdepth\n"); + //fprintf(stderr,"height_MoM height.%d\n",height); + MoM = komodo_calcMoM(height,MoMdepth); + ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); + ret.push_back(Pair("height",height)); + ret.push_back(Pair("MoMdepth",MoMdepth)); + ret.push_back(Pair("MoM",MoM.GetHex())); + return ret; +} diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 4eb2270fb..cd579c83c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -302,15 +302,17 @@ static const CRPCCommand vRPCCommands[] = { "blockchain", "paxpending", &paxpending, true }, { "blockchain", "paxprices", &paxprices, true }, { "blockchain", "notaries", ¬aries, true }, - { "blockchain", "allMoMs", &allMoMs, true }, - { "blockchain", "MoMoMdata", &MoMoMdata, true }, - { "blockchain", "calc_MoM", &calc_MoM, true }, - { "blockchain", "height_MoM", &height_MoM, true }, - { "blockchain", "txMoMproof", &txMoMproof, true }, { "blockchain", "minerids", &minerids, true }, { "blockchain", "kvsearch", &kvsearch, true }, { "blockchain", "kvupdate", &kvupdate, true }, + /* Cross chain utilities */ + { "crosschain", "MoMoMdata", &MoMoMdata, true }, + { "crosschain", "calc_MoM", &calc_MoM, true }, + { "crosschain", "height_MoM", &height_MoM, true }, + { "crosschain", "assetchainproof", &assetchainproof, true }, + { "crosschain", "crosschainproof", &crosschainproof, true }, + /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, { "mining", "getmininginfo", &getmininginfo, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index ce412cdb9..7d7ef5d7e 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -312,11 +312,11 @@ extern UniValue z_validateaddress(const UniValue& params, bool fHelp); // in rpc extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp); // in rpcdisclosure.cpp extern UniValue z_validatepaymentdisclosure(const UniValue ¶ms, bool fHelp); // in rpcdisclosure.cpp -extern UniValue allMoMs(const UniValue& params, bool fHelp); extern UniValue MoMoMdata(const UniValue& params, bool fHelp); extern UniValue calc_MoM(const UniValue& params, bool fHelp); extern UniValue height_MoM(const UniValue& params, bool fHelp); -extern UniValue txMoMproof(const UniValue& params, bool fHelp); +extern UniValue assetchainproof(const UniValue& params, bool fHelp); +extern UniValue crosschainproof(const UniValue& params, bool fHelp); extern UniValue notaries(const UniValue& params, bool fHelp); extern UniValue minerids(const UniValue& params, bool fHelp); extern UniValue kvsearch(const UniValue& params, bool fHelp); diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index fe2f3ce96..81ccd71d7 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -28,7 +28,7 @@ class TestCoinImport : public ::testing::Test, public Eval { public: CMutableTransaction burnTx; std::vector payouts; - MomoProof proof; + TxProof proof; uint256 MoMoM; CMutableTransaction importTx; uint32_t chainId = 2; diff --git a/src/test-komodo/test_crosschain.cpp b/src/test-komodo/test_crosschain.cpp index ebf52fa13..6ff261247 100644 --- a/src/test-komodo/test_crosschain.cpp +++ b/src/test-komodo/test_crosschain.cpp @@ -28,7 +28,6 @@ extern uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); -extern struct notarized_checkpoint *komodo_npptr_at(int idx); /* @@ -109,8 +108,6 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) mtx.vin[0].scriptSig << getSig(mtx, inputTx.vout[0].scriptPubKey); acceptTxFail(CTransaction(mtx)); - printf("accept %snotarisation: %s\n", data.IsBackNotarisation ? "back" : "", - mtx.GetHash().GetHex().data()); return mtx.GetHash(); }; @@ -139,34 +136,13 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) * Generate proof */ uint256 txid = blocks[7].vtx[0].GetHash(); - int npIdx; - std::pair proof = GetAssetchainProof(txid, npIdx); + TxProof proof = GetAssetchainProof(txid); SendIPC(E_MARSHAL(ss << txid; ss << proof)); + E_UNMARSHAL(RecvIPC(), ss >> proof); - /* - * Test proof - */ - std::pair ccProof; - E_UNMARSHAL(RecvIPC(), ss >> ccProof); - - // Now we have the branch with the hash of the notarisation on KMD - // What we'd like is the notarised height on PIZZA so we can go forward - // to the next backnotarisation, and then to the next, to get the M3. - uint256 result = ccProof.second.Exec(txid); - printf("result m3: %s\n", result.GetHex().data()); - struct notarized_checkpoint* np = komodo_npptr_at(npIdx+1); - std::pair b; - pnotarisations->Read(np->notarized_desttxid, b); - printf("m3@1: %s\n", b.second.MoMoM.GetHex().data()); - - { - printf("RunTestAssetChain.test {\n txid: %s\n momom: %s\n", txid.GetHex().data(), b.second.MoMoM.GetHex().data()); - printf(" idx: %i\n", ccProof.second.nIndex); - for (int i=0; i bn; + if (!GetNextBacknotarisation(proof.first, bn)) return 1; + return proof.second.Exec(txid) == bn.second.MoMoM ? 0 : 1; }; auto RunTestKmd = [&] () @@ -186,10 +162,9 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) n.txHash = RecordNotarisation(blocks[height].vtx[0], n); { std::vector moms; - int assetChainHeight; - n.MoMoM = GetProofRoot(n.symbol, 2, height, moms, &assetChainHeight); + uint256 destNotarisationTxid; + n.MoMoM = CalculateProofRoot(n.symbol, 2, height, moms, destNotarisationTxid); } - printf("RunTestKmd {\n kmdnotid:%s\n momom:%s\n}\n", n.txHash.GetHex().data(), n.MoMoM.GetHex().data()); n.IsBackNotarisation = 1; SendIPC(E_MARSHAL(ss << n)); } @@ -197,11 +172,11 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) /* * Extend proof */ - std::pair proof; + TxProof proof; uint256 txid; // Extend proof to MoMoM assert(E_UNMARSHAL(RecvIPC(), ss >> txid; ss >> proof)); - proof.second = GetCrossChainProof(txid, (char*)"PIZZA", 2, proof.first, proof.second); + proof = GetCrossChainProof(txid, (char*)"PIZZA", 2, proof); SendIPC(E_MARSHAL(ss << proof)); }; @@ -217,20 +192,12 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) else { assert(0 == zmq_bind(socket, endpoint)); RunTestKmd(); - int returnStatus; + int returnStatus; waitpid(childPid, &returnStatus, 0); unlink("tmpKomodoTestCrossChainSock"); ASSERT_EQ(0, returnStatus); } - - /* - * We can now prove a tx from A on A, via a merkle root backpropagated from KMD. - * - * The transaction that we'll try to prove is the coinbase from the 3rd block. - * We should be able to start with only that transaction ID, and generate a merkle - * proof. - */ } diff --git a/src/test-komodo/testutils.cpp b/src/test-komodo/testutils.cpp index a6a2b8def..e8b57b6b9 100644 --- a/src/test-komodo/testutils.cpp +++ b/src/test-komodo/testutils.cpp @@ -72,13 +72,9 @@ void generateBlock(CBlock *block) SetMockTime(nMockTime+=100); // CreateNewBlock can fail if not enough time passes - char symbolPrefix = ASSETCHAINS_SYMBOL[0]; - //ASSETCHAINS_SYMBOL[0] = 0; // generate block fails otherwise - try { UniValue out = generate(params, false); blockId.SetHex(out[0].getValStr()); - ASSETCHAINS_SYMBOL[0] = symbolPrefix; if (block) ASSERT_TRUE(ReadBlockFromDisk(*block, mapBlockIndex[blockId], false)); } catch (const UniValue& e) { FAIL() << "failed to create block: " << e.write().data(); From 833115ea41708022e7caf9749a47ceb58d30f161 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sat, 19 May 2018 02:27:58 +0200 Subject: [PATCH 0065/1123] add DSEC --- src/ac/dsec | 2 ++ src/assetchains | 1 + src/assetchains.old | 1 + src/assetchains_stop | 1 + src/dpowassets | 1 + src/fiat-cli | 1 + src/fiat/dsec | 2 ++ 7 files changed, 9 insertions(+) create mode 100644 src/ac/dsec create mode 100644 src/fiat/dsec diff --git a/src/ac/dsec b/src/ac/dsec new file mode 100644 index 000000000..a050ca94f --- /dev/null +++ b/src/ac/dsec @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=DSEC $1 $2 $3 $4 $5 $6 diff --git a/src/assetchains b/src/assetchains index 2a883726d..a8ab28155 100755 --- a/src/assetchains +++ b/src/assetchains @@ -54,3 +54,4 @@ komodo_asset OOT 216000000 komodo_asset BNTN 500000000 komodo_asset CHAIN 999999 komodo_asset PRLPAY 500000000 +komodo_asset DSEC 7000000 diff --git a/src/assetchains.old b/src/assetchains.old index d41b64766..4e56fe639 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -31,6 +31,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=BNTN -ac_supply=500000000 -addnode=94.130.169.205 & ./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 & ./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 & +./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & #sleep $delay #./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & diff --git a/src/assetchains_stop b/src/assetchains_stop index ba314e1c9..e55231b1a 100644 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -37,3 +37,4 @@ komodo_stop OOT komodo_stop BNTN komodo_stop CHAIN komodo_stop PRLPAY +komodo_stop DSEC diff --git a/src/dpowassets b/src/dpowassets index 5076a385c..537b116e4 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -30,6 +30,7 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" #curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":10,\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index 76f219c83..463906cf2 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -27,3 +27,4 @@ echo oot; fiat/oot $1 $2 $3 $4 echo bntn; fiat/bntn $1 $2 $3 $4 echo chain; fiat/chain $1 $2 $3 $4 echo prlpay; fiat/prlpay $1 $2 $3 $4 +echo dsec; fiat/dsec $1 $2 $3 $4 diff --git a/src/fiat/dsec b/src/fiat/dsec new file mode 100644 index 000000000..a050ca94f --- /dev/null +++ b/src/fiat/dsec @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=DSEC $1 $2 $3 $4 $5 $6 From db83a2c0c3f6dc3c7050677ff86f76889f30e605 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 19 May 2018 00:56:25 -0700 Subject: [PATCH 0066/1123] Try Hush regtest params This fails with: $ ./komodod -regtest Assertion failed: (consensus.hashGenesisBlock == uint256S("0x0379ff1530af893f2f2e61146db6e900dd828dc8254215b9de23df2dba06664f")), function CRegTestParams, file chainparams.cpp, line 540. Abort trap: 6 (core dumped) From https://github.com/MyHush/hush/pull/106/commits/1d8c55ecc297e9d6574d9eeb55d7eebb9546838b --- src/chainparams.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index df258d782..1482189d5 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -532,11 +532,13 @@ public: BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); nEquihashN = N; nEquihashK = K; - genesis.nTime = 1296688602; + genesis.nTime = 1519568466; genesis.nBits = KOMODO_MINDIFF_NBITS; - genesis.nNonce = uint256S("0x0000000000000000000000000000000000000000000000000000000000000021"); - genesis.nSolution = ParseHex("0f2a976db4c4263da10fd5d38eb1790469cf19bdb4bf93450e09a72fdff17a3454326399"); + genesis.nNonce = uint256S("0x0000000000000000000000000000000000000000000000000000000000000016"); + genesis.nSolution = ParseHex("0d1d1ef025037da781252f695ff279c12d492c5ed53e565c8ecdc044ede53cea96cff5fc"); consensus.hashGenesisBlock = genesis.GetHash(); + assert(consensus.hashGenesisBlock == uint256S("0x0379ff1530af893f2f2e61146db6e900dd828dc8254215b9de23df2dba06664f")); + nDefaultPort = 17779; nPruneAfterHeight = 1000; From a34f39e9b2e5ab759a520c441ecc3c6fe2b91e29 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 May 2018 15:49:34 +0300 Subject: [PATCH 0067/1123] Dont overwrite sp->MoM with null --- src/komodo.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index ec1bc8013..9af2eed71 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -695,8 +695,11 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; sp->NOTARIZED_DESTTXID = desttxid; - sp->MoM = MoM; - sp->MoMdepth = MoMdepth; + if ( bits256_nonz(MoM) != 0 && MoMdepth > 0 ) + { + sp->MoM = MoM; + sp->MoMdepth = MoMdepth; + } komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); From 1b15c32d18fadeb0f92c2fcf3388f8e35b2e1be5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 May 2018 16:41:38 +0300 Subject: [PATCH 0068/1123] syntax --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 9af2eed71..36c7c2ef3 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -695,7 +695,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; sp->NOTARIZED_DESTTXID = desttxid; - if ( bits256_nonz(MoM) != 0 && MoMdepth > 0 ) + if ( MoM != zero && MoMdepth > 0 ) { sp->MoM = MoM; sp->MoMdepth = MoMdepth; From cadcb27a614470a0e5d92ebf49bbd424f32dd989 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Sat, 19 May 2018 16:50:17 +0300 Subject: [PATCH 0069/1123] Chmod fix --- src/ac/dsec | 0 src/assetchains_stop | 0 src/fiat/dsec | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/ac/dsec mode change 100644 => 100755 src/assetchains_stop mode change 100644 => 100755 src/fiat/dsec diff --git a/src/ac/dsec b/src/ac/dsec old mode 100644 new mode 100755 diff --git a/src/assetchains_stop b/src/assetchains_stop old mode 100644 new mode 100755 diff --git a/src/fiat/dsec b/src/fiat/dsec old mode 100644 new mode 100755 From b860fdec0d479784b095032a3b7aa9a5bfe13800 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 19 May 2018 18:48:33 +0300 Subject: [PATCH 0070/1123] Enable GAME --- src/dpowassets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpowassets b/src/dpowassets index 537b116e4..f148bda05 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -33,4 +33,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" -#curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":10,\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":10,\"pubkey\":\"$pubkey\"}" From b78c39beb269037b923de33314b86673b8068c95 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 19 May 2018 08:51:45 -0700 Subject: [PATCH 0071/1123] Convert to using CreateGenesisBlock() like Zcash upstream --- src/chainparams.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 1482189d5..0c45e1961 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -532,12 +532,15 @@ public: BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); nEquihashN = N; nEquihashK = K; - genesis.nTime = 1519568466; - genesis.nBits = KOMODO_MINDIFF_NBITS; - genesis.nNonce = uint256S("0x0000000000000000000000000000000000000000000000000000000000000016"); - genesis.nSolution = ParseHex("0d1d1ef025037da781252f695ff279c12d492c5ed53e565c8ecdc044ede53cea96cff5fc"); + genesis = CreateGenesisBlock( + 1519568466, + uint256S("0x0000000000000000000000000000000000000000000000000000000000000016"), + ParseHex("0d1d1ef025037da781252f695ff279c12d492c5ed53e565c8ecdc044ede53cea96cff5fc"), + KOMODO_MINDIFF_NBITS, 4, 0); + consensus.hashGenesisBlock = genesis.GetHash(); assert(consensus.hashGenesisBlock == uint256S("0x0379ff1530af893f2f2e61146db6e900dd828dc8254215b9de23df2dba06664f")); + //TODO: assert merkle root nDefaultPort = 17779; nPruneAfterHeight = 1000; From b6ef9c089a9b8e3635e4ae9659149bc5d8d58084 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sat, 19 May 2018 12:56:48 -0300 Subject: [PATCH 0072/1123] fix broken test case --- src/test-komodo/test_coinimport.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index 81ccd71d7..c1db6cc78 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -43,13 +43,14 @@ public: uint32_t GetCurrentLedgerID() const { return chainId; } - bool GetNotarisationData(int notarisationHeight, NotarisationData &data, bool verifyCanonical) const + bool GetProofRoot(uint256 hash, uint256 &momom) const { if (MoMoM.IsNull()) return false; - data.MoMoM = MoMoM; + momom = MoMoM; return true; } + protected: static void SetUpTestCase() { setupChain(); } virtual void SetUp() { From 373afcb4990ea009acbde64b85971f0b83c95c77 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 19 May 2018 10:05:53 -0700 Subject: [PATCH 0073/1123] Use correct regtest genesis block hash komodod now starts up and dies with InvalidChainFound, I think due to checkpoints: call komodo_args.(./src/komodod) NOTARY_PUBKEY.() initialized at 1526749522 finished loading blocks Assertion failed: (tip), function InvalidChainFound, file main.cpp, line 1942. --- src/chainparams.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 0c45e1961..7fd9ba9ad 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -532,14 +532,17 @@ public: BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); nEquihashN = N; nEquihashK = K; + // #define KOMODO_MINDIFF_NBITS 0x200f0f0f genesis = CreateGenesisBlock( - 1519568466, - uint256S("0x0000000000000000000000000000000000000000000000000000000000000016"), - ParseHex("0d1d1ef025037da781252f695ff279c12d492c5ed53e565c8ecdc044ede53cea96cff5fc"), + 1296688602, + uint256S("0x000000000000000000000000000000000000000000000000000000000000002f"), + ParseHex("1d64134e87a42ad5f12196da1452cb56b1f22a438fabd776ee8fca71ce1fb9b7fcc6f5ec"), KOMODO_MINDIFF_NBITS, 4, 0); consensus.hashGenesisBlock = genesis.GetHash(); - assert(consensus.hashGenesisBlock == uint256S("0x0379ff1530af893f2f2e61146db6e900dd828dc8254215b9de23df2dba06664f")); + printf("genblock hash=%s\n", consensus.hashGenesisBlock.ToString().c_str() ); + assert(consensus.hashGenesisBlock == uint256S("0xe76fb931218cd30c8bc6e6dfe26925eeff7611c7e6957466ea0d38cde03f0008")); + //assert(consensus.hashGenesisBlock == uint256S("0x02dd14e268a4b7a7e6758f14e718abf82cc6649e53bf00bace3059a74d66ec79")); //TODO: assert merkle root nDefaultPort = 17779; From 16df92af5983757f6de61e5cbc7f59e28e9b98bc Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 19 May 2018 10:45:12 -0700 Subject: [PATCH 0074/1123] Use latest Zcash regtest params, could not use the same as Hush because KMD has merged in latest consensus changes from ZEC upstream --- src/chainparams.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 7fd9ba9ad..43acd0bb2 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -532,18 +532,15 @@ public: BOOST_STATIC_ASSERT(equihash_parameters_acceptable(N, K)); nEquihashN = N; nEquihashK = K; - // #define KOMODO_MINDIFF_NBITS 0x200f0f0f + genesis = CreateGenesisBlock( 1296688602, - uint256S("0x000000000000000000000000000000000000000000000000000000000000002f"), - ParseHex("1d64134e87a42ad5f12196da1452cb56b1f22a438fabd776ee8fca71ce1fb9b7fcc6f5ec"), - KOMODO_MINDIFF_NBITS, 4, 0); - + uint256S("0x0000000000000000000000000000000000000000000000000000000000000009"), + ParseHex("01936b7db1eb4ac39f151b8704642d0a8bda13ec547d54cd5e43ba142fc6d8877cab07b3"), + 0x200f0f0f, 4, 0); consensus.hashGenesisBlock = genesis.GetHash(); - printf("genblock hash=%s\n", consensus.hashGenesisBlock.ToString().c_str() ); - assert(consensus.hashGenesisBlock == uint256S("0xe76fb931218cd30c8bc6e6dfe26925eeff7611c7e6957466ea0d38cde03f0008")); - //assert(consensus.hashGenesisBlock == uint256S("0x02dd14e268a4b7a7e6758f14e718abf82cc6649e53bf00bace3059a74d66ec79")); - //TODO: assert merkle root + assert(consensus.hashGenesisBlock == uint256S("0x029f11d80ef9765602235e1bc9727e3eb6ba20839319f761fee920d63401e327")); + assert(genesis.hashMerkleRoot == uint256S("0xc4eaa58879081de3c24a7b117ed2b28300e7ec4c4c1dff1d3f1268b7857a4ddb")); nDefaultPort = 17779; nPruneAfterHeight = 1000; From 8cf70067ac76378278eaab6a35b506c8e228edc1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 19 May 2018 10:49:01 -0700 Subject: [PATCH 0075/1123] Use the KOMODO_MINDIFF_NBITS constant --- src/chainparams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 43acd0bb2..d78e1351b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -537,7 +537,7 @@ public: 1296688602, uint256S("0x0000000000000000000000000000000000000000000000000000000000000009"), ParseHex("01936b7db1eb4ac39f151b8704642d0a8bda13ec547d54cd5e43ba142fc6d8877cab07b3"), - 0x200f0f0f, 4, 0); + KOMODO_MINDIFF_NBITS, 4, 0); consensus.hashGenesisBlock = genesis.GetHash(); assert(consensus.hashGenesisBlock == uint256S("0x029f11d80ef9765602235e1bc9727e3eb6ba20839319f761fee920d63401e327")); assert(genesis.hashMerkleRoot == uint256S("0xc4eaa58879081de3c24a7b117ed2b28300e7ec4c4c1dff1d3f1268b7857a4ddb")); From 137e08d7298750f9316af7c6e09ddfc5b00d4877 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 20 May 2018 00:12:37 +0300 Subject: [PATCH 0076/1123] -print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fa2937005..e50d01f68 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4502,7 +4502,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) script = (uint8_t *)out.tx->vout[out.i].scriptPubKey.data(); if ( out.tx->vout[out.i].scriptPubKey.size() != 35 || script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(notarypub33,script+1,33) != 0 ) { - fprintf(stderr,"scriptsize.%d [0] %02x\n",(int32_t)out.tx->vout[out.i].scriptPubKey.size(),script[0]); + //fprintf(stderr,"scriptsize.%d [0] %02x\n",(int32_t)out.tx->vout[out.i].scriptPubKey.size(),script[0]); continue; } utxovalue = (uint64_t)nValue; From 0df96a2f06e48a3f8ad27183d3e2173fc7635303 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 20 May 2018 01:27:31 -0300 Subject: [PATCH 0077/1123] fix all tests --- src/cc/eval.cpp | 19 +++-- src/cc/eval.h | 3 +- src/cc/import.cpp | 27 +++--- src/importcoin.cpp | 53 +++++++----- src/importcoin.h | 9 +- src/rpccrosschain.cpp | 125 ++++++++++++++++++++++++++++ src/test-komodo/test_coinimport.cpp | 33 +++++--- src/test-komodo/testutils.cpp | 3 + 8 files changed, 215 insertions(+), 57 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 8ed29da9d..edd5c6850 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -147,12 +147,6 @@ bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t t } -uint32_t Eval::GetCurrentLedgerID() const -{ - return -1; // TODO -} - - /* * Get MoM from a notarisation tx hash (on KMD) */ @@ -171,6 +165,19 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data) */ bool Eval::GetProofRoot(uint256 kmdNotarisationHash, uint256 &momom) const { + return false; // TODO +} + + +uint32_t Eval::GetAssetchainsCC() const +{ + return ASSETCHAINS_CC; +} + + +std::string Eval::GetAssetchainsSymbol() const +{ + return std::string(ASSETCHAINS_SYMBOL); } diff --git a/src/cc/eval.h b/src/cc/eval.h index 2a30bba90..aacec3847 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -74,7 +74,8 @@ public: virtual bool GetNotarisationData(uint256 notarisationHash, NotarisationData &data) const; virtual bool GetProofRoot(uint256 kmdNotarisationHash, uint256 &momom) const; virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const; - virtual uint32_t GetCurrentLedgerID() const; + virtual uint32_t GetAssetchainsCC() const; + virtual std::string GetAssetchainsSymbol() const; }; diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 202d75468..506b2a989 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -12,30 +12,31 @@ */ bool Eval::ImportCoin(const std::vector params, const CTransaction &importTx, unsigned int nIn) { - if (importTx.vout.size() == 0) return Invalid("no-vouts"); + if (importTx.vout.size() < 2) + return Invalid("too-few-vouts"); // params TxProof proof; CTransaction burnTx; - if (!E_UNMARSHAL(params, ss >> proof; ss >> burnTx)) + std::vector payouts; + + if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) return Invalid("invalid-params"); // Control all aspects of this transaction - // It must not be at all malleable - if (MakeImportCoinTransaction(proof, burnTx, importTx.vout).GetHash() != importTx.GetHash()) + // It should not be at all malleable + if (MakeImportCoinTransaction(proof, burnTx, payouts).GetHash() != importTx.GetHash()) return Invalid("non-canonical"); // burn params - uint32_t chain; // todo + uint32_t targetCcid; + std::string targetSymbol; uint256 payoutsHash; - std::vector burnOpret; - if (burnTx.vout.size() == 0) return Invalid("invalid-burn-outputs"); - GetOpReturnData(burnTx.vout[0].scriptPubKey, burnOpret); - if (!E_UNMARSHAL(burnOpret, ss >> VARINT(chain); ss >> payoutsHash)) - return Invalid("invalid-burn-params"); - // check chain - if (chain != GetCurrentLedgerID()) + if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCcid, payoutsHash)) + return Invalid("invalid-burn-tx"); + + if (targetCcid != GetAssetchainsCC() || targetSymbol != GetAssetchainsSymbol()) return Invalid("importcoin-wrong-chain"); // check burn amount @@ -51,7 +52,7 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp } // Check burntx shows correct outputs hash - if (payoutsHash != SerializeHash(importTx.vout)) + if (payoutsHash != SerializeHash(payouts)) return Invalid("wrong-payouts"); // Check proof confirms existance of burnTx diff --git a/src/importcoin.cpp b/src/importcoin.cpp index e0c260916..bbada7e99 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -6,42 +6,48 @@ #include "primitives/transaction.h" -/* - * Generate ImportCoin transaction. - * - * Contains an empty OP_RETURN as first output; this is critical for preventing a double - * import. If it doesn't contain this it's invalid. The empty OP_RETURN will hang around - * in the UTXO set and the transaction will be detected as a duplicate. - */ CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts) { - std::vector payload = - E_MARSHAL(ss << EVAL_IMPORTCOIN; ss << proof; ss << burnTx); + std::vector payload = E_MARSHAL(ss << EVAL_IMPORTCOIN); CMutableTransaction mtx; mtx.vin.push_back(CTxIn(COutPoint(burnTx.GetHash(), 10e8), CScript() << payload)); mtx.vout = payouts; + auto importData = E_MARSHAL(ss << proof; ss << burnTx); + mtx.vout.insert(mtx.vout.begin(), CTxOut(0, CScript() << OP_RETURN << importData)); return CTransaction(mtx); } -CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector payouts) + +CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts) { - std::vector opret = E_MARSHAL(ss << VARINT(targetChain); ss << SerializeHash(payouts)); + std::vector opret = E_MARSHAL(ss << VARINT(targetCCid); + ss << targetSymbol; + ss << SerializeHash(payouts)); return CTxOut(value, CScript() << OP_RETURN << opret); } -static bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx) +bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx, + std::vector &payouts) { - CScript scriptSig = importTx.vin[0].scriptSig; - auto pc = scriptSig.begin(); - opcodetype opcode; - std::vector evalScript; - int code; - bool out = false; - if (scriptSig.GetOp(pc, opcode, evalScript)) - if (pc == scriptSig.end()) - out = E_UNMARSHAL(evalScript, ss >> VARINT(code); ss >> proof; ss >> burnTx); - return code == EVAL_IMPORTCOIN && out; + std::vector vData; + GetOpReturnData(importTx.vout[0].scriptPubKey, vData); + if (importTx.vout.size() < 1) return false; + payouts = std::vector(importTx.vout.begin()+1, importTx.vout.end()); + return importTx.vin.size() == 1 && + importTx.vin[0].scriptSig == (CScript() << E_MARSHAL(ss << EVAL_IMPORTCOIN)) && + E_UNMARSHAL(vData, ss >> proof; ss >> burnTx); +} + + +bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash) +{ + std::vector burnOpret; + if (burnTx.vout.size() == 0) return false; + GetOpReturnData(burnTx.vout[0].scriptPubKey, burnOpret); + return E_UNMARSHAL(burnOpret, ss >> VARINT(*targetCCid); + ss >> targetSymbol; + ss >> payoutsHash); } @@ -53,7 +59,8 @@ CAmount GetCoinImportValue(const CTransaction &tx) { TxProof proof; CTransaction burnTx; - if (UnmarshalImportTx(tx, proof, burnTx)) { + std::vector payouts; + if (UnmarshalImportTx(tx, proof, burnTx, payouts)) { return burnTx.vout.size() ? burnTx.vout[0].nValue : 0; } return 0; diff --git a/src/importcoin.h b/src/importcoin.h index f59851c44..8e43f9376 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -13,10 +13,13 @@ CAmount GetCoinImportValue(const CTransaction &tx); CTransaction MakeImportCoinTransaction(const TxProof proof, const CTransaction burnTx, const std::vector payouts); -CTxOut MakeBurnOutput(CAmount value, int targetChain, const std::vector payouts); +CTxOut MakeBurnOutput(CAmount value, uint32_t targetCCid, std::string targetSymbol, const std::vector payouts); -bool VerifyCoinImport(const CScript& scriptSig, - TransactionSignatureChecker& checker, CValidationState &state); +bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint32_t *targetCCid, uint256 &payoutsHash); +bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransaction &burnTx, + std::vector &payouts); + +bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& checker, CValidationState &state); void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, int nHeight); diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index a7bb49d2e..c66a805e7 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -3,9 +3,11 @@ #include "chainparams.h" #include "checkpoints.h" #include "crosschain.h" +#include "importcoin.h" #include "base58.h" #include "consensus/validation.h" #include "cc/eval.h" +#include "cc/utils.h" #include "main.h" #include "primitives/transaction.h" #include "rpcserver.h" @@ -156,3 +158,126 @@ UniValue calc_MoM(const UniValue& params, bool fHelp) ret.push_back(Pair("MoM",MoM.GetHex())); return ret; } + + +UniValue migrate_converttoexport(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 3) + throw runtime_error( + "migrate_converttoexport \"hexstring\" \"dest_symbol\" \"burn_amount\"\n" + "\nConvert a raw transaction to a cross-chain export.\n" + "If neccesary, the transaction should be funded using fundrawtransaction.\n" + "Finally, the transaction should be signed using signrawtransaction\n" + "The finished export transaction, plus the vouts, should be passed to " + "the \"importtransaction\" method on a KMD node to get the corresponding " + "import transaction.\n" + ); + + if (ASSETCHAINS_CC < 2) + throw runtime_error("-ac_cc < 2"); + + if (ASSETCHAINS_SYMBOL[0] == 0) + throw runtime_error("Must be called on assetchain"); + + vector txData(ParseHexV(params[0], "argument 1")); + CMutableTransaction tx; + if (!E_UNMARSHAL(txData, ss >> tx)) + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); + + string targetSymbol = params[1].get_str(); + if (targetSymbol.size() == 0 || targetSymbol.size() > 32) + throw runtime_error("targetSymbol length must be >0 and <=32"); + + CAmount burnAmount = params[2].get_int64(); + { + CAmount needed; + for (int i=0; i txData(ParseHexV(params[0], "argument 1")); + + CTransaction burnTx; + if (!E_UNMARSHAL(txData, ss >> burnTx)) + throw runtime_error("Couldn't parse burnTx"); + + + vector payouts; + if (!E_UNMARSHAL(ParseHexV(params[0], "argument 2"), ss >> payouts)) + throw runtime_error("Couldn't parse payouts"); + + uint256 txid = burnTx.GetHash(); + TxProof proof = GetAssetchainProof(burnTx.GetHash()); + + CTransaction importTx = MakeImportCoinTransaction(proof, burnTx, payouts); + return HexStr(E_MARSHAL(ss << importTx)); +} + + +UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) +{ + if (fHelp || params.size() != 1) + throw runtime_error(""); + + if (ASSETCHAINS_SYMBOL[0] != 0) + throw runtime_error("Must be called on KMD"); + + CTransaction importTx; + if (!E_UNMARSHAL(ParseHexV(params[0], "argument 2"), ss >> importTx)) + throw runtime_error("Couldn't parse importTx"); + + TxProof proof; + CTransaction burnTx; + vector payouts; + if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) + throw runtime_error("Couldn't parse importTx data"); + + std::string targetSymbol; + uint32_t targetCCid; + uint256 payoutsHash; + if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash)) + throw runtime_error("Couldn't parse burnTx data"); + + proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); + + importTx = MakeImportCoinTransaction(proof, burnTx, importTx.vout); + + return HexStr(E_MARSHAL(ss << importTx)); +} diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index c1db6cc78..3cd6eff6e 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -31,17 +31,19 @@ public: TxProof proof; uint256 MoMoM; CMutableTransaction importTx; - uint32_t chainId = 2; + uint32_t testCcid = 2; + std::string testSymbol = "PIZZA"; CAmount amount = 100; void SetImportTx() { burnTx.vout.resize(0); - burnTx.vout.push_back(MakeBurnOutput(amount, chainId, payouts)); - MoMoM = burnTx.GetHash(); // TODO: an actual branch + burnTx.vout.push_back(MakeBurnOutput(amount, testCcid, testSymbol, payouts)); importTx = CMutableTransaction(MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts)); + MoMoM = burnTx.GetHash(); // TODO: an actual branch } - uint32_t GetCurrentLedgerID() const { return chainId; } + uint32_t GetAssetchainsCC() const { return testCcid; } + std::string GetAssetchainsSymbol() const { return testSymbol; } bool GetProofRoot(uint256 hash, uint256 &momom) const { @@ -145,7 +147,7 @@ TEST_F(TestCoinImport, testNoVouts) { importTx.vout.resize(0); TestRunCCEval(importTx); - EXPECT_EQ("no-vouts", state.GetRejectReason()); + EXPECT_EQ("too-few-vouts", state.GetRejectReason()); } @@ -172,23 +174,23 @@ TEST_F(TestCoinImport, testInvalidBurnOutputs) MoMoM = burnTx.GetHash(); // TODO: an actual branch CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts); TestRunCCEval(tx); - EXPECT_EQ("invalid-burn-outputs", state.GetRejectReason()); + EXPECT_EQ("invalid-burn-tx", state.GetRejectReason()); } TEST_F(TestCoinImport, testInvalidBurnParams) { - burnTx.vout[0].scriptPubKey = CScript() << OP_RETURN << E_MARSHAL(ss << VARINT(chainId)); + burnTx.vout[0].scriptPubKey = CScript() << OP_RETURN << E_MARSHAL(ss << VARINT(testCcid)); MoMoM = burnTx.GetHash(); // TODO: an actual branch CTransaction tx = MakeImportCoinTransaction(proof, CTransaction(burnTx), payouts); TestRunCCEval(tx); - EXPECT_EQ("invalid-burn-params", state.GetRejectReason()); + EXPECT_EQ("invalid-burn-tx", state.GetRejectReason()); } TEST_F(TestCoinImport, testWrongChainId) { - chainId = 0; + testCcid = 0; TestRunCCEval(importTx); EXPECT_EQ("importcoin-wrong-chain", state.GetRejectReason()); } @@ -206,15 +208,24 @@ TEST_F(TestCoinImport, testInvalidBurnAmount) TEST_F(TestCoinImport, testPayoutTooHigh) { - importTx.vout[0].nValue = 101; + importTx.vout[1].nValue = 101; TestRunCCEval(importTx); EXPECT_EQ("payout-too-high", state.GetRejectReason()); } +TEST_F(TestCoinImport, testAmountInOpret) +{ + importTx.vout[0].nValue = 1; + TestRunCCEval(importTx); + EXPECT_EQ("non-canonical", state.GetRejectReason()); +} + + + TEST_F(TestCoinImport, testInvalidPayouts) { - importTx.vout[0].nValue = 40; + importTx.vout[1].nValue = 40; importTx.vout.push_back(importTx.vout[0]); TestRunCCEval(importTx); EXPECT_EQ("wrong-payouts", state.GetRejectReason()); diff --git a/src/test-komodo/testutils.cpp b/src/test-komodo/testutils.cpp index e8b57b6b9..59ea4307a 100644 --- a/src/test-komodo/testutils.cpp +++ b/src/test-komodo/testutils.cpp @@ -47,6 +47,9 @@ void setupChain() COINBASE_MATURITY = 1; // Global mock time nMockTime = GetTime(); + + // Unload + UnloadBlockIndex(); // Init blockchain ClearDatadirCache(); From 1333d0d7cfdf5d74a98131eaaa5d36b8cd68e388 Mon Sep 17 00:00:00 2001 From: alrighttt Date: Mon, 21 May 2018 18:34:18 -0400 Subject: [PATCH 0078/1123] Changed help docs to reflect KMD/assetchains --- src/wallet/rpcwallet.cpp | 209 ++++++++++++++++++++------------------- 1 file changed, 107 insertions(+), 102 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fa2937005..82ff2fa7f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -42,6 +42,7 @@ using namespace std; using namespace libzcash; +extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); int64_t nWalletUnlockTime; @@ -113,6 +114,11 @@ string AccountFromValue(const UniValue& value) return strAccount; } +char *komodo_chainname() +{ + return(ASSETCHAINS_SYMBOL[0] == 0 ? (char *)"KMD" : ASSETCHAINS_SYMBOL); +} + UniValue getnewaddress(const UniValue& params, bool fHelp) { if (!EnsureWalletIsAvailable(fHelp)) @@ -121,11 +127,11 @@ UniValue getnewaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "getnewaddress ( \"account\" )\n" - "\nReturns a new Komodo address for receiving payments.\n" + "\nReturns a new " + strprintf("%s",komodo_chainname()) + " address for receiving payments.\n" "\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" + "\"" + strprintf("%s",komodo_chainname()) + "_address\" (string) The new " + strprintf("%s",komodo_chainname()) + " address\n" "\nExamples:\n" + HelpExampleCli("getnewaddress", "") + HelpExampleRpc("getnewaddress", "") @@ -198,11 +204,11 @@ UniValue getaccountaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( "getaccountaddress \"account\"\n" - "\nDEPRECATED. Returns the current Komodo address for receiving payments to this account.\n" + "\nDEPRECATED. Returns the current " + strprintf("%s",komodo_chainname()) + " address for receiving payments to this account.\n" "\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" + "\"" + strprintf("%s",komodo_chainname()) + "_address\" (string) The account " + strprintf("%s",komodo_chainname()) + " address\n" "\nExamples:\n" + HelpExampleCli("getaccountaddress", "") + HelpExampleCli("getaccountaddress", "\"\"") @@ -230,7 +236,7 @@ UniValue getrawchangeaddress(const UniValue& params, bool fHelp) if (fHelp || params.size() > 1) throw runtime_error( "getrawchangeaddress\n" - "\nReturns a new Komodo address, for receiving change.\n" + "\nReturns a new " + strprintf("%s",komodo_chainname()) + " address, for receiving change.\n" "This is for use with raw transactions, NOT normal use.\n" "\nResult:\n" "\"address\" (string) The address\n" @@ -264,21 +270,21 @@ UniValue setaccount(const UniValue& params, bool fHelp) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( - "setaccount \"zcashaddress\" \"account\"\n" + "setaccount \"" + strprintf("%s",komodo_chainname()) + "_address\" \"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. \"" + strprintf("%s",komodo_chainname()) + "_address\" (string, required) The " + strprintf("%s",komodo_chainname()) + " 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", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"tabby\"") + + HelpExampleRpc("setaccount", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"tabby\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); string strAccount; if (params.size() > 1) @@ -310,22 +316,22 @@ UniValue getaccount(const UniValue& params, bool fHelp) if (fHelp || params.size() != 1) throw runtime_error( - "getaccount \"zcashaddress\"\n" + "getaccount \"" + strprintf("%s",komodo_chainname()) + "_address\"\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. \"" + strprintf("%s",komodo_chainname()) + "_address\" (string, required) The " + strprintf("%s",komodo_chainname()) + " address for account lookup.\n" "\nResult:\n" "\"accountname\" (string) the account address\n" "\nExamples:\n" - + HelpExampleCli("getaccount", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\"") - + HelpExampleRpc("getaccount", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\"") + + HelpExampleCli("getaccount", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"") + + HelpExampleRpc("getaccount", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); string strAccount; map::iterator mi = pwalletMain->mapAddressBook.find(address.Get()); @@ -348,7 +354,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" + " \"" + strprintf("%s",komodo_chainname()) + "_address\" (string) a " + strprintf("%s",komodo_chainname()) + " address associated with the given account\n" " ,...\n" "]\n" "\nExamples:\n" @@ -424,33 +430,33 @@ 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 \"" + strprintf("%s",komodo_chainname()) + "_address\" 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" - "2. \"amount\" (numeric, required) The amount in " + CURRENCY_UNIT + " to send. eg 0.1\n" + "1. \"" + strprintf("%s",komodo_chainname()) + "_address\" (string, required) The " + strprintf("%s",komodo_chainname()) + " address to send to.\n" + "2. \"amount\" (numeric, required) The amount in " + strprintf("%s",komodo_chainname()) + " 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" "4. \"comment-to\" (string, optional) A comment to store the name of the person or organization \n" " 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 " + strprintf("%s",komodo_chainname()) + " 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", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1") + + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"\" \"\" true") + + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); // Amount CAmount nAmount = AmountFromValue(params[1]); @@ -483,7 +489,6 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) uint64_t PAX_fiatdest(uint64_t *seedp,int32_t tokomodo,char *destaddr,uint8_t pubkey37[37],char *coinaddr,int32_t height,char *base,int64_t fiatoshis); int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_t opretlen); #define CRYPTO777_KMDADDR "RXL3YXG2ceaB6C5hfJcN4fvmLH2C34knhA" -extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern int32_t KOMODO_PAX; extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; int32_t komodo_is_issuer(); @@ -712,8 +717,8 @@ UniValue listaddressgroupings(const UniValue& params, bool fHelp) "[\n" " [\n" " [\n" - " \"zcashaddress\", (string) The zcash address\n" - " amount, (numeric) The amount in " + CURRENCY_UNIT + "\n" + " \"" + strprintf("%s",komodo_chainname()) + " address\", (string) The " + strprintf("%s",komodo_chainname()) + " address\n" + " amount, (numeric) The amount in " + strprintf("%s",komodo_chainname()) + "\n" " \"account\" (string, optional) The account (DEPRECATED)\n" " ]\n" " ,...\n" @@ -755,11 +760,11 @@ UniValue signmessage(const UniValue& params, bool fHelp) if (fHelp || params.size() != 2) throw runtime_error( - "signmessage \"zcashaddress\" \"message\"\n" + "signmessage \"" + strprintf("%s",komodo_chainname()) + " address\" \"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. \"" + strprintf("%s",komodo_chainname()) + " address\" (string, required) The " + strprintf("%s",komodo_chainname()) + " 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 +772,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", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"my message\"") + "\nVerify the signature\n" - + HelpExampleCli("verifymessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" \"signature\" \"my message\"") + + + HelpExampleCli("verifymessage", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"signature\" \"my message\"") + "\nAs json rpc\n" - + HelpExampleRpc("signmessage", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\", \"my message\"") + + HelpExampleRpc("signmessage", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"my message\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -811,22 +816,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 \"" + strprintf("%s",komodo_chainname()) + "_address\" ( minconf )\n" + "\nReturns the total amount received by the given " + strprintf("%s",komodo_chainname()) + " address in transactions with at least minconf confirmations.\n" "\nArguments:\n" - "1. \"zcashaddress\" (string, required) The Zcash address for transactions.\n" + "1. \"" + strprintf("%s",komodo_chainname()) + "_address\" (string, required) The " + strprintf("%s",komodo_chainname()) + " 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" + "amount (numeric) The total amount in " + strprintf("%s",komodo_chainname()) + " received at this address.\n" "\nExamples:\n" "\nThe amount from transactions with at least 1 confirmation\n" - + HelpExampleCli("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\"") + + + HelpExampleCli("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"") + "\nThe amount including unconfirmed transactions, zero confirmations\n" - + HelpExampleCli("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" 0") + + + HelpExampleCli("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0") + "\nThe amount with at least 6 confirmations, very safe\n" - + HelpExampleCli("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\" 6") + + + HelpExampleCli("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 6") + "\nAs a json rpc call\n" - + HelpExampleRpc("getreceivedbyaddress", "\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\", 6") + + HelpExampleRpc("getreceivedbyaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 6") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -834,7 +839,7 @@ UniValue getreceivedbyaddress(const UniValue& params, bool fHelp) // Bitcoin address CBitcoinAddress address = CBitcoinAddress(params[0].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); CScript scriptPubKey = GetScriptForDestination(address.Get()); if (!IsMine(*pwalletMain,scriptPubKey)) return (double)0.0; @@ -875,7 +880,7 @@ UniValue getreceivedbyaccount(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" "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 for this account.\n" + "amount (numeric) The total amount in " + strprintf("%s",komodo_chainname()) + " received for this account.\n" "\nExamples:\n" "\nAmount received by the default account with at least 1 confirmation\n" + HelpExampleCli("getreceivedbyaccount", "\"\"") + @@ -965,7 +970,7 @@ UniValue getbalance(const UniValue& params, bool fHelp) "2. minconf (numeric, optional, default=1) Only include transactions confirmed at least this many times.\n" "3. includeWatchonly (bool, optional, default=false) Also include balance in watchonly addresses (see 'importaddress')\n" "\nResult:\n" - "amount (numeric) The total amount in " + CURRENCY_UNIT + " received for this account.\n" + "amount (numeric) The total amount in " + strprintf("%s",komodo_chainname()) + " received for this account.\n" "\nExamples:\n" "\nThe total amount in the wallet\n" + HelpExampleCli("getbalance", "") + @@ -1051,15 +1056,15 @@ UniValue movecmd(const UniValue& params, bool fHelp) "\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. \"toaccount\" (string, required) MUST be set to the empty string \"\" to represent the default account. Passing any other string will result in an error.\n" - "3. amount (numeric) Quantity of " + CURRENCY_UNIT + " to move between accounts.\n" + "3. amount (numeric) Quantity of " + strprintf("%s",komodo_chainname()) + " to move between accounts.\n" "4. minconf (numeric, optional, default=1) Only use funds with at least this many confirmations.\n" "5. \"comment\" (string, optional) An optional comment, stored in the wallet only.\n" "\nResult:\n" "true|false (boolean) true if successful.\n" "\nExamples:\n" - "\nMove 0.01 " + CURRENCY_UNIT + " from the default account to the account named tabby\n" + "\nMove 0.01 " + strprintf("%s",komodo_chainname()) + " from the default account to the account named tabby\n" + HelpExampleCli("move", "\"\" \"tabby\" 0.01") + - "\nMove 0.01 " + CURRENCY_UNIT + " timotei to akiko with a comment and funds have 6 confirmations\n" + "\nMove 0.01 " + strprintf("%s",komodo_chainname()) + " timotei to akiko with a comment and funds have 6 confirmations\n" + HelpExampleCli("move", "\"timotei\" \"akiko\" 0.01 6 \"happy birthday!\"") + "\nAs a json rpc call\n" + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"") @@ -1119,14 +1124,14 @@ 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\" \"to" + strprintf("%s",komodo_chainname()) + "address\" amount ( minconf \"comment\" \"comment-to\" )\n" + "\nDEPRECATED (use sendtoaddress). Sent an amount from an account to a " + strprintf("%s",komodo_chainname()) + " 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" - "3. amount (numeric, required) The amount in " + CURRENCY_UNIT + " (transaction fee is added on top).\n" + "2. \"to" + strprintf("%s",komodo_chainname()) + "address\" (string, required) The " + strprintf("%s",komodo_chainname()) + " address to send funds to.\n" + "3. amount (numeric, required) The amount in " + strprintf("%s",komodo_chainname()) + " (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" " This is not part of the transaction, just kept in your wallet.\n" @@ -1136,12 +1141,12 @@ UniValue sendfrom(const UniValue& params, bool fHelp) "\nResult:\n" "\"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") + + "\nSend 0.01 " + strprintf("%s",komodo_chainname()) + " from the default account to the address, must have at least 1 confirmation\n" + + HelpExampleCli("sendfrom", "\"\" \"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 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\" \"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 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\", \"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.01, 6, \"donation\", \"seans outpost\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1149,7 +1154,7 @@ UniValue sendfrom(const UniValue& params, bool fHelp) string strAccount = AccountFromValue(params[0]); CBitcoinAddress address(params[1].get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Komodo address"); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); CAmount nAmount = AmountFromValue(params[2]); if (nAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for send"); @@ -1191,14 +1196,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 " + strprintf("%s",komodo_chainname()) + " address is the key, the numeric amount in " + strprintf("%s",komodo_chainname()) + " 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 " + strprintf("%s",komodo_chainname()) + " 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 +1214,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", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":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", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":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", "\"\" \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\" 1 \"\" \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\",\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\"]\"") + "\nAs a json rpc call\n" - + HelpExampleRpc("sendmany", "\"\", \"{\\\"t14oHp2v54vfmdgQ3v3SNuQga8JKHTNi2a1\\\":0.01,\\\"t1353tsE8YMTA4EuV7dgUXGjNFf9KpVvKHz\\\":0.02}\", 6, \"testing\"") + + HelpExampleRpc("sendmany", "\"\", \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\", 6, \"testing\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1244,7 +1249,7 @@ UniValue sendmany(const UniValue& params, bool fHelp) { CBitcoinAddress address(name_); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Komodo address: ")+name_); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid " + strprintf("%s",komodo_chainname()) + " address: ")+name_); //if (setAddress.count(address)) // throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+name_); @@ -1301,26 +1306,26 @@ UniValue addmultisigaddress(const UniValue& params, bool fHelp) { string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n" "\nAdd a nrequired-to-sign multisignature address to the wallet.\n" - "Each key is a Komodo address or hex-encoded public key.\n" + "Each key is a " + strprintf("%s",komodo_chainname()) + " address or hex-encoded public key.\n" "If 'account' is specified (DEPRECATED), assign address to that account.\n" "\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 " + strprintf("%s",komodo_chainname()) + " addresses or hex-encoded public keys\n" " [\n" - " \"address\" (string) Zcash address or hex-encoded public key\n" + " \"address\" (string) " + strprintf("%s",komodo_chainname()) + " 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" + "\"" + strprintf("%s",komodo_chainname()) + "_address\" (string) A " + strprintf("%s",komodo_chainname()) + " address associated with the keys.\n" "\nExamples:\n" "\nAdd a multisig address from 2 addresses\n" - + HelpExampleCli("addmultisigaddress", "2 \"[\\\"t16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"t171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + + + HelpExampleCli("addmultisigaddress", "2 \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\",\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\"]\"") + "\nAs json rpc call\n" - + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"t16sSauSf5pF2UkUwvKGq4qjNRzBZYqgEL5\\\",\\\"t171sgjn4YtPu27adkKGrdDwzRTxnRkBfKV\\\"]\"") + + HelpExampleRpc("addmultisigaddress", "2, \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\",\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\"]\"") ; throw runtime_error(msg); } @@ -1493,7 +1498,7 @@ UniValue listreceivedbyaddress(const UniValue& params, bool fHelp) " \"involvesWatchonly\" : true, (bool) Only returned if imported addresses were involved in transaction\n" " \"address\" : \"receivingaddress\", (string) The receiving address\n" " \"account\" : \"accountname\", (string) DEPRECATED. The account of the receiving address. The default account is \"\".\n" - " \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " received by the address\n" + " \"amount\" : x.xxx, (numeric) The total amount in " + strprintf("%s",komodo_chainname()) + " received by the address\n" " \"confirmations\" : n (numeric) The number of confirmations of the most recent transaction included\n" " }\n" " ,...\n" @@ -1669,17 +1674,17 @@ 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\":\"" + strprintf("%s",komodo_chainname()) + "_address\", (string) The " + strprintf("%s",komodo_chainname()) + " 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" " transaction id or block. 'send' and 'receive' transactions are \n" " associated with an address, transaction id and block details\n" - " \"amount\": x.xxx, (numeric) The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and for the\n" + " \"amount\": x.xxx, (numeric) The amount in " + strprintf("%s",komodo_chainname()) + ". This is negative for the 'send' category, and for the\n" " 'move' category for moves outbound. It is positive for the 'receive' category,\n" " and for the 'move' category for inbound funds.\n" " \"vout\" : n, (numeric) the vout value\n" - " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the \n" + " \"fee\": x.xxx, (numeric) The amount of the fee in " + strprintf("%s",komodo_chainname()) + ". This is negative and only available for the \n" " 'send' category of transactions.\n" " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and \n" " 'receive' category of transactions.\n" @@ -1869,12 +1874,12 @@ 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\":\"" + strprintf("%s",komodo_chainname()) + "_address\", (string) The " + strprintf("%s",komodo_chainname()) + " 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" + " \"amount\": x.xxx, (numeric) The amount in " + strprintf("%s",komodo_chainname()) + ". 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" " \"vout\" : n, (numeric) the vout value\n" - " \"fee\": x.xxx, (numeric) The amount of the fee in " + CURRENCY_UNIT + ". This is negative and only available for the 'send' category of transactions.\n" + " \"fee\": x.xxx, (numeric) The amount of the fee in " + strprintf("%s",komodo_chainname()) + ". This is negative and only available for the 'send' category of transactions.\n" " \"confirmations\": n, (numeric) The number of confirmations for the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"blockhash\": \"hashvalue\", (string) The block hash containing the transaction. Available for 'send' and 'receive' category of transactions.\n" " \"blockindex\": n, (numeric) The block index containing the transaction. Available for 'send' and 'receive' category of transactions.\n" @@ -1957,7 +1962,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp) "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n" "\nResult:\n" "{\n" - " \"amount\" : x.xxx, (numeric) The transaction amount in " + CURRENCY_UNIT + "\n" + " \"amount\" : x.xxx, (numeric) The transaction amount in " + strprintf("%s",komodo_chainname()) + "\n" " \"confirmations\" : n, (numeric) The number of confirmations\n" " \"blockhash\" : \"hash\", (string) The block hash\n" " \"blockindex\" : xx, (numeric) The block index\n" @@ -1968,9 +1973,9 @@ 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\" : \"" + strprintf("%s",komodo_chainname()) + "_address\", (string) The " + strprintf("%s",komodo_chainname()) + " 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" + " \"amount\" : x.xxx (numeric) The amount in " + strprintf("%s",komodo_chainname()) + "\n" " \"vout\" : n, (numeric) the vout value\n" " }\n" " ,...\n" @@ -2128,7 +2133,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 " + strprintf("%s",komodo_chainname()) + "\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 +2247,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", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 1.0") + "\nClear the passphrase since we are done before 2 minutes is up\n" + HelpExampleCli("walletlock", "") + "\nAs json rpc call\n" @@ -2293,10 +2298,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 " + strprintf("%s",komodo_chainname()) + "\n" + HelpExampleCli("walletpassphrase", "\"my pass phrase\"") + "\nNow we can so something like sign\n" - + HelpExampleCli("signmessage", "\"zcashaddress\" \"test message\"") + + + HelpExampleCli("signmessage", "\"" + strprintf("%s",komodo_chainname()) + "_address\" \"test message\"") + "\nNow lock the wallet again by removing the passphrase\n" + HelpExampleCli("walletlock", "") + "\nAs a json rpc call\n" @@ -2344,7 +2349,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 " + strprintf("%s",komodo_chainname()) + ".\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" @@ -2477,7 +2482,7 @@ UniValue settxfee(const UniValue& params, bool fHelp) "settxfee amount\n" "\nSet the transaction fee per kB.\n" "\nArguments:\n" - "1. amount (numeric, required) The transaction fee in " + CURRENCY_UNIT + "/kB rounded to the nearest 0.00000001\n" + "1. amount (numeric, required) The transaction fee in " + strprintf("%s",komodo_chainname()) + "/kB rounded to the nearest 0.00000001\n" "\nResult\n" "true|false (boolean) Returns true if successful\n" "\nExamples:\n" @@ -2506,9 +2511,9 @@ UniValue getwalletinfo(const UniValue& params, bool fHelp) "\nResult:\n" "{\n" " \"walletversion\": xxxxx, (numeric) the wallet version\n" - " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + CURRENCY_UNIT + "\n" - " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + CURRENCY_UNIT + "\n" - " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + CURRENCY_UNIT + "\n" + " \"balance\": xxxxxxx, (numeric) the total confirmed balance of the wallet in " + strprintf("%s",komodo_chainname()) + "\n" + " \"unconfirmed_balance\": xxx, (numeric) the total unconfirmed balance of the wallet in " + strprintf("%s",komodo_chainname()) + "\n" + " \"immature_balance\": xxxxxx, (numeric) the total immature balance of the wallet in " + strprintf("%s",komodo_chainname()) + "\n" " \"txcount\": xxxxxxx, (numeric) the total number of transactions in the wallet\n" " \"keypoololdest\": xxxxxx, (numeric) the timestamp (seconds since GMT epoch) of the oldest pre-generated key in the key pool\n" " \"keypoolsize\": xxxx, (numeric) how many new keys are pre-generated\n" @@ -2577,9 +2582,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 " + strprintf("%s",komodo_chainname()) + " addresses to filter\n" " [\n" - " \"address\" (string) Zcash address\n" + " \"address\" (string) " + strprintf("%s",komodo_chainname()) + " address\n" " ,...\n" " ]\n" "\nResult\n" @@ -2588,10 +2593,10 @@ 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 " + strprintf("%s",komodo_chainname()) + " 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" + " \"amount\" : x.xxx, (numeric) the transaction amount in " + strprintf("%s",komodo_chainname()) + "\n" " \"confirmations\" : n (numeric) The number of confirmations\n" " }\n" " ,...\n" @@ -2599,8 +2604,8 @@ UniValue listunspent(const UniValue& params, bool fHelp) "\nExamples\n" + HelpExampleCli("listunspent", "") - + HelpExampleCli("listunspent", "6 9999999 \"[\\\"t1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"t1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"") - + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"t1PGFqEzfmQch1gKD3ra4k18PNj3tTUUSqg\\\",\\\"t1LtvqCaApEdUGFkpKMM4MstjcaL4dKg8SP\\\"]\"") + + HelpExampleCli("listunspent", "6 9999999 \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\",\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\"]\"") + + HelpExampleRpc("listunspent", "6, 9999999 \"[\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\",\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\"]\"") ); RPCTypeCheck(params, boost::assign::list_of(UniValue::VNUM)(UniValue::VNUM)(UniValue::VARR)); @@ -2620,7 +2625,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) const UniValue& input = inputs[idx]; CBitcoinAddress address(input.get_str()); if (!address.IsValid()) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid Komodo address: ")+input.get_str()); + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, string("Invalid " + strprintf("%s",komodo_chainname()) + " address: ")+input.get_str()); if (setAddress.count(address)) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+input.get_str()); setAddress.insert(address); @@ -3231,7 +3236,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" + "\"" + strprintf("%s",komodo_chainname()) + "_address\" (string) The new zaddr\n" "\nExamples:\n" + HelpExampleCli("z_getnewaddress", "") + HelpExampleRpc("z_getnewaddress", "") @@ -3670,8 +3675,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", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" '[{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]'") + + HelpExampleRpc("z_sendmany", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", [{\"address\": \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\" ,\"amount\": 5.0}]") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -3890,8 +3895,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", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") + + HelpExampleRpc("z_shieldcoinbase", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") ); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4118,8 +4123,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", "'[\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"]' ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf") + + HelpExampleRpc("z_mergetoaddress", "[\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\"], \"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") ); if (!fEnableMergeToAddress) { From 0b485d3c6649c238630401715ded3dc0d829281b Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 22 May 2018 15:16:37 -0300 Subject: [PATCH 0079/1123] rpc methods for cross chain transactions --- src/crosschain.cpp | 31 +++++++++++++++++++++++++++ src/crosschain.h | 3 +-- src/importcoin.cpp | 1 + src/importcoin.h | 1 - src/rpcclient.cpp | 17 +++++++++++---- src/rpccrosschain.cpp | 33 ++++++++++------------------- src/rpcserver.cpp | 3 +++ src/rpcserver.h | 4 ++++ src/test-komodo/test_crosschain.cpp | 13 +++++++++--- 9 files changed, 74 insertions(+), 32 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index b68b77b33..dc45e994c 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -1,9 +1,14 @@ #include "cc/eval.h" +#include "importcoin.h" #include "main.h" #include "notarisationdb.h" #include "komodo_structs.h" +/* + * This file is built in the server + */ + /* On KMD */ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, uint256 &destNotarisationTxid) @@ -123,6 +128,30 @@ cont: } +/* + * Takes an importTx that has proof leading to assetchain root + * and extends proof to cross chain root + */ +void CompleteImportTransaction(CTransaction &importTx) +{ + TxProof proof; + CTransaction burnTx; + std::vector payouts; + if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) + throw std::runtime_error("Couldn't parse importTx"); + + std::string targetSymbol; + uint32_t targetCCid; + uint256 payoutsHash; + if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash)) + throw std::runtime_error("Couldn't parse burnTx"); + + proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); + + importTx = MakeImportCoinTransaction(proof, burnTx, importTx.vout); +} + + struct notarized_checkpoint *komodo_npptr_at(int idx); struct notarized_checkpoint *komodo_npptr_for_height(int32_t height, int *idx); @@ -236,3 +265,5 @@ TxProof GetAssetchainProof(uint256 hash) CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION); return std::make_pair(np->notarized_desttxid, MerkleBranch(nIndex, branch)); } + + diff --git a/src/crosschain.h b/src/crosschain.h index 64bacb759..15452ac63 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -10,10 +10,9 @@ TxProof GetAssetchainProof(uint256 hash); /* On KMD */ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, uint256 &destNotarisationTxid); - -/* On KMD */ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid, const TxProof assetChainProof); +void CompleteImportTransaction(CTransaction &importTx); /* On assetchain */ bool GetNextBacknotarisation(uint256 txid, std::pair &bn); diff --git a/src/importcoin.cpp b/src/importcoin.cpp index bbada7e99..55717fc69 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -1,3 +1,4 @@ +#include "crosschain.h" #include "importcoin.h" #include "cc/utils.h" #include "coins.h" diff --git a/src/importcoin.h b/src/importcoin.h index 8e43f9376..f62bb45a1 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -21,7 +21,6 @@ bool UnmarshalImportTx(const CTransaction &importTx, TxProof &proof, CTransactio bool VerifyCoinImport(const CScript& scriptSig, TransactionSignatureChecker& checker, CValidationState &state); - void AddImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs, int nHeight); void RemoveImportTombstone(const CTransaction &importTx, CCoinsViewCache &inputs); int ExistsImportTombstone(const CTransaction &importTx, const CCoinsViewCache &inputs); diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index e421feb4c..f93dbbb0f 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -134,16 +134,25 @@ static const CRPCConvertParam vRPCConvertParams[] = { "paxprices", 3 }, { "paxpending", 0 }, { "notaries", 2 }, - { "height_MoM", 1 }, - { "MoMoMdata", 3 }, - { "txMoMproof", 1 }, { "minerids", 1 }, { "kvsearch", 1 }, { "kvupdate", 4 }, { "z_importkey", 2 }, { "z_importviewingkey", 2 }, { "z_getpaymentdisclosure", 1}, - { "z_getpaymentdisclosure", 2} + { "z_getpaymentdisclosure", 2}, + + // crosschain + { "assetchainproof", 1}, + { "crosschainproof", 1}, + { "getproofroot", 2}, + { "height_MoM", 1}, + { "MoMoMdata", 3}, + { "calc_MoM", 2}, + { "migrate_converttoexport", 3}, + { "migrate_createimporttransaction", 2}, + { "migrate_completeimporttransaction", 1} + }; class CRPCConvertTable diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index c66a805e7..b2414a651 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -164,12 +164,12 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 3) throw runtime_error( - "migrate_converttoexport \"hexstring\" \"dest_symbol\" \"burn_amount\"\n" + "migrate_converttoexport rawTx dest_symbol burn_amount\n" "\nConvert a raw transaction to a cross-chain export.\n" "If neccesary, the transaction should be funded using fundrawtransaction.\n" "Finally, the transaction should be signed using signrawtransaction\n" - "The finished export transaction, plus the vouts, should be passed to " - "the \"importtransaction\" method on a KMD node to get the corresponding " + "The finished export transaction, plus the payouts, should be passed to " + "the \"migrate_createimporttransaction\" method on a KMD node to get the corresponding " "import transaction.\n" ); @@ -199,7 +199,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) CTxOut burnOut = MakeBurnOutput(burnAmount, ASSETCHAINS_CC, targetSymbol, tx.vout); UniValue ret(UniValue::VOBJ); - ret.push_back(Pair("vouts", HexStr(E_MARSHAL(ss << tx.vout)))); + ret.push_back(Pair("payouts", HexStr(E_MARSHAL(ss << tx.vout)))); tx.vout.clear(); tx.vout.push_back(burnOut); ret.push_back(Pair("exportTx", HexStr(E_MARSHAL(ss << tx)))); @@ -224,7 +224,8 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 2) - throw runtime_error(""); + throw runtime_error("migrate_createimporttransaction burnTx payouts\n\n" + "Create an importTx given a burnTx and the corresponding payouts, hex encoded"); if (ASSETCHAINS_CC < 2) throw runtime_error("-ac_cc < 2"); @@ -254,30 +255,18 @@ UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp) UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) - throw runtime_error(""); + throw runtime_error("migrate_completeimporttransaction importTx\n\n" + "Takes a cross chain import tx with proof generated on assetchain " + "and extends proof to target chain proof root"); if (ASSETCHAINS_SYMBOL[0] != 0) throw runtime_error("Must be called on KMD"); CTransaction importTx; - if (!E_UNMARSHAL(ParseHexV(params[0], "argument 2"), ss >> importTx)) + if (!E_UNMARSHAL(ParseHexV(params[0], "argument 1"), ss >> importTx)) throw runtime_error("Couldn't parse importTx"); - TxProof proof; - CTransaction burnTx; - vector payouts; - if (!UnmarshalImportTx(importTx, proof, burnTx, payouts)) - throw runtime_error("Couldn't parse importTx data"); - - std::string targetSymbol; - uint32_t targetCCid; - uint256 payoutsHash; - if (!UnmarshalBurnTx(burnTx, targetSymbol, &targetCCid, payoutsHash)) - throw runtime_error("Couldn't parse burnTx data"); - - proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); - - importTx = MakeImportCoinTransaction(proof, burnTx, importTx.vout); + CompleteImportTransaction(importTx); return HexStr(E_MARSHAL(ss << importTx)); } diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index cd579c83c..97b2bab1b 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -312,6 +312,9 @@ static const CRPCCommand vRPCCommands[] = { "crosschain", "height_MoM", &height_MoM, true }, { "crosschain", "assetchainproof", &assetchainproof, true }, { "crosschain", "crosschainproof", &crosschainproof, true }, + { "crosschain", "migrate_converttoexport", &migrate_converttoexport, true }, + { "crosschain", "migrate_createimporttransaction", &migrate_createimporttransaction, true }, + { "crosschain", "migrate_completeimporttransaction", &migrate_completeimporttransaction, true }, /* Mining */ { "mining", "getblocktemplate", &getblocktemplate, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 7d7ef5d7e..1f64d9d07 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -317,6 +317,10 @@ extern UniValue calc_MoM(const UniValue& params, bool fHelp); extern UniValue height_MoM(const UniValue& params, bool fHelp); extern UniValue assetchainproof(const UniValue& params, bool fHelp); extern UniValue crosschainproof(const UniValue& params, bool fHelp); +extern UniValue migrate_converttoexport(const UniValue& params, bool fHelp); +extern UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp); +extern UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp); + extern UniValue notaries(const UniValue& params, bool fHelp); extern UniValue minerids(const UniValue& params, bool fHelp); extern UniValue kvsearch(const UniValue& params, bool fHelp); diff --git a/src/test-komodo/test_crosschain.cpp b/src/test-komodo/test_crosschain.cpp index 6ff261247..356a7ab6c 100644 --- a/src/test-komodo/test_crosschain.cpp +++ b/src/test-komodo/test_crosschain.cpp @@ -133,7 +133,7 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) } /* - * Generate proof + * Test a proof */ uint256 txid = blocks[7].vtx[0].GetHash(); TxProof proof = GetAssetchainProof(txid); @@ -141,8 +141,15 @@ TEST_F(TestCrossChain, testCreateAndValidateImportProof) E_UNMARSHAL(RecvIPC(), ss >> proof); std::pair bn; - if (!GetNextBacknotarisation(proof.first, bn)) return 1; - return proof.second.Exec(txid) == bn.second.MoMoM ? 0 : 1; + if (!GetNextBacknotarisation(proof.first, bn)) { + printf("GetNextBackNotarisation failed\n"); + return 1; + } + if (proof.second.Exec(txid) != bn.second.MoMoM) { + printf("MoMom incorrect\n"); + return 1; + } + return 0; }; auto RunTestKmd = [&] () From e2d299ee8349ba05e0b15db6b884a5f8aa42d6e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 May 2018 10:05:51 +0300 Subject: [PATCH 0080/1123] GAME freq.5 --- src/dpowassets | 2 +- src/komodo_gateway.h | 3 ++- src/rpcrawtransaction.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dpowassets b/src/dpowassets index f148bda05..40bb89cce 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -33,4 +33,4 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":10,\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 7b642746a..9b2f3eb8e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -717,7 +717,8 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( height >= activation ) { - fprintf(stderr,">>>>>>>> <<<<<<<<<< ht.%d illegal nonz output %.8f n.%d\n",height,dstr(block.vtx[0].vout[1].nValue),n); + 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); } } diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 123e0bbb9..904fe1c5e 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -452,7 +452,7 @@ int32_t gettxout_scriptPubKey(uint8_t *scriptPubKey,int32_t maxsize,uint256 txid }*/ CTransaction tx; uint256 hashBlock; - if ( GetTransaction(txid,tx,hashBlock,true) == 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) == 0 ) return(-1); else if ( n <= tx.vout.size() ) // vout.size() seems off by 1 { From 4543015b01046e46589d78c04d1eaa4776ddbd70 Mon Sep 17 00:00:00 2001 From: igorvoltaic Date: Wed, 23 May 2018 11:32:44 +0300 Subject: [PATCH 0081/1123] lets get rid of this message: 'section __textcoal_nt is deprecated' --- README-mac.md | 40 ++++++++++++++++++++++++++++++++------ darwin.host.mk.patch | 4 ++-- darwin.mk.patch | 8 ++++---- depends/builders/darwin.mk | 8 ++++---- depends/hosts/darwin.mk | 4 ++-- libsnark.mk.patch | 2 +- toolchain-info.sh | 2 +- zcutil/build-mac.sh | 6 +++--- 8 files changed, 51 insertions(+), 23 deletions(-) diff --git a/README-mac.md b/README-mac.md index c085cb617..f3dd5e281 100644 --- a/README-mac.md +++ b/README-mac.md @@ -1,4 +1,6 @@ -First off you need Apple's Xcode (at least version 7, preferably 8.x) and the Xcode Command Line Tools: +## Install for Mac OS X + +First off you need Apple's Xcode (at least version 7, preferably 8.x or later) and the Xcode Command Line Tools: https://itunes.apple.com/us/app/xcode/id497799835?mt=12 @@ -11,25 +13,51 @@ And this is the list of brew packages you'll need installed: ```shell brew tap discoteq/discoteq; brew install flock brew install autoconf autogen automake -brew tap homebrew/versions; brew install homebrew/versions/gcc5 +brew install gcc@6 brew install binutils brew install protobuf brew install coreutils brew install wget ``` +or + +```shell +brew tap discoteq/discoteq; brew install flock autoconf autogen automake gcc@6 binutils protobuf coreutils wget +``` + Get all that installed, then run: ```shell -git clone https://github.com/j-cimb-barker/komodo.git +git clone https://github.com/jl777/komodo.git cd komodo -git checkout dev ./zcutil/build-mac.sh +./zcutil/fetch-params.sh ``` To build a distributable version of komodo then run the makeDistrib.sh script after building. -When you are done building, you need to do a few things in the [Configuration](https://github.com/zcash/zcash/wiki/1.0-User-Guide#configuration) section of the Zcash User Guide differently because we are on the Mac. All instances of `~/.zcash` need to be replaced by `~/Library/Application\ Support/Zcash` -The fetch-params.sh script, however, has already been altered to fetch the proving keys into the correct directory to conform to Mac specific naming conventions. +When you are done building, you need to create `Komodo.conf` the Mac way. + +```shell +mkdir ~/Library/Application\ Support/Komodo +touch ~/Library/Application\ Support/Komodo/Komodo.conf +nano ~/Library/Application\ Support/Komodo/Komodo.conf +``` + +Add the following lines to the Komodo.conf file: + +```shell +rpcuser=dontuseweakusernameoryougetrobbed +rpcpassword=dontuseweakpasswordoryougetrobbed +txindex=1 +addnode=5.9.102.210 +addnode=78.47.196.146 +addnode=178.63.69.164 +addnode=88.198.65.74 +addnode=5.9.122.241 +addnode=144.76.94.38 +addnode=89.248.166.91 +``` Happy Building diff --git a/darwin.host.mk.patch b/darwin.host.mk.patch index 426702563..deeb7a810 100644 --- a/darwin.host.mk.patch +++ b/darwin.host.mk.patch @@ -5,8 +5,8 @@ OSX_SDK_VERSION=10.9 OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk LD64_VERSION=241.9 -! darwin_CC=gcc-5 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -! darwin_CXX=g++-5 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +! darwin_CC=gcc-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +! darwin_CXX=g++-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) darwin_CFLAGS=-pipe darwin_CXXFLAGS=$(darwin_CFLAGS) diff --git a/darwin.mk.patch b/darwin.mk.patch index 80bc5b2d9..fdfd7bc38 100644 --- a/darwin.mk.patch +++ b/darwin.mk.patch @@ -2,8 +2,8 @@ --- ../../komodo-jl777/depends/builders/darwin.mk 2017-01-03 09:48:21.646034937 +0000 *************** *** 1,5 **** -! build_darwin_CC = gcc-5 -! build_darwin_CXX = g++-5 +! build_darwin_CC = gcc-6 +! build_darwin_CXX = g++-6 build_darwin_AR: = $(shell xcrun -f ar) build_darwin_RANLIB: = $(shell xcrun -f ranlib) build_darwin_STRIP: = $(shell xcrun -f strip) @@ -21,8 +21,8 @@ ! build_darwin_DOWNLOAD = wget --timeout=$(DOWNLOAD_CONNECT_TIMEOUT) --tries=$(DOWNLOAD_RETRIES) -nv -O #darwin host on darwin builder. overrides darwin host preferences. -! darwin_CC= gcc-5 -! darwin_CXX= g++-5 +! darwin_CC= gcc-6 +! darwin_CXX= g++-6 darwin_AR:=$(shell xcrun -f ar) darwin_RANLIB:=$(shell xcrun -f ranlib) darwin_STRIP:=$(shell xcrun -f strip) diff --git a/depends/builders/darwin.mk b/depends/builders/darwin.mk index 0028d3f6f..f9b066fcf 100644 --- a/depends/builders/darwin.mk +++ b/depends/builders/darwin.mk @@ -1,5 +1,5 @@ -build_darwin_CC = gcc-5 -build_darwin_CXX = g++-5 +build_darwin_CC = gcc-6 +build_darwin_CXX = g++-6 build_darwin_AR: = $(shell xcrun -f ar) build_darwin_RANLIB: = $(shell xcrun -f ranlib) build_darwin_STRIP: = $(shell xcrun -f strip) @@ -10,8 +10,8 @@ build_darwin_SHA256SUM = shasum -a 256 build_darwin_DOWNLOAD = curl --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -L -f -o #darwin host on darwin builder. overrides darwin host preferences. -darwin_CC= gcc-5 -darwin_CXX= g++-5 +darwin_CC= gcc-6 +darwin_CXX= g++-6 darwin_AR:=$(shell xcrun -f ar) darwin_RANLIB:=$(shell xcrun -f ranlib) darwin_STRIP:=$(shell xcrun -f strip) diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index 70211078b..5eaeddc26 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -2,8 +2,8 @@ OSX_MIN_VERSION=10.8 OSX_SDK_VERSION=10.11 OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk LD64_VERSION=253.9 -darwin_CC=gcc-5 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -darwin_CXX=g++-5 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +darwin_CC=gcc-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +darwin_CXX=g++-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) darwin_CFLAGS=-pipe darwin_CXXFLAGS=$(darwin_CFLAGS) diff --git a/libsnark.mk.patch b/libsnark.mk.patch index f43ea2188..28a60c8b6 100644 --- a/libsnark.mk.patch +++ b/libsnark.mk.patch @@ -14,7 +14,7 @@ - ifeq ($(build_os),darwin) - define $(package)_build_cmds -- CC=gcc-5 CXX=g++-5 CXXFLAGS="-arch x86_64 -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=0 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT +- CC=gcc-6 CXX=g++-6 CXXFLAGS="-arch x86_64 -DBINARY_OUTPUT -DNO_PT_COMPRESSION=1" $(MAKE) lib DEPINST=$(host_prefix) CURVE=ALT_BN128 MULTICORE=0 NO_PROCPS=1 NO_GTEST=1 NO_DOCS=1 STATIC=1 NO_SUPERCOP=1 FEATUREFLAGS=-DMONTGOMERY_OUTPUT - endef - else define $(package)_build_cmds diff --git a/toolchain-info.sh b/toolchain-info.sh index 3322755f0..0bb39c19b 100755 --- a/toolchain-info.sh +++ b/toolchain-info.sh @@ -1,6 +1,6 @@ #!/bin/bash -tools=("gcc-5" "g++-5" "otool" "nm") +tools=("gcc-6" "g++-6" "otool" "nm") echo "Platform: `uname -a`" echo "-------------------------------------" diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index cf2af5a2a..138508cb5 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -1,6 +1,6 @@ #!/bin/bash -export CC=gcc-5 -export CXX=g++-5 +export CC=gcc-6 +export CXX=g++-6 export LIBTOOL=libtool export AR=ar export RANLIB=ranlib @@ -44,7 +44,7 @@ make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ -CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc5/5.4.0/include/c++/5.4.0 -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ +CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ ./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" make "$@" V=1 NO_GTEST=1 STATIC=1 From a035da46d511a4e5f50966b693366fc2e080a28a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 May 2018 00:39:41 -1100 Subject: [PATCH 0082/1123] +print --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9b2f3eb8e..0849d4870 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -746,7 +746,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( overflow != 0 || total > 0 || strangeout != 0 ) { if ( strangeout != 0 ) - fprintf(stderr,">>>>>>>>>>>>> DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",height,strangeout,notmatched); + fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched); return(-1); } } From a6c06faf32de1c103b51945f48324b309240eee4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 May 2018 00:42:21 -1100 Subject: [PATCH 0083/1123] 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 0084/1123] 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 Date: Wed, 23 May 2018 00:55:13 -1100 Subject: [PATCH 0085/1123] +comment --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0849d4870..410e106ae 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],notmatched=0; 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; + 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))); From a748b1a26de7f7f5543c692f4236fca6a82987aa Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Fri, 25 May 2018 14:47:54 -0300 Subject: [PATCH 0086/1123] recognize btc backnotarisations and include ccid in MoMoMdata rpc --- src/cc/eval.h | 30 +++++++++++++++++++++--------- src/rpccrosschain.cpp | 25 +++---------------------- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/cc/eval.h b/src/cc/eval.h index aacec3847..66e0c43f1 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -124,13 +124,6 @@ extern char ASSETCHAINS_SYMBOL[65]; */ class NotarisationData { - bool IsBack() - { - if (IsBackNotarisation == 2) { - return ASSETCHAINS_SYMBOL[0] != 0; - } - return (bool) IsBackNotarisation; - } public: int IsBackNotarisation = 0; uint256 blockHash; @@ -149,16 +142,21 @@ public: template inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + + bool IsBack = IsBackNotarisation; + if (2 == IsBackNotarisation) IsBack = AutoIsBackNotarisation(s, ser_action); + READWRITE(blockHash); READWRITE(height); - if (IsBack()) + if (IsBack) READWRITE(txHash); SerSymbol(s, ser_action); + if (s.size() == 0) return; READWRITE(MoM); READWRITE(MoMDepth); if (s.size() == 0) return; READWRITE(ccId); - if (IsBack()) { + if (IsBack) { READWRITE(MoMoM); READWRITE(MoMoMDepth); } @@ -178,6 +176,20 @@ public: throw std::ios_base::failure("couldn't parse symbol"); s.read(symbol, nullPos-&s[0]+1); } + + template + bool AutoIsBackNotarisation(Stream& s, CSerActionUnserialize act) + { + if (ASSETCHAINS_SYMBOL[0]) return 1; + if (s.size() >= 72 && strcmp("BTC", &s[68]) == 0) return 1; + return 0; + } + + template + bool AutoIsBackNotarisation(Stream& s, CSerActionSerialize act) + { + return !txHash.IsNull(); + } }; diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index b2414a651..3aed3a2bb 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -50,29 +50,10 @@ UniValue assetchainproof(const UniValue& params, bool fHelp) UniValue crosschainproof(const UniValue& params, bool fHelp) { - } -UniValue getproofroot(const UniValue& params, bool fHelp) -{ - std::string symbol; - int kmdHeight; - - // parse params and get notarisation data for tx - if ( fHelp || params.size() != 2) - throw runtime_error("getproofroot needs a symbol and a kmdHeight"); - symbol = params[0].get_str(); - kmdHeight = atoi(params[0].get_str().c_str()); - if (kmdHeight <= 0) - throw runtime_error("Invalid kmdHeight"); - - UniValue ret(UniValue::VOBJ); - return ret; -} - - UniValue height_MoM(const UniValue& params, bool fHelp) { int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR); @@ -120,10 +101,10 @@ UniValue MoMoMdata(const UniValue& params, bool fHelp) UniValue ret(UniValue::VOBJ); char* symbol = (char *)params[0].get_str().c_str(); int kmdheight = atoi(params[1].get_str().c_str()); - int ccid = atoi(params[2].get_str().c_str()); + uint32_t ccid = atoi(params[2].get_str().c_str()); ret.push_back(Pair("coin",symbol)); ret.push_back(Pair("kmdheight",kmdheight)); - ret.push_back(Pair("ccid", ccid)); + ret.push_back(Pair("ccid", (int) ccid)); uint256 destNotarisationTxid; std::vector moms; @@ -134,7 +115,7 @@ UniValue MoMoMdata(const UniValue& params, bool fHelp) ret.push_back(Pair("MoMs", valMoms)); ret.push_back(Pair("notarization_hash", destNotarisationTxid.GetHex())); ret.push_back(Pair("MoMoM", MoMoM.GetHex())); - auto vmomomdata = E_MARSHAL(ss << MoMoM; ss << ((uint32_t)0)); + auto vmomomdata = E_MARSHAL(ss << ccid; ss << MoMoM; ss << ((uint32_t)0)); ret.push_back(Pair("data", HexStr(vmomomdata))); return ret; } From 9de5ae87cf776f2db52959afbf2abb77f9448ea5 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sat, 26 May 2018 13:18:20 -0300 Subject: [PATCH 0087/1123] remove workaround for tests --- src/komodo_bitcoind.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cf72a0715..2174a8d80 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1268,7 +1268,6 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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; - return 1; // TODO: obviously cant commit this if ( !CheckEquihashSolution(pblock, Params()) ) { fprintf(stderr,"komodo_checkPOW slowflag.%d ht.%d CheckEquihashSolution failed\n",slowflag,height); From f937f44e103da50ffe8020dc2c8f22a808307806 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 27 May 2018 11:03:38 -0300 Subject: [PATCH 0088/1123] detect backnotarisation by KMD symbol --- src/Makefile.ktest.include | 3 ++- src/cc/eval.h | 1 + src/test-komodo/test_parse_notarisation.cpp | 23 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/test-komodo/test_parse_notarisation.cpp diff --git a/src/Makefile.ktest.include b/src/Makefile.ktest.include index 93d3460e2..07c64caa0 100644 --- a/src/Makefile.ktest.include +++ b/src/Makefile.ktest.include @@ -10,7 +10,8 @@ komodo_test_SOURCES = \ test-komodo/test_coinimport.cpp \ test-komodo/test_eval_bet.cpp \ test-komodo/test_eval_notarisation.cpp \ - test-komodo/test_crosschain.cpp + test-komodo/test_crosschain.cpp \ + test-komodo/test_parse_notarisation.cpp komodo_test_CPPFLAGS = $(komodod_CPPFLAGS) diff --git a/src/cc/eval.h b/src/cc/eval.h index 66e0c43f1..676fd0a73 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -182,6 +182,7 @@ public: { if (ASSETCHAINS_SYMBOL[0]) return 1; if (s.size() >= 72 && strcmp("BTC", &s[68]) == 0) return 1; + if (s.size() >= 72 && strcmp("KMD", &s[68]) == 0) return 1; return 0; } diff --git a/src/test-komodo/test_parse_notarisation.cpp b/src/test-komodo/test_parse_notarisation.cpp new file mode 100644 index 000000000..285f98813 --- /dev/null +++ b/src/test-komodo/test_parse_notarisation.cpp @@ -0,0 +1,23 @@ +#include + +#include "cc/eval.h" +#include "core_io.h" +#include "key.h" + +#include "testutils.h" + + +namespace TestParseNotarisation { + +class TestParseNotarisation : public ::testing::Test, public Eval {}; + + +TEST(TestParseNotarisation, test_ee2fa) +{ + // ee2fa47820a31a979f9f21cb3fedbc484bf9a8957cb6c9acd0af28ced29bdfe1 + std::vector opret = ParseHex("c349ff90f3bce62c1b7b49d1da0423b1a3d9b733130cce825b95b9e047c729066e020d00743a06fdb95ad5775d032b30bbb3680dac2091a0f800cf54c79fd3461ce9b31d4b4d4400"); + NotarisationData nd; + ASSERT_TRUE(E_UNMARSHAL(opret, ss >> nd)); +} + +} From 2ad1557300b579b7d453bd32398e97d727b667c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 27 May 2018 20:21:15 -1100 Subject: [PATCH 0089/1123] Fix ;; --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 70a5488f8..fce556d33 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4519,7 +4519,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) txNew.vin.resize(1); txNew.vout.resize(1); - txfee = utxovalue / 2;; + txfee = utxovalue / 2; //for (i=0; i<32; i++) // ((uint8_t *)&revtxid)[i] = ((uint8_t *)&utxotxid)[31 - i]; txNew.vin[0].prevout.hash = utxotxid; //revtxid; From ab78e2413064fbcdd589efca5f2fbe2f0eb5031b Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Mon, 28 May 2018 14:19:11 +0300 Subject: [PATCH 0090/1123] 2 new chains --- src/assetchains | 2 ++ src/assetchains.old | 2 ++ src/dpowassets | 2 ++ src/fiat-cli | 2 ++ src/fiat/eql | 2 ++ src/fiat/glxt | 2 ++ 6 files changed, 12 insertions(+) create mode 100755 src/fiat/eql create mode 100755 src/fiat/glxt diff --git a/src/assetchains b/src/assetchains index a8ab28155..ec77fba28 100755 --- a/src/assetchains +++ b/src/assetchains @@ -55,3 +55,5 @@ komodo_asset BNTN 500000000 komodo_asset CHAIN 999999 komodo_asset PRLPAY 500000000 komodo_asset DSEC 7000000 +komodo_asset GLXT 100000000 +komodo_asset EQL 500000000 diff --git a/src/assetchains.old b/src/assetchains.old index 4e56fe639..cf46922de 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -32,6 +32,8 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 & ./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 & ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & +./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & +./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & #sleep $delay #./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & diff --git a/src/dpowassets b/src/dpowassets index 40bb89cce..dbf928d79 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -31,6 +31,8 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GLXT\",\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EQL\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index 463906cf2..8e54aeeb6 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -28,3 +28,5 @@ echo bntn; fiat/bntn $1 $2 $3 $4 echo chain; fiat/chain $1 $2 $3 $4 echo prlpay; fiat/prlpay $1 $2 $3 $4 echo dsec; fiat/dsec $1 $2 $3 $4 +echo dsec; fiat/glxt $1 $2 $3 $4 +echo dsec; fiat/eql $1 $2 $3 $4 diff --git a/src/fiat/eql b/src/fiat/eql new file mode 100755 index 000000000..99cfa9a09 --- /dev/null +++ b/src/fiat/eql @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=EQL $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/glxt b/src/fiat/glxt new file mode 100755 index 000000000..6cedfbf87 --- /dev/null +++ b/src/fiat/glxt @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=GLXT $1 $2 $3 $4 $5 $6 From f3c9d7c7e9c4040cf285c06f7f0d124908bef167 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Mon, 28 May 2018 14:22:02 +0300 Subject: [PATCH 0091/1123] 2 new chains --- src/ac/eql | 2 ++ src/ac/glxt | 2 ++ src/fiat-cli | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100755 src/ac/eql create mode 100755 src/ac/glxt diff --git a/src/ac/eql b/src/ac/eql new file mode 100755 index 000000000..99cfa9a09 --- /dev/null +++ b/src/ac/eql @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=EQL $1 $2 $3 $4 $5 $6 diff --git a/src/ac/glxt b/src/ac/glxt new file mode 100755 index 000000000..6cedfbf87 --- /dev/null +++ b/src/ac/glxt @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=GLXT $1 $2 $3 $4 $5 $6 diff --git a/src/fiat-cli b/src/fiat-cli index 8e54aeeb6..6183f35d1 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -28,5 +28,5 @@ echo bntn; fiat/bntn $1 $2 $3 $4 echo chain; fiat/chain $1 $2 $3 $4 echo prlpay; fiat/prlpay $1 $2 $3 $4 echo dsec; fiat/dsec $1 $2 $3 $4 -echo dsec; fiat/glxt $1 $2 $3 $4 -echo dsec; fiat/eql $1 $2 $3 $4 +echo glxt; fiat/glxt $1 $2 $3 $4 +echo eql; fiat/eql $1 $2 $3 $4 From 3fdb3782919079cfea210b530564b916e680cb2b Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 28 May 2018 17:53:49 -0300 Subject: [PATCH 0092/1123] workaround for assetchain mining blocks in regtest mode --- src/cc/eval.h | 12 +++++++----- src/komodo_bitcoind.h | 3 +++ src/test-komodo/test_crosschain.cpp | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/cc/eval.h b/src/cc/eval.h index 676fd0a73..e4c6a467d 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -144,7 +144,7 @@ public: inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { bool IsBack = IsBackNotarisation; - if (2 == IsBackNotarisation) IsBack = AutoIsBackNotarisation(s, ser_action); + if (2 == IsBackNotarisation) IsBack = DetectBackNotarisation(s, ser_action); READWRITE(blockHash); READWRITE(height); @@ -178,16 +178,18 @@ public: } template - bool AutoIsBackNotarisation(Stream& s, CSerActionUnserialize act) + bool DetectBackNotarisation(Stream& s, CSerActionUnserialize act) { if (ASSETCHAINS_SYMBOL[0]) return 1; - if (s.size() >= 72 && strcmp("BTC", &s[68]) == 0) return 1; - if (s.size() >= 72 && strcmp("KMD", &s[68]) == 0) return 1; + if (s.size() >= 72) { + if (strcmp("BTC", &s[68]) == 0) return 1; + if (strcmp("KMD", &s[68]) == 0) return 1; + } return 0; } template - bool AutoIsBackNotarisation(Stream& s, CSerActionSerialize act) + bool DetectBackNotarisation(Stream& s, CSerActionSerialize act) { return !txHash.IsNull(); } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2174a8d80..f88faf268 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1265,6 +1265,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ return(isPoS); } +bool KOMODO_TEST_ASSETCHAIN_SKIP_POW = 0; + 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; @@ -1304,6 +1306,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( possible == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) { + if (KOMODO_TEST_ASSETCHAIN_SKIP_POW) return(0); fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); return(-1); } diff --git a/src/test-komodo/test_crosschain.cpp b/src/test-komodo/test_crosschain.cpp index 356a7ab6c..9d24b4d1d 100644 --- a/src/test-komodo/test_crosschain.cpp +++ b/src/test-komodo/test_crosschain.cpp @@ -28,6 +28,7 @@ extern uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); +extern bool KOMODO_TEST_ASSETCHAIN_SKIP_POW; /* @@ -48,6 +49,7 @@ public: protected: static void SetUpTestCase() { } virtual void SetUp() { + KOMODO_TEST_ASSETCHAIN_SKIP_POW = 1; ASSETCHAINS_CC = 1; EVAL_TEST = this; } From f84a3239504603cbecba8e99b95fcec987a3acb6 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 28 May 2018 20:48:56 -0300 Subject: [PATCH 0093/1123] log notarisation parse errors to file --- src/notarisationdb.cpp | 2 +- src/test-komodo/test_parse_notarisation.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 7ef5a0cf8..42a3ae41f 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -24,7 +24,7 @@ NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight) if (ParseNotarisationOpReturn(tx, data)) vNotarisations.push_back(std::make_pair(tx.GetHash(), data)); else - fprintf(stderr, "Warning: Couldn't parse notarisation for tx: %s at height %i\n", + LogPrintf("WARNING: Couldn't parse notarisation for tx: %s at height %i\n", tx.GetHash().GetHex().data(), nHeight); } } diff --git a/src/test-komodo/test_parse_notarisation.cpp b/src/test-komodo/test_parse_notarisation.cpp index 285f98813..a61ca2aa3 100644 --- a/src/test-komodo/test_parse_notarisation.cpp +++ b/src/test-komodo/test_parse_notarisation.cpp @@ -20,4 +20,15 @@ TEST(TestParseNotarisation, test_ee2fa) ASSERT_TRUE(E_UNMARSHAL(opret, ss >> nd)); } +TEST(TestParseNotarisation, test__) +{ + // 576e910a1f704207bcbcf724124ff9adc5237f45cb6919589cd0aa152caec424 + std::vector opret = ParseHex("b3ed7fbbfbc027caeeeec81e65489ec5d9cd47cda675a5cbb75b4a845e67cf0ef6330300b5a6bd8385feb833f3be961c9d8a46fcecd36dcdfa42ad81a20a892433722f0b4b4d44004125a06024eae24c11f36ea110acd707b041d5355b6e1b42de5e2614357999c6aa02000d26ad0300000000404b4c000000000005130300500d000061f22ba7d19fe29ac3baebd839af8b7127d1f90755534400"); + NotarisationData nd; + // We can't parse this one + ASSERT_FALSE(E_UNMARSHAL(opret, ss >> nd)); +} + +// for l in `g 'parse notarisation' ~/.komodo/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/komodo-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done + } From 0ffacf04dcb1d5a97bbb649e1359d03528f18a12 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 28 May 2018 21:02:34 -0300 Subject: [PATCH 0094/1123] take care of some TODOs --- src/cc/eval.cpp | 6 +++++- src/importcoin.cpp | 1 - src/test-komodo/test_coinimport.cpp | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index edd5c6850..2c966f192 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -9,6 +9,7 @@ #include "main.h" #include "chain.h" #include "core_io.h" +#include "crosschain.h" Eval* EVAL_TEST = 0; @@ -165,7 +166,10 @@ bool Eval::GetNotarisationData(const uint256 notaryHash, NotarisationData &data) */ bool Eval::GetProofRoot(uint256 kmdNotarisationHash, uint256 &momom) const { - return false; // TODO + std::pair out; + if (!GetNextBacknotarisation(kmdNotarisationHash, out)) return false; + momom = out.second.MoMoM; + return true; } diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 55717fc69..8b87cb535 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -54,7 +54,6 @@ bool UnmarshalBurnTx(const CTransaction &burnTx, std::string &targetSymbol, uint /* * Required by main - * TODO: test */ CAmount GetCoinImportValue(const CTransaction &tx) { diff --git a/src/test-komodo/test_coinimport.cpp b/src/test-komodo/test_coinimport.cpp index 3cd6eff6e..eac21428a 100644 --- a/src/test-komodo/test_coinimport.cpp +++ b/src/test-komodo/test_coinimport.cpp @@ -248,4 +248,10 @@ TEST_F(TestCoinImport, testMomomCheckFail) EXPECT_EQ("momom-check-fail", state.GetRejectReason()); } + +TEST_F(TestCoinImport, testGetCoinImportValue) +{ + ASSERT_EQ(100, GetCoinImportValue(importTx)); +} + } /* namespace TestCoinImport */ From 69c67b5117cad7bf52ca3189727419e67f965f7b Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 28 May 2018 23:31:42 -0300 Subject: [PATCH 0095/1123] disconnect notarisations --- src/cc/eval.cpp | 1 - src/main.cpp | 19 +++++++++++++------ src/notarisationdb.cpp | 16 +++++++++++++--- src/notarisationdb.h | 3 ++- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 2c966f192..25550d1e2 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -201,7 +201,6 @@ bool ParseNotarisationOpReturn(const CTransaction &tx, NotarisationData &data) /* * Misc */ - std::string EvalToStr(EvalCode c) { FOREACH_EVAL(EVAL_GENERATE_STRING); diff --git a/src/main.cpp b/src/main.cpp index a3bd0f515..2e73f2af0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2482,7 +2482,14 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex RemoveImportTombstone(tx, view); } } - + + // Delete from notarisations cache + NotarisationsInBlock nibs; + if (GetBlockNotarisations(block.GetHash(), nibs)) { + pnotarisations->Erase(block.GetHash()); + EraseBackNotarisations(nibs); + } + // set the old best anchor back view.PopAnchor(blockUndo.old_tree_root); @@ -2502,6 +2509,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex return AbortNode(state, "Failed to write address unspent index"); } } + return fClean; } @@ -2836,13 +2844,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); } - // Record Notarisations NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight); - pnotarisations->Write(block.GetHash(), notarisations); - WriteBackNotarisations(notarisations); // Very important to disconnect this - // TODO: Disconnect? - + if (notarisations.size() > 0) { + pnotarisations->Write(block.GetHash(), notarisations); + WriteBackNotarisations(notarisations); + } view.PushAnchor(tree); if (!fJustCheck) { diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 42a3ae41f..18b9da685 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -47,11 +47,21 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n) /* * Write an index of KMD notarisation id -> backnotarisation */ -void WriteBackNotarisations(NotarisationsInBlock notarisations) +void WriteBackNotarisations(const NotarisationsInBlock notarisations) { - BOOST_FOREACH(Notarisation &n, notarisations) + BOOST_FOREACH(const Notarisation &n, notarisations) { - if (n.second.IsBackNotarisation) + if (!n.second.txHash.IsNull()) pnotarisations->Write(n.second.txHash, n); } } + + +void EraseBackNotarisations(const NotarisationsInBlock notarisations) +{ + BOOST_FOREACH(const Notarisation &n, notarisations) + { + if (!n.second.txHash.IsNull()) + pnotarisations->Erase(n.second.txHash); + } +} diff --git a/src/notarisationdb.h b/src/notarisationdb.h index 0e3d48c00..27f979784 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -21,6 +21,7 @@ typedef std::vector NotarisationsInBlock; NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight); bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs); bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); -void WriteBackNotarisations(NotarisationsInBlock notarisations); +void WriteBackNotarisations(const NotarisationsInBlock notarisations); +void EraseBackNotarisations(const NotarisationsInBlock notarisations); #endif /* NOTARISATIONDB_H */ From 6fd79871df7933ec65b05362f26b84954471b32c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:03:48 -1100 Subject: [PATCH 0096/1123] wallet/rpcwallet.cpp:2701: uint64_t komodo_interestsum(): Assertion` pwalletMain != NULL' failed.` --- src/wallet/rpcwallet.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fce556d33..0b3b45a80 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2696,6 +2696,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { +#ifdef ENABLE_WALLET uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; vector vecOutputs; assert(pwalletMain != NULL); @@ -2719,6 +2720,9 @@ uint64_t komodo_interestsum() KOMODO_INTERESTSUM = sum; KOMODO_WALLETBALANCE = pwalletMain->GetBalance(); return(sum); +#else + return(0); +#endif } UniValue fundrawtransaction(const UniValue& params, bool fHelp) From d9f176ac7ef5abc7f8af299a7a69d015f50f0f8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:43:08 -1100 Subject: [PATCH 0097/1123] Support -ac_pubkey without -ac_perc If ac_pubkey is set, then height 1 out must go to that pub key --- src/komodo_bitcoind.h | 27 ++++++++++++++++++--------- src/komodo_port.c | 2 +- src/komodo_utils.h | 2 +- src/miner.cpp | 13 +++++++++---- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c434e33a3..2ef99c5e3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1333,20 +1333,29 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( is_PoSblock < 0 ) return(-1); } - if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 && ASSETCHAINS_COMMISSION != 0 ) + if ( failed == 0 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { - checktoshis = komodo_commission(pblock); - if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) - return(-1); - else if ( checktoshis != 0 ) + if ( height == 1 ) { - script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + script = (uint8_t *)pblock->vtx[0].vout[0].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)); + } + if ( 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); + } } } } diff --git a/src/komodo_port.c b/src/komodo_port.c index e92da3af1..991be2013 100644 --- a/src/komodo_port.c +++ b/src/komodo_port.c @@ -809,7 +809,7 @@ uint16_t komodo_calcport(char *name,uint64_t supply,uint64_t endsubsidy,uint64_t decay = 0; printf("decay cant be more than 100000000\n"); } - if ( endsubsidy != 0 || reward != 0 || halving != 0 || decay != 0 || commission != 0 || cc != 0 || staked != 0 ) + if ( endsubsidy != 0 || reward != 0 || halving != 0 || decay != 0 || commission != 0 || cc != 0 || staked != 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { //printf("end.%llu reward.%llu halving.%llu decay.%llu perc.%llu\n",(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,(long long)commission); extraptr = extrabuf; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 36766a1f7..119c4d6f4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1559,7 +1559,7 @@ void komodo_args(char *argv0) ASSETCHAINS_DECAY = 0; printf("ASSETCHAINS_DECAY cant be more than 100000000\n"); } - if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 && ASSETCHAINS_COMMISSION > 0 && ASSETCHAINS_COMMISSION <= 100000000 ) + if ( strlen(ASSETCHAINS_OVERRIDE_PUBKEY.c_str()) == 66 ) decode_hex(ASSETCHAINS_OVERRIDE_PUBKEY33,33,(char *)ASSETCHAINS_OVERRIDE_PUBKEY.c_str()); else if ( ASSETCHAINS_COMMISSION != 0 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 264a6e2d4..ff93ca91c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -108,7 +108,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern std::string NOTARY_PUBKEY; +extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; + extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; uint32_t Mining_start,Mining_height; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); @@ -582,10 +583,14 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& // Internal miner // -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) +CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; - if ( USE_EXTERNAL_PUBKEY != 0 ) + if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) + { + scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + } + else if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; @@ -787,7 +792,7 @@ void static BitcoinMiner() sleep(3); } #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From cf1b8419d426e7a7d1c65ce887249a167f6b5d4a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:56:05 -1100 Subject: [PATCH 0098/1123] Add nHeight --- src/rpcmining.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index bd9c45f5d..e3341144a 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -214,7 +214,7 @@ UniValue generate(const UniValue& params, bool fHelp) lastTime = GetTime(); #ifdef ENABLE_WALLET - std::unique_ptr pblocktemplate(CreateNewBlockWithKey(reservekey)); + std::unique_ptr pblocktemplate(CreateNewBlockWithKey(reservekey,nHeight)); #else std::unique_ptr pblocktemplate(CreateNewBlockWithKey()); #endif @@ -639,7 +639,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) } #ifdef ENABLE_WALLET CReserveKey reservekey(pwalletMain); - pblocktemplate = CreateNewBlockWithKey(reservekey); + pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1); #else pblocktemplate = CreateNewBlockWithKey(); #endif From 1afc2472d073a6e6907051f85a057fd912f8aa6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 02:56:49 -1100 Subject: [PATCH 0099/1123] Create block with nHeight --- src/miner.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.h b/src/miner.h index bf1a088f0..684b10187 100644 --- a/src/miner.h +++ b/src/miner.h @@ -30,7 +30,7 @@ struct CBlockTemplate CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn); #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey); -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey); +CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight); #else boost::optional GetMinerScriptPubKey(); CBlockTemplate* CreateNewBlockWithKey(); From 525c7b98a9c62d54b7f1c29e12be343eccd5df8c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:01:05 -1100 Subject: [PATCH 0100/1123] Skip equihash test for regrets --- src/pow.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pow.cpp b/src/pow.cpp index 817dcc1fe..e942883f2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -86,6 +86,8 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param unsigned int n = params.EquihashN(); unsigned int k = params.EquihashK(); + if ( Params().NetworkIDString() == "regtest" ) + return(true); // Hash state crypto_generichash_blake2b_state state; EhInitialiseState(n, k, state); From e2c2eec41a29794dea0f65c9f1eb3f89b63cffd2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:06:13 -1100 Subject: [PATCH 0101/1123] Guard null it->second --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 119967a46..fa402338a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5147,7 +5147,8 @@ void static CheckBlockIndex() // Build forward-pointing map of the entire block tree. std::multimap forward; for (BlockMap::iterator it = mapBlockIndex.begin(); it != mapBlockIndex.end(); it++) { - forward.insert(std::make_pair(it->second->pprev, it->second)); + if ( it->second != 0 ) + forward.insert(std::make_pair(it->second->pprev, it->second)); } assert(forward.size() == mapBlockIndex.size()); From d916630e3a267452ab0a3700fe2e1bc5de8079a6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:08:43 -1100 Subject: [PATCH 0102/1123] Bypass assert in regrets --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fa402338a..34d939431 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5150,8 +5150,8 @@ void static CheckBlockIndex() if ( it->second != 0 ) forward.insert(std::make_pair(it->second->pprev, it->second)); } - - assert(forward.size() == mapBlockIndex.size()); + if ( Params().NetworkIDString() != "regtest" ) + assert(forward.size() == mapBlockIndex.size()); std::pair::iterator,std::multimap::iterator> rangeGenesis = forward.equal_range(NULL); CBlockIndex *pindex = rangeGenesis.first->second; From 528f340601cd6aca31341623a27d291b8ea6a0ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:15:29 -1100 Subject: [PATCH 0103/1123] -print --- src/komodo.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 36c7c2ef3..d01de9553 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -201,8 +201,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals); //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); - } - else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); + } // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); return(func); } else return(-1); } @@ -342,8 +341,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long komodo_eventadd_pricefeed(sp,symbol,ht,pvals,numpvals); //printf("load pvals ht.%d numpvals.%d\n",ht,numpvals); } else printf("error loading pvals[%d]\n",numpvals); - } - else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); + } // else printf("[%s] %s illegal func.(%d %c)\n",ASSETCHAINS_SYMBOL,symbol,func,func); *fposp = fpos; return(func); } From 2d79309f33ed4fdb819170f2db15e856de62d16d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:25:26 -1100 Subject: [PATCH 0104/1123] unburn Notary vin txfee --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index ff93ca91c..e86902a92 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -479,11 +479,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nTime = pindexPrev->nTime + 65; if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 ) { - CAmount txfees = 0; + CAmount txfees = 5000; pblock->vtx.push_back(txNotary); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary)); nFees += txfees; + pblocktemplate->vTxFees[0] = -nFees; + pblock->vtx[0].vout[0].nValue += txfees; //fprintf(stderr,"added notaryvin\n"); } else From c255db29b37e1ac2d35e1e6477c7603b2f6f93d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:29:06 -1100 Subject: [PATCH 0105/1123] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e86902a92..9863c8139 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -485,7 +485,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary)); nFees += txfees; pblocktemplate->vTxFees[0] = -nFees; - pblock->vtx[0].vout[0].nValue += txfees; + *(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; //fprintf(stderr,"added notaryvin\n"); } else From c881e52b6ef23c1dc0df6a95d13ebe5429270a91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 03:41:03 -1100 Subject: [PATCH 0106/1123] Revert --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9863c8139..c789eb41d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -485,7 +485,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txNotary)); nFees += txfees; pblocktemplate->vTxFees[0] = -nFees; - *(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; + //*(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; //fprintf(stderr,"added notaryvin\n"); } else From fb6bb4e82ebbaee6cf1ebbbd3c9de6ff0bc68ecd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 04:18:31 -1100 Subject: [PATCH 0107/1123] fix -ac_perc --- src/komodo_bitcoind.h | 42 +++++++++++++++++++++++++----------------- src/komodo_gateway.h | 19 ++++++++++++++----- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2ef99c5e3..b48c40442 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1265,6 +1265,29 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ return(isPoS); } +int64_t komodo_checkcommission(CBlock *pblock,int32_t height) +{ + int64_t checktoshis=0; uint8_t *script; + if ( 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,"ht.%d checktoshis %.8f vs actual vout[1] %.8f\n",height,dstr(checktoshis),dstr(pblock->vtx[0].vout[1].nValue)); + return(-1); + } + } + } + return(checktoshis); +} + 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; @@ -1341,23 +1364,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); } - if ( 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); - } - } - } + if ( komodo_checkcommission(pblock,height) < 0 ) + 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 ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 410e106ae..283c2ef0c 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,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; + 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,seed; int64_t checktoshis,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))); @@ -743,11 +743,20 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } else { - if ( overflow != 0 || total > 0 || strangeout != 0 ) + checktoshis = 0; + if ( ASSETCHAINS_COMMISSION != 0 ) { - if ( strangeout != 0 ) - fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched); - return(-1); + if ( (checktoshis= komodo_checkcommission(&block,height)) < 0 ) + return(-1); + } + else + { + if ( overflow != 0 || total > checktoshis || 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 44bbf01edf6b4f522132cfe4e52c973d901c93bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 04:22:02 -1100 Subject: [PATCH 0108/1123] Fix --- src/komodo_gateway.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 283c2ef0c..55ab8b477 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -746,7 +746,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim checktoshis = 0; if ( ASSETCHAINS_COMMISSION != 0 ) { - if ( (checktoshis= komodo_checkcommission(&block,height)) < 0 ) + if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 ) return(-1); } else From dc241f13d0460b094f911d0f58d5b04325e72d7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 05:30:21 -1100 Subject: [PATCH 0109/1123] Special case ht.1 --- src/komodo_gateway.h | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 55ab8b477..3b2922a7b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -744,7 +744,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim else { checktoshis = 0; - if ( ASSETCHAINS_COMMISSION != 0 ) + if ( ASSETCHAINS_COMMISSION != 0 && height > 1 ) { if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 ) return(-1); diff --git a/src/miner.cpp b/src/miner.cpp index c789eb41d..081796aaa 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -440,7 +440,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; 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 ( nHeight > 1 && 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 c9855c14864df71b7cfc332c1af02b9941c67137 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 08:34:47 -1100 Subject: [PATCH 0110/1123] Height 1 exclusion -ac_pubkey --- src/komodo_bitcoind.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b48c40442..5b19dfb6f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1364,8 +1364,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); } - if ( komodo_checkcommission(pblock,height) < 0 ) - return(-1); + else + { + if ( komodo_checkcommission(pblock,height) < 0 ) + 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 ) From c7bcf05da45c7276b5dfe03ea3b49b13c7bb20fa Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 30 May 2018 18:12:05 -0300 Subject: [PATCH 0111/1123] fix MoM hash calculation --- src/crosschain.cpp | 20 ++++++++++-------- src/komodo_ccdata.h | 45 ++++++++-------------------------------- src/primitives/block.cpp | 15 ++++++++++---- src/primitives/block.h | 2 ++ src/rpcclient.cpp | 4 ---- src/rpccrosschain.cpp | 15 +++++++------- 6 files changed, 41 insertions(+), 60 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index dc45e994c..0e9861cf8 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -182,6 +182,8 @@ struct notarized_checkpoint* komodo_npptr(int32_t height); int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip); +uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth); + /* * On assetchain * in: txid @@ -210,20 +212,20 @@ TxProof GetAssetchainProof(uint256 hash) // build merkle chain from blocks to MoM { - // since the merkle branch code is tied up in a block class - // and we want to make a merkle branch for something that isnt transactions - CBlock fakeBlock; + std::vector leaves, tree; for (int i=0; iMoMdepth; i++) { uint256 mRoot = chainActive[np->notarized_height - i]->hashMerkleRoot; - CTransaction fakeTx; - // first value in CTransaction memory is it's hash - memcpy((void*)&fakeTx, mRoot.begin(), 32); - fakeBlock.vtx.push_back(fakeTx); + leaves.push_back(mRoot); } - branch = fakeBlock.GetMerkleBranch(nIndex); + bool fMutated; + BuildMerkleTree(&fMutated, leaves, tree); + branch = GetMerkleBranch(nIndex, leaves.size(), tree); // Check branch - if (np->MoM != CBlock::CheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex)) + uint256 komodoGets = komodo_calcMoM(np->notarized_height, np->MoMdepth); + uint256 ourResult = SafeCheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex); + printf("Komodo gets:%s, we get:%s\n", komodoGets.GetHex().data(), ourResult.GetHex().data()); + if (np->MoM != ourResult) throw std::runtime_error("Failed merkle block->MoM"); } diff --git a/src/komodo_ccdata.h b/src/komodo_ccdata.h index 058e38cee..637d13557 100644 --- a/src/komodo_ccdata.h +++ b/src/komodo_ccdata.h @@ -19,53 +19,28 @@ struct komodo_ccdata *CC_data; int32_t CC_firstheight; -bits256 iguana_merkle(bits256 *tree,int32_t txn_count) -{ - int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2]; - if ( txn_count == 1 ) - return(tree[0]); - prev = 0; - while ( txn_count > 1 ) - { - if ( (txn_count & 1) != 0 ) - tree[prev + txn_count] = tree[prev + txn_count-1], txn_count++; - n += txn_count; - for (i=0; i> 1)] = bits256_doublesha256(0,serialized,sizeof(serialized)); - } - prev = n; - txn_count >>= 1; - } - return(tree[n]); -} +uint256 BuildMerkleTree(bool* fMutated, const std::vector leaves, std::vector &vMerkleTree); uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth) { - static uint256 zero; bits256 MoM,*tree; CBlockIndex *pindex; int32_t i; + static uint256 zero; CBlockIndex *pindex; int32_t i; std::vector tree, leaves; + bool fMutated; if ( MoMdepth >= height ) return(zero); - tree = (bits256 *)calloc(MoMdepth * 3,sizeof(*tree)); for (i=0; ihashMerkleRoot,sizeof(bits256)); + leaves.push_back(pindex->hashMerkleRoot); else - { - free(tree); return(zero); - } } - MoM = iguana_merkle(tree,MoMdepth); - free(tree); - return(*(uint256 *)&MoM); + return BuildMerkleTree(&fMutated, leaves, tree); } struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi) { - struct komodo_ccdata_entry *allMoMs=0; bits256 *tree,tmp; struct komodo_ccdata *ccdata,*tmpptr; int32_t i,num,max; + struct komodo_ccdata_entry *allMoMs=0; struct komodo_ccdata *ccdata,*tmpptr; int32_t i,num,max; + bool fMutated; std::vector tree, leaves; num = max = 0; portable_mutex_lock(&KOMODO_CC_mutex); DL_FOREACH_SAFE(CC_data,ccdata,tmpptr) @@ -90,11 +65,9 @@ struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t portable_mutex_unlock(&KOMODO_CC_mutex); if ( (*nump= num) > 0 ) { - tree = (bits256 *)calloc(sizeof(bits256),num*3); for (i=0; i CBlock::GetMerkleBranch(int nIndex) const +std::vector GetMerkleBranch(int nIndex, int nLeaves, const std::vector &vMerkleTree) { - if (vMerkleTree.empty()) - BuildMerkleTree(); std::vector vMerkleBranch; int j = 0; - for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2) + for (int nSize = nLeaves; nSize > 1; nSize = (nSize + 1) / 2) { int i = std::min(nIndex^1, nSize-1); vMerkleBranch.push_back(vMerkleTree[j+i]); @@ -106,6 +104,15 @@ std::vector CBlock::GetMerkleBranch(int nIndex) const return vMerkleBranch; } + +std::vector CBlock::GetMerkleBranch(int nIndex) const +{ + if (vMerkleTree.empty()) + BuildMerkleTree(); + return ::GetMerkleBranch(nIndex, vtx.size(), vMerkleTree); +} + + uint256 CBlock::CheckMerkleBranch(uint256 hash, const std::vector& vMerkleBranch, int nIndex) { if (nIndex == -1) diff --git a/src/primitives/block.h b/src/primitives/block.h index 2d3c0cfe4..6bc06f426 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -142,6 +142,8 @@ public: uint256 BuildMerkleTree(bool* fMutated, const std::vector leaves, std::vector &vMerkleTree); +std::vector GetMerkleBranch(int nIndex, int nLeaves, const std::vector &vMerkleTree); + /** * Custom serializer for CBlockHeader that omits the nonce and solution, for use diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index f93dbbb0f..e84e9085c 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -149,10 +149,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "height_MoM", 1}, { "MoMoMdata", 3}, { "calc_MoM", 2}, - { "migrate_converttoexport", 3}, - { "migrate_createimporttransaction", 2}, - { "migrate_completeimporttransaction", 1} - }; class CRPCConvertTable diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 3aed3a2bb..a4b0cb503 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -145,7 +145,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 3) throw runtime_error( - "migrate_converttoexport rawTx dest_symbol burn_amount\n" + "migrate_converttoexport rawTx dest_symbol export_amount\n" "\nConvert a raw transaction to a cross-chain export.\n" "If neccesary, the transaction should be funded using fundrawtransaction.\n" "Finally, the transaction should be signed using signrawtransaction\n" @@ -169,13 +169,14 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); - CAmount burnAmount = params[2].get_int64(); + CAmount burnAmount = AmountFromValue(params[2]); + if (burnAmount <= 0) + throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export"); { - CAmount needed; - for (int i=0; i payouts; - if (!E_UNMARSHAL(ParseHexV(params[0], "argument 2"), ss >> payouts)) + if (!E_UNMARSHAL(ParseHexV(params[1], "argument 2"), ss >> payouts)) throw runtime_error("Couldn't parse payouts"); uint256 txid = burnTx.GetHash(); From 44b541d92fd5f84a7c1470836d38e72e8b44b03f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 10:52:43 -1100 Subject: [PATCH 0112/1123] Add VRSC to assetchains.old --- src/assetchains.old | 65 +-------------------------------------------- 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/src/assetchains.old b/src/assetchains.old index cf46922de..af9361746 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -34,68 +34,5 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & -#sleep $delay +~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & -#./komodod -pubkey=$pubkey -ac_name=USD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=EUR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=JPY -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=GBP -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=AUD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CAD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CHF -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=NZD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CNY -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=RUB -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=MXN -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=BRL -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=INR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=HKD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=TRY -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=ZAR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=PLN -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=NOK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=SEK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=DKK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=CZK -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=HUF -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=ILS -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=KRW -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=MYR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=PHP -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=RON -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=SGD -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=THB -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=BGN -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=IDR -addnode=78.47.196.146 $1 & -#sleep $delay -#./komodod -pubkey=$pubkey -ac_name=HRK -addnode=78.47.196.146 $1 & From b6e71fe96c8bc1518ab58a8c48f488095de07e5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 12:30:16 -1100 Subject: [PATCH 0113/1123] Encode Ccid into upper MoMdepth --- src/komodo.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d01de9553..efb59dee1 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -113,7 +113,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char if ( fread(&MoMdepth,1,sizeof(MoMdepth),fp) != sizeof(MoMdepth) ) errs++; if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) - printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth); + printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else { @@ -258,7 +258,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long if ( memread(&MoMdepth,sizeof(MoMdepth),filedata,&fpos,datalen) != sizeof(MoMdepth) ) errs++; if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) - printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth); + printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else { @@ -480,7 +480,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar //printf("ht.%d func N ht.%d errs.%d\n",height,NOTARIZED_HEIGHT,errs); if ( sp != 0 ) { - if ( sp->MoMdepth > 0 && sp->MoM != zero ) + if ( sp->MoMdepth != 0 && sp->MoM != zero ) fputc('M',fp); else fputc('N',fp); if ( fwrite(&height,1,sizeof(height),fp) != sizeof(height) ) @@ -491,7 +491,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar errs++; if ( fwrite(&sp->NOTARIZED_DESTTXID,1,sizeof(sp->NOTARIZED_DESTTXID),fp) != sizeof(sp->NOTARIZED_DESTTXID) ) errs++; - if ( sp->MoMdepth > 0 && sp->MoM != zero ) + if ( sp->MoMdepth != 0 && sp->MoM != zero ) { if ( fwrite(&sp->MoM,1,sizeof(sp->MoM),fp) != sizeof(sp->MoM) ) errs++; @@ -641,10 +641,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM); len += iguana_rwnum(0,&scriptbuf[len],sizeof(MoMdepth),(uint8_t *)&MoMdepth); ccdata.MoMdata.MoM = MoM; - ccdata.MoMdata.MoMdepth = MoMdepth; + ccdata.MoMdata.MoMdepth = MoMdepth & 0xffff; if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen ) { len += iguana_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid); + if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) + fprintf(stderr,"%s CCid mismatch %u != %u\n",ASSETCHAINS_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); ccdata.len = sizeof(ccdata.CCid); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { @@ -670,7 +672,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else ccdata.len = MoMoMdata.len = 0; } } - if ( MoM == zero || MoMdepth > *notarizedheightp || MoMdepth < 0 ) + if ( MoM == zero || (MoMdepth&0xffff) > *notarizedheightp || (MoMdepth&0xffff) < 0 ) { memset(&MoM,0,sizeof(MoM)); MoMdepth = 0; @@ -679,7 +681,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr { komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata); if ( matched != 0 ) - printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth); + printf("[%s] matched.%d VALID (%s) MoM.%s [%d] CCid.%u\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } if ( MoMoMdata.pairs != 0 ) free(MoMoMdata.pairs); @@ -693,7 +695,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; sp->NOTARIZED_DESTTXID = desttxid; - if ( MoM != zero && MoMdepth > 0 ) + if ( MoM != zero && (MoMdepth&0xffff) > 0 ) { sp->MoM = MoM; sp->MoMdepth = MoMdepth; From 1b9f98cd1980493f995c5c1bef0f12d8b81c0397 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 30 May 2018 12:57:21 -1100 Subject: [PATCH 0114/1123] Truncate MoMdepth --- src/komodo_bitcoind.h | 2 +- src/komodo_ccdata.h | 1 + src/komodo_notary.h | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5b19dfb6f..24f510b8b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -932,7 +932,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in memset(MoMp,0,sizeof(*MoMp)); memset(kmdtxidp,0,sizeof(*kmdtxidp)); *notarized_heightp = 0; - if ( depth > 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht ) + if ( depth != 0 && notarized_ht > 0 && nHeight > notarized_ht-depth && nHeight <= notarized_ht ) { *MoMp = MoM; *notarized_heightp = notarized_ht; diff --git a/src/komodo_ccdata.h b/src/komodo_ccdata.h index 058e38cee..6e7d0fabe 100644 --- a/src/komodo_ccdata.h +++ b/src/komodo_ccdata.h @@ -45,6 +45,7 @@ bits256 iguana_merkle(bits256 *tree,int32_t txn_count) uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth) { static uint256 zero; bits256 MoM,*tree; CBlockIndex *pindex; int32_t i; + MoMdepth &= 0xffff; if ( MoMdepth >= height ) return(zero); tree = (bits256 *)calloc(MoMdepth * 3,sizeof(*tree)); diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 25a03f83b..f83f85afe 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -392,7 +392,7 @@ struct notarized_checkpoint *komodo_npptr(int32_t height) for (i=sp->NUM_NPOINTS-1; i>=0; i--) { np = &sp->NPOINTS[i]; - if ( np->MoMdepth > 0 && height > np->notarized_height-np->MoMdepth && height <= np->notarized_height ) + if ( np->MoMdepth != 0 && height > np->notarized_height-(np->MoMdepth&0xffff) && height <= np->notarized_height ) return(np); } } @@ -447,7 +447,7 @@ int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,in *MoMoMdepthp = np->MoMoMdepth; *kmdstartip = np->kmdstarti; *kmdendip = np->kmdendi; - return(np->MoMdepth); + return(np->MoMdepth & 0xffff); } *notarized_htp = *MoMoMoffsetp = *MoMoMdepthp = *kmdstartip = *kmdendip = 0; memset(MoMp,0,sizeof(*MoMp)); From 91d929221c941491cfba787b707e6cf64723fe79 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 30 May 2018 21:25:44 -0300 Subject: [PATCH 0115/1123] update ccid location in notarisation data --- src/cc/eval.h | 6 +++--- src/crosschain.cpp | 9 +++------ src/rpcclient.cpp | 1 - src/rpccrosschain.cpp | 2 +- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/cc/eval.h b/src/cc/eval.h index e4c6a467d..43cdadea7 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -131,8 +131,8 @@ public: uint256 txHash; char symbol[64] = "\0"; uint256 MoM; - uint32_t MoMDepth; - uint32_t ccId; + uint16_t MoMDepth; + uint16_t ccId; uint256 MoMoM; uint32_t MoMoMDepth; @@ -154,8 +154,8 @@ public: if (s.size() == 0) return; READWRITE(MoM); READWRITE(MoMDepth); - if (s.size() == 0) return; READWRITE(ccId); + if (s.size() == 0) return; if (IsBack) { READWRITE(MoMoM); READWRITE(MoMoMDepth); diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 0e9861cf8..3eb618bd7 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -180,10 +180,6 @@ bool GetNextBacknotarisation(uint256 kmdNotarisationTxid, std::pairnHeight))) throw std::runtime_error("notarisation not found"); @@ -222,9 +221,7 @@ TxProof GetAssetchainProof(uint256 hash) branch = GetMerkleBranch(nIndex, leaves.size(), tree); // Check branch - uint256 komodoGets = komodo_calcMoM(np->notarized_height, np->MoMdepth); uint256 ourResult = SafeCheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex); - printf("Komodo gets:%s, we get:%s\n", komodoGets.GetHex().data(), ourResult.GetHex().data()); if (np->MoM != ourResult) throw std::runtime_error("Failed merkle block->MoM"); } diff --git a/src/rpcclient.cpp b/src/rpcclient.cpp index e84e9085c..9d1d0b336 100644 --- a/src/rpcclient.cpp +++ b/src/rpcclient.cpp @@ -147,7 +147,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { "crosschainproof", 1}, { "getproofroot", 2}, { "height_MoM", 1}, - { "MoMoMdata", 3}, { "calc_MoM", 2}, }; diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index a4b0cb503..c99581406 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -115,7 +115,7 @@ UniValue MoMoMdata(const UniValue& params, bool fHelp) ret.push_back(Pair("MoMs", valMoms)); ret.push_back(Pair("notarization_hash", destNotarisationTxid.GetHex())); ret.push_back(Pair("MoMoM", MoMoM.GetHex())); - auto vmomomdata = E_MARSHAL(ss << ccid; ss << MoMoM; ss << ((uint32_t)0)); + auto vmomomdata = E_MARSHAL(ss << MoMoM; ss << ((uint32_t)0)); ret.push_back(Pair("data", HexStr(vmomomdata))); return ret; } From 627aaf734b425f0bb608f17ed73576de3c295988 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 31 May 2018 05:07:18 -1100 Subject: [PATCH 0116/1123] Skip invalid Ccid compare --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index efb59dee1..248396812 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -645,8 +645,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen ) { len += iguana_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid); - if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) - fprintf(stderr,"%s CCid mismatch %u != %u\n",ASSETCHAINS_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); + //if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) + // fprintf(stderr,"%s CCid mismatch %u != %u\n",ASSETCHAINS_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); ccdata.len = sizeof(ccdata.CCid); if ( ASSETCHAINS_SYMBOL[0] != 0 ) { From 379e23fcec151742aa04c8d80d297821957db1da Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Thu, 31 May 2018 15:19:46 -0300 Subject: [PATCH 0117/1123] allow TXSCL notarisations without notary inputs --- src/notarisationdb.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 18b9da685..3087a563f 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -19,10 +19,24 @@ NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight) for (unsigned int i = 0; i < block.vtx.size(); i++) { CTransaction tx = block.vtx[i]; - if (eval->CheckNotaryInputs(tx, nHeight, block.nTime)) { + + // Special case for TXSCL. Should prob be removed at some point. + bool isTxscl = 0; + { NotarisationData data; if (ParseNotarisationOpReturn(tx, data)) + if (strlen(data.symbol) >= 5 && strncmp(data.symbol, "TXSCL", 5) == 0) + isTxscl = 1; + } + + if (isTxscl || eval->CheckNotaryInputs(tx, nHeight, block.nTime)) { + NotarisationData data; + if (ParseNotarisationOpReturn(tx, data)) { vNotarisations.push_back(std::make_pair(tx.GetHash(), data)); + //printf("Parsed a notarisation for: %s, txid:%s, ccid:%i, momdepth:%i\n", + // data.symbol, tx.GetHash().GetHex().data(), data.ccId, data.MoMDepth); + //if (!data.MoMoM.IsNull()) printf("MoMoM:%s\n", data.MoMoM.GetHex().data()); + } else LogPrintf("WARNING: Couldn't parse notarisation for tx: %s at height %i\n", tx.GetHash().GetHex().data(), nHeight); From fe98fc34b916c3f480df1ee65b4e9b56d363626d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 03:30:25 -1100 Subject: [PATCH 0118/1123] Nameoffset --- src/komodo.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 248396812..9b069624b 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -603,9 +603,12 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } offset = 32 * (1 + matched) + 4; nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]); - if ( nameoffset == 2 ) + /*if ( nameoffset == 2 ) nameoffset += 2; - else nameoffset++; + else if ( nameoffset == 1 ) + nameoffset += 3; + else*/ + nameoffset++; memset(&ccdata,0,sizeof(ccdata)); strncpy(ccdata.symbol,(char *)&scriptbuf[len+offset],sizeof(ccdata.symbol)); if ( j == 1 && opretlen >= len+offset-opoffset ) @@ -635,7 +638,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr ccdata.MoMdata.notarized_height = *notarizedheightp; ccdata.MoMdata.height = height; ccdata.MoMdata.txi = i; - //printf("nameoffset.%d len.%d + 36 %d vs opretlen.%d\n",nameoffset,len,len+36,opretlen); + printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); if ( len+36-opoffset <= opretlen ) { len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM); From 4a15f78eada27e2a254b2621ae57e75c38fecc8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 04:02:42 -1100 Subject: [PATCH 0119/1123] Kv test --- src/komodo.h | 9 ++------- src/komodo_kv.h | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 9b069624b..c6c523683 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -603,12 +603,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } offset = 32 * (1 + matched) + 4; nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]); - /*if ( nameoffset == 2 ) - nameoffset += 2; - else if ( nameoffset == 1 ) - nameoffset += 3; - else*/ - nameoffset++; + nameoffset++; memset(&ccdata,0,sizeof(ccdata)); strncpy(ccdata.symbol,(char *)&scriptbuf[len+offset],sizeof(ccdata.symbol)); if ( j == 1 && opretlen >= len+offset-opoffset ) @@ -638,7 +633,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr ccdata.MoMdata.notarized_height = *notarizedheightp; ccdata.MoMdata.height = height; ccdata.MoMdata.txi = i; - printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); + //printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); if ( len+36-opoffset <= opretlen ) { len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM); diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 58d550414..dbcf99f6c 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -64,7 +64,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp if ( ptr != 0 ) { duration = komodo_kvduration(ptr->flags); - //printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); + printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); if ( current_height > (ptr->height + duration) ) { HASH_DELETE(hh,KOMODO_KV,ptr); @@ -171,7 +171,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) memcpy(ptr->key,key,keylen); newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); - //printf("KV add.(%s) (%s)\n",ptr->key,valueptr); + printf("KV add.(%s) (%s)\n",ptr->key,valueptr); } if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) { From 29806831f29e0f3acfa009d03102df9f1dc6f529 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 04:08:08 -1100 Subject: [PATCH 0120/1123] Print --- src/komodo_kv.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index dbcf99f6c..0b0b21161 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -64,7 +64,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp if ( ptr != 0 ) { duration = komodo_kvduration(ptr->flags); - printf("duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); + fprintf(stderr,"duration.%d flags.%d current.%d ht.%d keylen.%d valuesize.%d\n",duration,ptr->flags,current_height,ptr->height,ptr->keylen,ptr->valuesize); if ( current_height > (ptr->height + duration) ) { HASH_DELETE(hh,KOMODO_KV,ptr); @@ -171,7 +171,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) memcpy(ptr->key,key,keylen); newflag = 1; HASH_ADD_KEYPTR(hh,KOMODO_KV,ptr->key,ptr->keylen,ptr); - printf("KV add.(%s) (%s)\n",ptr->key,valueptr); + fprintf(stderr,"KV add.(%s) (%s)\n",ptr->key,valueptr); } if ( newflag != 0 || (ptr->flags & KOMODO_KVPROTECTED) == 0 ) { From ebe5e09afe2cc5694ebecfb45ef60f6e40d8a839 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 04:10:52 -1100 Subject: [PATCH 0121/1123] Test --- src/komodo_kv.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 0b0b21161..116924b5a 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -88,7 +88,7 @@ int32_t komodo_kvsearch(uint256 *pubkeyp,int32_t current_height,uint32_t *flagsp if ( (retval= ptr->valuesize) > 0 ) memcpy(value,ptr->value,retval); } - } + } else fprintf(stderr,"couldnt find (%s)\n",(char *)key); portable_mutex_unlock(&KOMODO_KV_mutex); if ( retval < 0 ) { @@ -151,6 +151,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) HASH_FIND(hh,KOMODO_KV,key,keylen,ptr); if ( ptr != 0 ) { + fprintf(stderr,"(%s) already there\n",(char *)key); //if ( (ptr->flags & KOMODO_KVPROTECTED) != 0 ) { tstr = (char *)"transfer:"; From 3f1012ff4c136b2e7d7630b4816a7e0621171ac2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 04:15:07 -1100 Subject: [PATCH 0122/1123] Test --- src/komodo_kv.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 116924b5a..80fac5ff8 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -111,13 +111,13 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) if ( keylen+13 > opretlen ) { static uint32_t counter; - if ( ++counter < 1 ) - printf("komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen); + if ( ++counter < 100 ) + fprintf(stderr,"komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen); return; } valueptr = &key[keylen]; fee = komodo_kvfee(flags,opretlen,keylen); - //printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); if ( value >= fee ) { coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1); @@ -142,7 +142,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) { if ( komodo_kvsigverify(keyvalue,keylen+refvaluesize,refpubkey,sig) < 0 ) { - printf("komodo_kvsigverify error [%d]\n",coresize-13); + fprintf(stderr,"komodo_kvsigverify error [%d]\n",coresize-13); return; } } @@ -194,7 +194,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) ptr->height = height; ptr->flags = flags; // jl777 used to or in KVPROTECTED portable_mutex_unlock(&KOMODO_KV_mutex); - } else fprintf(stderr,"size mismatch %d vs %d\n",opretlen,coresize); + } else fprintf(stderr,"KV update size mismatch %d vs %d\n",opretlen,coresize); } else fprintf(stderr,"not enough fee\n"); } From 4263c6935d12c93287b071f69a106199698656cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 04:19:53 -1100 Subject: [PATCH 0123/1123] Prints --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c6c523683..79d511db2 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -311,7 +311,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long { if ( memread(opret,olen,filedata,&fpos,datalen) != olen ) errs++; - if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) + if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && matched != 0 ) { int32_t i; for (i=0; i Date: Fri, 1 Jun 2018 04:29:16 -1100 Subject: [PATCH 0124/1123] Fix state update --- src/komodo.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 79d511db2..c94dc0ece 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -717,13 +717,13 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr fwrite(&signedmask,1,sizeof(signedmask),signedfp); fflush(signedfp); } - if ( opretlen > len && scriptbuf[len] == 'A' ) - { - //for (i=0; i len && scriptbuf[len] == 'A' ) + { + for (i=0; i 600000 && matched != 0 ) From dd801e5d470238ae096b9875300e318d9b107e7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 04:43:42 -1100 Subject: [PATCH 0125/1123] Test --- src/komodo.h | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index c94dc0ece..0a0fa2cd8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -601,6 +601,11 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) matched = 1; } + if ( scriptbuf[len] == 'K' ) + { + fprintf(stderr,"KV OPRET len.%d\n",opretlen); + return(-1); + } offset = 32 * (1 + matched) + 4; nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]); nameoffset++; @@ -717,13 +722,13 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr fwrite(&signedmask,1,sizeof(signedmask),signedfp); fflush(signedfp); } - } - if ( opretlen > len && scriptbuf[len] == 'A' ) - { - for (i=0; i len && scriptbuf[len] == 'A' ) + { + //for (i=0; i 600000 && matched != 0 ) From b8fef917d954595dafb583d7b13ed90ef825fcb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 04:46:41 -1100 Subject: [PATCH 0126/1123] Test --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 0a0fa2cd8..d69768e8f 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -603,7 +603,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } if ( scriptbuf[len] == 'K' ) { - fprintf(stderr,"KV OPRET len.%d\n",opretlen); + fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value)); return(-1); } offset = 32 * (1 + matched) + 4; From 265f4e9675a2c525396d925a1baf4da74e6f3608 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 05:44:42 -1100 Subject: [PATCH 0127/1123] Print --- src/miner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 081796aaa..79e5d619c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -957,9 +957,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - if ( h > hashTarget ) - return false; - /*for (z=31; z>=16; z--) + for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -967,7 +965,9 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n");*/ + fprintf(stderr," POW\n"); + if ( h > hashTarget ) + return false; if ( NOTARY_PUBKEY33[0] != 0 && B.nTime > GetAdjustedTime() ) { fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); From 2515c9f22a161519a2f893a22bab172fb3885342 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 05:52:39 -1100 Subject: [PATCH 0128/1123] First 10 blocks as normal --- src/komodo_bitcoind.h | 2 +- src/miner.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 24f510b8b..5f96bf2b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,7 +1147,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { 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 ) + if ( height < 10 ) return(target); sum = arith_uint256(0); ave = sum; diff --git a/src/miner.cpp b/src/miner.cpp index 79e5d619c..9dd800cdd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -940,7 +940,7 @@ void static BitcoinMiner() // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); arith_uint256 hashTarget; - if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) + if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; std::function)> validBlock = From e83bf6b3cbbc701dd0eae09a5ef0010625af8317 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:05:23 -1100 Subject: [PATCH 0129/1123] Fix PoS PoW diff --- src/komodo_bitcoind.h | 5 ++++- src/main.cpp | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5f96bf2b8..5b605a4aa 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1154,6 +1154,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he for (i=n=0; i<100; i++) { ht = height - 100 + i; + if ( ht <= 1 ) + continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); @@ -1341,7 +1343,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - else bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound + else if ( height > 100 ) + bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound if ( bhash > bnTarget ) { for (i=31; i>=16; i--) diff --git a/src/main.cpp b/src/main.cpp index 34d939431..12433f1e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4273,7 +4273,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo 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); + //fprintf(stderr,"passed checkblock but failed checkPOW.%d\n",from_miner && ASSETCHAINS_STAKED == 0); } if (!checked && futureblock == 0) { From 3753f56834d0baf9452098c962cd8a6249988a41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:16:44 -1100 Subject: [PATCH 0130/1123] Test --- src/komodo_bitcoind.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5b605a4aa..83f3bb518 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,7 +1147,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; - if ( height < 10 ) + if ( height <= 10 ) return(target); sum = arith_uint256(0); ave = sum; @@ -1161,7 +1161,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he 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 + if ( hashval <= bnTarget ) // PoW is never as easy as PoS/16, some PoS will be counted as PoW { fprintf(stderr,"1"); sum += hashval; @@ -1176,7 +1176,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr," %d, ",percPoS); } } - fprintf(stderr," -> %d%% percPoS ht.%d\n",percPoS,height); + if ( n < 100 ) + percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; + fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( n > 0 ) @@ -1188,16 +1190,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he 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--) From a2ec2aaad257d27d787e9dd9656d2c56d10db28c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:25:31 -1100 Subject: [PATCH 0131/1123] Stake best utxo --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9dd800cdd..3c07fbb16 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -415,14 +415,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( GetAdjustedTime() < blocktime-13 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-13 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - //printf("PoS ht.%d t%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime); + printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,GetAdjustedTime() - (blocktime-13)); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } From 535f0c1a2c31188f53c27c1eb75cf89771f737a5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:26:38 -1100 Subject: [PATCH 0132/1123] Syntax --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3c07fbb16..08f3da2be 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -422,7 +422,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,GetAdjustedTime() - (blocktime-13)); + printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } From 7e679101e1a2afab6893e82d582945c81b0920a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:33:50 -1100 Subject: [PATCH 0133/1123] Print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 83f3bb518..fd8b19a55 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1128,7 +1128,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); @@ -1138,7 +1138,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh 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 ) + if ( nHeight < 10 ) return(blocktime); return(blocktime * winner); } From 2214fc14b8d44ce081566a7abd116641f648a2c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:39:23 -1100 Subject: [PATCH 0134/1123] Prints --- src/miner.cpp | 2 -- src/wallet/rpcwallet.cpp | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 08f3da2be..dfad0f402 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -410,8 +410,6 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); - //if ( blocktime > pindexPrev->GetMedianTimePast()+60 ) - // blocktime = pindexPrev->GetMedianTimePast() + 60; if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0b3b45a80..bac222f63 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4590,7 +4590,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { @@ -4632,9 +4632,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; i Date: Fri, 1 Jun 2018 06:45:45 -1100 Subject: [PATCH 0135/1123] -print --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index dfad0f402..ef943b3aa 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -955,7 +955,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - for (z=31; z>=16; z--) + /*for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -963,7 +963,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n"); + fprintf(stderr," POW\n");*/ if ( h > hashTarget ) return false; if ( NOTARY_PUBKEY33[0] != 0 && B.nTime > GetAdjustedTime() ) From 2e4cc2a27f65b18335190497036139cc9c2ece94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:54:14 -1100 Subject: [PATCH 0136/1123] Test --- src/wallet/rpcwallet.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bac222f63..b09e656b8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4550,7 +4550,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) 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) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 9999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4562,14 +4562,23 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + { + fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; + } if ( setAddress.size() ) { CTxDestination address; if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + { + fprintf(stderr,"komodo_staked ExtractDestination error\n"); continue; + } if (!setAddress.count(address)) + { + fprintf(stderr,"komodo_staked setAddress.count error\n"); continue; + } } CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; @@ -4602,8 +4611,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *txtimep = (uint32_t)out.tx->nLockTime; fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } - } - } + } else fprintf(stderr,"%s not eligible\n",out.tx->GetHash().c_str()); + } else fprintf(stderr,"no tipindex\n"); } if ( earliest != 0 ) { From 65777b40ab38cbea4b5d93969da99c4e85826b7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:56:35 -1100 Subject: [PATCH 0137/1123] Syntax --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b09e656b8..5bb4a74aa 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4611,7 +4611,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *txtimep = (uint32_t)out.tx->nLockTime; fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } - } else fprintf(stderr,"%s not eligible\n",out.tx->GetHash().c_str()); + } else fprintf(stderr,"%s not eligible\n",out.tx->GetHash()); } else fprintf(stderr,"no tipindex\n"); } if ( earliest != 0 ) From 3851fb86e406f552421a642ad0a22cb4678624d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 06:58:50 -1100 Subject: [PATCH 0138/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5bb4a74aa..0ea28b696 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4611,7 +4611,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *txtimep = (uint32_t)out.tx->nLockTime; fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } - } else fprintf(stderr,"%s not eligible\n",out.tx->GetHash()); + } else fprintf(stderr,"utxo not eligible\n"); } else fprintf(stderr,"no tipindex\n"); } if ( earliest != 0 ) From 985990dded76c10254508b60a9236e1e7653c302 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 07:03:34 -1100 Subject: [PATCH 0139/1123] +print --- src/komodo_bitcoind.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fd8b19a55..0ddcb7ffe 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1087,9 +1087,13 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime < prevtime+57 ) blocktime = prevtime+57; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) + { + fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); + } if ( (minage= nHeight*3) > 6000 ) minage = 6000; + pindex = 0; 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)); @@ -1137,7 +1141,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh 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); } - } + } else fprintf(stderr,"skip PoS scan: blocktime %u > %u txtime+minage %u\n",blocktime,txtime,minage); if ( nHeight < 10 ) return(blocktime); return(blocktime * winner); From 012026ed973161f14c50f4aa975ff16acbb81e09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 07:03:52 -1100 Subject: [PATCH 0140/1123] -print --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0ea28b696..6dddc5401 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4611,8 +4611,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *txtimep = (uint32_t)out.tx->nLockTime; fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } - } else fprintf(stderr,"utxo not eligible\n"); - } else fprintf(stderr,"no tipindex\n"); + } //else fprintf(stderr,"utxo not eligible\n"); + } //else fprintf(stderr,"no tipindex\n"); } if ( earliest != 0 ) { From 3a9d2c4323d29809009c731dfafb39e25572dec7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 07:10:15 -1100 Subject: [PATCH 0141/1123] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0ddcb7ffe..52678da39 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1094,7 +1094,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( (minage= nHeight*3) > 6000 ) minage = 6000; pindex = 0; - if ( blocktime > txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) + 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); @@ -1141,7 +1141,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh 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); } - } else fprintf(stderr,"skip PoS scan: blocktime %u > %u txtime+minage %u\n",blocktime,txtime,minage); + } else fprintf(stderr,"skip PoS scan: diff %d blocktime %u > %u txtime+minage %u pindex.%p\n",(int32_t)(blocktime - (txtime+minage)),blocktime,txtime,minage,pindex); if ( nHeight < 10 ) return(blocktime); return(blocktime * winner); From 26a2b5cd68cd713ba18019f46957f02e040575ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 07:13:08 -1100 Subject: [PATCH 0142/1123] Test --- src/komodo_bitcoind.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 52678da39..c9b1cf1c5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1094,7 +1094,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( (minage= nHeight*3) > 6000 ) minage = 6000; pindex = 0; - if ( blocktime >= txtime+minage && (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) + if ( (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); @@ -1108,6 +1108,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24 ) break; + if ( blocktime+iter+segid*2 < txtime+minage ) + continue; coinage = (value * diff) * ((diff >> 16) + 1); hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) @@ -1141,7 +1143,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh 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); } - } else fprintf(stderr,"skip PoS scan: diff %d blocktime %u > %u txtime+minage %u pindex.%p\n",(int32_t)(blocktime - (txtime+minage)),blocktime,txtime,minage,pindex); + } //else fprintf(stderr,"skip PoS scan: diff %d blocktime %u > %u txtime+minage %u pindex.%p\n",(int32_t)(blocktime - (txtime+minage)),blocktime,txtime,minage,pindex); if ( nHeight < 10 ) return(blocktime); return(blocktime * winner); From 9b79591bba1d45663902964d0a169ec6c642abee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 07:20:47 -1100 Subject: [PATCH 0143/1123] Test --- src/komodo_bitcoind.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c9b1cf1c5..5f9cbae8a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1106,8 +1106,10 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh for (iter=0; iter<3600; iter++) { diff = (iter + blocktime - txtime - minage); - if ( diff > 3600*24 ) - break; + if ( iter > 0 ) + diff += iter + segid*2; + //if ( diff > 3600*24 ) + // break; if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); From ad277ac6449ae51588f0c2c4b4b9a141eb5e80a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 07:30:49 -1100 Subject: [PATCH 0144/1123] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5f9cbae8a..a5ef1ccab 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1136,7 +1136,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 1 ) + if ( 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 34bcc3094f09d164981f76357a40cdf8d1fc0740 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Jun 2018 07:37:41 -1100 Subject: [PATCH 0145/1123] -print --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6dddc5401..65dd0e22b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4599,7 +4599,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { @@ -4609,7 +4609,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); @@ -4641,7 +4641,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; i Date: Fri, 1 Jun 2018 09:05:10 -1100 Subject: [PATCH 0146/1123] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 12433f1e8..2100b59ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3779,7 +3779,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",blockhdr.GetBlockTime() - GetAdjustedTime()); return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); } } From fe727b9d922841d15fba8897e4f1a822cf6fe7a5 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sat, 2 Jun 2018 16:13:21 -0300 Subject: [PATCH 0147/1123] zero members in notarisationdata --- src/cc/eval.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/eval.h b/src/cc/eval.h index 43cdadea7..4bcdd5617 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -126,15 +126,15 @@ class NotarisationData { public: int IsBackNotarisation = 0; - uint256 blockHash; - uint32_t height; - uint256 txHash; - char symbol[64] = "\0"; - uint256 MoM; - uint16_t MoMDepth; - uint16_t ccId; - uint256 MoMoM; - uint32_t MoMoMDepth; + uint256 blockHash = uint256(); + uint32_t height = 0; + uint256 txHash = uint256(); + char symbol[64] = "\0"; + uint256 MoM = uint256(); + uint16_t MoMDepth = 0; + uint16_t ccId = 0; + uint256 MoMoM = uint256(); + uint32_t MoMoMDepth = 0; NotarisationData(int IsBack=2) : IsBackNotarisation(IsBack) {} From 97d48e24058dbba791c3c80f89ac804575ed9f6b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 2 Jun 2018 22:17:18 -0700 Subject: [PATCH 0148/1123] Add missing ZCVIEWING_KEY to base58Prefixes --- src/chainparams.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d78e1351b..e90fc23f0 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -173,6 +173,8 @@ public: base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x88)(0xAD)(0xE4).convert_to_container >(); // guarantees the first two characters, when base58 encoded, are "zc" base58Prefixes[ZCPAYMENT_ADDRRESS] = {22,154}; + // guarantees the first 4 characters, when base58 encoded, are "ZiVK" + base58Prefixes[ZCVIEWING_KEY] = {0xA8,0xAB,0xD3}; // guarantees the first two characters, when base58 encoded, are "SK" base58Prefixes[ZCSPENDING_KEY] = {171,54}; @@ -467,6 +469,8 @@ public: base58Prefixes[EXT_PUBLIC_KEY] = boost::assign::list_of(0x04)(0x35)(0x87)(0xCF).convert_to_container >(); base58Prefixes[EXT_SECRET_KEY] = boost::assign::list_of(0x04)(0x35)(0x83)(0x94).convert_to_container >(); base58Prefixes[ZCPAYMENT_ADDRRESS] = {20,81}; + // guarantees the first 4 characters, when base58 encoded, are "ZiVt" + base58Prefixes[ZCVIEWING_KEY] = {0xA8,0xAC,0x0C}; base58Prefixes[ZCSPENDING_KEY] = {177,235}; vFixedSeeds = std::vector(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test)); From 30999b9c129b4af030cb3fa0afb1414da9d7ca24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Jun 2018 00:52:55 -1100 Subject: [PATCH 0149/1123] Test --- src/komodo_gateway.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3b2922a7b..1ab58b04a 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -747,17 +747,18 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim if ( ASSETCHAINS_COMMISSION != 0 && height > 1 ) { if ( (checktoshis= komodo_checkcommission((CBlock *)&block,height)) < 0 ) - return(-1); - } - else - { - if ( overflow != 0 || total > checktoshis || strangeout != 0 ) { - if ( strangeout != 0 ) - fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched); + fprintf(stderr,"ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout); return(-1); } } + if ( overflow != 0 || total > checktoshis || strangeout != 0 ) + { + fprintf(stderr,"checkdeposit: ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout); + if ( strangeout != 0 ) + fprintf(stderr,">>>>>>>>>>>>> %s DUST ht.%d strangout.%d notmatched.%d <<<<<<<<<\n",ASSETCHAINS_SYMBOL,height,strangeout,notmatched); + return(-1); + } } return(0); } From d630af57fbfe083c16bc6b7d70ae13b1e920c43d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Jun 2018 00:55:40 -1100 Subject: [PATCH 0150/1123] Test --- src/komodo_gateway.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 1ab58b04a..9f008e3a0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -751,6 +751,8 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim fprintf(stderr,"ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout); return(-1); } + if ( height < 2 ) + return(0); } if ( overflow != 0 || total > checktoshis || strangeout != 0 ) { From b7aeaa2deb850c60d6a6bac60884d5b0debc589d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Jun 2018 00:58:51 -1100 Subject: [PATCH 0151/1123] Test --- src/komodo_gateway.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9f008e3a0..5717a2586 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -751,10 +751,8 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim fprintf(stderr,"ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout); return(-1); } - if ( height < 2 ) - return(0); } - if ( overflow != 0 || total > checktoshis || strangeout != 0 ) + if ( height >= 2 && (overflow != 0 || total > checktoshis || strangeout != 0) ) { fprintf(stderr,"checkdeposit: ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout); if ( strangeout != 0 ) From 93b144ac35cefccf31e3ec558365ed54b545814a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Jun 2018 02:54:03 -1100 Subject: [PATCH 0152/1123] KV fix --- src/komodo.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index d69768e8f..690e91248 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -598,14 +598,15 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else { + if ( scriptbuf[len] == 'K' ) + { + fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value)); + komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen,j,zero,0); + return(-1); + } if ( strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) matched = 1; } - if ( scriptbuf[len] == 'K' ) - { - fprintf(stderr,"i.%d j.%d KV OPRET len.%d %.8f\n",i,j,opretlen,dstr(value)); - return(-1); - } offset = 32 * (1 + matched) + 4; nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]); nameoffset++; From 7776d00b9a508a1f195ffa7702173a21f165ebe9 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 3 Jun 2018 13:22:00 -0300 Subject: [PATCH 0153/1123] fix MoMdepth in crosschain.cpp --- src/crosschain.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 3eb618bd7..94959544b 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -212,7 +212,8 @@ TxProof GetAssetchainProof(uint256 hash) // build merkle chain from blocks to MoM { std::vector leaves, tree; - for (int i=0; iMoMdepth; i++) { + uint32_t md = np->MoMdepth & 0xffff; // MoMdepth shares space with ccid + for (int i=0; inotarized_height - i]->hashMerkleRoot; leaves.push_back(mRoot); } From ceb6321c7ca18e9daf65d4ad2a7f0e781dfb0c5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 3 Jun 2018 05:46:46 -1100 Subject: [PATCH 0154/1123] -print --- src/komodo_kv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 80fac5ff8..ee0496aae 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -111,7 +111,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) if ( keylen+13 > opretlen ) { static uint32_t counter; - if ( ++counter < 100 ) + if ( ++counter < 1 ) fprintf(stderr,"komodo_kvupdate: keylen.%d + 13 > opretlen.%d, this can be ignored\n",keylen,opretlen); return; } From 181e67c617e7913f6c3ef728a6efa5a48f0389fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 5 Jun 2018 03:35:21 -1100 Subject: [PATCH 0155/1123] Increase conversion rate for PoW high diff, breaking change for existing testchains --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a5ef1ccab..12ba756fe 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1197,7 +1197,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { - bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256((goalperc) * (goalperc)); + bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); if ( 1 ) { for (i=31; i>=24; i--) From 5f20a85d14040ab92a0c368e9ee265d4607d7380 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Jun 2018 02:52:58 -1100 Subject: [PATCH 0156/1123] -genjson for komodo_port.c --- src/komodo_port.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/komodo_port.c b/src/komodo_port.c index 991be2013..14a97e159 100644 --- a/src/komodo_port.c +++ b/src/komodo_port.c @@ -826,7 +826,7 @@ uint16_t komodo_calcport(char *name,uint64_t supply,uint64_t endsubsidy,uint64_t int main(int argc, char * argv[]) { - uint16_t rpcport; int32_t i,j,offset=0,num = 1; uint64_t supply=10,commission=0,endsubsidy,reward,halving,decay; uint8_t *allocated=0,staked=0; uint32_t cc = 1; + uint16_t rpcport; int32_t i,j,offset=0,jsonflag=0,num = 1; uint64_t supply=10,commission=0,endsubsidy,reward,halving,decay; uint8_t *allocated=0,staked=0; uint32_t cc = 3; endsubsidy = reward = halving = decay = 0; if ( argc < 2 ) { @@ -835,9 +835,11 @@ int main(int argc, char * argv[]) printf("%s -gen num name supply endsubsidy reward halving decay\n",argv[0]); return(-1); } - if ( strcmp(argv[1],"-gen") == 0 ) + if ( strncmp(argv[1],"-gen",3) == 0 ) { num = atoi(argv[2]); + if ( strcmp(argv[1],"-genjson") == 0 ) + jsonflag = 1; offset = 2; allocated = calloc(1,1 << 16); } @@ -852,7 +854,7 @@ int main(int argc, char * argv[]) if ( argc > offset + 6 ) decay = (long long)atof(argv[offset + 6]); rpcport = 1 + komodo_calcport(argv[offset + 1],supply,endsubsidy,reward,halving,decay,commission,staked,cc); - printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n",argv[offset + 1],cc,(long long)supply,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport); + printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n[",argv[offset + 1],cc,(long long)supply,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport); if ( allocated != 0 ) { char name[64],newname[64]; @@ -868,7 +870,14 @@ int main(int argc, char * argv[]) rpcport = 1 + komodo_calcport(newname,supply+j,endsubsidy,reward,halving,decay,commission,staked,cc); if ( allocated[rpcport] == 0 && allocated[rpcport-1] == 0 ) { - printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n",newname,cc,(long long)supply+j,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport); + if ( jsonflag == 0 ) + { + printf("./komodod -ac_name=%s -ac_cc=%u -ac_supply=%llu -ac_end=%llu -ac_reward=%llu -ac_halving=%llu -ac_decay=%llu & # rpcport %u\n",newname,cc,(long long)supply+j,(long long)endsubsidy,(long long)reward,(long long)halving,(long long)decay,rpcport); + } + else + { + printf("{ \"assetname\": \"%s\", \"p2p\": %u, \"rpc\": %u, \"supply\": %llu, \"ac_cc\": %u, \"ac_reward\": %llu, \"notarize\": %s }%s ",newname,rpcport-1,rpcport,(long long)supply+j,cc,(long long)reward,i<64?"true":"false",i Date: Wed, 6 Jun 2018 03:22:13 -1100 Subject: [PATCH 0157/1123] Fix coinbasevalue --- src/rpcmining.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index e3341144a..f7c99b1c0 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -692,7 +692,8 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) // Correct this if GetBlockTemplate changes the order // entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); //} - entry.push_back(Pair("coinbasevalue", 3*COIN)); + CAmount nReward = GetBlockSubsidy(chainActive.Tip()->nHeight+1, Params().GetConsensus()); + entry.push_back(Pair("coinbasevalue", nReward)); entry.push_back(Pair("required", true)); txCoinbase = entry; } else From 15d17928f89e83cbfcde77d408a91cfd74f05a56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 6 Jun 2018 07:06:40 -1100 Subject: [PATCH 0158/1123] Allow asset chains to have more coinbase vouts --- src/komodo_gateway.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 5717a2586..9de6b4fc9 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -752,6 +752,10 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim return(-1); } } + if ( height > 1 && checktoshis == 0 ) + { + checktoshis = ((uint64_t)GetBlockSubsidy(height, Params().GetConsensus()) - block.vtx[0].vout[0].nValue); + } if ( height >= 2 && (overflow != 0 || total > checktoshis || strangeout != 0) ) { fprintf(stderr,"checkdeposit: ht.%d checktoshis %.8f overflow.%d total %.8f strangeout.%d\n",height,dstr(checktoshis),overflow,dstr(total),strangeout); From acbc7a942a604af3c2ce84e5cb25ec04f926de17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 06:31:20 -1100 Subject: [PATCH 0159/1123] Segid to validate address --- src/komodo_bitcoind.h | 7 +++++++ src/rpcmisc.cpp | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 12ba756fe..32d34c700 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1080,6 +1080,13 @@ uint64_t komodo_commission(const CBlock *pblock) return(commission); } +uint32_t komodo_segid32(char *coinaddr) +{ + bits256 addrhash; + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + return(addrhash.uints[0]); +} + 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; diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index c356ef994..95285b580 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -52,6 +52,7 @@ int32_t komodo_whoami(char *pubkeystr,int32_t height,uint32_t timestamp); extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; +uint32_t komodo_segid32(char *coinaddr); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; @@ -326,7 +327,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(dest); ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - + ret.push_back(Pair("segid", komodo_segid(address.c_str()) & 3f)); #ifdef ENABLE_WALLET isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); From 3001f999ecc5bfc29f733e144f82e51527ad1a6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 09:12:26 -1100 Subject: [PATCH 0160/1123] Syntax --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 32d34c700..44c3db942 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1083,7 +1083,7 @@ uint64_t komodo_commission(const CBlock *pblock) uint32_t komodo_segid32(char *coinaddr) { bits256 addrhash; - vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)coinaddr,(int32_t)strlen(coinaddr)); return(addrhash.uints[0]); } From 584b784c57d80a8e3f41f6bb2a1756b0004bf485 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 09:13:38 -1100 Subject: [PATCH 0161/1123] Fix --- src/rpcmisc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 95285b580..ae3f48874 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -327,7 +327,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(dest); ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - ret.push_back(Pair("segid", komodo_segid(address.c_str()) & 3f)); + ret.push_back(Pair("segid", komodo_segid(address.c_str()) & 0x3f)); #ifdef ENABLE_WALLET isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); From d23c6a06e7dbd3b3666bc3000d541aa3bcd327b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 09:15:13 -1100 Subject: [PATCH 0162/1123] c++ --- src/rpcmisc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index ae3f48874..a09a4368b 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -327,7 +327,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(dest); ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - ret.push_back(Pair("segid", komodo_segid(address.c_str()) & 0x3f)); + ret.push_back(Pair("segid", komodo_segid(params[0].get_str().c_str()) & 0x3f)); #ifdef ENABLE_WALLET isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); From cf266927980fcf07a3c5b2965fccd0fd1deb5d41 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 09:15:52 -1100 Subject: [PATCH 0163/1123] Syntax --- src/rpcmisc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index a09a4368b..27b72dd0c 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -327,7 +327,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(dest); ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - ret.push_back(Pair("segid", komodo_segid(params[0].get_str().c_str()) & 0x3f)); + ret.push_back(Pair("segid", komodo_segid32(params[0].get_str().c_str()) & 0x3f)); #ifdef ENABLE_WALLET isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); From 1eb7f6169f85bfceb3808c3507439bec5994400c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 09:17:08 -1100 Subject: [PATCH 0164/1123] c++ --- src/rpcmisc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 27b72dd0c..bd22385d6 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -327,7 +327,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(dest); ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - ret.push_back(Pair("segid", komodo_segid32(params[0].get_str().c_str()) & 0x3f)); + ret.push_back(Pair("segid", (int32_t)komodo_segid32(params[0].get_str().c_str()) & 0x3f)); #ifdef ENABLE_WALLET isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); From 7cf23c98155c2525eb1e6090f1a3141ede1937ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 09:18:48 -1100 Subject: [PATCH 0165/1123] c++ --- src/rpcmisc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index bd22385d6..278fb8866 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -327,7 +327,7 @@ UniValue validateaddress(const UniValue& params, bool fHelp) CScript scriptPubKey = GetScriptForDestination(dest); ret.push_back(Pair("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()))); - ret.push_back(Pair("segid", (int32_t)komodo_segid32(params[0].get_str().c_str()) & 0x3f)); + ret.push_back(Pair("segid", (int32_t)komodo_segid32((char *)params[0].get_str().c_str()) & 0x3f)); #ifdef ENABLE_WALLET isminetype mine = pwalletMain ? IsMine(*pwalletMain, dest) : ISMINE_NO; ret.push_back(Pair("ismine", (mine & ISMINE_SPENDABLE) ? true : false)); From 16593898016ed2e020e6f9fda7e8f5d433b9bb84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 7 Jun 2018 21:01:41 -1100 Subject: [PATCH 0166/1123] Prevent very long gap in blocks --- src/miner.cpp | 33 +++++++++++---------------------- src/miner.h | 5 +++-- src/rpcmining.cpp | 5 +++-- src/test/miner_tests.cpp | 26 +++++++++++++------------- 4 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ef943b3aa..08fac7e22 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -124,10 +124,12 @@ 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); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); -CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) +CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params(); // Create new block + if ( gpucount < 0 ) + gpucount = KOMODO_MAXGPUCOUNT; std::unique_ptr pblocktemplate(new CBlockTemplate()); if(!pblocktemplate.get()) { @@ -475,6 +477,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); if ( pblock->nTime < pindexPrev->nTime+65 ) pblock->nTime = pindexPrev->nTime + 65; + if ( gpucount < 33 ) + pblock->nTime += (rand() % (33 - gpucount)*(33 - gpucount)); if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 ) { CAmount txfees = 5000; @@ -583,7 +587,7 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& // Internal miner // -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight) +CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i; if ( nHeight == 1 && ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) @@ -610,7 +614,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight) script[34] = OP_CHECKSIG; //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } - return CreateNewBlock(scriptPubKey); + return CreateNewBlock(scriptPubKey,gpucount); } void komodo_broadcast(CBlock *pblock,int32_t limit) @@ -717,7 +721,7 @@ void static BitcoinMiner() unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); - uint8_t *script; uint64_t total,checktoshis; int32_t i,j,notaryid = -1; + uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 && { sleep(1); @@ -771,11 +775,6 @@ void static BitcoinMiner() //fprintf(stderr,"%s Found peers\n",ASSETCHAINS_SYMBOL); miningTimer.start(); } - /*while ( ASSETCHAINS_SYMBOL[0] != 0 && chainActive.Tip()->nHeight < ASSETCHAINS_MINHEIGHT ) - { - fprintf(stderr,"%s waiting for block 100, ht.%d\n",ASSETCHAINS_SYMBOL,chainActive.Tip()->nHeight); - sleep(3); - }*/ // // Create new block // @@ -792,7 +791,7 @@ void static BitcoinMiner() sleep(3); } #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1,gpucount); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif @@ -835,7 +834,7 @@ void static BitcoinMiner() // // Search // - uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],gpucount,nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; HASHTarget = arith_uint256().SetCompact(pblock->nBits); roundrobin_delay = ROUNDROBIN_DELAY; @@ -874,18 +873,8 @@ void static BitcoinMiner() if ( mids[j] == -1 ) gpucount++; } - if ( gpucount > j/2 ) - { - double delta; - if ( notaryid < 0 ) - i = (rand() % 64); - else i = ((Mining_height + notaryid) % 64); - delta = sqrt((double)gpucount - j/2) / 2.; - roundrobin_delay += ((delta * i) / 64) - delta; - //fprintf(stderr,"delta.%f %f %f\n",delta,(double)(gpucount - j/3) / 2,(delta * i) / 64); - } if ( dispflag != 0 ) - fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u %d\n",pindexPrev->nHeight,notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL),roundrobin_delay); + fprintf(stderr," <- prev minerids from ht.%d notary.%d gpucount.%d %.2f%% t.%u\n",pindexPrev->nHeight,notaryid,gpucount,100.*(double)gpucount/j,(uint32_t)time(NULL)); } for (j=0; j<65; j++) if ( mids[j] == notaryid ) diff --git a/src/miner.h b/src/miner.h index 684b10187..5486f2d5e 100644 --- a/src/miner.h +++ b/src/miner.h @@ -25,12 +25,13 @@ struct CBlockTemplate std::vector vTxFees; std::vector vTxSigOps; }; +#define KOMODO_MAXGPUCOUNT 65 /** Generate a new block, without valid proof-of-work */ -CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn); +CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount); #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey); -CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight); +CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey,int32_t nHeight,int32_t gpucount); #else boost::optional GetMinerScriptPubKey(); CBlockTemplate* CreateNewBlockWithKey(); diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index f7c99b1c0..7f66f23f6 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -32,6 +32,7 @@ using namespace std; + /** * Return average network hashes per second based on the last 'lookup' blocks, * or over the difficulty averaging window if 'lookup' is nonpositive. @@ -214,7 +215,7 @@ UniValue generate(const UniValue& params, bool fHelp) lastTime = GetTime(); #ifdef ENABLE_WALLET - std::unique_ptr pblocktemplate(CreateNewBlockWithKey(reservekey,nHeight)); + std::unique_ptr pblocktemplate(CreateNewBlockWithKey(reservekey,nHeight,KOMODO_MAXGPUCOUNT)); #else std::unique_ptr pblocktemplate(CreateNewBlockWithKey()); #endif @@ -639,7 +640,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) } #ifdef ENABLE_WALLET CReserveKey reservekey(pwalletMain); - pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1); + pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1,KOMODO_MAXGPUCOUNT); #else pblocktemplate = CreateNewBlockWithKey(); #endif diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 7866d3ac1..3822a271d 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) for (unsigned int i = 0; i < sizeof(blockinfo)/sizeof(*blockinfo); ++i) { // Simple block creation, nothing special yet: - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); CBlock *pblock = &pblocktemplate->block; // pointer for convenience pblock->nVersion = 4; @@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) } // Just to make sure we can still make simple blocks - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; // block sigops > limit: 1000 CHECKMULTISIG + 1 @@ -289,7 +289,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx)); tx.vin[0].prevout.hash = hash; } - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -310,14 +310,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx)); tx.vin[0].prevout.hash = hash; } - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); // orphan in mempool hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -335,7 +335,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue = 49000LL; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -346,7 +346,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue = 0; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -364,7 +364,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].nValue -= 10000; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(false).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -378,17 +378,17 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) tx.vout[0].scriptPubKey = CScript() << OP_2; hash = tx.GetHash(); mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); // subsidy changing int nHeight = chainActive.Height(); chainActive.Tip()->nHeight = 209999; - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->nHeight = 210000; - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->nHeight = nHeight; @@ -420,7 +420,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) mempool.addUnchecked(hash, entry.Time(GetTime()).SpendsCoinbase(true).FromTx(tx2)); BOOST_CHECK(!CheckFinalTx(tx2, LOCKTIME_MEDIAN_TIME_PAST)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); // Neither tx should have made it into the template. BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1); @@ -435,7 +435,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) //BOOST_CHECK(CheckFinalTx(tx)); //BOOST_CHECK(CheckFinalTx(tx2)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2); delete pblocktemplate; From 7714b7f1430b6aa18941117a8363ce9c1a718a04 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 8 Jun 2018 02:15:46 -1100 Subject: [PATCH 0167/1123] Handle -disablewallet=1 --- src/wallet/rpcwallet.cpp | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 65dd0e22b..7187b8fe8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2697,32 +2697,34 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { #ifdef ENABLE_WALLET - uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; - vector vecOutputs; - assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); - pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); - BOOST_FOREACH(const COutput& out,vecOutputs) + if ( GetBoolArg("-disablewallet", false) == 0 ) { - CAmount nValue = out.tx->vout[out.i].nValue; - if ( out.tx->nLockTime != 0 && out.fSpendable != 0 ) + uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; + vector vecOutputs; + assert(pwalletMain != NULL); + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + BOOST_FOREACH(const COutput& out,vecOutputs) { - BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex,*pindex = it->second; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + CAmount nValue = out.tx->vout[out.i].nValue; + if ( out.tx->nLockTime != 0 && out.fSpendable != 0 ) { - interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); - //interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); - sum += interest; + BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); + CBlockIndex *tipindex,*pindex = it->second; + if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + { + interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); + //interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); + sum += interest; + } } } + KOMODO_INTERESTSUM = sum; + KOMODO_WALLETBALANCE = pwalletMain->GetBalance(); + return(sum); } - KOMODO_INTERESTSUM = sum; - KOMODO_WALLETBALANCE = pwalletMain->GetBalance(); - return(sum); -#else - return(0); #endif + return(0); } UniValue fundrawtransaction(const UniValue& params, bool fHelp) From fa04bcf38c6cedabe80414c10e20ccf8189ba80d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 8 Jun 2018 05:17:25 -1100 Subject: [PATCH 0168/1123] 65 seconds to 60 --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 08fac7e22..35eb8e4d3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -475,8 +475,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 ) { CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); - if ( pblock->nTime < pindexPrev->nTime+65 ) - pblock->nTime = pindexPrev->nTime + 65; + if ( pblock->nTime < pindexPrev->nTime+60 ) + pblock->nTime = pindexPrev->nTime + 60; if ( gpucount < 33 ) pblock->nTime += (rand() % (33 - gpucount)*(33 - gpucount)); if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 ) From 99d7ed2567868d790e5ceac0d5afa6aa612aa873 Mon Sep 17 00:00:00 2001 From: l0rb Date: Fri, 8 Jun 2018 21:16:24 +0200 Subject: [PATCH 0169/1123] remove unused variable minor code cleanup --- src/komodo_bitcoind.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 44c3db942..be0f07c5a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1024,9 +1024,8 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) else return(0); } -int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag) +int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { if ( txheight > 246748 ) From 89cfc4272dd6c3a3a7f1a70e6b144b6aea193ccf Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 10 Jun 2018 15:12:10 +0200 Subject: [PATCH 0170/1123] fixes for import coin --- src/cc/import.cpp | 3 ++- src/crosschain.cpp | 7 ++++--- src/komodo_ccdata.h | 2 +- src/notarisationdb.cpp | 8 ++++++-- src/rpcrawtransaction.cpp | 3 +++ src/test-komodo/test_parse_notarisation.cpp | 20 ++++++++++++++++++++ 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 506b2a989..5f0b804e8 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -57,10 +57,11 @@ bool Eval::ImportCoin(const std::vector params, const CTransaction &imp // Check proof confirms existance of burnTx { - uint256 momom; + uint256 momom, target; if (!GetProofRoot(proof.first, momom)) return Invalid("coudnt-load-momom"); + target = proof.second.Exec(burnTx.GetHash()); if (momom != proof.second.Exec(burnTx.GetHash())) return Invalid("momom-check-fail"); } diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 94959544b..dd352b025 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -148,7 +148,7 @@ void CompleteImportTransaction(CTransaction &importTx) proof = GetCrossChainProof(burnTx.GetHash(), targetSymbol.data(), targetCCid, proof); - importTx = MakeImportCoinTransaction(proof, burnTx, importTx.vout); + importTx = MakeImportCoinTransaction(proof, burnTx, payouts); } @@ -187,7 +187,7 @@ struct notarized_checkpoint* komodo_npptr(int32_t height); */ TxProof GetAssetchainProof(uint256 hash) { - int nIndex; + int nIndex, md; CBlockIndex* blockIndex; struct notarized_checkpoint* np; std::vector branch; @@ -207,12 +207,13 @@ TxProof GetAssetchainProof(uint256 hash) // index of block in MoM leaves nIndex = np->notarized_height - blockIndex->nHeight; + // MoMdepth shares space with ccid + md = np->MoMdepth & 0xffff; } // build merkle chain from blocks to MoM { std::vector leaves, tree; - uint32_t md = np->MoMdepth & 0xffff; // MoMdepth shares space with ccid for (int i=0; inotarized_height - i]->hashMerkleRoot; leaves.push_back(mRoot); diff --git a/src/komodo_ccdata.h b/src/komodo_ccdata.h index 6fd065953..012183fc7 100644 --- a/src/komodo_ccdata.h +++ b/src/komodo_ccdata.h @@ -25,7 +25,7 @@ uint256 komodo_calcMoM(int32_t height,int32_t MoMdepth) { static uint256 zero; CBlockIndex *pindex; int32_t i; std::vector tree, leaves; bool fMutated; - MoMdepth &= 0xffff; + MoMdepth &= 0xffff; // In case it includes the ccid if ( MoMdepth >= height ) return(zero); for (i=0; iWrite(n.second.txHash, n); + batch.Write(n.second.txHash, n); } + pnotarisations->WriteBatch(batch, true); } void EraseBackNotarisations(const NotarisationsInBlock notarisations) { + CLevelDBBatch batch; BOOST_FOREACH(const Notarisation &n, notarisations) { if (!n.second.txHash.IsNull()) - pnotarisations->Erase(n.second.txHash); + batch.Erase(n.second.txHash); } + pnotarisations->WriteBatch(batch, true); } diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 5f349096a..91dff8bf9 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -134,6 +134,9 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& UniValue in(UniValue::VOBJ); if (tx.IsCoinBase()) in.push_back(Pair("coinbase", HexStr(txin.scriptSig.begin(), txin.scriptSig.end()))); + else if (tx.IsCoinImport()) { + in.push_back(Pair("is_import", "1")); + } else { in.push_back(Pair("txid", txin.prevout.hash.GetHex())); in.push_back(Pair("vout", (int64_t)txin.prevout.n)); diff --git a/src/test-komodo/test_parse_notarisation.cpp b/src/test-komodo/test_parse_notarisation.cpp index a61ca2aa3..2910e2f96 100644 --- a/src/test-komodo/test_parse_notarisation.cpp +++ b/src/test-komodo/test_parse_notarisation.cpp @@ -29,6 +29,26 @@ TEST(TestParseNotarisation, test__) ASSERT_FALSE(E_UNMARSHAL(opret, ss >> nd)); } +TEST(TestParseNotarisation, test__a) +{ + // be55101e6c5a93fb3611a44bd66217ad8714d204275ea4e691cfff9d65dff85c TXSCL + std::vector opret = ParseHex("fb9ea2818eec8b07f8811bab49d64379db074db478997f8114666f239bd79803cc460000d0fac4e715b7e2b917a5d79f85ece0c423d27bd3648fd39ac1dc7db8e1bd4b16545853434c00a69eab9f23d7fb63c4624973e7a9079d6ada2f327040936356d7af5e849f6d670a0003001caf7b7b9e1c9bc59d0c7a619c9683ab1dd0794b6f3ea184a19f8fda031150e700000000"); + NotarisationData nd(1); + bool res = E_UNMARSHAL(opret, ss >> nd); + ASSERT_TRUE(res); +} + +TEST(TestParseNotarisation, test__b) +{ + // 03085dafed656aaebfda25bf43ffe9d1fb72565bb1fc8b2a12a631659f28f877 TXSCL + std::vector opret = ParseHex("48c71a10aa060eab1a43f52acefac3b81fb2a2ce310186b06141884c0501d403c246000052e6d49afd82d9ab3d97c996dd9b6a78a554ffa1625e8dadf0494bd1f8442e3e545853434c007cc5c07e3b67520fd14e23cd5b49f2aa022f411500fd3326ff91e6dc0544a1c90c0003008b69117bb1376ac8df960f785d8c208c599d3a36248c98728256bb6d4737e59600000000"); + NotarisationData nd(1); + bool res = E_UNMARSHAL(opret, ss >> nd); + ASSERT_TRUE(res); +} + + + // for l in `g 'parse notarisation' ~/.komodo/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/komodo-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done } From 846384769c22891934a7f0d56d187de6ab428182 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Mon, 11 Jun 2018 17:29:16 +0200 Subject: [PATCH 0171/1123] log notarisations written to index --- src/main.cpp | 28 ++++++++++++++++++---------- src/notarisationdb.cpp | 13 ++++++------- src/notarisationdb.h | 4 ++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 714d8625b..d8dc2ddf1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2486,8 +2486,12 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // Delete from notarisations cache NotarisationsInBlock nibs; if (GetBlockNotarisations(block.GetHash(), nibs)) { - pnotarisations->Erase(block.GetHash()); - EraseBackNotarisations(nibs); + CLevelDBBatch batch; + batch.Erase(block.GetHash()); + EraseBackNotarisations(nibs, batch); + pnotarisations->WriteBatch(batch, true); + LogPrintf("ConnectBlock: Deleted %i block notarisations in block: %s\n", + nibs.size(), block.GetHash().GetHex().data()); } // set the old best anchor back @@ -2844,14 +2848,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin vPos.push_back(std::make_pair(tx.GetHash(), pos)); pos.nTxOffset += ::GetSerializeSize(tx, SER_DISK, CLIENT_VERSION); } - - // Record Notarisations - NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight); - if (notarisations.size() > 0) { - pnotarisations->Write(block.GetHash(), notarisations); - WriteBackNotarisations(notarisations); - } - + view.PushAnchor(tree); if (!fJustCheck) { pindex->hashAnchorEnd = tree.root(); @@ -2920,6 +2917,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin pindex->RaiseValidity(BLOCK_VALID_SCRIPTS); setDirtyBlockIndex.insert(pindex); } + + // Record Notarisations + NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight); + if (notarisations.size() > 0) { + CLevelDBBatch batch; + batch.Write(block.GetHash(), notarisations); + WriteBackNotarisations(notarisations, batch); + pnotarisations->WriteBatch(batch, true); + LogPrintf("ConnectBlock: wrote %i block notarisations in block: %s\n", + notarisations.size(), block.GetHash().GetHex().data()); + } if (fTxIndex) if (!pblocktree->WriteTxIndex(vPos)) diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 023588874..4b2ade793 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -61,25 +61,24 @@ bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n) /* * Write an index of KMD notarisation id -> backnotarisation */ -void WriteBackNotarisations(const NotarisationsInBlock notarisations) +void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch) { - CLevelDBBatch batch; + int wrote = 0; BOOST_FOREACH(const Notarisation &n, notarisations) { - if (!n.second.txHash.IsNull()) + if (!n.second.txHash.IsNull()) { batch.Write(n.second.txHash, n); + wrote++; + } } - pnotarisations->WriteBatch(batch, true); } -void EraseBackNotarisations(const NotarisationsInBlock notarisations) +void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch) { - CLevelDBBatch batch; BOOST_FOREACH(const Notarisation &n, notarisations) { if (!n.second.txHash.IsNull()) batch.Erase(n.second.txHash); } - pnotarisations->WriteBatch(batch, true); } diff --git a/src/notarisationdb.h b/src/notarisationdb.h index 27f979784..59c500fc4 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -21,7 +21,7 @@ typedef std::vector NotarisationsInBlock; NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight); bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs); bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); -void WriteBackNotarisations(const NotarisationsInBlock notarisations); -void EraseBackNotarisations(const NotarisationsInBlock notarisations); +void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch); +void EraseBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch); #endif /* NOTARISATIONDB_H */ From 936078888db0780f880828b0a5336a3332b1b824 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:04:00 -1100 Subject: [PATCH 0172/1123] int32_t CBlockTreeDB::SnapShot() --- src/txdb.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/txdb.cpp b/src/txdb.cpp index c856947ad..0d802345a 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -396,6 +396,43 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, return true; } +int32_t CBlockTreeDB::SnapShot() +{ + char chType; int32_t num = 0; std::string address; + boost::scoped_ptr pcursor(NewIterator()); + while (pcursor->Valid()) + { + boost::this_thread::interruption_point(); + try + { + leveldb::Slice slKey = pcursor->key(); + CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); + CAddressIndexKey indexKey; + ssKey >> chType; + ssKey >> indexKey; + if ( chType == DB_ADDRESSINDEX ) + { + try { + leveldb::Slice slValue = pcursor->value(); + CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); + CAmount nValue; + ssValue >> nValue; + getAddressFromIndex(indexKey.type, indexKey.addressBytes, address); + fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + num++; + //addressIndex.push_back(make_pair(indexKey, nValue)); + pcursor->Next(); + } catch (const std::exception& e) { + return error("failed to get address index value"); + } + } else break; + } catch (const std::exception& e) { + break; + } + } + return(num); +} + bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey ×tampIndex) { CLevelDBBatch batch; batch.Write(make_pair(DB_TIMESTAMPINDEX, timestampIndex), 0); From b4b4c499853d308c9ae2bc67ce2131576cddaa16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:07:51 -1100 Subject: [PATCH 0173/1123] Syntax --- src/txdb.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/txdb.h b/src/txdb.h index 401f92144..14728d748 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -94,6 +94,7 @@ public: bool ReadFlag(const std::string &name, bool &fValue); bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); + int32_t SnapShot(); }; #endif // BITCOIN_TXDB_H From bd1469982428160c89e4c0a0ff520a5bbf2d3cda Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:10:37 -1100 Subject: [PATCH 0174/1123] Syntax --- src/txdb.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 0d802345a..67f403c64 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -396,6 +396,8 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, return true; } +bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address); + int32_t CBlockTreeDB::SnapShot() { char chType; int32_t num = 0; std::string address; @@ -417,7 +419,7 @@ int32_t CBlockTreeDB::SnapShot() CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); CAmount nValue; ssValue >> nValue; - getAddressFromIndex(indexKey.type, indexKey.addressBytes, address); + getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); num++; //addressIndex.push_back(make_pair(indexKey, nValue)); From 2200781907408b07f0de4988b07728680e89e7b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:26:46 -1100 Subject: [PATCH 0175/1123] Snapshot roc --- src/rpcmisc.cpp | 17 +++++++++++++++++ src/rpcserver.cpp | 1 + src/rpcserver.h | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 278fb8866..b348a893f 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -993,6 +993,23 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp) } +UniValue getsnapshot(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); int32_t num; + if ( fHelp || params.size() > 0 ) + { + throw runtime_error( + "getsnapshot\n" + ); + } + if ( pblocktree != 0 ) + { + num = pblocktree->Snapshot(); + result.push_back(Pair("numaddresses", num)); + } else result.push_back(Pair("error", "no addressindex")); + return(result); +} + UniValue getaddresstxids(const UniValue& params, bool fHelp) { if (fHelp || params.size() != 1) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 86a7aed86..8e9a2c634 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -345,6 +345,7 @@ static const CRPCCommand vRPCCommands[] = { "addressindex", "getaddressdeltas", &getaddressdeltas, false }, { "addressindex", "getaddresstxids", &getaddresstxids, false }, { "addressindex", "getaddressbalance", &getaddressbalance, false }, + { "addressindex", "getsnapshot", &getsnapshot, false }, /* Utility functions */ { "util", "createmultisig", &createmultisig, true }, diff --git a/src/rpcserver.h b/src/rpcserver.h index ce412cdb9..1fbcca794 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -177,7 +177,8 @@ extern UniValue getaddressmempool(const UniValue& params, bool fHelp); extern UniValue getaddressutxos(const UniValue& params, bool fHelp); extern UniValue getaddressdeltas(const UniValue& params, bool fHelp); extern UniValue getaddresstxids(const UniValue& params, bool fHelp); -extern UniValue getaddressbalance(const UniValue& params, bool fHelp); +extern UniValue getaddresstxids(const UniValue& params, bool fHelp); +extern UniValue getsnapshot(const UniValue& params, bool fHelp); extern UniValue getpeerinfo(const UniValue& params, bool fHelp); extern UniValue ping(const UniValue& params, bool fHelp); extern UniValue addnode(const UniValue& params, bool fHelp); From 329d80d2c1b8ecbfea30b0d78f7252bc4da94bf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:34:28 -1100 Subject: [PATCH 0176/1123] Move code --- src/main.cpp | 8 ++++++++ src/rpcmisc.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2100b59ed..d15ff62c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -585,6 +585,14 @@ CBlockTreeDB *pblocktree = NULL; #define KOMODO_ZCASH #include "komodo.h" +int32_t komodo_snapshot() +{ + int32_t num = -1; + if ( pblocktree != 0 ) + num = pblocktree->Snapshot(); + return(num); +} + ////////////////////////////////////////////////////////////////////////////// // // mapOrphanTransactions diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index b348a893f..4c4d1958b 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -993,6 +993,8 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp) } +int32_t komodo_snapshot(); + UniValue getsnapshot(const UniValue& params, bool fHelp) { UniValue result(UniValue::VOBJ); int32_t num; @@ -1002,11 +1004,9 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) "getsnapshot\n" ); } - if ( pblocktree != 0 ) - { - num = pblocktree->Snapshot(); + if ( (num= komodo_snapshot()) >= 0 ) result.push_back(Pair("numaddresses", num)); - } else result.push_back(Pair("error", "no addressindex")); + else result.push_back(Pair("error", "no addressindex")); return(result); } From bf91fda6825132f6f6b470eb458cef17a71cfaa6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:35:59 -1100 Subject: [PATCH 0177/1123] SnapShot -> snapshot --- src/txdb.cpp | 2 +- src/txdb.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 67f403c64..d2ffb0b21 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -398,7 +398,7 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address); -int32_t CBlockTreeDB::SnapShot() +int32_t CBlockTreeDB::Snapshot() { char chType; int32_t num = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); diff --git a/src/txdb.h b/src/txdb.h index 14728d748..a93e50f19 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -94,7 +94,7 @@ public: bool ReadFlag(const std::string &name, bool &fValue); bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); - int32_t SnapShot(); + int32_t Snapshot(); }; #endif // BITCOIN_TXDB_H From 50b11c4a55c76f7fc6a9259212f623ed05e5f910 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:38:15 -1100 Subject: [PATCH 0178/1123] Fix --- src/rpcserver.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcserver.h b/src/rpcserver.h index 1fbcca794..b122e307a 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -177,8 +177,8 @@ extern UniValue getaddressmempool(const UniValue& params, bool fHelp); extern UniValue getaddressutxos(const UniValue& params, bool fHelp); extern UniValue getaddressdeltas(const UniValue& params, bool fHelp); extern UniValue getaddresstxids(const UniValue& params, bool fHelp); -extern UniValue getaddresstxids(const UniValue& params, bool fHelp); extern UniValue getsnapshot(const UniValue& params, bool fHelp); +extern UniValue getaddressbalance(const UniValue& params, bool fHelp); extern UniValue getpeerinfo(const UniValue& params, bool fHelp); extern UniValue ping(const UniValue& params, bool fHelp); extern UniValue addnode(const UniValue& params, bool fHelp); From 67d2e41b3f0332767eefb698f53c82b1a4b7eba3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:41:46 -1100 Subject: [PATCH 0179/1123] Test --- src/main.cpp | 8 ++++---- src/rpcmisc.cpp | 6 +++--- src/txdb.cpp | 10 ++++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d15ff62c0..8dee9bfea 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -585,12 +585,12 @@ CBlockTreeDB *pblocktree = NULL; #define KOMODO_ZCASH #include "komodo.h" -int32_t komodo_snapshot() +int64_t komodo_snapshot() { - int32_t num = -1; + int64_t total = -1; if ( pblocktree != 0 ) - num = pblocktree->Snapshot(); - return(num); + total = pblocktree->Snapshot(); + return(total); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 4c4d1958b..b873dc495 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -997,15 +997,15 @@ int32_t komodo_snapshot(); UniValue getsnapshot(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); int32_t num; + UniValue result(UniValue::VOBJ); int64_t total; if ( fHelp || params.size() > 0 ) { throw runtime_error( "getsnapshot\n" ); } - if ( (num= komodo_snapshot()) >= 0 ) - result.push_back(Pair("numaddresses", num)); + if ( (total= komodo_snapshot()) >= 0 ) + result.push_back(Pair("total", (double)total/COIN)); else result.push_back(Pair("error", "no addressindex")); return(result); } diff --git a/src/txdb.cpp b/src/txdb.cpp index d2ffb0b21..72ff85937 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -398,9 +398,9 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address); -int32_t CBlockTreeDB::Snapshot() +int64_t CBlockTreeDB::Snapshot() { - char chType; int32_t num = 0; std::string address; + char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); while (pcursor->Valid()) { @@ -421,7 +421,9 @@ int32_t CBlockTreeDB::Snapshot() ssValue >> nValue; getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - num++; + if ( total < 0 ) + total = (int64_t)nValue; + else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); pcursor->Next(); } catch (const std::exception& e) { @@ -432,7 +434,7 @@ int32_t CBlockTreeDB::Snapshot() break; } } - return(num); + return(total); } bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey ×tampIndex) { From 78a6f7041ec4d43fc29539b24d390c073ddc70d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 00:43:46 -1100 Subject: [PATCH 0180/1123] int64_t --- src/txdb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txdb.h b/src/txdb.h index a93e50f19..cb4d6d19e 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -94,7 +94,7 @@ public: bool ReadFlag(const std::string &name, bool &fValue); bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); - int32_t Snapshot(); + int64_t Snapshot(); }; #endif // BITCOIN_TXDB_H From 74db3cd02768174b4e4c37322d30a3ece8dca062 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 02:01:14 -1100 Subject: [PATCH 0181/1123] SeekToFirst --- src/main.cpp | 1 + src/txdb.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 8dee9bfea..c9a798e4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -590,6 +590,7 @@ int64_t komodo_snapshot() int64_t total = -1; if ( pblocktree != 0 ) total = pblocktree->Snapshot(); + else fprintf(stderr,"null pblocktree start with -addressindex=true\n"); return(total); } diff --git a/src/txdb.cpp b/src/txdb.cpp index 72ff85937..d061d7792 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,6 +402,8 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); + pcursor->SeekToFirst(); + fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { boost::this_thread::interruption_point(); From de84abc1b04c80b1be561fdd453c02bb95d959bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 02:06:11 -1100 Subject: [PATCH 0182/1123] Prints --- src/txdb.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index d061d7792..a0f764962 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -414,6 +414,7 @@ int64_t CBlockTreeDB::Snapshot() CAddressIndexKey indexKey; ssKey >> chType; ssKey >> indexKey; + fprintf(stderr,"chType.%d\n",chType); if ( chType == DB_ADDRESSINDEX ) { try { @@ -431,7 +432,7 @@ int64_t CBlockTreeDB::Snapshot() } catch (const std::exception& e) { return error("failed to get address index value"); } - } else break; + } else { break; } } catch (const std::exception& e) { break; } From 67d4c3beef517ad54efc56ac5c24243a65322f4c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 03:13:45 -1100 Subject: [PATCH 0183/1123] Test --- src/rpcmisc.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index b873dc495..3cc18c6a6 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -634,12 +634,12 @@ bool getAddressesFromParams(const UniValue& params, std::vector > addresses; @@ -753,8 +753,8 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp) " }\n" "]\n" "\nExamples:\n" - + HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'") - + HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}") + + HelpExampleCli("getaddressutxos", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'") + + HelpExampleRpc("getaddressutxos", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}") ); bool includeChainInfo = false; @@ -840,8 +840,8 @@ UniValue getaddressdeltas(const UniValue& params, bool fHelp) " }\n" "]\n" "\nExamples:\n" - + HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'") - + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}") + + HelpExampleCli("getaddressdeltas", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'") + + HelpExampleRpc("getaddressdeltas", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}") ); @@ -957,8 +957,8 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp) " \"received\" (string) The total number of satoshis received (including change)\n" "}\n" "\nExamples:\n" - + HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'") - + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}") + + HelpExampleCli("getaddressbalance", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'") + + HelpExampleRpc("getaddressbalance", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}") ); std::vector > addresses; @@ -1032,8 +1032,8 @@ UniValue getaddresstxids(const UniValue& params, bool fHelp) " ,...\n" "]\n" "\nExamples:\n" - + HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}'") - + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX\"]}") + + HelpExampleCli("getaddresstxids", "'{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}'") + + HelpExampleRpc("getaddresstxids", "{\"addresses\": [\"RY5LccmGiX9bUHYGtSWQouNy1yFhc5rM87\"]}") ); std::vector > addresses; From 32748f525e9db520b6def11a8c73b50268d92ce9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 03:38:36 -1100 Subject: [PATCH 0184/1123] New iterator --- src/txdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index a0f764962..151acdb68 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -401,7 +401,7 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; - boost::scoped_ptr pcursor(NewIterator()); + boost::scoped_ptr pcursor(const_cast(&db)->NewIterator()); pcursor->SeekToFirst(); fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) From afd86eb21ef844cabf3e21babf1ad6eb979d8e8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 03:46:42 -1100 Subject: [PATCH 0185/1123] Undo --- src/txdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 151acdb68..a0f764962 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -401,7 +401,7 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; - boost::scoped_ptr pcursor(const_cast(&db)->NewIterator()); + boost::scoped_ptr pcursor(NewIterator()); pcursor->SeekToFirst(); fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) From 28a62b60df3f57eaad1d946b75a1af6f3f7b15e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 05:46:21 -1100 Subject: [PATCH 0186/1123] Deterministic RNG for notary mining --- src/miner.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 35eb8e4d3..07e4a7a16 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -112,6 +112,7 @@ extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; uint32_t Mining_start,Mining_height; +int32_t My_notaryid = -1; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize); //uint64_t komodo_paxtotal(); @@ -472,13 +473,21 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) } pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && My_notaryid >= 0 ) { + uint32_t r; CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); if ( pblock->nTime < pindexPrev->nTime+60 ) pblock->nTime = pindexPrev->nTime + 60; if ( gpucount < 33 ) - pblock->nTime += (rand() % (33 - gpucount)*(33 - gpucount)); + { + uint8_t tmpbuffer[40]; int32_t n=0; bits256 randvals; + memcpy(&tmpbuffer[n],&My_notaryid,sizeof(My_notaryid)), n += sizeof(My_notaryid); + memcpy(&tmpbuffer[n],&Mining_height,sizeof(Mining_height)), n += sizeof(Mining_height); + memcpy(&tmpbuffer[n],&pblock->hashPrevBlock,sizeof(pblock->hashPrevBlock)), n += sizeof(pblock->hashPrevBlock); + vcalc_sha256(0,randvals.bytes,tmpbuffer,n); + pblock->nTime += (randvals.uints[0] % (33 - gpucount)*(33 - gpucount)); + } if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 ) { CAmount txfees = 5000; @@ -729,7 +738,8 @@ void static BitcoinMiner() break; } komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime()); - + if ( notaryid != My_notaryid ) + My_notaryid = notaryid; std::string solver; //if ( notaryid >= 0 || ASSETCHAINS_SYMBOL[0] != 0 ) solver = "tromp"; From 55566f16bd2cb405d93e896ed2b687beaa1c7853 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 05:50:20 -1100 Subject: [PATCH 0187/1123] Fix --- src/miner.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 07e4a7a16..45b70040f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -481,12 +481,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) pblock->nTime = pindexPrev->nTime + 60; if ( gpucount < 33 ) { - uint8_t tmpbuffer[40]; int32_t n=0; bits256 randvals; + uint8_t tmpbuffer[40]; uint32_t r; int32_t n=0; uint256 randvals; memcpy(&tmpbuffer[n],&My_notaryid,sizeof(My_notaryid)), n += sizeof(My_notaryid); memcpy(&tmpbuffer[n],&Mining_height,sizeof(Mining_height)), n += sizeof(Mining_height); memcpy(&tmpbuffer[n],&pblock->hashPrevBlock,sizeof(pblock->hashPrevBlock)), n += sizeof(pblock->hashPrevBlock); - vcalc_sha256(0,randvals.bytes,tmpbuffer,n); - pblock->nTime += (randvals.uints[0] % (33 - gpucount)*(33 - gpucount)); + vcalc_sha256(0,(void *)&randvals,tmpbuffer,n); + memcpy(&r,&randvals,sizeof(r)); + pblock->nTime += (r % (33 - gpucount)*(33 - gpucount)); } if ( komodo_notaryvin(txNotary,NOTARY_PUBKEY33) > 0 ) { From 292809f76cc838ca0d2f4996df46c3016eac291b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 05:51:17 -1100 Subject: [PATCH 0188/1123] Fix --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 45b70040f..327382089 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -109,6 +109,7 @@ extern int32_t ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOS extern uint64_t ASSETCHAINS_REWARD,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY; +void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; uint32_t Mining_start,Mining_height; From 9a146fef7685b8b84d0b6c490f6996e0e5b17068 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 12 Jun 2018 05:52:44 -1100 Subject: [PATCH 0189/1123] Fix --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 327382089..5f753f267 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -486,7 +486,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) memcpy(&tmpbuffer[n],&My_notaryid,sizeof(My_notaryid)), n += sizeof(My_notaryid); memcpy(&tmpbuffer[n],&Mining_height,sizeof(Mining_height)), n += sizeof(Mining_height); memcpy(&tmpbuffer[n],&pblock->hashPrevBlock,sizeof(pblock->hashPrevBlock)), n += sizeof(pblock->hashPrevBlock); - vcalc_sha256(0,(void *)&randvals,tmpbuffer,n); + vcalc_sha256(0,(uint8_t *)&randvals,tmpbuffer,n); memcpy(&r,&randvals,sizeof(r)); pblock->nTime += (r % (33 - gpucount)*(33 - gpucount)); } From 2c6d812dff58c67e91e2030a2031a70474afb1b1 Mon Sep 17 00:00:00 2001 From: St3rling0x <38841176+St3rling0x@users.noreply.github.com> Date: Wed, 13 Jun 2018 20:55:06 +0200 Subject: [PATCH 0190/1123] Added ZILLA --- src/assetchains | 1 + 1 file changed, 1 insertion(+) diff --git a/src/assetchains b/src/assetchains index ec77fba28..6697c1735 100755 --- a/src/assetchains +++ b/src/assetchains @@ -57,3 +57,4 @@ komodo_asset PRLPAY 500000000 komodo_asset DSEC 7000000 komodo_asset GLXT 100000000 komodo_asset EQL 500000000 +komodo_asset ZILLA 11000000 From a358386ba67592f84c75b9219f2a59b7688b9cb5 Mon Sep 17 00:00:00 2001 From: St3rling0x <38841176+St3rling0x@users.noreply.github.com> Date: Wed, 13 Jun 2018 20:56:09 +0200 Subject: [PATCH 0191/1123] added Zilla --- src/assetchains.old | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/assetchains.old b/src/assetchains.old index af9361746..44b494647 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -35,4 +35,6 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & ~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & +./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & + From cccc5ac04e95a5573f7982ca7488f1a8ab736f33 Mon Sep 17 00:00:00 2001 From: St3rling0x <38841176+St3rling0x@users.noreply.github.com> Date: Wed, 13 Jun 2018 20:56:34 +0200 Subject: [PATCH 0192/1123] Added Zilla --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index 44b494647..3f42fef13 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -34,7 +34,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & -~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & ./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & +~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & From 784e0917cfdfb3c6e53153bd6ee94e45d183ee06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 13 Jun 2018 08:48:47 -1100 Subject: [PATCH 0193/1123] Prevent skipping even old notarizations --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 690e91248..18a97ab00 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -694,7 +694,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 ) komodo_rwccdata((char *)"KMD",1,&ccdata,0); - if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) + if ( matched != 0 )//&& *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; From 77dbf244b8bab1a204afc20a9dd3c119f238c3b4 Mon Sep 17 00:00:00 2001 From: PTYX11 <32718517+ptyx11@users.noreply.github.com> Date: Wed, 13 Jun 2018 23:02:53 +0200 Subject: [PATCH 0194/1123] Added Zilla --- src/dpowassets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpowassets b/src/dpowassets index dbf928d79..b15bdbbd3 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -33,6 +33,6 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GLXT\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EQL\",\"pubkey\":\"$pubkey\"}" - +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZILLA\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" From cc175ed24d76527ef2ec4e5b0b1916a95fb1a1eb Mon Sep 17 00:00:00 2001 From: PTYX11 <32718517+ptyx11@users.noreply.github.com> Date: Wed, 13 Jun 2018 23:03:26 +0200 Subject: [PATCH 0195/1123] Added Zilla --- src/fiat-cli | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fiat-cli b/src/fiat-cli index 6183f35d1..1362833d9 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -30,3 +30,4 @@ echo prlpay; fiat/prlpay $1 $2 $3 $4 echo dsec; fiat/dsec $1 $2 $3 $4 echo glxt; fiat/glxt $1 $2 $3 $4 echo eql; fiat/eql $1 $2 $3 $4 +echo zilla; fiat/eql $1 $2 $3 $4 From 656133e978061028b3cc7b4c88408da9bb28025e Mon Sep 17 00:00:00 2001 From: PTYX11 <32718517+ptyx11@users.noreply.github.com> Date: Wed, 13 Jun 2018 23:03:51 +0200 Subject: [PATCH 0196/1123] changed to zilla --- src/fiat-cli | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fiat-cli b/src/fiat-cli index 1362833d9..4e1c61675 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -30,4 +30,4 @@ echo prlpay; fiat/prlpay $1 $2 $3 $4 echo dsec; fiat/dsec $1 $2 $3 $4 echo glxt; fiat/glxt $1 $2 $3 $4 echo eql; fiat/eql $1 $2 $3 $4 -echo zilla; fiat/eql $1 $2 $3 $4 +echo zilla; fiat/zilla $1 $2 $3 $4 From 62c218de74f2d5998248ca0a733e9bb178cd9b8e Mon Sep 17 00:00:00 2001 From: PTYX11 <32718517+ptyx11@users.noreply.github.com> Date: Wed, 13 Jun 2018 23:05:15 +0200 Subject: [PATCH 0197/1123] created zilla file --- src/fiat/zilla | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/fiat/zilla diff --git a/src/fiat/zilla b/src/fiat/zilla new file mode 100644 index 000000000..d8c713369 --- /dev/null +++ b/src/fiat/zilla @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=ZILLA $1 $2 $3 $4 $5 $6 From 68e359a462e4e29705218b6ce62338a23227a818 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 13 Jun 2018 21:01:32 -1100 Subject: [PATCH 0198/1123] Revert unfiltered notarizations --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 18a97ab00..690e91248 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -694,7 +694,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr } else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 ) komodo_rwccdata((char *)"KMD",1,&ccdata,0); - if ( matched != 0 )//&& *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) + if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height ) { sp->NOTARIZED_HEIGHT = *notarizedheightp; sp->NOTARIZED_HASH = srchash; From 7f3cc8a2969051f30e371f635de058e911a1d4a2 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Thu, 14 Jun 2018 08:35:53 -0300 Subject: [PATCH 0199/1123] create function to query notarisations leveldb by height --- src/crosschain.cpp | 72 ++++++++++++++++++++++++++---------------- src/main.cpp | 2 +- src/notarisationdb.cpp | 2 +- src/notarisationdb.h | 2 +- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index dd352b025..10910a48a 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -1,8 +1,11 @@ #include "cc/eval.h" +#include "crosschain.h" #include "importcoin.h" #include "main.h" #include "notarisationdb.h" -#include "komodo_structs.h" + + +int NOTARISATION_SCAN_LIMIT_BLOCKS = 1440; /* @@ -32,7 +35,7 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh int seenOwnNotarisations = 0; - for (int i=0; i<1440; i++) { + for (int i=0; i kmdHeight) break; NotarisationsInBlock notarisations; uint256 blockHash = *chainActive[kmdHeight-i]->phashBlock; @@ -60,6 +63,32 @@ end: } +/* + * Get a notarisation from a given height + * + * Will scan notarisations leveldb up to a limit + */ +template +int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &found) +{ + int limit = std::min(nHeight + NOTARISATION_SCAN_LIMIT_BLOCKS, chainActive.Height()); + + for (int h=nHeight; hphashBlock; + if (!GetBlockNotarisations(blockHash, notarisations)) + continue; + + BOOST_FOREACH(found, notarisations) { + if (f(found)) { + return h; + } + } + } + return 0; +} + + /* On KMD */ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_t targetCCid, const TxProof assetChainProof) @@ -152,12 +181,13 @@ void CompleteImportTransaction(CTransaction &importTx) } -struct notarized_checkpoint *komodo_npptr_at(int idx); -struct notarized_checkpoint *komodo_npptr_for_height(int32_t height, int *idx); +bool IsSameAssetChain(const Notarisation ¬a) { + return strcmp(nota.second.symbol, ASSETCHAINS_SYMBOL) == 0; +}; /* On assetchain */ -bool GetNextBacknotarisation(uint256 kmdNotarisationTxid, std::pair &out) +bool GetNextBacknotarisation(uint256 kmdNotarisationTxid, Notarisation &out) { /* * Here we are given a txid, and a proof. @@ -168,18 +198,10 @@ bool GetNextBacknotarisation(uint256 kmdNotarisationTxid, std::pairnotarized_desttxid, out); - throw std::runtime_error("Can't get backnotarisation"); + return (bool) ScanNotarisationsFromHeight(bn.second.height+1, &IsSameAssetChain, out); } -struct notarized_checkpoint* komodo_npptr(int32_t height); - /* * On assetchain * in: txid @@ -187,9 +209,9 @@ struct notarized_checkpoint* komodo_npptr(int32_t height); */ TxProof GetAssetchainProof(uint256 hash) { - int nIndex, md; + int nIndex; CBlockIndex* blockIndex; - struct notarized_checkpoint* np; + Notarisation nota; std::vector branch; { @@ -202,20 +224,18 @@ TxProof GetAssetchainProof(uint256 hash) throw std::runtime_error("tx still in mempool"); blockIndex = mapBlockIndex[blockHash]; - if (!(np = komodo_npptr(blockIndex->nHeight))) + if (!ScanNotarisationsFromHeight(blockIndex->nHeight, &IsSameAssetChain, nota)) throw std::runtime_error("notarisation not found"); // index of block in MoM leaves - nIndex = np->notarized_height - blockIndex->nHeight; - // MoMdepth shares space with ccid - md = np->MoMdepth & 0xffff; + nIndex = nota.second.height - blockIndex->nHeight; } // build merkle chain from blocks to MoM { std::vector leaves, tree; - for (int i=0; inotarized_height - i]->hashMerkleRoot; + for (int i=0; ihashMerkleRoot; leaves.push_back(mRoot); } bool fMutated; @@ -224,7 +244,7 @@ TxProof GetAssetchainProof(uint256 hash) // Check branch uint256 ourResult = SafeCheckMerkleBranch(blockIndex->hashMerkleRoot, branch, nIndex); - if (np->MoM != ourResult) + if (nota.second.MoM != ourResult) throw std::runtime_error("Failed merkle block->MoM"); } @@ -259,12 +279,10 @@ TxProof GetAssetchainProof(uint256 hash) } // Check the proof - if (np->MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) + if (nota.second.MoM != CBlock::CheckMerkleBranch(hash, branch, nIndex)) throw std::runtime_error("Failed validating MoM"); // All done! CDataStream ssProof(SER_NETWORK, PROTOCOL_VERSION); - return std::make_pair(np->notarized_desttxid, MerkleBranch(nIndex, branch)); + return std::make_pair(nota.second.txHash, MerkleBranch(nIndex, branch)); } - - diff --git a/src/main.cpp b/src/main.cpp index d8dc2ddf1..b67b1c478 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2919,7 +2919,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } // Record Notarisations - NotarisationsInBlock notarisations = GetNotarisationsInBlock(block, pindex->nHeight); + NotarisationsInBlock notarisations = ScanBlockNotarisations(block, pindex->nHeight); if (notarisations.size() > 0) { CLevelDBBatch batch; batch.Write(block.GetHash(), notarisations); diff --git a/src/notarisationdb.cpp b/src/notarisationdb.cpp index 4b2ade793..6210d88dd 100644 --- a/src/notarisationdb.cpp +++ b/src/notarisationdb.cpp @@ -12,7 +12,7 @@ NotarisationDB *pnotarisations; NotarisationDB::NotarisationDB(size_t nCacheSize, bool fMemory, bool fWipe) : CLevelDBWrapper(GetDataDir() / "notarisations", nCacheSize, fMemory, fWipe, false, 64) { } -NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight) +NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight) { EvalRef eval; NotarisationsInBlock vNotarisations; diff --git a/src/notarisationdb.h b/src/notarisationdb.h index 59c500fc4..ce5360e7d 100644 --- a/src/notarisationdb.h +++ b/src/notarisationdb.h @@ -18,7 +18,7 @@ extern NotarisationDB *pnotarisations; typedef std::pair Notarisation; typedef std::vector NotarisationsInBlock; -NotarisationsInBlock GetNotarisationsInBlock(const CBlock &block, int nHeight); +NotarisationsInBlock ScanBlockNotarisations(const CBlock &block, int nHeight); bool GetBlockNotarisations(uint256 blockHash, NotarisationsInBlock &nibs); bool GetBackNotarisation(uint256 notarisationHash, Notarisation &n); void WriteBackNotarisations(const NotarisationsInBlock notarisations, CLevelDBBatch &batch); From 84964112be9ff72f67692580302939b8f65b49f2 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sat, 16 Jun 2018 12:05:22 -0300 Subject: [PATCH 0200/1123] move disconnect notarisations from DisconnectBlock to DisconnectTip --- src/crosschain.cpp | 4 ++-- src/main.cpp | 54 ++++++++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 10910a48a..ddceb1b9b 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -75,8 +75,8 @@ int ScanNotarisationsFromHeight(int nHeight, const IsTarget f, Notarisation &fou for (int h=nHeight; hphashBlock; - if (!GetBlockNotarisations(blockHash, notarisations)) + + if (!GetBlockNotarisations(*chainActive[h]->phashBlock, notarisations)) continue; BOOST_FOREACH(found, notarisations) { diff --git a/src/main.cpp b/src/main.cpp index b67b1c478..563608cbf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2349,6 +2349,37 @@ static bool ApplyTxInUndo(const CTxInUndo& undo, CCoinsViewCache& view, const CO return fClean; } + +void ConnectNotarisations(const CBlock &block, int height) +{ + // Record Notarisations + NotarisationsInBlock notarisations = ScanBlockNotarisations(block, height); + if (notarisations.size() > 0) { + CLevelDBBatch batch; + batch.Write(block.GetHash(), notarisations); + WriteBackNotarisations(notarisations, batch); + pnotarisations->WriteBatch(batch, true); + LogPrintf("ConnectBlock: wrote %i block notarisations in block: %s\n", + notarisations.size(), block.GetHash().GetHex().data()); + } +} + + +void DisconnectNotarisations(const CBlock &block) +{ + // Delete from notarisations cache + NotarisationsInBlock nibs; + if (GetBlockNotarisations(block.GetHash(), nibs)) { + CLevelDBBatch batch; + batch.Erase(block.GetHash()); + EraseBackNotarisations(nibs, batch); + pnotarisations->WriteBatch(batch, true); + LogPrintf("DisconnectTip: deleted %i block notarisations in block: %s\n", + nibs.size(), block.GetHash().GetHex().data()); + } +} + + bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool* pfClean) { assert(pindex->GetBlockHash() == view.GetBestBlock()); @@ -2483,17 +2514,6 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } } - // Delete from notarisations cache - NotarisationsInBlock nibs; - if (GetBlockNotarisations(block.GetHash(), nibs)) { - CLevelDBBatch batch; - batch.Erase(block.GetHash()); - EraseBackNotarisations(nibs, batch); - pnotarisations->WriteBatch(batch, true); - LogPrintf("ConnectBlock: Deleted %i block notarisations in block: %s\n", - nibs.size(), block.GetHash().GetHex().data()); - } - // set the old best anchor back view.PopAnchor(blockUndo.old_tree_root); @@ -2918,16 +2938,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin setDirtyBlockIndex.insert(pindex); } - // Record Notarisations - NotarisationsInBlock notarisations = ScanBlockNotarisations(block, pindex->nHeight); - if (notarisations.size() > 0) { - CLevelDBBatch batch; - batch.Write(block.GetHash(), notarisations); - WriteBackNotarisations(notarisations, batch); - pnotarisations->WriteBatch(batch, true); - LogPrintf("ConnectBlock: wrote %i block notarisations in block: %s\n", - notarisations.size(), block.GetHash().GetHex().data()); - } + ConnectNotarisations(block, pindex->nHeight); if (fTxIndex) if (!pblocktree->WriteTxIndex(vPos)) @@ -3165,6 +3176,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if (!DisconnectBlock(block, state, pindexDelete, view)) return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString()); assert(view.Flush()); + DisconnectNotarisations(block); } LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); uint256 anchorAfterDisconnect = pcoinsTip->GetBestAnchor(); From 36f8002f93cadbc143bd619390079b5976fcb88d Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Sun, 17 Jun 2018 17:20:20 -0300 Subject: [PATCH 0201/1123] fix GetNextBacknotarisation --- src/crosschain.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index ddceb1b9b..d6493f35d 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -198,7 +198,16 @@ bool GetNextBacknotarisation(uint256 kmdNotarisationTxid, Notarisation &out) if (!GetBackNotarisation(kmdNotarisationTxid, bn)) return false; - return (bool) ScanNotarisationsFromHeight(bn.second.height+1, &IsSameAssetChain, out); + // Need to get block height of that backnotarisation + EvalRef eval; + CBlockIndex block; + CTransaction tx; + if (!eval->GetTxConfirmed(bn.first, tx, block)){ + fprintf(stderr, "Can't get height of backnotarisation, this should not happen\n"); + return false; + } + + return (bool) ScanNotarisationsFromHeight(block.nHeight+1, &IsSameAssetChain, out); } From 1c03ff0ecf8533958cdb8ecf73879b4b0d02d1c9 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Mon, 18 Jun 2018 21:15:49 +0700 Subject: [PATCH 0202/1123] Make src/fiat/zilla executable --- src/fiat/zilla | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 src/fiat/zilla diff --git a/src/fiat/zilla b/src/fiat/zilla old mode 100644 new mode 100755 From 469bd6378f9fa2189f34f5f26608c8ccccf4d590 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 19 Jun 2018 12:45:42 -0300 Subject: [PATCH 0203/1123] fix momom generation to inclusive or exclusive of whole blocks --- src/crosschain.cpp | 54 +++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index d6493f35d..4f19f0eb2 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -23,7 +23,7 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh * previous notarisation. * * kmdHeight notarisations-0 notarisations-1 - * | |********************| + * *********************| * > scan backwards > */ @@ -41,20 +41,25 @@ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeigh uint256 blockHash = *chainActive[kmdHeight-i]->phashBlock; if (!GetBlockNotarisations(blockHash, notarisations)) continue; + + // See if we have an own notarisation in this block BOOST_FOREACH(Notarisation& nota, notarisations) { - NotarisationData& data = nota.second; - if (data.ccId != targetCCid) - continue; - if (strcmp(data.symbol, symbol) == 0) + if (strcmp(nota.second.symbol, symbol) == 0) { seenOwnNotarisations++; - if (seenOwnNotarisations == 2) - goto end; if (seenOwnNotarisations == 1) destNotarisationTxid = nota.first; + else if (seenOwnNotarisations == 2) + goto end; + break; + } + } + + if (seenOwnNotarisations == 1) { + BOOST_FOREACH(Notarisation& nota, notarisations) { + if (nota.second.ccId == targetCCid) + moms.push_back(nota.second.MoM); } - if (seenOwnNotarisations == 1) - moms.push_back(data.MoM); } } @@ -108,14 +113,25 @@ TxProof GetCrossChainProof(const uint256 txid, const char* targetSymbol, uint32_ CTransaction sourceNotarisation; uint256 hashBlock; CBlockIndex blockIdx; - if (eval->GetTxConfirmed(assetChainProof.first, sourceNotarisation, blockIdx)) - kmdHeight = blockIdx.nHeight; - else if (eval->GetTxUnconfirmed(assetChainProof.first, sourceNotarisation, hashBlock)) - kmdHeight = chainActive.Tip()->nHeight; - else + if (!eval->GetTxConfirmed(assetChainProof.first, sourceNotarisation, blockIdx)) throw std::runtime_error("Notarisation not found"); + kmdHeight = blockIdx.nHeight; } + // We now have a kmdHeight of the notarisation from chain A. So we know that a MoM exists + // at that height. + // If we call CalculateProofRoot with that height, it'll scan backwards, until it finds + // a notarisation from B, and it might not include our notarisation from A + // at all. So, the thing we need to do is scan forwards to find the notarisation for B, + // that is inclusive of A. + Notarisation nota; + auto isTarget = [&](Notarisation ¬a) { + return strcmp(nota.second.symbol, targetSymbol) == 0; + }; + kmdHeight = ScanNotarisationsFromHeight(kmdHeight, isTarget, nota); + if (!kmdHeight) + throw std::runtime_error("Cannot find notarisation for target inclusive of source"); + // Get MoMs for kmd height and symbol std::vector moms; uint256 targetChainNotarisationTxid; @@ -233,7 +249,15 @@ TxProof GetAssetchainProof(uint256 hash) throw std::runtime_error("tx still in mempool"); blockIndex = mapBlockIndex[blockHash]; - if (!ScanNotarisationsFromHeight(blockIndex->nHeight, &IsSameAssetChain, nota)) + int h = blockIndex->nHeight; + // The assumption here is that the first notarisation for a height GTE than + // the transaction block height will contain the corresponding MoM. If there + // are sequence issues with the notarisations this may fail. + auto isTarget = [&](Notarisation ¬a) { + if (!IsSameAssetChain(nota)) return false; + return nota.second.height >= blockIndex->nHeight; + }; + if (!ScanNotarisationsFromHeight(blockIndex->nHeight, isTarget, nota)) throw std::runtime_error("notarisation not found"); // index of block in MoM leaves From 87d08c5a45602534ceaea7e97bd02a660bc663f1 Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Tue, 19 Jun 2018 20:39:04 -0300 Subject: [PATCH 0204/1123] some comments --- src/crosschain.cpp | 25 ++++++++++++++++++++----- src/rpccrosschain.cpp | 3 +-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 4f19f0eb2..ca7223abb 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -4,14 +4,29 @@ #include "main.h" #include "notarisationdb.h" +/* + * The crosschain workflow. + * + * 3 chains, A, B, and KMD. We would like to prove TX on B. + * There is a notarisation, nA0, which will include TX via an MoM. + * The notarisation nA0 must fall between 2 notarisations of B, + * ie, nB0 and nB1. An MoMoM including this range is propagated to + * B in notarisation receipt (backnotarisation) bnB2. + * + * A: TX bnA0 + * \ / + * KMD: nB0 nA0 nB1 nB2 + * \ \ \ + * B: bnB0 bnB1 bnB2 + */ + +// XXX: There are potential crashes wherever we access chainActive without a lock, +// because it might be disconnecting blocks at the same time. + int NOTARISATION_SCAN_LIMIT_BLOCKS = 1440; -/* - * This file is built in the server - */ - /* On KMD */ uint256 CalculateProofRoot(const char* symbol, uint32_t targetCCid, int kmdHeight, std::vector &moms, uint256 &destNotarisationTxid) @@ -258,7 +273,7 @@ TxProof GetAssetchainProof(uint256 hash) return nota.second.height >= blockIndex->nHeight; }; if (!ScanNotarisationsFromHeight(blockIndex->nHeight, isTarget, nota)) - throw std::runtime_error("notarisation not found"); + throw std::runtime_error("backnotarisation not yet confirmed"); // index of block in MoM leaves nIndex = nota.second.height - blockIndex->nHeight; diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index c99581406..35542613a 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -19,11 +19,10 @@ #include "script/standard.h" #include - #include - #include + using namespace std; int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip); From 8154603bf337c418e5ebc2635e0a4fa0cbb6d751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 20 Jun 2018 05:03:31 -1100 Subject: [PATCH 0205/1123] Change entropy source for PoS to blockhash[-50] --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1b35918c5..8eed2572b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1100,7 +1100,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( (minage= nHeight*3) > 6000 ) minage = 6000; pindex = 0; - if ( (pindex= komodo_chainactive(nHeight>200?nHeight-200:1)) != 0 ) + if ( (pindex= komodo_chainactive(nHeight>50?nHeight-50:1)) != 0 ) { vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); segid = ((nHeight + addrhash.uints[0]) & 0x3f); From 4c36b53066e5a15896f556f1cbf9ab535868aacb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Jun 2018 07:27:09 -1100 Subject: [PATCH 0206/1123] +VRSC +RFOX --- src/assetchains.old | 3 ++- src/dpowassets | 2 ++ src/fiat-cli | 2 ++ src/fiat/rfox | 2 ++ src/fiat/vrsc | 2 ++ src/komodo_bitcoind.h | 2 +- 6 files changed, 11 insertions(+), 2 deletions(-) create mode 100755 src/fiat/rfox create mode 100755 src/fiat/vrsc diff --git a/src/assetchains.old b/src/assetchains.old index 3f42fef13..e6d019168 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -35,6 +35,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & ./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & -~/VerusCoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & +./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 78.47.196.146 & +~/veruscoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & diff --git a/src/dpowassets b/src/dpowassets index b15bdbbd3..f9d86dd57 100755 --- a/src/dpowassets +++ b/src/dpowassets @@ -36,3 +36,5 @@ curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dp curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZILLA\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RFOX\",\"freq\":10,\"pubkey\":\"$pubkey\"}" +curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VRSC\",\"freq\":10,\"pubkey\":\"$pubkey\"}" diff --git a/src/fiat-cli b/src/fiat-cli index 4e1c61675..910246e6c 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -31,3 +31,5 @@ echo dsec; fiat/dsec $1 $2 $3 $4 echo glxt; fiat/glxt $1 $2 $3 $4 echo eql; fiat/eql $1 $2 $3 $4 echo zilla; fiat/zilla $1 $2 $3 $4 +echo vrsc; fiat/zilla $1 $2 $3 $4 +echo rfox; fiat/zilla $1 $2 $3 $4 diff --git a/src/fiat/rfox b/src/fiat/rfox new file mode 100755 index 000000000..e082505d0 --- /dev/null +++ b/src/fiat/rfox @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=RFOX $1 $2 $3 $4 $5 $6 diff --git a/src/fiat/vrsc b/src/fiat/vrsc new file mode 100755 index 000000000..6cd4dd1fb --- /dev/null +++ b/src/fiat/vrsc @@ -0,0 +1,2 @@ +#!/bin/bash +./komodo-cli -ac_name=VRSC $1 $2 $3 $4 $5 $6 diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8eed2572b..5a41c2bfc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1097,7 +1097,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - if ( (minage= nHeight*3) > 6000 ) + if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; if ( (pindex= komodo_chainactive(nHeight>50?nHeight-50:1)) != 0 ) From ce3cd49fb7e91ba297a1fc4c1bd6f3230183e1f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Jun 2018 07:57:56 -1100 Subject: [PATCH 0207/1123] Fix zilla --- src/fiat-cli | 4 ++-- src/fiat/zilla | 0 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 src/fiat/zilla diff --git a/src/fiat-cli b/src/fiat-cli index 910246e6c..2838575f9 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -31,5 +31,5 @@ echo dsec; fiat/dsec $1 $2 $3 $4 echo glxt; fiat/glxt $1 $2 $3 $4 echo eql; fiat/eql $1 $2 $3 $4 echo zilla; fiat/zilla $1 $2 $3 $4 -echo vrsc; fiat/zilla $1 $2 $3 $4 -echo rfox; fiat/zilla $1 $2 $3 $4 +echo vrsc; fiat/vrsc $1 $2 $3 $4 +echo rfox; fiat/rfox $1 $2 $3 $4 diff --git a/src/fiat/zilla b/src/fiat/zilla old mode 100644 new mode 100755 From 9d13e5c842de93c4d215fa09bf6145a3237c4315 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 21 Jun 2018 08:00:43 -1100 Subject: [PATCH 0208/1123] -addnode --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index e6d019168..228767f25 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -35,7 +35,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & ./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & -./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 78.47.196.146 & +./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & ~/veruscoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & From 38e9a59c2c389a03cfb8132fca65884e3ea4be6c Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 25 Jun 2018 14:16:08 -0400 Subject: [PATCH 0209/1123] add help doc for KV --- src/rpcblockchain.cpp | 23 ++++++++++++++++++++++- src/wallet/rpcwallet.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fc6092e03..8e13fb666 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -767,7 +767,28 @@ UniValue kvsearch(const UniValue& params, bool fHelp) { UniValue ret(UniValue::VOBJ); uint32_t flags; uint8_t value[IGUANA_MAXSCRIPTSIZE],key[IGUANA_MAXSCRIPTSIZE]; int32_t duration,j,height,valuesize,keylen; uint256 refpubkey; static uint256 zeroes; if (fHelp || params.size() != 1 ) - throw runtime_error("kvsearch key"); + throw runtime_error( + "kvsearch key\n" + "\nSearch for a key stored via the kvupdate command. This feature is only available for asset chains.\n" + "\nArguments:\n" + "1. key (string, required) search the chain for this key\n" + "\nResult:\n" + "{\n" + " \"coin\": \"xxxxx\", (string) chain the key is stored on\n" + " \"currentheight\": xxxxx, (numeric) current height of the chain\n" + " \"key\": \"xxxxx\", (string) key\n" + " \"keylen\": xxxxx, (string) length of the key \n" + " \"owner\": \"xxxx\" (string) hex string representing the owner of the key \n" + " \"height\": xxxxx, (numeric) height the key was stored at\n" + " \"expiration\": xxxxx, (numeric) height the key will expire\n" + " \"flags\": x (numeric) 1 if the key was created with a password; 0 otherwise.\n" + " \"value\": \"xxxxx\", (string) stored value\n" + " \"valuesize\": xxxxx (string) amount of characters stored\n" + "}\n" + "\nExamples:\n" + + HelpExampleCli("kvsearch", "examplekey") + + HelpExampleRpc("kvsearch", "examplekey") + ); LOCK(cs_main); if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7187b8fe8..c8b350b73 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -509,7 +509,31 @@ UniValue kvupdate(const UniValue& params, bool fHelp) CWalletTx wtx; UniValue ret(UniValue::VOBJ); uint8_t keyvalue[IGUANA_MAXSCRIPTSIZE],opretbuf[IGUANA_MAXSCRIPTSIZE]; int32_t i,coresize,haveprivkey,duration,opretlen,height; uint16_t keylen=0,valuesize=0,refvaluesize=0; uint8_t *key,*value=0; uint32_t flags,tmpflags,n; struct komodo_kv *ptr; uint64_t fee; uint256 privkey,pubkey,refpubkey,sig; if (fHelp || params.size() < 3 ) - throw runtime_error("kvupdate key value flags/passphrase"); + throw runtime_error( + "kvupdate key \"value\" days passphrase\n" + "\nStore a key value. This feature is only available for asset chains.\n" + "\nArguments:\n" + "1. key (string, required) key\n" + "2. \"value\" (string, required) value\n" + "3. days (numeric, required) amount of days(1440 blocks/day) before the key expires. Minimum 1 day\n" + "4. passphrase (string, optional) passphrase required to update this key\n" + "\nResult:\n" + "{\n" + " \"coin\": \"xxxxx\", (string) chain the key is stored on\n" + " \"height\": xxxxx, (numeric) height the key was stored at\n" + " \"expiration\": \"xxxxx\", (numeric) height the key will expire\n" + " \"flags\": xxxxx, (string) amount of days the key will be stored \n" + " \"key\": xxxxx, (numeric) stored key\n" + " \"keylen\": xxxxx, (numeric) length of the key\n" + " \"value\": x (numeric) stored value\n" + " \"valuesize\": \"xxxxx\", (string) length of the stored value\n" + " \"fee\": xxxxx (string) transaction fee paid to store the key\n" + " \"txid\": xxxxx (string) transaction id\n" + "}\n" + "\nExamples:\n" + + HelpExampleCli("kvupdate", "examplekey \"examplevalue\" 2 examplepassphrase") + + HelpExampleRpc("kvupdate", "examplekey \"examplevalue\" 2 examplepassphrase") + ); if (!EnsureWalletIsAvailable(fHelp)) return 0; if ( ASSETCHAINS_SYMBOL[0] == 0 ) From 6f3db929c641b64c6810f720c720a9c1e408ba83 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Mon, 25 Jun 2018 14:42:07 -0400 Subject: [PATCH 0210/1123] fix KV help --- src/rpcblockchain.cpp | 2 +- src/wallet/rpcwallet.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 8e13fb666..cfb89815b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -778,7 +778,7 @@ UniValue kvsearch(const UniValue& params, bool fHelp) " \"currentheight\": xxxxx, (numeric) current height of the chain\n" " \"key\": \"xxxxx\", (string) key\n" " \"keylen\": xxxxx, (string) length of the key \n" - " \"owner\": \"xxxx\" (string) hex string representing the owner of the key \n" + " \"owner\": \"xxxxx\" (string) hex string representing the owner of the key \n" " \"height\": xxxxx, (numeric) height the key was stored at\n" " \"expiration\": xxxxx, (numeric) height the key will expire\n" " \"flags\": x (numeric) 1 if the key was created with a password; 0 otherwise.\n" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c8b350b73..bbbc9d897 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -521,14 +521,14 @@ UniValue kvupdate(const UniValue& params, bool fHelp) "{\n" " \"coin\": \"xxxxx\", (string) chain the key is stored on\n" " \"height\": xxxxx, (numeric) height the key was stored at\n" - " \"expiration\": \"xxxxx\", (numeric) height the key will expire\n" - " \"flags\": xxxxx, (string) amount of days the key will be stored \n" - " \"key\": xxxxx, (numeric) stored key\n" + " \"expiration\": xxxxx, (numeric) height the key will expire\n" + " \"flags\": x, (string) amount of days the key will be stored \n" + " \"key\": \"xxxxx\", (numeric) stored key\n" " \"keylen\": xxxxx, (numeric) length of the key\n" - " \"value\": x (numeric) stored value\n" - " \"valuesize\": \"xxxxx\", (string) length of the stored value\n" + " \"value\": \"xxxxx\" (numeric) stored value\n" + " \"valuesize\": xxxxx, (string) length of the stored value\n" " \"fee\": xxxxx (string) transaction fee paid to store the key\n" - " \"txid\": xxxxx (string) transaction id\n" + " \"txid\": \"xxxxx\" (string) transaction id\n" "}\n" "\nExamples:\n" + HelpExampleCli("kvupdate", "examplekey \"examplevalue\" 2 examplepassphrase") From ade63fa9491e771fef34113e9674c85bafabb440 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Jun 2018 02:57:08 -1100 Subject: [PATCH 0211/1123] +print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2466928c1..52651b7f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2832,7 +2832,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (fAddressIndex) { for (unsigned int k = 0; k < tx.vout.size(); k++) { const CTxOut &out = tx.vout[k]; - +fprintf(stderr,"add %d vouts\n",(int32_t)tx.vout.size()); if (out.scriptPubKey.IsPayToScriptHash()) { vector hashBytes(out.scriptPubKey.begin()+2, out.scriptPubKey.begin()+22); From ba31c2f4b4205942f1ea92bdd37b10eb596d5765 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Jun 2018 03:04:06 -1100 Subject: [PATCH 0212/1123] Fix pay to pubkey for -addressindex --- src/main.cpp | 10 +++++----- src/rpcblockchain.cpp | 2 +- src/txmempool.cpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 52651b7f4..6aed822e5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2430,7 +2430,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(2, uint160(hashBytes), hash, k), CAddressUnspentValue())); } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); + vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); // undo receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue)); @@ -2503,7 +2503,7 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23); + vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); // undo spending activity addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1)); @@ -2784,7 +2784,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin hashBytes = uint160(vector (prevout.scriptPubKey.begin()+2, prevout.scriptPubKey.begin()+22)); addressType = 2; } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - hashBytes = uint160(vector (prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23)); + hashBytes = uint160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); addressType = 1; } else { hashBytes.SetNull(); @@ -2832,7 +2832,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (fAddressIndex) { for (unsigned int k = 0; k < tx.vout.size(); k++) { const CTxOut &out = tx.vout[k]; -fprintf(stderr,"add %d vouts\n",(int32_t)tx.vout.size()); +//fprintf(stderr,"add %d vouts\n",(int32_t)tx.vout.size()); if (out.scriptPubKey.IsPayToScriptHash()) { vector hashBytes(out.scriptPubKey.begin()+2, out.scriptPubKey.begin()+22); @@ -2843,7 +2843,7 @@ fprintf(stderr,"add %d vouts\n",(int32_t)tx.vout.size()); addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(2, uint160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); + vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); // record receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ebb706167..0a47339fa 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -204,7 +204,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) delta.push_back(Pair("address", CBitcoinAddress(CScriptID(uint160(hashBytes))).ToString())); } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); + vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); delta.push_back(Pair("address", CBitcoinAddress(CKeyID(uint160(hashBytes))).ToString())); } else { continue; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index f2bf39c29..c7dafb5f4 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -138,7 +138,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC mapAddress.insert(make_pair(key, delta)); inserted.push_back(key); } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23); + vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); CMempoolAddressDeltaKey key(1, uint160(hashBytes), txhash, j, 1); CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n); mapAddress.insert(make_pair(key, delta)); @@ -154,7 +154,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue))); inserted.push_back(key); } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); + vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); std::pair ret; CMempoolAddressDeltaKey key(1, uint160(hashBytes), txhash, k, 0); mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue))); @@ -213,7 +213,7 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac addressHash = uint160(vector (prevout.scriptPubKey.begin()+2, prevout.scriptPubKey.begin()+22)); addressType = 2; } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - addressHash = uint160(vector (prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23)); + addressHash = uint160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); addressType = 1; } else { addressHash.SetNull(); From fa7bf712a164da7020d62d4b7b0ce9b015913fc9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Jun 2018 04:40:32 -1100 Subject: [PATCH 0213/1123] Add support for pay2pubkey for -addressindex --- src/main.cpp | 66 ++++++++++++++++++++++++++++++++------- src/rpcblockchain.cpp | 26 ++++++++++++--- src/rpcmisc.cpp | 6 +++- src/rpcrawtransaction.cpp | 6 +++- src/script/script.cpp | 8 +++++ src/script/script.h | 1 + src/txmempool.cpp | 36 ++++++++++++++++----- 7 files changed, 123 insertions(+), 26 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6aed822e5..5a1cdcd10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2429,8 +2429,9 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // undo unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(2, uint160(hashBytes), hash, k), CAddressUnspentValue())); - } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + } + else if (out.scriptPubKey.IsPayToPublicKeyHash()) { + vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); // undo receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue)); @@ -2438,7 +2439,18 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // undo unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, uint160(hashBytes), hash, k), CAddressUnspentValue())); - } else { + } + else if (out.scriptPubKey.IsPayToPublicKey()) { + vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + + // undo receiving activity + addressIndex.push_back(make_pair(CAddressIndexKey(3, uint160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue)); + + // undo unspent index + addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(3, uint160(hashBytes), hash, k), CAddressUnspentValue())); + + } + else { continue; } @@ -2502,8 +2514,9 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(2, uint160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); - } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); + } + else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { + vector hashBytes(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23); // undo spending activity addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1)); @@ -2511,7 +2524,18 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex // restore unspent index addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, uint160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); - } else { + } + else if (prevout.scriptPubKey.IsPayToPublicKey()) { + vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); + + // undo spending activity + addressIndex.push_back(make_pair(CAddressIndexKey(3, Hash160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1)); + + // restore unspent index + addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(3, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); + + } + else { continue; } } @@ -2783,10 +2807,16 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (prevout.scriptPubKey.IsPayToScriptHash()) { hashBytes = uint160(vector (prevout.scriptPubKey.begin()+2, prevout.scriptPubKey.begin()+22)); addressType = 2; - } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - hashBytes = uint160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); + } + else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { + hashBytes = uint160(vector (prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23)); addressType = 1; - } else { + } + else if (prevout.scriptPubKey.IsPayToPublicKey()) { + hashBytes = uint160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); + addressType = 3; + } + else { hashBytes.SetNull(); addressType = 0; } @@ -2842,8 +2872,9 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // record unspent output addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(2, uint160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); - } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + } + else if (out.scriptPubKey.IsPayToPublicKeyHash()) { + vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); // record receiving activity addressIndex.push_back(make_pair(CAddressIndexKey(1, uint160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); @@ -2851,7 +2882,18 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin // record unspent output addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, uint160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); - } else { + } + else if (out.scriptPubKey.IsPayToPublicKey()) { + vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + + // record receiving activity + addressIndex.push_back(make_pair(CAddressIndexKey(3, Hash160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); + + // record unspent output + addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(3, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); + + } + else { continue; } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 0a47339fa..ca9a21278 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -172,9 +172,14 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) if (GetSpentIndex(spentKey, spentInfo)) { if (spentInfo.addressType == 1) { delta.push_back(Pair("address", CBitcoinAddress(CKeyID(spentInfo.addressHash)).ToString())); - } else if (spentInfo.addressType == 2) { + } + else if (spentInfo.addressType == 2) { delta.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); - } else { + } + else if (spentInfo.addressType == 3) { + xxx delta.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); + } + else { continue; } delta.push_back(Pair("satoshis", -1 * spentInfo.satoshis)); @@ -203,10 +208,21 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) vector hashBytes(out.scriptPubKey.begin()+2, out.scriptPubKey.begin()+22); delta.push_back(Pair("address", CBitcoinAddress(CScriptID(uint160(hashBytes))).ToString())); - } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + } + else if (out.scriptPubKey.IsPayToPublicKeyHash()) { + vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); delta.push_back(Pair("address", CBitcoinAddress(CKeyID(uint160(hashBytes))).ToString())); - } else { + } + else if (out.scriptPubKey.IsPayToPublicKey()) { + CTxDestination address; + if (ExtractDestination(out.scriptPubKey, address)) + { + //vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + //xxx delta.push_back(Pair("address", CBitcoinAddress(CKeyID(uint160(hashBytes))).ToString())); + delta.push_back(Pair("address", address.ToString())); + } + } + else { continue; } diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 3cc18c6a6..67518c09c 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -603,7 +603,11 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr address = CBitcoinAddress(CScriptID(hash)).ToString(); } else if (type == 1) { address = CBitcoinAddress(CKeyID(hash)).ToString(); - } else { + } + else if (type == 3) { + xxx address = CBitcoinAddress(CKeyID(hash)).ToString(); + } + else { return false; } return true; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 91dff8bf9..ff6df3505 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -161,9 +161,13 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& in.push_back(Pair("valueSat", spentInfo.satoshis)); if (spentInfo.addressType == 1) { in.push_back(Pair("address", CBitcoinAddress(CKeyID(spentInfo.addressHash)).ToString())); - } else if (spentInfo.addressType == 2) { + } + else if (spentInfo.addressType == 2) { in.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); } + else if (spentInfo.addressType == 3) { + xxx in.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); + } } } in.push_back(Pair("sequence", (int64_t)txin.nSequence)); diff --git a/src/script/script.cpp b/src/script/script.cpp index 160c57016..4cffc6c5a 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -229,6 +229,14 @@ bool CScript::IsPayToPublicKeyHash() const (*this)[24] == OP_CHECKSIG); } +bool CScript::IsPayToPublicKey() const +{ + // Extra-fast test for pay-to-pubkey CScripts: + return (this->size() == 35 && + (*this)[0] == 33 && + (*this)[34] == OP_CHECKSIG); +} + bool CScript::IsPayToScriptHash() const { // Extra-fast test for pay-to-script-hash CScripts: diff --git a/src/script/script.h b/src/script/script.h index 864a92f1f..56d2ff0b6 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -567,6 +567,7 @@ public: unsigned int GetSigOpCount(const CScript& scriptSig) const; bool IsPayToPublicKeyHash() const; + bool IsPayToPublicKey() const; bool IsPayToScriptHash() const; bool IsPayToCryptoCondition() const; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index c7dafb5f4..67e79b5cf 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -137,13 +137,21 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n); mapAddress.insert(make_pair(key, delta)); inserted.push_back(key); - } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); + } + else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { + vector hashBytes(prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23); CMempoolAddressDeltaKey key(1, uint160(hashBytes), txhash, j, 1); CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n); mapAddress.insert(make_pair(key, delta)); inserted.push_back(key); } + else if (prevout.scriptPubKey.IsPayToPublicKey()) { + vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); + CMempoolAddressDeltaKey key(3, Hash160(hashBytes), txhash, j, 1); + CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n); + mapAddress.insert(make_pair(key, delta)); + inserted.push_back(key); + } } for (unsigned int k = 0; k < tx.vout.size(); k++) { @@ -153,13 +161,21 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC CMempoolAddressDeltaKey key(2, uint160(hashBytes), txhash, k, 0); mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue))); inserted.push_back(key); - } else if (out.scriptPubKey.IsPayToPublicKeyHash()) { - vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + } + else if (out.scriptPubKey.IsPayToPublicKeyHash()) { + vector hashBytes(out.scriptPubKey.begin()+3, out.scriptPubKey.begin()+23); std::pair ret; CMempoolAddressDeltaKey key(1, uint160(hashBytes), txhash, k, 0); mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue))); inserted.push_back(key); } + else if (out.scriptPubKey.IsPayToPublicKey()) { + vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); + std::pair ret; + CMempoolAddressDeltaKey key(3, Hash160(hashBytes), txhash, k, 0); + mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue))); + inserted.push_back(key); + } } mapAddressInserted.insert(make_pair(txhash, inserted)); @@ -212,10 +228,16 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac if (prevout.scriptPubKey.IsPayToScriptHash()) { addressHash = uint160(vector (prevout.scriptPubKey.begin()+2, prevout.scriptPubKey.begin()+22)); addressType = 2; - } else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { - addressHash = uint160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); + } + else if (prevout.scriptPubKey.IsPayToPublicKeyHash()) { + addressHash = uint160(vector (prevout.scriptPubKey.begin()+3, prevout.scriptPubKey.begin()+23)); addressType = 1; - } else { + } + else if (prevout.scriptPubKey.IsPayToPublicKey()) { + addressHash = Hash160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); + addressType = 3; + } + else { addressHash.SetNull(); addressType = 0; } From dc276bd08718349f69f6cf47e80bb5b97295647d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Jun 2018 06:18:12 -1100 Subject: [PATCH 0214/1123] Map address type 3 -> 1 --- src/main.cpp | 10 +++++----- src/rpcblockchain.cpp | 3 --- src/rpcrawtransaction.cpp | 3 --- src/txmempool.cpp | 6 +++--- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5a1cdcd10..bb1f959ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2529,10 +2529,10 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); // undo spending activity - addressIndex.push_back(make_pair(CAddressIndexKey(3, Hash160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1)); + addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, j, true), prevout.nValue * -1)); // restore unspent index - addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(3, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); + addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), input.prevout.hash, input.prevout.n), CAddressUnspentValue(prevout.nValue, prevout.scriptPubKey, undo.nHeight))); } else { @@ -2814,7 +2814,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin } else if (prevout.scriptPubKey.IsPayToPublicKey()) { hashBytes = uint160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); - addressType = 3; + addressType = 1; } else { hashBytes.SetNull(); @@ -2887,10 +2887,10 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); // record receiving activity - addressIndex.push_back(make_pair(CAddressIndexKey(3, Hash160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); + addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, txhash, k, false), out.nValue)); // record unspent output - addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(3, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); + addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), txhash, k), CAddressUnspentValue(out.nValue, out.scriptPubKey, pindex->nHeight))); } else { diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ca9a21278..28f7dc38c 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -176,9 +176,6 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) else if (spentInfo.addressType == 2) { delta.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); } - else if (spentInfo.addressType == 3) { - xxx delta.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); - } else { continue; } diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index ff6df3505..a9aff1b7f 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -165,9 +165,6 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& else if (spentInfo.addressType == 2) { in.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); } - else if (spentInfo.addressType == 3) { - xxx in.push_back(Pair("address", CBitcoinAddress(CScriptID(spentInfo.addressHash)).ToString())); - } } } in.push_back(Pair("sequence", (int64_t)txin.nSequence)); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 67e79b5cf..51ed1103e 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -147,7 +147,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC } else if (prevout.scriptPubKey.IsPayToPublicKey()) { vector hashBytes(prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34); - CMempoolAddressDeltaKey key(3, Hash160(hashBytes), txhash, j, 1); + CMempoolAddressDeltaKey key(1, Hash160(hashBytes), txhash, j, 1); CMempoolAddressDelta delta(entry.GetTime(), prevout.nValue * -1, input.prevout.hash, input.prevout.n); mapAddress.insert(make_pair(key, delta)); inserted.push_back(key); @@ -172,7 +172,7 @@ void CTxMemPool::addAddressIndex(const CTxMemPoolEntry &entry, const CCoinsViewC else if (out.scriptPubKey.IsPayToPublicKey()) { vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); std::pair ret; - CMempoolAddressDeltaKey key(3, Hash160(hashBytes), txhash, k, 0); + CMempoolAddressDeltaKey key(1, Hash160(hashBytes), txhash, k, 0); mapAddress.insert(make_pair(key, CMempoolAddressDelta(entry.GetTime(), out.nValue))); inserted.push_back(key); } @@ -235,7 +235,7 @@ void CTxMemPool::addSpentIndex(const CTxMemPoolEntry &entry, const CCoinsViewCac } else if (prevout.scriptPubKey.IsPayToPublicKey()) { addressHash = Hash160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); - addressType = 3; + addressType = 1; } else { addressHash.SetNull(); From 98d1a795df36ac9bd3026efffc50c8b7641a2ffc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Jun 2018 06:23:36 -1100 Subject: [PATCH 0215/1123] Test --- src/rpcblockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 28f7dc38c..42cf7f2b0 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -216,7 +216,7 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) { //vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); //xxx delta.push_back(Pair("address", CBitcoinAddress(CKeyID(uint160(hashBytes))).ToString())); - delta.push_back(Pair("address", address.ToString())); + delta.push_back(Pair("address", CBitcoinAddress(address).ToString())); } } else { From 17e4ca47c79f511ac0a4cd1d1e0936efec3bf1d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Jun 2018 06:31:38 -1100 Subject: [PATCH 0216/1123] Syntax --- src/rpcmisc.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 67518c09c..065739a9a 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -604,9 +604,6 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr } else if (type == 1) { address = CBitcoinAddress(CKeyID(hash)).ToString(); } - else if (type == 3) { - xxx address = CBitcoinAddress(CKeyID(hash)).ToString(); - } else { return false; } From 31e2a04e3e64242a6fa3b4d46a631b8af8f1a1d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 26 Jun 2018 06:50:37 -1100 Subject: [PATCH 0217/1123] Fix --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bb1f959ad..98fdf9452 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2444,10 +2444,10 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex vector hashBytes(out.scriptPubKey.begin()+1, out.scriptPubKey.begin()+34); // undo receiving activity - addressIndex.push_back(make_pair(CAddressIndexKey(3, uint160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue)); + addressIndex.push_back(make_pair(CAddressIndexKey(1, Hash160(hashBytes), pindex->nHeight, i, hash, k, false), out.nValue)); // undo unspent index - addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(3, uint160(hashBytes), hash, k), CAddressUnspentValue())); + addressUnspentIndex.push_back(make_pair(CAddressUnspentKey(1, Hash160(hashBytes), hash, k), CAddressUnspentValue())); } else { @@ -2813,7 +2813,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin addressType = 1; } else if (prevout.scriptPubKey.IsPayToPublicKey()) { - hashBytes = uint160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); + hashBytes = Hash160(vector (prevout.scriptPubKey.begin()+1, prevout.scriptPubKey.begin()+34)); addressType = 1; } else { From abe140dad5c73968b4aab9d20c25a93f63dc5d63 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Wed, 27 Jun 2018 03:44:34 +0300 Subject: [PATCH 0218/1123] RFOX added to assetchains file --- src/assetchains | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/assetchains b/src/assetchains index 6697c1735..759d198a7 100755 --- a/src/assetchains +++ b/src/assetchains @@ -21,6 +21,13 @@ function komodo_asset () supply=" " fi + if [ -n "$3" ] + then + supply=" -ac_reward=$3" + else + supply=" " + fi + $komodo_binary -ac_name=$1 $gen $supply $args -pubkey=$pubkey -addnode=$seed_ip & sleep $delay } @@ -58,3 +65,4 @@ komodo_asset DSEC 7000000 komodo_asset GLXT 100000000 komodo_asset EQL 500000000 komodo_asset ZILLA 11000000 +komodo_asset RFOX 1000000000 100000000 From 80b521772c9c8f13e5142a27612827acddf036be Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Wed, 27 Jun 2018 03:52:05 +0300 Subject: [PATCH 0219/1123] RFOX added to assetchains file --- src/assetchains | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index 759d198a7..d5a87485e 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,9 +1,13 @@ #!/bin/bash + source pubkey.txt +# You can now add delay line to pubkey.txt file + args=("$@") seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` komodo_binary='./komodod' -delay=20 + +if [ -z "$delay" ]; then delay=20; fi function komodo_asset () { From 435c6bb1ccd41f00596b23bb2a04852b5fbb5cb5 Mon Sep 17 00:00:00 2001 From: Mihail Fedorov Date: Wed, 27 Jun 2018 04:07:28 +0300 Subject: [PATCH 0220/1123] fix --- src/assetchains | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/assetchains b/src/assetchains index d5a87485e..4029dc039 100755 --- a/src/assetchains +++ b/src/assetchains @@ -27,12 +27,12 @@ function komodo_asset () if [ -n "$3" ] then - supply=" -ac_reward=$3" + reward=" -ac_reward=$3" else - supply=" " + reward=" " fi - $komodo_binary -ac_name=$1 $gen $supply $args -pubkey=$pubkey -addnode=$seed_ip & + $komodo_binary -ac_name=$1 $gen $supply $reward $args -pubkey=$pubkey -addnode=$seed_ip & sleep $delay } From 67df454d1154a3cfde465b6cc245670a93857819 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jun 2018 00:40:49 -1100 Subject: [PATCH 0221/1123] End free4all at height 1 million, cap PoSdiff to mindiff*4 --- src/komodo_bitcoind.h | 6 +++++- src/miner.cpp | 2 +- src/pow.cpp | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5a41c2bfc..fb3d2702b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1088,7 +1088,11 @@ uint32_t komodo_segid32(char *coinaddr) 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; + CBlockIndex *pindex; bool fNegative,fOverflow; 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; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); + if ( bnTarget > bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) blocktime = prevtime+57; diff --git a/src/miner.cpp b/src/miner.cpp index ec410384f..6008fd5d9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -861,7 +861,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 ) { j = 65; - if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 ) + if ( (Mining_height >= 235300 && Mining_height < 236000) || (Mining_height % KOMODO_ELECTION_GAP) > 64 || (Mining_height % KOMODO_ELECTION_GAP) == 0 || Mining_height > 1000000 ) { int32_t dispflag = 0; if ( notaryid <= 3 || notaryid == 32 || (notaryid >= 43 && notaryid <= 45) ||notaryid == 51 || notaryid == 52 || notaryid == 56 || notaryid == 57 || notaryid == 62 ) diff --git a/src/pow.cpp b/src/pow.cpp index e942883f2..2e525e8cb 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -172,7 +172,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int else if ( height >= 80000 && height < 108000 && special2 > 0 ) flag = 1; else if ( height >= 108000 && special2 > 0 ) - flag = ((height % KOMODO_ELECTION_GAP) > 64 || (height % KOMODO_ELECTION_GAP) == 0); + flag = (height > 1000000 || (height % KOMODO_ELECTION_GAP) > 64 || (height % KOMODO_ELECTION_GAP) == 0); else if ( height == 790833 ) flag = 1; else if ( special2 < 0 ) From 68761a40ee50b174c347e65071e6d7068012dde6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jun 2018 01:52:14 -1100 Subject: [PATCH 0222/1123] Fix bnTarget compare direction --- src/komodo_bitcoind.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fb3d2702b..0e8d8ddfd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1089,10 +1089,6 @@ uint32_t komodo_segid32(char *coinaddr) 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; bool fNegative,fOverflow; 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; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); - if ( bnTarget > bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) blocktime = prevtime+57; @@ -1101,6 +1097,10 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; From adc354ef47245fba16b0623582fcd8214caf15a6 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Wed, 27 Jun 2018 20:43:34 +0700 Subject: [PATCH 0223/1123] Add assetchains.json --- src/assetchains.json | 157 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 src/assetchains.json diff --git a/src/assetchains.json b/src/assetchains.json new file mode 100644 index 000000000..7837b95af --- /dev/null +++ b/src/assetchains.json @@ -0,0 +1,157 @@ +[ + { + "name": "REVS", + "rpcPort": 1234, + "params": "-ac_name=REVS -ac_supply=1300000" + }, + { + "name": "SUPERNET", + "rpcPort": 1234, + "params": "-ac_name=SUPERNET -ac_supply=816061" + }, + { + "name": "DEX", + "rpcPort": 1234, + "params": "-ac_name=DEX -ac_supply=999999" + }, + { + "name": "PANGEA", + "rpcPort": 1234, + "params": "-ac_name=PANGEA -ac_supply=999999" + }, + { + "name": "JUMBLR", + "rpcPort": 1234, + "params": "-ac_name=JUMBLR -ac_supply=999999" + }, + { + "name": "BET", + "rpcPort": 1234, + "params": "-ac_name=BET -ac_supply=999999" + }, + { + "name": "CRYPTO", + "rpcPort": 1234, + "params": "-ac_name=CRYPTO -ac_supply=999999" + }, + { + "name": "HODL", + "rpcPort": 1234, + "params": "-ac_name=HODL -ac_supply=9999999" + }, + { + "name": "MSHARK", + "rpcPort": 1234, + "params": "-ac_name=MSHARK -ac_supply=1400000" + }, + { + "name": "BOTS", + "rpcPort": 1234, + "params": "-ac_name=BOTS -ac_supply=999999" + }, + { + "name": "MGW", + "rpcPort": 1234, + "params": "-ac_name=MGW -ac_supply=999999" + }, + { + "name": "COQUI", + "rpcPort": 1234, + "params": "-ac_name=COQUI -ac_supply=72000000" + }, + { + "name": "WLC", + "rpcPort": 1234, + "params": "-ac_name=WLC -ac_supply=210000000" + }, + { + "name": "KV", + "rpcPort": 1234, + "params": "-ac_name=KV -ac_supply=1000000" + }, + { + "name": "CEAL", + "rpcPort": 1234, + "params": "-ac_name=CEAL -ac_supply=366666666" + }, + { + "name": "MESH", + "rpcPort": 1234, + "params": "-ac_name=MESH -ac_supply=1000007" + }, + { + "name": "MNZ", + "rpcPort": 1234, + "params": "-ac_name=MNZ -ac_supply=257142858" + }, + { + "name": "AXO", + "rpcPort": 1234, + "params": "-ac_name=AXO -ac_supply=200000000" + }, + { + "name": "ETOMIC", + "rpcPort": 1234, + "params": "-ac_name=ETOMIC -ac_supply=100000000" + }, + { + "name": "BTCH", + "rpcPort": 1234, + "params": "-ac_name=BTCH -ac_supply=20998641" + }, + { + "name": "PIZZA", + "rpcPort": 1234, + "params": "-ac_name=PIZZA -ac_supply=100000000" + }, + { + "name": "BEER", + "rpcPort": 1234, + "params": "-ac_name=BEER -ac_supply=100000000" + }, + { + "name": "NINJA", + "rpcPort": 1234, + "params": "-ac_name=NINJA -ac_supply=100000000" + }, + { + "name": "OOT", + "rpcPort": 1234, + "params": "-ac_name=OOT -ac_supply=216000000" + }, + { + "name": "BNTN", + "rpcPort": 1234, + "params": "-ac_name=BNTN -ac_supply=500000000" + }, + { + "name": "CHAIN", + "rpcPort": 1234, + "params": "-ac_name=CHAIN -ac_supply=999999" + }, + { + "name": "PRLPAY", + "rpcPort": 1234, + "params": "-ac_name=PRLPAY -ac_supply=500000000" + }, + { + "name": "DSEC", + "rpcPort": 1234, + "params": "-ac_name=DSEC -ac_supply=7000000" + }, + { + "name": "GLXT", + "rpcPort": 1234, + "params": "-ac_name=GLXT -ac_supply=100000000" + }, + { + "name": "EQL", + "rpcPort": 1234, + "params": "-ac_name=EQL -ac_supply=500000000" + }, + { + "name": "ZILLA", + "rpcPort": 1234, + "params": "-ac_name=ZILLA -ac_supply=11000000" + } +] From fc6aca1ff9263ff31101930cf74b02ce24cfbed1 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Wed, 27 Jun 2018 21:23:09 +0700 Subject: [PATCH 0224/1123] Update ./assetchains to use assetchains.json --- src/assetchains | 65 +++++++++---------------------------------------- 1 file changed, 12 insertions(+), 53 deletions(-) diff --git a/src/assetchains b/src/assetchains index 6697c1735..175ebe576 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,60 +1,19 @@ #!/bin/bash +set -euo pipefail + source pubkey.txt -args=("$@") +assetchain_args=`jq -r '.[].params' assetchains.json` +overide_args=("$@") seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` komodo_binary='./komodod' delay=20 -function komodo_asset () -{ - if [ $[RANDOM % 10] == 1 ] - then - gen=" -gen" - else - gen="" - fi +while read args; do + gen="" + if [ $[RANDOM % 10] == 1 ]; then + gen=" -gen" + fi - if [ -n "$2" ] - then - supply=" -ac_supply=$2" - else - supply=" " - fi - - $komodo_binary -ac_name=$1 $gen $supply $args -pubkey=$pubkey -addnode=$seed_ip & - sleep $delay -} - -#set -x - -komodo_asset REVS 1300000 -komodo_asset SUPERNET 816061 -komodo_asset DEX 999999 -komodo_asset PANGEA 999999 -komodo_asset JUMBLR 999999 -komodo_asset BET 999999 -komodo_asset CRYPTO 999999 -komodo_asset HODL 9999999 -komodo_asset MSHARK 1400000 -komodo_asset BOTS 999999 -komodo_asset MGW 999999 -komodo_asset COQUI 72000000 -komodo_asset WLC 210000000 -komodo_asset KV 1000000 -komodo_asset CEAL 366666666 -komodo_asset MESH 1000007 -komodo_asset MNZ 257142858 -komodo_asset AXO 200000000 -komodo_asset ETOMIC 100000000 -komodo_asset BTCH 20998641 -komodo_asset PIZZA 100000000 -komodo_asset BEER 100000000 -komodo_asset NINJA 100000000 -komodo_asset OOT 216000000 -komodo_asset BNTN 500000000 -komodo_asset CHAIN 999999 -komodo_asset PRLPAY 500000000 -komodo_asset DSEC 7000000 -komodo_asset GLXT 100000000 -komodo_asset EQL 500000000 -komodo_asset ZILLA 11000000 + $komodo_binary $gen $args $overide_args -pubkey=$pubkey -addnode=$seed_ip & + sleep $delay +done <<< "$assetchain_args" From e4004af5784ae19fefa5bc0ddd2b832cd4825d83 Mon Sep 17 00:00:00 2001 From: SHossain Date: Wed, 27 Jun 2018 18:27:37 +0100 Subject: [PATCH 0225/1123] VRSC fix --- src/assetchains.old | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/assetchains.old b/src/assetchains.old index 228767f25..b8658ab24 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -36,6 +36,5 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & ./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & -~/veruscoin/src/komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & - +~/VerusCoin/src/komodod -pubkey=$pubkey -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_veruspos=50 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -addnode=185.25.48.236 -addnode=185.64.105.111 & From 9aa708afb8eb55fb4823db98bcb09530c8e3888c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jun 2018 06:53:12 -1100 Subject: [PATCH 0226/1123] Protect height 1 --- src/main.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 98fdf9452..c6272cc35 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4060,16 +4060,19 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if (pcheckpoint && nHeight > 1 && nHeight < pcheckpoint->nHeight ) - return state.DoS(1, error("%s: forked chain older than last checkpoint (height %d) vs %d", __func__, nHeight,pcheckpoint->nHeight)); - else if ( komodo_checkpoint(¬arized_height,nHeight,hash) < 0 ) + if ( pcheckpoint && nHeight > 1 ) { - CBlockIndex *heightblock = chainActive[nHeight]; - if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) + if (nHeight < pcheckpoint->nHeight ) + return state.DoS(1, error("%s: forked chain older than last checkpoint (height %d) vs %d", __func__, nHeight,pcheckpoint->nHeight)); + else if ( komodo_checkpoint(¬arized_height,nHeight,hash) < 0 ) { - //fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight); - return true; - } else return state.DoS(1, error("%s: forked chain %d older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height)); + CBlockIndex *heightblock = chainActive[nHeight]; + if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) + { + //fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight); + return true; + } else return state.DoS(1, error("%s: forked chain %d older than last notarized (height %d) vs %d", __func__,nHeight, notarized_height)); + } } } // Reject block.nVersion < 4 blocks From 2d28ad9c6f57360f0596b2b2ef2ef5994d0f6dfe Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jun 2018 07:08:30 -1100 Subject: [PATCH 0227/1123] Tweak height 1 fix --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c6272cc35..2d83ac89d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4060,11 +4060,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if ( pcheckpoint && nHeight > 1 ) + if ( nHeight > 1 ) { - if (nHeight < pcheckpoint->nHeight ) + if ( pcheckpoint != 0 && nHeight < pcheckpoint->nHeight ) return state.DoS(1, error("%s: forked chain older than last checkpoint (height %d) vs %d", __func__, nHeight,pcheckpoint->nHeight)); - else if ( komodo_checkpoint(¬arized_height,nHeight,hash) < 0 ) + if ( komodo_checkpoint(¬arized_height,nHeight,hash) < 0 ) { CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) From e7433b08e5dfec2592ef2c5207918179c596d2ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jun 2018 08:43:08 -1100 Subject: [PATCH 0228/1123] Reject height 1 reorganization --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2d83ac89d..c22b93fae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4060,7 +4060,9 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if ( nHeight > 1 ) + if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) + return(false) + if ( nHeight != 0 ) { if ( pcheckpoint != 0 && nHeight < pcheckpoint->nHeight ) return state.DoS(1, error("%s: forked chain older than last checkpoint (height %d) vs %d", __func__, nHeight,pcheckpoint->nHeight)); From 9710a28a54684545eb549f61688301caa4d0474a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jun 2018 08:59:05 -1100 Subject: [PATCH 0229/1123] Use entire magic in height 1 reward --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c22b93fae..c67974971 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1753,7 +1753,11 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) else { if ( nHeight == 1 ) - return(ASSETCHAINS_SUPPLY * COIN + (ASSETCHAINS_MAGIC & 0xffffff)); + { + if ( ASSETCHAINS_STAKED == 0 || strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) + return(ASSETCHAINS_SUPPLY * COIN + (ASSETCHAINS_MAGIC & 0xffffff)); + else return(ASSETCHAINS_SUPPLY * COIN + ASSETCHAINS_MAGIC); + } else if ( ASSETCHAINS_ENDSUBSIDY == 0 || nHeight < ASSETCHAINS_ENDSUBSIDY ) { if ( ASSETCHAINS_REWARD == 0 ) From 40d1de3231eaf5646f7551690624d89ee2d0c346 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 27 Jun 2018 09:18:59 -1100 Subject: [PATCH 0230/1123] Syntax --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c67974971..6ba31906a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4065,7 +4065,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) - return(false) + return(false); if ( nHeight != 0 ) { if ( pcheckpoint != 0 && nHeight < pcheckpoint->nHeight ) From 7efaea1895460371b6dc168447e907b7ef9cb1ff Mon Sep 17 00:00:00 2001 From: Scott Sadler Date: Wed, 27 Jun 2018 20:32:50 -0300 Subject: [PATCH 0231/1123] two fixes for eval.h, so it compiles on older gcc and prevent an overflow --- src/cc/eval.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/eval.h b/src/cc/eval.h index 4bcdd5617..0eef563a3 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -129,14 +129,16 @@ public: uint256 blockHash = uint256(); uint32_t height = 0; uint256 txHash = uint256(); - char symbol[64] = "\0"; + char symbol[64]; uint256 MoM = uint256(); uint16_t MoMDepth = 0; uint16_t ccId = 0; uint256 MoMoM = uint256(); uint32_t MoMoMDepth = 0; - NotarisationData(int IsBack=2) : IsBackNotarisation(IsBack) {} + NotarisationData(int IsBack=2) : IsBackNotarisation(IsBack) { + symbol[0] = '\0'; + } ADD_SERIALIZE_METHODS; @@ -171,7 +173,8 @@ public: template void SerSymbol(Stream& s, CSerActionUnserialize act) { - char *nullPos = (char*) memchr(&s[0], 0, s.size()); + size_t readlen = std::min(sizeof(symbol), s.size()); + char *nullPos = (char*) memchr(&s[0], 0, readlen); if (!nullPos) throw std::ios_base::failure("couldn't parse symbol"); s.read(symbol, nullPos-&s[0]+1); From b81701543b7f91c90c8b3c7388576602596d949c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 05:41:03 -1100 Subject: [PATCH 0232/1123] Increase size of KMD/BTCUSERPASS[] to avoid overflow --- src/komodo_globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 342d28fe8..947b84671 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -58,7 +58,7 @@ uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; -char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; +char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; uint64_t PENDING_KOMODO_TX; extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; From 4d0683677d8fadb23272101c69886529a7c192ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 21:37:47 -1100 Subject: [PATCH 0233/1123] fix staking destination, enable staking with genproclimit=0, enable cross chain notarization checks for notary nodes --- src/komodo.h | 10 +++++----- src/komodo_events.h | 6 +++--- src/komodo_globals.h | 2 +- src/komodo_utils.h | 10 ++++++++++ src/main.cpp | 4 ++-- src/miner.cpp | 36 ++++++++++++++---------------------- src/wallet/rpcwallet.cpp | 2 +- 7 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 690e91248..ae0898ed3 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -538,7 +538,7 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr return(-1); if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac ) { - if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 && NOTARY_PUBKEY33[0] != 0 ) + if ( i == 0 && j == 0 && memcmp(NOTARY_PUBKEY33,scriptbuf+1,33) == 0 && IS_KOMODO_NOTARY != 0 ) { printf("%s KOMODO_LASTMINED.%d -> %d\n",ASSETCHAINS_SYMBOL,KOMODO_LASTMINED,height); prevKOMODO_LASTMINED = KOMODO_LASTMINED; @@ -879,7 +879,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } notarized = 1; } - if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) + if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("(tx.%d: ",i); for (j=0; j= sizeof(uint32_t) && len <= sizeof(scriptbuf) ) @@ -916,7 +916,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) + if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf(") "); if ( 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("[%s] ht.%d txi.%d signedmask.%llx numvins.%d numvouts.%d notarized.%d special.%d isratification.%d\n",ASSETCHAINS_SYMBOL,height,i,(long long)signedmask,numvins,numvouts,notarized,specialtx,isratification); @@ -959,7 +959,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } } } - if ( NOTARY_PUBKEY33[0] != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) + if ( IS_KOMODO_NOTARY != 0 && ASSETCHAINS_SYMBOL[0] == 0 ) printf("%s ht.%d\n",ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL,height); if ( pindex->nHeight == hwmheight ) komodo_stateupdate(height,0,0,0,zero,0,0,0,0,height,(uint32_t)pindex->nTime,0,0,0,0,zero,0); diff --git a/src/komodo_events.h b/src/komodo_events.h index d3eab4902..d4ea17ce5 100644 --- a/src/komodo_events.h +++ b/src/komodo_events.h @@ -41,14 +41,14 @@ void komodo_eventadd_notarized(struct komodo_state *sp,char *symbol,int32_t heig { static uint32_t counter; int32_t verified=0; char *coin; struct komodo_event_notarized N; coin = (ASSETCHAINS_SYMBOL[0] == 0) ? (char *)"KMD" : ASSETCHAINS_SYMBOL; - if ( (ASSETCHAINS_SYMBOL[0] == 0 && height > 814000) && NOTARY_PUBKEY33[0] != 0 && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 ) + if ( IS_KOMODO_NOTARY != 0 && (verified= komodo_verifynotarization(symbol,dest,height,notarizedheight,notarized_hash,notarized_desttxid)) < 0 ) { - if ( ASSETCHAINS_SYMBOL[0] == 0 && height > 814000 && counter++ < 10 ) + if ( counter++ < 100 ) printf("[%s] error validating notarization ht.%d notarized_height.%d, if on a pruned %s node this can be ignored\n",ASSETCHAINS_SYMBOL,height,notarizedheight,dest); } else if ( strcmp(symbol,coin) == 0 ) { - if ( 0 && NOTARY_PUBKEY33[0] != 0 && verified != 0 ) + if ( 0 && IS_KOMODO_NOTARY != 0 && verified != 0 ) fprintf(stderr,"validated [%s] ht.%d notarized %d\n",coin,height,notarizedheight); memset(&N,0,sizeof(N)); N.blockhash = notarized_hash; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 342d28fe8..947b84671 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -58,7 +58,7 @@ uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; -char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; +char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; uint64_t PENDING_KOMODO_TX; extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 119c4d6f4..40dabd4e5 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1510,6 +1510,16 @@ void komodo_args(char *argv0) if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { USE_EXTERNAL_PUBKEY = 1; + if ( IS_KOMODO_NOTARY == 0 ) + { + for (i=0; inHeight,dstr(block.vtx[0].GetValueOut()),dstr(blockReward),dstr(sum)); } if (!control.Wait()) @@ -6110,7 +6110,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } pfrom->PushMessage("headers", vHeaders); } - /*else if ( NOTARY_PUBKEY33[0] != 0 ) + /*else if ( IS_KOMODO_NOTARY != 0 ) { static uint32_t counter; if ( counter++ < 3 ) diff --git a/src/miner.cpp b/src/miner.cpp index 6008fd5d9..257627b47 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -418,7 +418,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); - if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] != 0 ) + if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); @@ -475,14 +475,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); - if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || NOTARY_PUBKEY33[0] == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED == 0 || GetArg("-genproclimit", 0) > 0 ) { UpdateTime(pblock, Params().GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); } pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && My_notaryid >= 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) { uint32_t r; CMutableTransaction txNotary = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); @@ -875,7 +875,7 @@ void static BitcoinMiner() if ( i == 33 ) externalflag = 1; else externalflag = 0; - if ( NOTARY_PUBKEY33[0] != 0 ) + if ( IS_KOMODO_NOTARY != 0 ) { for (i=1; i<66; i++) if ( memcmp(pubkeys[i],pubkeys[0],33) == 0 ) @@ -909,7 +909,7 @@ void static BitcoinMiner() } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; } else Mining_start = 0; - if ( ASSETCHAINS_STAKED != 0 && NOTARY_PUBKEY33[0] == 0 ) + if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) { int32_t percPoS,z; /*if ( Mining_height <= 100 ) @@ -947,7 +947,7 @@ void static BitcoinMiner() // (x_1, x_2, ...) = A(I, V, n, k) LogPrint("pow", "Running Equihash solver \"%s\" with nNonce = %s\n",solver, pblock->nNonce.ToString()); arith_uint256 hashTarget; - if ( NOTARY_PUBKEY33[0] == 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) + if ( GetArg("-genproclimit", 0) > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; std::function)> validBlock = @@ -975,7 +975,7 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) return false; - if ( NOTARY_PUBKEY33[0] != 0 && B.nTime > GetAdjustedTime() ) + if ( B.nTime > GetAdjustedTime() ) { fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime-2 ) @@ -990,7 +990,7 @@ void static BitcoinMiner() } if ( ASSETCHAINS_STAKED == 0 ) { - if ( NOTARY_PUBKEY33[0] != 0 ) + if ( IS_KOMODO_NOTARY != 0 ) { int32_t r; if ( (r= ((Mining_height + NOTARY_PUBKEY33[16]) % 64) / 8) > 0 ) @@ -999,18 +999,12 @@ void static BitcoinMiner() } else { - if ( NOTARY_PUBKEY33[0] != 0 ) - { - while ( GetAdjustedTime() < B.nTime ) - sleep(1); - } - else - { - uint256 tmp = B.GetHash(); - int32_t z; for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); - fprintf(stderr," mined block!\n"); - } + while ( GetAdjustedTime() < B.nTime ) + sleep(1); + uint256 tmp = B.GetHash(); + int32_t z; for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); + fprintf(stderr," mined block!\n"); } CValidationState state; if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) @@ -1043,8 +1037,6 @@ void static BitcoinMiner() ehSolverRuns.increment(); throw boost::thread_interrupted(); } - //if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 ) - // sleep(1800); return true; }; std::function cancelled = [&m_cs, &cancelSolver](EhSolverCancelCheck pos) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bbbc9d897..255f74a19 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4652,7 +4652,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; txNew.vin[0].prevout.hash = revtxid; txNew.vin[0].prevout.n = *utxovoutp; - txNew.vout[0].scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + txNew.vout[0].scriptPubKey = best_scriptPubKey;// CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txNew.vout[0].nValue = *utxovaluep - txfee; txNew.nLockTime = earliest; CTransaction txNewConst(txNew); From 626179f166b8aa7789ac6fc98cadd69ec9e7ad3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 21:46:16 -1100 Subject: [PATCH 0234/1123] -ac_public -> disable z transactions if you want to prevent privacy --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 5 +++-- src/main.cpp | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 947b84671..cd476830f 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33]; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 40dabd4e5..181d07989 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1538,6 +1538,7 @@ void komodo_args(char *argv0) } } ASSETCHAINS_CC = GetArg("-ac_cc",0); + ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); @@ -1576,7 +1577,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 0; printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); } - if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 ) { fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); extraptr = extrabuf; @@ -1585,7 +1586,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffffff) << 40); + val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | (ASSETCHAINS_PUBLIC & 0xff); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); } addn = GetArg("-seednode",""); diff --git a/src/main.cpp b/src/main.cpp index 5659a3c6f..a7565e0ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1109,6 +1109,11 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio // Ensure that joinsplit values are well-formed BOOST_FOREACH(const JSDescription& joinsplit, tx.vjoinsplit) { + if ( ASSETCHAINS_PUBLIC != 0 ) + { + return state.DoS(100, error("CheckTransaction(): this is a public chain, no privacy allowed"), + REJECT_INVALID, "bad-txns-acprivacy-chain"); + } if (joinsplit.vpub_old < 0) { return state.DoS(100, error("CheckTransaction(): joinsplit.vpub_old negative"), REJECT_INVALID, "bad-txns-vpub_old-negative"); @@ -1737,6 +1742,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; +extern uint8_t ASSETCHAINS_PUBLIC; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { From 1bc74c28cf61d5eb3a3abd9dd5e0f6d7395f86e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 21:58:03 -1100 Subject: [PATCH 0235/1123] -donation option to donate 5% rewards to a pubkey --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 1 + src/wallet/wallet.cpp | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index cd476830f..b4f886e4b 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -47,7 +47,7 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; -std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY; +std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 181d07989..9a8c3c5e0 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1506,6 +1506,7 @@ void komodo_args(char *argv0) IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); + DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 550cba683..b0b5669ce 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -43,6 +43,7 @@ bool fPayAtLeastCustomFee = true; extern int32_t KOMODO_EXCHANGEWALLET; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; +extern std:string DONATION_PUBKEY; /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) @@ -2789,6 +2790,11 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt //fprintf(stderr,"KOMODO_EXCHANGEWALLET disable interest sum %.8f, interest2 %.8f\n",(double)interest/COIN,(double)interest2/COIN); //interest = 0; // interest2 also //} + if ( ASSETCHAINS_SYMBOL[0] == 0 && DONATION_PUBKEY.size() == 66 && interest2 > 5000 ) + { + txNew.vout.insert(txNew.vout.size(), newTxOut(interest2, CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG)); + interest2 = 0; + } CAmount nChange = (nValueIn - nValue + interest2); //fprintf(stderr,"wallet change %.8f (%.8f - %.8f) interest2 %.8f total %.8f\n",(double)nChange/COIN,(double)nValueIn/COIN,(double)nValue/COIN,(double)interest2/COIN,(double)nTotalValue/COIN); if (nSubtractFeeFromAmount == 0) From e0bc68e669693b8971dbe6ded4d008a61d0f6eac Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 22:06:12 -1100 Subject: [PATCH 0236/1123] Fix burn of 5000 sats from notary vin --- src/miner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 257627b47..4b7d09252 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -443,6 +443,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,chainparams.GetConsensus()); + if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) + txNew.vout[0].nValue += 5000; txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); txNew.nExpiryHeight = 0; // Add fees From 055ee43334352f0647371fd6b7cc3e75da1dc512 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 23:27:24 -1100 Subject: [PATCH 0237/1123] Syntax --- src/komodo_utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 9a8c3c5e0..a29245ac2 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1502,6 +1502,7 @@ char *argv0names[] = void komodo_args(char *argv0) { extern int64_t MAX_MONEY; + extern const char *Notaries_elected1[][2]; std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[256],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,baseid,len,n,extralen = 0; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); if ( (KOMODO_EXCHANGEWALLET= GetBoolArg("-exchange", false)) != 0 ) @@ -1513,7 +1514,7 @@ void komodo_args(char *argv0) USE_EXTERNAL_PUBKEY = 1; if ( IS_KOMODO_NOTARY == 0 ) { - for (i=0; i Date: Thu, 28 Jun 2018 23:28:23 -1100 Subject: [PATCH 0238/1123] syntax --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a29245ac2..c8c2e35b1 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1518,7 +1518,7 @@ void komodo_args(char *argv0) if ( strcmp(NOTARY_PUBKEY.c_str(),Notaries_elected1[i][1]) == 0 ) { IS_KOMODO_NOTARY = 1; - fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]) + fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); break; } } From a55973aeea4bb3b60d1aa9fbd26452646b128eed Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 23:31:32 -1100 Subject: [PATCH 0239/1123] :: --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b0b5669ce..ef7391912 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -43,7 +43,7 @@ bool fPayAtLeastCustomFee = true; extern int32_t KOMODO_EXCHANGEWALLET; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; -extern std:string DONATION_PUBKEY; +extern std::string DONATION_PUBKEY; /** * Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) From 76471d5658903fb6d376a04d3e19c2cf30727ad4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 23:32:14 -1100 Subject: [PATCH 0240/1123] CTxOut --- src/wallet/wallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ef7391912..00ae77e0f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2792,6 +2792,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt //} if ( ASSETCHAINS_SYMBOL[0] == 0 && DONATION_PUBKEY.size() == 66 && interest2 > 5000 ) { + CTxOut newTxOut; txNew.vout.insert(txNew.vout.size(), newTxOut(interest2, CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG)); interest2 = 0; } From 85df50842b0ead86730176773492baec74ed2853 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 23:33:52 -1100 Subject: [PATCH 0241/1123] syntax --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 00ae77e0f..0d1c442e0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2792,8 +2792,8 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt //} if ( ASSETCHAINS_SYMBOL[0] == 0 && DONATION_PUBKEY.size() == 66 && interest2 > 5000 ) { - CTxOut newTxOut; - txNew.vout.insert(txNew.vout.size(), newTxOut(interest2, CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG)); + CTxOut newTxOut(interest2, CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG); + txNew.vout.insert(txNew.vout.size(),newTxOut) ; interest2 = 0; } CAmount nChange = (nValueIn - nValue + interest2); From 817ad14d08f8dc6f75e7d39b55f7956ca2eefdc0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 23:39:32 -1100 Subject: [PATCH 0242/1123] Fix --- src/wallet/wallet.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 0d1c442e0..68224c1a8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2792,8 +2792,11 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt //} if ( ASSETCHAINS_SYMBOL[0] == 0 && DONATION_PUBKEY.size() == 66 && interest2 > 5000 ) { - CTxOut newTxOut(interest2, CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG); - txNew.vout.insert(txNew.vout.size(),newTxOut) ; + CScript scriptDonation = CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG; + CTxOut newTxOut(interest2,scriptDonation); + nDonationPosRet = txNew.vout.size() - 1; // dont change first or last + vector::iterator position = txNew.vout.begin()+nChangePosRet; + txNew.vout.insert(position, newTxOut); interest2 = 0; } CAmount nChange = (nValueIn - nValue + interest2); From 719aa8b19e97291d6bc30bc0996eff792b221155 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 28 Jun 2018 23:42:32 -1100 Subject: [PATCH 0243/1123] Test --- src/wallet/wallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 68224c1a8..10bf93598 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2794,8 +2794,8 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt { CScript scriptDonation = CScript() << ParseHex(DONATION_PUBKEY) << OP_CHECKSIG; CTxOut newTxOut(interest2,scriptDonation); - nDonationPosRet = txNew.vout.size() - 1; // dont change first or last - vector::iterator position = txNew.vout.begin()+nChangePosRet; + int32_t nDonationPosRet = txNew.vout.size() - 1; // dont change first or last + vector::iterator position = txNew.vout.begin()+nDonationPosRet; txNew.vout.insert(position, newTxOut); interest2 = 0; } From ec9c462f1cf2da22b58701cb4bbaa649e8769b3c Mon Sep 17 00:00:00 2001 From: siulynot Date: Fri, 29 Jun 2018 11:06:14 -0400 Subject: [PATCH 0244/1123] GLXT supply change --- src/assetchains | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains b/src/assetchains index 4029dc039..661dd710a 100755 --- a/src/assetchains +++ b/src/assetchains @@ -66,7 +66,7 @@ komodo_asset BNTN 500000000 komodo_asset CHAIN 999999 komodo_asset PRLPAY 500000000 komodo_asset DSEC 7000000 -komodo_asset GLXT 100000000 +komodo_asset GLXT 10000000000 komodo_asset EQL 500000000 komodo_asset ZILLA 11000000 komodo_asset RFOX 1000000000 100000000 From 94f9918f9d085bfdabbcdf1ce60af1115894d096 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 01:18:10 -1100 Subject: [PATCH 0245/1123] Default genproclimit to 0 --- src/init.cpp | 6 +++--- src/rpcmining.cpp | 4 ++-- src/wallet/asyncrpcoperation_mergetoaddress.cpp | 4 ++-- src/wallet/asyncrpcoperation_sendmany.cpp | 4 ++-- src/wallet/asyncrpcoperation_shieldcoinbase.cpp | 4 ++-- src/zcbenchmarks.cpp | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 52c919421..1b8018b56 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -499,7 +499,7 @@ std::string HelpMessage(HelpMessageMode mode) #ifdef ENABLE_MINING strUsage += HelpMessageGroup(_("Mining options:")); strUsage += HelpMessageOpt("-gen", strprintf(_("Generate coins (default: %u)"), 0)); - strUsage += HelpMessageOpt("-genproclimit=", strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 1)); + strUsage += HelpMessageOpt("-genproclimit=", strprintf(_("Set the number of threads for coin generation if enabled (-1 = all cores, default: %d)"), 0)); strUsage += HelpMessageOpt("-equihashsolver=", _("Specify the Equihash solver to be used if enabled (default: \"default\")")); strUsage += HelpMessageOpt("-mineraddress=", _("Send mined coins to a specific single address")); strUsage += HelpMessageOpt("-minetolocalwallet", strprintf( @@ -1766,9 +1766,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // Generate coins in the background #ifdef ENABLE_WALLET if (pwalletMain || !GetArg("-mineraddress", "").empty()) - GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0)); #else - GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 0)); #endif #endif diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 7f66f23f6..afe4e5a33 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -319,8 +319,8 @@ UniValue setgenerate(const UniValue& params, bool fHelp) if (params.size() > 1) { nGenProcLimit = params[1].get_int(); - if (nGenProcLimit == 0) - fGenerate = false; + //if (nGenProcLimit == 0) + // fGenerate = false; } mapArgs["-gen"] = (fGenerate ? "1" : "0"); diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index a85f3315c..fa41c87d4 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -152,9 +152,9 @@ void AsyncRPCOperation_mergetoaddress::main() #ifdef ENABLE_MINING #ifdef ENABLE_WALLET - GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0)); #else - GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen", false), GetArg("-genproclimit", 0)); #endif #endif diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 6f33b514e..3652f7d0d 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -158,9 +158,9 @@ void AsyncRPCOperation_sendmany::main() { #ifdef ENABLE_MINING #ifdef ENABLE_WALLET - GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 0)); #else - GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 0)); #endif #endif diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index 1bc82fdbe..f48cf8dcd 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -137,9 +137,9 @@ void AsyncRPCOperation_shieldcoinbase::main() { #ifdef ENABLE_MINING #ifdef ENABLE_WALLET - GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen",false), pwalletMain, GetArg("-genproclimit", 0)); #else - GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen",false), GetArg("-genproclimit", 0)); #endif #endif diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp index 2c7e99a67..b3fbddf88 100644 --- a/src/zcbenchmarks.cpp +++ b/src/zcbenchmarks.cpp @@ -61,7 +61,7 @@ void post_wallet_load(){ #ifdef ENABLE_MINING // Generate coins in the background if (pwalletMain || !GetArg("-mineraddress", "").empty()) - GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); + GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 0)); #endif } From 3a446d9f249c706a0cad398b4d69a8955deaa6bb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 01:26:23 -1100 Subject: [PATCH 0246/1123] +print --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 4b7d09252..5903dd825 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1187,7 +1187,9 @@ void static BitcoinMiner() delete minerThreads; minerThreads = NULL; } - + fprintf(stderr,"nThreads.%d fGenerate.%d\n",(int32_t)nThreads,fGenerate); + if ( nThreads == 0 ) + nThreads = 1; if (nThreads == 0 || !fGenerate) return; From 8daf7cafe6b495752d24e7540da7ef6d16c6b0f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 01:33:40 -1100 Subject: [PATCH 0247/1123] 100 easy PoW blocks for staked=100 --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0e8d8ddfd..ca02f2a00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1165,7 +1165,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; - if ( height <= 10 ) + if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); sum = arith_uint256(0); ave = sum; From db178ad2baa5d1dacafe28d5461f1db42907e0e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 01:43:36 -1100 Subject: [PATCH 0248/1123] -print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ca02f2a00..4ff810723 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1136,12 +1136,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - for (i=31; i>=24; i--) + /*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); + 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; } } From 4f02fc40094f8f894072f6379ca279d3b95be569 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 02:52:29 -1100 Subject: [PATCH 0249/1123] Getbalance64 --- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + src/wallet/rpcwallet.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index bc1ba5b37..1cfab13d0 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -383,6 +383,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "getaccount", &getaccount, true }, { "wallet", "getaddressesbyaccount", &getaddressesbyaccount, true }, { "wallet", "getbalance", &getbalance, false }, + { "wallet", "getbalance64", &getbalance64, false }, { "wallet", "getnewaddress", &getnewaddress, true }, { "wallet", "getrawchangeaddress", &getrawchangeaddress, true }, { "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false }, diff --git a/src/rpcserver.h b/src/rpcserver.h index 40cb96288..e6edc3949 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -220,6 +220,7 @@ extern UniValue verifymessage(const UniValue& params, bool fHelp); extern UniValue getreceivedbyaddress(const UniValue& params, bool fHelp); extern UniValue getreceivedbyaccount(const UniValue& params, bool fHelp); extern UniValue getbalance(const UniValue& params, bool fHelp); +extern UniValue getbalance64(const UniValue& params, bool fHelp); extern UniValue getunconfirmedbalance(const UniValue& params, bool fHelp); extern UniValue movecmd(const UniValue& params, bool fHelp); extern UniValue sendfrom(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 255f74a19..a25b5f4bb 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4673,3 +4673,48 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } else fprintf(stderr,"no earliest utxo for staking\n"); return(siglen); } + +UniValue getbalance64(const UniValue& params, bool fHelp) +{ + set setAddress; vector vecOutputs; + UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); + const CKeyStore& keystore = *pwalletMain; + CAmount nValues[64],nValues2[64],nValue,total,total2; int32_t i,segid; + assert(pwalletMain != NULL); + if (fHelp || params.size() > 0) + throw runtime_error("getbalance64\n"); + total = total2 = 0; + memset(nValues,0,sizeof(nValues)); + memset(nValues2,0,sizeof(nValues2)); + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + BOOST_FOREACH(const COutput& out, vecOutputs) + { + nValue = out.tx->vout[out.i].nValue; + if ( setAddress.size() ) + { + CTxDestination address; + if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + continue; + if (!setAddress.count(address)) + continue; + segid = komodo_segid((char *)CBitcoinAddress(address).ToString().c_str()); + if ( out.nDepth < 100 ) + nValues2[segid] += nValue, total2 += nValue; + else nValues[segid] += nValue, total += nValue; + } + } + ret.push_back(Pair("staking",(double)total/COIN)); + ret.push_back(Pair("immature",(double)total2/COIN)); + for (i=0; i<64; i++) + { + UniValue item(UniValue::VOBJ); + item.push_back(double)nValues[i] / COIN); + a.push_back(item); + item.push_back(double)nValues2[i] / COIN); + b.push_back(item); + } + ret.push_back(Pair("staking", a)); + ret.push_back(Pair("immature", b)); + return ret; +} From 890e708b8749dec60df38a7050f0cfbfbfb18040 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 03:10:41 -1100 Subject: [PATCH 0250/1123] Test --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a25b5f4bb..a16fc77e4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -44,6 +44,7 @@ using namespace libzcash; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); +uint32_t komodo_segid32(char *coinaddr); int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; @@ -4709,9 +4710,9 @@ UniValue getbalance64(const UniValue& params, bool fHelp) for (i=0; i<64; i++) { UniValue item(UniValue::VOBJ); - item.push_back(double)nValues[i] / COIN); + item.push_back((double)nValues[i] / COIN); a.push_back(item); - item.push_back(double)nValues2[i] / COIN); + item.push_back((double)nValues2[i] / COIN); b.push_back(item); } ret.push_back(Pair("staking", a)); From ca76a7dfcd7ed4a145e9f7129986e05ad4378ba5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 03:13:18 -1100 Subject: [PATCH 0251/1123] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a16fc77e4..deb49e94a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4699,7 +4699,7 @@ UniValue getbalance64(const UniValue& params, bool fHelp) continue; if (!setAddress.count(address)) continue; - segid = komodo_segid((char *)CBitcoinAddress(address).ToString().c_str()); + segid = (komodo_segid32((char *)CBitcoinAddress(address).ToString().c_str()) & 0x3f); if ( out.nDepth < 100 ) nValues2[segid] += nValue, total2 += nValue; else nValues[segid] += nValue, total += nValue; @@ -4710,9 +4710,9 @@ UniValue getbalance64(const UniValue& params, bool fHelp) for (i=0; i<64; i++) { UniValue item(UniValue::VOBJ); - item.push_back((double)nValues[i] / COIN); + item.push_back((uint64_t)nValues[i]); a.push_back(item); - item.push_back((double)nValues2[i] / COIN); + item.push_back((uint64_t)nValues2[i]); b.push_back(item); } ret.push_back(Pair("staking", a)); From 5e0b330de9dd0de4be072e0520481b3f831ec9e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 03:19:39 -1100 Subject: [PATCH 0252/1123] Test --- src/wallet/rpcwallet.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index deb49e94a..7c76eb691 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt UniValue getbalance64(const UniValue& params, bool fHelp) { set setAddress; vector vecOutputs; - UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); + UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR),b(UniValue::VARR); CTxDestination address; const CKeyStore& keystore = *pwalletMain; CAmount nValues[64],nValues2[64],nValue,total,total2; int32_t i,segid; assert(pwalletMain != NULL); @@ -4692,30 +4692,23 @@ UniValue getbalance64(const UniValue& params, bool fHelp) BOOST_FOREACH(const COutput& out, vecOutputs) { nValue = out.tx->vout[out.i].nValue; - if ( setAddress.size() ) + if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) ) { - CTxDestination address; - if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) - continue; - if (!setAddress.count(address)) - continue; segid = (komodo_segid32((char *)CBitcoinAddress(address).ToString().c_str()) & 0x3f); if ( out.nDepth < 100 ) nValues2[segid] += nValue, total2 += nValue; else nValues[segid] += nValue, total += nValue; - } + fprintf(stderr,"%s %.8f depth.%d segid.%d\n",(char *)CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,(int32_t)out.nDepth,segid); + } else fprintf(stderr,"no destination\n"); } - ret.push_back(Pair("staking",(double)total/COIN)); + ret.push_back(Pair("mature",(double)total/COIN)); ret.push_back(Pair("immature",(double)total2/COIN)); for (i=0; i<64; i++) { - UniValue item(UniValue::VOBJ); - item.push_back((uint64_t)nValues[i]); - a.push_back(item); - item.push_back((uint64_t)nValues2[i]); - b.push_back(item); + a.push_back((uint64_t)nValues[i]); + b.push_back((uint64_t)nValues2[i]); } ret.push_back(Pair("staking", a)); - ret.push_back(Pair("immature", b)); + ret.push_back(Pair("notstaking", b)); return ret; } From d979952f3a0a73c706d7453d8cdce6017f809a5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 03:25:42 -1100 Subject: [PATCH 0253/1123] -print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7c76eb691..22fe7fba1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4698,7 +4698,7 @@ UniValue getbalance64(const UniValue& params, bool fHelp) if ( out.nDepth < 100 ) nValues2[segid] += nValue, total2 += nValue; else nValues[segid] += nValue, total += nValue; - fprintf(stderr,"%s %.8f depth.%d segid.%d\n",(char *)CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,(int32_t)out.nDepth,segid); + //fprintf(stderr,"%s %.8f depth.%d segid.%d\n",(char *)CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,(int32_t)out.nDepth,segid); } else fprintf(stderr,"no destination\n"); } ret.push_back(Pair("mature",(double)total/COIN)); From 2732d384f4b64a414da008aede956c506c8009d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 03:37:42 -1100 Subject: [PATCH 0254/1123] Stub getnewaddress64 --- src/rpcserver.cpp | 1 + src/rpcserver.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index 1cfab13d0..ed5110114 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -385,6 +385,7 @@ static const CRPCCommand vRPCCommands[] = { "wallet", "getbalance", &getbalance, false }, { "wallet", "getbalance64", &getbalance64, false }, { "wallet", "getnewaddress", &getnewaddress, true }, +// { "wallet", "getnewaddress64", &getnewaddress64, true }, { "wallet", "getrawchangeaddress", &getrawchangeaddress, true }, { "wallet", "getreceivedbyaccount", &getreceivedbyaccount, false }, { "wallet", "getreceivedbyaddress", &getreceivedbyaddress, false }, diff --git a/src/rpcserver.h b/src/rpcserver.h index e6edc3949..5bb949299 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -209,6 +209,7 @@ extern UniValue estimatefee(const UniValue& params, bool fHelp); extern UniValue estimatepriority(const UniValue& params, bool fHelp); extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp +//extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp extern UniValue getaccountaddress(const UniValue& params, bool fHelp); extern UniValue getrawchangeaddress(const UniValue& params, bool fHelp); extern UniValue setaccount(const UniValue& params, bool fHelp); From f2c1ac067116dfe6b16413e50a7d72a9afb10117 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 30 Jun 2018 03:40:02 -1100 Subject: [PATCH 0255/1123] -print --- src/komodo_bitcoind.h | 13 ++++++++----- src/miner.cpp | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4ff810723..5cd88d7de 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1181,22 +1181,25 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he hashval = UintToArith256(pindex->GetBlockHash()); if ( hashval <= bnTarget ) // PoW is never as easy as PoS/16, some PoS will be counted as PoW { - fprintf(stderr,"1"); + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"1"); sum += hashval; n++; } else { percPoS++; - fprintf(stderr,"0"); + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"0"); } - if ( (i % 10) == 9 ) + if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } } if ( n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; - fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( n > 0 ) @@ -1208,7 +1211,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); - if ( 1 ) + if ( ASSETCHAINS_STAKED < 100 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&ave)[i]); diff --git a/src/miner.cpp b/src/miner.cpp index 5903dd825..5ed1c5af7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -920,9 +920,12 @@ void static BitcoinMiner() continue; }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED); + if ( ASSETCHAINS_STAKED < 100 ) + { + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); + fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED); + } } while (true) { From 8bcd895c73f7ed6af73916fd6c582f543ffc24be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 1 Jul 2018 23:10:13 -1100 Subject: [PATCH 0256/1123] GLXT change --- src/assetchains.old | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/assetchains.old b/src/assetchains.old index b8658ab24..dd5c5d813 100755 --- a/src/assetchains.old +++ b/src/assetchains.old @@ -32,7 +32,7 @@ echo $pubkey ./komodod -pubkey=$pubkey -ac_name=CHAIN -ac_supply=999999 -addnode=78.47.146.222 & ./komodod -pubkey=$pubkey -ac_name=PRLPAY -ac_supply=500000000 -addnode=13.250.226.125 & ./komodod -pubkey=$pubkey -ac_name=DSEC -ac_supply=7000000 -addnode=185.148.147.30 & -./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=100000000 -addnode=13.230.224.15 & +./komodod -pubkey=$pubkey -ac_name=GLXT -ac_supply=10000000000 -addnode=13.230.224.15 & ./komodod -pubkey=$pubkey -ac_name=EQL -ac_supply=500000000 -addnode=46.101.124.153 & ./komodod -pubkey=$pubkey -ac_name=ZILLA -ac_supply=11000000 -addnode=54.39.23.248 & ./komodod -pubkey=$pubkey -ac_name=RFOX -ac_supply=1000000000 -ac_reward=100000000 -addnode=78.47.196.146 & From 36f9e6d6d581addb1bb29754b61287929673832f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Jul 2018 07:09:29 -1100 Subject: [PATCH 0257/1123] -ac_private --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 1 + src/main.cpp | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index b4f886e4b..c46486430 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -48,7 +48,7 @@ int COINBASE_MATURITY = _COINBASE_MATURITY;//100; int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAINS_SEED,KOMODO_ON_DEMAND,KOMODO_EXTERNAL_NOTARIES,KOMODO_PASSPORT_INITDONE,KOMODO_PAX,KOMODO_EXCHANGEWALLET,KOMODO_REWIND; int32_t KOMODO_LASTMINED,prevKOMODO_LASTMINED,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c8c2e35b1..c6ffe4cdd 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1541,6 +1541,7 @@ void komodo_args(char *argv0) } ASSETCHAINS_CC = GetArg("-ac_cc",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); + ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 ) { printf("KOMODO_REWIND %d\n",KOMODO_REWIND); diff --git a/src/main.cpp b/src/main.cpp index a7565e0ab..13a3121c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1090,6 +1090,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio // Check for negative or overflow output values CAmount nValueOut = 0; + int32_t iscoinbase = tx.IsCoinBase(); BOOST_FOREACH(const CTxOut& txout, tx.vout) { if (txout.nValue < 0) @@ -1100,6 +1101,10 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio fprintf(stderr,"%.8f > max %.8f\n",(double)txout.nValue/COIN,(double)MAX_MONEY/COIN); return state.DoS(100, error("CheckTransaction(): txout.nValue too high"),REJECT_INVALID, "bad-txns-vout-toolarge"); } + if ( txout.nValue > 0 && ASSETCHAINS_PRIVATE != 0 && iscoinbase == 0 ) + { + return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + } nValueOut += txout.nValue; if (!MoneyRange(nValueOut)) return state.DoS(100, error("CheckTransaction(): txout total out of range"), @@ -1742,7 +1747,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint32_t ASSETCHAINS_MAGIC; extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; -extern uint8_t ASSETCHAINS_PUBLIC; +extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { From 0a37f2072d7c3d28ca83f268670d4225ea706128 Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 2 Jul 2018 23:36:33 +0200 Subject: [PATCH 0258/1123] add travis CI --- .travis.yml | 82 ----------------------------------------------------- 1 file changed, 82 deletions(-) diff --git a/.travis.yml b/.travis.yml index ac331dcf9..250756396 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -<<<<<<< HEAD language: cpp compiler: @@ -22,84 +21,3 @@ notifications: - "Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build Time: %{duration}" - "Change view : %{compare_url}" - "Build details : %{build_url}" -======= -# errata: -# - A travis bug causes caches to trample eachother when using the same -# compiler key (which we don't use anyway). This is worked around for now by -# replacing the "compilers" with a build name prefixed by the no-op ":" -# command. See: https://github.com/travis-ci/travis-ci/issues/4393 -# - sudo/dist/group are set so as to get Blue Box VMs, necessary for [loopback] -# IPv6 support - -sudo: required -dist: precise -group: legacy - -os: linux -language: cpp -compiler: gcc -env: - global: - - MAKEJOBS=-j3 - - RUN_TESTS=false - - BOOST_TEST_RANDOM=1$TRAVIS_BUILD_ID - - CCACHE_SIZE=100M - - CCACHE_TEMPDIR=/tmp/.ccache-temp - - CCACHE_COMPRESS=1 - - BASE_OUTDIR=$TRAVIS_BUILD_DIR/out - - SDK_URL=https://bitcoincore.org/depends-sources/sdks - - PYTHON_DEBUG=1 - - WINEDEBUG=fixme-all -cache: - apt: true - directories: - - depends/built - - depends/sdk-sources - - $HOME/.ccache -matrix: - fast_finish: true - include: - - compiler: ": ARM" - env: HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" DEP_OPTS="" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Win32" - env: HOST=i686-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-i686 g++-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": 32-bit + dash" - env: HOST=i686-pc-linux-gnu PACKAGES="g++-multilib bc python-zmq" PPA="ppa:chris-lea/zeromq" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash" - - compiler: ": Win64" - env: HOST=x86_64-w64-mingw32 PACKAGES="nsis gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-dev wine bc" RUN_TESTS=true GOAL="deploy" BITCOIN_CONFIG="--enable-reduce-exports" MAKEJOBS="-j2" - - compiler: ": bitcoind" - env: HOST=x86_64-unknown-linux-gnu PACKAGES="bc python-zmq" PPA="ppa:chris-lea/zeromq" DEP_OPTS="DEBUG=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER" - - compiler: ": No wallet" - env: HOST=x86_64-unknown-linux-gnu DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports" - - compiler: ": Cross-Mac" - env: HOST=x86_64-apple-darwin11 PACKAGES="cmake libcap-dev libz-dev libbz2-dev" BITCOIN_CONFIG="--enable-reduce-exports" OSX_SDK=10.9 GOAL="deploy" - exclude: - - compiler: gcc -install: - - if [ -n "$PACKAGES" ]; then sudo rm -f /etc/apt/sources.list.d/travis_ci_zeromq3-source.list; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi - - if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi -before_script: - - unset CC; unset CXX - - mkdir -p depends/SDKs depends/sdk-sources - - if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - if [ -n "$OSX_SDK" -a -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then tar -C depends/SDKs -xf depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi - - make $MAKEJOBS -C depends HOST=$HOST $DEP_OPTS -script: - - if [ -n "$USE_SHELL" ]; then export CONFIG_SHELL="$USE_SHELL"; fi - - OUTDIR=$BASE_OUTDIR/$TRAVIS_PULL_REQUEST/$TRAVIS_JOB_NUMBER-$HOST - - BITCOIN_CONFIG_ALL="--disable-dependency-tracking --prefix=$TRAVIS_BUILD_DIR/depends/$HOST --bindir=$OUTDIR/bin --libdir=$OUTDIR/lib" - - depends/$HOST/native/bin/ccache --max-size=$CCACHE_SIZE - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then export CCACHE_READONLY=1; fi - - test -n "$USE_SHELL" && eval '"$USE_SHELL" -c "./autogen.sh"' || ./autogen.sh - - ./configure --cache-file=config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make distdir PACKAGE=bitcoin VERSION=$HOST - - cd bitcoin-$HOST - - ./configure --cache-file=../config.cache $BITCOIN_CONFIG_ALL $BITCOIN_CONFIG || ( cat config.log && false) - - make $MAKEJOBS $GOAL || ( echo "Build failure. Verbose build follows." && make $GOAL V=1 ; false ) - - export LD_LIBRARY_PATH=$TRAVIS_BUILD_DIR/depends/$HOST/lib - - if [ "$RUN_TESTS" = "true" ]; then make check; fi - - if [ "$RUN_TESTS" = "true" ]; then qa/pull-tester/rpc-tests.sh; fi -after_script: - - if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then (echo "Upload goes here. Something like: scp -r $BASE_OUTDIR server" || echo "upload failed"); fi ->>>>>>> zcash/master From 2f151c301925c9959d62d52a82d6ddcbe7971f00 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 3 Jul 2018 01:34:08 -1100 Subject: [PATCH 0259/1123] Prevent taddr outputs in most places for -ac_private --- src/komodo_utils.h | 5 +++++ src/wallet/rpcwallet.cpp | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index c6ffe4cdd..0c1ea8f18 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1558,6 +1558,11 @@ void komodo_args(char *argv0) ASSETCHAINS_OVERRIDE_PUBKEY = GetArg("-ac_pubkey",""); if ( (ASSETCHAINS_STAKED= GetArg("-ac_staked",0)) > 100 ) ASSETCHAINS_STAKED = 100; + if ( ASSETCHAINS_STAKED != 0 && ASSETCHAINS_PRIVATE != 0 ) + { + printf("-ac_private chains cant have any PoS\n"); + exit(0); + } if ( ASSETCHAINS_HALVING != 0 && ASSETCHAINS_HALVING < 1440 ) { ASSETCHAINS_HALVING = 1440; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 22fe7fba1..a1773f43b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -44,6 +44,7 @@ using namespace libzcash; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); +extern uint8_t ASSETCHAINS_PRIVATE; uint32_t komodo_segid32(char *coinaddr); int64_t nWalletUnlockTime; @@ -453,6 +454,9 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"") ); + if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid " + strprintf("%s",komodo_chainname()) + " address"); + LOCK2(cs_main, pwalletMain->cs_wallet); CBitcoinAddress address(params[0].get_str()); @@ -1071,6 +1075,8 @@ UniValue getunconfirmedbalance(const UniValue ¶ms, bool fHelp) UniValue movecmd(const UniValue& params, bool fHelp) { + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1144,6 +1150,8 @@ UniValue movecmd(const UniValue& params, bool fHelp) UniValue sendfrom(const UniValue& params, bool fHelp) { + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1209,6 +1217,8 @@ UniValue sendfrom(const UniValue& params, bool fHelp) UniValue sendmany(const UniValue& params, bool fHelp) { + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -3762,7 +3772,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) string address = find_value(o, "address").get_str(); bool isZaddr = false; CBitcoinAddress taddr(address); - if (!taddr.IsValid()) { + if (!taddr.IsValid()) + { try { CZCPaymentAddress zaddr(address); zaddr.Get(); @@ -3771,6 +3782,8 @@ UniValue z_sendmany(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ")+address ); } } + else if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (setAddress.count(address)) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, duplicated address: ")+address); @@ -4229,6 +4242,8 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) throw JSONRPCError(RPC_INVALID_PARAMETER, string("Invalid parameter, unknown address format: ") + destaddress ); } } + else if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); // Convert fee from currency format to zatoshis CAmount nFee = SHIELD_COINBASE_DEFAULT_MINERS_FEE; From 4addff14a06e97baa64b592f7558751bf9b8aac7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 3 Jul 2018 05:09:43 -1100 Subject: [PATCH 0260/1123] Make ac_private change magic --- src/komodo_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0c1ea8f18..f61fd05ea 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1585,7 +1585,7 @@ void komodo_args(char *argv0) ASSETCHAINS_COMMISSION = 0; printf("ASSETCHAINS_COMMISSION needs an ASETCHAINS_OVERRIDE_PUBKEY and cant be more than 100000000 (100%%)\n"); } - if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY != 0 || ASSETCHAINS_REWARD != 0 || ASSETCHAINS_HALVING != 0 || ASSETCHAINS_DECAY != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"end.%llu blocks, reward %.8f halving.%llu blocks, decay.%llu perc %.4f%% ac_pub=[%02x...]\n",(long long)ASSETCHAINS_ENDSUBSIDY,dstr(ASSETCHAINS_REWARD),(long long)ASSETCHAINS_HALVING,(long long)ASSETCHAINS_DECAY,dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0]); extraptr = extrabuf; @@ -1594,7 +1594,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY); - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | (ASSETCHAINS_PUBLIC & 0xff); + val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6); extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); } addn = GetArg("-seednode",""); From afaeb54b98ef5ae509751168a5528ba8dca59570 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 3 Jul 2018 05:16:45 -1100 Subject: [PATCH 0261/1123] -print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 5ed1c5af7..421e9bab3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1190,7 +1190,7 @@ void static BitcoinMiner() delete minerThreads; minerThreads = NULL; } - fprintf(stderr,"nThreads.%d fGenerate.%d\n",(int32_t)nThreads,fGenerate); + //fprintf(stderr,"nThreads.%d fGenerate.%d\n",(int32_t)nThreads,fGenerate); if ( nThreads == 0 ) nThreads = 1; if (nThreads == 0 || !fGenerate) From 361e75f6f97579e009bd8dc91bf4f04d2fd033a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 3 Jul 2018 05:22:51 -1100 Subject: [PATCH 0262/1123] +print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 421e9bab3..755b7439e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1009,7 +1009,7 @@ void static BitcoinMiner() uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); - fprintf(stderr," mined block!\n"); + fprintf(stderr," mined block %d!\n",Mining_height); } CValidationState state; if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) From 471f1b83888a52164e17737b21c3114fba6edc31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 3 Jul 2018 06:12:21 -1100 Subject: [PATCH 0263/1123] +print --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 13a3121c6..8d1649d3b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1101,9 +1101,11 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio fprintf(stderr,"%.8f > max %.8f\n",(double)txout.nValue/COIN,(double)MAX_MONEY/COIN); return state.DoS(100, error("CheckTransaction(): txout.nValue too high"),REJECT_INVALID, "bad-txns-vout-toolarge"); } - if ( txout.nValue > 0 && ASSETCHAINS_PRIVATE != 0 && iscoinbase == 0 ) + if ( ASSETCHAINS_PRIVATE != 0 ) { - return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); + fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); + if ( txout.nValue > 0 && iscoinbase == 0 ) + return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } nValueOut += txout.nValue; if (!MoneyRange(nValueOut)) From dfec6b538670091bec1d6fd2523a8624988a8c16 Mon Sep 17 00:00:00 2001 From: ca333 Date: Tue, 3 Jul 2018 19:27:05 +0200 Subject: [PATCH 0264/1123] update travisCI deployment --- .travis.yml | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 250756396..81c2092aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,33 @@ +dist: xenial language: cpp - compiler: - - gcc - +- gcc before_install: - - sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa - - sudo apt-get update -qq - - sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate -#install: - -script: - - ./zcutil/build.sh -j 5 - +- sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa +- sudo apt-get update -qq +- sudo apt-get install libgnutls28-dev +- sudo apt-get install build-essential pkg-config libcurl3-gnutls-dev libc6-dev libevent-dev + m4 g++-multilib autoconf libtool ncurses-dev unzip git python zlib1g-dev wget bsdmainutils + automake libssl-dev libprotobuf-dev protobuf-compiler libdb++-dev ntp ntpdate +script: +- "./zcutil/build.sh -j 5" notifications: irc: channels: - - "chat.freenode.net#komodoplatform" + - chat.freenode.net#komodoplatform template: - - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" - - "Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build Time: %{duration}" - - "Change view : %{compare_url}" - - "Build details : %{build_url}" + - "%{repository}/%{branch} (%{commit} - %{author}): %{message}" + - 'Alt Message : %{repository_slug} - (%{commit} - %{author}): %{message}, Build + Time: %{duration}' + - 'Change view : %{compare_url}' + - 'Build details : %{build_url}' +before_deploy: + - git tag "$(date +'%Y%m%d%H%M%S')-$(git log --format=%h -1)" +deploy: + provider: releases + api_key: + secure: oyMB9JDSoL/val/d80Em3sd3mSJY+PPkiclUb3ktizNz7DgYZbBiStUOZIJo95GUYADEvm9RVrP0JmBiDuqneEjfFRzME9/MnpY/LmRCiYGgprMDR80ZqbLgOzSKpE10RE2XM3vZkZeXT/JcGGayUm0faElep2qx62S4ozsAxSvFJ5l/PG+wEltrlnp1z8uYdXV3PBChbjzXJ0BdMVxMrrU39kwzqwu2Ge9PnNjVv0AVxn/oZpf+bzYa7vkSuGTRe2Jcs8U9AABYnZ22wu+tdlD76pdOJzGEwR70e8CjUJmdSn+M+wwAPPHStPW/JHFwSaWsKZtUyB5EWQW2kqq6P+M1Fe7yo6srznsaAcZRWeCrbUO/k44bEfnj7HMGmxfjDJOwbxVEoHg7im+l3HLUiG8rcw5dM/TAnrmgjH/OEj/EM1lbwV2C+PdDGOjdguljEhjBABGRbRABMZjwW8w+uBFVlKlcn7y+zJbMB3mGd+FNGo/OgAcsFzRcpaN8SrC/kzUF2SeEwJjTKvAqRgA66yl7CzDPBtUv2NtoPUz/8YO9rsdGElcWfmDIVacuIEjo1CizlbDzeS7zPiFPW5MRCGryLFLt0WjA/s8lkLO+DbGYXPa4rG6+7ZNUDLfziM+lFqZH8b382/bhv+a6ctpWjaazjiW6yWemsuN8QhByuGw= + file: src/komodod + skip_cleanup: true + on: + repo: KomodoPlatform/komodo From b310ffff5bfa1a0e84184e43f0a3cba33a48ec52 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 4 Jul 2018 09:50:49 -1100 Subject: [PATCH 0265/1123] Fix ac_private help --- src/wallet/rpcwallet.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a1773f43b..53086291a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1075,8 +1075,6 @@ UniValue getunconfirmedbalance(const UniValue ¶ms, bool fHelp) UniValue movecmd(const UniValue& params, bool fHelp) { - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1100,6 +1098,8 @@ UniValue movecmd(const UniValue& params, bool fHelp) "\nAs a json rpc call\n" + HelpExampleRpc("move", "\"timotei\", \"akiko\", 0.01, 6, \"happy birthday!\"") ); + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1150,8 +1150,6 @@ UniValue movecmd(const UniValue& params, bool fHelp) UniValue sendfrom(const UniValue& params, bool fHelp) { - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1181,6 +1179,8 @@ UniValue sendfrom(const UniValue& params, bool fHelp) "\nAs a json rpc call\n" + HelpExampleRpc("sendfrom", "\"tabby\", \"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.01, 6, \"donation\", \"seans outpost\"") ); + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1217,8 +1217,6 @@ UniValue sendfrom(const UniValue& params, bool fHelp) UniValue sendmany(const UniValue& params, bool fHelp) { - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; @@ -1257,6 +1255,8 @@ UniValue sendmany(const UniValue& params, bool fHelp) "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"\", \"{\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.01,\\\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\\\":0.02}\", 6, \"testing\"") ); + if ( ASSETCHAINS_PRIVATE != 0 ) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); From 69cf3284baf7ba86db45abccc6d2097b7eb8b1c6 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 5 Jul 2018 16:24:41 +0700 Subject: [PATCH 0266/1123] Update assetchains.json to array of param objects --- src/assetchains.json | 160 ++++++++++++++++++------------------------- 1 file changed, 67 insertions(+), 93 deletions(-) diff --git a/src/assetchains.json b/src/assetchains.json index 7837b95af..3b7bfb61e 100644 --- a/src/assetchains.json +++ b/src/assetchains.json @@ -1,157 +1,131 @@ [ { - "name": "REVS", - "rpcPort": 1234, - "params": "-ac_name=REVS -ac_supply=1300000" + "ac_name": "REVS", + "ac_supply": "1300000" }, { - "name": "SUPERNET", - "rpcPort": 1234, - "params": "-ac_name=SUPERNET -ac_supply=816061" + "ac_name": "SUPERNET", + "ac_supply": "816061" }, { - "name": "DEX", - "rpcPort": 1234, - "params": "-ac_name=DEX -ac_supply=999999" + "ac_name": "DEX", + "ac_supply": "999999" }, { - "name": "PANGEA", - "rpcPort": 1234, - "params": "-ac_name=PANGEA -ac_supply=999999" + "ac_name": "PANGEA", + "ac_supply": "999999" }, { - "name": "JUMBLR", - "rpcPort": 1234, - "params": "-ac_name=JUMBLR -ac_supply=999999" + "ac_name": "JUMBLR", + "ac_supply": "999999" }, { - "name": "BET", - "rpcPort": 1234, - "params": "-ac_name=BET -ac_supply=999999" + "ac_name": "BET", + "ac_supply": "999999" }, { - "name": "CRYPTO", - "rpcPort": 1234, - "params": "-ac_name=CRYPTO -ac_supply=999999" + "ac_name": "CRYPTO", + "ac_supply": "999999" }, { - "name": "HODL", - "rpcPort": 1234, - "params": "-ac_name=HODL -ac_supply=9999999" + "ac_name": "HODL", + "ac_supply": "9999999" }, { - "name": "MSHARK", - "rpcPort": 1234, - "params": "-ac_name=MSHARK -ac_supply=1400000" + "ac_name": "MSHARK", + "ac_supply": "1400000" }, { - "name": "BOTS", - "rpcPort": 1234, - "params": "-ac_name=BOTS -ac_supply=999999" + "ac_name": "BOTS", + "ac_supply": "999999" }, { - "name": "MGW", - "rpcPort": 1234, - "params": "-ac_name=MGW -ac_supply=999999" + "ac_name": "MGW", + "ac_supply": "999999" }, { - "name": "COQUI", - "rpcPort": 1234, - "params": "-ac_name=COQUI -ac_supply=72000000" + "ac_name": "COQUI", + "ac_supply": "72000000" }, { - "name": "WLC", - "rpcPort": 1234, - "params": "-ac_name=WLC -ac_supply=210000000" + "ac_name": "WLC", + "ac_supply": "210000000" }, { - "name": "KV", - "rpcPort": 1234, - "params": "-ac_name=KV -ac_supply=1000000" + "ac_name": "KV", + "ac_supply": "1000000" }, { - "name": "CEAL", - "rpcPort": 1234, - "params": "-ac_name=CEAL -ac_supply=366666666" + "ac_name": "CEAL", + "ac_supply": "366666666" }, { - "name": "MESH", - "rpcPort": 1234, - "params": "-ac_name=MESH -ac_supply=1000007" + "ac_name": "MESH", + "ac_supply": "1000007" }, { - "name": "MNZ", - "rpcPort": 1234, - "params": "-ac_name=MNZ -ac_supply=257142858" + "ac_name": "MNZ", + "ac_supply": "257142858" }, { - "name": "AXO", - "rpcPort": 1234, - "params": "-ac_name=AXO -ac_supply=200000000" + "ac_name": "AXO", + "ac_supply": "200000000" }, { - "name": "ETOMIC", - "rpcPort": 1234, - "params": "-ac_name=ETOMIC -ac_supply=100000000" + "ac_name": "ETOMIC", + "ac_supply": "100000000" }, { - "name": "BTCH", - "rpcPort": 1234, - "params": "-ac_name=BTCH -ac_supply=20998641" + "ac_name": "BTCH", + "ac_supply": "20998641" }, { - "name": "PIZZA", - "rpcPort": 1234, - "params": "-ac_name=PIZZA -ac_supply=100000000" + "ac_name": "PIZZA", + "ac_supply": "100000000" }, { - "name": "BEER", - "rpcPort": 1234, - "params": "-ac_name=BEER -ac_supply=100000000" + "ac_name": "BEER", + "ac_supply": "100000000" }, { - "name": "NINJA", - "rpcPort": 1234, - "params": "-ac_name=NINJA -ac_supply=100000000" + "ac_name": "NINJA", + "ac_supply": "100000000" }, { - "name": "OOT", - "rpcPort": 1234, - "params": "-ac_name=OOT -ac_supply=216000000" + "ac_name": "OOT", + "ac_supply": "216000000" }, { - "name": "BNTN", - "rpcPort": 1234, - "params": "-ac_name=BNTN -ac_supply=500000000" + "ac_name": "BNTN", + "ac_supply": "500000000" }, { - "name": "CHAIN", - "rpcPort": 1234, - "params": "-ac_name=CHAIN -ac_supply=999999" + "ac_name": "CHAIN", + "ac_supply": "999999" }, { - "name": "PRLPAY", - "rpcPort": 1234, - "params": "-ac_name=PRLPAY -ac_supply=500000000" + "ac_name": "PRLPAY", + "ac_supply": "500000000" }, { - "name": "DSEC", - "rpcPort": 1234, - "params": "-ac_name=DSEC -ac_supply=7000000" + "ac_name": "DSEC", + "ac_supply": "7000000" }, { - "name": "GLXT", - "rpcPort": 1234, - "params": "-ac_name=GLXT -ac_supply=100000000" + "ac_name": "GLXT", + "ac_supply": "10000000000" }, { - "name": "EQL", - "rpcPort": 1234, - "params": "-ac_name=EQL -ac_supply=500000000" + "ac_name": "EQL", + "ac_supply": "500000000" }, { - "name": "ZILLA", - "rpcPort": 1234, - "params": "-ac_name=ZILLA -ac_supply=11000000" + "ac_name": "ZILLA", + "ac_supply": "11000000" + }, + { + "ac_name": "RFOX", + "ac_supply": "1000000000", + "ac_reward": "100000000" } ] From 2e986a8a90d4572d4d62a97c85605156f23b439a Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 5 Jul 2018 16:42:10 +0700 Subject: [PATCH 0267/1123] Add assetchainparams script --- src/assetchainparams | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 src/assetchainparams diff --git a/src/assetchainparams b/src/assetchainparams new file mode 100755 index 000000000..fa83437e8 --- /dev/null +++ b/src/assetchainparams @@ -0,0 +1,17 @@ +#!/usr/bin/env python2 +import os +import json + +script_dir = os.path.dirname(__file__) +with open(script_dir + '/assetchains.json') as file: + assetchains = json.load(file) + +for chain in assetchains: + params = [] + for param, value in chain.items(): + if isinstance(value, list): + for dupe_value in value: + params.append('-' + param + '=' + dupe_value) + else: + params.append('-' + param + '=' + value) + print(' '.join(params)) From 8c263066db03cbf8363e9f92426e7f5c6937e1bc Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 5 Jul 2018 18:16:18 +0700 Subject: [PATCH 0268/1123] Update assetchains file to use assetchainparams script --- src/assetchains | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/assetchains b/src/assetchains index 175ebe576..959622970 100755 --- a/src/assetchains +++ b/src/assetchains @@ -1,12 +1,14 @@ #!/bin/bash -set -euo pipefail +set -eo pipefail +# You can now add delay line to pubkey.txt file source pubkey.txt -assetchain_args=`jq -r '.[].params' assetchains.json` -overide_args=("$@") +assetchain_args=`./assetchainparams` +overide_args="$@" seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` komodo_binary='./komodod' -delay=20 + +if [ -z "$delay" ]; then delay=20; fi while read args; do gen="" From 848bfdbdc485f17209e920279a8f47a9825f71dd Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 5 Jul 2018 18:37:49 +0700 Subject: [PATCH 0269/1123] Refactor param formatting out into function --- src/assetchainparams | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/assetchainparams b/src/assetchainparams index fa83437e8..5e6b71eb4 100755 --- a/src/assetchainparams +++ b/src/assetchainparams @@ -2,6 +2,9 @@ import os import json +def format_param(param, value): + return '-' + param + '=' + value + script_dir = os.path.dirname(__file__) with open(script_dir + '/assetchains.json') as file: assetchains = json.load(file) @@ -11,7 +14,7 @@ for chain in assetchains: for param, value in chain.items(): if isinstance(value, list): for dupe_value in value: - params.append('-' + param + '=' + dupe_value) + params.append(format_param(param, dupe_value)) else: - params.append('-' + param + '=' + value) + params.append(format_param(param, value)) print(' '.join(params)) From ac09a89f9764fb1ffc8bca5d87d2c7d153a3fdd1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 03:54:47 -1100 Subject: [PATCH 0270/1123] Test --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8d1649d3b..f533b7761 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,9 +6826,11 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) + { // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { + if ((nSyncStarted == 0 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + { state.fSyncStarted = true; nSyncStarted++; CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; From 20a1f68495067de1150a6d315c2351239c3857d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:01:37 -1100 Subject: [PATCH 0271/1123] +print --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index f533b7761..93bcb0421 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,8 +6826,10 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. + fprintf(stderr,"see if can request\n"); if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { + fprintf(stderr,"check for asking initial headers: nSyncStarted.%d fFetch.%d\n",(int32_t)nSyncStarted,(int32_t)fFetch); // Only actively request headers from a single peer, unless we're close to today. if ((nSyncStarted == 0 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { From 3a796a89aa1f0f0e13daa584d9137395eee11e4f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:07:53 -1100 Subject: [PATCH 0272/1123] Prints --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 93bcb0421..c4cbcc751 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,16 +6826,16 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - fprintf(stderr,"see if can request\n"); + //fprintf(stderr,"see if can request\n"); if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { - fprintf(stderr,"check for asking initial headers: nSyncStarted.%d fFetch.%d\n",(int32_t)nSyncStarted,(int32_t)fFetch); // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted == 0 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ((nSyncStarted < 3 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pto->nStartingHeight,pindexStart->nHeight); LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } From 3df89af7feddbe125b7095aa69df42bb2c82c05d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:16:09 -1100 Subject: [PATCH 0273/1123] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c4cbcc751..e517d8a6e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6830,7 +6830,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted < 3 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ((nSyncStarted < 30 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; From 18c515eb032f5e1bfbc5405e6bf76699e8375a47 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:20:21 -1100 Subject: [PATCH 0274/1123] Test --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e517d8a6e..2b820f1b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6827,15 +6827,15 @@ bool SendMessages(CNode* pto, bool fSendTrickle) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. //fprintf(stderr,"see if can request\n"); - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) { // Only actively request headers from a single peer, unless we're close to today. - if ((nSyncStarted < 30 && fFetch) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ( (nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; - fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pto->nStartingHeight,pindexStart->nHeight); + fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pindexStart->nHeight,pto->nStartingHeight); LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } From 8d124e7f5059d8e362892bba322996e040e5151a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:24:47 -1100 Subject: [PATCH 0275/1123] syntax --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2b820f1b2..80d9e533f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6830,7 +6830,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) { // Only actively request headers from a single peer, unless we're close to today. - if ( (nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ( nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; From 7aa8bcb497e7acb230c7537574fd0b03fabd19e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:28:34 -1100 Subject: [PATCH 0276/1123] Syntax --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 80d9e533f..a083f65e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6829,12 +6829,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle) //fprintf(stderr,"see if can request\n"); if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) { + CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; // Only actively request headers from a single peer, unless we're close to today. if ( nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pindexStart->nHeight,pto->nStartingHeight); LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); From 2a46683da275aa0cae25b366655fe9dc9a30903b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 04:32:12 -1100 Subject: [PATCH 0277/1123] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a083f65e3..89a0551dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6831,7 +6831,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) { CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; // Only actively request headers from a single peer, unless we're close to today. - if ( nSyncStarted < 30 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) + if ( nSyncStarted < 3 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; From e9b849601d3967fa11eedfa3ea882e40f3c905f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:27:09 -1100 Subject: [PATCH 0278/1123] Revert init headers tweaks --- src/main.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 89a0551dd..8d1649d3b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6826,16 +6826,12 @@ bool SendMessages(CNode* pto, bool fSendTrickle) if (pindexBestHeader == NULL) pindexBestHeader = chainActive.Tip(); bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->fOneShot); // Download if this is a nice peer, or we have no nice peers and this one might do. - //fprintf(stderr,"see if can request\n"); - if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex && pto->nStartingHeight != 0 ) - { - CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; + if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) { // Only actively request headers from a single peer, unless we're close to today. - if ( nSyncStarted < 3 && (fFetch || pindexStart->nHeight == 0) )//|| pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) - { + if ((nSyncStarted == 0 && fFetch) || pindexBestHeader->GetBlockTime() > GetAdjustedTime() - 24 * 60 * 60) { state.fSyncStarted = true; nSyncStarted++; - fprintf(stderr,"ask initial headers: nSyncStarted.%d fFetch.%d peer.%d [%d to %d]\n",(int32_t)nSyncStarted,(int32_t)fFetch,pto->id, pindexStart->nHeight,pto->nStartingHeight); + CBlockIndex *pindexStart = pindexBestHeader->pprev ? pindexBestHeader->pprev : pindexBestHeader; LogPrint("net", "initial getheaders (%d) to peer=%d (startheight:%d)\n", pindexStart->nHeight, pto->id, pto->nStartingHeight); pto->PushMessage("getheaders", chainActive.GetLocator(pindexStart), uint256()); } From 9c2f6f11bb3c45991e1b4a294aa0130b17404d76 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:44:54 -1100 Subject: [PATCH 0279/1123] Work around inadvertent CPU mining --- src/komodo_bitcoind.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5cd88d7de..0f49c3758 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1248,13 +1248,16 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { 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 ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + return(1); + if ( txn_count > 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { if ( prevtime == 0 ) { if ( (previndex= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } + // add strict check for 100% of vin -> vout txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) @@ -1265,7 +1268,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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 + 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) ) From c6d2cccf9231989c5cd4b1fdbe08a98f6a282785 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:49:19 -1100 Subject: [PATCH 0280/1123] -print --- src/komodo_bitcoind.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0f49c3758..cfa4c7c33 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,7 +1257,6 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( (previndex= mapBlockIndex[pblock->hashPrevBlock]) != 0 ) prevtime = (uint32_t)previndex->nTime; } - // add strict check for 100% of vin -> vout txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) From feefa2d3201c11adb6957bb8bf7b2508ae0d3a07 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:52:44 -1100 Subject: [PATCH 0281/1123] Vins == 1 check for staking utxo --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cfa4c7c33..6aadde9b8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1250,7 +1250,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ txn_count = pblock->vtx.size(); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) return(1); - if ( txn_count > 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) + if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { if ( prevtime == 0 ) { From 6420c2d1c0ac052d40416ee8f73cf12e05785525 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 05:56:50 -1100 Subject: [PATCH 0282/1123] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6aadde9b8..0ca0bd123 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1248,8 +1248,6 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { 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 ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - return(1); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { if ( prevtime == 0 ) @@ -1277,8 +1275,10 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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); + } //else return(-1); } + if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + return(1); return(isPoS); } From d4acce54ac3df12a22c21e6f5229f0b9a7b99d6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:03:22 -1100 Subject: [PATCH 0283/1123] Test --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0ca0bd123..2374c3262 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1277,6 +1277,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); } //else return(-1); } + fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) return(1); return(isPoS); From 5c6adb31e91cac5f12be0b5beecc86d73ef136b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:06:07 -1100 Subject: [PATCH 0284/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2374c3262..df0cc6baa 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1275,7 +1275,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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); + } else return(-1); } fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) From 764576d5e2ffeb4a84d9416606745475da35f483 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:11:06 -1100 Subject: [PATCH 0285/1123] Prepare for new isPoS --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index df0cc6baa..2374c3262 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1275,7 +1275,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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); + } //else return(-1); } fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) From ffd6dd51965634aa9a02e74a79b87106a8737105 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:19:48 -1100 Subject: [PATCH 0286/1123] Fix isPoS detection --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2374c3262..d459678f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1247,6 +1247,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; + if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + return(1); txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { @@ -1277,9 +1279,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); } //else return(-1); } - fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); - if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - return(1); + //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); return(isPoS); } From 800b9aa7779cfd4a380f72026e723f63bd70979e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 06:32:30 -1100 Subject: [PATCH 0287/1123] No exemption for isPoS --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d459678f9..88fea5e2b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1247,8 +1247,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; - if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - return(1); + //if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) + // return(1); txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { From a3d08df0fc90383a350e83efacf5c3a9a862ce17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 07:03:25 -1100 Subject: [PATCH 0288/1123] Prevent PoW in 100% PoS --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 88fea5e2b..acba52c7c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1352,7 +1352,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } } - else if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW + if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { From 640b264174a72ad13e2139d073bb36fd4c2036f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 07:17:15 -1100 Subject: [PATCH 0289/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index acba52c7c..66076ac96 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1356,7 +1356,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { - if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! + if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! return(-1); else { From 6ac497242db9b056b3c18ac321dd4414224f1f12 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 07:45:13 -1100 Subject: [PATCH 0290/1123] Ht.200 exemption --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 66076ac96..fa2bb3ba2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1247,8 +1247,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; - //if ( ASSETCHAINS_STAKED == 100 && height < 1000 ) - // return(1); + if ( ASSETCHAINS_STAKED == 100 && height < 200 ) + return(1); txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) { From d719807f84203ad580387fb00757b2b6798b99af Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 6 Jul 2018 07:08:33 +0700 Subject: [PATCH 0291/1123] assetchainparams => listassetchainparams --- src/assetchains | 2 +- src/{assetchainparams => listassetchainparams} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/{assetchainparams => listassetchainparams} (100%) diff --git a/src/assetchains b/src/assetchains index 959622970..e33970177 100755 --- a/src/assetchains +++ b/src/assetchains @@ -3,7 +3,7 @@ set -eo pipefail # You can now add delay line to pubkey.txt file source pubkey.txt -assetchain_args=`./assetchainparams` +assetchain_args=`./listassetchainparams` overide_args="$@" seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` komodo_binary='./komodod' diff --git a/src/assetchainparams b/src/listassetchainparams similarity index 100% rename from src/assetchainparams rename to src/listassetchainparams From f192db220f71fa2405fd28f0c85fda4474374925 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 6 Jul 2018 07:10:16 +0700 Subject: [PATCH 0292/1123] Created listassetchains --- src/listassetchains | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 src/listassetchains diff --git a/src/listassetchains b/src/listassetchains new file mode 100755 index 000000000..768381070 --- /dev/null +++ b/src/listassetchains @@ -0,0 +1,10 @@ +#!/usr/bin/env python2 +import os +import json + +script_dir = os.path.dirname(__file__) +with open(script_dir + '/assetchains.json') as file: + assetchains = json.load(file) + +for chain in assetchains: + print(chain['ac_name']) From cd7fd0552e6de335130a422890856ac12ef228a2 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 6 Jul 2018 07:13:56 +0700 Subject: [PATCH 0293/1123] Update assetchains_stop to use src/listassetchains and fix lots of bugs --- src/assetchains_stop | 43 ++++++------------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/src/assetchains_stop b/src/assetchains_stop index e55231b1a..f2cd234ef 100755 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -1,40 +1,9 @@ #!/bin/bash -args=("$@") +set -eo pipefail + +assetchains=`./listassetchains` komodo_cli='./komodo-cli' -delay=20 -function komodo_stop () -{ - $komodo_cli --ac_name=$1 stop -} - -#set -x - -komodo_stop REVS -komodo_stop SUPERNET -komodo_stop DEX -komodo_stop PANGEA -komodo_stop JUMBLR -komodo_stop BET -komodo_stop CRYPTO -komodo_stop HODL -komodo_stop MSHARK -komodo_stop BOTS -komodo_stop MGW -komodo_stop COQUI -komodo_stop WLC -komodo_stop KV -komodo_stop CEAL -komodo_stop MESH -komodo_stop MNZ -komodo_stop AXO -komodo_stop ETOMIC -komodo_stop BTCH -komodo_stop PIZZA -komodo_stop BEER -komodo_stop NINJA -komodo_stop OOT -komodo_stop BNTN -komodo_stop CHAIN -komodo_stop PRLPAY -komodo_stop DSEC +while read chain; do + $komodo_cli --ac_name=$chain stop +done <<< "$assetchains" From 0467e742e3c0d98e6e78f22abfcfe883223f0256 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 6 Jul 2018 07:15:59 +0700 Subject: [PATCH 0294/1123] Pipe into while loops --- src/assetchains | 5 ++--- src/assetchains_stop | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/assetchains b/src/assetchains index e33970177..299028e90 100755 --- a/src/assetchains +++ b/src/assetchains @@ -3,14 +3,13 @@ set -eo pipefail # You can now add delay line to pubkey.txt file source pubkey.txt -assetchain_args=`./listassetchainparams` overide_args="$@" seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` komodo_binary='./komodod' if [ -z "$delay" ]; then delay=20; fi -while read args; do +./listassetchainparams | while read args; do gen="" if [ $[RANDOM % 10] == 1 ]; then gen=" -gen" @@ -18,4 +17,4 @@ while read args; do $komodo_binary $gen $args $overide_args -pubkey=$pubkey -addnode=$seed_ip & sleep $delay -done <<< "$assetchain_args" +done diff --git a/src/assetchains_stop b/src/assetchains_stop index f2cd234ef..26940e141 100755 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -1,9 +1,8 @@ #!/bin/bash set -eo pipefail -assetchains=`./listassetchains` komodo_cli='./komodo-cli' -while read chain; do +./listassetchains | while read chain; do $komodo_cli --ac_name=$chain stop -done <<< "$assetchains" +done From b48bf090bc78d57eaf5068bada419befab87a6b3 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 6 Jul 2018 07:18:28 +0700 Subject: [PATCH 0295/1123] Update fiat-cli to use src/listassetchains and fix lots of bugs --- src/fiat-cli | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/src/fiat-cli b/src/fiat-cli index 2838575f9..6c7a8d732 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -1,35 +1,10 @@ #!/bin/bash -#set -x -echo revs; fiat/revs $1 $2 $3 $4 -echo supernet; fiat/supernet $1 $2 $3 $4 -echo dex; fiat/dex $1 $2 $3 $4 -echo pangea; fiat/pangea $1 $2 $3 $4 -echo jumblr; fiat/jumblr $1 $2 $3 $4 -echo bet; fiat/bet $1 $2 $3 $4 -echo crypto; fiat/crypto $1 $2 $3 $4 -echo hodl; fiat/hodl $1 $2 $3 $4 -echo mshark; fiat/mshark $1 $2 $3 $4 -echo bots; fiat/bots $1 $2 $3 $4 -echo mgw; fiat/mgw $1 $2 $3 $4 -echo coqui; fiat/coqui $1 $2 $3 $4 -echo wlc; fiat/wlc $1 $2 $3 $4 -echo kv; fiat/kv $1 $2 $3 $4 -echo ceal; fiat/ceal $1 $2 $3 $4 -echo mesh; fiat/mesh $1 $2 $3 $4 -echo mnz; fiat/mnz $1 $2 $3 $4 -echo axo; fiat/axo $1 $2 $3 $4 -echo etomic; fiat/etomic $1 $2 $3 $4 -echo btch; fiat/btch $1 $2 $3 $4 -echo pizza; fiat/pizza $1 $2 $3 $4 -echo beer; fiat/beer $1 $2 $3 $4 -echo ninja; fiat/ninja $1 $2 $3 $4 -echo oot; fiat/oot $1 $2 $3 $4 -echo bntn; fiat/bntn $1 $2 $3 $4 -echo chain; fiat/chain $1 $2 $3 $4 -echo prlpay; fiat/prlpay $1 $2 $3 $4 -echo dsec; fiat/dsec $1 $2 $3 $4 -echo glxt; fiat/glxt $1 $2 $3 $4 -echo eql; fiat/eql $1 $2 $3 $4 -echo zilla; fiat/zilla $1 $2 $3 $4 -echo vrsc; fiat/vrsc $1 $2 $3 $4 -echo rfox; fiat/rfox $1 $2 $3 $4 +set -eo pipefail + +args="$@" +komodo_cli='./komodo-cli' + +./listassetchains | while read chain; do + echo $chain + $komodo_cli --ac_name=$chain $args +done From 8543360b20508ed1412d8c614e4ce4f3d87d8c35 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Fri, 6 Jul 2018 07:20:31 +0700 Subject: [PATCH 0296/1123] Remove pointless komodo_cli variable --- src/assetchains | 3 +-- src/assetchains_stop | 4 +--- src/fiat-cli | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/assetchains b/src/assetchains index 299028e90..57e705d5c 100755 --- a/src/assetchains +++ b/src/assetchains @@ -5,7 +5,6 @@ set -eo pipefail source pubkey.txt overide_args="$@" seed_ip=`getent hosts zero.kolo.supernet.org | awk '{ print $1 }'` -komodo_binary='./komodod' if [ -z "$delay" ]; then delay=20; fi @@ -15,6 +14,6 @@ if [ -z "$delay" ]; then delay=20; fi gen=" -gen" fi - $komodo_binary $gen $args $overide_args -pubkey=$pubkey -addnode=$seed_ip & + ./komodod $gen $args $overide_args -pubkey=$pubkey -addnode=$seed_ip & sleep $delay done diff --git a/src/assetchains_stop b/src/assetchains_stop index 26940e141..60549dc20 100755 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -1,8 +1,6 @@ #!/bin/bash set -eo pipefail -komodo_cli='./komodo-cli' - ./listassetchains | while read chain; do - $komodo_cli --ac_name=$chain stop + ./komodo-cli --ac_name=$chain stop done diff --git a/src/fiat-cli b/src/fiat-cli index 6c7a8d732..719141d07 100755 --- a/src/fiat-cli +++ b/src/fiat-cli @@ -2,9 +2,8 @@ set -eo pipefail args="$@" -komodo_cli='./komodo-cli' ./listassetchains | while read chain; do echo $chain - $komodo_cli --ac_name=$chain $args + ./komodo-cli --ac_name=$chain $args done From d6f8eeb965d75f13c771349632c2ed5084ed6bb9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 21:48:08 -1100 Subject: [PATCH 0297/1123] Remove mindiff cap for 100% PoS --- src/coins.cpp | 2 +- src/komodo_bitcoind.h | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index b2d838506..38b105e9d 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -466,7 +466,7 @@ bool CCoinsViewCache::HaveInputs(const CTransaction& tx) const const COutPoint &prevout = tx.vin[i].prevout; const CCoins* coins = AccessCoins(prevout.hash); if (!coins || !coins->IsAvailable(prevout.n)) { - fprintf(stderr,"HaveInputs missing input %s/v%d\n",prevout.hash.ToString().c_str(),prevout.n); + //fprintf(stderr,"HaveInputs missing input %s/v%d\n",prevout.hash.ToString().c_str(),prevout.n); return false; } } diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fa2bb3ba2..113a470c2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1094,13 +1094,16 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh blocktime = prevtime+57; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; + if ( ASSETCHAINS_STAKED != 100 || nHeight < 2000 ) + { + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; + } if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; From 99fb7ab30a79c9a65abc69e4bf9dc79c3dc28291 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 21:49:51 -1100 Subject: [PATCH 0298/1123] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8d1649d3b..d4dfae7ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1311,7 +1311,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa uint256 hash = tx.GetHash(); if (pool.exists(hash)) { - fprintf(stderr,"already in mempool\n"); + //fprintf(stderr,"already in mempool\n"); return state.Invalid(false, REJECT_DUPLICATE, "already in mempool"); } From 99fbc8f0c0667c92a90e8fa41928efe7ac9b5404 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 22:01:16 -1100 Subject: [PATCH 0299/1123] -print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 53086291a..67bafd32b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4605,7 +4605,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) { - fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); + //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } if ( setAddress.size() ) From 1da1d6616340bc1722271b3a8ba770a81c2380de Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 22:01:46 -1100 Subject: [PATCH 0300/1123] -print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 755b7439e..667e1a3c4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -432,7 +432,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); + //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } From 01e50e731f64dc48cf7c8aa5862aa8b9babb8f26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 5 Jul 2018 22:02:31 -1100 Subject: [PATCH 0301/1123] +symbol --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 667e1a3c4..dcf22b1bd 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1009,7 +1009,7 @@ void static BitcoinMiner() uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); - fprintf(stderr," mined block %d!\n",Mining_height); + fprintf(stderr," mined %s block %d!\n",ASSETCHAINS_SYMBOL,Mining_height); } CValidationState state; if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) From d184dbb444a93b791f1323563b36708c521ab81b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 6 Jul 2018 04:07:07 -1100 Subject: [PATCH 0302/1123] Hash in utxo for PoS --- src/komodo_bitcoind.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 113a470c2..4f6b6e2fc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1114,7 +1114,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh 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); + if ( nHeight >= 2000 ) + { + memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)],&txid,sizeof(txid)); + memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*3 + sizeof(vout)); + } else 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++) { From 049e24ce9e7e0528d1bbcf754bd5ecd71ce6ce86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 01:48:52 -1100 Subject: [PATCH 0303/1123] Test newstake --- src/komodo_bitcoind.h | 131 ++++++++++++++++++++++++++++++++++++++++-- src/miner.cpp | 2 + 2 files changed, 129 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4f6b6e2fc..6f3af9d27 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1086,9 +1086,131 @@ uint32_t komodo_segid32(char *coinaddr) return(addrhash.uints[0]); } +int8_t komodo_segid(int32_t height) +{ + CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; bits256 txid; int8_t segid = -1; + if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) + { + if ( komodo_blockload(block,pindex) == 0 ) + { + txn_count = pblock->vtx.size(); + if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) + { + txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; + vout = pblock->vtx[txn_count-1].vin[0].prevout.n; + 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 ) + { + segid = komodo_segid32(voutaddr) & 0x3f; + } + } else fprintf(stderr,"komodo_segid ht.%d couldnt extract voutaddress\n",height); + } + } + } + return(segid); +} + +int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) +{ + static uint8_t prevhashbuf[100]; static int32_t prevheight; + int32_t i; + if ( height == prevheight && n == 100 ) + memcpy(hashbuf,prevhashbuf,100); + else + { + memset(hashbuf,0xff,n); + for (i=0; i 6000 ) // about 100 blocks + minage = 6000; + pindex = 0; + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + segid = ((nHeight + addrhash.uints[0]) & 0x3f); + komodo_segids(hashbuf,nHeight-101,100); + memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); + memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); + memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); + vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); + for (iter=0; iter<3600; iter++) + { + diff = (iter + blocktime - txtime - minage); + if ( diff > 3600*24*30 ) + diff = 3600*24*30; + if ( iter > 0 ) + diff += segid*2; + if ( blocktime+iter+segid*2 < txtime+minage ) + continue; + coinage = (value * diff) * ((diff >> 16) + 1); + hashval = arith_uint256(supply * mfactor) * (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 < 10 ) + return(blocktime); + return(blocktime * winner); +} + 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; bool fNegative,fOverflow; 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; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; 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 mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + //if ( nHeight >= 4000 ) + return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) blocktime = prevtime+57; @@ -1120,18 +1242,19 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*3 + sizeof(vout)); } else vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); + 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*30 ) + diff = 3600*24*30 if ( iter > 0 ) diff += iter + segid*2; - //if ( diff > 3600*24 ) - // break; if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * 64) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; diff --git a/src/miner.cpp b/src/miner.cpp index dcf22b1bd..7bf93a8ed 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -920,6 +920,8 @@ void static BitcoinMiner() continue; }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); + if ( Mining_height >= 4000 ) + HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) From 86f88c4f0c000fa72a46014b471e4af0e50a195f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 01:53:28 -1100 Subject: [PATCH 0304/1123] Syntax --- src/komodo_bitcoind.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6f3af9d27..b1656d09b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1088,21 +1088,21 @@ uint32_t komodo_segid32(char *coinaddr) int8_t komodo_segid(int32_t height) { - CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; bits256 txid; int8_t segid = -1; + CTxDestination voutaddress; CBlock block; CBlockIndex *pindex; uint64_t value; uint32_t txtime; char voutaddr[64],destaddr[64]; int32_t txn_count,vout; uint256 txid; int8_t segid = -1; if ( height > 0 && (pindex= komodo_chainactive(height)) != 0 ) { if ( komodo_blockload(block,pindex) == 0 ) { - txn_count = pblock->vtx.size(); - if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) + txn_count = block.vtx.size(); + if ( txn_count > 1 && block.vtx[txn_count-1].vin.size() == 1 && block.vtx[txn_count-1].vout.size() == 1 ) { - txid = pblock->vtx[txn_count-1].vin[0].prevout.hash; - vout = pblock->vtx[txn_count-1].vin[0].prevout.n; + txid = block.vtx[txn_count-1].vin[0].prevout.hash; + vout = block.vtx[txn_count-1].vin[0].prevout.n; txtime = komodo_txtime(&value,txid,vout,destaddr); - if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) + if ( ExtractDestination(block.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 ) + if ( strcmp(destaddr,voutaddr) == 0 && block.vtx[txn_count-1].vout[0].nValue == value ) { segid = komodo_segid32(voutaddr) & 0x3f; } @@ -1209,7 +1209,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe 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; bool fNegative,fOverflow; 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 mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - //if ( nHeight >= 4000 ) +//if ( nHeight >= 4000 ) return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) @@ -1248,7 +1248,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) - diff = 3600*24*30 + diff = 3600*24*30; if ( iter > 0 ) diff += iter + segid*2; if ( blocktime+iter+segid*2 < txtime+minage ) From 4aef05c93fa6de279bfd21d10c7cafc27dcc3985 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 01:56:53 -1100 Subject: [PATCH 0305/1123] Fix --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b1656d09b..c981b20b7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; 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 mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+60 ) blocktime = prevtime+60; From b7865ea8f39a9aec6189720e02cd57aa1752abb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 02:47:46 -1100 Subject: [PATCH 0306/1123] Newstake active at 4000 --- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c981b20b7..787ba5f6b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1209,7 +1209,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe 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; bool fNegative,fOverflow; 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 mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; -//if ( nHeight >= 4000 ) + if ( nHeight >= 4000 ) return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 67bafd32b..2230a1aa7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4621,6 +4621,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt fprintf(stderr,"komodo_staked setAddress.count error\n"); continue; } + if ( IsMine(*pwalletMain, address) == 0 ) + continue; } CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; From e8dd12a110e009eb75decca4e106e91af5116597 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 04:37:40 -1100 Subject: [PATCH 0307/1123] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 787ba5f6b..e68c1a74b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1395,7 +1395,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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)); + //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; } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx From 41070f82b7c103f7e97bd249e2eea7fe4a12a7f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 06:57:59 -1100 Subject: [PATCH 0308/1123] Skip fractional utxo for staking --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2230a1aa7..9cbefea63 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4625,6 +4625,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN && *utxovaluep != 0 ) + continue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); CTxDestination address; From 2f83c3e638aed65cff55367e71323d1dd25b726a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 07:00:06 -1100 Subject: [PATCH 0309/1123] Simplify --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9cbefea63..c866a3be8 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4625,7 +4625,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN && *utxovaluep != 0 ) + if ( nValue < COIN ) continue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); From e3124af1da164fe1b9d54d5c8667f4bf4efe4336 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 20:31:28 -1100 Subject: [PATCH 0310/1123] Decker's fix for watch only addresses --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c866a3be8..1e330b20c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4625,7 +4625,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN ) + if ( nValue < COIN || !out.fSpendable ) continue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); From 42c0fc6a632c2c3fd19f844924d980abc6766161 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 7 Jul 2018 21:01:23 -1100 Subject: [PATCH 0311/1123] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e68c1a74b..d469ab953 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1406,7 +1406,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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 (%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); } From 196c69f770084c0bda8cdf41c826454e44e52789 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 00:13:09 -1100 Subject: [PATCH 0312/1123] Fix easy diff check for PoS --- COPYING | 1 + src/pow.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/COPYING b/COPYING index c84bfb7aa..eecf5ccc8 100644 --- a/COPYING +++ b/COPYING @@ -1,3 +1,4 @@ +Copyright (c) 2016-2018 The Komodo developers Copyright (c) 2016-2017 The Zcash developers Copyright (c) 2009-2017 The Bitcoin Core developers diff --git a/src/pow.cpp b/src/pow.cpp index 2e525e8cb..5e9560850 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,6 +190,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); + if ( height >= 4000 && ASSETCHAINS_STAKED != 0 ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From dec86f1b5a0e12b9fe1bfafa283f7622714de064 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 00:14:24 -1100 Subject: [PATCH 0313/1123] Delay activation to 4200 --- src/pow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pow.cpp b/src/pow.cpp index 5e9560850..cd7f47c71 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,7 +190,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( height >= 4000 && ASSETCHAINS_STAKED != 0 ) + if ( height >= 4200 && ASSETCHAINS_STAKED != 0 ) bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 0cd39760aada64f7bc6dce1b84ef8338caa76521 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:05:40 -1100 Subject: [PATCH 0314/1123] Test --- src/komodo_bitcoind.h | 9 ++++++--- src/miner.cpp | 2 +- src/pow.cpp | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d469ab953..79bd25e38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,7 +1147,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( nHeight < 6000 ) // POSTEST64 change newstake to stake and stake to oldstake and remove + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; @@ -1209,7 +1210,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe 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; bool fNegative,fOverflow; 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 mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - if ( nHeight >= 4000 ) + if ( nHeight >= 4000 ) // POSTEST64 remove when this is oldstake return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); txtime = komodo_txtime(&value,txid,vout,address); if ( blocktime < prevtime+57 ) @@ -1448,7 +1449,9 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + if ( ASSETCHAINS_STAKED == 100 && height >= 4000 && height < 6000 ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + else 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); diff --git a/src/miner.cpp b/src/miner.cpp index 7bf93a8ed..0b41c5cc0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -920,7 +920,7 @@ void static BitcoinMiner() continue; }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 4000 ) + if ( Mining_height >= 4000 && Mining_height < 6000 ) // POSTEST64 remove this HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { diff --git a/src/pow.cpp b/src/pow.cpp index cd7f47c71..8f12f56b4 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,7 +190,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( height >= 4200 && ASSETCHAINS_STAKED != 0 ) + if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 6000 ) // POSTEST64 remove this bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 07529d5eb13f1a9f2c79b6bcac4db9c9dbc9efd7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:06:18 -1100 Subject: [PATCH 0315/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 79bd25e38..2eb1f1164 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1449,7 +1449,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - if ( ASSETCHAINS_STAKED == 100 && height >= 4000 && height < 6000 ) + if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); else bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); From f02af889b9ae06953deb19534e5282d8aaac5cef Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:53:38 -1100 Subject: [PATCH 0316/1123] Test --- src/komodo_bitcoind.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2eb1f1164..c29668146 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1449,8 +1449,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) + if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) // POSTEST64 + { bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + fprintf(stderr,"setmindiff ht.%d\n",height); + } else bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); @@ -1481,7 +1484,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) } else if ( possible == 0 || ASSETCHAINS_SYMBOL[0] != 0 ) { - if (KOMODO_TEST_ASSETCHAIN_SKIP_POW) return(0); + if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) + return(0); fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); return(-1); } @@ -1490,7 +1494,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { - if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! + if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! POSTEST64 return(-1); else { From b45eddd85afc97ca559fa24839abe7bb62bd908a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 02:59:05 -1100 Subject: [PATCH 0317/1123] Test --- src/komodo_bitcoind.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c29668146..6e76e5349 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1454,7 +1454,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); fprintf(stderr,"setmindiff ht.%d\n",height); } - else bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + else + { + bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); + fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); + } bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); //fprintf(stderr,"height.%d slowflag.%d possible.%d cmp.%d\n",height,slowflag,possible,bhash > bnTarget); From ffd2c3834893741d599198824b38fe7cbdd80b42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 03:03:21 -1100 Subject: [PATCH 0318/1123] Remove easy diff at 4400 --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 4 ++-- src/pow.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6e76e5349..863c39134 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,7 +1147,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - if ( nHeight < 6000 ) // POSTEST64 change newstake to stake and stake to oldstake and remove + if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks @@ -1449,12 +1449,12 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 6000 ) // POSTEST64 + /*if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 4400 ) // POSTEST64 { bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); fprintf(stderr,"setmindiff ht.%d\n",height); } - else + else*/ { bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); diff --git a/src/miner.cpp b/src/miner.cpp index 0b41c5cc0..2fb623b84 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -911,7 +911,7 @@ void static BitcoinMiner() } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; } else Mining_start = 0; - if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) { int32_t percPoS,z; /*if ( Mining_height <= 100 ) @@ -920,7 +920,7 @@ void static BitcoinMiner() continue; }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 4000 && Mining_height < 6000 ) // POSTEST64 remove this + if ( Mining_height >= 4000 && Mining_height < 4400 ) // POSTEST64 remove this HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { diff --git a/src/pow.cpp b/src/pow.cpp index 8f12f56b4..a6117b35c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,7 +190,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 6000 ) // POSTEST64 remove this + if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 62a9cee4d34c239c620f2d96ae6eb08b9c9e07f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:01:57 -1100 Subject: [PATCH 0319/1123] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 863c39134..d742914e8 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1457,7 +1457,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else*/ { bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); + //fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); } bhash = UintToArith256(hash); possible = komodo_block2pubkey33(pubkey33,pblock); From f89f4ef034de31075d95849e238d0c50869cb3b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:04:55 -1100 Subject: [PATCH 0320/1123] Update URL to white paper --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d85d013d..788635536 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ It downloads and stores the entire history of Komodo transactions; depending on - 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) +- Whitepaper: [Komodo Whitepaper](https://komodoplatform.com/wp-content/uploads/2018/06/Komodo-Whitepaper-June-3.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 From 4ff37947b10c03df679003289e2e79590ff73115 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:32:02 -1100 Subject: [PATCH 0321/1123] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d742914e8..1f6680134 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -567,7 +567,7 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) #endif hashBlock, true)) { - fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); From 5aa69f6d75c8c5839bc00e61c2e93a0830949b66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 04:34:27 -1100 Subject: [PATCH 0322/1123] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1f6680134..2b4cf8cbc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1490,7 +1490,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); - fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); + //fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); return(-1); } } From 45ee62cb719499b3ff2fde6168e2ef9aa0364076 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:17:39 -1100 Subject: [PATCH 0323/1123] Ht 6000 test --- src/komodo_bitcoind.h | 20 ++++++-------------- src/miner.cpp | 11 ++--------- src/pow.cpp | 2 -- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2b4cf8cbc..0f3033914 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,15 +1140,16 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); - if ( blocktime < prevtime+60 ) - blocktime = prevtime+60; + if ( nHeight < 6000 ) + { + if ( blocktime < prevtime+60 ) + blocktime = prevtime+60; + } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; @@ -1449,16 +1450,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } hash = pblock->GetHash(); - /*if ( ASSETCHAINS_STAKED == 100 && height >= 4250 && height < 4400 ) // POSTEST64 - { - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - fprintf(stderr,"setmindiff ht.%d\n",height); - } - else*/ - { - bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow); - //fprintf(stderr,"set diff ht.%d slowflag.%d\n",height,slowflag); - } + 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); diff --git a/src/miner.cpp b/src/miner.cpp index 2fb623b84..5e7871dd4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -425,7 +425,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-13 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-30 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); @@ -914,14 +914,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) { int32_t percPoS,z; - /*if ( Mining_height <= 100 ) - { - sleep(60); - continue; - }*/ HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 4000 && Mining_height < 4400 ) // POSTEST64 remove this - HASHTarget = arith_uint256().SetCompact(KOMODO_MINDIFF_NBITS); if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) @@ -984,7 +977,7 @@ void static BitcoinMiner() return false; if ( B.nTime > GetAdjustedTime() ) { - fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); + //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime-2 ) { sleep(1); diff --git a/src/pow.cpp b/src/pow.cpp index a6117b35c..2e525e8cb 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,8 +190,6 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From 7ed0e00b8201a1c6e5f7c63d040c59a04e71c9c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:23:30 -1100 Subject: [PATCH 0324/1123] Test --- src/komodo_bitcoind.h | 2 ++ src/pow.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0f3033914..b95efc8d1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1150,6 +1150,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } + if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; diff --git a/src/pow.cpp b/src/pow.cpp index 2e525e8cb..a6117b35c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,6 +190,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); + if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From 4646f21b5bd0b210e56336cdeeab914eb1ffcfde Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:30:41 -1100 Subject: [PATCH 0325/1123] Height 6000 disable 60 sec delay --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b95efc8d1..e1249a955 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1125,13 +1125,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Sun, 8 Jul 2018 16:50:11 -1100 Subject: [PATCH 0326/1123] Remove miner locks --- src/miner.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 5e7871dd4..20ff32d7c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -425,7 +425,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-30 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-57 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); @@ -975,7 +975,7 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) return false; - if ( B.nTime > GetAdjustedTime() ) + if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) { //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); while ( GetAdjustedTime() < B.nTime-2 ) @@ -999,8 +999,8 @@ void static BitcoinMiner() } else { - while ( GetAdjustedTime() < B.nTime ) - sleep(1); + //while ( B.nTime > GetAdjustedTime() ) + // sleep(1); uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From 0c35569bdcc102afab31183e81999465e7526a87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:52:14 -1100 Subject: [PATCH 0327/1123] tweak --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 20ff32d7c..2e552d62f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -999,8 +999,8 @@ void static BitcoinMiner() } else { - //while ( B.nTime > GetAdjustedTime() ) - // sleep(1); + while ( B.nTime-57 > GetAdjustedTime() ) + sleep(1); uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From 3aac96a8228e4f126cbf2c8b097902f631b9b58c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 8 Jul 2018 16:53:01 -1100 Subject: [PATCH 0328/1123] <6000 compatibility --- src/miner.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 2e552d62f..bbcbf6643 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1001,6 +1001,11 @@ void static BitcoinMiner() { while ( B.nTime-57 > GetAdjustedTime() ) sleep(1); + if ( Mining_height < 6000 ) + { + while ( B.nTime > GetAdjustedTime() ) + sleep(1); + } uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From de7cb53f9933e773c3be96f435a9d3081d5098b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:20:08 -1100 Subject: [PATCH 0329/1123] Test post 6000 --- src/komodo_bitcoind.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e1249a955..3956e36f1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1145,6 +1145,11 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime < prevtime+60 ) blocktime = prevtime+60; } + else + { + if ( blocktime < prevtime+30 ) + blocktime = prevtime+30; + } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); From 422b307c873ac94a0ddf080642ba3596e77eaae4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:24:40 -1100 Subject: [PATCH 0330/1123] Reduce gap --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3956e36f1..1f3c251ec 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1147,8 +1147,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } else { - if ( blocktime < prevtime+30 ) - blocktime = prevtime+30; + if ( blocktime < prevtime+3 ) + blocktime = prevtime+3; } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { From f1d8e4b6b5a96d6c173cf4bd7dc0c2162615ecf7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:38:27 -1100 Subject: [PATCH 0331/1123] Fix timestamps --- src/komodo_bitcoind.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1f3c251ec..44ec68aa7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,6 +1140,8 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); + if ( blocktime < GetAdjustedTime() ) + blocktime = GetAdjustedTime(); if ( nHeight < 6000 ) // POSTEST64 { if ( blocktime < prevtime+60 ) From 89931e6e6096908f98521cf334aa07f44f74f9ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:40:33 -1100 Subject: [PATCH 0332/1123] Fix --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 44ec68aa7..a3077828a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1140,7 +1140,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); - if ( blocktime < GetAdjustedTime() ) + if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); if ( nHeight < 6000 ) // POSTEST64 { From 7c28c718f0e6c2b583dd96c347eec3c165fdba3d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 08:44:15 -1100 Subject: [PATCH 0333/1123] +segids print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a3077828a..3fda9ce00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1125,13 +1125,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Mon, 9 Jul 2018 08:57:16 -1100 Subject: [PATCH 0334/1123] -print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3fda9ce00..a3077828a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1125,13 +1125,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Mon, 9 Jul 2018 22:15:27 -1100 Subject: [PATCH 0335/1123] 7250 diff cap.16 hardfork for PoS --- src/komodo_bitcoind.h | 11 +++++++++-- src/miner.cpp | 11 +++++++++-- src/pow.cpp | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a3077828a..1a679c485 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1159,6 +1159,13 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + else if ( nHeight >= 7250 ) + { + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; + } mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; @@ -1491,8 +1498,8 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW ) return(0); - //fprintf(stderr,"pow violation and no chance it is notary ht.%d %s\n",height,hash.ToString().c_str()); - return(-1); + if ( ASSETCHAINS_STAKED == 0 ) // komodo_is_PoSblock will check bnTarget + return(-1); } } if ( ASSETCHAINS_STAKED != 0 && height >= 2 ) // must PoS or have at least 16x better PoW diff --git a/src/miner.cpp b/src/miner.cpp index bbcbf6643..bc56df370 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -856,7 +856,7 @@ void static BitcoinMiner() // // Search // - uint8_t pubkeys[66][33]; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); savebits = pblock->nBits; HASHTarget = arith_uint256().SetCompact(pblock->nBits); roundrobin_delay = ROUNDROBIN_DELAY; @@ -911,10 +911,17 @@ void static BitcoinMiner() } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; } else Mining_start = 0; - if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + if ( ASSETCHAINS_STAKED != 0 ) { int32_t percPoS,z; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); + if ( Mining_height >= 7250 ) + { + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); + if ( HASHtarget < bnMaxPoSdiff ) + HASHtarget = bnMaxPoSdiff; + } if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) diff --git a/src/pow.cpp b/src/pow.cpp index a6117b35c..39204f7f9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -190,8 +190,19 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int } if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit)) return error("CheckProofOfWork(): nBits below minimum work"); - if ( ASSETCHAINS_STAKED != 0 && height >= 4200 && height < 4400 ) // POSTEST64 remove this - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + if ( ASSETCHAINS_STAKED != 0 ) + { + if ( height >= 4200 && height < 4400 ) + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + else if ( height >= 7250 ) + { + arith_uint256 bnMaxPoSdiff; + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; + } + } // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) { From ed3d0a051e6e325ccbd658e5d3502d740c3940a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 9 Jul 2018 22:21:39 -1100 Subject: [PATCH 0336/1123] Syntax --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bc56df370..d85e4d510 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -913,14 +913,14 @@ void static BitcoinMiner() } else Mining_start = 0; if ( ASSETCHAINS_STAKED != 0 ) { - int32_t percPoS,z; + int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); if ( Mining_height >= 7250 ) { bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( HASHtarget < bnMaxPoSdiff ) - HASHtarget = bnMaxPoSdiff; + if ( HASHTarget < bnMaxPoSdiff ) + HASHTarget = bnMaxPoSdiff; } if ( ASSETCHAINS_STAKED < 100 ) { From 97a337f739d0234ea11c348deeb37b8e7b3e7ded Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 01:19:29 -1100 Subject: [PATCH 0337/1123] Initial revisions --- src/komodo_bitcoind.h | 126 +++++------------------------------------- src/komodo_defs.h | 1 + src/miner.cpp | 39 ++----------- src/pow.cpp | 16 ++---- 4 files changed, 27 insertions(+), 155 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a679c485..7685011e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1136,37 +1136,26 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) } } -uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) +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; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; 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; arith_uint256 bnMaxPoSdiff,ratio; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); - if ( nHeight < 6000 ) // POSTEST64 - { - if ( blocktime < prevtime+60 ) - blocktime = prevtime+60; - } - else - { - if ( blocktime < prevtime+3 ) - blocktime = prevtime+3; - } + if ( blocktime < prevtime+3 ) + blocktime = prevtime+3; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } - if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - else if ( nHeight >= 7250 ) - { - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; - } - mfactor = 1024; + if ( value < SATOSHIDEN ) + return(0); + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (bnTarget / bnMaxPoSdiff); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; @@ -1187,7 +1176,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); if ( hashval <= bnTarget ) { winner = 1; @@ -1224,100 +1213,15 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe return(blocktime * winner); } -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; bool fNegative,fOverflow; 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 mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; - if ( nHeight >= 4000 ) // POSTEST64 remove when this is oldstake - return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr)); - txtime = komodo_txtime(&value,txid,vout,address); - if ( blocktime < prevtime+57 ) - blocktime = prevtime+57; - if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) - { - //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); - return(0); - } - if ( ASSETCHAINS_STAKED != 100 || nHeight < 2000 ) - { - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; - } - if ( (minage= nHeight*3) > 6000 ) // about 100 blocks - minage = 6000; - pindex = 0; - if ( (pindex= komodo_chainactive(nHeight>50?nHeight-50: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)); - if ( nHeight >= 2000 ) - { - memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)],&txid,sizeof(txid)); - memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); - vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*3 + sizeof(vout)); - } else vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2); - 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*30 ) - diff = 3600*24*30; - if ( iter > 0 ) - diff += iter + segid*2; - if ( blocktime+iter+segid*2 < txtime+minage ) - continue; - coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * mfactor) * (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); - } - } //else fprintf(stderr,"skip PoS scan: diff %d blocktime %u > %u txtime+minage %u pindex.%p\n",(int32_t)(blocktime - (txtime+minage)),blocktime,txtime,minage,pindex); - if ( nHeight < 10 ) - 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; + CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; *percPoSp = percPoS = 0; if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); sum = arith_uint256(0); ave = sum; + easydiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); for (i=n=0; i<100; i++) { ht = height - 100 + i; @@ -1375,7 +1279,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { - bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); if ( 1 ) { for (i=31; i>=24; i--) diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 1d7351638..9650620a9 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -8,5 +8,6 @@ #define KOMODO_LIMITED_NETWORKSIZE 4 #define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" +#define KOMODO_MAXPOS_DIFF 16 #endif diff --git a/src/miner.cpp b/src/miner.cpp index d85e4d510..2ec853756 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -117,11 +117,7 @@ uint32_t Mining_start,Mining_height; int32_t My_notaryid = -1; int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp); int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize); -//uint64_t komodo_paxtotal(); int32_t komodo_baseid(char *origbase); -//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); 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); @@ -140,29 +136,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return NULL; } CBlock *pblock = &pblocktemplate->block; // pointer for convenience - /*if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && chainActive.Tip()->nHeight >= ASSETCHAINS_MINHEIGHT ) - { - isrealtime = komodo_isrealtime(&kmdheight); - deposits = komodo_paxtotal(); - while ( KOMODO_ON_DEMAND == 0 && deposits == 0 && (int32_t)mempool.GetTotalTxSize() == 0 ) - { - deposits = komodo_paxtotal(); - if ( KOMODO_PASSPORT_INITDONE == 0 || KOMODO_INITDONE == 0 || (komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && (isrealtime= komodo_isrealtime(&kmdheight)) == 0) ) - { - //fprintf(stderr,"INITDONE.%d RT.%d deposits %.8f ht.%d\n",KOMODO_INITDONE,isrealtime,(double)deposits/COIN,kmdheight); - } - else if ( komodo_isrealtime(&kmdheight) != 0 && (deposits != 0 || (int32_t)mempool.GetTotalTxSize() > 0) ) - { - fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u KOMODO_ON_DEMAND.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),isrealtime,KOMODO_ON_DEMAND); - break; - } - sleep(10); - } - KOMODO_ON_DEMAND = 0; - if ( 0 && deposits != 0 ) - printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize()); - }*/ - // -regtest only: allow overriding block.nVersion with + // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios if (Params().MineBlocksOnDemand()) pblock->nVersion = GetArg("-blockversion", pblock->nVersion); @@ -915,13 +889,10 @@ void static BitcoinMiner() { int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - if ( Mining_height >= 7250 ) - { - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( HASHTarget < bnMaxPoSdiff ) - HASHTarget = bnMaxPoSdiff; - } + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); + if ( HASHTarget < bnMaxPoSdiff ) + HASHTarget = bnMaxPoSdiff; if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) diff --git a/src/pow.cpp b/src/pow.cpp index 39204f7f9..0b00c5929 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -127,6 +127,7 @@ extern int32_t KOMODO_CHOSEN_ONE; extern uint64_t ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; #define KOMODO_ELECTION_GAP 2000 +#define KOMODO_MAXPOS_DIFF 16 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height); int32_t KOMODO_LOADINGBLOCKS = 1; @@ -192,16 +193,11 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int return error("CheckProofOfWork(): nBits below minimum work"); if ( ASSETCHAINS_STAKED != 0 ) { - if ( height >= 4200 && height < 4400 ) - bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - else if ( height >= 7250 ) - { - arith_uint256 bnMaxPoSdiff; - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; - } + arith_uint256 bnMaxPoSdiff; + bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); + if ( bnTarget < bnMaxPoSdiff ) + bnTarget = bnMaxPoSdiff; } // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From 443277cab34f7617975f4e6d829b0bb086614302 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:04:00 -1100 Subject: [PATCH 0338/1123] 7500 changes --- src/komodo_bitcoind.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a679c485..afd54c784 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1026,7 +1026,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { if ( txheight > 246748 ) { @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 ratio,hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1162,13 +1162,18 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe else if ( nHeight >= 7250 ) { bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (bnMaxPoSdiff / bnTarget); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); if ( bnTarget < bnMaxPoSdiff ) bnTarget = bnMaxPoSdiff; } mfactor = 1024; if ( (minage= nHeight*3) > 6000 ) // about 100 blocks + { minage = 6000; + if ( height >= 7500 ) + txtime -= KOMODO_MAXMEMPOOLTIME; + } pindex = 0; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); segid = ((nHeight + addrhash.uints[0]) & 0x3f); @@ -1187,7 +1192,9 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); + if ( height < 7500 ) + hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); + else hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); if ( hashval <= bnTarget ) { winner = 1; From 41ee6d2a1f142c1e61d10d7071dec8f5bed30972 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:07:27 -1100 Subject: [PATCH 0339/1123] Syntax --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index afd54c784..20c2c63b4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 ratio,hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); From 25c8fec1c32b46fb79d70c255c0a427656d10e26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:08:27 -1100 Subject: [PATCH 0340/1123] nHeight --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 20c2c63b4..e7a74b0f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1171,7 +1171,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( (minage= nHeight*3) > 6000 ) // about 100 blocks { minage = 6000; - if ( height >= 7500 ) + if ( nHeight >= 7500 ) txtime -= KOMODO_MAXMEMPOOLTIME; } pindex = 0; @@ -1192,7 +1192,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - if ( height < 7500 ) + if ( nHeight < 7500 ) hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); else hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); if ( hashval <= bnTarget ) From 5a62cfb73b41d046ca0e99406586b0c10b4613d6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:23:24 -1100 Subject: [PATCH 0341/1123] Fix exceptions --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e7a74b0f9..f6f7005ba 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1028,9 +1028,9 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 ) + if ( txheight < 247205 && || ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From c515ae54d208935617019796ffaf7db9d55a7c3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:25:00 -1100 Subject: [PATCH 0342/1123] Syntax --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f6f7005ba..0ec295fbd 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1030,7 +1030,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 && || ASSETCHAINS_STAKED == 0 ) + if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From 837aaaecb605847ba895b4ff8a2c81b3e0c9cbe4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:26:27 -1100 Subject: [PATCH 0343/1123] Fix exception --- src/komodo_bitcoind.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7685011e2..18117f665 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1026,11 +1026,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 ) + if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { @@ -1140,6 +1140,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; 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; arith_uint256 bnMaxPoSdiff,ratio; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; txtime = komodo_txtime(&value,txid,vout,address); + txtime -= KOMODO_MAXMEMPOOLTIME; if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); if ( blocktime < prevtime+3 ) @@ -1152,7 +1153,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( value < SATOSHIDEN ) return(0); bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - ratio = (bnTarget / bnMaxPoSdiff); + ratio = (bnMaxPoSdiff / bnTarget); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); if ( bnTarget < bnMaxPoSdiff ) bnTarget = bnMaxPoSdiff; From d60e3fd1a1f414c9c6cfb76827ef0cd2cf09e7e1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:51:35 -1100 Subject: [PATCH 0344/1123] +print --- src/komodo_bitcoind.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0ec295fbd..95679eb4c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1207,12 +1207,15 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } 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);*/ + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr," ratio -> "); + 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; } } From 1cb7611fc9254216319434abf0b22d0fa0c00a1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 03:58:38 -1100 Subject: [PATCH 0345/1123] Test --- src/komodo_bitcoind.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 95679eb4c..f02c9a2e0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1207,7 +1207,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe } if ( validateflag != 0 ) { - for (i=31; i>=0; i--) + /*for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) @@ -1215,13 +1215,16 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe 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); + 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 ) + if ( 1 ) { + for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); From c662a3bad1d1eeb154ea45cebed61167b3cde929 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:04:53 -1100 Subject: [PATCH 0346/1123] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f02c9a2e0..7fcb1671b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,8 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval,origtarget; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + origtarget = bnTarget; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1229,7 +1230,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe 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,"%02x",((uint8_t *)&origtarget)[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 < 10 ) From a86b70f4811c67195f0b9af90d67be87f59a9c5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:09:16 -1100 Subject: [PATCH 0347/1123] Test --- src/komodo_bitcoind.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7fcb1671b..b7d4c7d51 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr) { - CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,hashval,origtarget; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,newhashval,hashval,origtarget,bnMaxPoSdiff; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; origtarget = bnTarget; txtime = komodo_txtime(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) @@ -1195,7 +1195,14 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe coinage = (value * diff) * ((diff >> 16) + 1); if ( nHeight < 7500 ) hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); - else hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); + else + { + newhashval = (ratio * arith_uint256(supply)) * (UintToArith256(hash) / arith_uint256(coinage+1)); + + if ( hashval < 8000 ) + hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); + else hashval = newhashval; + } if ( hashval <= bnTarget ) { winner = 1; @@ -1224,7 +1231,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe if ( 1 ) { for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr,"%02x",((uint8_t *)&newhashval)[i]); fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 5ce19c1775e32ab951b2e6fce2f1dd6f20e971ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:16:41 -1100 Subject: [PATCH 0348/1123] Test --- src/komodo_bitcoind.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b7d4c7d51..b09857ace 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1197,8 +1197,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1)); else { - newhashval = (ratio * arith_uint256(supply)) * (UintToArith256(hash) / arith_uint256(coinage+1)); - + newhashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval < 8000 ) hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); else hashval = newhashval; @@ -1232,7 +1231,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe { for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&newhashval)[i]); - fprintf(stderr," ratio -> "); + fprintf(stderr," newhash -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); From 84f19b77ae2ca56557a422a86b2b8aef880442f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:19:15 -1100 Subject: [PATCH 0349/1123] Fix --- src/komodo_bitcoind.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 18117f665..9e774bf50 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1138,7 +1138,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) 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; bool fNegative,fOverflow; uint8_t hashbuf[256]; 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; arith_uint256 bnMaxPoSdiff,ratio; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN; + CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; 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); txtime -= KOMODO_MAXMEMPOOLTIME; if ( validateflag == 0 && blocktime < GetAdjustedTime() ) @@ -1152,11 +1152,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value < SATOSHIDEN ) return(0); - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - ratio = (bnMaxPoSdiff / bnTarget); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; + mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; pindex = 0; @@ -1177,7 +1174,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1); + newhashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; @@ -1190,12 +1187,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } 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);*/ + /*for (i=31; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); + fprintf(stderr," ratio -> "); + 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; } } From b19bee1eb7af6520b0f4235a826e31514455d6ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:25:18 -1100 Subject: [PATCH 0350/1123] 8000 changes --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b09857ace..08fcb2be7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1165,7 +1165,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (bnMaxPoSdiff / bnTarget); bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16)); - if ( bnTarget < bnMaxPoSdiff ) + if ( nHeight < 8000 && bnTarget < bnMaxPoSdiff ) bnTarget = bnMaxPoSdiff; } mfactor = 1024; From 14fd7614736d64a0831f20718fb2516fd7430d4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:26:41 -1100 Subject: [PATCH 0351/1123] 8000 changes --- src/komodo_bitcoind.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 08fcb2be7..b6887dbf3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1229,14 +1229,11 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); if ( 1 ) { - for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&newhashval)[i]); - fprintf(stderr," newhash -> "); 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 *)&origtarget)[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 < 10 ) From 38cbe99ba41c90156fd526d43e3182fd2cb3394b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:28:03 -1100 Subject: [PATCH 0352/1123] Fix --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9e774bf50..132ebc135 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,7 +1174,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff) * ((diff >> 16) + 1); - newhashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); + hashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { winner = 1; From f108acf94381c5230f90eb3e5568d6e9c6a9b695 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 04:53:28 -1100 Subject: [PATCH 0353/1123] Easy diff for PoS --- src/komodo_bitcoind.h | 2 +- src/komodo_defs.h | 1 - src/miner.cpp | 5 +---- src/pow.cpp | 6 +----- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 132ebc135..ea830ce9e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1200,7 +1200,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) + if ( 1 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); diff --git a/src/komodo_defs.h b/src/komodo_defs.h index 9650620a9..1d7351638 100644 --- a/src/komodo_defs.h +++ b/src/komodo_defs.h @@ -8,6 +8,5 @@ #define KOMODO_LIMITED_NETWORKSIZE 4 #define KOMODO_MAXMEMPOOLTIME 3600 // affects consensus #define CRYPTO777_PUBSECPSTR "020e46e79a2a8d12b9b5d12c7a91adb4e454edfae43c0a0cb805427d2ac7613fd9" -#define KOMODO_MAXPOS_DIFF 16 #endif diff --git a/src/miner.cpp b/src/miner.cpp index 2ec853756..9ca979e07 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -889,10 +889,7 @@ void static BitcoinMiner() { int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); - if ( HASHTarget < bnMaxPoSdiff ) - HASHTarget = bnMaxPoSdiff; + HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( ASSETCHAINS_STAKED < 100 ) { for (z=31; z>=0; z--) diff --git a/src/pow.cpp b/src/pow.cpp index 0b00c5929..6d218ef13 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -127,7 +127,6 @@ extern int32_t KOMODO_CHOSEN_ONE; extern uint64_t ASSETCHAINS_STAKED; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; #define KOMODO_ELECTION_GAP 2000 -#define KOMODO_MAXPOS_DIFF 16 int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height); int32_t KOMODO_LOADINGBLOCKS = 1; @@ -194,10 +193,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int if ( ASSETCHAINS_STAKED != 0 ) { arith_uint256 bnMaxPoSdiff; - bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(KOMODO_MAXPOS_DIFF)); - if ( bnTarget < bnMaxPoSdiff ) - bnTarget = bnMaxPoSdiff; + bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); } // Check proof of work matches claimed amount if ( UintToArith256(hash) > bnTarget ) From a03465f69e964711dca1df25466cee5a76e12665 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:22:11 -1100 Subject: [PATCH 0354/1123] Rescale --- src/komodo_bitcoind.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ea830ce9e..7072781ba 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1152,6 +1152,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( value < SATOSHIDEN ) return(0); + value /= SATOSHIDEN; mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks From 0a953df21b0ac2cd6a6aad286681811757ae378b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:38:28 -1100 Subject: [PATCH 0355/1123] Txtime2 --- src/komodo_bitcoind.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7072781ba..cb7ef6c65 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -580,6 +580,32 @@ uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) return(tx.nLockTime); } +uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) +{ + CTxDestination address; CBlockIndex *pindex; CTransaction tx; uint256 hashBlock; uint32_t txtime = 0; + *valuep = 0; + if (!GetTransaction(hash, tx, +#ifndef KOMODO_ZCASH + Params().GetConsensus(), +#endif + hashBlock, true)) + { + //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + return(0); + } + if ( (pindex= mapBlockIndex[block->GetHash()]) != 0 ) + txtime = pindex->nTime; + else txtime = tx.nLockTime; + //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); + if ( n < tx.vout.size() ) + { + *valuep = tx.vout[n].nValue; + if (ExtractDestination(tx.vout[n].scriptPubKey, address)) + strcpy(destaddr,CBitcoinAddress(address).ToString().c_str()); + } + return(txtime); +} + void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; @@ -1139,8 +1165,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) 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; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; 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); - txtime -= KOMODO_MAXMEMPOOLTIME; + txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); if ( blocktime < prevtime+3 ) From cc08cccff2682eedb5e30afa6e0385ef1d217674 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:40:48 -1100 Subject: [PATCH 0356/1123] Fix --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cb7ef6c65..08c43c468 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -593,7 +593,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - if ( (pindex= mapBlockIndex[block->GetHash()]) != 0 ) + if ( (pindex= mapBlockIndex[pindex->GetHash()]) != 0 ) txtime = pindex->nTime; else txtime = tx.nLockTime; //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); From 85bf0316b012d54a2494ac264ef71462b4121828 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 05:42:03 -1100 Subject: [PATCH 0357/1123] Fix --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 08c43c468..7beb0db42 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -593,7 +593,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - if ( (pindex= mapBlockIndex[pindex->GetHash()]) != 0 ) + if ( (pindex= mapBlockIndex[pindex->GetBlockHash()]) != 0 ) txtime = pindex->nTime; else txtime = tx.nLockTime; //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); From ec894008176b9054daad5e24edb4a7182b5f58a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:07:01 -1100 Subject: [PATCH 0358/1123] Fix --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7beb0db42..4f0698038 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -593,7 +593,7 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) //fprintf(stderr,"ERROR: %s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); return(0); } - if ( (pindex= mapBlockIndex[pindex->GetBlockHash()]) != 0 ) + if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) txtime = pindex->nTime; else txtime = tx.nLockTime; //fprintf(stderr,"%s/v%d locktime.%u\n",hash.ToString().c_str(),n,(uint32_t)tx.nLockTime); @@ -1172,7 +1172,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh blocktime = prevtime+3; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) From bfa19436af5f4672c8d9505a1e7640efa0e5c2de Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:21:41 -1100 Subject: [PATCH 0359/1123] Test --- src/komodo_bitcoind.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4f0698038..95b4f6e47 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) 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; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; 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; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; 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_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1182,7 +1182,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; - pindex = 0; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); segid = ((nHeight + addrhash.uints[0]) & 0x3f); komodo_segids(hashbuf,nHeight-101,100); @@ -1195,11 +1194,13 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) diff = 3600*24*30; + else if ( diff < 0 ) + diff = 60; if ( iter > 0 ) diff += segid*2; if ( blocktime+iter+segid*2 < txtime+minage ) continue; - coinage = (value * diff) * ((diff >> 16) + 1); + coinage = (value * diff); hashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); if ( hashval <= bnTarget ) { @@ -1233,7 +1234,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh 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); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); } if ( nHeight < 10 ) return(blocktime); From 5e90f44589025333edb436302287991edc0d517d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:32:27 -1100 Subject: [PATCH 0360/1123] Test --- src/komodo_bitcoind.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 95b4f6e47..c053285a7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1193,7 +1193,10 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) + { + printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,minage); diff = 3600*24*30; + } else if ( diff < 0 ) diff = 60; if ( iter > 0 ) From b9ed7fa848605b8a09231138085c36c646679cc0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:34:12 -1100 Subject: [PATCH 0361/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c053285a7..f10c34b3f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1194,7 +1194,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) { - printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,minage); + printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } else if ( diff < 0 ) From 745a8dfc5dbb5e8c7e5fda32b1ddec422341c4f4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:36:54 -1100 Subject: [PATCH 0362/1123] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f10c34b3f..28b8d4368 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) 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) { - bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; 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; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1194,7 +1194,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = (iter + blocktime - txtime - minage); if ( diff > 3600*24*30 ) { - printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",diff,iter,blocktime,txtime,(int32_t)minage); + printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } else if ( diff < 0 ) From f6567e80078d9bab45e0f61186349dc30647f966 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:44:04 -1100 Subject: [PATCH 0363/1123] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 28b8d4368..599b6b44e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1192,13 +1192,13 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh for (iter=0; iter<3600; iter++) { diff = (iter + blocktime - txtime - minage); - if ( diff > 3600*24*30 ) + if ( diff < 0 ) + diff = 60; + else if ( diff > 3600*24*30 ) { printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } - else if ( diff < 0 ) - diff = 60; if ( iter > 0 ) diff += segid*2; if ( blocktime+iter+segid*2 < txtime+minage ) From 0999e80e0edbcd0376a18e2087989c43dd9def14 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:50:26 -1100 Subject: [PATCH 0364/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 599b6b44e..d942d3078 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) 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) { - bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); From 01994dbac72583b7ffd101a1ce33adc990ba9480 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 06:57:20 -1100 Subject: [PATCH 0365/1123] Test --- src/komodo_bitcoind.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d942d3078..856e22e7d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1172,7 +1172,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh blocktime = prevtime+3; if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { - fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); + //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); return(0); } if ( value < SATOSHIDEN ) @@ -1196,7 +1196,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh diff = 60; else if ( diff > 3600*24*30 ) { - printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); + //printf("diff.%d (iter.%d blocktime.%u txtime.%u minage.%d)\n",(int32_t)diff,iter,blocktime,txtime,(int32_t)minage); diff = 3600*24*30; } if ( iter > 0 ) @@ -1217,20 +1217,17 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - /*for (i=31; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&ratio)[i]); - fprintf(stderr," ratio -> "); for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs target "); + 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 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);*/ + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); break; } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 1 ) + if ( 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 26b9af8048b43fa5c9f0e6a5c25b993689645901 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:06:04 -1100 Subject: [PATCH 0366/1123] Prints --- src/komodo_bitcoind.h | 6 +++--- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 856e22e7d..e667ae280 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1217,17 +1217,17 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( validateflag != 0 ) { - for (i=31; i>=24; i--) + /*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 v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 ) + if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1e330b20c..5151936c4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4645,7 +4645,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { From 4dc0ad386693422611dee60bf75ae8ca85b6b5f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:15:24 -1100 Subject: [PATCH 0367/1123] -print --- src/komodo_bitcoind.h | 4 ++-- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e667ae280..9872275e1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1227,14 +1227,14 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( validateflag != 0 ) + if ( validateflag > 1 ) { 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 v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff); + fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } if ( nHeight < 10 ) return(blocktime); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5151936c4..a3559fc00 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4645,7 +4645,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 9aa243103f25b465873f3ddc8e8bd2e179a2fa44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:20:45 -1100 Subject: [PATCH 0368/1123] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9872275e1..3eac19dff 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1328,7 +1328,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) { CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; - if ( ASSETCHAINS_STAKED == 100 && height < 200 ) + if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); txn_count = pblock->vtx.size(); if ( txn_count > 1 && pblock->vtx[txn_count-1].vin.size() == 1 && pblock->vtx[txn_count-1].vout.size() == 1 ) @@ -1438,7 +1438,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) { if ( (is_PoSblock= komodo_is_PoSblock(slowflag,height,pblock,bnTarget)) == 0 ) { - if ( ASSETCHAINS_STAKED == 100 && height > 130 ) // only PoS allowed! POSTEST64 + if ( ASSETCHAINS_STAKED == 100 && height > 100 ) // only PoS allowed! POSTEST64 return(-1); else { From 8316bde87de5d4fb4b67d6c46bdf365c1969fd23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:27:12 -1100 Subject: [PATCH 0369/1123] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3eac19dff..9076ef125 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1227,7 +1227,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( validateflag > 1 ) + if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); @@ -1345,7 +1345,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ 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)); + 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; } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx From 0c974f218db513b2660f7e6b4c691fa2b34efdd5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 07:31:01 -1100 Subject: [PATCH 0370/1123] +print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a3559fc00..1e330b20c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 5a7fd132cf5080d572423a48e761e90fc499f6ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 09:54:28 -1100 Subject: [PATCH 0371/1123] Fix estimate PoS perc --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9076ef125..1c0a6414d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1269,6 +1269,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else { + n++; percPoS++; if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"0"); diff --git a/src/miner.cpp b/src/miner.cpp index 9ca979e07..c837268f9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -784,7 +784,7 @@ void static BitcoinMiner() if ( ASSETCHAINS_SYMBOL[0] != 0 && ASSETCHAINS_STAKED == 0 ) { //fprintf(stderr,"%s create new block ht.%d\n",ASSETCHAINS_SYMBOL,Mining_height); - sleep(3); + //sleep(3); } #ifdef ENABLE_WALLET CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey,pindexPrev->nHeight+1,gpucount); @@ -976,11 +976,11 @@ void static BitcoinMiner() { while ( B.nTime-57 > GetAdjustedTime() ) sleep(1); - if ( Mining_height < 6000 ) + /*if ( Mining_height < 6000 ) { while ( B.nTime > GetAdjustedTime() ) sleep(1); - } + }*/ uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From d5a38d16a8866207cb96ab96f6a99befd3bb8c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 10 Jul 2018 11:17:30 -1100 Subject: [PATCH 0372/1123] +print --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c837268f9..8824959e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -939,7 +939,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - /*for (z=31; z>=16; z--) + for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -947,7 +947,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n");*/ + fprintf(stderr," POW\n"); if ( h > hashTarget ) return false; if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) From afdcba6b470d707f5d0f5f182690d4031b5349ed Mon Sep 17 00:00:00 2001 From: Christoph Ritzer Date: Wed, 11 Jul 2018 13:35:48 +0200 Subject: [PATCH 0373/1123] remove a bad alert --- src/Makefile.test.include | 1 - src/init.cpp | 5 - src/test/alert_tests.cpp | 447 -------------------------------------- 3 files changed, 453 deletions(-) delete mode 100644 src/test/alert_tests.cpp diff --git a/src/Makefile.test.include b/src/Makefile.test.include index ff270bd6a..a52b66335 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -45,7 +45,6 @@ BITCOIN_TESTS =\ test/arith_uint256_tests.cpp \ test/bignum.h \ test/addrman_tests.cpp \ - test/alert_tests.cpp \ test/allocator_tests.cpp \ test/base32_tests.cpp \ test/base58_tests.cpp \ diff --git a/src/init.cpp b/src/init.cpp index 1b8018b56..a9bdc6151 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1756,11 +1756,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) StartNode(threadGroup, scheduler); - // Monitor the chain, and alert if we get blocks much quicker or slower than expected - int64_t nPowTargetSpacing = Params().GetConsensus().nPowTargetSpacing; - CScheduler::Function f = boost::bind(&PartitionCheck, &IsInitialBlockDownload, - boost::ref(cs_main), boost::cref(pindexBestHeader), nPowTargetSpacing); - scheduler.scheduleEvery(f, nPowTargetSpacing); #ifdef ENABLE_MINING // Generate coins in the background diff --git a/src/test/alert_tests.cpp b/src/test/alert_tests.cpp deleted file mode 100644 index ef607dacc..000000000 --- a/src/test/alert_tests.cpp +++ /dev/null @@ -1,447 +0,0 @@ -// Copyright (c) 2013 The Bitcoin Core developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -// -// Unit tests for alert system -// - -#include "alert.h" -#include "chain.h" -#include "chainparams.h" -#include "clientversion.h" -#include "data/alertTests.raw.h" - -#include "main.h" -#include "rpcprotocol.h" -#include "rpcserver.h" -#include "serialize.h" -#include "streams.h" -#include "util.h" -#include "utilstrencodings.h" - -#include "test/test_bitcoin.h" - -#include - -#include -#include -#include - -#include "key.h" -#include "alertkeys.h" -#include - -/* - * If the alert key pairs have changed, the test suite will fail as the - * test data is now invalid. To create valid test data, signed with a - * new alert private key, follow these steps: - * - * 1. Copy your private key into alertkeys.h. Don't commit this file! - * See sendalert.cpp for more info. - * - * 2. Set the GENERATE_ALERTS_FLAG to true. - * - * 3. Build and run: - * test_bitcoin -t Generate_Alert_Test_Data - * - * 4. Test data is saved in your current directory as alertTests.raw.NEW - * Copy this file to: src/test/data/alertTests.raw - * - * For debugging purposes, terminal output can be copied into: - * src/test/data/alertTests.raw.h - * - * 5. Clean up... - * - Set GENERATE_ALERTS_FLAG back to false. - * - Remove your private key from alertkeys.h - * - * 6. Build and verify the new test data: - * test_bitcoin -t Alert_tests - * - */ -#define GENERATE_ALERTS_FLAG false - -#if GENERATE_ALERTS_FLAG - -// NOTE: -// A function SignAndSave() was used by Bitcoin Core to create alert test data -// but it has not been made publicly available. So instead, we have adapted -// some publicly available code which achieves the intended result: -// https://gist.github.com/lukem512/9b272bd35e2cdefbf386 - - -// Code to output a C-style array of values -template -std::string HexStrArray(const T itbegin, const T itend, int lineLength) -{ - std::string rv; - static const char hexmap[16] = { '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - rv.reserve((itend-itbegin)*3); - int i = 0; - for(T it = itbegin; it < itend; ++it) - { - unsigned char val = (unsigned char)(*it); - if(it != itbegin) - { - if (i % lineLength == 0) - rv.push_back('\n'); - else - rv.push_back(' '); - } - rv.push_back('0'); - rv.push_back('x'); - rv.push_back(hexmap[val>>4]); - rv.push_back(hexmap[val&15]); - rv.push_back(','); - i++; - } - - return rv; -} - -template -inline std::string HexStrArray(const T& vch, int lineLength) -{ - return HexStrArray(vch.begin(), vch.end(), lineLength); -} - - -// Sign CAlert with alert private key -bool SignAlert(CAlert &alert) -{ - // serialize alert data - CDataStream sMsg(SER_NETWORK, PROTOCOL_VERSION); - sMsg << *(CUnsignedAlert*)&alert; - alert.vchMsg = std::vector(sMsg.begin(), sMsg.end()); - - // sign alert - std::vector vchTmp(ParseHex(pszPrivKey)); - CPrivKey vchPrivKey(vchTmp.begin(), vchTmp.end()); - CKey key; - if (!key.SetPrivKey(vchPrivKey, false)) - { - printf("key.SetPrivKey failed\n"); - return false; - } - if (!key.Sign(Hash(alert.vchMsg.begin(), alert.vchMsg.end()), alert.vchSig)) - { - printf("SignAlert() : key.Sign failed\n"); - return false; - } - return true; -} - -// Sign a CAlert and serialize it -bool SignAndSerialize(CAlert &alert, CDataStream &buffer) -{ - // Sign - if(!SignAlert(alert)) - { - printf("SignAndSerialize() : could not sign alert\n"); - return false; - } - // ...and save! - buffer << alert; - return true; -} - -void GenerateAlertTests() -{ - CDataStream sBuffer(SER_DISK, CLIENT_VERSION); - - CAlert alert; - alert.nRelayUntil = 60; - alert.nExpiration = 24 * 60 * 60; - alert.nID = 1; - alert.nCancel = 0; // cancels previous messages up to this ID number - alert.nMinVer = 0; // These versions are protocol versions - alert.nMaxVer = 999001; - alert.nPriority = 1; - alert.strComment = "Alert comment"; - alert.strStatusBar = "Alert 1"; - - // Replace SignAndSave with SignAndSerialize - SignAndSerialize(alert, sBuffer); - - // More tests go here ... - alert.setSubVer.insert(std::string("/MagicBean:0.1.0/")); - alert.strStatusBar = "Alert 1 for MagicBean 0.1.0"; - SignAndSerialize(alert, sBuffer); - - alert.setSubVer.insert(std::string("/MagicBean:0.2.0/")); - alert.strStatusBar = "Alert 1 for MagicBean 0.1.0, 0.2.0"; - SignAndSerialize(alert, sBuffer); - - alert.setSubVer.clear(); - ++alert.nID; - alert.nCancel = 1; - alert.nPriority = 100; - alert.strStatusBar = "Alert 2, cancels 1"; - SignAndSerialize(alert, sBuffer); - - alert.nExpiration += 60; - ++alert.nID; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nPriority = 5000; - alert.strStatusBar = "Alert 3, disables RPC"; - alert.strRPCError = "RPC disabled"; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nPriority = 5000; - alert.strStatusBar = "Alert 4, re-enables RPC"; - alert.strRPCError = ""; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nMinVer = 11; - alert.nMaxVer = 22; - alert.nPriority = 100; - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.strStatusBar = "Alert 2 for MagicBean 0.1.0"; - alert.setSubVer.insert(std::string("/MagicBean:0.1.0/")); - SignAndSerialize(alert, sBuffer); - - ++alert.nID; - alert.nMinVer = 0; - alert.nMaxVer = 999999; - alert.strStatusBar = "Evil Alert'; /bin/ls; echo '"; - alert.setSubVer.clear(); - bool b = SignAndSerialize(alert, sBuffer); - - if (b) { - // Print the hex array, which will become the contents of alertTest.raw.h - std::vector vch = std::vector(sBuffer.begin(), sBuffer.end()); - printf("%s\n", HexStrArray(vch, 8).c_str()); - - // Write the data to alertTests.raw.NEW, to be copied to src/test/data/alertTests.raw - std::ofstream outfile("alertTests.raw.NEW", std::ios::out | std::ios::binary); - outfile.write((const char*)&vch[0], vch.size()); - outfile.close(); - } -} - - - -struct GenerateAlertTestsFixture : public TestingSetup { - GenerateAlertTestsFixture() {} - ~GenerateAlertTestsFixture() {} -}; - -BOOST_FIXTURE_TEST_SUITE(Generate_Alert_Test_Data, GenerateAlertTestsFixture); -BOOST_AUTO_TEST_CASE(GenerateTheAlertTests) -{ - GenerateAlertTests(); -} -BOOST_AUTO_TEST_SUITE_END() - - -#else - - -struct ReadAlerts : public TestingSetup -{ - ReadAlerts() - { - std::vector vch(alert_tests::alertTests, alert_tests::alertTests + sizeof(alert_tests::alertTests)); - CDataStream stream(vch, SER_DISK, CLIENT_VERSION); - try { - while (!stream.eof()) - { - CAlert alert; - stream >> alert; - alerts.push_back(alert); - } - } - catch (const std::exception&) { } - } - ~ReadAlerts() { } - - static std::vector read_lines(boost::filesystem::path filepath) - { - std::vector result; - - std::ifstream f(filepath.string().c_str()); - std::string line; - while (std::getline(f,line)) - result.push_back(line); - - return result; - } - - std::vector alerts; -}; - -BOOST_FIXTURE_TEST_SUITE(Alert_tests, ReadAlerts) - - -BOOST_AUTO_TEST_CASE(AlertApplies) -{ - SetMockTime(11); - const std::vector& alertKey = Params(CBaseChainParams::MAIN).AlertKey(); - - BOOST_FOREACH(const CAlert& alert, alerts) - { - BOOST_CHECK(alert.CheckSignature(alertKey)); - } - - BOOST_CHECK(alerts.size() >= 3); - - // Matches: - BOOST_CHECK(alerts[0].AppliesTo(1, "")); - BOOST_CHECK(alerts[0].AppliesTo(999001, "")); - BOOST_CHECK(alerts[0].AppliesTo(1, "/MagicBean:11.11.11/")); - - BOOST_CHECK(alerts[1].AppliesTo(1, "/MagicBean:0.1.0/")); - BOOST_CHECK(alerts[1].AppliesTo(999001, "/MagicBean:0.1.0/")); - - BOOST_CHECK(alerts[2].AppliesTo(1, "/MagicBean:0.1.0/")); - BOOST_CHECK(alerts[2].AppliesTo(1, "/MagicBean:0.2.0/")); - - // Don't match: - BOOST_CHECK(!alerts[0].AppliesTo(-1, "")); - BOOST_CHECK(!alerts[0].AppliesTo(999002, "")); - - BOOST_CHECK(!alerts[1].AppliesTo(1, "")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "MagicBean:0.1.0")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "/MagicBean:0.1.0")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "MagicBean:0.1.0/")); - BOOST_CHECK(!alerts[1].AppliesTo(-1, "/MagicBean:0.1.0/")); - BOOST_CHECK(!alerts[1].AppliesTo(999002, "/MagicBean:0.1.0/")); - BOOST_CHECK(!alerts[1].AppliesTo(1, "/MagicBean:0.2.0/")); - - BOOST_CHECK(!alerts[2].AppliesTo(1, "/MagicBean:0.3.0/")); - - SetMockTime(0); -} - - -BOOST_AUTO_TEST_CASE(AlertNotify) -{ - SetMockTime(11); - const std::vector& alertKey = Params(CBaseChainParams::MAIN).AlertKey(); - - boost::filesystem::path temp = GetTempPath() / - boost::filesystem::unique_path("alertnotify-%%%%.txt"); - - mapArgs["-alertnotify"] = std::string("echo %s >> ") + temp.string(); - - BOOST_FOREACH(CAlert alert, alerts) - alert.ProcessAlert(alertKey, false); - - std::vector r = read_lines(temp); - BOOST_CHECK_EQUAL(r.size(), 6u); - -// Windows built-in echo semantics are different than posixy shells. Quotes and -// whitespace are printed literally. - -#ifndef _WIN32 - BOOST_CHECK_EQUAL(r[0], "Alert 1"); - BOOST_CHECK_EQUAL(r[1], "Alert 2, cancels 1"); - BOOST_CHECK_EQUAL(r[2], "Alert 2, cancels 1"); - BOOST_CHECK_EQUAL(r[3], "Alert 3, disables RPC"); - BOOST_CHECK_EQUAL(r[4], "Alert 4, reenables RPC"); // dashes should be removed - BOOST_CHECK_EQUAL(r[5], "Evil Alert; /bin/ls; echo "); // single-quotes should be removed -#else - BOOST_CHECK_EQUAL(r[0], "'Alert 1' "); - BOOST_CHECK_EQUAL(r[1], "'Alert 2, cancels 1' "); - BOOST_CHECK_EQUAL(r[2], "'Alert 2, cancels 1' "); - BOOST_CHECK_EQUAL(r[3], "'Alert 3, disables RPC' "); - BOOST_CHECK_EQUAL(r[4], "'Alert 4, reenables RPC' "); // dashes should be removed - BOOST_CHECK_EQUAL(r[5], "'Evil Alert; /bin/ls; echo ' "); -#endif - boost::filesystem::remove(temp); - - SetMockTime(0); - mapAlerts.clear(); -} - -BOOST_AUTO_TEST_CASE(AlertDisablesRPC) -{ - SetMockTime(11); - const std::vector& alertKey = Params(CBaseChainParams::MAIN).AlertKey(); - - // Command should work before alerts - BOOST_CHECK_EQUAL(GetWarnings("rpc"), ""); - - // First alert should disable RPC - alerts[5].ProcessAlert(alertKey, false); - BOOST_CHECK_EQUAL(alerts[5].strRPCError, "RPC disabled"); - BOOST_CHECK_EQUAL(GetWarnings("rpc"), "RPC disabled"); - - // Second alert should re-enable RPC - alerts[6].ProcessAlert(alertKey, false); - BOOST_CHECK_EQUAL(alerts[6].strRPCError, ""); - BOOST_CHECK_EQUAL(GetWarnings("rpc"), ""); - - SetMockTime(0); - mapAlerts.clear(); -} - -static bool falseFunc() { return false; } - -BOOST_AUTO_TEST_CASE(PartitionAlert) -{ - // Test PartitionCheck - CCriticalSection csDummy; - CBlockIndex indexDummy[400]; - CChainParams& params = Params(CBaseChainParams::MAIN); - int64_t nPowTargetSpacing = params.GetConsensus().nPowTargetSpacing; - - // Generate fake blockchain timestamps relative to - // an arbitrary time: - int64_t now = 1427379054; - SetMockTime(now); - for (int i = 0; i < 400; i++) - { - indexDummy[i].phashBlock = NULL; - if (i == 0) indexDummy[i].pprev = NULL; - else indexDummy[i].pprev = &indexDummy[i-1]; - indexDummy[i].nHeight = i; - indexDummy[i].nTime = now - (400-i)*nPowTargetSpacing; - // Other members don't matter, the partition check code doesn't - // use them - } - - // Test 1: chain with blocks every nPowTargetSpacing seconds, - // as normal, no worries: - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(strMiscWarning.empty()); - - // Test 2: go 3.5 hours without a block, expect a warning: - now += 3*60*60+30*60; - SetMockTime(now); - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(!strMiscWarning.empty()); - BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); - strMiscWarning = ""; - - // Test 3: test the "partition alerts only go off once per day" - // code: - now += 60*10; - SetMockTime(now); - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(strMiscWarning.empty()); - - // Test 4: get 2.5 times as many blocks as expected: - now += 60*60*24; // Pretend it is a day later - SetMockTime(now); - int64_t quickSpacing = nPowTargetSpacing*2/5; - for (int i = 0; i < 400; i++) // Tweak chain timestamps: - indexDummy[i].nTime = now - (400-i)*quickSpacing; - PartitionCheck(falseFunc, csDummy, &indexDummy[399], nPowTargetSpacing); - BOOST_CHECK(!strMiscWarning.empty()); - BOOST_TEST_MESSAGE(std::string("Got alert text: ")+strMiscWarning); - strMiscWarning = ""; - - SetMockTime(0); -} - -BOOST_AUTO_TEST_SUITE_END() - -#endif From 1cdb961ba26865efb46b30eb1daa61327d7cea28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 02:51:42 -1100 Subject: [PATCH 0374/1123] Fix PoW mining in mixed PoS/PoW, fix orphaned stake tx --- src/chain.h | 26 ++++++++++++++++++++++++++ src/komodo_bitcoind.h | 15 +++++++++------ src/main.cpp | 28 ++++++++++++++++++++++------ src/miner.cpp | 4 ++-- src/validationinterface.cpp | 4 ++++ src/validationinterface.h | 1 + src/wallet/wallet.cpp | 12 ++++++++++++ src/wallet/wallet.h | 1 + 8 files changed, 77 insertions(+), 14 deletions(-) diff --git a/src/chain.h b/src/chain.h index a28e4e44a..e2b03c4df 100644 --- a/src/chain.h +++ b/src/chain.h @@ -16,6 +16,7 @@ #include +uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr); static const int SPROUT_VALUE_VERSION = 1001400; struct CDiskBlockPos @@ -321,6 +322,31 @@ public: //! Efficiently find an ancestor of this block. CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; + + bool IsPOSBlock() const + { + if ( ASSETCHAINS_STAKED != 0 ) + { + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + const CBlockIndex *pindex = this; + if ( (n= pindex->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + { + txid = pblock->vtx[n-1].vin[0].prevout.hash; + vout = pblock->vtx[n-1].vin[0].prevout.n; + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pindex->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pindex->vtx[n-1].vout[0].nValue == value ) + { + fprintf(stderr,"is PoS block!\n"); + return(true); + } + } + } + } + return(false); + } }; /** Used to marshal pointers into hashes for db storage. */ diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1c0a6414d..2c27589cc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1328,7 +1328,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget) { - CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible,isPoS = 0; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,txn_count,eligible=0,isPoS = 0; uint64_t value; CTxDestination voutaddress; if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) return(1); txn_count = pblock->vtx.size(); @@ -1343,7 +1343,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ vout = pblock->vtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) { - eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); + if ( pblock->IsPOSBlock() != 0 ) + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); @@ -1351,14 +1352,16 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { - txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( pblock->IsPOSBlock() != 0 ) + isPoS = 1; + /*txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) { strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[txn_count-1].vout[0].nValue == value ) isPoS = 1; // close enough for a pre-filter //else fprintf(stderr,"komodo_is_PoSblock ht.%d (%s) != (%s) or %.8f != %.8f\n",height,destaddr,voutaddr,dstr(value),dstr(pblock->vtx[txn_count-1].vout[0].nValue)); - } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height); + } else fprintf(stderr,"komodo_is_PoSblock ht.%d couldnt extract voutaddress\n",height);*/ } //else return(-1); } //fprintf(stderr,"slow.%d ht.%d isPoS.%d\n",slowflag,height,isPoS); @@ -1443,10 +1446,10 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); else { + if ( slowflag == 0 ) // need all past 100 blocks to calculate PoW target + return(0); if ( slowflag != 0 ) bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - else if ( height > 100 ) - bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); // lower bound if ( bhash > bnTarget ) { for (i=31; i>=16; i--) diff --git a/src/main.cpp b/src/main.cpp index d4dfae7ae..bd6aef8ce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3252,13 +3252,17 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { if (!FlushStateToDisk(state, FLUSH_STATE_IF_NEEDED)) return false; - if (!fBare) { + if (!fBare) + { // Resurrect mempool transactions from the disconnected block. - BOOST_FOREACH(const CTransaction &tx, block.vtx) { + //BOOST_FOREACH(const CTransaction &tx, block.vtx) { + for (int i = 0; i < block.vtx.size(); i++) + { + CTransaction &tx = block.vtx[i]; // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3275,11 +3279,23 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { assert(pcoinsTip->GetAnchorAt(pcoinsTip->GetBestAnchor(), newTree)); // Let wallets know transactions went from 1-confirmed to // 0-confirmed or conflicted: - BOOST_FOREACH(const CTransaction &tx, block.vtx) { - SyncWithWallets(tx, NULL); - } + //BOOST_FOREACH(const CTransaction &tx, block.vtx) { + // SyncWithWallets(tx, NULL); + //} // Update cached incremental witnesses //fprintf(stderr,"chaintip false\n"); + for (int i = 0; i < block.vtx.size(); i++) + { + CTransaction &tx = block.vtx[i]; + if (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) + { + EraseFromWallets(tx.GetHash()); + } + else + { + SyncWithWallets(tx, NULL); + } + } GetMainSignals().ChainTip(pindexDelete, &block, newTree, false); return true; } diff --git a/src/miner.cpp b/src/miner.cpp index 8824959e1..c837268f9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -939,7 +939,7 @@ void static BitcoinMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - for (z=31; z>=16; z--) + /*for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," mined "); for (z=31; z>=16; z--) @@ -947,7 +947,7 @@ void static BitcoinMiner() fprintf(stderr," hashTarget "); for (z=31; z>=16; z--) fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); - fprintf(stderr," POW\n"); + fprintf(stderr," POW\n");*/ if ( h > hashTarget ) return false; if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index cd3e30f3d..a8e15db99 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -51,3 +51,7 @@ void UnregisterAllValidationInterfaces() { void SyncWithWallets(const CTransaction &tx, const CBlock *pblock) { g_signals.SyncTransaction(tx, pblock); } + +void EraseFromWallets(const uint256 &hash) { + g_signals.EraseTransaction(hash); +} diff --git a/src/validationinterface.h b/src/validationinterface.h index 1855dacd7..a1f111753 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -28,6 +28,7 @@ void UnregisterValidationInterface(CValidationInterface* pwalletIn); void UnregisterAllValidationInterfaces(); /** Push an updated transaction to all registered wallets */ void SyncWithWallets(const CTransaction& tx, const CBlock* pblock = NULL); +void EraseFromWallets(const uint256 &hash); class CValidationInterface { protected: diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 10bf93598..1cf52d1b4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1358,6 +1358,18 @@ bool CWallet::IsFromMe(const uint256& nullifier) const return false; } +void CWallet::EraseFromWallet(const uint256 &hash) +{ + if (!fFileBacked) + return; + { + LOCK(cs_wallet); + if (mapWallet.erase(hash)) + CWalletDB(strWalletFile).EraseTx(hash); + } + return; +} + void CWallet::GetNoteWitnesses(std::vector notes, std::vector>& witnesses, uint256 &final_anchor) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f77a55a04..f6c8563ef 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -995,6 +995,7 @@ public: bool UpdateNullifierNoteMap(); void UpdateNullifierNoteMapWithTx(const CWalletTx& wtx); bool AddToWallet(const CWalletTx& wtxIn, bool fFromLoadWallet, CWalletDB* pwalletdb); + void EraseFromWallet(const uint256 &hash); void SyncTransaction(const CTransaction& tx, const CBlock* pblock); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); void EraseFromWallet(const uint256 &hash); From d1db09204a50e47ea882160c8bf1634a8900d42a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 02:58:41 -1100 Subject: [PATCH 0375/1123] Syntax --- src/chain.h | 25 ------------------------- src/komodo_bitcoind.h | 32 ++++++++++++++++++++++++++++---- src/main.cpp | 4 ++-- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/chain.h b/src/chain.h index e2b03c4df..41cf28652 100644 --- a/src/chain.h +++ b/src/chain.h @@ -16,7 +16,6 @@ #include -uint32_t komodo_txtime(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr); static const int SPROUT_VALUE_VERSION = 1001400; struct CDiskBlockPos @@ -323,30 +322,6 @@ public: CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; - bool IsPOSBlock() const - { - if ( ASSETCHAINS_STAKED != 0 ) - { - int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; - const CBlockIndex *pindex = this; - if ( (n= pindex->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) - { - txid = pblock->vtx[n-1].vin[0].prevout.hash; - vout = pblock->vtx[n-1].vin[0].prevout.n; - txtime = komodo_txtime(&value,txid,vout,destaddr); - if ( ExtractDestination(pindex->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) - { - strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); - if ( strcmp(destaddr,voutaddr) == 0 && pindex->vtx[n-1].vout[0].nValue == value ) - { - fprintf(stderr,"is PoS block!\n"); - return(true); - } - } - } - } - return(false); - } }; /** Used to marshal pointers into hashes for db storage. */ diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2c27589cc..ab7bad30f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -606,6 +606,30 @@ uint32_t komodo_txtime2(uint64_t *valuep,uint256 hash,int32_t n,char *destaddr) return(txtime); } +int32_t komodo_isPoS(CBlock *pblock) +{ + int32_t n,vout; uint32_t txtime; uint64_t value; char voutaddr[64],destaddr[64]; CTxDestination voutaddress; uint256 txid; + if ( ASSETCHAINS_STAKED != 0 ) + { + if ( (n= pblock->vtx.size()) > 1 && pblock->vtx[n-1].vin.size() == 1 && pblock->vtx[n-1].vout.size() == 1 ) + { + txid = pblock->vtx[n-1].vin[0].prevout.hash; + vout = pblock->vtx[n-1].vin[0].prevout.n; + txtime = komodo_txtime(&value,txid,vout,destaddr); + if ( ExtractDestination(pblock->vtx[n-1].vout[0].scriptPubKey,voutaddress) ) + { + strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); + if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) + { + fprintf(stderr,"is PoS block!\n"); + return(1); + } + } + } + } + return(0); +} + void komodo_disconnect(CBlockIndex *pindex,CBlock& block) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; @@ -1151,13 +1175,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; ivtx[txn_count-1].vin[0].prevout.n; if ( prevtime != 0 ) { - if ( pblock->IsPOSBlock() != 0 ) + if ( komodo_isPoS(pblock) != 0 ) eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { @@ -1352,7 +1376,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx { - if ( pblock->IsPOSBlock() != 0 ) + if ( komodo_isPoS(pblock) != 0 ) isPoS = 1; /*txtime = komodo_txtime(&value,txid,vout,destaddr); if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) diff --git a/src/main.cpp b/src/main.cpp index bd6aef8ce..ea18662aa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3262,7 +3262,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3287,7 +3287,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - if (block.IsPOSBlock() && (i == (block.vtx.size() - 1))) + if (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) { EraseFromWallets(tx.GetHash()); } From 72953c8342459633b16e6a8f33523a0ba7099f83 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:00:38 -1100 Subject: [PATCH 0376/1123] Syntax --- src/wallet/wallet.cpp | 12 ------------ src/wallet/wallet.h | 1 - 2 files changed, 13 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1cf52d1b4..10bf93598 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1358,18 +1358,6 @@ bool CWallet::IsFromMe(const uint256& nullifier) const return false; } -void CWallet::EraseFromWallet(const uint256 &hash) -{ - if (!fFileBacked) - return; - { - LOCK(cs_wallet); - if (mapWallet.erase(hash)) - CWalletDB(strWalletFile).EraseTx(hash); - } - return; -} - void CWallet::GetNoteWitnesses(std::vector notes, std::vector>& witnesses, uint256 &final_anchor) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f6c8563ef..0c6a90840 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -998,7 +998,6 @@ public: void EraseFromWallet(const uint256 &hash); void SyncTransaction(const CTransaction& tx, const CBlock* pblock); bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pblock, bool fUpdate); - void EraseFromWallet(const uint256 &hash); void WitnessNoteCommitment( std::vector commitments, std::vector>& witnesses, From 333cf46c477808757d82ddd319b9730faf649d6a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:16:21 -1100 Subject: [PATCH 0377/1123] Accept duplicate height 1 --- src/main.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ea18662aa..7529a9d98 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3262,7 +3262,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { // ignore validation errors in resurrected transactions list removed; CValidationState stateDummy; - if (tx.IsCoinBase() || (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) + if (tx.IsCoinBase() || ((i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0) || !AcceptToMemoryPool(mempool, stateDummy, tx, false, NULL)) mempool.remove(tx, removed, true); } if (anchorBeforeDisconnect != anchorAfterDisconnect) { @@ -3287,7 +3287,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { for (int i = 0; i < block.vtx.size(); i++) { CTransaction &tx = block.vtx[i]; - if (komodo_isPoS((CBlock *)&block) != 0 && (i == (block.vtx.size() - 1))) + if ( (i == (block.vtx.size() - 1)) && komodo_isPoS((CBlock *)&block) != 0 ) { EraseFromWallets(tx.GetHash()); } @@ -4094,7 +4094,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) + { + CBlockIndex *heightblock = chainActive[nHeight]; + if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) + return true; return(false); + } if ( nHeight != 0 ) { if ( pcheckpoint != 0 && nHeight < pcheckpoint->nHeight ) From 42bbeb4f4db3b9850f93ced9b6edc52d763e75ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:21:28 -1100 Subject: [PATCH 0378/1123] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7529a9d98..5f51a47c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4098,7 +4098,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) return true; - return(false); + return state.DoS(1, error("%s: trying to change height 1 forbidden", __func__)); } if ( nHeight != 0 ) { From 8808427254f402bcba651ae3838437bdd23470a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:26:47 -1100 Subject: [PATCH 0379/1123] -print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ab7bad30f..366011db6 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -621,7 +621,7 @@ int32_t komodo_isPoS(CBlock *pblock) strcpy(voutaddr,CBitcoinAddress(voutaddress).ToString().c_str()); if ( strcmp(destaddr,voutaddr) == 0 && pblock->vtx[n-1].vout[0].nValue == value ) { - fprintf(stderr,"is PoS block!\n"); + //fprintf(stderr,"is PoS block!\n"); return(1); } } @@ -1181,7 +1181,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) { memcpy(prevhashbuf,hashbuf,100); prevheight = height; - fprintf(stderr,"segids.%d\n",height); + fprintf(stderr,"prevsegids.%d\n",height+n); } } } From 6789cd6db6fcdbbc7a6d483e7ebfe64d33e4b191 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 03:28:12 -1100 Subject: [PATCH 0380/1123] -print --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 366011db6..25bd2b831 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1175,13 +1175,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From ce2b6b330c64fecb79bef0c9608c8c8b3e3690e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 07:41:16 -1100 Subject: [PATCH 0381/1123] Steepen PoW diff easement --- src/komodo_bitcoind.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 25bd2b831..ddfe7c6eb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1332,7 +1332,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { - bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + //bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + bnTarget = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); + if ( bnTarget > easydiff ) + bnTarget = easydiff; if ( 1 ) { for (i=31; i>=24; i--) From 43ff67f5fceadd67d277ce2d028d00f65fd5097d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 08:57:03 -1100 Subject: [PATCH 0382/1123] Handle 100% PoS for -ac_target = < 100 --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ddfe7c6eb..e9bcb0389 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1313,7 +1313,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he ave = (sum / arith_uint256(n)); if ( ave > target ) ave = target; - } else return(target); + } else ave = easydiff; //else return(target); if ( percPoS < goalperc ) // increase PoW diff -> lower bnTarget { bnTarget = (ave * arith_uint256(percPoS * percPoS)) / arith_uint256(goalperc * goalperc * goalperc); From 4cc33bf81ee66f3e864b53c170663c440b44e80c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:10:51 -1100 Subject: [PATCH 0383/1123] Test --- src/komodo_bitcoind.h | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9bcb0389..58b037a62 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,19 +1267,37 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val; + CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val; *percPoSp = percPoS = 0; if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); sum = arith_uint256(0); ave = sum; easydiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - for (i=n=0; i<100; i++) + for (i=n=m=0; i<100; i++) { ht = height - 100 + i; if ( ht <= 1 ) continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) + { + if ( komodo_segid(ht) >= 0 ) + { + n++; + percPoS++; + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"0"); + } + else + { + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"1"); + sum += hashval; + m++; + n++; + } + } + /*if ( (pindex= komodo_chainactive(ht)) != 0 ) { bnTarget.SetCompact(pindex->nBits,&fNegative,&fOverflow); bnTarget = (bnTarget / arith_uint256(KOMODO_POWMINMULT)); @@ -1298,9 +1316,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"0"); } - if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) - fprintf(stderr," %d, ",percPoS); - } + }*/ + if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) + fprintf(stderr," %d, ",percPoS); } if ( n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; @@ -1308,9 +1326,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; target = (target / arith_uint256(KOMODO_POWMINMULT)); - if ( n > 0 ) + if ( m > 0 ) { - ave = (sum / arith_uint256(n)); + ave = (sum / arith_uint256(m)); if ( ave > target ) ave = target; } else ave = easydiff; //else return(target); From 153a7898146c872ac4647b4f68184670bf0d662c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:12:39 -1100 Subject: [PATCH 0384/1123] Neutral diff for PoW --- src/komodo_bitcoind.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 58b037a62..3eff2a882 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1104,9 +1104,8 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ commission must be in coinbase.vout[1] and must be >= 10000 sats PoS stake must be without txfee and in the last tx in the block at vout[0] - PoW mining on PoS chain must solve a harder diff that adjusts, but never less than KOMODO_POWMINMULT */ -#define KOMODO_POWMINMULT 16 +//#define KOMODO_POWMINMULT 16 uint64_t komodo_commission(const CBlock *pblock) { @@ -1325,7 +1324,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; - target = (target / arith_uint256(KOMODO_POWMINMULT)); + //target = (target / arith_uint256(KOMODO_POWMINMULT)); if ( m > 0 ) { ave = (sum / arith_uint256(m)); From 9e1a6d76c4e0b72d1d0ffabb1888932ca08d50f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 09:45:35 -1100 Subject: [PATCH 0385/1123] Fix null hashval --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 3eff2a882..f405f2571 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1291,7 +1291,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr,"1"); - sum += hashval; + sum += UintToArith256(pindex->GetBlockHash()); m++; n++; } From ae2d90651b0651ac548bba99a934d91032b4e790 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 10:09:58 -1100 Subject: [PATCH 0386/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f405f2571..afd1fe46e 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1351,7 +1351,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he { //bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); bnTarget = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); - if ( bnTarget > easydiff ) + if ( bnTarget > easydiff || bnTarget < ave ) bnTarget = easydiff; if ( 1 ) { From ae67e0923cf3dc1ba3850b0999fea0700f6f0c65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 10:58:42 -1100 Subject: [PATCH 0387/1123] Fix PoS estimator for first 100 blocks --- src/komodo_bitcoind.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index afd1fe46e..6656b8e25 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1293,7 +1293,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr,"1"); sum += UintToArith256(pindex->GetBlockHash()); m++; - n++; } } /*if ( (pindex= komodo_chainactive(ht)) != 0 ) From b6c80e46e31b3833d589a9699d91ff833ab89846 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 11:06:05 -1100 Subject: [PATCH 0388/1123] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6656b8e25..c48413575 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1348,10 +1348,11 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he } else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget { - //bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); bnTarget = (ave * arith_uint256(percPoS * percPoS * percPoS)) / arith_uint256(goalperc * goalperc); - if ( bnTarget > easydiff || bnTarget < ave ) + if ( bnTarget > easydiff ) bnTarget = easydiff; + else if ( bnTarget < ave ) // overflow + bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); if ( 1 ) { for (i=31; i>=24; i--) From 0fa08b81c9ce0b4df8feadcaba2581ed78ec29b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 11:41:39 -1100 Subject: [PATCH 0389/1123] Fix PoSperc count --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c48413575..7a50f3ce2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1318,7 +1318,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } - if ( n < 100 ) + if ( m+n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; if ( ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); From 8ba2ae9e592d6b078b4a700b409f5a9cae07d503 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 12:46:10 -1100 Subject: [PATCH 0390/1123] One more underflow check --- src/komodo_bitcoind.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7a50f3ce2..785cfe6cf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1352,7 +1352,11 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( bnTarget > easydiff ) bnTarget = easydiff; else if ( bnTarget < ave ) // overflow + { bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc); + if ( bnTarget < ave ) + bnTarget = ave; + } if ( 1 ) { for (i=31; i>=24; i--) From 6d2fc2903ee81ecbec27b83490a0044e13064c95 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:19:45 -1100 Subject: [PATCH 0391/1123] -stopat= --- src/komodo_globals.h | 2 +- src/komodo_utils.h | 1 + src/main.cpp | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index c46486430..8dfc7108c 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -52,7 +52,7 @@ uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; +uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index f61fd05ea..8188a6154 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1539,6 +1539,7 @@ void komodo_args(char *argv0) } } } + KOMODO_STOPAT = GetArg("-stopat",0); ASSETCHAINS_CC = GetArg("-ac_cc",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); ASSETCHAINS_PRIVATE = GetArg("-ac_private",0); diff --git a/src/main.cpp b/src/main.cpp index 5f51a47c4..cfc97db81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2691,7 +2691,8 @@ static int64_t nTimeTotal = 0; bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { const CChainParams& chainparams = Params(); - + if ( KOMODO_STOPAT != 0 && pindex->nHeight > KOMODO_STOPAT ) + return(false); //fprintf(stderr,"connectblock ht.%d\n",(int32_t)pindex->nHeight); AssertLockHeld(cs_main); bool fExpensiveChecks = true; From 7e282415b1b24c51f6bbc5b96b118139ce8b8e99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:57:20 -1100 Subject: [PATCH 0392/1123] Coin supply api --- src/chain.h | 2 +- src/komodo_bitcoind.h | 47 +++++++++++++++++++++++++++++++++++++++++++ src/rpcmisc.cpp | 18 +++++++++++++++++ src/rpcserver.h | 1 + 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 41cf28652..8c86a7ede 100644 --- a/src/chain.h +++ b/src/chain.h @@ -121,7 +121,7 @@ public: //! height of the entry in the chain. The genesis block has height 0 int nHeight; - + int64_t newcoins; //! Which # file this block is stored in (blk?????.dat) int nFile; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 785cfe6cf..7230757e5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,3 +1532,50 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } +int64_t komodo_newcoins(CBlockIndex *pindex) +{ + int32_t i,j,m,n,vout; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + n = pblock->vtx.size(); + for (i=0; ivtx[i]; + if ( (m= tx.vin.size()) > 0 ) + { + for (j=0; j= vintx.vout.size() ) + { + fprintf(stderr,"ERROR: %s/v%d cant find\n",txid.ToString().c_str(),vout); + return(0); + } + vinsum += vintx.vout[vout].nValue; + } + } + if ( (m= tx.vout.size()) > 0 ) + { + for (j=0; j %.8f\n",pindex->nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + return(voutsum - vinsum); +} + +int64_t komodo_coinsupply(int32_t height) +{ + CBlockIndex *pindex; int64_t supply = 0; + if ( (pindex= komodo_chainactive(height)) != 0 ) + { + if ( pindex->newcoins == 0 ) + pindex->newcoins = komodo_newcoins(pindex); + supply += pindex->newcoins; + } + return(supply); +} diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 065739a9a..b055e591a 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -53,6 +53,7 @@ extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); +int64_t komodo_coinsupply(int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; @@ -226,6 +227,23 @@ public: }; #endif +UniValue coinsupply(const UniValue& params, bool fHelp) +{ + int32_t height = 0; int64_t supply = 0; UniValue result(UniValue::VOBJ); + if (fHelp || params.size() > 1) + throw runtime_error("coinsupply \n"); + if ( params.size() == 0 ) + height = chainActive.Height(); + else height = atoi(params[0].get_str()); + if ( (supply= komodo_coinsupply(height)) > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("height", (int)height)); + result.push_back(Pair("supply", ValueFromAmount(supply))); + } else result.push_back(Pair("error", "couldnt calculate supply")); + return(result); +} + UniValue jumblr_deposit(const UniValue& params, bool fHelp) { int32_t retval; UniValue result(UniValue::VOBJ); diff --git a/src/rpcserver.h b/src/rpcserver.h index 5bb949299..586d79a88 100644 --- a/src/rpcserver.h +++ b/src/rpcserver.h @@ -207,6 +207,7 @@ extern UniValue getblocktemplate(const UniValue& params, bool fHelp); extern UniValue submitblock(const UniValue& params, bool fHelp); extern UniValue estimatefee(const UniValue& params, bool fHelp); extern UniValue estimatepriority(const UniValue& params, bool fHelp); +extern UniValue coinsupply(const UniValue& params, bool fHelp); extern UniValue getnewaddress(const UniValue& params, bool fHelp); // in rpcwallet.cpp //extern UniValue getnewaddress64(const UniValue& params, bool fHelp); // in rpcwallet.cpp From ab98eb8e6ab5ea2005dae06145a9998e40fa5a68 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 11 Jul 2018 23:59:32 -1100 Subject: [PATCH 0393/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7230757e5..9005d8c04 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1534,7 +1534,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) int64_t komodo_newcoins(CBlockIndex *pindex) { - int32_t i,j,m,n,vout; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; i Date: Thu, 12 Jul 2018 00:01:02 -1100 Subject: [PATCH 0394/1123] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9005d8c04..b50273c79 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1538,7 +1538,7 @@ int64_t komodo_newcoins(CBlockIndex *pindex) n = pblock->vtx.size(); for (i=0; ivtx[i]; + const CTransaction vintx,&tx = pindex->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; j Date: Thu, 12 Jul 2018 00:01:42 -1100 Subject: [PATCH 0395/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b50273c79..cb2a4af53 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1538,7 +1538,7 @@ int64_t komodo_newcoins(CBlockIndex *pindex) n = pblock->vtx.size(); for (i=0; ivtx[i]; + CTransaction vintx,&tx = pindex->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; j Date: Thu, 12 Jul 2018 00:04:45 -1100 Subject: [PATCH 0396/1123] Test --- src/komodo_bitcoind.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cb2a4af53..7d9fd5c3a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,13 +1532,13 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(CBlockIndex *pindex) +int64_t komodo_newcoins(CBlock *pblock) { int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; ivtx[i]; + CTransaction vintx,&tx = pblock->vtx[i]; if ( (m= tx.vin.size()) > 0 ) { for (j=0; jnewcoins == 0 ) - pindex->newcoins = komodo_newcoins(pindex); + { + if ( komodo_blockload(block,pindex) == 0 ) + pindex->newcoins = komodo_newcoins(&block); + else return(0); + } supply += pindex->newcoins; } return(supply); From 97a4e9238a097ae986508b7ee5b88d9c4b6675d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:06:47 -1100 Subject: [PATCH 0397/1123] Test --- src/komodo_bitcoind.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 7d9fd5c3a..e24883c08 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,7 +1532,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(CBlock *pblock) +int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) { int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; n = pblock->vtx.size(); @@ -1564,7 +1564,7 @@ int64_t komodo_newcoins(CBlock *pblock) voutsum += tx.vout[j].nValue; } } - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",pindex->nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); return(voutsum - vinsum); } @@ -1573,13 +1573,17 @@ int64_t komodo_coinsupply(int32_t height) CBlockIndex *pindex; CBlock block; int64_t supply = 0; if ( (pindex= komodo_chainactive(height)) != 0 ) { - if ( pindex->newcoins == 0 ) + while ( pindex != 0 && pindex->nHeight > 0 ) { - if ( komodo_blockload(block,pindex) == 0 ) - pindex->newcoins = komodo_newcoins(&block); - else return(0); + if ( pindex->newcoins == 0 ) + { + if ( komodo_blockload(block,pindex) == 0 ) + pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); + else return(0); + } + supply += pindex->newcoins; + pindex = pindex->pprev; } - supply += pindex->newcoins; } return(supply); } From 26204e59df5d16a22ac2b3b35b1a6ef516432f2c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:18:58 -1100 Subject: [PATCH 0398/1123] Add coinsupply rpc --- src/rpcserver.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index ed5110114..f37124d0c 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -280,6 +280,7 @@ static const CRPCCommand vRPCCommands[] = { "network", "clearbanned", &clearbanned, true }, /* Block chain and UTXO */ + { "blockchain", "coinsupply", &coinsupply, true }, { "blockchain", "getblockchaininfo", &getblockchaininfo, true }, { "blockchain", "getbestblockhash", &getbestblockhash, true }, { "blockchain", "getblockcount", &getblockcount, true }, From df74ee5fa0c5e28abccff98e19c9c89d980c31be Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:23:50 -1100 Subject: [PATCH 0399/1123] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e24883c08..1fd179ae9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1571,15 +1571,21 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) int64_t komodo_coinsupply(int32_t height) { CBlockIndex *pindex; CBlock block; int64_t supply = 0; + fprintf(stderr,"coinsupply %d\n",height); if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) { + printf("start ht.%d\n",pindex->nHeight); if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); - else return(0); + else + { + fprintf(stderr,"error loading block.%d\n",pindex->nHeight); + return(0); + } } supply += pindex->newcoins; pindex = pindex->pprev; From a46d6afb2b2670c2b7973db24787cb06a82ef53f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:28:15 -1100 Subject: [PATCH 0400/1123] Test --- src/chain.h | 1 + src/komodo_bitcoind.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chain.h b/src/chain.h index 8c86a7ede..5400abb00 100644 --- a/src/chain.h +++ b/src/chain.h @@ -181,6 +181,7 @@ public: void SetNull() { phashBlock = NULL; + newcoins = 0; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1fd179ae9..6c5f615f3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1576,7 +1576,6 @@ int64_t komodo_coinsupply(int32_t height) { while ( pindex != 0 && pindex->nHeight > 0 ) { - printf("start ht.%d\n",pindex->nHeight); if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) @@ -1588,6 +1587,7 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; + printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } From 67459d80b4680504c80a9dec77556c770c398714 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:39:04 -1100 Subject: [PATCH 0401/1123] Test --- src/komodo_bitcoind.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6c5f615f3..5140c0d27 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1564,6 +1564,7 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) voutsum += tx.vout[j].nValue; } } + if ( voutsum-vinsum > 100000*SATOSHIDEN || voutsum-vinsum < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); return(voutsum - vinsum); } @@ -1571,7 +1572,7 @@ int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) int64_t komodo_coinsupply(int32_t height) { CBlockIndex *pindex; CBlock block; int64_t supply = 0; - fprintf(stderr,"coinsupply %d\n",height); + //fprintf(stderr,"coinsupply %d\n",height); if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) @@ -1587,7 +1588,7 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; - printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); + //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } From 261895095501daf0acd7134471628456c50e8bc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:52:36 -1100 Subject: [PATCH 0402/1123] Test --- src/chain.h | 4 ++-- src/komodo_bitcoind.h | 17 +++++++++++------ src/rpcmisc.cpp | 8 +++++--- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/chain.h b/src/chain.h index 5400abb00..71d788531 100644 --- a/src/chain.h +++ b/src/chain.h @@ -121,7 +121,7 @@ public: //! height of the entry in the chain. The genesis block has height 0 int nHeight; - int64_t newcoins; + int64_t newcoins,zfunds; //! Which # file this block is stored in (blk?????.dat) int nFile; @@ -181,7 +181,7 @@ public: void SetNull() { phashBlock = NULL; - newcoins = 0; + newcoins = zfunds = 0; pprev = NULL; pskip = NULL; nHeight = 0; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 5140c0d27..e9bde8595 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1532,13 +1532,14 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) else return(0); } -int64_t komodo_newcoins(int32_t nHeight,CBlock *pblock) +int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { - int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t vinsum=0,voutsum=0; + int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; ivtx[i]; + zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; j 100000*SATOSHIDEN || voutsum-vinsum < 0 ) - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum)); + fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } -int64_t komodo_coinsupply(int32_t height) +int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) { - CBlockIndex *pindex; CBlock block; int64_t supply = 0; + CBlockIndex *pindex; CBlock block; int64_t zfunds=0,supply = 0; //fprintf(stderr,"coinsupply %d\n",height); + *zfundsp = 0; if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->nHeight > 0 ) @@ -1580,7 +1583,7 @@ int64_t komodo_coinsupply(int32_t height) if ( pindex->newcoins == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) - pindex->newcoins = komodo_newcoins(pindex->nHeight,&block); + pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block); else { fprintf(stderr,"error loading block.%d\n",pindex->nHeight); @@ -1588,9 +1591,11 @@ int64_t komodo_coinsupply(int32_t height) } } supply += pindex->newcoins; + zfunds += pindex->zfunds; //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); pindex = pindex->pprev; } } + *zfundsp = zfunds; return(supply); } diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index b055e591a..04376f4a5 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -53,7 +53,7 @@ extern uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE,KOMODO_LONGESTCHAIN; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); -int64_t komodo_coinsupply(int32_t height); +int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.1.1" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; @@ -229,17 +229,19 @@ public: UniValue coinsupply(const UniValue& params, bool fHelp) { - int32_t height = 0; int64_t supply = 0; UniValue result(UniValue::VOBJ); + int32_t height = 0; int64_t zfunds,supply = 0; UniValue result(UniValue::VOBJ); if (fHelp || params.size() > 1) throw runtime_error("coinsupply \n"); if ( params.size() == 0 ) height = chainActive.Height(); else height = atoi(params[0].get_str()); - if ( (supply= komodo_coinsupply(height)) > 0 ) + if ( (supply= komodo_coinsupply(&zfunds,height)) > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("height", (int)height)); result.push_back(Pair("supply", ValueFromAmount(supply))); + result.push_back(Pair("zfunds", ValueFromAmount(zfunds))); + result.push_back(Pair("total", ValueFromAmount(zfunds + supply))); } else result.push_back(Pair("error", "couldnt calculate supply")); return(result); } From ae4dbe22bbe32f6a8d1f71db7ac2efa47badec67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 00:58:25 -1100 Subject: [PATCH 0403/1123] tx.GetJoinSplitValueOut() --- src/komodo_bitcoind.h | 2 +- src/primitives/transaction.cpp | 17 ++++++++++++++++- src/primitives/transaction.h | 2 ++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e9bde8595..0293c0dd5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1539,7 +1539,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) for (i=0; ivtx[i]; - zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); + zfunds += (tx.GetJoinSplitValueIn() - tx.GetJoinSplitValueOut()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; jvpub_new; - + if (!MoneyRange(it->vpub_new) || !MoneyRange(nValue)) throw std::runtime_error("CTransaction::GetJoinSplitValueIn(): value out of range"); } + + return nValue; +} +CAmount CTransaction::GetJoinSplitValueOut() const +{ + CAmount nValue = 0; + for (std::vector::const_iterator it(vjoinsplit.begin()); it != vjoinsplit.end(); ++it) + { + // NB: vpub_new "gives" money to the value pool just as inputs do + nValue += it->vpub_old; + + if (!MoneyRange(it->vpub_old) || !MoneyRange(nValue)) + throw std::runtime_error("CTransaction::GetJoinSplitValueOut(): value out of range"); + } + return nValue; } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 88ee9a312..e3615c120 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -445,6 +445,8 @@ public: // Return sum of JoinSplit vpub_new CAmount GetJoinSplitValueIn() const; + // Return sum of JoinSplit vpub_old + CAmount GetJoinSplitValueOut() const; // Compute priority, given priority of inputs and (optionally) tx size double ComputePriority(double dPriorityInputs, unsigned int nTxSize=0) const; From 1ec2a42ff317ab4cbc81dafb49d6108a6ea6cc16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:01:45 -1100 Subject: [PATCH 0404/1123] Test --- src/komodo_bitcoind.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0293c0dd5..1ceeebd38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1566,7 +1566,12 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) } } *zfundsp = zfunds; - if ( voutsum-vinsum > 100000*SATOSHIDEN || voutsum-vinsum < 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) + { + fprintf(stderr,"ht.%d special case return 3\n",nHeight); + return(3 * SATOSHIDEN); + } + if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } From 3118a070000f4267ded1e5c70e3253f3a54c0551 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:16:41 -1100 Subject: [PATCH 0405/1123] Test --- src/komodo_bitcoind.h | 4 ++-- src/main.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1ceeebd38..1c0264a3a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1539,7 +1539,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) for (i=0; ivtx[i]; - zfunds += (tx.GetJoinSplitValueIn() - tx.GetJoinSplitValueOut()); + zfunds += (tx.GetJoinSplitValueOut() - tx.GetJoinSplitValueIn()); if ( (m= tx.vin.size()) > 0 ) { for (j=0; jnewcoins; zfunds += pindex->zfunds; - //printf("start ht.%d new %.8f -> supply %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply)); + //printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->nHeight,dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds)); pindex = pindex->pprev; } } diff --git a/src/main.cpp b/src/main.cpp index cfc97db81..b08d2e522 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1104,7 +1104,7 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio if ( ASSETCHAINS_PRIVATE != 0 ) { fprintf(stderr,"private chain nValue %.8f iscoinbase.%d\n",(double)txout.nValue/COIN,iscoinbase); - if ( txout.nValue > 0 && iscoinbase == 0 ) + if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } nValueOut += txout.nValue; From 7130a7cdc8572f8376bb147fb8f4ffbdfc8ff4fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:21:32 -1100 Subject: [PATCH 0406/1123] Test --- src/komodo_bitcoind.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1c0264a3a..f33fc2c01 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1566,11 +1566,8 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) } } *zfundsp = zfunds; - if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) - { - fprintf(stderr,"ht.%d special case return 3\n",nHeight); + if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) // 15 times return(3 * SATOSHIDEN); - } if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); @@ -1585,7 +1582,7 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) { while ( pindex != 0 && pindex->nHeight > 0 ) { - if ( pindex->newcoins == 0 ) + if ( pindex->newcoins == 0 && pindex->zfunds == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->nHeight,&block); From aa51eef61991942a6e7eed944d08b673e7c646d0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:37:55 -1100 Subject: [PATCH 0407/1123] coinsupply rpc call --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f33fc2c01..27f0a26a4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1568,8 +1568,8 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) *zfundsp = zfunds; if ( ASSETCHAINS_SYMBOL[0] == 0 && (voutsum-vinsum) == 100003*SATOSHIDEN ) // 15 times return(3 * SATOSHIDEN); - if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) - fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); + //if ( voutsum-vinsum+zfunds > 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) + //. fprintf(stderr,"ht.%d vins %.8f, vouts %.8f -> %.8f zfunds %.8f\n",nHeight,dstr(vinsum),dstr(voutsum),dstr(voutsum)-dstr(vinsum),dstr(zfunds)); return(voutsum - vinsum); } From 8aa6378bc9dde7c81c093e0cd898018bcfc27cfc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 01:46:32 -1100 Subject: [PATCH 0408/1123] Add symbol to coinsupply return --- src/rpcmisc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 04376f4a5..bf7f345d5 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -238,6 +238,7 @@ UniValue coinsupply(const UniValue& params, bool fHelp) if ( (supply= komodo_coinsupply(&zfunds,height)) > 0 ) { result.push_back(Pair("result", "success")); + result.push_back(Pair("coin", ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL)); result.push_back(Pair("height", (int)height)); result.push_back(Pair("supply", ValueFromAmount(supply))); result.push_back(Pair("zfunds", ValueFromAmount(zfunds))); From 40df8d84b1c06d9bf6ce1069724b8cda94fba94c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 03:52:54 -1100 Subject: [PATCH 0409/1123] Reduce staking CPU usage --- src/miner.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index c837268f9..7bd6777d4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -949,7 +949,11 @@ void static BitcoinMiner() fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); fprintf(stderr," POW\n");*/ if ( h > hashTarget ) + { + if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + sleep(1); return false; + } if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) { //fprintf(stderr,"need to wait %d seconds to submit block\n",(int32_t)(B.nTime - GetAdjustedTime())); From 0f7abeea0ea7af9a4a4204cf19a386039424164e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 04:08:51 -1100 Subject: [PATCH 0410/1123] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 7bd6777d4..bc5bbe1f7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -396,6 +396,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { uint64_t txfees,utxovalue; uint32_t txtime; uint256 utxotxid,revtxid; int32_t i,siglen,numsigs,utxovout; uint8_t utxosig[128],*ptr; CMutableTransaction txStaked = CreateNewContextualCMutableTransaction(Params().GetConsensus(), chainActive.Height() + 1); + sleep(1); if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; From 2b72340d10710d0f54c04fb463b289f74a3bf210 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 06:25:02 -1100 Subject: [PATCH 0411/1123] -print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1e330b20c..7199db0be 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4690,7 +4690,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt //fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep)); *blocktimep = earliest; } - } else fprintf(stderr,"no earliest utxo for staking\n"); + } //else fprintf(stderr,"no earliest utxo for staking\n"); return(siglen); } From 29bb0d039cd1d94d8f121f84177c4b3843cd9cb6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 08:23:58 -1100 Subject: [PATCH 0412/1123] Cap search to 2 minutes --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 27f0a26a4..cc60bc0e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1212,7 +1212,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); - for (iter=0; iter<3600; iter++) + for (iter=0; iter<120; iter++) { diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) From 8a7c025aaef77372b506d94007bd6873a807d43f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 08:39:33 -1100 Subject: [PATCH 0413/1123] De-clumpify at 900 --- src/komodo_bitcoind.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index cc60bc0e2..d09503751 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) 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) { - bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; + bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 && blocktime < GetAdjustedTime() ) blocktime = GetAdjustedTime(); @@ -1227,7 +1227,10 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; coinage = (value * diff); - hashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1)); + coinage256 = arith_uint256(coinage+1); + hashval = ratio * (UintToArith256(hash) / coinage256); + if ( nHeight >= 900 ) + hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { winner = 1; From 832ca82122ea5ce196d0bf8b6e0ac261bb8120f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 08:53:46 -1100 Subject: [PATCH 0414/1123] +print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7199db0be..334b1dfe3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From c3ed86ad18cd337cfb0155d049bc001acde4a466 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:01:48 -1100 Subject: [PATCH 0415/1123] Test --- src/komodo_bitcoind.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d09503751..734c57f73 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1189,10 +1189,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); - if ( validateflag == 0 && blocktime < GetAdjustedTime() ) - blocktime = GetAdjustedTime(); - if ( blocktime < prevtime+3 ) - blocktime = prevtime+3; + if ( validateflag == 0 ) + { + fprintf(stderr,"blocktime.%u -> ",blocktime); + if ( blocktime < GetAdjustedTime() ) + blocktime = GetAdjustedTime(); + if ( blocktime < prevtime+3 ) + blocktime = prevtime+3; + fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); @@ -1236,6 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } From e0a3ab0a32f12e972850b030e39e8d101a04f148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:24:58 -1100 Subject: [PATCH 0416/1123] Test --- src/komodo_bitcoind.h | 14 +++++++------- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 734c57f73..fa5266d38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - fprintf(stderr,"blocktime.%u -> ",blocktime); - if ( blocktime < GetAdjustedTime() ) - blocktime = GetAdjustedTime(); + //fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; - fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + if ( blocktime < GetAdjustedTime()-60 ) + blocktime = GetAdjustedTime()-60; + //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1217,7 +1217,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); - for (iter=0; iter<120; iter++) + for (iter=0; iter<180; iter++) { diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } @@ -1401,7 +1401,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( prevtime != 0 ) { if ( komodo_isPoS(pblock) != 0 ) - eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(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)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 334b1dfe3..400dc9088 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4640,10 +4640,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()); + eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { - if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) + if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } From 8785f8cee0a64b1e7849c454d787764632b2b4e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:26:41 -1100 Subject: [PATCH 0417/1123] Fix --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fa5266d38..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1195,7 +1195,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) - blocktime = GetAdjustedTime()-60; + blocktime = GetAdjustedTime()+30; //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) @@ -1234,7 +1234,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh coinage = (value * diff); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); - if ( nHeight >= 900 ) + if ( nHeight >= 900 && nHeight < 916 ) hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { From ed3d9247b42eb3797596457d1e6e3f51a1eb0e10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:28:34 -1100 Subject: [PATCH 0418/1123] New version --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index bc5bbe1f7..c6855cd57 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,7 +400,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-57 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); From 593d06a8c749d4a3aa11f76781b5f8c385726ec3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:29:20 -1100 Subject: [PATCH 0419/1123] -print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 400dc9088..85141aa6a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 668ff11a727af89f84dba5ffd22c5a0f471cc6b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:38:47 -1100 Subject: [PATCH 0420/1123] +print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 85141aa6a..400dc9088 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From c067f5148bc234ad863ccaa31f54994911f9c286 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:44:07 -1100 Subject: [PATCH 0421/1123] +print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..2916e4d56 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + //if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From e53395fccf810c66d567336fbe2fd1f09ae19d60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:50:00 -1100 Subject: [PATCH 0422/1123] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2916e4d56..1a9377e85 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,9 +1257,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } + 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 v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( 0 && validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From cb595b48018eaa00c18631a1afb3597bf74c0f3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:00:10 -1100 Subject: [PATCH 0423/1123] -print --- src/komodo_bitcoind.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a9377e85..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,12 +1257,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } - 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 v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); if ( 0 && validateflag != 0 ) From 2da6a5a5ad4d6813a9a7fed1b5416f29a475b11c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:05:05 -1100 Subject: [PATCH 0424/1123] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index c6855cd57..773762937 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,7 +400,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 )//&& GetAdjustedTime() < blocktime-157 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); From eedbc1907eb46c12bae422c53014fba2531b3c66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:09:48 -1100 Subject: [PATCH 0425/1123] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..4e09b3592 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - //fprintf(stderr,"blocktime.%u -> ",blocktime); + fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) blocktime = GetAdjustedTime()+30; - //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } From 0debf37ff7cb7a0294eecc1f324a83050521b130 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:14:15 -1100 Subject: [PATCH 0426/1123] Test --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4e09b3592..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - fprintf(stderr,"blocktime.%u -> ",blocktime); + //fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) blocktime = GetAdjustedTime()+30; - fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } diff --git a/src/miner.cpp b/src/miner.cpp index 773762937..ca04343e4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,8 +400,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 )//&& GetAdjustedTime() < blocktime-157 ) - return(0); + //if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + // return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); From cdb34664622baacc337fc8a5d413bf64939dc486 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:18:16 -1100 Subject: [PATCH 0427/1123] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index ca04343e4..2b37590e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -492,7 +492,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return(0); } } - else + else if ( ASSETCHAINS_STAKED == 0 ) { CValidationState state; if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) From afa90f17b126d345fdae07b56479de45dc374a4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:23:36 -1100 Subject: [PATCH 0428/1123] Detect new block while sleeping --- src/miner.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 2b37590e1..8a0c63f88 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -951,8 +951,8 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) { - if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) - sleep(1); + //if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + // sleep(1); return false; } if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) @@ -980,12 +980,11 @@ void static BitcoinMiner() else { while ( B.nTime-57 > GetAdjustedTime() ) - sleep(1); - /*if ( Mining_height < 6000 ) { - while ( B.nTime > GetAdjustedTime() ) - sleep(1); - }*/ + sleep(1); + if ( chainActive.Tip()->nHeight >= Mining_height ) + return(false); + } uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From b0910b9e2a17f93f908a47ac6170c46d49b3cb5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:33:01 -1100 Subject: [PATCH 0429/1123] +print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 400dc9088..4c3a66c2a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From b30fdbd2378bbee5bb5801f83e5fc45d37ef5fc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:48:32 -1100 Subject: [PATCH 0430/1123] +segids print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..8c4e2c537 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,13 +1174,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Thu, 12 Jul 2018 10:49:26 -1100 Subject: [PATCH 0431/1123] -prints --- src/komodo_bitcoind.h | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8c4e2c537..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,13 +1174,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; iGetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 308ee0761c265b2c1af855d67a85b4e9014cc2dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:52:38 -1100 Subject: [PATCH 0432/1123] Guard error print --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..0c714ba9c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1404,7 +1404,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(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)); + if ( ASSETCHAINS_STAKED < 100 ) + 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; } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx From 6d2faeb0b8ddcdf843198067740e8be7a7618e62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 11:13:32 -1100 Subject: [PATCH 0433/1123] +print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0c714ba9c..4b91f8230 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From d5614a7628dd72f744ed15cd878f2b32dea8ebeb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 11:43:32 -1100 Subject: [PATCH 0434/1123] Set nBits more often --- src/miner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 8a0c63f88..dbe6dc41c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -832,8 +832,9 @@ void static BitcoinMiner() // Search // uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); savebits = pblock->nBits; - HASHTarget = arith_uint256().SetCompact(pblock->nBits); + HASHTarget = arith_uint256().SetCompact(savebits); roundrobin_delay = ROUNDROBIN_DELAY; if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 ) { From 3dcc06d3acbd1cca46554f72589c15da41b49c26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 22:12:27 -1100 Subject: [PATCH 0435/1123] +print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4b91f8230..74b9786f3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( validateflag != 0 ) + //if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 5162b553a0e0f91d5a976d533b810e72855fd2ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 22:14:22 -1100 Subject: [PATCH 0436/1123] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 74b9786f3..0c714ba9c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 0401884fee36534c5508b794d89c559bfd0a66ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 04:45:32 -1100 Subject: [PATCH 0437/1123] Mitigation of very long block times, starting 2500 for PoW --- src/komodo_bitcoind.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0c714ba9c..da244e079 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1219,6 +1219,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); for (iter=0; iter<180; iter++) { + if ( blocktime+iter+segid*2 < txtime+minage ) + continue; diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) diff = 60; @@ -1229,9 +1231,9 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( iter > 0 ) diff += segid*2; - if ( blocktime+iter+segid*2 < txtime+minage ) - continue; coinage = (value * diff); + if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); if ( nHeight >= 900 && nHeight < 916 ) From 485df724b988548f9204f0f59ef5841c51f32496 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 23:12:59 -1100 Subject: [PATCH 0438/1123] Fix invalid tx in mempool for PoS --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index da244e079..42318252f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,11 +1076,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) + if ( txheight > 246748 ) { - if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) + if ( txheight < 247205 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From 82fd97935b50eead75971b2d32e1180710237b6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 23:15:43 -1100 Subject: [PATCH 0439/1123] Revert --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 42318252f..e584b2c93 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,11 +1076,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 ) + if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From b39b4d733efea2fb3140a737ec6f57ca86217043 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 00:11:29 -1100 Subject: [PATCH 0440/1123] ( --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e584b2c93..da244e079 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,7 +1076,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { From 3cbc956e040778621e9ebd563485ac71635d2cc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 03:08:05 -1100 Subject: [PATCH 0441/1123] Test fix for crash --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 10bf93598..df0cd9c2b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2112,7 +2112,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Don't rebroadcast if newer than nTime: if (wtx.nTimeReceived > nTime) continue; - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + //if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME ) { From 84eabd0d59a56b98e2bed897f8b8a6787750b386 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 05:43:18 -1100 Subject: [PATCH 0442/1123] Skip null privacy address --- src/komodo_bitcoind.h | 13 ++++++++++--- src/wallet/rpcwallet.cpp | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index da244e079..eb649be99 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1546,7 +1546,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { - int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; + CTxDestination address; int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; i 0 ) { for (j=0; j %s\n",dstr(),CBitcoinAddress(address).ToString().c_str()); + } script = (uint8_t *)tx.vout[j].scriptPubKey.data(); if ( script == 0 || script[0] != 0x6a ) - voutsum += tx.vout[j].nValue; + { + if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 ) + voutsum += tx.vout[j].nValue; + } } } *zfundsp = zfunds; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6831585c4..07bf91c89 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) 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) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4643,11 +4643,17 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { - if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + besttime = 0; + if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); - } - else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime-300 ) + break; + fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + } else continue; + eligible = besttime; + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { earliest = eligible; best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; @@ -4655,7 +4661,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 27d76b740bb4b59e35335706c6d06b7f604de1d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:02:53 -1100 Subject: [PATCH 0443/1123] Syntax --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eb649be99..f328853b3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1574,7 +1574,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 ) voutsum += tx.vout[j].nValue; - else printf("skip %.8f -> %s\n",dstr(),CBitcoinAddress(address).ToString().c_str()); + else printf("skip %.8f -> %s\n",dstr(tx.vout[j].nValue),CBitcoinAddress(address).ToString().c_str()); } script = (uint8_t *)tx.vout[j].scriptPubKey.data(); if ( script == 0 || script[0] != 0x6a ) From b388a2914475cda3196eb45218f99f610283b9eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:22:25 -1100 Subject: [PATCH 0444/1123] Add loop --- src/wallet/rpcwallet.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 07bf91c89..542666755 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4646,11 +4646,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = 0; if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - besttime = eligible; - eligible--; - if ( eligible < (uint32_t)tipindex->nTime-300 ) - break; - fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + while ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + { + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime-300 ) + break; + fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + } } else continue; eligible = besttime; if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) From beb03773e4bd9c8550b3b48183ed2950ca7e1b02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:37:07 -1100 Subject: [PATCH 0445/1123] Test --- src/wallet/rpcwallet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 542666755..d5b01a495 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) 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) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4640,6 +4640,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { + m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { @@ -4652,7 +4653,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt eligible--; if ( eligible < (uint32_t)tipindex->nTime-300 ) break; - fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + m++; + //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); } } else continue; eligible = besttime; @@ -4664,7 +4666,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 424aeca00d8ff14e541be3d84a3ee478c0171aa7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:04:10 -1100 Subject: [PATCH 0446/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d5b01a495..be1be1b28 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4651,7 +4651,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-300 ) + if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); From 17ec046d90b8966caea92d8c67cb62d1f5051721 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:15:26 -1100 Subject: [PATCH 0447/1123] Test --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index be1be1b28..765b718a1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4601,6 +4601,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) @@ -4702,6 +4703,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); + fprintf(stderr,"end scan of utxo for staking %u\n",(uint32_t)time(NULL)); return(siglen); } From 4fc4e200964a77efdb62eec30682642f8c98c704 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:22:28 -1100 Subject: [PATCH 0448/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 765b718a1..51b9edb8e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4652,7 +4652,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + //if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); From 55dd662212f77be38ad94625d0019fa4fd3a671f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:41:29 -1100 Subject: [PATCH 0449/1123] Optimize staking loop a bit --- src/wallet/rpcwallet.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 51b9edb8e..88759a6f4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) 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) { - set setAddress; int32_t i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *tipindex; CTxDestination address; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4601,15 +4601,26 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + if ( (tipindex= chainActive.Tip()) == 0 ) + return(0); fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); BOOST_FOREACH(const COutput& out, vecOutputs) { + counter++; + if ( chainActive.Tip() != tipindex ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) { //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } - if ( setAddress.size() ) + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + /*if ( setAddress.size() ) { CTxDestination address; if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) @@ -4624,23 +4635,13 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } if ( IsMine(*pwalletMain, address) == 0 ) continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; + }*/ const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - CTxDestination address; - if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) - { - //entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); - //if (pwalletMain->mapAddressBook.count(address)) - // entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); - } - //BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex; - if ( (tipindex= chainActive.Tip()) != 0 ) + if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) != 0 ) { + if ( IsMine(*pwalletMain,address) == 0 ) + continue; m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) @@ -4703,7 +4704,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking %u\n",(uint32_t)time(NULL)); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d\n",(uint32_t)time(NULL),counter); return(siglen); } From aa2ef3abfcbaba8090f930a9358a92c178909c59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 08:05:00 -1100 Subject: [PATCH 0450/1123] Test --- src/wallet/rpcwallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 88759a6f4..9b7e17d4e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4668,7 +4668,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep,counter); + if ( counter > 1000 ) + break; } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From d04efc6ff574bfdd826cdd137bd0aec0d4393f5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 08:30:38 -1100 Subject: [PATCH 0451/1123] Test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9b7e17d4e..5073ab845 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4642,6 +4642,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( IsMine(*pwalletMain,address) == 0 ) continue; +continue; m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) From ac53109534eb6023a960ee2e01862ab2256dc623 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:29:29 -1100 Subject: [PATCH 0452/1123] Optimized staker --- src/komodo_bitcoind.h | 11 ++ src/wallet/rpcwallet.cpp | 212 +++++++++++++++++++++++++++------------ 2 files changed, 160 insertions(+), 63 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f328853b3..58fc643b7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1185,6 +1185,17 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) } } +uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) +{ + bits256 addrhash; uint8_t hashbuf[256]; + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); + memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); + memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); + vcalc_sha256(0,(uint8_t *)hashp,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); + return(addrhash.uints[0]); +} + 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) { bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5073ab845..13ca693f5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4513,6 +4513,7 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); +int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { @@ -4590,10 +4591,86 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) return(siglen); } +struct komodo_staking +{ + char address[64]; + uint256 txid; + arith_uint256 hashval; + uint64_t nValue; + uint32_t segid32; + int32_t vout; + const CScript scriptPubKey; +}; + +struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,const CScript pk) +{ + uint256 hash; uint32_t segid32; struct komodo_staking *kp; + segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); + kp = &array[(*numlp)++]; + memset(*kp,0,sizeof(*kp)); + strcpy(kp->address,address); + kp->txid = txid; + kp->vout = vout; + kp->hashval = UintToArith256(hash); + kp->txtime = txtime; + kp->segid32 = segid32; + kp->nValue = nValue; + kp->scriptPubKey = pk; + return(array); +} + +arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uint32_t blocktime,int32_t iter,int32_t minage,int32_t segid,int32_t nHeight,uint32_t prevtime) +{ + int32_t diff; uint64_t coinage; arith_uint256 coinage256,hashval; + diff = (iter + blocktime - kp->txtime - minage); + if ( diff < 0 ) + diff = 60; + else if ( diff > 3600*24*30 ) + diff = 3600*24*30; + if ( iter > 0 ) + diff += segid*2; + coinage = ((uint64_t)kp->nValue/COIN * diff); + if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); + coinage256 = arith_uint256(coinage+1); + hashval = ratio * (kp->hashval / coinage256); + if ( nHeight >= 900 && nHeight < 916 ) + hashval = (hashval / coinage256); + return(hashval); +} + +uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage) +{ + int32_t maxiters = 180; + int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; + segid = ((nHeight + kp->segid32) & 0x3f); + hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + for (iter=0; itertxtime+minage ) + continue; + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + blocktime += iter; + blocktime += segid * 2; + return(blocktime); + } + } + } + return(0); +} + 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) { - set setAddress; int32_t counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *tipindex; CTxDestination address; + static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 ratio,mindiff,hashBlock,ratio; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); + mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; @@ -4603,79 +4680,88 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); if ( (tipindex= chainActive.Tip()) == 0 ) return(0); - fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); - BOOST_FOREACH(const COutput& out, vecOutputs) + nHeight = tipindex->nHeight + 1; + if ( (minage= nHeight*3) > 6000 ) // about 100 blocks + minage = 6000; + komodo_segids(hashbuf,nHeight-101,100); + fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); + if ( time(NULL) > lasttime+600 ) { - counter++; - if ( chainActive.Tip() != tipindex ) + if ( array != 0 ) { - fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); - return(0); + free(array); + array = 0; + maxkp = numkp = 0; } - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + BOOST_FOREACH(const COutput& out, vecOutputs) { - //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; - /*if ( setAddress.size() ) - { - CTxDestination address; - if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + if ( (tipindex= chainActive.Tip()) == 0 || tipindex->nHeight+1 > nHeight ) { - fprintf(stderr,"komodo_staked ExtractDestination error\n"); + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } + counter++; + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + { + //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } - if (!setAddress.count(address)) + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + if ( ExtractDestination(pk,address) != 0 ) { - fprintf(stderr,"komodo_staked setAddress.count error\n"); - continue; - } - if ( IsMine(*pwalletMain, address) == 0 ) - continue; - }*/ - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) != 0 ) - { - if ( IsMine(*pwalletMain,address) == 0 ) - continue; -continue; - m = 0; - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); - if ( eligible > 0 ) - { - besttime = 0; - if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + if ( IsMine(*pwalletMain,address) == 0 ) + continue; + if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { - while ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) - { - besttime = eligible; - eligible--; - //if ( eligible < (uint32_t)tipindex->nTime+3 ) - break; - m++; - //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); - } - } else continue; - eligible = besttime; - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) - { - earliest = eligible; - best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; - *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - *utxovoutp = out.i; - *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep,counter); - if ( counter > 1000 ) - break; + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,pk); } - } //else fprintf(stderr,"utxo not eligible\n"); - } //else fprintf(stderr,"no tipindex\n"); + } + } + lasttime = (uint32_t)time(NULL); + fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } + for (i=0; inTime+27,minage); + //eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + if ( eligible > 0 ) + { + besttime = m = 0; + if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime+3 ) + break; + m++; + fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)nValue/COIN,eligible); + } + } + else + { + fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)nValue/COIN,eligible); + continue; + } + eligible = besttime; + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + { + earliest = eligible; + best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; + *utxovaluep = (uint64_t)kp->nValue; + //decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); + decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); + *utxovoutp = kp->vout; + *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",nHeight,earliest,(int32_t)(earliest- *blocktimep),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter); + } + } //else fprintf(stderr,"utxo not eligible\n"); + } //else fprintf(stderr,"no tipindex\n"); if ( earliest != 0 ) { bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; From 5649e3d39d0350598fa5bbeaf08c8a570fc7cb75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:30:50 -1100 Subject: [PATCH 0453/1123] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 58fc643b7..fad483d3f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) { - bits256 addrhash; uint8_t hashbuf[256]; + bits256 addrhash; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); From 1273624d3e440bd9578f246b45531dd4661dd7c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:38:45 -1100 Subject: [PATCH 0454/1123] Test --- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fad483d3f..d624dc72a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) { - bits256 addrhash; + bits256 addrhash; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 13ca693f5..d9de578d5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4514,6 +4514,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); +int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { @@ -4597,17 +4598,22 @@ struct komodo_staking uint256 txid; arith_uint256 hashval; uint64_t nValue; - uint32_t segid32; + uint32_t segid32,txtime; int32_t vout; - const CScript scriptPubKey; + CScript scriptPubKey; }; -struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,const CScript pk) +struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,CScript pk) { uint256 hash; uint32_t segid32; struct komodo_staking *kp; segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); - kp = &array[(*numlp)++]; - memset(*kp,0,sizeof(*kp)); + if ( *numkp >= *maxkp ) + { + *maxkp += 1000; + array = (struct komodo_staking *)realloc(array,sizeof(*array) * (*maxkp)); + } + kp = &array[(*numkp)++]; + memset(kp,0,sizeof(*kp)); strcpy(kp->address,address); kp->txid = txid; kp->vout = vout; @@ -4667,7 +4673,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 ratio,mindiff,hashBlock,ratio; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4716,7 +4722,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { - array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,pk); + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); } } } From aecf58592c68a873893e4c8f476b6014d214f6d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:41:08 -1100 Subject: [PATCH 0455/1123] Fix --- src/wallet/rpcwallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d9de578d5..3633c56e4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4720,7 +4720,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( IsMine(*pwalletMain,address) == 0 ) continue; - if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) + if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); } @@ -4746,16 +4746,16 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; - fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)nValue/COIN,eligible); + fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else { - fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)nValue/COIN,eligible); + fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); continue; } eligible = besttime; - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; From 76df25be7a6f964272eb4383b698375c95351726 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:51:01 -1100 Subject: [PATCH 0456/1123] Test --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3633c56e4..c37e78889 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4732,8 +4732,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; inTime+27,minage); - //eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + continue; + eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { besttime = m = 0; From ecae680bfa8f842849ca057233ea5973d7daec20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:52:42 -1100 Subject: [PATCH 0457/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c37e78889..babeabe6e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4734,7 +4734,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt kp = &array[i]; if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); if ( eligible > 0 ) { besttime = m = 0; From 011b0a24334378c2a71ef3a069efac111f3afeed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:02:23 -1100 Subject: [PATCH 0458/1123] Test --- src/wallet/rpcwallet.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index babeabe6e..59516472b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+600 ) + //if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) { @@ -4747,7 +4747,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; - fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); + //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else @@ -4769,6 +4769,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); + if ( array != 0 ) + { + free(array); + array = 0; + maxkp = numkp = 0; + } if ( earliest != 0 ) { bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; @@ -4800,7 +4806,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking t.%u counter.%d\n",(uint32_t)time(NULL),counter); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d\n",(uint32_t)time(NULL),counter,numkp); return(siglen); } From 518e079e9172d69e211ed783bb7873f36b1e0333 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:14:53 -1100 Subject: [PATCH 0459/1123] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 59516472b..384c23001 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4740,11 +4740,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = m = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { + fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + if ( eligible < (uint32_t)tipindex->nTime-180 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 1d8f1b466afec494601820a696923f53ff68f6ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:18:36 -1100 Subject: [PATCH 0460/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 384c23001..cc8f63040 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4740,7 +4740,6 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = m = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { - fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { besttime = eligible; @@ -4757,6 +4756,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } eligible = besttime; + fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; From 817aedba536f3573c715a90b49c24a2d240a68a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:53:42 -1100 Subject: [PATCH 0461/1123] Test --- src/wallet/rpcwallet.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cc8f63040..7c1b81af1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,13 +4691,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - //if ( time(NULL) > lasttime+600 ) + if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { free(array); array = 0; maxkp = numkp = 0; + lasttime = 0; } BOOST_FOREACH(const COutput& out, vecOutputs) { @@ -4731,6 +4732,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } for (i=0; inHeight+1 > nHeight ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } kp = &array[i]; if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; @@ -4770,11 +4776,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( array != 0 ) + if ( 0 && array != 0 ) { free(array); array = 0; maxkp = numkp = 0; + lasttime = 0; } if ( earliest != 0 ) { From a87b6f5f629a2d55c2db677155e5347f6dcad7e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:55:01 -1100 Subject: [PATCH 0462/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7c1b81af1..8a0d83d1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4750,7 +4750,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-180 ) + if ( eligible < (uint32_t)tipindex->nTime-60 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From cbce9f1f65a3bca9c373577178d6e6447d09dc90 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 14 Jul 2018 23:00:09 +0000 Subject: [PATCH 0463/1123] WIP debugging why leveldb iterator is broke --- src/main.cpp | 14 +++++++++++--- src/txdb.cpp | 18 ++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b08d2e522..15d74adb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -590,10 +590,18 @@ CBlockTreeDB *pblocktree = NULL; int64_t komodo_snapshot() { + fprintf(stderr,"komodo_snapshot\n"); int64_t total = -1; - if ( pblocktree != 0 ) - total = pblocktree->Snapshot(); - else fprintf(stderr,"null pblocktree start with -addressindex=true\n"); + if (fAddressIndex) { + if ( pblocktree != 0 ) { + total = pblocktree->Snapshot(); + } else { + fprintf(stderr,"null pblocktree start with -addressindex=true\n"); + } + } else { + fprintf(stderr,"getsnapshot requires -addressindex=true\n"); + } + fprintf(stderr,"total=%li\n", total); return(total); } diff --git a/src/txdb.cpp b/src/txdb.cpp index a0f764962..fa3766faf 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,18 +402,31 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); - pcursor->SeekToFirst(); + //boost::scoped_ptr pcursor(pdb->NewIterator(leveldb::ReadOptions()) ); + //boost::scoped_ptr pcursor(db->NewIterator()); + fprintf(stderr,"Snapshot\n"); + + //pcursor->SeekToFirst(); + pcursor->SeekToLast(); + fprintf(stderr,"SeekToLast\n"); + fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { + fprintf(stderr,"pcursor valid\n"); boost::this_thread::interruption_point(); + fprintf(stderr,"about to try\n"); try { leveldb::Slice slKey = pcursor->key(); + fprintf(stderr,"made slice\n"); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); + fprintf(stderr,"made ssKey\n"); CAddressIndexKey indexKey; ssKey >> chType; + fprintf(stderr,"made chType\n"); ssKey >> indexKey; + fprintf(stderr,"made indexKey\n"); fprintf(stderr,"chType.%d\n",chType); if ( chType == DB_ADDRESSINDEX ) { @@ -428,12 +441,13 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Next(); + pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } } else { break; } } catch (const std::exception& e) { + fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); break; } } From 45c4bfef6434afc0f351566691257b49a126cebc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:02:20 -1100 Subject: [PATCH 0464/1123] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8a0d83d1f..d068ac18d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+60 ) + //if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { @@ -4776,7 +4776,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( 0 && array != 0 ) + if ( array != 0 ) { free(array); array = 0; From d5c81c59bbc70ea5067c316cf34a73960cc181a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:11:43 -1100 Subject: [PATCH 0465/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d068ac18d..28166a6fa 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); + //LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); From b8b06863603f0f0b284731d107cb4efc0de73447 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:21:33 -1100 Subject: [PATCH 0466/1123] Test --- src/wallet/rpcwallet.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 28166a6fa..d11300c96 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4660,7 +4660,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); @@ -4673,12 +4673,12 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); - //LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - //if ( time(NULL) > lasttime+60 ) + if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { @@ -4730,7 +4730,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } - for (i=0; inHeight+1 > nHeight ) { @@ -4738,9 +4738,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(0); } kp = &array[i]; - if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); + fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; From cfe64b2b487c991b8775a875949025bfb0ed0299 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:26:38 -1100 Subject: [PATCH 0467/1123] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d11300c96..987e6db62 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4651,6 +4651,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); + fprintf(stderr,"b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter Date: Sat, 14 Jul 2018 12:35:26 -1100 Subject: [PATCH 0468/1123] Test --- src/wallet/rpcwallet.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 987e6db62..1977bb4df 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4645,20 +4645,24 @@ arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uin return(hashval); } -uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage) +uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage,uint8_t *hashbuf) { - int32_t maxiters = 180; + int32_t maxiters = 180; uint256 hash; int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; + komodo_stakehash(&hash,kp->address,hashbuf,kp->txid,kp->vout); + kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - fprintf(stderr,"b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + for (int i=32; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; itertxtime+minage ) continue; - hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime,hashbuf); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); @@ -4739,7 +4743,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(0); } kp = &array[i]; - if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); From 37d6294dbe692798fac29b536754a6cc8bf00425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:36:44 -1100 Subject: [PATCH 0469/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1977bb4df..5612f5f79 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4662,7 +4662,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod { if ( blocktime+iter+segid*2 < kp->txtime+minage ) continue; - hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime,hashbuf); + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); From d3ce166fb8b21972151ecb7673c8f9bbbd942194 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:41:30 -1100 Subject: [PATCH 0470/1123] Test --- src/wallet/rpcwallet.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5612f5f79..824eb60b9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4653,9 +4653,9 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - for (int i=32; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + //for (int i=32; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + //fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter 6000 ) // about 100 blocks minage = 6000; komodo_segids(hashbuf,nHeight-101,100); + if ( blocktime > tipindex->nTime+60 ) + blocktime = tipindex->nTime+60; fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+60 ) + if ( time(NULL) > lasttime+100 ) { if ( array != 0 ) { @@ -4735,7 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } - for (i=0; inHeight+1 > nHeight ) { From 6e7dcf31067a4501dd6caf2643b58c1b5936ffe4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:42:51 -1100 Subject: [PATCH 0471/1123] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 824eb60b9..a8575497f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4695,8 +4695,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; komodo_segids(hashbuf,nHeight-101,100); - if ( blocktime > tipindex->nTime+60 ) - blocktime = tipindex->nTime+60; + if ( *blocktimep > tipindex->nTime+60 ) + *blocktimep = tipindex->nTime+60; fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); if ( time(NULL) > lasttime+100 ) { From 1973dfa0505aa51cf471bc67aac2919a00615e82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:49:18 -1100 Subject: [PATCH 0472/1123] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a8575497f..330c5f253 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4665,7 +4665,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); @@ -4698,7 +4698,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( *blocktimep > tipindex->nTime+60 ) *blocktimep = tipindex->nTime+60; fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+100 ) + if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) { @@ -4748,7 +4748,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); - fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); + //fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; From 2d4811152640e6e4413f811af0b02cc8605022b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:02:35 -1100 Subject: [PATCH 0473/1123] -prints --- src/wallet/rpcwallet.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 330c5f253..c55a306ed 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4697,7 +4697,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt komodo_segids(hashbuf,nHeight-101,100); if ( *blocktimep > tipindex->nTime+60 ) *blocktimep = tipindex->nTime+60; - fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); + //fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) @@ -4737,7 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } - for (i=0; inHeight+1 > nHeight ) { @@ -4770,7 +4770,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } eligible = besttime; - fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); + winners++; + //fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible); if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; @@ -4780,11 +4781,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); *utxovoutp = kp->vout; *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",nHeight,earliest,(int32_t)(earliest- *blocktimep),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winnders.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( 0 && array != 0 ) + if ( numkp < 10000 && array != 0 ) { free(array); array = 0; @@ -4822,7 +4823,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d\n",(uint32_t)time(NULL),counter,numkp); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners); return(siglen); } From 8cbf8d6a12fee8999c1a8b591e606b681e31b2f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:12:08 -1100 Subject: [PATCH 0474/1123] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c55a306ed..debec99b6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4735,7 +4735,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } lasttime = (uint32_t)time(NULL); - fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); + //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } for (i=winners=0; inTime-60 ) + if ( eligible < (uint32_t)tipindex->nTime+30 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); @@ -4823,7 +4823,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners); + //fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners); return(siglen); } From 779b7b3a5b5a472bd0893807bbbf023fa4313360 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:16:18 -1100 Subject: [PATCH 0475/1123] Typo --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index debec99b6..23ba352dd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4781,7 +4781,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str()); *utxovoutp = kp->vout; *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winnders.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winners.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 8afd5b3a0444e241dbcd885ffc300f580e60dcf3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:25:57 -1100 Subject: [PATCH 0476/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 23ba352dd..383c84ef9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4758,7 +4758,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+30 ) + if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From a3b8c12830810f7d8b81bf7bfe5296675d2aa550 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:26:39 -1100 Subject: [PATCH 0477/1123] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 383c84ef9..c4374737f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4758,7 +4758,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + if ( eligible < (uint32_t)tipindex->nTime-63 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 48c3fcbed30c10ef75297659012ab036bceaca30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 23:48:09 -1100 Subject: [PATCH 0478/1123] Snapshot() reverse iterator --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index a0f764962..ae15d37e1 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,7 +402,7 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); - pcursor->SeekToFirst(); + pcursor->SeekToLast(); fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { @@ -428,7 +428,7 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Next(); + pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } From 6651944ae70065fa8f4a93c4fb81d2263d04f360 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 23:59:08 -1100 Subject: [PATCH 0479/1123] Test --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index ae15d37e1..31af362ac 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -400,7 +400,7 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr int64_t CBlockTreeDB::Snapshot() { - char chType; int64_t total = -1; std::string address; + char chType; int64_t total = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); pcursor->SeekToLast(); fprintf(stderr,"pcursor iterate\n"); @@ -428,7 +428,6 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -436,6 +435,7 @@ int64_t CBlockTreeDB::Snapshot() } catch (const std::exception& e) { break; } + pcursor->Prev(); } return(total); } From 7246f7f31d21875d47ea815bf822bada3a88ad0c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 15 Jul 2018 22:01:35 -0700 Subject: [PATCH 0480/1123] WIP correctly calculate block progress for asset chains --- src/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b08d2e522..c17f4456f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3195,10 +3195,18 @@ void static UpdateTip(CBlockIndex *pindexNew) { nTimeBestReceived = GetTime(); mempool.AddTransactionsUpdated(1); KOMODO_NEWBLOCKS++; + double progress; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); + } else { + progress = (KOMODO_LONGESTCHAIN > 0 ) ? chainActive.Height() / KOMODO_LONGESTCHAIN : 1.0; + } + LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); + chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), + log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress, + pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); cvBlockChange.notify_all(); From 3bd2c3bd6a060f3408a22aff6debaa76865b0884 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 16 Jul 2018 07:57:56 +0000 Subject: [PATCH 0481/1123] Fix progress estimate for asset chains, mostly --- src/main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c17f4456f..2ef9eb519 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3199,7 +3199,8 @@ void static UpdateTip(CBlockIndex *pindexNew) { if ( ASSETCHAINS_SYMBOL[0] == 0 ) { progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); } else { - progress = (KOMODO_LONGESTCHAIN > 0 ) ? chainActive.Height() / KOMODO_LONGESTCHAIN : 1.0; + int32_t longestchain = komodo_longestchain(); + progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, @@ -4858,11 +4859,21 @@ bool static LoadBlockIndexDB() it->second->hashAnchorEnd = pcoinsTip->GetBestAnchor(); PruneBlockIndexCandidates(); + + double progress; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + progress = Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()); + } else { + int32_t longestchain = komodo_longestchain(); + // TODO: komodo_longestchain does not have the data it needs at the time LoadBlockIndexDB + // runs, which makes it return 0, so we guess 50% for now + progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 0.5; + } LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip())); + progress); EnforceNodeDeprecation(chainActive.Height(), true); From 8d487e52a7f01b137e3704315e0eedcf8e6b001c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Jul 2018 21:41:16 -1100 Subject: [PATCH 0482/1123] Change deprecation height for 1400000 --- src/deprecation.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/deprecation.h b/src/deprecation.h index 78ed8ebda..ec8b084d9 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -6,14 +6,14 @@ #define ZCASH_DEPRECATION_H // Deprecation policy: -// * Shut down 16 weeks' worth of blocks after the estimated release block height. -// * A warning is shown during the 2 weeks' worth of blocks prior to shut down. -static const int APPROX_RELEASE_HEIGHT = 800000; -static const int WEEKS_UNTIL_DEPRECATION = 52; -static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 24); +// * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height. +// * A warning is shown during the WEEKS_UNTIL_DEPRECATION worth of blocks prior to shut down. +//static const int APPROX_RELEASE_HEIGHT = 800000; +//static const int WEEKS_UNTIL_DEPRECATION = 52; +static const int DEPRECATION_HEIGHT = 1400000; //APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); // Number of blocks before deprecation to warn users -static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months +static const int WEEKS_UNTIL_DEPRECATION = 60 * 24 * 60; // 2 months /** * Checks whether the node is deprecated based on the current block height, and From 86131275722b856b80d3032d74f89d94ff6e0ea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Jul 2018 22:47:16 -1100 Subject: [PATCH 0483/1123] LastTip() and tweak deprecation heights --- src/chain.cpp | 1 + src/chain.h | 6 ++++++ src/deprecation.h | 10 ++++----- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 16 +++++++------- src/komodo_gateway.h | 2 +- src/komodo_jumblr.h | 2 +- src/komodo_pax.h | 4 ++-- src/main.cpp | 44 +++++++++++++++++++-------------------- src/metrics.cpp | 2 +- src/miner.cpp | 34 +++++++++++++++--------------- src/rest.cpp | 6 +++--- src/rpcblockchain.cpp | 30 +++++++++++++------------- src/rpcmining.cpp | 24 ++++++++++----------- src/rpcmisc.cpp | 8 +++---- src/rpcrawtransaction.cpp | 2 +- src/txmempool.cpp | 2 +- src/wallet/rpcdump.cpp | 8 +++---- src/wallet/rpcwallet.cpp | 12 +++++------ src/wallet/wallet.cpp | 12 +++++------ 20 files changed, 118 insertions(+), 111 deletions(-) diff --git a/src/chain.cpp b/src/chain.cpp index 7bb72d5d3..d79a66f9a 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -11,6 +11,7 @@ using namespace std; * CChain implementation */ void CChain::SetTip(CBlockIndex *pindex) { + lastTip = pindex; if (pindex == NULL) { vChain.clear(); return; diff --git a/src/chain.h b/src/chain.h index 71d788531..d882083e6 100644 --- a/src/chain.h +++ b/src/chain.h @@ -416,6 +416,7 @@ public: class CChain { private: std::vector vChain; + CBlockIndex *lastTip; public: /** Returns the index entry for the genesis block of this chain, or NULL if none. */ @@ -427,6 +428,11 @@ public: CBlockIndex *Tip() const { return vChain.size() > 0 ? vChain[vChain.size() - 1] : NULL; } + + /** Returns the last tip of the chain, or NULL if none. */ + CBlockIndex *LastTip() const { + return vChain.size() > 0 ? lastTip : NULL; + } /** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */ CBlockIndex *operator[](int nHeight) const { diff --git a/src/deprecation.h b/src/deprecation.h index ec8b084d9..11eb69ef4 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -7,13 +7,13 @@ // Deprecation policy: // * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height. -// * A warning is shown during the WEEKS_UNTIL_DEPRECATION worth of blocks prior to shut down. -//static const int APPROX_RELEASE_HEIGHT = 800000; -//static const int WEEKS_UNTIL_DEPRECATION = 52; -static const int DEPRECATION_HEIGHT = 1400000; //APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); +// * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down. +static const int WEEKS_UNTIL_DEPRECATION = 52; +static const int DEPRECATION_HEIGHT = 1400000; +static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); // Number of blocks before deprecation to warn users -static const int WEEKS_UNTIL_DEPRECATION = 60 * 24 * 60; // 2 months +static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months /** * Checks whether the node is deprecated based on the current block height, and diff --git a/src/komodo.h b/src/komodo.h index ae0898ed3..e89dea2e4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -823,7 +823,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_event_rewind(sp,symbol,pindex->nHeight); komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0); } - komodo_currentheight_set(chainActive.Tip()->nHeight); + komodo_currentheight_set(chainActive.LastTip()->nHeight); if ( pindex != 0 ) { height = pindex->nHeight; @@ -907,7 +907,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif - notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.Tip()->GetBlockTime()); + notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( 0 && i > 0 ) { for (k=0; kGetBlockTime()); + if ( chainActive.LastTip() != 0 ) + return((uint32_t)chainActive.LastTip()->GetBlockTime()); else return(0); } @@ -760,11 +760,11 @@ CBlockIndex *komodo_chainactive(int32_t height) { if ( chainActive.Tip() != 0 ) { - if ( height <= chainActive.Tip()->nHeight ) + if ( height <= chainActive.LastTip()->nHeight ) return(chainActive[height]); - // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); + // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->nHeight); } - //fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); + //fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height); return(0); } @@ -994,7 +994,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) { int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex; - if ( (pindex= chainActive.Tip()) == 0 ) + if ( (pindex= chainActive.LastTip()) == 0 ) return(-1); notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid); *notarized_heightp = notarized_height; @@ -1036,7 +1036,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_ *valuep = tx.vout[n].nValue; *txheightp = pindex->nHeight; *txheighttimep = pindex->nTime; - if ( *tiptimep == 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 ) *tiptimep = (uint32_t)tipindex->nTime; locktime = tx.nLockTime; //fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep); @@ -1069,7 +1069,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 ) *kmdheightp = sp->CURRENT_HEIGHT; else *kmdheightp = 0; - if ( (pindex= chainActive.Tip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() ) + if ( (pindex= chainActive.LastTip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() ) return(1); else return(0); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9de6b4fc9..6a8ef310b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1490,7 +1490,7 @@ void komodo_passport_iteration() komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); if ( (fp= fopen(fname,"wb")) != 0 ) { - buf[0] = (uint32_t)chainActive.Tip()->nHeight; + buf[0] = (uint32_t)chainActive.LastTip()->nHeight; buf[1] = (uint32_t)komodo_longestchain(); if ( buf[0] != 0 && buf[0] == buf[1] ) { diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index f36bb441a..fa44425fd 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -648,7 +648,7 @@ void jumblr_iteration() free(retstr); } } - height = (int32_t)chainActive.Tip()->nHeight; + height = (int32_t)chainActive.LastTip()->nHeight; if ( time(NULL) < lasttime+40 ) return; lasttime = (uint32_t)time(NULL); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index d0bad0e14..35d226fc3 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -637,13 +637,13 @@ uint64_t komodo_paxpriceB(uint64_t seed,int32_t height,char *base,char *rel,uint uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && height > chainActive.LastTip()->nHeight ) { if ( height < 100000000 ) { static uint32_t counter; if ( counter++ < 3 ) - printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight); + printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.LastTip()->nHeight); } return(0); } diff --git a/src/main.cpp b/src/main.cpp index 2ef9eb519..330bf6ad1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1269,7 +1269,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 ) + if ( komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) { //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -1399,7 +1399,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime); + nValueIn = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime); if ( 0 && interest != 0 ) fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool @@ -1891,7 +1891,7 @@ void CheckForkWarningConditions() if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 288) pindexBestForkTip = NULL; - if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6))) + if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.LastTip()->nChainWork + (GetBlockProof(*chainActive.LastTip()) * 6))) { if (!fLargeWorkForkFound && pindexBestForkBase) { @@ -1926,7 +1926,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) AssertLockHeld(cs_main); // If we are on a fork that is sufficiently large, set a warning flag CBlockIndex* pfork = pindexNewForkTip; - CBlockIndex* plonger = chainActive.Tip(); + CBlockIndex* plonger = chainActive.LastTip(); while (pfork && pfork != plonger) { while (plonger && plonger->nHeight > pfork->nHeight) @@ -1983,7 +1983,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew) pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexNew->GetBlockTime())); - CBlockIndex *tip = chainActive.Tip(); + CBlockIndex *tip = chainActive.LastTip(); assert (tip); LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", __func__, tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0), @@ -2111,14 +2111,14 @@ namespace Consensus { // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; #ifdef KOMODO_ENABLE_INTEREST - if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 ) { if ( coins->vout[prevout.n].nValue >= 10*COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue,(int32_t)nSpendHeight-1)) != 0 ) { - //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.LastTip()->nTime); nValueIn += interest; } } @@ -2868,7 +2868,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!tx.IsCoinBase()) { - nFees += view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut(); + nFees += view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime) - tx.GetValueOut(); sum += interest; std::vector vChecks; @@ -3197,16 +3197,16 @@ void static UpdateTip(CBlockIndex *pindexNew) { KOMODO_NEWBLOCKS++; double progress; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip()); } else { int32_t longestchain = komodo_longestchain(); progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), - log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress, + chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), + log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.LastTip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress, pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); cvBlockChange.notify_all(); @@ -3455,7 +3455,7 @@ static void PruneBlockIndexCandidates() { // Note that we can't delete the current block itself, as we may need to return to it later in case a // reorganization to a better block fails. std::set::iterator it = setBlockIndexCandidates.begin(); - while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) { + while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.LastTip())) { setBlockIndexCandidates.erase(it++); } // Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates. @@ -3507,8 +3507,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if ( KOMODO_REWIND != 0 ) { CBlockIndex *tipindex; - fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.Tip()->nHeight,KOMODO_REWIND); - while ( KOMODO_REWIND > 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->nHeight > KOMODO_REWIND ) + fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.LastTip()->nHeight,KOMODO_REWIND); + while ( KOMODO_REWIND > 0 && (tipindex= chainActive.LastTip()) != 0 && tipindex->nHeight > KOMODO_REWIND ) { fBlocksDisconnected = true; fprintf(stderr,"%d ",(int32_t)tipindex->nHeight); @@ -3922,9 +3922,9 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- CheckBlockHeader\n"); - if ( chainActive.Tip() != 0 ) + if ( chainActive.LastTip() != 0 ) { - hash = chainActive.Tip()->GetBlockHash(); + hash = chainActive.LastTip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip\n"); @@ -4103,7 +4103,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) + if ( nHeight == 1 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight > 1 ) { CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) @@ -4440,8 +4440,8 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); - if ( chainActive.Tip() != 0 ) - komodo_currentheight_set(chainActive.Tip()->nHeight); + if ( chainActive.LastTip() != 0 ) + komodo_currentheight_set(chainActive.LastTip()->nHeight); checked = CheckBlock(&futureblock,height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); { LOCK(cs_main); @@ -4871,8 +4871,8 @@ bool static LoadBlockIndexDB() } LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), + chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress); EnforceNodeDeprecation(chainActive.Height(), true); diff --git a/src/metrics.cpp b/src/metrics.cpp index 6c8f80fe5..cb9fe245c 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -211,7 +211,7 @@ int printStats(bool mining) { LOCK2(cs_main, cs_vNodes); height = chainActive.Height(); - tipmediantime = chainActive.Tip()->GetMedianTimePast(); + tipmediantime = chainActive.LastTip()->GetMedianTimePast(); connections = vNodes.size(); netsolps = GetNetworkHashPS(120, -1); } diff --git a/src/miner.cpp b/src/miner.cpp index dbe6dc41c..0c458a985 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -166,7 +166,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { LOCK2(cs_main, mempool.cs); - CBlockIndex* pindexPrev = chainActive.Tip(); + CBlockIndex* pindexPrev = chainActive.LastTip(); const int nHeight = pindexPrev->nHeight + 1; uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus()); pblock->nTime = GetAdjustedTime(); @@ -334,7 +334,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //fprintf(stderr,"dont have inputs\n"); continue; } - CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) @@ -400,14 +400,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - //if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + //if ( (int32_t)chainActive.LastTip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) // return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); + //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } @@ -640,19 +640,19 @@ static bool ProcessBlockFound(CBlock* pblock) #endif // ENABLE_WALLET { LogPrintf("%s\n", pblock->ToString()); - LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.Tip()->nHeight+1); + LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->nHeight+1); // Found a solution { LOCK(cs_main); - if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash()) + if (pblock->hashPrevBlock != chainActive.LastTip()->GetBlockHash()) { uint256 hash; int32_t i; hash = pblock->hashPrevBlock; for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- prev (stale)\n"); - hash = chainActive.Tip()->GetBlockHash(); + hash = chainActive.LastTip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip (stale)\n"); @@ -680,7 +680,7 @@ static bool ProcessBlockFound(CBlock* pblock) // Process this block the same as if we had received it from another node CValidationState state; - if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); @@ -718,13 +718,13 @@ void static BitcoinMiner() unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; - while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 && + while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.LastTip()->nHeight != 235300 && { sleep(1); if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) break; } - komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime()); + komodo_chosennotary(¬aryid,chainActive.LastTip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( notaryid != My_notaryid ) My_notaryid = notaryid; std::string solver; @@ -750,9 +750,9 @@ void static BitcoinMiner() fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); while (true) { - if (chainparams.MiningRequiresPeers()) //chainActive.Tip()->nHeight != 235300 && + if (chainparams.MiningRequiresPeers()) //chainActive.LastTip()->nHeight != 235300 && { - //if ( ASSETCHAINS_SEED != 0 && chainActive.Tip()->nHeight < 100 ) + //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->nHeight < 100 ) // break; // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. @@ -776,7 +776,7 @@ void static BitcoinMiner() // Create new block // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrev = chainActive.Tip(); + CBlockIndex* pindexPrev = chainActive.LastTip(); if ( Mining_height != pindexPrev->nHeight+1 ) { Mining_height = pindexPrev->nHeight+1; @@ -962,7 +962,7 @@ void static BitcoinMiner() while ( GetAdjustedTime() < B.nTime-2 ) { sleep(1); - if ( chainActive.Tip()->nHeight >= Mining_height ) + if ( chainActive.LastTip()->nHeight >= Mining_height ) { fprintf(stderr,"new block arrived\n"); return(false); @@ -983,7 +983,7 @@ void static BitcoinMiner() while ( B.nTime-57 > GetAdjustedTime() ) { sleep(1); - if ( chainActive.Tip()->nHeight >= Mining_height ) + if ( chainActive.LastTip()->nHeight >= Mining_height ) return(false); } uint256 tmp = B.GetHash(); @@ -992,7 +992,7 @@ void static BitcoinMiner() fprintf(stderr," mined %s block %d!\n",ASSETCHAINS_SYMBOL,Mining_height); } CValidationState state; - if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) + if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) { h = UintToArith256(B.GetHash()); for (z=31; z>=0; z--) @@ -1112,7 +1112,7 @@ void static BitcoinMiner() fprintf(stderr,"timeout, break\n"); break; } - if ( pindexPrev != chainActive.Tip() ) + if ( pindexPrev != chainActive.LastTip() ) { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"Tip advanced, break\n"); diff --git a/src/rest.cpp b/src/rest.cpp index 8e2e4d1e6..38cc38466 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -530,7 +530,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // serialize data // use exact same output as mentioned in Bip64 CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; string ssGetUTXOResponseString = ssGetUTXOResponse.str(); req->WriteHeader("Content-Type", "application/octet-stream"); @@ -540,7 +540,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) case RF_HEX: { CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n"; req->WriteHeader("Content-Type", "text/plain"); @@ -554,7 +554,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // pack in some essentials // use more or less the same output as mentioned in Bip64 objGetUTXOResponse.push_back(Pair("chainHeight", chainActive.Height())); - objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.Tip()->GetBlockHash().GetHex())); + objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.LastTip()->GetBlockHash().GetHex())); objGetUTXOResponse.push_back(Pair("bitmap", bitmapStringRepresentation)); UniValue utxos(UniValue::VARR); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 42cf7f2b0..7f8984c63 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -38,10 +38,10 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul // minimum difficulty = 1.0. if (blockindex == NULL) { - if (chainActive.Tip() == NULL) + if (chainActive.LastTip() == NULL) return 1.0; else - blockindex = chainActive.Tip(); + blockindex = chainActive.LastTip(); } uint32_t bits; @@ -326,7 +326,7 @@ UniValue getbestblockhash(const UniValue& params, bool fHelp) ); LOCK(cs_main); - return chainActive.Tip()->GetBlockHash().GetHex(); + return chainActive.LastTip()->GetBlockHash().GetHex(); } UniValue getdifficulty(const UniValue& params, bool fHelp) @@ -803,13 +803,13 @@ UniValue kvsearch(const UniValue& params, bool fHelp) if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("currentheight", (int64_t)chainActive.Tip()->nHeight)); + ret.push_back(Pair("currentheight", (int64_t)chainActive.LastTip()->nHeight)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",keylen)); if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); @@ -837,7 +837,7 @@ UniValue minerids(const UniValue& params, bool fHelp) LOCK(cs_main); int32_t height = atoi(params[0].get_str().c_str()); if ( height <= 0 ) - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; else { CBlockIndex *pblockindex = chainActive[height]; @@ -899,8 +899,8 @@ UniValue notaries(const UniValue& params, bool fHelp) else timestamp = (uint32_t)time(NULL); if ( height < 0 ) { - height = chainActive.Tip()->nHeight; - timestamp = chainActive.Tip()->GetBlockTime(); + height = chainActive.LastTip()->nHeight; + timestamp = chainActive.LastTip()->GetBlockTime(); } else if ( params.size() < 2 ) { @@ -988,7 +988,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) std::string rel = params[1].get_str(); int32_t height; if ( params.size() == 2 ) - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; else height = atoi(params[2].get_str().c_str()); //if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 ) basevolume = 100000; @@ -1280,10 +1280,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); - obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); + obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty())); - obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip()))); - obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); + obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip()))); + obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex())); obj.push_back(Pair("pruned", fPruneMode)); ZCIncrementalMerkleTree tree; @@ -1294,7 +1294,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.push_back(Pair("commitments", tree.size())); #endif - CBlockIndex* tip = chainActive.Tip(); + CBlockIndex* tip = chainActive.LastTip(); UniValue valuePools(UniValue::VARR); valuePools.push_back(ValuePoolDesc("sprout", tip->nChainSproutValue, boost::none)); obj.push_back(Pair("valuePools", valuePools)); @@ -1319,7 +1319,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) if (fPruneMode) { - CBlockIndex *block = chainActive.Tip(); + CBlockIndex *block = chainActive.LastTip(); while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) block = block->pprev; @@ -1394,7 +1394,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) } // Always report the currently active tip. - setTips.insert(chainActive.Tip()); + setTips.insert(chainActive.LastTip()); /* Construct the output array. */ UniValue res(UniValue::VARR); const CBlockIndex *forked; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index afe4e5a33..47fbeec30 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -39,7 +39,7 @@ using namespace std; * If 'height' is nonnegative, compute the estimate at the time when a given block was found. */ int64_t GetNetworkHashPS(int lookup, int height) { - CBlockIndex *pb = chainActive.Tip(); + CBlockIndex *pb = chainActive.LastTip(); if (height >= 0 && height < chainActive.Height()) pb = chainActive[height]; @@ -224,7 +224,7 @@ UniValue generate(const UniValue& params, bool fHelp) CBlock *pblock = &pblocktemplate->block; { LOCK(cs_main); - IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce); + IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce); } // Hash state @@ -268,7 +268,7 @@ UniValue generate(const UniValue& params, bool fHelp) } endloop: CValidationState state; - if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL)) throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); ++nHeight; blockHashes.push_back(pblock->GetHash().GetHex()); @@ -550,7 +550,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) return "duplicate-inconclusive"; } - CBlockIndex* const pindexPrev = chainActive.Tip(); + CBlockIndex* const pindexPrev = chainActive.LastTip(); // TestBlockValidity only supports blocks built on the current Tip if (block.hashPrevBlock != pindexPrev->GetBlockHash()) return "inconclusive-not-best-prevblk"; @@ -589,7 +589,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) else { // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier - hashWatchedChain = chainActive.Tip()->GetBlockHash(); + hashWatchedChain = chainActive.LastTip()->GetBlockHash(); nTransactionsUpdatedLastLP = nTransactionsUpdatedLast; } @@ -599,7 +599,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) checktxtime = boost::get_system_time() + boost::posix_time::minutes(1); boost::unique_lock lock(csBestBlock); - while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) + while (chainActive.LastTip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) { if (!cvBlockChange.timed_wait(lock, checktxtime)) { @@ -621,7 +621,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) static CBlockIndex* pindexPrev; static int64_t nStart; static CBlockTemplate* pblocktemplate; - if (pindexPrev != chainActive.Tip() || + if (pindexPrev != chainActive.LastTip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { // Clear pindexPrev so future calls make a new block, despite any failures from here on @@ -629,7 +629,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) // Store the pindexBest used before CreateNewBlockWithKey, to avoid races nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrevNew = chainActive.Tip(); + CBlockIndex* pindexPrevNew = chainActive.LastTip(); nStart = GetTime(); // Create new block @@ -640,7 +640,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) } #ifdef ENABLE_WALLET CReserveKey reservekey(pwalletMain); - pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1,KOMODO_MAXGPUCOUNT); + pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.LastTip()->nHeight+1,KOMODO_MAXGPUCOUNT); #else pblocktemplate = CreateNewBlockWithKey(); #endif @@ -693,7 +693,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) // Correct this if GetBlockTemplate changes the order // entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); //} - CAmount nReward = GetBlockSubsidy(chainActive.Tip()->nHeight+1, Params().GetConsensus()); + CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->nHeight+1, Params().GetConsensus()); entry.push_back(Pair("coinbasevalue", nReward)); entry.push_back(Pair("required", true)); txCoinbase = entry; @@ -726,7 +726,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("coinbaseaux", aux)); result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); } - result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); + result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); @@ -809,7 +809,7 @@ UniValue submitblock(const UniValue& params, bool fHelp) CValidationState state; submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); + bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, &block, true, NULL); UnregisterValidationInterface(&sc); if (fBlockPresent) { diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index bf7f345d5..4405a407d 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -133,8 +133,8 @@ UniValue getinfo(const UniValue& params, bool fHelp) //fprintf(stderr,"after longestchain %u\n",(uint32_t)time(NULL)); obj.push_back(Pair("longestchain", longestchain)); obj.push_back(Pair("timeoffset", GetTimeOffset())); - if ( chainActive.Tip() != 0 ) - obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime)); + if ( chainActive.LastTip() != 0 ) + obj.push_back(Pair("tiptime", (int)chainActive.LastTip()->nTime)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); @@ -152,7 +152,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("errors", GetWarnings("statusbar"))); { char pubkeystr[65]; int32_t notaryid; - if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) + if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("pubkey", pubkeystr)); @@ -826,7 +826,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp) result.push_back(Pair("utxos", utxos)); LOCK(cs_main); - result.push_back(Pair("hash", chainActive.Tip()->GetBlockHash().GetHex())); + result.push_back(Pair("hash", chainActive.LastTip()->GetBlockHash().GetHex())); result.push_back(Pair("height", (int)chainActive.Height())); return result; } else { diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index a9aff1b7f..525c35ca4 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -179,7 +179,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->nHeight); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 51ed1103e..e96f0d975 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -437,7 +437,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight) for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); - tipindex = chainActive.Tip(); + tipindex = chainActive.LastTip(); if (IsExpiredTx(tx, nBlockHeight) || (ASSETCHAINS_SYMBOL[0] == 0 && tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,0)) < 0) { transactionsToRemove.push_back(tx); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 15caad846..c8dc7aa5b 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -278,7 +278,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); - int64_t nTimeBegin = chainActive.Tip()->GetBlockTime(); + int64_t nTimeBegin = chainActive.LastTip()->GetBlockTime(); bool fGood = true; @@ -364,7 +364,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys file.close(); pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI - CBlockIndex *pindex = chainActive.Tip(); + CBlockIndex *pindex = chainActive.LastTip(); while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200) pindex = pindex->pprev; @@ -509,8 +509,8 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys) // produce output file << strprintf("# Wallet dump created by Komodo %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); - file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString()); - file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime())); + file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.LastTip()->GetBlockHash().ToString()); + file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.LastTip()->GetBlockTime())); file << "\n"; for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { const CKeyID &keyid = it->second; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c4374737f..084a4f752 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -574,7 +574,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) valuesize = (int32_t)strlen(params[1].get_str().c_str()); } memcpy(keyvalue,key,keylen); - if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) + if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) { if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) { @@ -599,7 +599,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) // printf("%02x",((uint8_t *)&sig)[i]); //printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) ret.push_back(Pair("owner",refpubkey.GetHex())); ret.push_back(Pair("height", (int64_t)height)); @@ -671,7 +671,7 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); std::string dest; - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis ) { fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis); @@ -2713,13 +2713,13 @@ UniValue listunspent(const UniValue& params, bool fHelp) BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; uint64_t interest; uint32_t locktime; int32_t txheight; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); //interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } - //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); + //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); @@ -2746,7 +2746,7 @@ uint64_t komodo_interestsum() { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); //interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index df0cd9c2b..ce5630fb6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1819,7 +1819,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false); - double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false); + double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip(), false); while (pindex) { if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) @@ -2299,20 +2299,20 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( KOMODO_EXCHANGEWALLET == 0 ) { uint32_t locktime; int32_t txheight; CBlockIndex *tipindex; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 ) { if ( pcoin->vout[i].nValue >= 10*COIN ) { - if ( (tipindex= chainActive.Tip()) != 0 ) + if ( (tipindex= chainActive.LastTip()) != 0 ) { komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue,(int32_t)tipindex->nHeight); interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); } else interest = 0; - //interest = komodo_interestnew(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); + //interest = komodo_interestnew(chainActive.LastTip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.LastTip()->nTime); if ( interest != 0 ) { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u/%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,txheight,locktime,pcoin->nLockTime,tipindex->nTime); - //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.LastTip()->nHeight+1,pcoin->nLockTime,chainActive.LastTip()->nTime); //ptr = (uint64_t *)&pcoin->vout[i].nValue; //(*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; @@ -2687,7 +2687,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt int nextBlockHeight = chainActive.Height() + 1; CMutableTransaction txNew = CreateNewContextualCMutableTransaction( Params().GetConsensus(), nextBlockHeight); - txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now + txNew.nLockTime = (uint32_t)chainActive.LastTip()->nTime + 1; // set to a time close to now // Activates after Overwinter network upgrade // Set nExpiryHeight to expiryDelta (default 20) blocks past current block height From 17839698a34ac122200fe4eaf82f709b3b1c94a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jul 2018 00:55:48 -1100 Subject: [PATCH 0484/1123] block_from_future_rejecttime used in RAMstaker --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 084a4f752..02cea5bef 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4737,6 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt lasttime = (uint32_t)time(NULL); //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); } + block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; inHeight+1 > nHeight ) @@ -4758,7 +4759,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-63 ) + if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From d62d9d7889f7c647f19534f0986e0e9372db6377 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 01:40:24 +0000 Subject: [PATCH 0485/1123] Almost working snapshot, we need to sum unspent outputs for each address and return to final snapshot data in json response --- src/txdb.cpp | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index fa3766faf..dfef647e6 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -400,36 +400,30 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr int64_t CBlockTreeDB::Snapshot() { - char chType; int64_t total = -1; std::string address; + char chType; int64_t total = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); - //boost::scoped_ptr pcursor(pdb->NewIterator(leveldb::ReadOptions()) ); - //boost::scoped_ptr pcursor(db->NewIterator()); - fprintf(stderr,"Snapshot\n"); - + //pcursor->SeekToFirst(); pcursor->SeekToLast(); - fprintf(stderr,"SeekToLast\n"); - fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { - fprintf(stderr,"pcursor valid\n"); + //fprintf(stderr,"pcursor valid\n"); boost::this_thread::interruption_point(); - fprintf(stderr,"about to try\n"); try { leveldb::Slice slKey = pcursor->key(); - fprintf(stderr,"made slice\n"); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); - fprintf(stderr,"made ssKey\n"); - CAddressIndexKey indexKey; + // CAddressIndexKey indexKey; + CAddressIndexIteratorKey indexKey; ssKey >> chType; - fprintf(stderr,"made chType\n"); ssKey >> indexKey; - fprintf(stderr,"made indexKey\n"); - fprintf(stderr,"chType.%d\n",chType); - if ( chType == DB_ADDRESSINDEX ) + //fprintf(stderr,"chType.%d\n",chType); + //fprintf(stderr,"dbindex prefix=%d\n",DB_ADDRESSINDEX); + //if ( chType == 'u' ) // chType == DB_ADDRESSINDEX ) + if ( chType == DB_ADDRESSUNSPENTINDEX ) // chType == DB_ADDRESSINDEX ) { + try { leveldb::Slice slValue = pcursor->value(); CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); @@ -437,11 +431,9 @@ int64_t CBlockTreeDB::Snapshot() ssValue >> nValue; getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - if ( total < 0 ) - total = (int64_t)nValue; - else total += (int64_t)nValue; + + total += (double) nValue / COIN; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -450,6 +442,7 @@ int64_t CBlockTreeDB::Snapshot() fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); break; } + pcursor->Prev(); } return(total); } From 920f9601222ad9d4d047e6242e75e539ed991f03 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 06:05:36 +0000 Subject: [PATCH 0486/1123] Correctly print out snapshot data to stderr for now --- src/txdb.cpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index dfef647e6..00d3d276b 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,38 +402,46 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); + std::map addressAmounts; //pcursor->SeekToFirst(); pcursor->SeekToLast(); while (pcursor->Valid()) { - //fprintf(stderr,"pcursor valid\n"); boost::this_thread::interruption_point(); try { leveldb::Slice slKey = pcursor->key(); CDataStream ssKey(slKey.data(), slKey.data()+slKey.size(), SER_DISK, CLIENT_VERSION); - // CAddressIndexKey indexKey; CAddressIndexIteratorKey indexKey; ssKey >> chType; ssKey >> indexKey; - //fprintf(stderr,"chType.%d\n",chType); - //fprintf(stderr,"dbindex prefix=%d\n",DB_ADDRESSINDEX); - //if ( chType == 'u' ) // chType == DB_ADDRESSINDEX ) - if ( chType == DB_ADDRESSUNSPENTINDEX ) // chType == DB_ADDRESSINDEX ) - { + if ( chType == DB_ADDRESSUNSPENTINDEX ) + { try { leveldb::Slice slValue = pcursor->value(); CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); CAmount nValue; ssValue >> nValue; + //if (!getAddressFromIndex(indexKey.type, indexKey.hashBytes, address)) { getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); - fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - total += (double) nValue / COIN; - //addressIndex.push_back(make_pair(indexKey, nValue)); + std::map ::iterator pos = addressAmounts.find(address); + if (pos == addressAmounts.end()) { + // insert new address + utxo amount + fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + } else { + // update unspent tally for this address + addressAmounts[address] += nValue; + } + + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + total += (double) nValue / COIN; + //addressIndex.push_back(make_pair(indexKey, nValue)); + //} } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -442,8 +450,14 @@ int64_t CBlockTreeDB::Snapshot() fprintf(stderr, "%s: LevelDB exception! - %s\n", __func__, e.what()); break; } - pcursor->Prev(); + pcursor->Prev(); } + + for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) + { + fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + } + return(total); } From 7000ef1af3ddfc99bde07c185c781ea198d5eea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Jul 2018 05:26:34 -1100 Subject: [PATCH 0487/1123] Possible workaround for crash --- src/wallet/wallet.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ce5630fb6..e62c6e60b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1885,6 +1885,11 @@ void CWallet::ReacceptWalletTransactions() bool CWalletTx::RelayWalletTransaction() { + if ( pwallet == 0 ) + { + fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n"); + return(false); + } assert(pwallet->GetBroadcastTransactions()); if (!IsCoinBase()) { @@ -2124,9 +2129,13 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { - CWalletTx& wtx = *item.second; - if (wtx.RelayWalletTransaction()) - result.push_back(wtx.GetHash()); + CWalletTx& wtx; + if ( item.second != 0 ) + { + wtx = *item.second; + if (wtx.RelayWalletTransaction()) + result.push_back(wtx.GetHash()); + } } return result; } From 3872e9cb59b99fbffc23ea9fa3587afbb68a524c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Jul 2018 05:29:01 -1100 Subject: [PATCH 0488/1123] Fix --- src/wallet/wallet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e62c6e60b..5100a2470 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2129,10 +2129,9 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { - CWalletTx& wtx; if ( item.second != 0 ) { - wtx = *item.second; + CWalletTx &wtx = *item.second; if (wtx.RelayWalletTransaction()) result.push_back(wtx.GetHash()); } From 92dc28a3c92a1b5fea3c5ccf69dd796c6664e7b6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 18:42:30 +0000 Subject: [PATCH 0489/1123] Return snapshot info as JSON --- src/main.cpp | 9 ++++----- src/rpcmisc.cpp | 12 ++++++++---- src/txdb.cpp | 43 ++++++++++++++++++++++++------------------- src/txdb.h | 3 ++- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 15d74adb2..dfebfec4f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -588,21 +588,20 @@ CBlockTreeDB *pblocktree = NULL; #define KOMODO_ZCASH #include "komodo.h" -int64_t komodo_snapshot() +UniValue komodo_snapshot() { - fprintf(stderr,"komodo_snapshot\n"); int64_t total = -1; + UniValue result(UniValue::VOBJ); if (fAddressIndex) { if ( pblocktree != 0 ) { - total = pblocktree->Snapshot(); + result = pblocktree->Snapshot(); } else { fprintf(stderr,"null pblocktree start with -addressindex=true\n"); } } else { fprintf(stderr,"getsnapshot requires -addressindex=true\n"); } - fprintf(stderr,"total=%li\n", total); - return(total); + return(result); } ////////////////////////////////////////////////////////////////////////////// diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index bf7f345d5..198b41090 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -1015,7 +1015,7 @@ UniValue getaddressbalance(const UniValue& params, bool fHelp) } -int32_t komodo_snapshot(); +UniValue komodo_snapshot(); UniValue getsnapshot(const UniValue& params, bool fHelp) { @@ -1026,9 +1026,13 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) "getsnapshot\n" ); } - if ( (total= komodo_snapshot()) >= 0 ) - result.push_back(Pair("total", (double)total/COIN)); - else result.push_back(Pair("error", "no addressindex")); + result = komodo_snapshot(); + if ( result.size() > 0 ) { + // add timestamp, maybe block height? + result.push_back(Pair("time", time(NULL))); + } else { + result.push_back(Pair("error", "no addressindex")); + } return(result); } diff --git a/src/txdb.cpp b/src/txdb.cpp index 00d3d276b..63b640123 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -10,6 +10,7 @@ #include "main.h" #include "pow.h" #include "uint256.h" +#include "core_io.h" #include @@ -398,11 +399,12 @@ bool CBlockTreeDB::ReadAddressIndex(uint160 addressHash, int type, bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &address); -int64_t CBlockTreeDB::Snapshot() +extern UniValue CBlockTreeDB::Snapshot() { - char chType; int64_t total = 0; std::string address; + char chType; int64_t total = 0; int64_t totalAddresses = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); std::map addressAmounts; + UniValue result(UniValue::VOBJ); //pcursor->SeekToFirst(); pcursor->SeekToLast(); @@ -425,23 +427,22 @@ int64_t CBlockTreeDB::Snapshot() CDataStream ssValue(slValue.data(), slValue.data()+slValue.size(), SER_DISK, CLIENT_VERSION); CAmount nValue; ssValue >> nValue; - //if (!getAddressFromIndex(indexKey.type, indexKey.hashBytes, address)) { - getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); - std::map ::iterator pos = addressAmounts.find(address); - if (pos == addressAmounts.end()) { - // insert new address + utxo amount - fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); - addressAmounts[address] = nValue; - } else { - // update unspent tally for this address - addressAmounts[address] += nValue; - } + getAddressFromIndex(indexKey.type, indexKey.hashBytes, address); + std::map ::iterator pos = addressAmounts.find(address); + if (pos == addressAmounts.end()) { + // insert new address + utxo amount + fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + addressAmounts[address] = nValue; + totalAddresses++; + } else { + // update unspent tally for this address + addressAmounts[address] += nValue; + } - //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); - total += (double) nValue / COIN; - //addressIndex.push_back(make_pair(indexKey, nValue)); - //} + //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); + total += nValue; + //addressIndex.push_back(make_pair(indexKey, nValue)); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -453,12 +454,16 @@ int64_t CBlockTreeDB::Snapshot() pcursor->Prev(); } + // TODO: create addresses key with array of {address,amount} + + fprintf(stderr, "total=%f, totalAddresses=%li\n", (double) total / COIN, totalAddresses); for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) { - fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + result.push_back(make_pair( it->first.c_str(), (double) it->second / COIN ) ); } - return(total); + return(result); } bool CBlockTreeDB::WriteTimestampIndex(const CTimestampIndexKey ×tampIndex) { diff --git a/src/txdb.h b/src/txdb.h index cb4d6d19e..6c6b41917 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -13,6 +13,7 @@ #include #include #include +#include class CBlockFileInfo; class CBlockIndex; @@ -94,7 +95,7 @@ public: bool ReadFlag(const std::string &name, bool &fValue); bool LoadBlockIndexGuts(); bool blockOnchainActive(const uint256 &hash); - int64_t Snapshot(); + UniValue Snapshot(); }; #endif // BITCOIN_TXDB_H From 29a5aa99fd5090bf3ca1b1248a844807bcff377c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 19:39:55 +0000 Subject: [PATCH 0490/1123] Move address+amount data to addresses key in JSON; add some useful metadata to snapshot response --- src/txdb.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 63b640123..9170ceea0 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -454,15 +454,23 @@ extern UniValue CBlockTreeDB::Snapshot() pcursor->Prev(); } - // TODO: create addresses key with array of {address,amount} + UniValue addresses(UniValue::VARR); fprintf(stderr, "total=%f, totalAddresses=%li\n", (double) total / COIN, totalAddresses); for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) { - fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); - result.push_back(make_pair( it->first.c_str(), (double) it->second / COIN ) ); + UniValue obj(UniValue::VOBJ); + fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); + obj.push_back( make_pair("addr", it->first.c_str() ) ); + obj.push_back( make_pair("amount", (double) it->second / COIN)); + addresses.push_back(obj); } + result.push_back(make_pair("addresses", addresses)); + result.push_back(make_pair("total", total / COIN )); + result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); + result.push_back(make_pair("total_addresses", totalAddresses)); + result.push_back(make_pair("height", chainActive.Height())); return(result); } From 6e74fd25780d8ac14d20bd89d5ced6eb368e7440 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 21:37:52 +0000 Subject: [PATCH 0491/1123] In memory sorting, add a few metadata fields; printing small floats correctly still not working --- src/txdb.cpp | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 9170ceea0..b4ea54f9b 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -409,6 +409,14 @@ extern UniValue CBlockTreeDB::Snapshot() //pcursor->SeekToFirst(); pcursor->SeekToLast(); + int64_t startingHeight = chainActive.Height(); + + // prevent any node updates so we can get a consistent snapshot at this height + // causes coredumps + // LOCK(cs_main); + // does not compile + //LOCK(cs_wallet); + while (pcursor->Valid()) { boost::this_thread::interruption_point(); @@ -442,7 +450,6 @@ extern UniValue CBlockTreeDB::Snapshot() //fprintf(stderr,"{\"%s\", %.8f},\n",address.c_str(),(double)nValue/COIN); total += nValue; - //addressIndex.push_back(make_pair(indexKey, nValue)); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -455,22 +462,39 @@ extern UniValue CBlockTreeDB::Snapshot() } UniValue addresses(UniValue::VARR); - fprintf(stderr, "total=%f, totalAddresses=%li\n", (double) total / COIN, totalAddresses); - for (map ::iterator it = addressAmounts.begin(); it != addressAmounts.end(); it++) - { - UniValue obj(UniValue::VOBJ); - fprintf(stderr,"{\"%s\", %.8f},\n",it->first.c_str(),(double) it->second / COIN); - obj.push_back( make_pair("addr", it->first.c_str() ) ); - obj.push_back( make_pair("amount", (double) it->second / COIN)); - addresses.push_back(obj); + + typedef std::function, std::pair)> Comparator; + Comparator compFunctor = [](std::pair elem1 ,std::pair elem2) { + return elem1.second > elem2.second; /* descending */ + }; + // This is our intermediate data structure that allows us to calculate addressSorted + std::set, Comparator> sortedSnapshot(addressAmounts.begin(), addressAmounts.end(), compFunctor); + + UniValue obj(UniValue::VOBJ); + UniValue addressesSorted(UniValue::VARR); + for (std::pair element : sortedSnapshot) { + UniValue obj(UniValue::VOBJ); + obj.push_back( make_pair("addr", element.first.c_str() ) ); + std::ostringstream strs; + strs << ((double) element.second/COIN); + std::string amount = strs.str(); + + //std::string amount = boost::lexical_cast((double) element.second/COIN); + //sprintf(amount, "%.8f", (double) element.second / COIN); + obj.push_back( make_pair("amount", amount) ); + addressesSorted.push_back(obj); } - result.push_back(make_pair("addresses", addresses)); + result.push_back(make_pair("addresses", addressesSorted)); result.push_back(make_pair("total", total / COIN )); result.push_back(make_pair("average",(double) (total/COIN) / totalAddresses )); + // Total number of addresses in this snaphot result.push_back(make_pair("total_addresses", totalAddresses)); - result.push_back(make_pair("height", chainActive.Height())); + // The snapshot began at this block height + result.push_back(make_pair("start_height", startingHeight)); + // The snapshot finished at this block height + result.push_back(make_pair("ending_height", chainActive.Height())); return(result); } From 3eb535b8b4c61e63027611aaf02f3a4dcae9626b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 22:31:06 +0000 Subject: [PATCH 0492/1123] Include start_time+end_time and correctly format amount --- src/main.cpp | 1 + src/rpcmisc.cpp | 3 +-- src/txdb.cpp | 15 +++------------ 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index dfebfec4f..11bc3a352 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -592,6 +592,7 @@ UniValue komodo_snapshot() { int64_t total = -1; UniValue result(UniValue::VOBJ); + if (fAddressIndex) { if ( pblocktree != 0 ) { result = pblocktree->Snapshot(); diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index 198b41090..01bd813e6 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -1028,8 +1028,7 @@ UniValue getsnapshot(const UniValue& params, bool fHelp) } result = komodo_snapshot(); if ( result.size() > 0 ) { - // add timestamp, maybe block height? - result.push_back(Pair("time", time(NULL))); + result.push_back(Pair("end_time", time(NULL))); } else { result.push_back(Pair("error", "no addressindex")); } diff --git a/src/txdb.cpp b/src/txdb.cpp index b4ea54f9b..2360ed340 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -405,18 +405,13 @@ extern UniValue CBlockTreeDB::Snapshot() boost::scoped_ptr pcursor(NewIterator()); std::map addressAmounts; UniValue result(UniValue::VOBJ); + result.push_back(Pair("start_time", time(NULL))); //pcursor->SeekToFirst(); pcursor->SeekToLast(); int64_t startingHeight = chainActive.Height(); - // prevent any node updates so we can get a consistent snapshot at this height - // causes coredumps - // LOCK(cs_main); - // does not compile - //LOCK(cs_wallet); - while (pcursor->Valid()) { boost::this_thread::interruption_point(); @@ -476,12 +471,8 @@ extern UniValue CBlockTreeDB::Snapshot() for (std::pair element : sortedSnapshot) { UniValue obj(UniValue::VOBJ); obj.push_back( make_pair("addr", element.first.c_str() ) ); - std::ostringstream strs; - strs << ((double) element.second/COIN); - std::string amount = strs.str(); - - //std::string amount = boost::lexical_cast((double) element.second/COIN); - //sprintf(amount, "%.8f", (double) element.second / COIN); + char amount[32]; + sprintf(amount, "%.8f", (double) element.second / COIN); obj.push_back( make_pair("amount", amount) ); addressesSorted.push_back(obj); } From 539080b3a4109285dc1a3b77fb5a15e782d7cc7e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 17 Jul 2018 22:33:19 +0000 Subject: [PATCH 0493/1123] Less noise to stderr --- src/txdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 2360ed340..cb0358403 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -435,7 +435,7 @@ extern UniValue CBlockTreeDB::Snapshot() std::map ::iterator pos = addressAmounts.find(address); if (pos == addressAmounts.end()) { // insert new address + utxo amount - fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); + //fprintf(stderr, "inserting new address %s with amount %li\n", address.c_str(), nValue); addressAmounts[address] = nValue; totalAddresses++; } else { From 4ac134db0c5c0e7e99222bfd3f2fb62f255094eb Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Wed, 18 Jul 2018 02:34:10 -0400 Subject: [PATCH 0494/1123] change zcashd reference, update example conf --- contrib/debian/examples/komodo.conf | 140 ++++++++++++++++++++++++++++ src/bitcoind.cpp | 12 +-- 2 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 contrib/debian/examples/komodo.conf diff --git a/contrib/debian/examples/komodo.conf b/contrib/debian/examples/komodo.conf new file mode 100644 index 000000000..656a43533 --- /dev/null +++ b/contrib/debian/examples/komodo.conf @@ -0,0 +1,140 @@ +## +## komodo.conf configuration file. Lines beginning with # are comments. +## + +# Network-related settings: + +# Run a regression test network +#regtest=0 + +# Connect via a SOCKS5 proxy +#proxy=127.0.0.1:9050 + +# Bind to given address and always listen on it. Use [host]:port notation for IPv6 +#bind= + +# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6 +#whitebind= + +############################################################## +## Quick Primer on addnode vs connect ## +## Let's say for instance you use addnode=4.2.2.4 ## +## addnode will connect you to and tell you about the ## +## nodes connected to 4.2.2.4. In addition it will tell ## +## the other nodes connected to it that you exist so ## +## they can connect to you. ## +## connect will not do the above when you 'connect' to it. ## +## It will *only* connect you to 4.2.2.4 and no one else.## +## ## +## So if you're behind a firewall, or have other problems ## +## finding nodes, add some using 'addnode'. ## +## ## +## If you want to stay private, use 'connect' to only ## +## connect to "trusted" nodes. ## +## ## +## If you run multiple nodes on a LAN, there's no need for ## +## all of them to open lots of connections. Instead ## +## 'connect' them all to one node that is port forwarded ## +## and has lots of connections. ## +## Thanks goes to [Noodle] on Freenode. ## +############################################################## + +# Use as many addnode= settings as you like to connect to specific peers +#addnode=69.164.218.197 +#addnode=10.0.0.2:8233 + +# Alternatively use as many connect= settings as you like to connect ONLY to specific peers +#connect=69.164.218.197 +#connect=10.0.0.1:8233 + +# Listening mode, enabled by default except when 'connect' is being used +#listen=1 + +# Maximum number of inbound+outbound connections. +#maxconnections= + +# +# JSON-RPC options (for controlling a running Komodo/komodod process) +# + +# server=1 tells komodod to accept JSON-RPC commands (set as default if not specified) +#server=1 + +# Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6. +# This option can be specified multiple times (default: bind to all interfaces) +#rpcbind= + +# You must set rpcuser and rpcpassword to secure the JSON-RPC api +#rpcuser=Ulysses +#rpcpassword=YourSuperGreatPasswordNumber_DO_NOT_USE_THIS_OR_YOU_WILL_GET_ROBBED_385593 + +# How many seconds komodo will wait for a complete RPC HTTP request. +# after the HTTP connection is established. +#rpcclienttimeout=30 + +# By default, only RPC connections from localhost are allowed. +# Specify as many rpcallowip= settings as you like to allow connections from other hosts, +# either as a single IPv4/IPv6 or with a subnet specification. + +# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED, +# because the rpcpassword is transmitted over the network unencrypted and also because anyone +# that can authenticate on the RPC port can steal your keys + take over the account running komodod +# For more information see https://github.com/zcash/zcash/issues/1497 + +#rpcallowip=10.1.1.34/255.255.255.0 +#rpcallowip=1.2.3.4/24 +#rpcallowip=2001:db8:85a3:0:0:8a2e:370:7334/96 + +# Listen for RPC connections on this TCP port: +#rpcport=8232 + +# You can use Komodo or komodod to send commands to Komodo/komodod +# running on another host using this option: +#rpcconnect=127.0.0.1 + +# Transaction Fee + +# Send transactions as zero-fee transactions if possible (default: 0) +#sendfreetransactions=0 + +# Create transactions that have enough fees (or priority) so they are likely to # begin confirmation within n blocks (default: 1). +# This setting is overridden by the -paytxfee option. +#txconfirmtarget=n + +# Miscellaneous options + +# Enable attempt to mine komodo. +#gen=0 + +# Set the number of threads to be used for mining komodo (-1 = all cores). +#genproclimit=1 + +# Specify a different Equihash solver (e.g. "tromp") to try to mine komodo +# faster when gen=1. +#equihashsolver=default + +# Pre-generate this many public/private key pairs, so wallet backups will be valid for +# both prior transactions and several dozen future transactions. +#keypool=100 + +# Pay an optional transaction fee every time you send komodo. Transactions with fees +# are more likely than free transactions to be included in generated blocks, so may +# be validated sooner. This setting does not affect private transactions created with +# 'z_sendmany'. +#paytxfee=0.00 + +#Rewind the chain to specific block height. This is useful for creating snapshots at a given block height. +#rewind=777777 + +#Stop the chain a specific block height. This is useful for creating snapshots at a given block height. +#stopat=1000000 + +#Set an address to use as change address for all transactions. This value must be set to a 33 byte pubkey. All mined coins will also be sent to this address. +#pubkey=027dc7b5cfb5efca96674b45e9fda18df069d040b9fd9ff32c35df56005e330392 + +#Forfeit all user rewards to miners. Set this to explicitly not claim user rewards. +#exchange=1 + +#Donate all user rewards to a a specific address. This value must be set to a 33 byte pubkey. +#donation=027dc7b5cfb5efca96674b45e9fda18df069d040b9fd9ff32c35df56005e330392 + diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 5c12cfa2f..36fea57bf 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -144,21 +144,21 @@ bool AppInit(int argc, char* argv[]) ReadConfigFile(mapArgs, mapMultiArgs); } catch (const missing_zcash_conf& e) { fprintf(stderr, - (_("Before starting zcashd, you need to create a configuration file:\n" + (_("Before starting komodod, you need to create a configuration file:\n" "%s\n" "It can be completely empty! That indicates you are happy with the default\n" - "configuration of zcashd. But requiring a configuration file to start ensures\n" - "that zcashd won't accidentally compromise your privacy if there was a default\n" + "configuration of komodod. But requiring a configuration file to start ensures\n" + "that komodod won't accidentally compromise your privacy if there was a default\n" "option you needed to change.\n" "\n" "You can look at the example configuration file for suggestions of default\n" "options that you may want to change. It should be in one of these locations,\n" - "depending on how you installed Zcash:\n") + + "depending on how you installed Komodo:\n") + _("- Source code: %s\n" "- .deb package: %s\n")).c_str(), GetConfigFile().string().c_str(), - "contrib/debian/examples/zcash.conf", - "/usr/share/doc/zcash/examples/zcash.conf"); + "contrib/debian/examples/komodo.conf", + "/usr/share/doc/komodo/examples/komodo.conf"); return false; } catch (const std::exception& e) { fprintf(stderr,"Error reading configuration file: %s\n", e.what()); From 9ef7fec1efd4f45ca603fbd7a25aa2beae4a5f64 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 18 Jul 2018 06:54:43 +0000 Subject: [PATCH 0495/1123] Protect komodo_snapshot() by cs_main lock --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 1376c3c7b..aa4435843 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -590,6 +590,7 @@ CBlockTreeDB *pblocktree = NULL; UniValue komodo_snapshot() { + LOCK(cs_main); int64_t total = -1; UniValue result(UniValue::VOBJ); From f345b95386d1ac73bc136b549dbf6f41e1854b86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Jul 2018 03:02:37 -1100 Subject: [PATCH 0496/1123] Initial assets --- src/cc/assets.cpp | 191 ++++++++++++++++++++ src/cc/betprotocol.cpp | 15 ++ src/cc/betprotocol.h | 15 ++ src/cc/eval.cpp | 19 ++ src/cc/eval.h | 19 +- src/cc/import.cpp | 15 ++ src/cc/utils.h | 15 ++ src/cryptoconditions/src/anon.c | 14 ++ src/cryptoconditions/src/cryptoconditions.c | 15 ++ src/cryptoconditions/src/ed25519.c | 15 ++ src/cryptoconditions/src/eval.c | 15 ++ src/cryptoconditions/src/internal.h | 15 ++ src/cryptoconditions/src/json_rpc.c | 15 ++ src/cryptoconditions/src/prefix.c | 14 ++ src/cryptoconditions/src/preimage.c | 14 ++ src/cryptoconditions/src/threshold.c | 14 ++ src/cryptoconditions/src/utils.c | 15 ++ 17 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 src/cc/assets.cpp diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp new file mode 100644 index 000000000..1e7dc61a8 --- /dev/null +++ b/src/cc/assets.cpp @@ -0,0 +1,191 @@ +/****************************************************************************** + * Copyright © 2014-2018 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +#include +#include