From ca55a347103c3908bbc04c3f6ffa37ef83bba69f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 07:48:23 -1100 Subject: [PATCH 01/11] zmigrate COIN sapling --- src/cc/dapps/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dapps/README.md b/src/cc/dapps/README.md index 0d8b2cac2..d59878d47 100644 --- a/src/cc/dapps/README.md +++ b/src/cc/dapps/README.md @@ -12,7 +12,7 @@ This tool converts Sprout zaddress funds into Sapling funds in a new Sapling add ### Usage - ./zmigrate zsaplingaddr + ./zmigrate COIN zsaplingaddr The above command may need to be run multiple times to complete the process. From 2c8363bb86525fa1a3ac5d9a2fd1c5b915cbc83e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 08:18:10 -1100 Subject: [PATCH 02/11] Revalidate sapling activation height --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 55beec474..dab6222ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4920,7 +4920,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) { - if ( ASSETCHAINS_CC == 0 ) + if ( ASSETCHAINS_CC == 0 && pindex->nHeight != mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); else { From d8e9a8a51c434cf1609a88851dff5029e1ad94fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 08:19:03 -1100 Subject: [PATCH 03/11] Use GetHeight() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index dab6222ab..e51be9ce6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4920,7 +4920,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) { - if ( ASSETCHAINS_CC == 0 && pindex->nHeight != mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) + if ( ASSETCHAINS_CC == 0 && pindex->GetHeight() != mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); else { From 4bb4b495935a33b4170b4c83e08909b8afa87384 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 08:20:35 -1100 Subject: [PATCH 04/11] Params().GetConsensus().vUpgrades --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e51be9ce6..e5293b1f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4920,7 +4920,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) { - if ( ASSETCHAINS_CC == 0 && pindex->GetHeight() != mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) + if ( ASSETCHAINS_CC == 0 && pindex->GetHeight() != Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); else { From d8657dcd177543a093cc005c0a5c1365cc962633 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 08:27:57 -1100 Subject: [PATCH 05/11] Reconsider before sapling activation --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e5293b1f5..bb5efa0e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4920,7 +4920,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) { - if ( ASSETCHAINS_CC == 0 && pindex->GetHeight() != Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) + if ( ASSETCHAINS_CC == 0 && KOMODO_INSYNC > Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); else { From ec6c22d86d666f38718173d4a93b6d87251acb61 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 08:36:27 -1100 Subject: [PATCH 06/11] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bb5efa0e6..6bc50a646 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1080,7 +1080,7 @@ bool ContextualCheckTransaction( // Reject transactions intended for Sprout if (!tx.fOverwintered) { int32_t ht = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight; - return state.DoS((ht < 0 || nHeight < ht) ? 0 : dosLevel, error("ContextualCheckTransaction: overwinter is active"),REJECT_INVALID, "tx-overwinter-active"); + return state.DoS((ASSETCHAINS_PRIVATE != 0 || ht < 0 || nHeight < ht) ? 0 : dosLevel, error("ContextualCheckTransaction: overwinter is active"),REJECT_INVALID, "tx-overwinter-active"); } // Check that all transactions are unexpired @@ -4920,7 +4920,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) { - if ( ASSETCHAINS_CC == 0 && KOMODO_INSYNC > Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight ) + if ( ASSETCHAINS_CC == 0 && (ASSETCHAINS_PRIVATE == 0 || KOMODO_INSYNC >= Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); else { From 0d4c230f4947572af2c4f4c8b3525e86838ebfa4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 08:51:26 -1100 Subject: [PATCH 07/11] Test --- src/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 6bc50a646..cba9ffe5c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1076,10 +1076,13 @@ bool ContextualCheckTransaction( } // Rules that apply to Overwinter or later: - if (overwinterActive) { + if (overwinterActive) + { // Reject transactions intended for Sprout - if (!tx.fOverwintered) { + if (!tx.fOverwintered) + { int32_t ht = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight; + fprintf(stderr,"overwinter is active tx.%s not, ht.%d vs %d\n",tx.GetHash().ToString(),nHeight,ht); return state.DoS((ASSETCHAINS_PRIVATE != 0 || ht < 0 || nHeight < ht) ? 0 : dosLevel, error("ContextualCheckTransaction: overwinter is active"),REJECT_INVALID, "tx-overwinter-active"); } From bf064209466feebeac323efd5dded2d9c4f7981f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 08:53:55 -1100 Subject: [PATCH 08/11] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cba9ffe5c..f26385689 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1082,7 +1082,7 @@ bool ContextualCheckTransaction( if (!tx.fOverwintered) { int32_t ht = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight; - fprintf(stderr,"overwinter is active tx.%s not, ht.%d vs %d\n",tx.GetHash().ToString(),nHeight,ht); + fprintf(stderr,"overwinter is active tx.%s not, ht.%d vs %d\n",tx.GetHash().ToString().c_str(),nHeight,ht); return state.DoS((ASSETCHAINS_PRIVATE != 0 || ht < 0 || nHeight < ht) ? 0 : dosLevel, error("ContextualCheckTransaction: overwinter is active"),REJECT_INVALID, "tx-overwinter-active"); } From 77528e4ebb269b57552423c241fb6954429e2312 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 15:00:22 -1100 Subject: [PATCH 09/11] Track sprout funds in coin supply --- src/komodo_bitcoind.h | 7 +++++-- src/main.cpp | 2 +- src/rpc/misc.cpp | 10 ++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 096590563..8223d3af3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1851,9 +1851,9 @@ int32_t komodo_acpublic(uint32_t tiptime) return(acpublic); } -int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) +int64_t komodo_newcoins(int64_t *zfundsp,int64_t *sproutfundsp,int32_t nHeight,CBlock *pblock) { - CTxDestination address; 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,sproutfunds=0; n = pblock->vtx.size(); for (i=0; i 100000*SATOSHIDEN || voutsum-vinsum+zfunds < 0 ) diff --git a/src/main.cpp b/src/main.cpp index f26385689..c811fa65f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4923,7 +4923,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat *ppindex = pindex; if ( pindex != 0 && pindex->nStatus & BLOCK_FAILED_MASK ) { - if ( ASSETCHAINS_CC == 0 && (ASSETCHAINS_PRIVATE == 0 || KOMODO_INSYNC >= Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) ) + if ( ASSETCHAINS_CC == 0 )//&& (ASSETCHAINS_PRIVATE == 0 || KOMODO_INSYNC >= Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) ) return state.Invalid(error("%s: block is marked invalid", __func__), 0, "duplicate"); else { diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 26c273236..7bfb98f7b 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -54,7 +54,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(int64_t *zfundsp,int32_t height); +int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); #define KOMODO_VERSION "0.3.1" #define VERUS_VERSION "0.4.0g" @@ -282,7 +282,7 @@ public: UniValue coinsupply(const UniValue& params, bool fHelp) { - int32_t height = 0; int32_t currentHeight; int64_t zfunds,supply = 0; UniValue result(UniValue::VOBJ); + int32_t height = 0; int32_t currentHeight; int64_t sproutfunds,zfunds,supply = 0; UniValue result(UniValue::VOBJ); if (fHelp || params.size() > 1) throw runtime_error("coinsupply \n" "\nReturn coin supply information at a given block height. If no height is given, the current height is used.\n" @@ -295,7 +295,8 @@ UniValue coinsupply(const UniValue& params, bool fHelp) " \"height\" : 420, (integer) The height of this coin supply data\n" " \"supply\" : \"777.0\", (float) The transparent coin supply\n" " \"zfunds\" : \"0.777\", (float) The shielded coin supply (in zaddrs)\n" - " \"total\" : \"777.777\", (float) The total coin supply, i.e. sum of supply + zfunds\n" + " \"sprout\" : \"0.077\", (float) The sprout coin supply (in zcaddrs)\n" + " \"total\" : \"777.777\", (float) The total coin supply, i.e. sum of supply + zfunds\n" "}\n" "\nExamples:\n" + HelpExampleCli("coinsupply", "420") @@ -307,13 +308,14 @@ UniValue coinsupply(const UniValue& params, bool fHelp) currentHeight = chainActive.Height(); if (height >= 0 && height <= currentHeight) { - if ( (supply= komodo_coinsupply(&zfunds,height)) > 0 ) + if ( (supply= komodo_coinsupply(&zfunds,&sproutfunds,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))); + result.push_back(Pair("sprout", ValueFromAmount(sproutfunds))); result.push_back(Pair("total", ValueFromAmount(zfunds + supply))); } else result.push_back(Pair("error", "couldnt calculate supply")); } else { From 349122749448c41a2447979d6e10d8ed036147ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 15 Dec 2018 15:03:24 -1100 Subject: [PATCH 10/11] Sprout funds --- src/chain.h | 2 +- src/komodo_bitcoind.h | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/chain.h b/src/chain.h index 95553c23c..0b6e2b046 100644 --- a/src/chain.h +++ b/src/chain.h @@ -219,7 +219,7 @@ public: CBlockIndex* pskip; //! height of the entry in the chain. The genesis block has height 0 - int64_t newcoins,zfunds; int8_t segid; // jl777 fields + int64_t newcoins,zfunds,sproutfunds; int8_t segid; // jl777 fields //! Which # file this block is stored in (blk?????.dat) int nFile; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8223d3af3..add4f4e7f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1907,11 +1907,11 @@ int64_t komodo_newcoins(int64_t *zfundsp,int64_t *sproutfundsp,int32_t nHeight,C return(voutsum - vinsum); } -int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) +int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height) { - CBlockIndex *pindex; CBlock block; int64_t zfunds=0,supply = 0; + CBlockIndex *pindex; CBlock block; int64_t zfunds=0,sproutfunds=0,supply = 0; //fprintf(stderr,"coinsupply %d\n",height); - *zfundsp = 0; + *zfundsp = *sproutfundsp = 0; if ( (pindex= komodo_chainactive(height)) != 0 ) { while ( pindex != 0 && pindex->GetHeight() > 0 ) @@ -1919,7 +1919,7 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) if ( pindex->newcoins == 0 && pindex->zfunds == 0 ) { if ( komodo_blockload(block,pindex) == 0 ) - pindex->newcoins = komodo_newcoins(&pindex->zfunds,pindex->GetHeight(),&block); + pindex->newcoins = komodo_newcoins(&pindex->zfunds,&pindex->sproutfunds,pindex->GetHeight(),&block); else { fprintf(stderr,"error loading block.%d\n",pindex->GetHeight()); @@ -1928,10 +1928,12 @@ int64_t komodo_coinsupply(int64_t *zfundsp,int32_t height) } supply += pindex->newcoins; zfunds += pindex->zfunds; + sproutfunds += pindex->sproutfunds; //printf("start ht.%d new %.8f -> supply %.8f zfunds %.8f -> %.8f\n",pindex->GetHeight(),dstr(pindex->newcoins),dstr(supply),dstr(pindex->zfunds),dstr(zfunds)); pindex = pindex->pprev; } } *zfundsp = zfunds; + *sproutfundsp = sproutfunds; return(supply); } From 6955ce6de7e8105c738e7ca5629f86f77d26b209 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 16 Dec 2018 03:31:35 -1100 Subject: [PATCH 11/11] Prevent fractional migrate --- src/cc/dapps/zmigrate.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 84cf4b057..a857623a5 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -940,6 +940,11 @@ again: if ( amount == lastamount3 && amount == lastamount4 ) stdamount /= 10; } + if ( stdamount < COIN ) + { + stdamount = COIN; + refamount = COIN * 50; + } if ( stdamount < refamount ) refamount = stdamount; lastamount4 = lastamount3;