From 5b6a65f30a86e816166351e1c1292b8e37cfcf75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 Jan 2019 07:30:00 -1100 Subject: [PATCH 001/122] -prints --- 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 6e5bc5b83..79710969a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2979,7 +2979,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { // TODO: should we throw JSONRPCError ? fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); @@ -3013,7 +3013,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { // TODO: should we throw JSONRPCError ? fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); @@ -3804,7 +3804,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); } @@ -3836,7 +3836,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) BlockMap::const_iterator it = mapBlockIndex.find(hashBlock); if (it != mapBlockIndex.end()) { nHeight = it->second->GetHeight(); - fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); + //fprintf(stderr,"blockHash %s height %d\n",hashBlock.ToString().c_str(), nHeight); } else { fprintf(stderr,"block hash %s does not exist!\n", hashBlock.ToString().c_str() ); } From 9392a2b9ecbbd3f2c802df817eb56cfa1e1b1081 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Sat, 12 Jan 2019 15:27:17 +0700 Subject: [PATCH 002/122] oracles autotests fixed --- qa/rpc-tests/cryptoconditions_oracles.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py index f295bf020..048b577d1 100755 --- a/qa/rpc-tests/cryptoconditions_oracles.py +++ b/qa/rpc-tests/cryptoconditions_oracles.py @@ -112,17 +112,15 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): # baton oraclesdata_d = self.send_and_mine(result["hex"], rpc) result = rpc.oraclessamples(globals()["oracle_{}".format("d")], oraclesdata_d, "1") - # TODO: working not correct now! - #assert_equal("[u'01']", str(result["samples"][0]), "Data match") + assert_equal("[u'01']", str(result["samples"][0]), "Data match") # D type - result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "0101") + result = rpc.oraclesdata(globals()["oracle_{}".format("D")], "010001") assert_success(result) # baton oraclesdata_D = self.send_and_mine(result["hex"], rpc) result = rpc.oraclessamples(globals()["oracle_{}".format("D")], oraclesdata_D, "1") - # TODO: working not correct now! - #assert_equal("[u'01']", str(result["samples"][0]), "Data match") + assert_equal("[u'01']", str(result["samples"][0]), "Data match") # c type result = rpc.oraclesdata(globals()["oracle_{}".format("c")], "ff") @@ -198,12 +196,12 @@ class CryptoconditionsOraclesTest(CryptoconditionsTestFramework): assert_equal("[u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") # Ihh type - result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff") + result = rpc.oraclesdata(globals()["oracle_{}".format("Ihh")], "ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000ffffffff") assert_success(result) # baton oraclesdata_Ihh = self.send_and_mine(result["hex"], rpc) result = rpc.oraclessamples(globals()["oracle_{}".format("Ihh")], oraclesdata_Ihh, "1") - assert_equal("[u'0']", str(result["samples"][0]), "Data match") + assert_equal("[u'4294967295', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000', u'ffffffff00000000ffffffff00000000ffffffff00000000ffffffff00000000']", str(result["samples"][0]), "Data match") def run_test(self): From 2bde89c9ce4b3ae6d068a47bc3e2d43c070d829e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:29:37 -1100 Subject: [PATCH 003/122] Marmara coinbase initial impl --- src/cc/CCMarmara.h | 5 ++++ src/cc/marmara.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ src/chainparams.cpp | 2 +- src/komodo_gateway.h | 10 +++++++ src/komodo_globals.h | 2 +- src/komodo_utils.h | 5 +++- 6 files changed, 85 insertions(+), 3 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 45fda83bd..5fc7fd673 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -19,6 +19,11 @@ #include "CCinclude.h" +#define MARMARA_GROUPSIZE 60 +#define MARMARA_MINLOCK (1440 * 3 * 30) +#define MARMARA_MAXLOCK (1440 * 24 * 30) +uint64_t komodo_block_prg(uint32_t nHeight); + bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); // CCcustom diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4bbccee4a..0f166e5df 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -71,6 +71,70 @@ bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio else return(true); } +int32_t MarmaraRandomize(uint32_t ind) +{ + uint64_t val64; uint32_t val,range = (MARMARA_MAXLOCK - MARMARA_MINLOCK); + val64 = komodo_block_prg(ind); + val = (uint32_t)(val64 >> 32); + val ^= (uint32_t)val64; + return(val % range); +} + +int32_t MarmaraUnlockht(int32_t height) +{ + uint32_t ind = height / MARMARA_GROUPSIZE; + return(height + MarmaraRandomize(ind)); +} + +CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t height) +{ + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; + unlockht = MarmaraUnlockht(ht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << height << unlockht); + return(opret); +} + +uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlckht) +{ + std::vector vopret; uint8_t *script,e,f,funcid; + GetOpReturnData(scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) + { + if ( script[1] == 'C' ) + { + if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) + { + return(script[1]); + } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); + } + } + return(0); +} + +int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) +{ + struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; + cp = CCinit(&C,EVAL_MARMARA); + for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) + fprintf(stderr,"%d ",MarmaraUnlockht(ht)); + fprintf(stderr,"<- unlock hts\n"); + if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) + { + if ( DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' ) + { + if ( ht == height && MarmaraUnlockht(height) == unlockht ) + { + ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) + return(0); + fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); + } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); + } else fprintf(stderr,"ht.%d error decoding coinbase opret\n"); + } + return(-1); +} + bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 23d900d4e..47f4d48a8 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -107,7 +107,7 @@ public: strNetworkID = "main"; strCurrencyUnits = "KMD"; - bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md (ZCASH, should be VRSC) + bip44CoinType = 141; // As registered in https://github.com/satoshilabs/slips/blob/master/slip-0044.md consensus.fCoinbaseMustBeProtected = false; // true this is only true wuth Verus and enforced after block 12800 consensus.nSubsidySlowStartInterval = 20000; consensus.nSubsidyHalvingInterval = 840000; diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 982f16b0b..360ddfcc0 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -16,6 +16,8 @@ // paxdeposit equivalent in reverse makes opreturn and KMD does the same in reverse #include "komodo_defs.h" +int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx); + int32_t pax_fiatstatus(uint64_t *available,uint64_t *deposited,uint64_t *issued,uint64_t *withdrawn,uint64_t *approved,uint64_t *redeemed,char *base) { int32_t baseid; struct komodo_state *sp; int64_t netliability,maxallowed,maxval; @@ -687,6 +689,14 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } } } + if ( ASSETCHAINS_MARMARA != 0 && (height & 1) != 0 ) + { + if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) + { + fprintf(stderr,"MARMARA constrains odd height blocks to pay 100% to CC in vout0\n"); + return(-1); + } + } // we don't want these checks in VRSC, leave it at the Sapling upgrade if ( ASSETCHAINS_SYMBOL[0] == 0 || (ASSETCHAINS_COMMISSION != 0 && height > 1) || diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 8a72b5ad7..f434674b7 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -49,7 +49,7 @@ unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; int32_t KOMODO_MININGTHREADS = -1,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,KOMODO_CONNECTING = -1,KOMODO_DEALERNODE,KOMODO_EXTRASATOSHI,ASSETCHAINS_FOUNDERS; int32_t KOMODO_INSYNC,KOMODO_LASTMINED,prevKOMODO_LASTMINED,KOMODO_CCACTIVATE,JUMBLR_PAUSE = 1; std::string NOTARY_PUBKEY,ASSETCHAINS_NOTARIES,ASSETCHAINS_OVERRIDE_PUBKEY,DONATION_PUBKEY,ASSETCHAINS_SCRIPTPUB,ASSETCHAINS_SELFIMPORT; -uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW; +uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEYHASH[20],ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE,ASSETCHAINS_TXPOW,ASSETCHAINS_MARMARA; bool VERUS_MINTBLOCKS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index a5b22e592..55b9bec35 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1778,6 +1778,7 @@ void komodo_args(char *argv0) ASSETCHAINS_SCRIPTPUB = GetArg("-ac_script",""); ASSETCHAINS_BEAMPORT = GetArg("-ac_beam",0); ASSETCHAINS_CODAPORT = GetArg("-ac_coda",0); + ASSETCHAINS_MARMARA = GetArg("-ac_marmara",0); if ( ASSETCHAINS_BEAMPORT != 0 && ASSETCHAINS_CODAPORT != 0 ) { fprintf(stderr,"can only have one of -ac_beam or -ac_coda\n"); @@ -1857,7 +1858,7 @@ void komodo_args(char *argv0) printf("ASSETCHAINS_FOUNDERS needs an ASETCHAINS_OVERRIDE_PUBKEY\n"); } } - if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 ) + if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); extraptr = extrabuf; @@ -1931,6 +1932,8 @@ void komodo_args(char *argv0) extraptr[extralen++] = 'b'; if ( ASSETCHAINS_CODAPORT != 0 ) extraptr[extralen++] = 'c'; + if ( ASSETCHAINS_MARMARA != 0 ) + extraptr[extralen++] = ASSETCHAINS_MARMARA; } addn = GetArg("-seednode",""); From 2515d72e58e6d8606344476da150cd43c0e3447b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:32:20 -1100 Subject: [PATCH 004/122] Syntax --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 0f166e5df..1a67b4df6 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -86,15 +86,15 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t height) +CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << height << unlockht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); return(opret); } -uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlckht) +uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int32_t &height,int32_t &unlockht) { std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); @@ -130,7 +130,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) return(0); fprintf(stderr,"ht.%d mismatched CCvout scriptPubKey\n",height); } else fprintf(stderr,"ht.%d %d vs %d unlock.%d\n",height,MarmaraUnlockht(height),ht,unlockht); - } else fprintf(stderr,"ht.%d error decoding coinbase opret\n"); + } else fprintf(stderr,"ht.%d error decoding coinbase opret\n",height); } return(-1); } From 99f0709686d756806394ef7fd07472529d1ab1f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:34:24 -1100 Subject: [PATCH 005/122] 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 360ddfcc0..0ad1b66ad 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -693,7 +693,7 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim { if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) { - fprintf(stderr,"MARMARA constrains odd height blocks to pay 100% to CC in vout0\n"); + fprintf(stderr,"MARMARA constrains odd height blocks to pay 100%% to CC in vout0 with opreturn\n"); return(-1); } } From c0a9c015adcc209562af07492d9f7bc4b097d0d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:37:41 -1100 Subject: [PATCH 006/122] Even heights with constraint so ac_supply is unlocked --- src/cc/marmara.cpp | 2 ++ src/komodo_gateway.h | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1a67b4df6..359092ef9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -119,6 +119,8 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) fprintf(stderr,"%d ",MarmaraUnlockht(ht)); fprintf(stderr,"<- unlock hts\n"); + if ( (height & 1) != 0 ) + return(0); if ( tx.vout.size() == 2 && tx.vout[1].nValue == 0 ) { if ( DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' ) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 0ad1b66ad..fcdf4b85e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -689,11 +689,11 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtim } } } - if ( ASSETCHAINS_MARMARA != 0 && (height & 1) != 0 ) + if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 ) { if ( MarmaraValidateCoinbase(height,block.vtx[0]) < 0 ) { - fprintf(stderr,"MARMARA constrains odd height blocks to pay 100%% to CC in vout0 with opreturn\n"); + fprintf(stderr,"MARMARA constrains even height blocks to pay 100%% to CC in vout0 with opreturn\n"); return(-1); } } From 5435d63aedd64fa8eb3abdf11d5872bdbe8331c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 00:57:16 -1100 Subject: [PATCH 007/122] Histogram --- src/cc/marmara.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 359092ef9..908e3557d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -116,9 +116,18 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - for (ht=0; ht<10000; ht+=MARMARA_GROUPSIZE/3) - fprintf(stderr,"%d ",MarmaraUnlockht(ht)); - fprintf(stderr,"<- unlock hts\n"); + int32_t d,histo[365*2]; + for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + { + memset(histo,0,sizeof(histo)); + d = (MarmaraUnlockht(ht) - ht) / 1440 + if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) + fprintf(stderr,"d error.%d at ht.%d\n",d,ht); + else histo[d]++; + } + for (ht=0; ht Date: Sat, 12 Jan 2019 00:57:55 -1100 Subject: [PATCH 008/122] ; --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 908e3557d..254b62efd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -120,7 +120,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { memset(histo,0,sizeof(histo)); - d = (MarmaraUnlockht(ht) - ht) / 1440 + d = (MarmaraUnlockht(ht) - ht) / 1440; if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) fprintf(stderr,"d error.%d at ht.%d\n",d,ht); else histo[d]++; From f816960557f9fe8e868bad5733372adf5023dc72 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:00:08 -1100 Subject: [PATCH 009/122] memset Outside loop --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 254b62efd..389ed0227 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -117,9 +117,9 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); int32_t d,histo[365*2]; + memset(histo,0,sizeof(histo)); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { - memset(histo,0,sizeof(histo)); d = (MarmaraUnlockht(ht) - ht) / 1440; if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) fprintf(stderr,"d error.%d at ht.%d\n",d,ht); @@ -127,7 +127,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) } for (ht=0; ht Date: Sat, 12 Jan 2019 01:03:22 -1100 Subject: [PATCH 010/122] += MARMARA_MINLOCK --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 389ed0227..dadbb9249 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -77,7 +77,7 @@ int32_t MarmaraRandomize(uint32_t ind) val64 = komodo_block_prg(ind); val = (uint32_t)(val64 >> 32); val ^= (uint32_t)val64; - return(val % range); + return((val % range) + MARMARA_MINLOCK); } int32_t MarmaraUnlockht(int32_t height) @@ -116,7 +116,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - int32_t d,histo[365*2]; + int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { From 9e55c207256cf83cc98aaa6c792ebb51ac2450d8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:08:17 -1100 Subject: [PATCH 011/122] -print --- src/cc/marmara.cpp | 23 +++++++++++++---------- src/komodo_gateway.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index dadbb9249..8cfd6f6de 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -116,18 +116,21 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - int32_t d,histo[365*2+30]; - memset(histo,0,sizeof(histo)); - for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + if ( 0 ) { - d = (MarmaraUnlockht(ht) - ht) / 1440; - if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) - fprintf(stderr,"d error.%d at ht.%d\n",d,ht); - else histo[d]++; + int32_t d,histo[365*2+30]; + memset(histo,0,sizeof(histo)); + for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) + { + d = (MarmaraUnlockht(ht) - ht) / 1440; + if ( d < 0 || d > sizeof(histo)/sizeof(*histo) ) + fprintf(stderr,"d error.%d at ht.%d\n",d,ht); + else histo[d]++; + } + for (ht=0; ht Date: Sat, 12 Jan 2019 01:36:01 -1100 Subject: [PATCH 012/122] Marmara coinbase opret --- src/cc/marmara.cpp | 29 +++++++++++++++++++++++++++++ src/miner.cpp | 14 ++++++++++++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8cfd6f6de..a7e9f2d1f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -112,6 +112,35 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(0); } +CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) +{ + CTxOut ccvout; uint8_t *ptr; CPubKey pk; + if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + { + ptr = (uint8_t *)pubkey.begin(); + if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) + pk = buf2pk(ptr+1); + ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); + return(ccvout.scriptPubKey); + } + return(scriptPubKey); +} + +CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) +{ + uint8_t *ptr; CPubKey pk; + if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + { + ptr = (uint8_t *)pubkey.begin(); + if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) + { + pk = buf2pk(ptr+1); + return(EncodeMarmaraCoinbaseOpRet(pk,height); + } + } + return(scriptPubKey); +} + int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; diff --git a/src/miner.cpp b/src/miner.cpp index 7948fd0cd..223972c80 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -141,7 +141,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; 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]; +extern uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_MARMARA; 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); @@ -155,6 +155,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); +CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey); +CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey); CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -534,7 +536,13 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator - if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + { + txNew.vout.resize(2); + txNew.vout[1].nValue = 0; + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,scriptPubKeyIn); + } + else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { int32_t opretlen, p2shlen, scriptlen; CScriptExt opretScript = CScriptExt(); @@ -775,6 +783,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } + if ( ASSETCHAINS_MARMARA != 0 ) + scriptPubKey = Marmara_scriptPubKey(height,scriptPubKey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 5b4ae1d702358a4cfc171ef599c2152d9e89fc31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:37:41 -1100 Subject: [PATCH 013/122] Fix --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a7e9f2d1f..93d24b868 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -115,9 +115,9 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) { CTxOut ccvout; uint8_t *ptr; CPubKey pk; - if ( height > 0 && ASSETCHAINS_MARMARA != 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) + if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)pubkey.begin(); + ptr = (uint8_t *)scriptPubKey.begin(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) pk = buf2pk(ptr+1); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); @@ -131,11 +131,11 @@ CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)pubkey.begin(); + ptr = (uint8_t *)scriptPubKey.begin(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) { pk = buf2pk(ptr+1); - return(EncodeMarmaraCoinbaseOpRet(pk,height); + return(EncodeMarmaraCoinbaseOpRet(pk,height)); } } return(scriptPubKey); From e656efa89c2c468921d2297f2bbcb2e474209c0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:38:30 -1100 Subject: [PATCH 014/122] data() --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 93d24b868..f25b0c62a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -117,7 +117,7 @@ CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) CTxOut ccvout; uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)scriptPubKey.begin(); + ptr = (uint8_t *)scriptPubKey.data(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) pk = buf2pk(ptr+1); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); @@ -131,7 +131,7 @@ CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) uint8_t *ptr; CPubKey pk; if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) { - ptr = (uint8_t *)scriptPubKey.begin(); + ptr = (uint8_t *)scriptPubKey.data(); if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) { pk = buf2pk(ptr+1); From 9a46e8a5774207d45950fcf7a83251d271a6f050 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:45:23 -1100 Subject: [PATCH 015/122] Use pk --- src/cc/marmara.cpp | 29 ++++++++--------------------- src/miner.cpp | 18 +++++++++++------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f25b0c62a..63a8bbe3b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -112,33 +112,20 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(0); } -CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey) +CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) { - CTxOut ccvout; uint8_t *ptr; CPubKey pk; - if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) - { - ptr = (uint8_t *)scriptPubKey.data(); - if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) - pk = buf2pk(ptr+1); + CTxOut ccvout; + if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); - return(ccvout.scriptPubKey); - } - return(scriptPubKey); + return(ccvout.scriptPubKey); } -CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey) +CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { uint8_t *ptr; CPubKey pk; - if ( height > 0 && (height & 1) == 0 && scriptPubKey.size() == 35 ) - { - ptr = (uint8_t *)scriptPubKey.data(); - if ( ptr[0] == 33 && ptr[34] == OP_CHECKSIG ) - { - pk = buf2pk(ptr+1); - return(EncodeMarmaraCoinbaseOpRet(pk,height)); - } - } - return(scriptPubKey); + if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) + return(EncodeMarmaraCoinbaseOpRet(pk,height)); + return(CScript()); } int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) diff --git a/src/miner.cpp b/src/miner.cpp index 223972c80..3322bbb16 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -155,8 +155,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits, arith_uint256 &hashResult, uint8_t *utxosig, CPubKey &pk); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); -CScript Marmara_scriptPubKey(int32_t height,CScript scriptPubKey); -CScript MarmaraCoinbaseOpret(int32_t height,CScript scriptPubKey); +CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); +CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -540,7 +540,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, { txNew.vout.resize(2); txNew.vout[1].nValue = 0; - txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,scriptPubKeyIn); + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,pk); } else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { @@ -751,7 +751,10 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 ) { if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) - scriptPubKey = CScript() << ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY) << OP_CHECKSIG; + { + pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); + scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + } else { len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); @@ -764,7 +767,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, else if ( USE_EXTERNAL_PUBKEY != 0 ) { //fprintf(stderr,"use notary pubkey\n"); - scriptPubKey = CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; + pubkey = ParseHex(NOTARY_PUBKEY); + scriptPubKey = CScript() << pubkey << OP_CHECKSIG; } else { @@ -783,8 +787,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } - if ( ASSETCHAINS_MARMARA != 0 ) - scriptPubKey = Marmara_scriptPubKey(height,scriptPubKey); + if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + scriptPubKey = Marmara_scriptPubKey(height,pubkey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 8b43e641290d0a4bdf34bfb035d2bd0a0b348c1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:45:57 -1100 Subject: [PATCH 016/122] Fx --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 63a8bbe3b..18ba87734 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -122,7 +122,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { - uint8_t *ptr; CPubKey pk; + uint8_t *ptr; if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); From 621be31f25d3473bc313fab756bd3fa3ea9b5751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:48:55 -1100 Subject: [PATCH 017/122] nHeight --- src/miner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3322bbb16..51078f963 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -536,7 +536,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator - if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) + if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) { txNew.vout.resize(2); txNew.vout[1].nValue = 0; @@ -753,7 +753,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); - scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } else { @@ -768,7 +768,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, { //fprintf(stderr,"use notary pubkey\n"); pubkey = ParseHex(NOTARY_PUBKEY); - scriptPubKey = CScript() << pubkey << OP_CHECKSIG; + scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; } else { @@ -787,8 +787,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, //scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; } } - if ( ASSETCHAINS_MARMARA != 0 && height > 0 && (height & 1) == 0 ) - scriptPubKey = Marmara_scriptPubKey(height,pubkey); + if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) + scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); return CreateNewBlock(scriptPubKey, gpucount, isStake); } From 4bb5c6cbd311b291ecf9a5259e68175974609a10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:54:01 -1100 Subject: [PATCH 018/122] EVAL_MARMARA --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 18ba87734..a069af713 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -88,7 +88,7 @@ int32_t MarmaraUnlockht(int32_t height) CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { - CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_ORACLES; + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); return(opret); @@ -107,8 +107,8 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 { return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); - } - } + } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); + } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",vopret.size(),script[0],EVAL_MARMARA); return(0); } From e1dd671e66eb2c243c562b8dff4ea9e12fdeed1f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 01:54:48 -1100 Subject: [PATCH 019/122] (Int32_t) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a069af713..41a85802e 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -108,7 +108,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); - } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",vopret.size(),script[0],EVAL_MARMARA); + } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",(int32_t)vopret.size(),script[0],EVAL_MARMARA); return(0); } From 8250a4bab83940782ef5b0331eb5ff719db58215 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:00:17 -1100 Subject: [PATCH 020/122] +print --- src/cc/marmara.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 41a85802e..9cb9ce813 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -91,6 +91,16 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + { + std::vector vopret; uint8_t *script,i; + GetOpReturnData(opret,vopret); + script = (uint8_t *)vopret.data(); + { + for (i=0; i vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); + { + int32_t i; + for (i=0; i 2 && script[0] == EVAL_MARMARA ) { if ( script[1] == 'C' ) @@ -108,7 +124,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); - } else fprintf(stderr,"vopret.size() is %d [0] is %d != %d\n",(int32_t)vopret.size(),script[0],EVAL_MARMARA); + } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } From cf2251127a9044097fbf667bb71b6d5336f1f34d Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:03:53 -1100 Subject: [PATCH 021/122] +prints --- src/cc/marmara.cpp | 1 + src/miner.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 9cb9ce813..d69585046 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -139,6 +139,7 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) { uint8_t *ptr; + fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); diff --git a/src/miner.cpp b/src/miner.cpp index 51078f963..62eb46f69 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -167,6 +167,7 @@ CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, txnouttype txT; if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) { + fprintf(stderr,"txT.%d vs TX_PUBKEY.%d\n",txT,TX_PUBKEY); if (txT == TX_PUBKEY) pk = CPubKey(vAddrs[0]); } From a06cbd09ae778f953d9e441de36a088ed2cc1684 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:10:49 -1100 Subject: [PATCH 022/122] Pass in _pk to CreateBlock --- src/miner.cpp | 23 +++++++++++++---------- src/miner.h | 2 +- src/test/miner_tests.cpp | 26 +++++++++++++------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 62eb46f69..c6df5cdb6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -158,19 +158,22 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); -CBlockTemplate* CreateNewBlock(const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) +CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { CScript scriptPubKeyIn(_scriptPubKeyIn); - CPubKey pk = CPubKey(); - std::vector> vAddrs; - txnouttype txT; - if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) + CPubKey pk; + if ( _pk.size() != 33 ) { - fprintf(stderr,"txT.%d vs TX_PUBKEY.%d\n",txT,TX_PUBKEY); - if (txT == TX_PUBKEY) - pk = CPubKey(vAddrs[0]); - } + pk = CPubKey(); + std::vector> vAddrs; + txnouttype txT; + if ( scriptPubKeyIn.size() > 0 && Solver(scriptPubKeyIn, txT, vAddrs)) + { + if (txT == TX_PUBKEY) + pk = CPubKey(vAddrs[0]); + } + } else pk = _pk; uint64_t deposits; int32_t isrealtime,kmdheight; uint32_t blocktime; const CChainParams& chainparams = Params(); //fprintf(stderr,"create new block\n"); @@ -790,7 +793,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); - return CreateNewBlock(scriptPubKey, gpucount, isStake); + return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake); } void komodo_broadcast(CBlock *pblock,int32_t limit) diff --git a/src/miner.h b/src/miner.h index 5494022bd..a3bedd292 100644 --- a/src/miner.h +++ b/src/miner.h @@ -43,7 +43,7 @@ struct CBlockTemplate #define KOMODO_MAXGPUCOUNT 65 /** Generate a new block, without valid proof-of-work */ -CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, int32_t gpucount, bool isStake = false); +CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& scriptPubKeyIn, int32_t gpucount, bool isStake = false); #ifdef ENABLE_WALLET boost::optional GetMinerScriptPubKey(CReserveKey& reservekey); CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake = false); diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 6d80fc4b7..277b726c8 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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); CBlock *pblock = &pblocktemplate->block; // pointer for convenience pblock->nVersion = 4; @@ -273,7 +273,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) } // Just to make sure we can still make simple blocks - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; // block sigops > limit: 1000 CHECKMULTISIG + 1 @@ -292,7 +292,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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -313,14 +313,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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -338,7 +338,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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -349,7 +349,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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -367,7 +367,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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); @@ -381,17 +381,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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; mempool.clear(); // subsidy changing int nHeight = chainActive.Height(); chainActive.Tip()->SetHeight(209999); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->SetHeight(210000); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); delete pblocktemplate; chainActive.Tip()->SetHeight(nHeight); @@ -423,7 +423,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,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); // Neither tx should have made it into the template. BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 1); @@ -438,7 +438,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) //BOOST_CHECK(CheckFinalTx(tx)); //BOOST_CHECK(CheckFinalTx(tx2)); - BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey,-1)); + BOOST_CHECK(pblocktemplate = CreateNewBlock(CPubKey(),scriptPubKey,-1)); BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 2); delete pblocktemplate; From 5a8af74e4ddc92784747ce5dbe7497ec4cd3c977 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:13:18 -1100 Subject: [PATCH 023/122] Include pubkey.h --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index c6df5cdb6..35ba20798 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -24,6 +24,7 @@ #endif #include "amount.h" +#include "pubkey.h" #include "chainparams.h" #include "importcoin.h" #include "consensus/consensus.h" From ad0842336bf9c45ea11e44c4170ba1e25de0bf17 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:13:32 -1100 Subject: [PATCH 024/122] First --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 35ba20798..fb9ed8820 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -18,13 +18,13 @@ * * ******************************************************************************/ +#include "pubkey.h" #include "miner.h" #ifdef ENABLE_MINING #include "pow/tromp/equi_miner.h" #endif #include "amount.h" -#include "pubkey.h" #include "chainparams.h" #include "importcoin.h" #include "consensus/consensus.h" From 0638d3b056c04e949004f0e5e3b2614a58604117 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:18:55 -1100 Subject: [PATCH 025/122] Map all unlock hts in group to same unlockht --- src/cc/marmara.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d69585046..8cd949981 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -83,6 +83,7 @@ int32_t MarmaraRandomize(uint32_t ind) int32_t MarmaraUnlockht(int32_t height) { uint32_t ind = height / MARMARA_GROUPSIZE; + height = (height / MARMARA_GROUPSIZE) * MARMARA_GROUPSIZE; return(height + MarmaraRandomize(ind)); } @@ -91,6 +92,7 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + if ( 0 ) { std::vector vopret; uint8_t *script,i; GetOpReturnData(opret,vopret); @@ -109,6 +111,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 std::vector vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); script = (uint8_t *)vopret.data(); + if ( 0 ) { int32_t i; for (i=0; i 0 && (height & 1) == 0 && pk.size() == 33 ) return(EncodeMarmaraCoinbaseOpRet(pk,height)); return(CScript()); @@ -149,10 +152,13 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - if ( 0 ) + if ( 1 ) { int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); + for (ht=2; ht<100; ht++) + fprintf(stderr,"%d ",MarmaraUnlockht(ht)); + fprintf(stderr," <- first 100 unlock heights\n"); for (ht=2; ht<1000000; ht+=MARMARA_GROUPSIZE) { d = (MarmaraUnlockht(ht) - ht) / 1440; From f3b0e439c38e96396720ebe03d8e83c0a73340c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 02:21:32 -1100 Subject: [PATCH 026/122] Test --- src/cc/marmara.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8cd949981..3c011ec02 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -152,7 +152,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { struct CCcontract_info *cp,C; CPubKey pk; int32_t ht,unlockht; CTxOut ccvout; cp = CCinit(&C,EVAL_MARMARA); - if ( 1 ) + if ( 0 ) { int32_t d,histo[365*2+30]; memset(histo,0,sizeof(histo)); @@ -178,6 +178,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { if ( ht == height && MarmaraUnlockht(height) == unlockht ) { + fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); From a0c16d089ac51644e0a25c7cf09458b6851d583e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:20:30 -1100 Subject: [PATCH 027/122] MarmaraPoolPayout --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 132 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 108 insertions(+), 25 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 5fc7fd673..15a8f811f 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -23,6 +23,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 3c011ec02..2167c1364 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -87,11 +87,11 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) +CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) { CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << 'C' << pk << ht << unlockht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); if ( 0 ) { std::vector vopret; uint8_t *script,i; @@ -100,13 +100,13 @@ CScript EncodeMarmaraCoinbaseOpRet(CPubKey pk,int32_t ht) { for (i=0; i vopret; uint8_t *script,e,f,funcid; GetOpReturnData(scriptPubKey,vopret); @@ -120,13 +120,13 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript &scriptPubKey,CPubKey &pk,int3 } if ( vopret.size() > 2 && script[0] == EVAL_MARMARA ) { - if ( script[1] == 'C' ) + if ( script[1] == 'C' || script[1] == 'P' ) { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { return(script[1]); - } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for C\n"); - } else fprintf(stderr,"script[1] is %d != 'C' %d\n",script[1],'C'); + } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); + } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); } else fprintf(stderr,"vopret.size() is %d\n",(int32_t)vopret.size()); return(0); } @@ -144,7 +144,7 @@ CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) uint8_t *ptr; //fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - return(EncodeMarmaraCoinbaseOpRet(pk,height)); + return(EncodeMarmaraCoinbaseOpRet('C',pk,height)); return(CScript()); } @@ -230,29 +230,31 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t // helper functions for rpc calls in rpcwallet.cpp -int64_t AddMarmaraInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) +int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - // add threshold check - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; - GetCCaddress(cp,coinaddr,pk); + GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); + unlocks = MarmaraUnlockHt(firstheight); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - // no need to prevent dup - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vintx.IsCoinBase() != 0 ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 1000000 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( total != 0 && maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) - break; + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( maxinputs > 0 && n >= maxinputs ) + break; + } } } } @@ -326,9 +328,89 @@ UniValue MarmaraInfo() result.push_back(Pair("name","Marmara")); cp = CCinit(&C,EVAL_MARMARA); Marmarapk = GetUnspendable(cp,0); - funding = AddMarmaraInputs(cp,mtx,Marmarapk,0,0); - sprintf(numstr,"%.8f",(double)funding/COIN); - result.push_back(Pair("funding",numstr)); + return(result); +} + +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string res; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + if ( pubkey2pk(Mypubkey()) != poolpk ) + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","poolpk is not your pubkey")); + return(result); + } + if ( txfee == 0 ) + txfee = 10000; + cp = CCinit(&C,EVAL_MARMARA); + Marmarapk = GetUnspendable(cp,0); + if ( (array= cJSON_Parse(jsonstr)) != 0 && (n= cJSON_GetArraySize(array)) > 0 ) + { + for (i=0; i SMALLVAL ) + { + shares += shares * perc; + if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) + { + for (i=0; i SMALLVAL ) + { + payout = (share * (total - txfee)) / shares; + if ( payout > 0 ) + { + if ( (pkstr= jstr(jitem(item,0))) != 0 && strlen(pkstr) == 66 ) + { + totalpayout += payout; + decode_hex(buf,33,pkstr); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); + } + } + } + } + if ( totalpayout > 0 && total > totalpayout-txfee ) + { + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); + } + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); + if ( rawtx.size() == 0 ) + errorstr = "couldnt finalize CCtx"; + } else errorstr = "couldnt find any coinbases to payout"; + } + else if ( errorstr == 0 ) + errorstr = "no valid shares submitted"; + free(array); + } else errorstr = "couldnt parse poolshares jsonstr"; + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result","success")); + result.push_back(Pair("rawtx",rawtx)); + if ( totalpayout > 0 && total > totalpayout-txfee ) + { + result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); + result.push_back(Pair("totalshares",shares)); + result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); + result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + } + } return(result); } From a36f051e0c4c88f089d2632f2355fc6973eee7dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:23:32 -1100 Subject: [PATCH 028/122] cJSON.h --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 15a8f811f..a5f816fbe 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -18,6 +18,7 @@ #define CC_TRIGGERS_H #include "CCinclude.h" +#include "../cJSON.h" #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2167c1364..8f3ec46c7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -232,11 +232,11 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx,int32_t firstheight,CPubKey poolpk,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; + char coinaddr[64]; CPubKey pk; int64_t nValue,totalinputs = 0; uint256 txid,hashBlock; CTransaction vintx; int32_t unlockht,ht,vout,unlocks,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); - unlocks = MarmaraUnlockHt(firstheight); + unlocks = MarmaraUnlockht(firstheight); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -334,7 +334,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string res; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; if ( pubkey2pk(Mypubkey()) != poolpk ) { result.push_back(Pair("result","error")); @@ -354,7 +354,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe shares += jdouble(jitem(item,1),0); else { - errorstr = "all items must be of the form [, ]"; + errorstr = (char *)"all items must be of the form [, ]"; break; } } @@ -386,13 +386,13 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe } rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); if ( rawtx.size() == 0 ) - errorstr = "couldnt finalize CCtx"; - } else errorstr = "couldnt find any coinbases to payout"; + errorstr = (char *)"couldnt finalize CCtx"; + } else errorstr = (char *)"couldnt find any coinbases to payout"; } else if ( errorstr == 0 ) - errorstr = "no valid shares submitted"; + errorstr = (char *)"no valid shares submitted"; free(array); - } else errorstr = "couldnt parse poolshares jsonstr"; + } else errorstr = (char *)"couldnt parse poolshares jsonstr"; if ( rawtx.size() == 0 || errorstr != 0 ) { result.push_back(Pair("result","error")); @@ -401,7 +401,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe } else { - result.push_back(Pair("result","success")); + result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { From f9f1452336c235f9932664ffba55abd12a6b0077 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:26:34 -1100 Subject: [PATCH 029/122] komodo_cJSON.h --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 41 ----------------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index a5f816fbe..b25f73f4b 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -18,7 +18,7 @@ #define CC_TRIGGERS_H #include "CCinclude.h" -#include "../cJSON.h" +#include "../komodo_cJSON.h" #define MARMARA_GROUPSIZE 60 #define MARMARA_MINLOCK (1440 * 3 * 30) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8f3ec46c7..f04941da3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -261,47 +261,6 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } -std::string MarmaraGet(uint64_t txfee,int64_t nValue) -{ - CMutableTransaction tmpmtx,mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - CPubKey mypk,Marmarapk; int64_t inputs,CCchange=0; struct CCcontract_info *cp,C; std::string rawhex; uint32_t j; int32_t i,len; uint8_t buf[32768]; bits256 hash; - cp = CCinit(&C,EVAL_MARMARA); - if ( txfee == 0 ) - txfee = 10000; - Marmarapk = GetUnspendable(cp,0); - mypk = pubkey2pk(Mypubkey()); - if ( (inputs= AddMarmaraInputs(cp,mtx,Marmarapk,nValue+txfee,60)) > 0 ) - { - if ( inputs > nValue ) - CCchange = (inputs - nValue - txfee); - if ( CCchange != 0 ) - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,CCchange,Marmarapk)); - mtx.vout.push_back(CTxOut(nValue,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); - fprintf(stderr,"start at %u\n",(uint32_t)time(NULL)); - j = rand() & 0xfffffff; - for (i=0; i<1000000; i++,j++) - { - tmpmtx = mtx; - rawhex = FinalizeCCTx(-1LL,cp,tmpmtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_MARMARA << (uint8_t)'G' << j)); - if ( (len= (int32_t)rawhex.size()) > 0 && len < 65536 ) - { - len >>= 1; - decode_hex(buf,len,(char *)rawhex.c_str()); - hash = bits256_doublesha256(0,buf,len); - if ( (hash.bytes[0] & 0xff) == 0 && (hash.bytes[31] & 0xff) == 0 ) - { - fprintf(stderr,"found valid txid after %d iterations %u\n",i,(uint32_t)time(NULL)); - return(rawhex); - } - //fprintf(stderr,"%02x%02x ",hash.bytes[0],hash.bytes[31]); - } - } - fprintf(stderr,"couldnt generate valid txid %u\n",(uint32_t)time(NULL)); - return(""); - } else fprintf(stderr,"cant find Marmara inputs\n"); - return(""); -} - std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); From 38705bdb2168e0cc4a328a618524ec43d6f7bceb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:28:04 -1100 Subject: [PATCH 030/122] Syntax --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f04941da3..5e9706ca9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -309,7 +309,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe for (i=0; i 0 ) { - if ( (pkstr= jstr(jitem(item,0))) != 0 && strlen(pkstr) == 66 ) + if ( (pkstr= jstr(jitem(item,0),0)) != 0 && strlen(pkstr) == 66 ) { totalpayout += payout; decode_hex(buf,33,pkstr); @@ -343,7 +343,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); } - rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',height,poolpk))); + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk))); if ( rawtx.size() == 0 ) errorstr = (char *)"couldnt finalize CCtx"; } else errorstr = (char *)"couldnt find any coinbases to payout"; From ee21bd6bc8156e99b3eeb76ef4c552b4b0e19db9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:31:29 -1100 Subject: [PATCH 031/122] Coinbaseopret --- src/cc/marmara.cpp | 4 ++-- src/miner.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5e9706ca9..6ba46dc8f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -139,12 +139,12 @@ CScript Marmara_scriptPubKey(int32_t height,CPubKey pk) return(ccvout.scriptPubKey); } -CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk) +CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk) { uint8_t *ptr; //fprintf(stderr,"height.%d pksize.%d\n",height,(int32_t)pk.size()); if ( height > 0 && (height & 1) == 0 && pk.size() == 33 ) - return(EncodeMarmaraCoinbaseOpRet('C',pk,height)); + return(EncodeMarmaraCoinbaseOpRet(funcid,pk,height)); return(CScript()); } diff --git a/src/miner.cpp b/src/miner.cpp index fb9ed8820..5ea5aafe0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -157,7 +157,7 @@ int32_t verus_staked(CBlock *pBlock, CMutableTransaction &txNew, uint32_t &nBits int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); CScript Marmara_scriptPubKey(int32_t height,CPubKey pk); -CScript MarmaraCoinbaseOpret(int32_t height,CPubKey pk); +CScript MarmaraCoinbaseOpret(uint8_t funcid,int32_t height,CPubKey pk); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { @@ -545,7 +545,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 { txNew.vout.resize(2); txNew.vout[1].nValue = 0; - txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret(nHeight,pk); + txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); } else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { From 386286c95d7220174ef1a838db0c2a09639d7b82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:47:18 -1100 Subject: [PATCH 032/122] +prints --- src/komodo_bitcoind.h | 8 ++++---- src/komodo_utils.h | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index c6eb05324..00ce20853 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1721,10 +1721,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 25; if ( matched == 0 ) { - //int32_t i; - //for (i=0; i<25; i++) - // fprintf(stderr,"%02x",script[i]); - //fprintf(stderr," payment to wrong pubkey scriptlen.%d, scriptpub[%d]\n",scriptlen,(int32_t)ASSETCHAINS_SCRIPTPUB.size()/2); + int32_t i; + for (i=0; i 1 && ASSETCHAINS_MARMARA != 0 ) + { + fprintf(stderr,"-ac_script and -ac_marmara are mutually exclusive\n"); + exit(0); + } if ( ASSETCHAINS_ENDSUBSIDY[0] != 0 || ASSETCHAINS_REWARD[0] != 0 || ASSETCHAINS_HALVING[0] != 0 || ASSETCHAINS_DECAY[0] != 0 || ASSETCHAINS_COMMISSION != 0 || ASSETCHAINS_PUBLIC != 0 || ASSETCHAINS_PRIVATE != 0 || ASSETCHAINS_TXPOW != 0 || ASSETCHAINS_FOUNDERS != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1 || ASSETCHAINS_SELFIMPORT.size() > 0 || ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_TIMELOCKGTE != _ASSETCHAINS_TIMELOCKOFF|| ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH || ASSETCHAINS_LWMAPOS != 0 || ASSETCHAINS_LASTERA > 0 || ASSETCHAINS_BEAMPORT != 0 || ASSETCHAINS_CODAPORT != 0 || ASSETCHAINS_MARMARA != 0 ) { fprintf(stderr,"perc %.4f%% ac_pub=[%02x%02x%02x...] acsize.%d\n",dstr(ASSETCHAINS_COMMISSION)*100,ASSETCHAINS_OVERRIDE_PUBKEY33[0],ASSETCHAINS_OVERRIDE_PUBKEY33[1],ASSETCHAINS_OVERRIDE_PUBKEY33[2],(int32_t)ASSETCHAINS_SCRIPTPUB.size()); From b02113975d8ca9be2a1d122b0649e6f6d4043bf0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:48:09 -1100 Subject: [PATCH 033/122] -) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6ba46dc8f..bdd7b2be7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -343,7 +343,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKe { mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); } - rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk))); + rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk)); if ( rawtx.size() == 0 ) errorstr = (char *)"couldnt finalize CCtx"; } else errorstr = (char *)"couldnt find any coinbases to payout"; From dda3ecd759fdae1216ad653bd1f85c25fe4f408a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 06:58:58 -1100 Subject: [PATCH 034/122] Connect marmara_poolpayout --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 11 +++-------- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 13 +++++++++++++ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index b25f73f4b..4a50c2539 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -24,7 +24,7 @@ #define MARMARA_MINLOCK (1440 * 3 * 30) #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); -UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bdd7b2be7..bce201383 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -290,16 +290,11 @@ UniValue MarmaraInfo() return(result); } -UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,CPubKey poolpk,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; - if ( pubkey2pk(Mypubkey()) != poolpk ) - { - result.push_back(Pair("result","error")); - result.push_back(Pair("error","poolpk is not your pubkey")); - return(result); - } + UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; cp = CCinit(&C,EVAL_MARMARA); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 1a932382e..56b32c837 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -443,6 +443,7 @@ static const CRPCCommand vRPCCommands[] = // Marmara { "marmara", "Marmaraaddress", &marmaraaddress, true }, + { "marmara", "Marmarapoolpayout", &marmara_poolpayout, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 5bdf62799..bd00bb9d1 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -272,6 +272,7 @@ extern UniValue pricesstatus(const UniValue& params, bool fHelp); extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); +extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 79710969a..36e23c93d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5531,6 +5531,19 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) return(CCaddress(cp,(char *)"Assets",pubkey)); } +UniValue marmara_poolpayout(const UniValue& params, bool fHelp) +{ + int32_t firstheight; double perc; char *jsonstr; + if ( fHelp || params.size() != 3 ) + throw runtime_error("marmara_poolpayout perc firstheight \"[[pubkey:shares], ...]\"\n"); + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + perc = atof(params[0].get_str().c_str()) / 100.; + firstheight = atol(params[1].get_str().c_str()); + jsonstr = (char *)params[2].get_str().c_str(); + return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 45096107db5fa0104989c9b1105e4a71ebb1e4ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:24:19 -1100 Subject: [PATCH 035/122] Test --- src/komodo_bitcoind.h | 3 ++- src/miner.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 00ce20853..b6173def9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1704,7 +1704,8 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) return(-1); else*/ if ( checktoshis != 0 ) { - script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; + //script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; + script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { diff --git a/src/miner.cpp b/src/miner.cpp index 5ea5aafe0..bdbf7a570 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -589,8 +589,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 ptr = (uint8_t *)&txNew.vout[1].scriptPubKey[0]; ptr[0] = 33; for (i=0; i<33; i++) + { ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; + fprintf(stderr,"%02x",ptr[i+1]); + } ptr[34] = OP_CHECKSIG; + fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); } //printf("autocreate commision vout\n"); } From bbc8c98e7180a35287bc699b6595807010dd9ac6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:26:24 -1100 Subject: [PATCH 036/122] Syntax --- 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 b6173def9..00ce20853 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1704,8 +1704,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) return(-1); else*/ if ( checktoshis != 0 ) { - //script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; - script = (uint8_t *)pblock->vtx[0].vout[1].scriptPubKey.data(); + script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { From 18c82335b59c122e76e5f9f81c8208e1083d0cc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:34:05 -1100 Subject: [PATCH 037/122] 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 00ce20853..1b8bb85b0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1699,13 +1699,19 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) if ( ASSETCHAINS_COMMISSION != 0 ) { checktoshis = komodo_commission(pblock,height); - //fprintf(stderr,"height.%d commission %.8f\n",height,(double)checktoshis/COIN); - /*if ( checktoshis > 10000 && pblock->vtx[0].vout.size() != 2 ) jl777: not sure why this was here + if ( checktoshis >= 10000 && pblock->vtx[0].vout.size() < 2 ) + { + fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); return(-1); - else*/ if ( checktoshis != 0 ) + } + else if ( checktoshis != 0 ) { script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); + int32_t i; + for (i=0; ivtx[0].vout[1].nValue/COIN)); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) @@ -1721,9 +1727,6 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) matched = 25; if ( matched == 0 ) { - int32_t i; - for (i=0; ivtx[0].vout[0].scriptPubKey[0]; - if ( script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) + scriptlen = (int32_t)pblock->vtx[0].vout[0].scriptPubKey.size(); + if ( scriptlen != 35 || script[0] != 33 || script[34] != OP_CHECKSIG || memcmp(script+1,ASSETCHAINS_OVERRIDE_PUBKEY33,33) != 0 ) return(-1); } } From 36a74b8d2787ba7ee5ab2976daa33e94c1cf0090 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:34:48 -1100 Subject: [PATCH 038/122] -) --- 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 1b8bb85b0..a36e1f744 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1711,7 +1711,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) int32_t i; for (i=0; ivtx[0].vout[1].nValue/COIN)); + fprintf(stderr," vout[1] %.8f vs %.8f\n",(double)checktoshis/COIN,(double)pblock->vtx[0].vout[1].nValue/COIN); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) From 43cbde9fe4f46baf17f6a6618c13e2f60a07cfed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:35:50 -1100 Subject: [PATCH 039/122] scriptlen --- 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 a36e1f744..341ee49e2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1745,7 +1745,7 @@ 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; + uint256 hash; arith_uint256 bnTarget,bhash; bool fNegative,fOverflow; uint8_t *script,pubkey33[33],pubkeys[64][33]; int32_t i,scriptlen,possible,PoSperc,is_PoSblock=0,n,failed = 0,notaryid = -1; int64_t checktoshis,value; CBlockIndex *pprev; if ( KOMODO_TEST_ASSETCHAIN_SKIP_POW == 0 && Params().NetworkIDString() == "regtest" ) KOMODO_TEST_ASSETCHAIN_SKIP_POW = 1; if ( !CheckEquihashSolution(pblock, Params()) ) From e3110f16fb9b75524cb11688d67d6cad8068dc37 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:41:26 -1100 Subject: [PATCH 040/122] Change priority of mining ac_variants --- src/miner.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index bdbf7a570..5bf230050 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -547,28 +547,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[1].nValue = 0; txNew.vout[1].scriptPubKey = MarmaraCoinbaseOpret('C',nHeight,pk); } - else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) - { - int32_t opretlen, p2shlen, scriptlen; - CScriptExt opretScript = CScriptExt(); - - txNew.vout.resize(2); - - // prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins - // protected only by the time lock rather than 100% inaccessible - opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight)); - if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) - { - fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); - return 0; - } - - opretScript += scriptPubKeyIn; - - txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); - txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK); - txNew.vout[1].nValue = 0; - } // timelocks and commissions are currently incompatible due to validation complexity of the combination else if ( nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0 ) { int32_t i; uint8_t *ptr; @@ -598,6 +576,28 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } //printf("autocreate commision vout\n"); } + else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + { + int32_t opretlen, p2shlen, scriptlen; + CScriptExt opretScript = CScriptExt(); + + txNew.vout.resize(2); + + // prepend time lock to original script unless original script is P2SH, in which case, we will leave the coins + // protected only by the time lock rather than 100% inaccessible + opretScript.AddCheckLockTimeVerify(komodo_block_unlocktime(nHeight)); + if (scriptPubKeyIn.IsPayToScriptHash() || scriptPubKeyIn.IsPayToCryptoCondition()) + { + fprintf(stderr,"CreateNewBlock: attempt to add timelock to pay2sh or pay2cc\n"); + return 0; + } + + opretScript += scriptPubKeyIn; + + txNew.vout[0].scriptPubKey = CScriptExt().PayToScriptHash(CScriptID(opretScript)); + txNew.vout[1].scriptPubKey = CScriptExt().OpReturnScript(opretScript, OPRETTYPE_TIMELOCK); + txNew.vout[1].nValue = 0; + } // timelocks and commissions are currently incompatible due to validation complexity of the combination pblock->vtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; From 6f345c4ed1e0247a148df575756ec062a12ad743 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:48:13 -1100 Subject: [PATCH 041/122] +prints --- src/komodo_bitcoind.h | 10 +++++----- src/miner.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 341ee49e2..c647b1692 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue; } @@ -1708,10 +1708,10 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) { script = (uint8_t *)&pblock->vtx[0].vout[1].scriptPubKey[0]; scriptlen = (int32_t)pblock->vtx[0].vout[1].scriptPubKey.size(); - int32_t i; - for (i=0; ivtx[0].vout[1].nValue/COIN); + //int32_t i; + //for (i=0; ivtx[0].vout[1].nValue/COIN); if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { if ( ASSETCHAINS_SCRIPTPUB.size()/2 == scriptlen && scriptlen < sizeof(scripthex) ) diff --git a/src/miner.cpp b/src/miner.cpp index 5bf230050..dc476b4c3 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -576,7 +576,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 } //printf("autocreate commision vout\n"); } - else if ((uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) + else if ( (uint64_t)(txNew.vout[0].nValue) >= ASSETCHAINS_TIMELOCKGTE) { int32_t opretlen, p2shlen, scriptlen; CScriptExt opretScript = CScriptExt(); From 8ffe7c1119f6a8b3bf3aba589be0ca5bc2280b46 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:48:58 -1100 Subject: [PATCH 042/122] Block --- 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 c647b1692..64faa28bc 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; } From 5ddb8a234694978fa34034a2e48e043f9c5fedf5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 07:56:04 -1100 Subject: [PATCH 043/122] Test --- src/komodo_bitcoind.h | 1 + src/miner.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 64faa28bc..82abfb1f2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1171,6 +1171,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } if ( commission < 10000 ) commission = 0; + fprintf(stderr,"-> %.8f\n",(double)commission/COIN); return(commission); } diff --git a/src/miner.cpp b/src/miner.cpp index dc476b4c3..71366bd12 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -554,6 +554,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[1].nValue = commission; if ( ASSETCHAINS_SCRIPTPUB.size() > 1 ) { + fprintf(stderr,"mine to -ac_script\n"); //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; From 36a962d0b58d95ed61acd640776149d2130e052b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:02:03 -1100 Subject: [PATCH 044/122] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 71366bd12..0e7c093de 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -539,6 +539,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; + fprintf(stderr,"ht.%d cmp.%d\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) From c877777d7b88874b098fcdae3a42bc884e22115f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:04:38 -1100 Subject: [PATCH 045/122] +print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 0e7c093de..a5712025f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -539,7 +539,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; - fprintf(stderr,"ht.%d cmp.%d\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); + fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) From de4aed1a620e2406b01e53116b12c9970c0c1efb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:07:56 -1100 Subject: [PATCH 046/122] pblock->vtx[0] = txNew; --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index a5712025f..f634be072 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -538,6 +538,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; + pblock->vtx[0] = txNew; fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock From 34a26023f206dbbad74abe4cacfa469af4cd6c2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:09:54 -1100 Subject: [PATCH 047/122] Test --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 82abfb1f2..6e6dc7b35 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1162,7 +1162,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) n = pblock->vtx[i].vout.size(); for (j=0; jvtx[i].vout[j].nValue),j); + //fprintf(stderr,"(%d %.8f).%d ",i,dstr(pblock->vtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; } @@ -1171,7 +1171,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } if ( commission < 10000 ) commission = 0; - fprintf(stderr,"-> %.8f\n",(double)commission/COIN); + //fprintf(stderr,"-> %.8f\n",(double)commission/COIN); return(commission); } @@ -1702,7 +1702,7 @@ int64_t komodo_checkcommission(CBlock *pblock,int32_t height) checktoshis = komodo_commission(pblock,height); if ( checktoshis >= 10000 && pblock->vtx[0].vout.size() < 2 ) { - fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); + //fprintf(stderr,"komodo_checkcommission vsize.%d height.%d commission %.8f\n",(int32_t)pblock->vtx[0].vout.size(),height,(double)checktoshis/COIN); return(-1); } else if ( checktoshis != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index f634be072..128a94e3a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -540,7 +540,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[0].nValue += 5000; pblock->vtx[0] = txNew; - fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); + //fprintf(stderr,"ht.%d cmp.%d [%d %d %d %d %d]\n",nHeight,nHeight > 1 && ASSETCHAINS_SYMBOL[0] != 0 && (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1) && ASSETCHAINS_COMMISSION != 0 && (commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0,nHeight > 1,ASSETCHAINS_SYMBOL[0] != 0, (ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 || ASSETCHAINS_SCRIPTPUB.size() > 1), ASSETCHAINS_COMMISSION != 0,(commission= komodo_commission((CBlock*)&pblocktemplate->block,(int32_t)nHeight)) != 0); // check if coinbase transactions must be time locked at current subsidy and prepend the time lock // to transaction if so, cast for GTE operator if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) @@ -572,10 +572,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 for (i=0; i<33; i++) { ptr[i+1] = ASSETCHAINS_OVERRIDE_PUBKEY33[i]; - fprintf(stderr,"%02x",ptr[i+1]); + //fprintf(stderr,"%02x",ptr[i+1]); } ptr[34] = OP_CHECKSIG; - fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); + //fprintf(stderr," set ASSETCHAINS_OVERRIDE_PUBKEY33 into vout[1]\n"); } //printf("autocreate commision vout\n"); } From 4c900a4708e44e4cc68a689ccc9f503a78f6dc11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:21:57 -1100 Subject: [PATCH 048/122] Son --- src/rpc/server.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 56b32c837..d6b801dd5 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -442,8 +442,8 @@ static const CRPCCommand vRPCCommands[] = { "pegs", "pegsaddress", &pegsaddress, true }, // Marmara - { "marmara", "Marmaraaddress", &marmaraaddress, true }, - { "marmara", "Marmarapoolpayout", &marmara_poolpayout, true }, + { "marmara", "marmaraaddress", &marmaraaddress, true }, + { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 36e23c93d..a4b30e383 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5535,7 +5535,10 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; if ( fHelp || params.size() != 3 ) - throw runtime_error("marmara_poolpayout perc firstheight \"[[pubkey:shares], ...]\"\n"); + { + fprintf(stderr,"params.size %d\n",(int32_t)params.size()); + throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); + } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); perc = atof(params[0].get_str().c_str()) / 100.; From 3fb0d3a82adaf30138f5d98a4575cc17d6312d67 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:24:41 -1100 Subject: [PATCH 049/122] Test --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bce201383..bb06b3e39 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -178,7 +178,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) { if ( ht == height && MarmaraUnlockht(height) == unlockht ) { - fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); + //fprintf(stderr,"ht.%d -> unlock.%d\n",ht,unlockht); ccvout = MakeCC1vout(EVAL_MARMARA,0,pk); if ( ccvout.scriptPubKey == tx.vout[0].scriptPubKey ) return(0); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a4b30e383..4a7024eb4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5534,7 +5534,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; - if ( fHelp || params.size() != 3 ) + if ( fHelp || params.size() < 3 ) { fprintf(stderr,"params.size %d\n",(int32_t)params.size()); throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); @@ -5544,6 +5544,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); + fprintf(stderr,"perc %.2f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From 1e17cbc61790d8c0c0bd8ee4df21b05aff73908c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:26:54 -1100 Subject: [PATCH 050/122] -print --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cd3c0d35f..44dab5ed1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3462,7 +3462,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),(int32_t)block.vtx[0].vout.size()); + else if ( pindex->nHeight > 1 ) + fprintf(stderr,"checktoshis %.8f vs %.8f numvouts %d\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue),(int32_t)block.vtx[0].vout.size()); } } if (ASSETCHAINS_SYMBOL[0] != 0 && pindex->GetHeight() == 1 && block.vtx[0].GetValueOut() != blockReward) From 7ebf1d817686b6dfe32465235b5ba3739bd250a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:41:23 -1100 Subject: [PATCH 051/122] +print --- src/cc/marmara.cpp | 31 ++++++++++++++++++------------- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index bb06b3e39..353f3edba 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -237,26 +237,31 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); + fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 && vintx.IsCoinBase() != 0 ) + fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); + if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) + if ( vintx.IsCoinBase() != 0 ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( maxinputs != 0 ) - mtx.vin.push_back(CTxIn(txid,vout,CScript())); - nValue = it->second.satoshis; - totalinputs += nValue; - n++; - if ( maxinputs > 0 && n >= maxinputs ) - break; - } - } - } + if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + { + if ( maxinputs != 0 ) + mtx.vin.push_back(CTxIn(txid,vout,CScript())); + nValue = it->second.satoshis; + totalinputs += nValue; + n++; + if ( maxinputs > 0 && n >= maxinputs ) + break; + } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); + } else fprintf(stderr,"decode error\n"); + } else fprintf(stderr,"not coinbase\n"); + } else fprintf(stderr,"error getting tx\n"); } return(totalinputs); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4a7024eb4..6a2a351dc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5544,7 +5544,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); - fprintf(stderr,"perc %.2f ht.%d (%s)\n",perc,firstheight,jsonstr); + fprintf(stderr,"perc %.8f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From 80c61ba5053b5ba20898e6134aa29217b3634b3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:44:14 -1100 Subject: [PATCH 052/122] ->GetHeight() --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 44dab5ed1..929ec9d5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3462,7 +3462,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { if ( block.vtx[0].vout.size() >= 2 && block.vtx[0].vout[1].nValue == checktoshis ) blockReward += checktoshis; - else if ( pindex->nHeight > 1 ) + else if ( pindex->GetHeight() > 1 ) fprintf(stderr,"checktoshis %.8f vs %.8f numvouts %d\n",dstr(checktoshis),dstr(block.vtx[0].vout[1].nValue),(int32_t)block.vtx[0].vout.size()); } } From c31f8ea3d57d400bd4d51967196efd345a4399ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:52:30 -1100 Subject: [PATCH 053/122] Test --- src/cc/marmara.cpp | 5 +++-- src/wallet/rpcwallet.cpp | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 353f3edba..66d082cb9 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -124,6 +124,7 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { + fprintf(stderr,"return %c\n",script[1]); return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); @@ -245,7 +246,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { - if ( vintx.IsCoinBase() != 0 ) + if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) { if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { @@ -259,7 +260,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, if ( maxinputs > 0 && n >= maxinputs ) break; } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); - } else fprintf(stderr,"decode error\n"); + } else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6a2a351dc..fc9655ec1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5536,7 +5536,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) int32_t firstheight; double perc; char *jsonstr; if ( fHelp || params.size() < 3 ) { - fprintf(stderr,"params.size %d\n",(int32_t)params.size()); + // marmarapoolpayout "0.5" 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) @@ -5544,7 +5544,6 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) perc = atof(params[0].get_str().c_str()) / 100.; firstheight = atol(params[1].get_str().c_str()); jsonstr = (char *)params[2].get_str().c_str(); - fprintf(stderr,"perc %.8f ht.%d (%s)\n",perc,firstheight,jsonstr); return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } From f6af25e545ee3ff9e9da583c8039d4c88bd8b7f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:56:00 -1100 Subject: [PATCH 054/122] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 66d082cb9..304d97f74 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -250,7 +250,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, { if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) { - if ( (nValue= IsMarmaravout(cp,vintx,vout)) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( maxinputs != 0 ) mtx.vin.push_back(CTxIn(txid,vout,CScript())); From fefe5dbd246bfc1139d0556ffed441d45bf3265b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 08:59:23 -1100 Subject: [PATCH 055/122] Args 3 --- src/cc/marmara.cpp | 1 - src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 304d97f74..b3be7cb32 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -124,7 +124,6 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 { if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> pk; ss >> height; ss >> unlockht) != 0 ) { - fprintf(stderr,"return %c\n",script[1]); return(script[1]); } else fprintf(stderr,"DecodeMaramaraCoinbaseOpRet unmarshal error for %c\n",script[1]); } else fprintf(stderr,"script[1] is %d != 'C' %d or 'P' %d\n",script[1],'C','P'); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index fc9655ec1..2bc4aeeba 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5534,7 +5534,7 @@ UniValue tokenaddress(const UniValue& params, bool fHelp) UniValue marmara_poolpayout(const UniValue& params, bool fHelp) { int32_t firstheight; double perc; char *jsonstr; - if ( fHelp || params.size() < 3 ) + if ( fHelp || params.size() != 3 ) { // marmarapoolpayout "0.5" 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); From 028725471c7a176605512ec4e3d5e7c9185f8b2b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:17:22 -1100 Subject: [PATCH 056/122] Total field --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b3be7cb32..103e8d51a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -364,6 +364,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { + result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); From 1b46c66023b207223070d06740516e1e8082987c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:21:54 -1100 Subject: [PATCH 057/122] Payouts --- src/cc/marmara.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 103e8d51a..852ac8469 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -237,12 +237,12 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, GetCCaddress(cp,coinaddr,poolpk); SetCCunspents(unspentOutputs,coinaddr); unlocks = MarmaraUnlockht(firstheight); - fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); + //fprintf(stderr,"check coinaddr.(%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); + //fprintf(stderr,"txid.%s/v%d\n",txid.GetHex().c_str(),vout); if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) { if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) @@ -259,7 +259,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, if ( maxinputs > 0 && n >= maxinputs ) break; } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); - } else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); + } //else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); } @@ -298,7 +298,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -335,6 +335,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); + a.push_back(Pair(pkstr,(double)payout/COIN)); } } } @@ -369,6 +370,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + result.push_back(Pair("payouts",a); } } return(result); From cdbdf8662b712b643266f44a736f56c1b81967d1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:23:02 -1100 Subject: [PATCH 058/122] +) --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 852ac8469..82d0a9995 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,7 +370,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); - result.push_back(Pair("payouts",a); + result.push_back(Pair("payouts",a)); } } return(result); From 9e94b62aa3f83d9a422d5c9a7332df6aea9a8455 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:25:30 -1100 Subject: [PATCH 059/122] Payout --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 82d0a9995..b1603cfbc 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -335,7 +335,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); - a.push_back(Pair(pkstr,(double)payout/COIN)); + a.push_back((double)payout/COIN); } } } From 70de1f76bd446c74e9a11752a2228e1882af805f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:28:12 -1100 Subject: [PATCH 060/122] x(UniValue::VOBJ), --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index b1603cfbc..f993d5555 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -332,10 +332,12 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { if ( (pkstr= jstr(jitem(item,0),0)) != 0 && strlen(pkstr) == 66 ) { + UniValue x(UniValue::VOBJ); totalpayout += payout; decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); - a.push_back((double)payout/COIN); + x.push_back(Pair(pkstr, (double)payout/COIN)); + a.push_back(item); } } } From 78b7341aa5aa03248bd3ba74fd1f3cec2e3b555e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:29:45 -1100 Subject: [PATCH 061/122] x --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f993d5555..4a32639af 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -337,7 +337,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * decode_hex(buf,33,pkstr); mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,payout,Marmarapk,buf2pk(buf))); x.push_back(Pair(pkstr, (double)payout/COIN)); - a.push_back(item); + a.push_back(x); } } } From 513c19d096298af8ee832cab2b3471642056ce36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:38:33 -1100 Subject: [PATCH 062/122] Split commission calc into 2 divs --- 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 6e6dc7b35..079e58fc5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1167,7 +1167,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) total += pblock->vtx[i].vout[j].nValue; } } - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000); + //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; From 59bb5fd47030ff9d5221edf19108d879e45ca960 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:46:58 -1100 Subject: [PATCH 063/122] -) --- 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 079e58fc5..841396a00 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1167,7 +1167,7 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) total += pblock->vtx[i].vout[j].nValue; } } - commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) From f105e133b972f9fdae7ce56eebd304ea0ae85911 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:54:12 -1100 Subject: [PATCH 064/122] First/last heights --- src/cc/marmara.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4a32639af..763c19ebe 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -367,6 +367,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("rawtx",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { + result.push_back(Pair("firstheight",firstheight)); + result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); From cae219a0c8970d80efb52d8cdf810d1fb67d24fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 09:56:52 -1100 Subject: [PATCH 065/122] Test --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 763c19ebe..4b154cc8c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -247,7 +247,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, { if ( vintx.IsCoinBase() != 0 && vintx.vout.size() == 2 && vintx.vout[1].nValue == 0 ) { - if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk ) + if ( DecodeMaramaraCoinbaseOpRet(vintx.vout[1].scriptPubKey,pk,ht,unlockht) == 'C' && unlockht == unlocks && pk == poolpk && ht >= firstheight ) { if ( (nValue= vintx.vout[vout].nValue) > 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { From 7949fcb64857a72118307ae7818575ab4689fe92 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 15:51:07 -1100 Subject: [PATCH 066/122] Tweak perc calc --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4b154cc8c..ccce9083f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,7 +319,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - shares += shares * perc; + shares += (shares / (1. - perc)); if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 15:55:31 -1100 Subject: [PATCH 067/122] Fix perc math --- src/cc/marmara.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ccce9083f..639a69567 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,7 +319,9 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - shares += (shares / (1. - perc)); + //shares += shares * perc; + shares /= (1. - perc); + if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 16:00:11 -1100 Subject: [PATCH 068/122] Revert --- src/cc/marmara.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 639a69567..4b154cc8c 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -319,9 +319,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( errorstr == 0 && shares > SMALLVAL ) { - //shares += shares * perc; - shares /= (1. - perc); - + shares += shares * perc; if ( (total= AddMarmaraCoinbases(cp,mtx,firstheight,poolpk,60)) > 0 ) { for (i=0; i Date: Sat, 12 Jan 2019 16:04:43 -1100 Subject: [PATCH 069/122] Adjust pool fee disp by three --- src/cc/marmara.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 4b154cc8c..751eb569b 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -298,7 +298,7 @@ UniValue MarmaraInfo() UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr) // [[pk0, shares0], [pk1, shares1], ...] { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; + UniValue result(UniValue::VOBJ),a(UniValue::VARR); cJSON *item,*array; std::string rawtx; int32_t i,n; uint8_t buf[33]; CPubKey Marmarapk,pk,poolpk; int64_t payout,poolfee=0,total,totalpayout=0; double poolshares,share,shares = 0.; char *pkstr,*errorstr=0; struct CCcontract_info *cp,C; poolpk = pubkey2pk(Mypubkey()); if ( txfee == 0 ) txfee = 10000; @@ -344,7 +344,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * } if ( totalpayout > 0 && total > totalpayout-txfee ) { - mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,total - totalpayout - txfee,Marmarapk,poolpk)); + poolfee = (total - totalpayout - txfee); + mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,poolfee,Marmarapk,poolpk)); } rawtx = FinalizeCCTx(0,cp,mtx,poolpk,txfee,MarmaraCoinbaseOpret('P',firstheight,poolpk)); if ( rawtx.size() == 0 ) @@ -372,8 +373,8 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("total",(double)total/COIN)); result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",(double)(total - totalpayout)/COIN)); - result.push_back(Pair("perc",100. * (double)(total - totalpayout)/totalpayout)); + result.push_back(Pair("poolfee",(double)poolfee/COIN)); + result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } } From 5ee45ecb45990a3f3d51480d9f08e5a7d070a2c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:12:24 -1100 Subject: [PATCH 070/122] ValueFromAmount( --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 751eb569b..ef2f62b40 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,10 +370,10 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { result.push_back(Pair("firstheight",firstheight)); result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); - result.push_back(Pair("total",(double)total/COIN)); - result.push_back(Pair("totalpayout",(double)totalpayout/COIN)); + result.push_back(Pair("total",ValueFromAmount(total)); + result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout)); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",(double)poolfee/COIN)); + result.push_back(Pair("poolfee",ValueFromAmount(poolfee)); result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } From 857bf5f4e6ea57df49c2e1debff69421e7428a39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:13:54 -1100 Subject: [PATCH 071/122] UniValue ValueFromAmount(const CAmount& amount) --- src/cc/CCinclude.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 0906a57c6..aaeadcc61 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -187,5 +187,6 @@ bits256 curve25519_basepoint9(); bits256 curve25519(bits256 mysecret,bits256 basepoint); void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); bits256 bits256_doublesha256(char *deprecated,uint8_t *data,int32_t datalen); +UniValue ValueFromAmount(const CAmount& amount); #endif From ba5462eec9a2172a9c60344ee0cb646cdc013807 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:16:21 -1100 Subject: [PATCH 072/122] +))) --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ef2f62b40..593ee48f7 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -370,10 +370,10 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * { result.push_back(Pair("firstheight",firstheight)); result.push_back(Pair("lastheight",((firstheight / MARMARA_GROUPSIZE)+1) * MARMARA_GROUPSIZE - 1)); - result.push_back(Pair("total",ValueFromAmount(total)); - result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout)); + result.push_back(Pair("total",ValueFromAmount(total))); + result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); - result.push_back(Pair("poolfee",ValueFromAmount(poolfee)); + result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); result.push_back(Pair("payouts",a)); } From 24cd52e8956201c8a8b01d91f686dda6f8486259 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:20:09 -1100 Subject: [PATCH 073/122] return eval->Invalid("no validation yet"); --- src/cc/auction.cpp | 2 +- src/cc/fsm.cpp | 2 +- src/cc/heir.cpp | 2 +- src/cc/lotto.cpp | 2 +- src/cc/marmara.cpp | 2 +- src/cc/payments.cpp | 2 +- src/cc/pegs.cpp | 2 +- src/cc/prices.cpp | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 70bc64379..0858facfa 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -73,7 +73,7 @@ bool AuctionExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any auction CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 04ca1d5a0..0bcc61a1b 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -75,7 +75,7 @@ bool FSMExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &t bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any FSM CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index 5caa6594a..44f01a8a4 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -74,7 +74,7 @@ bool HeirExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & bool HeirValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 7b44a99b7..e9c263ff1 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -115,7 +115,7 @@ bool LottoExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction bool LottoValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i; bool retval; - return(false); // reject any lotto CC for now + return eval->Invalid("no validation yet"); numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 593ee48f7..a4d548176 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -192,7 +192,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 1b6d88214..859a5ba3f 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -75,7 +75,7 @@ bool PaymentsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransacti bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 4e414d695..e2893bec8 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -82,7 +82,7 @@ bool PegsExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction & bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 8c2ecc021..5d919d6e8 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -89,7 +89,7 @@ uint8_t DecodePricesFundingOpRet(CScript scriptPubKey,CPubKey &planpk,uint256 &o bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return(false); + return eval->Invalid("no validation yet"); std::vector > txids; numvins = tx.vin.size(); numvouts = tx.vout.size(); From b6eed136785c5662cc18d83d231c588943d32392 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:22:59 -1100 Subject: [PATCH 074/122] Truncate perc print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a4d548176..171ef713d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -374,7 +374,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); - result.push_back(Pair("perc",100. * (double)poolfee/totalpayout)); + result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout)))); result.push_back(Pair("payouts",a)); } } From c38e4a0521534e81e81a25f95c9f33afd52730c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 16:24:23 -1100 Subject: [PATCH 075/122] * COIN --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 171ef713d..2e56c21b2 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -374,7 +374,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * result.push_back(Pair("totalpayout",ValueFromAmount(totalpayout))); result.push_back(Pair("totalshares",shares)); result.push_back(Pair("poolfee",ValueFromAmount(poolfee))); - result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout)))); + result.push_back(Pair("perc",ValueFromAmount((int64_t)(100. * (double)poolfee/totalpayout * COIN)))); result.push_back(Pair("payouts",a)); } } From 0b58392fff0671169aa06f16c8cab9bb2869daac Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:29:18 -1100 Subject: [PATCH 076/122] Validation for marmara 'P' --- src/cc/eval.cpp | 5 +++-- src/cc/marmara.cpp | 45 ++++++++++++++++++++++----------------------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index d50bc8a0d..9161f2007 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -38,8 +38,9 @@ bool RunCCEval(const CC *cond, const CTransaction &tx, unsigned int nIn) pthread_mutex_lock(&KOMODO_CC_mutex); bool out = eval->Dispatch(cond, tx, nIn); pthread_mutex_unlock(&KOMODO_CC_mutex); - //fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); - assert(eval->state.IsValid() == out); + if ( eval->state.IsValid() != out) + fprintf(stderr,"out %d vs %d isValid\n",(int32_t)out,(int32_t)eval->state.IsValid()); + //assert(eval->state.IsValid() == out); if (eval->state.IsValid()) return true; diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 2e56c21b2..d12959d2a 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -191,40 +191,39 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,numblocks; bool retval; uint256 txid; uint8_t hash[32]; char str[65],destaddr[64]; - return eval->Invalid("no validation yet"); - std::vector > txids; + CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; if ( numvouts < 1 ) return eval->Invalid("no vouts"); - else + else if ( tx.vout.size() >= 2 ) { - for (i=0; iInvalid("illegal normal vini"); + if ( (*cp->ismyvin)(tx.vin[i].scriptSig) != 0 ) + { + if ( eval->GetTxUnconfirmed(tx.vin[i].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("cant find vinTx"); + else + { + if ( vinTx.IsCoinbase() == 0 ) + return eval->Invalid("noncoinbase input"); + else if ( vinTx.size() != 2 ) + return eval->Invalid("coinbase doesnt have 2 vouts"); + vfuncid = DecodeMaramaraCoinbaseOpRet(vinTx.vout[1].scriptPubKey,vpk,vht,vunlockht); + if ( vfuncid != 'C' || vpk != pk || vunlockht != unlockht ) + return eval->Invalid("mismatched opreturn"); + } + } } - } - //fprintf(stderr,"check amounts\n"); - if ( MarmaraExactAmounts(cp,eval,tx,1,10000) == false ) - { - fprintf(stderr,"Marmaraget invalid amount\n"); - return false; - } - else - { - txid = tx.GetHash(); - memcpy(hash,&txid,sizeof(hash)); - retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); - if ( retval != 0 ) - fprintf(stderr,"Marmaraget validated\n"); - else fprintf(stderr,"Marmaraget invalid\n"); - return(retval); + return(true); } } + return eval->Invalid("fall through error"); } // end of consensus code From 7c0fb95d183384df38838e634e7555f19bba8a0e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:29:47 -1100 Subject: [PATCH 077/122] Syntax --- src/cc/marmara.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index d12959d2a..f272ecf8d 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -194,7 +194,6 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); - preventCCvins = preventCCvouts = -1; if ( numvouts < 1 ) return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) From ba281dae9f79fd287151c09211552a01a2736031 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:32:15 -1100 Subject: [PATCH 078/122] syntax --- src/cc/marmara.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index f272ecf8d..dd8e304cf 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -191,7 +191,7 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid; CPubKey pk,vpk; + CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) @@ -209,9 +209,9 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("cant find vinTx"); else { - if ( vinTx.IsCoinbase() == 0 ) + if ( vinTx.IsCoinBase() == 0 ) return eval->Invalid("noncoinbase input"); - else if ( vinTx.size() != 2 ) + else if ( vinTx.vout.size() != 2 ) return eval->Invalid("coinbase doesnt have 2 vouts"); vfuncid = DecodeMaramaraCoinbaseOpRet(vinTx.vout[1].scriptPubKey,vpk,vht,vunlockht); if ( vfuncid != 'C' || vpk != pk || vunlockht != unlockht ) From fe9d96b291bc4bdfdcf164b11765e4d02fb75cf2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 12 Jan 2019 17:35:48 -1100 Subject: [PATCH 079/122] Last vout is I-return --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index dd8e304cf..5c36eb563 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -198,7 +198,7 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) { - funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[1].scriptPubKey,pk,ht,unlockht); + funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); if ( funcid == 'P' ) { for (i=0; i Date: Sat, 12 Jan 2019 17:38:17 -1100 Subject: [PATCH 080/122] -print --- src/cc/marmara.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5c36eb563..6415671f8 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -256,7 +256,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, n++; if ( maxinputs > 0 && n >= maxinputs ) break; - } else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); + } //else fprintf(stderr,"nValue.%8f\n",(double)nValue/COIN); } //else fprintf(stderr,"decode error unlockht.%d vs %d pk.%d\n",unlockht,unlocks,pk == poolpk); } else fprintf(stderr,"not coinbase\n"); } else fprintf(stderr,"error getting tx\n"); From e149a4e4d798b31c6cdc69ba16b5bdcd6ab19530 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:34:07 -1100 Subject: [PATCH 081/122] Initial MarmaraReceive --- src/cc/marmara.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 6415671f8..ba4e4b005 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -33,7 +33,7 @@ int64_t IsMarmaravout(struct CCcontract_info *cp,const CTransaction& tx,int32_t return(0); } -bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) +/*bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx,int32_t minage,uint64_t txfee) { static uint256 zerohash; CTransaction vinTx; uint256 hashBlock,activehash; int32_t i,numvins,numvouts; int64_t inputs=0,outputs=0,assetoshis; @@ -69,7 +69,7 @@ bool MarmaraExactAmounts(struct CCcontract_info *cp,Eval* eval,const CTransactio return eval->Invalid("mismatched inputs != outputs + txfee"); } else return(true); -} +}*/ int32_t MarmaraRandomize(uint32_t ind) { @@ -191,16 +191,21 @@ int32_t MarmaraValidateCoinbase(int32_t height,CTransaction tx) bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn) { - CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid; CPubKey pk,vpk; + std::vector vopret; CTransaction vinTx; uint256 hashBlock; int32_t numvins,numvouts,i,ht,unlockht,vht,vunlockht; uint8_t funcid,vfuncid,*script; CPubKey pk,vpk; numvins = tx.vin.size(); numvouts = tx.vout.size(); if ( numvouts < 1 ) return eval->Invalid("no vouts"); else if ( tx.vout.size() >= 2 ) { - funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); + GetOpReturnData(tx.vout[tx.vout.size()-1].scriptPubKey,vopret); + script = (uint8_t *)vopret.data(); + if ( vopret.size() < 2 || script[0] != EVAL_MARMARA ) + return eval->Invalid("no opreturn"); + funcid = script[1]; if ( funcid == 'P' ) { + funcid = DecodeMaramaraCoinbaseOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,pk,ht,unlockht); for (i=0; iismyvin)(tx.vin[i].scriptSig) != 0 ) @@ -221,6 +226,38 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return(true); } + else if ( funcid == 'L' ) // lock -> lock funds with a unlockht + { + return(true); + } + else if ( funcid == 'R' ) // receive -> agree to receive 'I' from pk, amount, currency, dueht + { + return(true); + } + else if ( funcid == 'I' ) // issue -> issue currency to pk with due date height + { + return(true); + } + else if ( funcid == 'T' ) // transfer -> given 'R' transfer 'I' or 'T' to the pk of 'R' + { + return(true); + } + else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' + { + return(true); + } + else if ( funcid == 'A' ) // agree -> agree that 'I' is unable to be redeemed, remainder + { + return(true); + } + else if ( funcid == 'D' ) // dispute -> given 'I' submit for manual arbitration + { + return(true); + } + else if ( funcid == 'F' ) // foreclose -> given 'A' collect as much of remainder from credit loop + { + return(true); + } } return eval->Invalid("fall through error"); } @@ -264,6 +301,34 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, return(totalinputs); } +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 issuetxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + cp = CCinit(&C,EVAL_MARMARA); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + errorstr = (char *)"couldnt finalize CCtx"; + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraOpret('R',issuetxid,senderpk,amount,matures,currency)); + } else errorstr = "dont have enough normal inputs for 2*txfee"; + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + } + return(result); +} + std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); From b7341671fa97623020bf8e4781549761775f05cf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:45:51 -1100 Subject: [PATCH 082/122] CC baton for credit loop --- src/cc/marmara.cpp | 73 +++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index ba4e4b005..75f9e0ee4 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -87,25 +87,6 @@ int32_t MarmaraUnlockht(int32_t height) return(height + MarmaraRandomize(ind)); } -CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) -{ - CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; - unlockht = MarmaraUnlockht(ht); - opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); - if ( 0 ) - { - std::vector vopret; uint8_t *script,i; - GetOpReturnData(opret,vopret); - script = (uint8_t *)vopret.data(); - { - for (i=0; i vopret; uint8_t *script,e,f,funcid; @@ -131,6 +112,32 @@ uint8_t DecodeMaramaraCoinbaseOpRet(const CScript scriptPubKey,CPubKey &pk,int32 return(0); } +CScript EncodeMarmaraCoinbaseOpRet(uint8_t funcid,CPubKey pk,int32_t ht) +{ + CScript opret; int32_t unlockht; uint8_t evalcode = EVAL_MARMARA; + unlockht = MarmaraUnlockht(ht); + opret << OP_RETURN << E_MARSHAL(ss << evalcode << funcid << pk << ht << unlockht); + if ( 0 ) + { + std::vector vopret; uint8_t *script,i; + GetOpReturnData(opret,vopret); + script = (uint8_t *)vopret.data(); + { + for (i=0; i 0 ) + if ( currency != "MARMARA" ) + errorstr = "for now, only MARMARA loops are supported"; + else if ( amount < txfee ) + errorstr = "amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip->GetHeight() ) + errorstr = "it must mature in the future"; + if ( errorstr == 0 ) { - mtx.vout.push_back(CTxOut(txfee,CScript() << ParseHex(HexStr(senderpk)) << OP_CHECKSIG)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraOpret('R',issuetxid,senderpk,amount,matures,currency)); - } else errorstr = "dont have enough normal inputs for 2*txfee"; + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + errorstr = (char *)"couldnt finalize CCtx"; + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); + } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; + } if ( rawtx.size() == 0 || errorstr != 0 ) { result.push_back(Pair("result","error")); @@ -325,6 +341,11 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("createtxid",createtxid)); + result.push_back(Pair("senderpk",senderpk)); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("matures",matures)); + result.push_back(Pair("currency",currency)); } return(result); } From cd4b54dfeae90ccfadb39435f99b2eda88bbbb89 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:47:18 -1100 Subject: [PATCH 083/122] Strings --- src/cc/marmara.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 75f9e0ee4..5db0c07c3 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -341,8 +341,8 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("createtxid",createtxid)); - result.push_back(Pair("senderpk",senderpk)); + result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("senderpk",HexStr(senderpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); result.push_back(Pair("matures",matures)); result.push_back(Pair("currency",currency)); From 85271fb3a507ae79e8325b2450c2ed48881ce1b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:48:20 -1100 Subject: [PATCH 084/122] Test --- src/cc/marmara.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5db0c07c3..a50059305 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -317,11 +317,11 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri txfee = 10000; mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) - errorstr = "for now, only MARMARA loops are supported"; + errorstr = (char *)"for now, only MARMARA loops are supported"; else if ( amount < txfee ) - errorstr = "amount must be for more than txfee"; - else if ( matures <= chainActive.LastTip->GetHeight() ) - errorstr = "it must mature in the future"; + errorstr = (char *)"amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip()->GetHeight() ) + errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) From 38093ec82aeacf182fd322b69f89498256d5c495 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 02:52:29 -1100 Subject: [PATCH 085/122] Need baton in 'R' --- src/cc/marmara.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index a50059305..1ff1855dd 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -311,7 +311,7 @@ int64_t AddMarmaraCoinbases(struct CCcontract_info *cp,CMutableTransaction &mtx, UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); - UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; int32_t needbaton = 0; cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; @@ -324,10 +324,13 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri errorstr = (char *)"it must mature in the future"; if ( errorstr == 0 ) { - if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + if ( createtxid == zeroid ) + needbaton = 1; + if ( AddNormalinputs(mtx,mypk,(1+needbaton)*txfee,1) > 0 ) { errorstr = (char *)"couldnt finalize CCtx"; - mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); + if ( needbaton != 0 ) + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; } From 908ee69451cc2cceb48775b0a9344d331234a261 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:04:34 -1100 Subject: [PATCH 086/122] Marmarareceive roc --- src/cc/CCMarmara.h | 1 + src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 27 ++++++++++++++++++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 4a50c2539..d3eb67b77 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -25,6 +25,7 @@ #define MARMARA_MAXLOCK (1440 * 24 * 30) uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] +UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index d6b801dd5..5baadf34a 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -444,6 +444,7 @@ static const CRPCCommand vRPCCommands[] = // Marmara { "marmara", "marmaraaddress", &marmaraaddress, true }, { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, + { "marmara", "marmarareceive", &marmara_receive, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index bd00bb9d1..4787130e2 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -273,6 +273,7 @@ extern UniValue pricesfinish(const UniValue& params, bool fHelp); extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); +extern UniValue marmara_receive(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1790a574a..a2b0afa37 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5537,7 +5537,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; - throw runtime_error("marmara_poolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); + throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5547,6 +5547,31 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) return(MarmaraPoolPayout(0,firstheight,perc,jsonstr)); // [[pk0, shares0], [pk1, shares1], ...] } +UniValue marmara_receive(const UniValue& params, bool fHelp) +{ + uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; + if ( fHelp || (params.size() != 5 && params.size() != 4) ) + { + // marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + throw runtime_error("marmarareceive senderpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + memset(&createtxid,0,sizeof(createtxid)); + senderpub = ParseHex(params[0].get_str().c_str()); + if (senderpub.size()!= 33) + { + ERR_RESULT("invalid sender pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + if ( params.size() == 5 ) + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,createtxid)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 2084694843126a610875b6a5294219b30e0c3925 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:08:37 -1100 Subject: [PATCH 087/122] Syntax --- 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 a2b0afa37..7160489de 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5549,10 +5549,11 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) UniValue marmara_receive(const UniValue& params, bool fHelp) { - uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector senderpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || (params.size() != 5 && params.size() != 4) ) { - // marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + // 1st marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 + // after marmarareceive 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 throw runtime_error("marmarareceive senderpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) From a90b1bb7d516a9e21d8ae9f5bb751024923ef016 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:10:35 -1100 Subject: [PATCH 088/122] Clear default errorstr --- src/cc/marmara.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1ff1855dd..353e07a30 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -332,6 +332,8 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri if ( needbaton != 0 ) mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,senderpk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('R',createtxid,senderpk,amount,matures,currency)); + if ( rawtx.size() > 0 ) + errorstr = 0; } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; } if ( rawtx.size() == 0 || errorstr != 0 ) From 46069b7159ed360f0ec32e92d79a9553468cfd58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:12:07 -1100 Subject: [PATCH 089/122] funcid --- src/cc/marmara.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 353e07a30..85487f748 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -346,6 +346,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("funcid","R")); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("senderpk",HexStr(senderpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); From c10dfbb858ed1f36384043a82ff1a033f2a6299c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:21:20 -1100 Subject: [PATCH 090/122] marmara_issue --- src/cc/CCMarmara.h | 1 + src/cc/marmara.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 23 ++++++++++++++++++++ 5 files changed, 71 insertions(+) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index d3eb67b77..5fc1ce891 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,6 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); +UniValue MarmaraIssue(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 85487f748..5cd623966 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -356,6 +356,51 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri return(result); } +UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +{ + CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); + UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; + cp = CCinit(&C,EVAL_MARMARA); + if ( txfee == 0 ) + txfee = 10000; + mypk = pubkey2pk(Mypubkey()); + if ( currency != "MARMARA" ) + errorstr = (char *)"for now, only MARMARA loops are supported"; + else if ( amount < txfee ) + errorstr = (char *)"amount must be for more than txfee"; + else if ( matures <= chainActive.LastTip()->GetHeight() ) + errorstr = (char *)"it must mature in the future"; + if ( errorstr == 0 ) + { + if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) + { + errorstr = (char *)"couldnt finalize CCtx"; + mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('I',createtxid,receiverpk,amount,matures,currency)); + if ( rawtx.size() > 0 ) + errorstr = 0; + } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; + } + if ( rawtx.size() == 0 || errorstr != 0 ) + { + result.push_back(Pair("result","error")); + if ( errorstr != 0 ) + result.push_back(Pair("error",errorstr)); + } + else + { + result.push_back(Pair("result",(char *)"success")); + result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("funcid","R")); + result.push_back(Pair("createtxid",createtxid.GetHex())); + result.push_back(Pair("receiverpk",HexStr(receiverpk))); + result.push_back(Pair("amount",ValueFromAmount(amount))); + result.push_back(Pair("matures",matures)); + result.push_back(Pair("currency",currency)); + } + return(result); +} + std::string MarmaraFund(uint64_t txfee,int64_t funds) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 5baadf34a..add90902c 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -445,6 +445,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmaraaddress", &marmaraaddress, true }, { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, { "marmara", "marmarareceive", &marmara_receive, true }, + { "marmara", "marmaraissue", &marmara_issue, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index 4787130e2..b7654da38 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -274,6 +274,7 @@ extern UniValue pegsaddress(const UniValue& params, bool fHelp); extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue marmara_receive(const UniValue& params, bool fHelp); +extern UniValue marmara_issue(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7160489de..bb6bb8c12 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5573,6 +5573,29 @@ UniValue marmara_receive(const UniValue& params, bool fHelp) return(MarmaraReceive(0,pubkey2pk(senderpub),amount,currency,matures,createtxid)); } +UniValue marmara_issue(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 5 ) + { + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmarareceive receiverpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + receiverpub = ParseHex(params[0].get_str().c_str()); + if (receiverpub.size()!= 33) + { + ERR_RESULT("invalid receiverpub pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); +} + UniValue channelslist(const UniValue& params, bool fHelp) { if ( fHelp || params.size() > 0 ) From 8ae7b65569a4f5dc8b0aee5929841a544e518539 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:26:43 -1100 Subject: [PATCH 091/122] Off by 1 --- src/cc/marmara.cpp | 2 +- src/wallet/rpcwallet.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 5cd623966..1b06dfd2f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -391,7 +391,7 @@ UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("funcid","R")); + result.push_back(Pair("funcid","I")); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("receiverpk",HexStr(receiverpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index bb6bb8c12..e77f8e55a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5578,8 +5578,8 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 1440 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb - throw runtime_error("marmarareceive receiverpk amount currency matures createtxid\n"); + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmaraissue receiverpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); @@ -5591,7 +5591,7 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) } amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; currency = params[2].get_str(); - matures = atol(params[3].get_str().c_str()) + chainActive.LastTip()->GetHeight() + 1; + matures = atol(params[3].get_str().c_str()); createtxid = Parseuint256((char *)params[4].get_str().c_str()); return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); } From c334d5c2e426605445bb6a5372dcfb3c99d634d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 03:36:14 -1100 Subject: [PATCH 092/122] Marmara transfer --- src/cc/CCMarmara.h | 2 +- src/cc/marmara.cpp | 5 +++-- src/rpc/server.cpp | 1 + src/rpc/server.h | 1 + src/wallet/rpcwallet.cpp | 25 ++++++++++++++++++++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 5fc1ce891..8fbe25b62 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -26,7 +26,7 @@ uint64_t komodo_block_prg(uint32_t nHeight); UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char *jsonstr); // [[pk0, shares0], [pk1, shares1], ...] UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); -UniValue MarmaraIssue(uint64_t txfee,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey senderpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid); bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx, uint32_t nIn); diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 1b06dfd2f..41287c76f 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -356,7 +356,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri return(result); } -UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) +UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t amount,std::string currency,int32_t matures,uint256 createtxid) { CMutableTransaction mtx = CreateNewContextualCMutableTransaction(Params().GetConsensus(), komodo_nextheight()); UniValue result(UniValue::VOBJ); CPubKey mypk; struct CCcontract_info *cp,C; std::string rawtx; char *errorstr=0; @@ -391,7 +391,8 @@ UniValue MarmaraIssue(uint64_t txfee,CPubKey receiverpk,int64_t amount,std::stri { result.push_back(Pair("result",(char *)"success")); result.push_back(Pair("rawtx",rawtx)); - result.push_back(Pair("funcid","I")); + char str[2]; str[0] = funcid, str[1] = 0; + result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",createtxid.GetHex())); result.push_back(Pair("receiverpk",HexStr(receiverpk))); result.push_back(Pair("amount",ValueFromAmount(amount))); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index add90902c..497cb1ae2 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -446,6 +446,7 @@ static const CRPCCommand vRPCCommands[] = { "marmara", "marmarapoolpayout", &marmara_poolpayout, true }, { "marmara", "marmarareceive", &marmara_receive, true }, { "marmara", "marmaraissue", &marmara_issue, true }, + { "marmara", "marmaratransfer", &marmara_transfer, true }, // Payments { "payments", "paymentsaddress", &paymentsaddress, true }, diff --git a/src/rpc/server.h b/src/rpc/server.h index b7654da38..19680c0ef 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -275,6 +275,7 @@ extern UniValue marmaraaddress(const UniValue& params, bool fHelp); extern UniValue marmara_poolpayout(const UniValue& params, bool fHelp); extern UniValue marmara_receive(const UniValue& params, bool fHelp); extern UniValue marmara_issue(const UniValue& params, bool fHelp); +extern UniValue marmara_transfer(const UniValue& params, bool fHelp); extern UniValue paymentsaddress(const UniValue& params, bool fHelp); extern UniValue gatewaysaddress(const UniValue& params, bool fHelp); extern UniValue gatewayslist(const UniValue& params, bool fHelp); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e77f8e55a..d0dc60489 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5593,7 +5593,30 @@ UniValue marmara_issue(const UniValue& params, bool fHelp) currency = params[2].get_str(); matures = atol(params[3].get_str().c_str()); createtxid = Parseuint256((char *)params[4].get_str().c_str()); - return(MarmaraIssue(0,pubkey2pk(receiverpub),amount,currency,matures,createtxid)); + return(MarmaraIssue(0,'I',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); +} + +UniValue marmara_transfer(const UniValue& params, bool fHelp) +{ + UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; + if ( fHelp || params.size() != 5 ) + { + // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + throw runtime_error("marmaratransfer receiverpk amount currency matures createtxid\n"); + } + if ( ensure_CCrequirements() < 0 ) + throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); + receiverpub = ParseHex(params[0].get_str().c_str()); + if (receiverpub.size()!= 33) + { + ERR_RESULT("invalid receiverpub pubkey"); + return result; + } + amount = atof(params[1].get_str().c_str()) * COIN + 0.00000000499999; + currency = params[2].get_str(); + matures = atol(params[3].get_str().c_str()); + createtxid = Parseuint256((char *)params[4].get_str().c_str()); + return(MarmaraIssue(0,'T',pubkey2pk(receiverpub),amount,currency,matures,createtxid)); } UniValue channelslist(const UniValue& params, bool fHelp) From e06138fecf70ac4e36ce1e084e64b1336738ec42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 05:34:42 -1100 Subject: [PATCH 093/122] Cap -ac_perc to be based on million max --- src/cc/marmara.cpp | 19 +++++-------------- src/komodo_bitcoind.h | 6 ++++-- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 41287c76f..9a5a1e6ef 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -251,20 +251,9 @@ bool MarmaraValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } else if ( funcid == 'S' ) // collect -> automatically spend issuers locked funds, given 'I' { - return(true); - } - else if ( funcid == 'A' ) // agree -> agree that 'I' is unable to be redeemed, remainder - { - return(true); - } - else if ( funcid == 'D' ) // dispute -> given 'I' submit for manual arbitration - { - return(true); - } - else if ( funcid == 'F' ) // foreclose -> given 'A' collect as much of remainder from credit loop - { - return(true); + return(true); // iterate from issuer all remainder after maturity } + // staking only for locked utxo } return eval->Invalid("fall through error"); } @@ -315,6 +304,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; + // check for batonownership by senderpk and parameters match createtxid mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; @@ -363,6 +353,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a cp = CCinit(&C,EVAL_MARMARA); if ( txfee == 0 ) txfee = 10000; + // make sure if transfer that it is not too late mypk = pubkey2pk(Mypubkey()); if ( currency != "MARMARA" ) errorstr = (char *)"for now, only MARMARA loops are supported"; @@ -376,7 +367,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a { errorstr = (char *)"couldnt finalize CCtx"; mtx.vout.push_back(MakeCC1vout(EVAL_MARMARA,txfee,receiverpk)); - rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('I',createtxid,receiverpk,amount,matures,currency)); + rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret(funcid,createtxid,receiverpk,amount,matures,currency)); if ( rawtx.size() > 0 ) errorstr = 0; } else errorstr = (char *)"dont have enough normal inputs for 2*txfee"; diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 841396a00..9ecb8ce77 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1165,10 +1165,12 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) //fprintf(stderr,"(%d %.8f).%d ",i,dstr(pblock->vtx[i].vout[j].nValue),j); if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; + if ( total > 1000000 * COIN ) + total = 1000000 * COIN; } } - commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; - //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; + commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d0dc60489..f17faca58 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5601,7 +5601,7 @@ UniValue marmara_transfer(const UniValue& params, bool fHelp) UniValue result(UniValue::VOBJ); uint256 createtxid; std::vector receiverpub; int64_t amount; int32_t matures; std::string currency; if ( fHelp || params.size() != 5 ) { - // marmaraissue 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb + // marmaratransfer 039433dc3749aece1bd568f374a45da3b0bc6856990d7da3cd175399577940a775 7.5 MARMARA 2693 e5b1ef8ec90e981d3011c8e024cef869b69af2d4dd6837d1ab1d394d3730b7cb throw runtime_error("marmaratransfer receiverpk amount currency matures createtxid\n"); } if ( ensure_CCrequirements() < 0 ) From e565e0b7204314b2e48fdf83d6454a97a9b04df3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 06:15:44 -1100 Subject: [PATCH 094/122] Break --- src/komodo_bitcoind.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9ecb8ce77..b99b998e1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1166,7 +1166,10 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) if ( i != 0 || j != 1 ) total += pblock->vtx[i].vout[j].nValue; if ( total > 1000000 * COIN ) + { total = 1000000 * COIN; + break; + } } } //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; From aa7d0e8d888b5f11e4caf5e031924d2b196e8c93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 06:57:20 -1100 Subject: [PATCH 095/122] Fix pos64 with verushash --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 128a94e3a..ce2b88156 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1197,7 +1197,7 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From 530fb3901342196b595572ffe6519d0516ec525f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:04:45 -1100 Subject: [PATCH 096/122] +print --- src/komodo_bitcoind.h | 4 ++-- src/miner.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b99b998e1..b640d3db0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2084,7 +2084,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); bool resetstaker = false; if ( array != 0 ) @@ -2140,7 +2140,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,"numkp.%d blocktime.%u\n",numkp,*blocktimep); +fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; inBits); + printf("isStake.%d\n",isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { LEAVE_CRITICAL_SECTION(cs_main); From 6c9d66ed0de5ca0af847cbf139251fefa6669dab Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:10:50 -1100 Subject: [PATCH 097/122] Set isStaked --- src/miner.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 02a3e1a91..2c6f4af8d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -482,7 +482,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 int32_t stakeHeight = chainActive.Height() + 1; //LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); - printf("isStake.%d\n",isStake); if ( ASSETCHAINS_SYMBOL[0] != 0 && isStake ) { LEAVE_CRITICAL_SECTION(cs_main); @@ -802,6 +801,8 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } if ( ASSETCHAINS_MARMARA != 0 && nHeight > 0 && (nHeight & 1) == 0 ) scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); + if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) + isStake = true; return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake); } @@ -1198,7 +1199,7 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif From db879566f571cc7c123b554fe83769d845ead722 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:16:34 -1100 Subject: [PATCH 098/122] Test --- src/komodo_bitcoind.h | 8 ++++---- src/miner.cpp | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b640d3db0..66097b3f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1312,12 +1312,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 "); 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; } } @@ -2084,7 +2084,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); bool resetstaker = false; if ( array != 0 ) @@ -2140,7 +2140,7 @@ fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL), 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,"numkp.%d blocktime.%u\n",numkp,*blocktimep); +//fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep); block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; iGetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", -1) == 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif @@ -1502,7 +1502,7 @@ void static BitcoinMiner() { static uint32_t counter; if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) - fprintf(stderr,"created illegal block, retry\n"); + fprintf(stderr,"created illegal blockB, retry\n"); sleep(1); continue; } From 3118af7d07ab9b9375a8b8c1b4fb6a579a6100be Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:24:38 -1100 Subject: [PATCH 099/122] +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 66097b3f9..478aa9ac4 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2039,9 +2039,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 Date: Sun, 13 Jan 2019 07:26:02 -1100 Subject: [PATCH 100/122] Test --- src/miner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index f88b8f260..f6c3e1aac 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1199,14 +1199,14 @@ void static BitcoinMiner_noeq() miningTimer.start(); #ifdef ENABLE_WALLET - CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, 0); + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, Mining_height, ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 100 ) + if ( counter++ < 10 ) fprintf(stderr,"created illegal block, retry\n"); continue; } @@ -1501,7 +1501,7 @@ void static BitcoinMiner() if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 ) + if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 ) fprintf(stderr,"created illegal blockB, retry\n"); sleep(1); continue; From 290926a05f81cbb586d60d24f106415507851981 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:34:22 -1100 Subject: [PATCH 101/122] 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 478aa9ac4..fb5ca24a0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1312,12 +1312,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 "); 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; } } @@ -2039,8 +2039,11 @@ 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--) + for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { From 265c9b3c3b04bc1234594bc5aaee344502dff81c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:40:06 -1100 Subject: [PATCH 102/122] 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 fb5ca24a0..9e05ea1f9 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2052,9 +2052,15 @@ 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); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," vs "); + for (int i=31; i>=16; i--) + fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); + fprintf(stderr," iter.%d\n",iter); 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); From 6922cdfa835e697a850bfed64e0a90f61ab42e39 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:43:40 -1100 Subject: [PATCH 103/122] Test --- src/komodo_bitcoind.h | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9e05ea1f9..bf7dff756 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2039,12 +2039,12 @@ 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=31; i>=16; i--) + /*for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,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; itertxtime+minage ) continue; hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," iter.%d\n",iter); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); @@ -2164,7 +2158,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; @@ -2177,7 +2171,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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); +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 @@ -2187,7 +2181,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } eligible = besttime; 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); +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; @@ -2199,7 +2193,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; 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,"utxo not eligible\n"); } if ( numkp < 1000 && array != 0 ) { From 31bad59a04c8a09aa92c53a4d96e203fe4ef9094 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:46:32 -1100 Subject: [PATCH 104/122] Test --- 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 bf7dff756..634f61abf 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,7 +1267,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } 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 ) @@ -1312,12 +1312,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 "); 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; } } @@ -2054,7 +2054,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); From 05f3d0f8723ba0810ba099ba5cdcc5e094fcbadf Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:52:01 -1100 Subject: [PATCH 105/122] Test --- 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 634f61abf..ae564dc80 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1304,7 +1304,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; } @@ -1312,17 +1312,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 && validateflag != 0 ) + //if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From b7f3a6778a92c16a5d93eb8ffa2906c2910a2eba Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 07:58:01 -1100 Subject: [PATCH 106/122] Test --- src/komodo_bitcoind.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index ae564dc80..7741bfb11 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2158,7 +2158,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; @@ -2171,7 +2171,7 @@ fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); 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); +//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 @@ -2181,7 +2181,7 @@ fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u te } eligible = besttime; 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); +//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; @@ -2193,7 +2193,7 @@ fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",n *txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime; 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,"utxo not eligible\n"); } if ( numkp < 1000 && array != 0 ) { @@ -2229,7 +2229,7 @@ fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",n for (i=0; i Date: Sun, 13 Jan 2019 07:59:28 -1100 Subject: [PATCH 107/122] Split commission calc --- 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 7741bfb11..9dc481529 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1172,8 +1172,8 @@ uint64_t komodo_commission(const CBlock *pblock,int32_t height) } } } - //commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; - commission = ((total * ASSETCHAINS_COMMISSION) / COIN); + commission = ((total / 10000) * ASSETCHAINS_COMMISSION) / 10000; + //commission = ((total * ASSETCHAINS_COMMISSION) / COIN); } if ( commission < 10000 ) commission = 0; From c50181ee6b42b611016553b37fb8615d1de78ce2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 08:10:52 -1100 Subject: [PATCH 108/122] Use BitcoinMiner for staking verushash --- src/komodo_bitcoind.h | 2 +- src/miner.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9dc481529..a469ad2ed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1322,7 +1322,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]); diff --git a/src/miner.cpp b/src/miner.cpp index f6c3e1aac..d68ea7369 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1907,12 +1907,12 @@ void static BitcoinMiner() for (int i = 0; i < nThreads; i++) { #ifdef ENABLE_WALLET - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); else minerThreads->create_thread(boost::bind(&BitcoinMiner_noeq, pwallet)); #else - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) minerThreads->create_thread(&BitcoinMiner); else minerThreads->create_thread(&BitcoinMiner_noeq); From 5ee83c628c943094f7ab2c5b60c6d22ed65e5503 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 08:24:46 -1100 Subject: [PATCH 109/122] -print --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a469ad2ed..ebc50fa62 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1267,7 +1267,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } 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 ) @@ -1304,7 +1304,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; } @@ -2229,7 +2229,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; i 1 ) { - fprintf(stderr,"mine to -ac_script\n"); + //fprintf(stderr,"mine to -ac_script\n"); //txNew.vout[1].scriptPubKey = CScript() << ParseHex(); int32_t len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; From cf9f6577fc260772a5f47ac022246577599d7622 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Jan 2019 14:10:11 -1100 Subject: [PATCH 110/122] Adjust assert --- src/wallet/rpcwallet.cpp | 1 + src/wallet/wallet.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f17faca58..007c187a6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5537,6 +5537,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; + marmarapoolpayout 0 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000]]' throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index dd188d418..0000f8d42 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1180,7 +1180,7 @@ bool DecrementNoteWitnesses(NoteDataMap& noteDataMap, int indexHeight, int64_t n assert((nWitnessCacheSize - 1) >= nd->witnesses.size()); } } - assert(KOMODO_REWIND != 0 || nWitnessCacheSize > 0); + assert(KOMODO_REWIND != 0 || nWitnessCacheSize > 0 || WITNESS_CACHE_SIZE != _COINBASE_MATURITY+10); return true; } From 41363b7ea4089cc8720877f7a9eb3f626cb9cda0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 14 Jan 2019 17:09:17 +0800 Subject: [PATCH 111/122] fix prints --- src/miner.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 26d1a1df9..e06a570c7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1303,9 +1303,8 @@ void static BitcoinMiner_noeq() { int32_t percPoS,z; hashTarget = komodo_PoWtarget(&percPoS,hashTarget,Mining_height,ASSETCHAINS_STAKED); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); - fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%%\n",percPoS,(int32_t)ASSETCHAINS_STAKED); + if ( ASSETCHAINS_STAKED < 100 ) + LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED); } while (true) @@ -1630,18 +1629,16 @@ void static BitcoinMiner() } //else fprintf(stderr,"duplicate at j.%d\n",j); } else Mining_start = 0; } else Mining_start = 0; + if ( ASSETCHAINS_STAKED > 0 ) { int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( ASSETCHAINS_STAKED < 100 ) - { - //for (z=31; z>=0; z--) - // fprintf(stderr,"%02x",((uint8_t *)&HASHTarget_POW)[z]); LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED); - } } + while (true) { /*if ( KOMODO_INSYNC == 0 ) From b0ca0415ef02b2f32753e51befa98c4709a12d16 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 14 Jan 2019 17:27:34 +0800 Subject: [PATCH 112/122] fix build --- 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 9e253b6ea..eae71f987 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5672,7 +5672,7 @@ UniValue marmara_poolpayout(const UniValue& params, bool fHelp) if ( fHelp || params.size() != 3 ) { // marmarapoolpayout 0.5 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000],["02ebc786cb83de8dc3922ab83c21f3f8a2f3216940c3bf9da43ce39e2a3a882c92",100]]'; - marmarapoolpayout 0 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000]]' + //marmarapoolpayout 0 2 '[["024131032ed90941e714db8e6dd176fe5a86c9d873d279edecf005c06f773da686",1000]]' throw runtime_error("marmarapoolpayout perc firstheight \"[[\\\"pubkey\\\":shares], ...]\"\n"); } if ( ensure_CCrequirements() < 0 ) From f20420ea80a5147d56502968c6a77b8f2678851d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 14 Jan 2019 18:18:18 +0800 Subject: [PATCH 113/122] fixed staking/generate in getmininginfo --- src/rpc/mining.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index dccbd9cfe..3843529ac 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -438,8 +438,11 @@ UniValue getmininginfo(const UniValue& params, bool fHelp) obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC())); obj.push_back(Pair("chain", Params().NetworkIDString())); #ifdef ENABLE_MINING - obj.push_back(Pair("staking", VERUS_MINTBLOCKS)); - obj.push_back(Pair("generate", GetBoolArg("-gen", false))); + bool staking = VERUS_MINTBLOCKS; + if ( ASSETCHAINS_STAKED != 0 && GetBoolArg("-gen", false) && GetBoolArg("-genproclimit", -1) == 0 ) + staking = true; + obj.push_back(Pair("staking", staking)); + obj.push_back(Pair("generate", GetBoolArg("-gen", false) && GetBoolArg("-genproclimit", -1) != 0 )); obj.push_back(Pair("numthreads", (int64_t)KOMODO_MININGTHREADS)); #endif return obj; From 400a0758c1cd785bcedc5864794084045849cf58 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 16 Jan 2019 20:27:35 +0800 Subject: [PATCH 114/122] Many bug fixes. VerusHash now works with PoS64 without special exemptions. Difficulty on new chains still behaves weridly, hoping resolves as chain ages. Also reduced CPU load on all staking. These changes should work better if you are not the only node staking. --- src/komodo_bitcoind.h | 29 ++++++++++++++++------------- src/komodo_globals.h | 4 +++- src/komodo_utils.h | 5 +++-- src/miner.cpp | 41 ++++++++++++++++++++++++++--------------- 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index bb85ef1d1..662d0703c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1274,7 +1274,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); + mindiff.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; @@ -1342,11 +1342,12 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t oldflag = 0,dispflag = 0; 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) ) + if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); + sum = arith_uint256(0); ave = sum; - easydiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + easydiff.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); for (i=n=m=0; i<100; i++) { ht = height - 100 + i; @@ -1372,8 +1373,10 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } + // We now do actual PoS % at the start. Requires coin distribution in first 10 blocks! + // This is not hard to do and stops the chain having its PoS/PoW in large chunks. if ( m+n < 100 ) - percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; + percPoS = (percPoS*100) / (m+n); if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; @@ -1432,7 +1435,8 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); } } - else bnTarget = ave; // recent ave is perfect + else + bnTarget = ave; // recent ave is perfect return(bnTarget); } @@ -1468,7 +1472,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { if ( 0 && 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)); - if ( slowflag != 0 && pindex != 0 && height > 100) + if ( slowflag != 0 && pindex != 0 ) { pindex->segid = -1; //fprintf(stderr,"PoW block detected set segid.%d <- %d\n",height,pindex->segid); @@ -1477,7 +1481,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ else { isPoS = 2; // 2 means staking utxo validated - if ( slowflag != 0 && height > 100 ) + if ( slowflag != 0 ) { CTxDestination voutaddress; char voutaddr[64]; if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) ) @@ -1831,12 +1835,11 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) return(-1); } else { - // I think this means the block is valid PoW. We need to set the pindex->segid here. failed = 0; CBlockIndex *pindex; BlockMap::const_iterator it = mapBlockIndex.find(pblock->GetHash()); pindex = it != mapBlockIndex.end() ? it->second : NULL; - if ( pindex != 0 && height > 100 && pindex->segid == -2 ) { + if ( pindex != 0 && pindex->segid == -2 ) { pindex->segid = -1; //fprintf(stderr,"PoW block detected set segid.%d <- %d\n",height,pindex->segid); } @@ -2083,7 +2086,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return 0; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); - mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + mindiff.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); *utxovaluep = 0; @@ -2096,7 +2099,7 @@ 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 ( *blocktimep < 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); @@ -2155,7 +2158,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt //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,"numkp.%d blocktime.%u\n",numkp,*blocktimep); - block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; + block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; inTime+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; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index ef7af0ba2..f2f6ed6b4 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -53,7 +53,7 @@ bool VERUS_MINTBLOCKS; char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096],NOTARYADDRS[64][36]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_BEAMPORT,ASSETCHAINS_CODAPORT; -uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1; +uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1,STAKING_MIN_DIFF; uint32_t ASSETCHAINS_MAGIC = 2387029918; int64_t ASSETCHAINS_GENESISTXVAL = 5000000000; @@ -80,6 +80,8 @@ uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff,0xfffffff}; uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16}; uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,4096}; uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH; +// min diff returned from GetNextWorkRequired needs to be added here for each algo, so they can work with ac_staked. +uint32_t ASSETCHAINS_MINDIFF[] = {537857807,504303375}; // Verus proof of stake controls int32_t ASSETCHAINS_LWMAPOS = 0; // percentage of blocks should be PoS diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0ac40a48b..74e82f1e2 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1684,13 +1684,13 @@ void komodo_args(char *argv0) IS_KOMODO_NOTARY = 1; KOMODO_MININGTHREADS = 1; mapArgs ["-genproclimit"] = itostr(KOMODO_MININGTHREADS); - IS_STAKED_NOTARY = -1; + IS_STAKED_NOTARY = -1; fprintf(stderr,"running as notary.%d %s\n",i,Notaries_elected1[i][0]); break; } } } - name = GetArg("-ac_name",""); + name = GetArg("-ac_name",""); if ( argv0 != 0 ) { len = (int32_t)strlen(argv0); @@ -1726,6 +1726,7 @@ void komodo_args(char *argv0) if (std::string(ASSETCHAINS_ALGORITHMS[i]) == selectedAlgo) { ASSETCHAINS_ALGO = i; + STAKING_MIN_DIFF = ASSETCHAINS_MINDIFF[i]; // only worth mentioning if it's not equihash if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH) printf("ASSETCHAINS_ALGO, algorithm set to %s\n", selectedAlgo.c_str()); diff --git a/src/miner.cpp b/src/miner.cpp index e06a570c7..e90b22a5a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -531,6 +531,19 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //if ( blocktime > pindexPrev->GetMedianTimePast()+60 ) // blocktime = pindexPrev->GetMedianTimePast() + 60; siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig); + // if you skip this check it will create a block too far into the future and not pass ProcessBlock or AcceptBlock. + // This has been moved from the mining loop to save CPU, and to also make ac_staked work with the verus miner. + while ( blocktime-57 > GetAdjustedTime() ) + { + sleep(1); + if ( (rand() % 100) < 1 ) + fprintf(stderr, "%u seconds until elegible, waiting.\n", blocktime-((uint32_t)GetAdjustedTime()+57)); + if ( chainActive.LastTip()->GetHeight() >= stakeHeight ) + { + fprintf(stderr, "Block Arrived, reset staking loop.\n"); + return(0); + } + } } if ( siglen > 0 ) @@ -546,7 +559,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblock->nTime = blocktime; //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); - + } // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, nHeight); @@ -838,7 +851,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, scriptPubKey = Marmara_scriptPubKey(nHeight,pubkey); if ( ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0 ) isStake = true; - return CreateNewBlock(pubkey,scriptPubKey, gpucount, isStake); + return CreateNewBlock(pubkey, scriptPubKey, gpucount, isStake); } void komodo_broadcast(CBlock *pblock,int32_t limit) @@ -1241,7 +1254,7 @@ void static BitcoinMiner_noeq() if ( ptr == 0 ) { static uint32_t counter; - if ( counter++ < 10 ) + if ( ASSETCHAINS_STAKED == 0 && counter++ < 10 ) fprintf(stderr,"created illegal block, retry\n"); continue; } @@ -1301,10 +1314,12 @@ void static BitcoinMiner_noeq() if ( ASSETCHAINS_STAKED != 0 ) { - int32_t percPoS,z; - hashTarget = komodo_PoWtarget(&percPoS,hashTarget,Mining_height,ASSETCHAINS_STAKED); + int32_t percPoS,z; bool fNegative,fOverflow; + HASHTarget_POW = komodo_PoWtarget(&percPoS,hashTarget,Mining_height,ASSETCHAINS_STAKED); + // We use equihash min diff here to make the verus miner instantly finds a blockhash, this saves CPU when staking. + HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); if ( ASSETCHAINS_STAKED < 100 ) - LogPrintf("Block %d : PoS %d%% vs target %d%% \n",Mining_height,percPoS,(int32_t)ASSETCHAINS_STAKED); + LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } while (true) @@ -1319,6 +1334,9 @@ void static BitcoinMiner_noeq() vh.ClearExtra(); int64_t i, count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1; int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO]; + if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) + hashTarget = HASHTarget_POW; + else hashTarget = HASHTarget; // for speed check NONCEMASK at a time for (i = 0; i < count; i++) @@ -1414,7 +1432,6 @@ void static BitcoinMiner_noeq() printf("%lu mega hashes complete - working\n", (ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1) / 1048576); #endif break; - } } } @@ -1724,12 +1741,6 @@ void static BitcoinMiner() } else { - while ( B.nTime-57 > GetAdjustedTime() ) - { - sleep(1); - if ( chainActive.LastTip()->GetHeight() >= Mining_height ) - return(false); - } uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); @@ -1938,12 +1949,12 @@ void static BitcoinMiner() for (int i = 0; i < nThreads; i++) { #ifdef ENABLE_WALLET - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) + if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); else minerThreads->create_thread(boost::bind(&BitcoinMiner_noeq, pwallet)); #else - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH || (ASSETCHAINS_STAKED != 0 && KOMODO_MININGTHREADS == 0) ) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) minerThreads->create_thread(&BitcoinMiner); else minerThreads->create_thread(&BitcoinMiner_noeq); From a4f197794fb89e670714516b130c0ae0acfe0e0a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 16 Jan 2019 21:16:30 +0800 Subject: [PATCH 115/122] Many bug fixes. VerusHash now works with PoS64 without special exemptions. Difficulty on new chains still behaves weridly, hoping resolves as chain ages. Also reduced CPU load on all staking. These changes should work better if you are not the only node staking. --- src/komodo_bitcoind.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 662d0703c..0fea33ee5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1342,6 +1342,12 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he int32_t oldflag = 0,dispflag = 0; CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val; *percPoSp = percPoS = 0; + static bool new_rules, didinit; + if ( !didinit ) { + new_rules = is_STAKED(ASSETCHAINS_SYMBOL) != 0 && is_STAKED(ASSETCHAINS_SYMBOL) != 3 ? true : false; + didinit = true; + } + if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); @@ -1353,6 +1359,9 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he ht = height - 100 + i; if ( ht <= 1 ) continue; + // never count the first 10 blocks, they are always PoW! Cant do this for old chains, so limit to LABS and LAB for now. + if ( new_rules && ht < 10 ) + continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { if ( komodo_segid(0,ht) >= 0 ) @@ -1376,7 +1385,12 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he // We now do actual PoS % at the start. Requires coin distribution in first 10 blocks! // This is not hard to do and stops the chain having its PoS/PoW in large chunks. if ( m+n < 100 ) - percPoS = (percPoS*100) / (m+n); + { + if ( new_rules) + percPoS = (percPoS*100) / (m+n); + else + percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; + } if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; From d072863d6f047b99354d05e583cd85f005e54dc3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 17 Jan 2019 00:06:00 +0800 Subject: [PATCH 116/122] fix 100% chains. --- src/komodo_bitcoind.h | 2 +- src/miner.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0fea33ee5..1ffc68c62 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1457,7 +1457,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,arith_uint256 bhash) { CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; - if ( ASSETCHAINS_STAKED == 100 && height <= 10 ) + if ( ASSETCHAINS_STAKED == 100 && height <= 100 ) return(1); BlockMap::const_iterator it = mapBlockIndex.find(pblock->GetHash()); pindex = it != mapBlockIndex.end() ? it->second : NULL; diff --git a/src/miner.cpp b/src/miner.cpp index e90b22a5a..98bfa55a1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -132,7 +132,7 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" extern CCriticalSection cs_metrics; -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE,STAKING_MIN_DIFF; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; @@ -1316,10 +1316,8 @@ void static BitcoinMiner_noeq() { int32_t percPoS,z; bool fNegative,fOverflow; HASHTarget_POW = komodo_PoWtarget(&percPoS,hashTarget,Mining_height,ASSETCHAINS_STAKED); - // We use equihash min diff here to make the verus miner instantly finds a blockhash, this saves CPU when staking. - HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); - if ( ASSETCHAINS_STAKED < 100 ) - LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); + HASHTarget.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); + LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } while (true) @@ -1334,7 +1332,7 @@ void static BitcoinMiner_noeq() vh.ClearExtra(); int64_t i, count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1; int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO]; - if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) + if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) hashTarget = HASHTarget_POW; else hashTarget = HASHTarget; From 43be0a0e918c5d83a8be0492499f8c962d9b51d5 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 18 Jan 2019 17:54:41 +0800 Subject: [PATCH 117/122] VerusHash fix. 100% PoW wasnt working, min diff is now much higher fixing PoW doing 1s blocks. --- src/komodo_bitcoind.h | 24 ++++++++---------------- src/komodo_globals.h | 4 +++- src/miner.cpp | 16 ++++++++++------ src/notaries_staked.cpp | 4 ++-- 4 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1ffc68c62..2fea50e7b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1296,6 +1296,11 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( iter > 0 ) diff += segid*2; coinage = (value * diff); + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH ) + { + if ( blocktime+iter+segid*2 > prevtime+200 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+120)); + } if ( blocktime+iter+segid*2 > prevtime+480 ) coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); coinage256 = arith_uint256(coinage+1); @@ -1339,14 +1344,9 @@ 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) { - int32_t oldflag = 0,dispflag = 0; + int32_t oldflag = 0,dispflag = 1; CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val; *percPoSp = percPoS = 0; - static bool new_rules, didinit; - if ( !didinit ) { - new_rules = is_STAKED(ASSETCHAINS_SYMBOL) != 0 && is_STAKED(ASSETCHAINS_SYMBOL) != 3 ? true : false; - didinit = true; - } if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) ) return(target); @@ -1359,9 +1359,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he ht = height - 100 + i; if ( ht <= 1 ) continue; - // never count the first 10 blocks, they are always PoW! Cant do this for old chains, so limit to LABS and LAB for now. - if ( new_rules && ht < 10 ) - continue; if ( (pindex= komodo_chainactive(ht)) != 0 ) { if ( komodo_segid(0,ht) >= 0 ) @@ -1385,12 +1382,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he // We now do actual PoS % at the start. Requires coin distribution in first 10 blocks! // This is not hard to do and stops the chain having its PoS/PoW in large chunks. if ( m+n < 100 ) - { - if ( new_rules) - percPoS = (percPoS*100) / (m+n); - else - percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; - } + percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; @@ -1449,7 +1441,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr," ht.%d percPoS.%d vs goal.%d -> diff %d\n",height,percPoS,goalperc,goalperc - percPoS); } } - else + else bnTarget = ave; // recent ave is perfect return(bnTarget); } diff --git a/src/komodo_globals.h b/src/komodo_globals.h index f2f6ed6b4..70d621756 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -81,7 +81,9 @@ uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16}; uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,4096}; uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH; // min diff returned from GetNextWorkRequired needs to be added here for each algo, so they can work with ac_staked. -uint32_t ASSETCHAINS_MINDIFF[] = {537857807,504303375}; +uint32_t ASSETCHAINS_MINDIFF[] = {537857807,486648905}; + // nBits.486704888 -- too low? + // Verus proof of stake controls int32_t ASSETCHAINS_LWMAPOS = 0; // percentage of blocks should be PoS diff --git a/src/miner.cpp b/src/miner.cpp index 98bfa55a1..aac5164cb 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1297,6 +1297,7 @@ void static BitcoinMiner_noeq() pblock->nSolution = solnPlaceholder; savebits = pblock->nBits; arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); + HASHTarget = arith_uint256().SetCompact(savebits); arith_uint256 mask(ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO]); Mining_start = 0; @@ -1315,8 +1316,8 @@ void static BitcoinMiner_noeq() if ( ASSETCHAINS_STAKED != 0 ) { int32_t percPoS,z; bool fNegative,fOverflow; - HASHTarget_POW = komodo_PoWtarget(&percPoS,hashTarget,Mining_height,ASSETCHAINS_STAKED); - HASHTarget.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); + HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED); + HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED); } @@ -1332,10 +1333,12 @@ void static BitcoinMiner_noeq() vh.ClearExtra(); int64_t i, count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1; int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO]; - if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 && Mining_height > 10 ) - hashTarget = HASHTarget_POW; - else hashTarget = HASHTarget; - + if ( ASSETCHAINS_STAKED != 0) + { + if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED < 100 ) + hashTarget = HASHTarget_POW; + else hashTarget = HASHTarget; + } // for speed check NONCEMASK at a time for (i = 0; i < count; i++) { @@ -1429,6 +1432,7 @@ void static BitcoinMiner_noeq() #else printf("%lu mega hashes complete - working\n", (ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1) / 1048576); #endif + pblock->nBits = savebits; break; } } diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index ebee4868e..596c78b90 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -14,9 +14,9 @@ int8_t is_STAKED(const char *chain_name) { static int8_t STAKED,doneinit; if (doneinit == 1 && ASSETCHAINS_SYMBOL[0] != 0) return(STAKED); - if ( (strcmp(chain_name, "LABS") == 0) || (strncmp(chain_name, "LABS", 4) == 0) ) + if ( (strcmp(chain_name, "LABMAIN") == 0) || (strncmp(chain_name, "LABT1", 4) == 0) ) STAKED = 1; - else if ( (strcmp(chain_name, "LAB") == 0) || (strncmp(chain_name, "LAB", 3) == 0) ) + else if ( (strcmp(chain_name, "LABT2") == 0) || (strncmp(chain_name, "LABT2", 3) == 0) ) STAKED = 2; else if ( (strcmp(chain_name, "CFEK") == 0) || (strncmp(chain_name, "CFEK", 4) == 0) ) STAKED = 3; From 45dfd3a590a3cab4635f3262d9d8e3b06a3b5138 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Fri, 18 Jan 2019 17:55:20 +0800 Subject: [PATCH 118/122] fix back to LABS --- src/notaries_staked.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/notaries_staked.cpp b/src/notaries_staked.cpp index 596c78b90..ad1a2132f 100644 --- a/src/notaries_staked.cpp +++ b/src/notaries_staked.cpp @@ -14,7 +14,7 @@ int8_t is_STAKED(const char *chain_name) { static int8_t STAKED,doneinit; if (doneinit == 1 && ASSETCHAINS_SYMBOL[0] != 0) return(STAKED); - if ( (strcmp(chain_name, "LABMAIN") == 0) || (strncmp(chain_name, "LABT1", 4) == 0) ) + if ( (strcmp(chain_name, "LABS") == 0) || (strncmp(chain_name, "LABS", 4) == 0) ) STAKED = 1; else if ( (strcmp(chain_name, "LABT2") == 0) || (strncmp(chain_name, "LABT2", 3) == 0) ) STAKED = 2; From 2c3247e8f1e8e9e9fe5336fb6b94353d7a98817b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 22 Jan 2019 00:12:05 +0800 Subject: [PATCH 119/122] Enable -ac_algo=verushash11 --- src/chainparams.cpp | 8 +++----- src/init.cpp | 8 +++++++- src/komodo_bitcoind.h | 6 ++---- src/komodo_globals.h | 18 +++++++++--------- src/komodo_utils.h | 5 +++-- src/metrics.cpp | 4 ++-- src/miner.cpp | 32 +++++++++++++++++++++++++------- src/primitives/block.cpp | 12 ++++++++++-- src/primitives/block.h | 1 + src/wallet-utility.cpp | 1 + 10 files changed, 63 insertions(+), 32 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 6b0627d20..368e0eb50 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -94,11 +94,10 @@ void *chainparams_commandline(void *ptr); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC; +extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV2; extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER; -extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH; +extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_ALGO; -extern int8_t is_STAKED(const char *chain_name); const arith_uint256 maxUint = UintToArith256(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); class CMainParams : public CChainParams { @@ -269,8 +268,7 @@ void *chainparams_commandline(void *ptr) mainParams.pchMessageStart[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; mainParams.pchMessageStart[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; fprintf(stderr,">>>>>>>>>> %s: p2p.%u rpc.%u magic.%08x %u %u coins\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_MAGIC,ASSETCHAINS_MAGIC,(uint32_t)ASSETCHAINS_SUPPLY); - - if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2) { // this is only good for 60 second blocks with an averaging window of 45. for other parameters, use: // nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing diff --git a/src/init.cpp b/src/init.cpp index 3dd09ac50..6aca3ce1b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1177,7 +1177,8 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) globalVerifyHandle.reset(new ECCVerifyHandle()); // set the hash algorithm to use for this chain - extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH; + // Again likely better solution here, than using long IF ELSE. + extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV2; CVerusHash::init(); CVerusHashV2::init(); if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH) @@ -1185,6 +1186,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) // initialize VerusHash CBlockHeader::SetVerusHash(); } + else if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2) + { + // initialize VerusHashV2 + CBlockHeader::SetVerusHashV2(); + } // Sanity check if (!InitSanityCheck()) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2fea50e7b..b567c1488 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1296,11 +1296,11 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( iter > 0 ) diff += segid*2; coinage = (value * diff); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH ) + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) { if ( blocktime+iter+segid*2 > prevtime+200 ) coinage *= ((blocktime+iter+segid*2) - (prevtime+120)); - } + } if ( blocktime+iter+segid*2 > prevtime+480 ) coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); coinage256 = arith_uint256(coinage+1); @@ -1379,8 +1379,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 && (i % 10) == 9 ) fprintf(stderr," %d, ",percPoS); } - // We now do actual PoS % at the start. Requires coin distribution in first 10 blocks! - // This is not hard to do and stops the chain having its PoS/PoW in large chunks. if ( m+n < 100 ) percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 70d621756..2c2d4e855 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -68,22 +68,22 @@ int64_t MAX_MONEY = 200000000 * 100000000LL; uint64_t ASSETCHAINS_TIMELOCKGTE = _ASSETCHAINS_TIMELOCKOFF; uint64_t ASSETCHAINS_TIMEUNLOCKFROM = 0, ASSETCHAINS_TIMEUNLOCKTO = 0; -uint32_t ASSETCHAINS_LASTERA = 1; +uint64_t ASSETCHAINS_LASTERA = 1; uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS]; #define _ASSETCHAINS_EQUIHASH 0 -uint32_t ASSETCHAINS_NUMALGOS = 2; +uint32_t ASSETCHAINS_NUMALGOS = 3; uint32_t ASSETCHAINS_EQUIHASH = _ASSETCHAINS_EQUIHASH; uint32_t ASSETCHAINS_VERUSHASH = 1; -const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "verushash"}; -uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff,0xfffffff}; -uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16}; -uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,4096}; +uint32_t ASSETCHAINS_VERUSHASHV2 = 2; +const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "verushash", "verushash11"}; +uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff,0xfffffff,0xfffffff}; +uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16,16}; +uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,4096,4096}; uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH; // min diff returned from GetNextWorkRequired needs to be added here for each algo, so they can work with ac_staked. -uint32_t ASSETCHAINS_MINDIFF[] = {537857807,486648905}; - // nBits.486704888 -- too low? - +// VerusHash v1 and 1.1 use a custom tuned number or PoW blocks all are 1s. +uint32_t ASSETCHAINS_MINDIFF[] = {537857807,486648905,486648905}; // Verus proof of stake controls int32_t ASSETCHAINS_LWMAPOS = 0; // percentage of blocks should be PoS diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 74e82f1e2..1fe4c012a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1742,9 +1742,10 @@ void komodo_args(char *argv0) if ( ASSETCHAINS_LASTERA < 1 || ASSETCHAINS_LASTERA > ASSETCHAINS_MAX_ERAS ) { ASSETCHAINS_LASTERA = 1; - printf("ASSETCHAINS_LASTERA, if specified, must be between 1 and %u. ASSETCHAINS_LASTERA set to %u\n", ASSETCHAINS_MAX_ERAS, ASSETCHAINS_LASTERA); + printf("ASSETCHAINS_LASTERA, if specified, must be between 1 and %u. ASSETCHAINS_LASTERA set to %lu\n", ASSETCHAINS_MAX_ERAS, ASSETCHAINS_LASTERA); } ASSETCHAINS_LASTERA -= 1; + printf("ASSETCHAINS_LASTERA = %lu\n", ASSETCHAINS_LASTERA); ASSETCHAINS_TIMELOCKGTE = (uint64_t)GetArg("-ac_timelockgte", _ASSETCHAINS_TIMELOCKOFF); ASSETCHAINS_TIMEUNLOCKFROM = GetArg("-ac_timeunlockfrom", 0); @@ -2069,7 +2070,7 @@ void komodo_args(char *argv0) if ( strcmp("PIRATE",ASSETCHAINS_SYMBOL) == 0 && ASSETCHAINS_HALVING[0] == 77777 ) { ASSETCHAINS_HALVING[0] *= 5; - fprintf(stderr,"PIRATE halving changed to %d %.1f days ASSETCHAINS_LASTERA.%d\n",(int32_t)ASSETCHAINS_HALVING[0],(double)ASSETCHAINS_HALVING[0]/1440,ASSETCHAINS_LASTERA); + fprintf(stderr,"PIRATE halving changed to %d %.1f days ASSETCHAINS_LASTERA.%lu\n",(int32_t)ASSETCHAINS_HALVING[0],(double)ASSETCHAINS_HALVING[0]/1440,ASSETCHAINS_LASTERA); } else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) dpowconfs = 0; diff --git a/src/metrics.cpp b/src/metrics.cpp index a01d381a1..879765933 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -40,7 +40,7 @@ #include extern uint64_t ASSETCHAINS_TIMELOCKGTE; -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH; +extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV2; int64_t komodo_block_unlocktime(uint32_t nHeight); void AtomicTimer::start() @@ -137,7 +137,7 @@ int64_t GetUptime() double GetLocalSolPS() { - if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH) + if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2) { return miningTimer.rate(nHashCount); } diff --git a/src/miner.cpp b/src/miner.cpp index aac5164cb..66f1a263f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -137,7 +137,7 @@ extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; extern const char *ASSETCHAINS_ALGORITHMS[]; -extern int32_t VERUS_MIN_STAKEAGE, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH, ASSETCHAINS_LASTERA, ASSETCHAINS_LWMAPOS, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; +extern int32_t VERUS_MIN_STAKEAGE, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV2, ASSETCHAINS_LASTERA, ASSETCHAINS_LWMAPOS, ASSETCHAINS_NONCESHIFT[], ASSETCHAINS_HASHESPERROUND[]; extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],NOTARYADDRS[64][36]; extern std::string NOTARY_PUBKEY,ASSETCHAINS_OVERRIDE_PUBKEY,ASSETCHAINS_SCRIPTPUB; void vcalc_sha256(char deprecated[(256 >> 3) * 2 + 1],uint8_t hash[256 >> 3],uint8_t *src,int32_t len); @@ -1324,26 +1324,44 @@ void static BitcoinMiner_noeq() while (true) { arith_uint256 arNonce = UintToArith256(pblock->nNonce); - + int64_t *extraPtr; + + // This seems to be a really bad way to do this, but its better than copy pasting the entire miner function at this stage. CVerusHashWriter ss = CVerusHashWriter(SER_GETHASH, PROTOCOL_VERSION); ss << *((CBlockHeader *)pblock); - int64_t *extraPtr = ss.xI64p(); + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH ) + extraPtr = ss.xI64p(); CVerusHash &vh = ss.GetState(); uint256 hashResult = uint256(); vh.ClearExtra(); + + CVerusHashV2Writer ss2 = CVerusHashV2Writer(SER_GETHASH, PROTOCOL_VERSION); + ss2 << *((CBlockHeader *)pblock); + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) + extraPtr = ss2.xI64p(); + CVerusHashV2 &vh2 = ss2.GetState(); + vh2.ClearExtra(); + int64_t i, count = ASSETCHAINS_NONCEMASK[ASSETCHAINS_ALGO] + 1; int64_t hashesToGo = ASSETCHAINS_HASHESPERROUND[ASSETCHAINS_ALGO]; - if ( ASSETCHAINS_STAKED != 0) + if ( ASSETCHAINS_STAKED > 0 && ASSETCHAINS_STAKED < 100 ) { - if ( KOMODO_MININGTHREADS > 0 && ASSETCHAINS_STAKED < 100 ) + if ( KOMODO_MININGTHREADS > 0 ) hashTarget = HASHTarget_POW; - else hashTarget = HASHTarget; + else + hashTarget = HASHTarget; } + else if ( ASSETCHAINS_STAKED == 100 && Mining_height > 100 ) + hashTarget = HASHTarget; + // for speed check NONCEMASK at a time for (i = 0; i < count; i++) { *extraPtr = i; - vh.ExtraHash((unsigned char *)&hashResult); + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH ) + vh.ExtraHash((unsigned char *)&hashResult); + else if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) + vh2.ExtraHash((unsigned char *)&hashResult); if ( UintToArith256(hashResult) <= hashTarget ) { diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index 00fc8cee9..3c0dfdd37 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -46,8 +46,11 @@ uint256 CBlockHeader::GetVerusHash() const uint256 CBlockHeader::GetVerusV2Hash() const { - // no check for genesis block and use the optimized hash - return SerializeVerusHashV2(*this); + if (hashPrevBlock.IsNull()) + // always use SHA256D for genesis block + return SerializeHash(*this); + else + return SerializeVerusHashV2(*this); } void CBlockHeader::SetSHA256DHash() @@ -60,6 +63,11 @@ void CBlockHeader::SetVerusHash() CBlockHeader::hashFunction = &CBlockHeader::GetVerusHash; } +void CBlockHeader::SetVerusHashV2() +{ + CBlockHeader::hashFunction = &CBlockHeader::GetVerusV2Hash; +} + // returns false if unable to fast calculate the VerusPOSHash from the header. // if it returns false, value is set to 0, but it can still be calculated from the full block // in that case. the only difference between this and the POS hash for the contest is that it is not divided by the value out diff --git a/src/primitives/block.h b/src/primitives/block.h index 5cd0a72fe..6ef8e0633 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -106,6 +106,7 @@ public: uint256 GetVerusEntropyHash(int32_t nHeight) const; uint256 GetVerusV2Hash() const; + static void SetVerusHashV2(); int64_t GetBlockTime() const { diff --git a/src/wallet-utility.cpp b/src/wallet-utility.cpp index 7af2ca5bf..f4041dfbe 100644 --- a/src/wallet-utility.cpp +++ b/src/wallet-utility.cpp @@ -18,6 +18,7 @@ uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint32_t ASSETCHAINS_EQUIHASH = 0; uint32_t ASSETCHAINS_VERUSHASH = 1; +uint32_t ASSETCHAINS_VERUSHASHV2 = 2; uint32_t ASSETCHAINS_ALGO = 0; int32_t ASSETCHAINS_LWMAPOS = 0; int32_t VERUS_BLOCK_POSUNITS = 1000; From 8324e606cd99b240b812013fa3e5f43854d6a6e6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 22 Jan 2019 14:39:29 +0800 Subject: [PATCH 120/122] try to add PoS% to staking loop, to adjust staking difficulty --- src/chainparams.cpp | 14 ++- src/komodo_bitcoind.h | 220 +++++++++++++++++++++++------------------- src/komodo_globals.h | 5 +- src/pow.cpp | 2 + 4 files changed, 135 insertions(+), 106 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 368e0eb50..03a518d4b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -94,9 +94,9 @@ void *chainparams_commandline(void *ptr); extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH, ASSETCHAINS_VERUSHASHV2; +extern uint32_t ASSETCHAIN_INIT, ASSETCHAINS_MAGIC, ASSETCHAINS_VERUSHASHV2, ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_VERUSHASH; extern int32_t VERUS_BLOCK_POSUNITS, ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER; -extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_ALGO; +extern uint64_t ASSETCHAINS_SUPPLY; const arith_uint256 maxUint = UintToArith256(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); @@ -268,7 +268,7 @@ void *chainparams_commandline(void *ptr) mainParams.pchMessageStart[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; mainParams.pchMessageStart[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; fprintf(stderr,">>>>>>>>>> %s: p2p.%u rpc.%u magic.%08x %u %u coins\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_MAGIC,ASSETCHAINS_MAGIC,(uint32_t)ASSETCHAINS_SUPPLY); - if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2) + if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH) { // this is only good for 60 second blocks with an averaging window of 45. for other parameters, use: // nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing @@ -276,6 +276,14 @@ void *chainparams_commandline(void *ptr) mainParams.consensus.nPowAveragingWindow = 45; mainParams.consensus.powAlternate = uint256S("00000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); } + else if (ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2) + { + // this is only good for 60 second blocks with an averaging window of 45. for other parameters, use: + // nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing + mainParams.consensus.nLwmaAjustedWeight = 1350; + mainParams.consensus.nPowAveragingWindow = 45; + mainParams.consensus.powAlternate = uint256S("000000ff0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + } if (ASSETCHAINS_LWMAPOS != 0) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b567c1488..d2c3b3b30 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1253,95 +1253,6 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 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,segid32,winner = 0 ; uint64_t value,coinage; - txtime = komodo_txtime2(&value,txid,vout,address); - if ( validateflag == 0 ) - { - //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); - } - 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 ( value < SATOSHIDEN ) - return(0); - value /= SATOSHIDEN; - mindiff.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); - ratio = (mindiff / bnTarget); - if ( (minage= nHeight*3) > 6000 ) // about 100 blocks - minage = 6000; - komodo_segids(hashbuf,nHeight-101,100); - segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); - segid = ((nHeight + segid32) & 0x3f); - for (iter=0; iter<600; iter++) - { - if ( blocktime+iter+segid*2 < txtime+minage ) - continue; - diff = (iter + blocktime - txtime - minage); - 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; - } - if ( iter > 0 ) - diff += segid*2; - coinage = (value * diff); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) - { - if ( blocktime+iter+segid*2 > prevtime+200 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+120)); - } - if ( blocktime+iter+segid*2 > prevtime+480 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); - coinage256 = arith_uint256(coinage+1); - hashval = ratio * (UintToArith256(hash) / coinage256); - if ( hashval <= bnTarget ) - { - winner = 1; - if ( validateflag == 0 ) - { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); - 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 "); - 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);*/ - break; - } - } - //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 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 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); - return(blocktime * winner); -} - arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { int32_t oldflag = 0,dispflag = 1; @@ -1380,7 +1291,17 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he fprintf(stderr," %d, ",percPoS); } if ( m+n < 100 ) - percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; + { + // We do actual PoS % at the start. Requires coin distribution in first 10 blocks! + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) + percPoS = (percPoS*100) / (m+n); + else + // This seems to be inverse. The actual PoS % is backwards in the first 100 blocks. + // I dont't understand the math here, or why its backwards, so I am just disabling it for VerusHash. + // No doubt this is probably wrong for equihash aswell, we may need to test an equihash chain with the rule above. + // Need to ask james what the deal is here! Seems to be causeing ALL the problems. + percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; + } if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) fprintf(stderr," -> %d%% percPoS vs goalperc.%d ht.%d\n",percPoS,goalperc,height); *percPoSp = percPoS; @@ -1444,9 +1365,104 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he return(bnTarget); } +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,int32_t PoSperc) +{ + 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,segid32,winner = 0 ; uint64_t value,coinage; + txtime = komodo_txtime2(&value,txid,vout,address); + if ( validateflag == 0 ) + { + //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); + } + 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 ( value < SATOSHIDEN ) + return(0); + value /= SATOSHIDEN; + mindiff.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); + ratio = (mindiff / bnTarget); + if ( (minage= nHeight*3) > 6000 ) // about 100 blocks + minage = 6000; + komodo_segids(hashbuf,nHeight-101,100); + segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); + segid = ((nHeight + segid32) & 0x3f); + for (iter=0; iter<600; iter++) + { + if ( blocktime+iter+segid*2 < txtime+minage ) + continue; + diff = (iter + blocktime - txtime - minage); + 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; + } + if ( iter > 0 ) + diff += segid*2; + coinage = (value * diff); + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) + { + fprintf(stderr, "PoS % is: %i% vs. %i% \n", PoSperc, ASSETCHAINS_STAKED); + if ( PoSperc < ASSETCHAINS_STAKED ) + { + // This means we are under PoS % required and we need some extra help getting an elegible utxo. + // Likley there is some math required here to make it work properly. But getting the data here is no1 priority. + coinage = coinage * 1000; + } + } + // leave this here for now... + if ( blocktime+iter+segid*2 > prevtime+480 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); + coinage256 = arith_uint256(coinage+1); + hashval = ratio * (UintToArith256(hash) / coinage256); + if ( hashval <= bnTarget ) + { + winner = 1; + if ( validateflag == 0 ) + { + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + 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 "); + 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);*/ + break; + } + } + //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); + if ( 0 && validateflag != 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 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); + return(blocktime * winner); +} + int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_uint256 bnTarget,arith_uint256 bhash) { - CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; + CBlockIndex *previndex,*pindex; char voutaddr[64],destaddr[64]; uint256 txid; uint32_t txtime,prevtime=0; int32_t vout,PoSperc,txn_count,eligible=0,isPoS = 0,segid; uint64_t value; CTxDestination voutaddress; arith_uint256 POWTarget; if ( ASSETCHAINS_STAKED == 100 && height <= 100 ) return(1); BlockMap::const_iterator it = mapBlockIndex.find(pblock->GetHash()); @@ -1457,6 +1473,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ return(0); else return(1); } + // Get PoSperc and POW Target. for later. + POWTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); 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 ) { @@ -1470,7 +1488,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ { if ( komodo_isPoS(pblock) != 0 ) { - eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)"",PoSperc); } if ( eligible == 0 || eligible > pblock->nTime ) { @@ -1515,8 +1533,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ } else { - bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); - if ( bhash < bnTarget ) + if ( bhash < POWTarget ) { //fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); isPoS = 0; @@ -2085,10 +2102,11 @@ 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 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; + int32_t PoSperc; + 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,tmpTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; if (!EnsureWalletIsAvailable(0)) return 0; - + bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(STAKING_MIN_DIFF,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -2100,6 +2118,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (tipindex= chainActive.Tip()) == 0 ) return(0); nHeight = tipindex->GetHeight() + 1; + // Get the PoS% so we can pass it to komodo_stake, this is to adjust PoS dofficulty when it is under the target %! + tmpTarget = komodo_PoWtarget(&PoSperc,bnTarget,nHeight,ASSETCHAINS_STAKED); if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; komodo_segids(hashbuf,nHeight-101,100); @@ -2119,7 +2139,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } - if ( time(NULL) > lasttime+600 || array == 0 || resetstaker ) + if ( resetstaker || array == 0 || time(NULL) > lasttime+600 ) { LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); @@ -2175,14 +2195,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt kp = &array[i]; 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); + eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address,PoSperc); //fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); 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) ) + if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address,PoSperc) ) { - while ( 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,PoSperc) ) { besttime = eligible; eligible--; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 2c2d4e855..cb1d9987d 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -82,9 +82,8 @@ uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16,16}; uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,4096,4096}; uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH; // min diff returned from GetNextWorkRequired needs to be added here for each algo, so they can work with ac_staked. -// VerusHash v1 and 1.1 use a custom tuned number or PoW blocks all are 1s. -uint32_t ASSETCHAINS_MINDIFF[] = {537857807,486648905,486648905}; - +uint32_t ASSETCHAINS_MINDIFF[] = {537857807,503381775,503381775}; + // ^ wrong! // Verus proof of stake controls int32_t ASSETCHAINS_LWMAPOS = 0; // percentage of blocks should be PoS int32_t VERUS_BLOCK_POSUNITS = 1024; // one block is 1000 units diff --git a/src/pow.cpp b/src/pow.cpp index b69c4fce6..0e4b706a8 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -134,6 +134,8 @@ unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const bnLimit = UintToArith256(params.powAlternate); unsigned int nProofOfWorkLimit = bnLimit.GetCompact(); + + printf("PoWLimit: %u\n", nProofOfWorkLimit); // Find the first block in the averaging interval as we total the linearly weighted average const CBlockIndex* pindexFirst = pindexLast; From 7167793dbf4b776f6d4d8ae6daf7a6b150747c65 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 23 Jan 2019 02:50:53 +0800 Subject: [PATCH 121/122] new version --- src/chainparams.cpp | 2 +- src/komodo_bitcoind.h | 54 +++++++++++++++++++++++------------------- src/komodo_globals.h | 5 ++-- src/komodo_utils.h | 2 +- src/main.cpp | 3 ++- src/miner.cpp | 8 +++---- src/pow.cpp | 4 ++-- src/rpc/blockchain.cpp | 2 +- src/rpc/mining.cpp | 3 +-- src/rpc/misc.cpp | 4 ++-- 10 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 03a518d4b..45824f22b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -282,7 +282,7 @@ void *chainparams_commandline(void *ptr) // nLwmaAjustedWeight = (N+1)/2 * (0.9989^(500/nPowAveragingWindow)) * nPowTargetSpacing mainParams.consensus.nLwmaAjustedWeight = 1350; mainParams.consensus.nPowAveragingWindow = 45; - mainParams.consensus.powAlternate = uint256S("000000ff0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); + mainParams.consensus.powAlternate = uint256S("0000000f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f"); } if (ASSETCHAINS_LWMAPOS != 0) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d2c3b3b30..b2b8011b5 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1255,7 +1255,7 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc) { - int32_t oldflag = 0,dispflag = 1; + int32_t oldflag = 0,dispflag = 0; CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,m,ht,percPoS,diff,val; *percPoSp = percPoS = 0; @@ -1367,7 +1367,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he 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,int32_t PoSperc) { - 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,segid32,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 segid,minage,i,iter=0; int64_t diff=0; uint32_t txtime,segid32,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { @@ -1398,6 +1398,23 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime+iter+segid*2 < txtime+minage ) continue; diff = (iter + blocktime - txtime - minage); + if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) + { + if ( PoSperc < ASSETCHAINS_STAKED ) + { + // Under PoS % target and we need to increase diff. + //fprintf(stderr, "PoS too low diff.%i changed to.",diff); + diff = diff * ( (ASSETCHAINS_STAKED - PoSperc + 1) * (ASSETCHAINS_STAKED - PoSperc + 1) ); + //fprintf(stderr, "%i \n",diff); + } + else if ( PoSperc > ASSETCHAINS_STAKED ) + { + // Over PoS target need to lower diff. + //fprintf(stderr, "PoS too high diff.%i changed to.",diff); + diff = diff / ( (PoSperc - ASSETCHAINS_STAKED + 1) * (PoSperc - ASSETCHAINS_STAKED + 1) ); + //fprintf(stderr, "%i \n",diff); + } + } if ( diff < 0 ) diff = 60; else if ( diff > 3600*24*30 ) @@ -1408,19 +1425,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( iter > 0 ) diff += segid*2; coinage = (value * diff); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV2 ) - { - fprintf(stderr, "PoS % is: %i% vs. %i% \n", PoSperc, ASSETCHAINS_STAKED); - if ( PoSperc < ASSETCHAINS_STAKED ) - { - // This means we are under PoS % required and we need some extra help getting an elegible utxo. - // Likley there is some math required here to make it work properly. But getting the data here is no1 priority. - coinage = coinage * 1000; - } - } - // leave this here for now... - if ( blocktime+iter+segid*2 > prevtime+480 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); + if ( blocktime+iter+segid*2 > prevtime+128 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+102)); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); if ( hashval <= bnTarget ) @@ -1441,7 +1447,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 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; } } @@ -2048,7 +2054,8 @@ struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numk 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) +// WHY IS THIS HERE! It does this in komodo_stake! WTF! +/*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); @@ -2074,12 +2081,12 @@ 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=31; i>=16; i--) + for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); fprintf(stderr," vs "); for (int i=31; i>=16; i--) fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]); - fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,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; iternTime+27,minage,hashbuf)) == 0 ) - continue; + // WTF! was this here for! + //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,PoSperc); //fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index cb1d9987d..dd51d9c93 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -82,7 +82,7 @@ uint32_t ASSETCHAINS_NONCESHIFT[] = {32,16,16}; uint32_t ASSETCHAINS_HASHESPERROUND[] = {1,4096,4096}; uint32_t ASSETCHAINS_ALGO = _ASSETCHAINS_EQUIHASH; // min diff returned from GetNextWorkRequired needs to be added here for each algo, so they can work with ac_staked. -uint32_t ASSETCHAINS_MINDIFF[] = {537857807,503381775,503381775}; +uint32_t ASSETCHAINS_MINDIFF[] = {537857807,504303375,487526159}; // ^ wrong! // Verus proof of stake controls int32_t ASSETCHAINS_LWMAPOS = 0; // percentage of blocks should be PoS @@ -95,7 +95,8 @@ int32_t ASSETCHAINS_SAPLING = -1; int32_t ASSETCHAINS_OVERWINTER = -1; uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; -uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10,MIN_RECV_SATS; +int32_t ASSETCHAINS_STAKED; +uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY = 10,MIN_RECV_SATS; uint32_t KOMODO_INITDONE; char KMDUSERPASS[8192+512+1],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 1fe4c012a..cb7275898 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1916,7 +1916,7 @@ void komodo_args(char *argv0) extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_LWMAPOS),(void *)&ASSETCHAINS_LWMAPOS); } - val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; + val = ASSETCHAINS_COMMISSION | (((int64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffff) << 40) | ((ASSETCHAINS_PUBLIC != 0) << 7) | ((ASSETCHAINS_PRIVATE != 0) << 6) | ASSETCHAINS_TXPOW; extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val); if ( ASSETCHAINS_FOUNDERS != 0 ) { diff --git a/src/main.cpp b/src/main.cpp index c1cdc3935..5aaf69bfb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2216,8 +2216,9 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS]; extern uint32_t ASSETCHAINS_MAGIC; -extern uint64_t ASSETCHAINS_STAKED,ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; +extern uint64_t ASSETCHAINS_LINEAR,ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY; extern uint8_t ASSETCHAINS_PUBLIC,ASSETCHAINS_PRIVATE; +extern int32_t ASSETCHAINS_STAKED; CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { diff --git a/src/miner.cpp b/src/miner.cpp index 66f1a263f..4ce3bc37b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -132,8 +132,8 @@ void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, #include "komodo_defs.h" extern CCriticalSection cs_metrics; -extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE,STAKING_MIN_DIFF; -extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_STAKED; +extern int32_t KOMODO_MININGTHREADS,KOMODO_LONGESTCHAIN,ASSETCHAINS_SEED,IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,KOMODO_CHOSEN_ONE,ASSETCHAIN_INIT,KOMODO_INITDONE,KOMODO_ON_DEMAND,KOMODO_INITDONE,KOMODO_PASSPORT_INITDONE,STAKING_MIN_DIFF,ASSETCHAINS_STAKED; +extern uint64_t ASSETCHAINS_COMMISSION; extern bool VERUS_MINTBLOCKS; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[]; extern const char *ASSETCHAINS_ALGORITHMS[]; @@ -558,9 +558,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nFees += txfees; pblock->nTime = blocktime; //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->GetHeight()+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); - } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); - + } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } + // Create coinbase tx CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, nHeight); txNew.vin.resize(1); diff --git a/src/pow.cpp b/src/pow.cpp index 0e4b706a8..3e7afa720 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -37,9 +37,9 @@ #endif // ENABLE_RUST uint32_t komodo_chainactive_timestamp(); -extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_STAKED; +extern uint32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH; extern char ASSETCHAINS_SYMBOL[65]; -extern int32_t ASSETCHAINS_LWMAPOS,VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD; +extern int32_t ASSETCHAINS_LWMAPOS,VERUS_BLOCK_POSUNITS, VERUS_CONSECUTIVE_POS_THRESHOLD, VERUS_NOPOS_THRESHHOLD,ASSETCHAINS_STAKED; unsigned int lwmaGetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params); unsigned int lwmaCalculateNextWorkRequired(const CBlockIndex* pindexLast, const Consensus::Params& params); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index bb46f47fb..147b94b61 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -622,7 +622,7 @@ UniValue getblockhash(const UniValue& params, bool fHelp) return pblockindex->GetBlockHash().GetHex(); } -extern uint64_t ASSETCHAINS_STAKED; +extern int32_t ASSETCHAINS_STAKED; UniValue getlastsegidstakes(const UniValue& params, bool fHelp) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 3843529ac..44b0162ad 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -48,8 +48,7 @@ using namespace std; -extern int32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_LWMAPOS; -extern uint64_t ASSETCHAINS_STAKED; +extern int32_t ASSETCHAINS_ALGO, ASSETCHAINS_EQUIHASH, ASSETCHAINS_LWMAPOS,ASSETCHAINS_STAKED; extern int32_t KOMODO_MININGTHREADS; extern bool VERUS_MINTBLOCKS; arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc); diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index a174fedf7..4fa5c061c 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -80,8 +80,8 @@ int8_t StakedNotaryID(std::string ¬aryname, char *Raddress); extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; extern uint32_t ASSETCHAINS_MAGIC; -extern uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY,ASSETCHAINS_LASTERA; -extern int32_t ASSETCHAINS_LWMAPOS,ASSETCHAINS_SAPLING; +extern uint64_t ASSETCHAINS_COMMISSION,ASSETCHAINS_SUPPLY,ASSETCHAINS_LASTERA; +extern int32_t ASSETCHAINS_LWMAPOS,ASSETCHAINS_SAPLING,ASSETCHAINS_STAKED; extern uint64_t ASSETCHAINS_ENDSUBSIDY[],ASSETCHAINS_REWARD[],ASSETCHAINS_HALVING[],ASSETCHAINS_DECAY[]; extern std::string NOTARY_PUBKEY,NOTARY_ADDRESS; extern uint8_t NOTARY_PUBKEY33[]; From bbf756704f1bccfdeeae20643a034e53b5e7bfbf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 23 Jan 2019 13:54:09 +0800 Subject: [PATCH 122/122] clean up --- src/komodo_bitcoind.h | 57 +------------------------------------------ 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index b2b8011b5..ce7c0259a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2054,63 +2054,11 @@ struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numk return(array); } -// WHY IS THIS HERE! It does this in komodo_stake! WTF! -/*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 * diff); - if ( blocktime+iter+segid*2 > prevtime+480 ) - coinage *= ((blocktime+iter+segid*2) - (prevtime+400)); - coinage256 = arith_uint256(coinage+1); - hashval = ratio * (kp->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,uint8_t *hashbuf) -{ - int32_t maxiters = 600; 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); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," vs "); - for (int i=31; i>=16; i--) - fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[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); - if ( hashval <= bnTarget ) - { - //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); - } - } - } //else fprintf(stderr,"maxiters is not good enough\n"); - 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; int32_t PoSperc; - 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,tmpTarget; 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,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget,tmpTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; if (!EnsureWalletIsAvailable(0)) return 0; @@ -2198,9 +2146,6 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(0); } kp = &array[i]; - // WTF! was this here for! - //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,PoSperc); //fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 )