From 75979d037a877904965ae852a012d6713c2ad970 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 17:27:10 +0800 Subject: [PATCH 01/41] increse era wtf happened there lol --- src/notaries_staked.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/notaries_staked.h b/src/notaries_staked.h index 5545f8714..0a722f512 100644 --- a/src/notaries_staked.h +++ b/src/notaries_staked.h @@ -2,12 +2,14 @@ #ifndef NOTARIES_STAKED #define NOTARIES_STAKED +#include "crosschain.h" + static const int STAKED_ERA_GAP = 777; -static const int STAKED_NOTARIES_TIMESTAMP1 = 1537839874; -static const int STAKED_NOTARIES_TIMESTAMP2 = 1537843474; -static const int STAKED_NOTARIES_TIMESTAMP3 = 1537847074; -static const int STAKED_NOTARIES_TIMESTAMP4 = 1537850674; +static const int STAKED_NOTARIES_TIMESTAMP1 = 1537871673; +static const int STAKED_NOTARIES_TIMESTAMP2 = 1537875273; +static const int STAKED_NOTARIES_TIMESTAMP3 = 1537878873; +static const int STAKED_NOTARIES_TIMESTAMP4 = 1537895873; extern const char *notaries_STAKED1[][2]; extern int num_notaries_STAKED1; @@ -24,4 +26,7 @@ extern int num_notaries_STAKED4; int is_STAKED(const char *chain_name); int STAKED_era(int timestamp); +CrosschainAuthority Choose_auth_STAKED(int chosen_era); +CrosschainAuthority auth_STAKED_chosen(const char *notaries_chosen[][2],int num_notaries); + #endif From 7422645f78c5c4d7998861e4f7fb5fb4a02a4fa0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 18:08:30 +0800 Subject: [PATCH 02/41] add print for numvalid --- src/komodo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo.h b/src/komodo.h index 7c927a3d8..6fc219c32 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -858,6 +858,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j); } numvalid = bitweight(signedmask); + printf("numvalid.%d \n",numvalid); if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || numvalid > (numnotaries/5))) From b9673a33a8a62cc443ff840255cdce87989b65af Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 18:14:13 +0800 Subject: [PATCH 03/41] more rpints --- src/komodo.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo.h b/src/komodo.h index 6fc219c32..b0056f6c7 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -810,6 +810,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } //fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight); numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime()); + printf("numnotaries.%d\n",numnotaries); calc_rmd160_sha256(rmd160,pubkeys[0],33); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; From ad98d05ba1938404adf32223fee9e82fd1e0265f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 18:26:47 +0800 Subject: [PATCH 04/41] more prints --- src/komodo.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b0056f6c7..e7ea104aa 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -810,7 +810,6 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } //fprintf(stderr,"%s connect.%d\n",ASSETCHAINS_SYMBOL,pindex->nHeight); numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime()); - printf("numnotaries.%d\n",numnotaries); calc_rmd160_sha256(rmd160,pubkeys[0],33); if ( pindex->nHeight > hwmheight ) hwmheight = pindex->nHeight; @@ -826,8 +825,10 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0); } komodo_currentheight_set(chainActive.LastTip()->nHeight); + printf("BEFORE pindex != 0 check.\n", ); if ( pindex != 0 ) { + printf("AFTER pindex != 0 check.\n", ); height = pindex->nHeight; txn_count = block.vtx.size(); for (i=0; i 0 ) { @@ -860,9 +862,9 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } numvalid = bitweight(signedmask); printf("numvalid.%d \n",numvalid); - if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || + if (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || - numvalid > (numnotaries/5))) + numvalid > (numnotaries/5)) { if ( ASSETCHAINS_SYMBOL[0] != 0) { From aeeec99a0b3830a23e1e756f652f2caafcbd00cf Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 18:28:50 +0800 Subject: [PATCH 05/41] oops --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e7ea104aa..937e1f788 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -825,10 +825,10 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0); } komodo_currentheight_set(chainActive.LastTip()->nHeight); - printf("BEFORE pindex != 0 check.\n", ); + printf("BEFORE pindex != 0 check.\n"); if ( pindex != 0 ) { - printf("AFTER pindex != 0 check.\n", ); + printf("AFTER pindex != 0 check.\n"); height = pindex->nHeight; txn_count = block.vtx.size(); for (i=0; i Date: Tue, 25 Sep 2018 18:29:52 +0800 Subject: [PATCH 06/41] opps --- src/komodo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 937e1f788..7d2a75b4e 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -845,7 +845,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) for (j=0; j 0 ) { From 233666172a91564fc01b1c445a4f29bdb13b7e95 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 18:33:28 +0800 Subject: [PATCH 07/41] maybe this lol --- src/komodo.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 7d2a75b4e..0425a5002 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -825,17 +825,17 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0); } komodo_currentheight_set(chainActive.LastTip()->nHeight); - printf("BEFORE pindex != 0 check.\n"); if ( pindex != 0 ) { - printf("AFTER pindex != 0 check.\n"); height = pindex->nHeight; txn_count = block.vtx.size(); for (i=0; iGetBlockTime()) == 0)) + if ((is_STAKED(ASSETCHAINS_SYMBOL) != 0) && (STAKED_era(pindex->GetBlockTime()) == 0)) { printf("ERA 0 SKIP %s\n",ASSETCHAINS_SYMBOL); continue; + } + printf("we working now?\n"); txhash = block.vtx[i].GetHash(); numvouts = block.vtx[i].vout.size(); notaryid = -1; From b3cb6ec56de629090cb986902b8bc6c315d537e0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 18:37:02 +0800 Subject: [PATCH 08/41] fix --- src/komodo.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 0425a5002..c4200a1e8 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -835,7 +835,6 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) printf("ERA 0 SKIP %s\n",ASSETCHAINS_SYMBOL); continue; } - printf("we working now?\n"); txhash = block.vtx[i].GetHash(); numvouts = block.vtx[i].vout.size(); notaryid = -1; @@ -845,7 +844,6 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) for (j=0; j 0 ) { From 5b1b6887ecdec3f463d4318d1bc1176d828c02c4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 25 Sep 2018 18:41:08 +0800 Subject: [PATCH 09/41] good --- src/komodo.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index c4200a1e8..cc2a5dd3d 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -859,7 +859,6 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) } else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j); } numvalid = bitweight(signedmask); - printf("numvalid.%d \n",numvalid); if (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || (numvalid >= KOMODO_MINRATIFY && ASSETCHAINS_SYMBOL[0] != 0) || numvalid > (numnotaries/5)) From dee9067adc99f3d677417bf40aa5b83c770522e9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 14:53:41 +0800 Subject: [PATCH 10/41] modified: src/komodo_notary.h --- src/komodo_notary.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_notary.h b/src/komodo_notary.h index de343e184..0365a1faf 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -306,9 +306,9 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam } else if (staked_era == 0) { // this means we are in a gap, so we set the array of pubkeys to zero, this does't seem to correctly work, so added exeption to komodo.h aswell. - for (i=0; i<1; i++) - decode_hex(null_pubkeys[i],33,(char *)notaries_STAKED1[i][1]); - printf("%s IS A STAKED CHAIN and is in an ERA GAP, so we zeroed the pubkeys.\n",ASSETCHAINS_SYMBOL); + //for (i=0; i<1; i++) + // decode_hex(null_pubkeys[i],33,(char *)notaries_STAKED1[i][1]); + printf("%s IS A STAKED CHAIN and is in an ERA GAP.\n",ASSETCHAINS_SYMBOL); memcpy(pubkeys,null_pubkeys,64 * 33); return(64); } From 79171fa13b55fcb4445e5dbb5a0255bf8489839b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 15:03:55 +0800 Subject: [PATCH 11/41] try to add error check if export/import chain is the same --- src/rpccrosschain.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 09f1b21d1..baa4d4984 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -50,7 +50,7 @@ UniValue assetchainproof(const UniValue& params, bool fHelp) UniValue crosschainproof(const UniValue& params, bool fHelp) { - + } @@ -90,7 +90,7 @@ UniValue height_MoM(const UniValue& params, bool fHelp) ret.push_back(Pair("kmdendi",kmdendi)); } } else ret.push_back(Pair("error",(char *)"no MoM for height")); - + return ret; } @@ -169,6 +169,9 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); + if (strncmp(ASSETCHAINS_SYMBOL,targetSymbol) == 0) + throw runtime_error("cant send a coin to the same chain"); + CAmount burnAmount = AmountFromValue(params[2]); if (burnAmount <= 0) throw JSONRPCError(RPC_TYPE_ERROR, "Invalid amount for export"); @@ -220,8 +223,8 @@ UniValue migrate_createimporttransaction(const UniValue& params, bool fHelp) CTransaction burnTx; if (!E_UNMARSHAL(txData, ss >> burnTx)) throw runtime_error("Couldn't parse burnTx"); - - + + vector payouts; if (!E_UNMARSHAL(ParseHexV(params[1], "argument 2"), ss >> payouts)) throw runtime_error("Couldn't parse payouts"); @@ -240,7 +243,7 @@ UniValue migrate_completeimporttransaction(const UniValue& params, bool fHelp) throw runtime_error("migrate_completeimporttransaction importTx\n\n" "Takes a cross chain import tx with proof generated on assetchain " "and extends proof to target chain proof root"); - + if (ASSETCHAINS_SYMBOL[0] != 0) throw runtime_error("Must be called on KMD"); @@ -294,7 +297,7 @@ UniValue scanNotarisationsDB(const UniValue& params, bool fHelp) if (height == 0) { height = chainActive.Height(); } - + Notarisation nota; int matchedHeight = ScanNotarisationsDB(height, symbol, limit, nota); if (!matchedHeight) return NullUniValue; From 054eb923f9c4266f085edd04e47c1a08e5ebee55 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 15:56:38 +0800 Subject: [PATCH 12/41] n --- src/rpccrosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index baa4d4984..15e7a0393 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -169,7 +169,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); - if (strncmp(ASSETCHAINS_SYMBOL,targetSymbol) == 0) + if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol) == 0) throw runtime_error("cant send a coin to the same chain"); CAmount burnAmount = AmountFromValue(params[2]); From 7d7b68dc6fe6b42a3207474055ea5929021e5db1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 15:58:23 +0800 Subject: [PATCH 13/41] maybe thos willl work --- src/rpccrosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 15e7a0393..eaa059ec8 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -169,7 +169,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); - if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol) == 0) + if (ASSETCHAINS_SYMBOL == targetSymbol) throw runtime_error("cant send a coin to the same chain"); CAmount burnAmount = AmountFromValue(params[2]); From 66874998de55e44ffbcda4c750b05fb2ee99466d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 16:02:36 +0800 Subject: [PATCH 14/41] or this --- src/rpccrosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index eaa059ec8..52df5efaf 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -169,7 +169,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); - if (ASSETCHAINS_SYMBOL == targetSymbol) + if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol.c_str()) == 0) throw runtime_error("cant send a coin to the same chain"); CAmount burnAmount = AmountFromValue(params[2]); From 3e94e0a37bd3e0b1980d7f6c4328d47645e08e8b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 16:59:52 +0800 Subject: [PATCH 15/41] hmmm --- src/rpccrosschain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 52df5efaf..83554d1f6 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -169,6 +169,8 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); + printf("source.%s target.%s",ASSETCHAINS_SYMBOL,targetSymbol.c_str()) + if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol.c_str()) == 0) throw runtime_error("cant send a coin to the same chain"); From dc43d728486b5b5b550b23204fbddcb0372877be Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 17:04:02 +0800 Subject: [PATCH 16/41] ; --- src/rpccrosschain.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 83554d1f6..e991de71e 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -169,8 +169,8 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); - printf("source.%s target.%s",ASSETCHAINS_SYMBOL,targetSymbol.c_str()) - + printf("source.%s target.%s",ASSETCHAINS_SYMBOL,targetSymbol.c_str()); + if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol.c_str()) == 0) throw runtime_error("cant send a coin to the same chain"); From 42df9ee0602ef7d63716bb7c9da9de8c87749289 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 17:19:17 +0800 Subject: [PATCH 17/41] try this --- src/rpccrosschain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index e991de71e..f92632c8b 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -169,7 +169,7 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); - printf("source.%s target.%s",ASSETCHAINS_SYMBOL,targetSymbol.c_str()); + fprintf(stderr,"source.%s target.%s",ASSETCHAINS_SYMBOL,targetSymbol.c_str()); if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol.c_str()) == 0) throw runtime_error("cant send a coin to the same chain"); From 1a0749e538df926521b6eeda6820e4d15d77410c Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 26 Sep 2018 17:24:06 +0800 Subject: [PATCH 18/41] remove non wokring print --- src/rpccrosschain.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index f92632c8b..52df5efaf 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -169,8 +169,6 @@ UniValue migrate_converttoexport(const UniValue& params, bool fHelp) if (targetSymbol.size() == 0 || targetSymbol.size() > 32) throw runtime_error("targetSymbol length must be >0 and <=32"); - fprintf(stderr,"source.%s target.%s",ASSETCHAINS_SYMBOL,targetSymbol.c_str()); - if (strcmp(ASSETCHAINS_SYMBOL,targetSymbol.c_str()) == 0) throw runtime_error("cant send a coin to the same chain"); From 1449ae165f6923f8dadf60f132db5fee5bbf4287 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 5 Oct 2018 18:29:33 -1100 Subject: [PATCH 19/41] Fix bug in consensus code from miketout for small networks --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0aadc130c..d5adb5d69 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -397,7 +397,7 @@ namespace { if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); - if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) + if (itOld != mapBlockIndex.end() && itOld->second != 0 && itOld->second->nChainWork > 0) { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; @@ -3876,7 +3876,7 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { // Remove the invalidity flag from this block and all its descendants. BlockMap::iterator it = mapBlockIndex.begin(); - while (it != mapBlockIndex.end()) { + while (it != mapBlockIndex.end() && it->second != 0) { if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) { it->second->nStatus &= ~BLOCK_FAILED_MASK; setDirtyBlockIndex.insert(it->second); @@ -4680,7 +4680,7 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo } // Store to disk CBlockIndex *pindex = NULL; - if ( 1 ) + if ( 0 ) // miket's fixes in ReconsiderBlock and ProcessBlockAvailability deprecate the need { // without the komodo_ensure call, it is quite possible to get a non-error but null pindex returned from AcceptBlockHeader. In a 2 node network, it will be a long time before that block is reprocessed. Even though restarting makes it rescan, it seems much better to keep the nodes in sync komodo_ensure(pblock,hash); From 0de9262b57cd7c3795e88f0e9aeb7f59a9a84a05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 8 Oct 2018 00:00:46 -1100 Subject: [PATCH 20/41] Change prints --- src/komodo.h | 2 +- src/komodo_bitcoind.h | 2 +- src/komodo_kv.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index b233f2ffa..e303c2bac 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -851,7 +851,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) printf("%02x",scriptPubKey[k]); printf(" scriptPubKey doesnt match any notary vini.%d of %d\n",j,numvins); } - } else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j); + } //else printf("cant get scriptPubKey for ht.%d txi.%d vin.%d\n",height,i,j); } numvalid = bitweight(signedmask); if ( (((height < 90000 || (signedmask & 1) != 0) && numvalid >= KOMODO_MINRATIFY) || diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 86ed8f7b3..8e454fd5d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1450,7 +1450,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ bnTarget = komodo_PoWtarget(&PoSperc,bnTarget,height,ASSETCHAINS_STAKED); if ( bhash < bnTarget ) { - fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); + //fprintf(stderr,"ht.%d isPoS but meets PoW diff!\n",height); isPoS = 0; } } diff --git a/src/komodo_kv.h b/src/komodo_kv.h index 37e11d06d..834584e44 100644 --- a/src/komodo_kv.h +++ b/src/komodo_kv.h @@ -117,7 +117,7 @@ void komodo_kvupdate(uint8_t *opretbuf,int32_t opretlen,uint64_t value) } valueptr = &key[keylen]; fee = komodo_kvfee(flags,opretlen,keylen); - //printf("fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); + //fprintf(stderr,"fee %.8f vs %.8f flags.%d keylen.%d valuesize.%d height.%d (%02x %02x %02x) (%02x %02x %02x)\n",(double)fee/COIN,(double)value/COIN,flags,keylen,valuesize,height,key[0],key[1],key[2],valueptr[0],valueptr[1],valueptr[2]); if ( value >= fee ) { coresize = (int32_t)(sizeof(flags)+sizeof(height)+sizeof(keylen)+sizeof(valuesize)+keylen+valuesize+1); From 30743f73336751edc3a7b578f1f865668e02d8f4 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Mon, 8 Oct 2018 17:45:53 +0200 Subject: [PATCH 21/41] Add checks for correct input data --- src/cc/channels.cpp | 17 +++++++++++++---- src/wallet/rpcwallet.cpp | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index f6133d575..57a587c44 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -207,15 +207,15 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( IsCCInput(tx.vin[1].scriptSig) == 0 ) return eval->Invalid("vin.1 is CC for channelPayment!"); else if ( IsCCInput(tx.vin[2].scriptSig) == 0 ) - return eval->Invalid("vin.1 is CC for channelPayment!"); + return eval->Invalid("vin.2 is CC for channelPayment!"); else if ( tx.vout[0].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.0 is CC for channelPayment!"); else if ( tx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 ) return eval->Invalid("vout.1 is CC for channelPayment (marker to srcPub)!"); else if ( tx.vout[2].scriptPubKey.IsPayToCryptoCondition() == 0 ) - return eval->Invalid("vout.1 is CC for channelPayment (marker to dstPub)!"); + return eval->Invalid("vout.2 is CC for channelPayment (marker to dstPub)!"); else if ( tx.vout[3].scriptPubKey.IsPayToCryptoCondition() != 0 ) - return eval->Invalid("vout.1 is normal for channelPayment!"); + return eval->Invalid("vout.3 is normal for channelPayment!"); else if ( tx.vout[3].scriptPubKey!=CScript() << ParseHex(HexStr(destpub)) << OP_CHECKSIG) return eval->Invalid("payment funds do not go to receiver!"); else if ( param1 > CHANNELS_MAXPAYMENTS) @@ -487,7 +487,7 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 fprintf(stderr,"this is not our channel\n"); return(""); } - else if (amount % payment != 0) + else if (amount % payment != 0 || amount prevdepth) + { + fprintf(stderr,"not enough funds in channel for that amount\n"); + return (""); + } else if (numpayments == 0) + { + fprintf(stderr,"invalid amount\n"); + return (""); + } if (secret!=zeroid) { endiancpy(hash, (uint8_t * ) & secret, 32); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d97df5b3a..aa5392472 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5146,8 +5146,23 @@ UniValue channelsopen(const UniValue& params, bool fHelp) const CKeyStore& keystore = *pwalletMain; LOCK2(cs_main, pwalletMain->cs_wallet); destpub = ParseHex(params[0].get_str().c_str()); + if (destpub.size()!= 33) + { + ERR_RESULT("invalid destination pubkey"); + return result; + } numpayments = atoi(params[1].get_str().c_str()); + if (numpayments <1) + { + ERR_RESULT("invalid number of payments, must be greater than 0"); + return result; + } payment = atol(params[2].get_str().c_str()); + if (payment <1) + { + ERR_RESULT("invalid payment amount, must be greater than 0"); + return result; + } hex = ChannelOpen(0,pubkey2pk(destpub),numpayments,payment); if ( hex.size() > 0 ) { @@ -5169,6 +5184,11 @@ UniValue channelspayment(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); opentxid = Parseuint256((char *)params[0].get_str().c_str()); amount = atoi((char *)params[1].get_str().c_str()); + if (amount <1) + { + ERR_RESULT("invalid payment amount, must be greater than 0"); + return result; + } if (params.size() > 2 && !params[2].isNull() && !params[2].get_str().empty()) { secret = Parseuint256((char *)params[2].get_str().c_str()); From 702658f047753930525499fa542453c8fa14e887 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 9 Oct 2018 16:22:36 +0200 Subject: [PATCH 22/41] Code clean up --- src/cc/channels.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 57a587c44..bd0b5bb7f 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -163,7 +163,6 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; - fprintf(stderr,"validateCC\n"); if ( numvouts < 1 ) return eval->Invalid("no vouts"); else @@ -353,8 +352,8 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) - fprintf(stderr,"Channelsget validated\n"); - else fprintf(stderr,"Channelsget invalid\n"); + fprintf(stderr,"Channel tx validated\n"); + else fprintf(stderr,"Channel tx invalid\n"); return(retval); } } @@ -377,7 +376,7 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C } else { - fprintf(stderr,"invalid open txid\n"); + fprintf(stderr,"invalid channel open txid\n"); return 0; } @@ -396,7 +395,6 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C } if (txid!=zeroid && myIsutxo_spentinmempool(txid,0) != 0) { - fprintf(stderr,"spent in mempool\n"); txid=zeroid; int32_t mindepth=CHANNELS_MAXPAYMENTS; BOOST_FOREACH(const CTxMemPoolEntry &e, mempool.mapTx) @@ -428,7 +426,9 @@ int64_t AddChannelsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx, C std::string ChannelOpen(uint64_t txfee,CPubKey destpub,int32_t numpayments,int64_t payment) { - CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; CPubKey mypk; struct CCcontract_info *cp,C; + CMutableTransaction mtx; uint8_t hash[32],hashdest[32]; uint64_t funds; int32_t i; uint256 hashchain,entropy,hentropy; + CPubKey mypk; struct CCcontract_info *cp,C; + if ( numpayments <= 0 || payment <= 0 || numpayments > CHANNELS_MAXPAYMENTS ) { CCerror = strprintf("invalid ChannelOpen param numpayments.%d max.%d payment.%lld\n",numpayments,CHANNELS_MAXPAYMENTS,(long long)payment); @@ -481,7 +481,6 @@ std::string ChannelPayment(uint64_t txfee,uint256 opentxid,int64_t amount, uint2 { if ((numvouts=channelOpenTx.vout.size()) > 0 && DecodeChannelsOpRet(channelOpenTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, totalnumpayments, payment, hashchain)=='O') { - if (mypk != srcpub && mypk != destpub) { fprintf(stderr,"this is not our channel\n"); @@ -589,7 +588,7 @@ std::string ChannelClose(uint64_t txfee,uint256 opentxid) } if (mypk != srcpub) { - fprintf(stderr,"this channel is not in our ownership\n"); + fprintf(stderr,"cannot close, you are not channel owner\n"); return(""); } if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) @@ -637,7 +636,6 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } if (txid!=opentxid) { - fprintf(stderr,"%s - %s\n",txid.ToString().c_str(),opentxid.ToString().c_str()); fprintf(stderr, "open and close txid are not from same channel\n"); return (""); } @@ -653,14 +651,15 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) } if (mypk != srcpub) { - fprintf(stderr,"this channel is not in our ownership\n"); + fprintf(stderr,"cannot refund, you are not the channel owenr\n"); return(""); } if ( AddNormalinputs(mtx,mypk,2*txfee,1) > 0 ) { if ((funds=AddChannelsInputs(cp,mtx,channelOpenTx,prevtxid)) !=0 && funds-txfee>0) { - if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) + if ((GetTransaction(prevtxid,prevTx,hashblock,false) != 0) && (numvouts=prevTx.vout.size()) > 0 && + DecodeChannelsOpRet(prevTx.vout[numvouts-1].scriptPubKey, txid, srcpub, destpub, param1, param2, param3) != 0) { hentropy = DiceHashEntropy(entropy, channelOpenTx.vin[0].prevout.hash); endiancpy(hash, (uint8_t * ) & hentropy, 32); @@ -745,7 +744,8 @@ UniValue ChannelsInfo(uint256 channeltxid) } else if (DecodeChannelsOpRet(tx.vout[numvouts-1].scriptPubKey,opentxid,srcpub,destpub,param1,param2,param3) == 'P' && opentxid==channeltxid) { - if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') + if (GetTransaction(opentxid,opentx,hashBlock,false) != 0 && (numvouts=opentx.vout.size()) > 0 && + DecodeChannelsOpRet(opentx.vout[numvouts-1].scriptPubKey,tmp_txid,srcpub,destpub,numpayments,payment,hashchain) == 'O') { Getscriptaddress(str2,tx.vout[3].scriptPubKey); sprintf(str1,"%lld satoshi to %s, %lld payments left",(long long)(param2*payment),str2,(long long)param1); From c606ce69255c9dfd6f50a22320480a5f1790b668 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 11:56:02 -1100 Subject: [PATCH 23/41] Backward compatible dPoW enforcement! --- src/dpowassets | 42 --------------------------------------- src/komodo_bitcoind.h | 2 +- src/komodo_notary.h | 15 ++++++++++++++ src/rpcblockchain.cpp | 3 ++- src/rpcrawtransaction.cpp | 7 +++++-- src/wallet/rpcwallet.cpp | 10 +++++++--- 6 files changed, 30 insertions(+), 49 deletions(-) delete mode 100755 src/dpowassets diff --git a/src/dpowassets b/src/dpowassets deleted file mode 100755 index 88e6f72b8..000000000 --- a/src/dpowassets +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash -set -x -source pubkey.txt -echo $pubkey -sleep 3 - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"REVS\",\"pubkey\":\"$pubkey\"}" - -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SUPERNET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DEX\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PANGEA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"JUMBLR\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BET\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CRYPTO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"HODL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MSHARK\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BOTS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MGW\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"COQUI\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"WLC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"KV\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CEAL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MESH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"MNZ\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"AXO\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ETOMIC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BTCH\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHAIN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"NINJA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"OOT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"BNTN\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"PRLPAY\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"DSEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GLXT\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"EQL\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"ZILLA\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CHIPS\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"GAME\",\"freq\":5,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"RFOX\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"VRSC\",\"freq\":10,\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"SEC\",\"pubkey\":\"$pubkey\"}" -curl --url "http://127.0.0.1:7776" --data "{\"agent\":\"iguana\",\"method\":\"dpow\",\"symbol\":\"CCL\",\"pubkey\":\"$pubkey\"}" diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8e454fd5d..29992c172 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -391,7 +391,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig { if ( (item= jobj(json,(char *)"result")) != 0 ) { - txid_confirmations = jint(item,(char *)"confirmations"); + txid_confirmations = jint(item,(char *)"origconfirmations"); if ( txid_confirmations > 0 && height > txid_confirmations ) txid_height = height - txid_confirmations; else txid_height = height; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index 04fd30d5f..ffe575356 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -452,6 +452,21 @@ int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 * } } +int32_t komodo_dpowconfs(int32_t txheight,int32_t numconfs) +{ + char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; + if ( txheight > 0 && numconfs > 0 && (sp= komodo_stateptr(symbol,dest)) != 0 ) + { + if ( sp->NOTARIZED_HEIGHT > 0 ) + { + if ( txheight < sp->NOTARIZED_HEIGHT ) + return(numconfs); + else return(1); + } + } + return(numconfs); +} + int32_t komodo_MoMdata(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t height,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip) { struct notarized_checkpoint *np = 0; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index e9cf54bb4..893c291b0 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -32,6 +32,7 @@ using namespace std; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex); int32_t komodo_longestchain(); +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficulty) { @@ -1150,7 +1151,7 @@ UniValue gettxout(const UniValue& params, bool fHelp) ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) ret.push_back(Pair("confirmations", 0)); - else ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1)); + else ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->nHeight - coins.nHeight + 1))); ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); uint64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue,(int32_t)pindex->nHeight)) != 0 ) diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 9471abf0a..0d2edfd52 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -34,6 +34,7 @@ using namespace std; extern char ASSETCHAINS_SYMBOL[]; +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex) { @@ -230,7 +231,8 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& if (nConfirmations > 0) { entry.push_back(Pair("height", nHeight)); - entry.push_back(Pair("confirmations", nConfirmations)); + entry.push_back(Pair("confirmations", komodo_dpowconfs(nHeight,nConfirmations))); + entry.push_back(Pair("origconfirmations", nConfirmations)); entry.push_back(Pair("time", nBlockTime)); entry.push_back(Pair("blocktime", nBlockTime)); } else { @@ -290,7 +292,8 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) CBlockIndex* pindex = (*mi).second; if (chainActive.Contains(pindex)) { entry.push_back(Pair("height", pindex->nHeight)); - entry.push_back(Pair("confirmations", 1 + chainActive.Height() - pindex->nHeight)); + entry.push_back(Pair("origconfirmations", 1 + chainActive.Height() - pindex->nHeight)); + entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->nHeight,1 + chainActive.Height() - pindex->nHeight))); entry.push_back(Pair("time", pindex->GetBlockTime())); entry.push_back(Pair("blocktime", pindex->GetBlockTime())); } else { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index aa5392472..f5b38dc57 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -47,6 +47,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; extern UniValue TxJoinSplitToJSON(const CTransaction& tx); extern uint8_t ASSETCHAINS_PRIVATE; uint32_t komodo_segid32(char *coinaddr); +int32_t komodo_dpowconfs(int32_t height,int32_t numconfs); int64_t nWalletUnlockTime; static CCriticalSection cs_nWalletUnlockTime; @@ -2698,7 +2699,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) CAmount nValue = out.tx->vout[out.i].nValue; const CScript& pk = out.tx->vout[out.i].scriptPubKey; - UniValue entry(UniValue::VOBJ); + UniValue entry(UniValue::VOBJ); int32_t txheight = 0; entry.push_back(Pair("txid", out.tx->GetHash().GetHex())); entry.push_back(Pair("vout", out.i)); entry.push_back(Pair("generated", out.tx->IsCoinBase())); @@ -2723,7 +2724,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; - uint64_t interest; uint32_t locktime; int32_t txheight; + uint64_t interest; uint32_t locktime; if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); @@ -2732,7 +2733,10 @@ UniValue listunspent(const UniValue& params, bool fHelp) } //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } - entry.push_back(Pair("confirmations",out.nDepth)); + else if ( (tipindex= chainActive.LastTip()) != 0 ) + txheight = (tipindex->nHeight - out.nDepth - 1); + entry.push_back(Pair("origconfirmations",out.nDepth)); + entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); results.push_back(entry); } From 956a638a6026e68b47aea9a2e3af018986546cda Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 11:59:55 -1100 Subject: [PATCH 24/41] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f5b38dc57..2a7f7d1f3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2733,8 +2733,8 @@ UniValue listunspent(const UniValue& params, bool fHelp) } //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } - else if ( (tipindex= chainActive.LastTip()) != 0 ) - txheight = (tipindex->nHeight - out.nDepth - 1); + else if ( chainActive.LastTip() != 0 ) + txheight = (tipchainActive.LastTip()->nHeight - out.nDepth - 1); entry.push_back(Pair("origconfirmations",out.nDepth)); entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); From 20523c958c3e5a391fe655348a68c9cd91a2c7b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:00:58 -1100 Subject: [PATCH 25/41] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2a7f7d1f3..22aecf320 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2734,7 +2734,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } else if ( chainActive.LastTip() != 0 ) - txheight = (tipchainActive.LastTip()->nHeight - out.nDepth - 1); + txheight = (chainActive.LastTip()->nHeight - out.nDepth - 1); entry.push_back(Pair("origconfirmations",out.nDepth)); entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); From a079cdbc6c2f07e1e5c751cd287b2d02b9bcd475 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:39:06 -1100 Subject: [PATCH 26/41] rawconfirmations --- src/komodo_bitcoind.h | 2 +- src/rpcrawtransaction.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 29992c172..73a49e10c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -391,7 +391,7 @@ int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heig { if ( (item= jobj(json,(char *)"result")) != 0 ) { - txid_confirmations = jint(item,(char *)"origconfirmations"); + txid_confirmations = jint(item,(char *)"rawconfirmations"); if ( txid_confirmations > 0 && height > txid_confirmations ) txid_height = height - txid_confirmations; else txid_height = height; diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index 0d2edfd52..a870d526c 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -232,7 +232,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& if (nConfirmations > 0) { entry.push_back(Pair("height", nHeight)); entry.push_back(Pair("confirmations", komodo_dpowconfs(nHeight,nConfirmations))); - entry.push_back(Pair("origconfirmations", nConfirmations)); + entry.push_back(Pair("rawconfirmations", nConfirmations)); entry.push_back(Pair("time", nBlockTime)); entry.push_back(Pair("blocktime", nBlockTime)); } else { @@ -292,7 +292,7 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry) CBlockIndex* pindex = (*mi).second; if (chainActive.Contains(pindex)) { entry.push_back(Pair("height", pindex->nHeight)); - entry.push_back(Pair("origconfirmations", 1 + chainActive.Height() - pindex->nHeight)); + entry.push_back(Pair("rawconfirmations", 1 + chainActive.Height() - pindex->nHeight)); entry.push_back(Pair("confirmations", komodo_dpowconfs(pindex->nHeight,1 + chainActive.Height() - pindex->nHeight))); entry.push_back(Pair("time", pindex->GetBlockTime())); entry.push_back(Pair("blocktime", pindex->GetBlockTime())); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 22aecf320..e7c8e2bdd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2735,7 +2735,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) } else if ( chainActive.LastTip() != 0 ) txheight = (chainActive.LastTip()->nHeight - out.nDepth - 1); - entry.push_back(Pair("origconfirmations",out.nDepth)); + entry.push_back(Pair("rawconfirmations",out.nDepth)); entry.push_back(Pair("confirmations",komodo_dpowconfs(txheight,out.nDepth))); entry.push_back(Pair("spendable", out.fSpendable)); results.push_back(entry); From ade1fc54a8cf891ffcc00d67029a99a3c744e2a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:44:34 -1100 Subject: [PATCH 27/41] KOMODO_DPOWCONFS --- src/komodo_globals.h | 2 +- src/komodo_notary.h | 2 +- src/komodo_utils.h | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index f352b5333..a3a4e3cae 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -52,7 +52,7 @@ uint8_t NOTARY_PUBKEY33[33],ASSETCHAINS_OVERRIDE_PUBKEY33[33],ASSETCHAINS_PUBLIC char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN],ASSETCHAINS_USERPASS[4096]; uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; -uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT; +uint32_t ASSETCHAIN_INIT,ASSETCHAINS_CC,KOMODO_STOPAT,KOMODO_DPOWCONFS = 1; uint32_t ASSETCHAINS_MAGIC = 2387029918; uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; diff --git a/src/komodo_notary.h b/src/komodo_notary.h index ffe575356..8c51c7924 100644 --- a/src/komodo_notary.h +++ b/src/komodo_notary.h @@ -455,7 +455,7 @@ int32_t komodo_notarized_height(int32_t *prevMoMheightp,uint256 *hashp,uint256 * int32_t komodo_dpowconfs(int32_t txheight,int32_t numconfs) { char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; struct komodo_state *sp; - if ( txheight > 0 && numconfs > 0 && (sp= komodo_stateptr(symbol,dest)) != 0 ) + if ( KOMODO_DPOWCONFS != 0 && txheight > 0 && numconfs > 0 && (sp= komodo_stateptr(symbol,dest)) != 0 ) { if ( sp->NOTARIZED_HEIGHT > 0 ) { diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 75f68d87d..0a3c6754e 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1709,6 +1709,8 @@ void komodo_args(char *argv0) ASSETCHAINS_HALVING *= 5; fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440); } + else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) + KOMODO_DPOWCONFS = 0; } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); } From cd91f5d473a9c8037251d879c9bb5ea0ca0399e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 12:47:14 -1100 Subject: [PATCH 28/41] -dpowconfs --- src/komodo_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 0a3c6754e..62d3b0d3a 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,6 +1512,7 @@ void komodo_args(char *argv0) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); + KOMODO_DPOWCONFS = GetArg("-dpowconfs",KOMODO_DPOWCONFS); if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { USE_EXTERNAL_PUBKEY = 1; From a14f4bfe51407bcf7330d95ccb06f3910f651ccb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 21:09:45 -1100 Subject: [PATCH 29/41] Msig prints --- src/cc/gateways.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b9c78a612..a659f82ab 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -189,8 +189,10 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st if ( prefix == 60 ) { if ( N > 1 ) + { Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); - else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); + fprintf(stderr,"f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)pubkeys.size(),depositaddr); + } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); } else { From e2ad1fedd33ca7425c9dbebd121476ffa9cff13e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 14 Oct 2018 21:21:27 -1100 Subject: [PATCH 30/41] Test --- src/cc/gateways.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index a659f82ab..d2c43ad56 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -190,6 +190,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st { if ( N > 1 ) { + strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,pubkeys))).ToString().c_str()); Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); fprintf(stderr,"f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)pubkeys.size(),depositaddr); } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); From fb207182c8caf10dc58509a7807bcd210d74ef2f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 15 Oct 2018 16:24:23 -1100 Subject: [PATCH 31/41] Dpowconfs default 0 for VRSC --- src/komodo_utils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 62d3b0d3a..e6f6a044d 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1512,7 +1512,6 @@ void komodo_args(char *argv0) fprintf(stderr,"KOMODO_EXCHANGEWALLET mode active\n"); DONATION_PUBKEY = GetArg("-donation", ""); NOTARY_PUBKEY = GetArg("-pubkey", ""); - KOMODO_DPOWCONFS = GetArg("-dpowconfs",KOMODO_DPOWCONFS); if ( strlen(NOTARY_PUBKEY.c_str()) == 66 ) { USE_EXTERNAL_PUBKEY = 1; @@ -1701,6 +1700,7 @@ void komodo_args(char *argv0) break; } } + int32_t dpowconfs = KOMODO_DPOWCONFS; if ( ASSETCHAINS_SYMBOL[0] != 0 ) { BITCOIND_RPCPORT = GetArg("-rpcport", ASSETCHAINS_RPCPORT); @@ -1711,8 +1711,9 @@ void komodo_args(char *argv0) fprintf(stderr,"PIRATE halving changed to %d %.1f days\n",(int32_t)ASSETCHAINS_HALVING,(double)ASSETCHAINS_HALVING/1440); } else if ( strcmp("VRSC",ASSETCHAINS_SYMBOL) == 0 ) - KOMODO_DPOWCONFS = 0; + dpowconfs = 0; } else BITCOIND_RPCPORT = GetArg("-rpcport", BaseParams().RPCPort()); + KOMODO_DPOWCONFS = GetArg("-dpowconfs",dpowconfs); } void komodo_nameset(char *symbol,char *dest,char *source) From 6be00678e5c67a6e8d55bc43d044690fe50735da Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 16 Oct 2018 00:13:39 -1100 Subject: [PATCH 32/41] Add raw confirmations for gettxout --- src/rpcblockchain.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 893c291b0..01033bb4b 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -1151,7 +1151,11 @@ UniValue gettxout(const UniValue& params, bool fHelp) ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex())); if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT) ret.push_back(Pair("confirmations", 0)); - else ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->nHeight - coins.nHeight + 1))); + else + { + ret.push_back(Pair("confirmations", komodo_dpowconfs(coins.nHeight,pindex->nHeight - coins.nHeight + 1))); + ret.push_back(Pair("rawconfirmations", pindex->nHeight - coins.nHeight + 1)); + } ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue))); uint64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,hash,n,coins.nHeight,coins.vout[n].nValue,(int32_t)pindex->nHeight)) != 0 ) From 71ab53ffb7b13178d75aa49b5f88b8c10a238b01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 16 Oct 2018 00:17:28 -1100 Subject: [PATCH 33/41] Confirmations/rawconfirmations to block rpc --- src/rpcblockchain.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 01033bb4b..815860c7d 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -118,7 +118,8 @@ UniValue blockheaderToJSON(const CBlockIndex* blockindex) // Only report confirmations if the block is on the main chain if (chainActive.Contains(blockindex)) confirmations = chainActive.Height() - blockindex->nHeight + 1; - result.push_back(Pair("confirmations", confirmations)); + result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations))); + result.push_back(Pair("rawconfirmations", confirmations)); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", blockindex->nVersion)); result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex())); @@ -149,7 +150,8 @@ UniValue blockToDeltasJSON(const CBlock& block, const CBlockIndex* blockindex) } else { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block is an orphan"); } - result.push_back(Pair("confirmations", confirmations)); + result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations))); + result.push_back(Pair("rawconfirmations", confirmations)); result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); @@ -266,7 +268,8 @@ UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool tx // Only report confirmations if the block is on the main chain if (chainActive.Contains(blockindex)) confirmations = chainActive.Height() - blockindex->nHeight + 1; - result.push_back(Pair("confirmations", confirmations)); + result.push_back(Pair("confirmations", komodo_dpowconfs(blockindex->nHeight,confirmations))); + result.push_back(Pair("rawconfirmations", confirmations)); result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); From 07b1fe7785a1944e36f2f57f7515aff2f4bae579 Mon Sep 17 00:00:00 2001 From: Mihailo Milenkovic Date: Tue, 16 Oct 2018 17:36:01 +0200 Subject: [PATCH 34/41] Fix oraclesinfo --- src/cc/oracles.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 5a352afeb..6db1d0b6c 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -854,7 +854,7 @@ UniValue OracleDataSamples(uint256 reforacletxid,uint256 batontxid,int32_t num) UniValue OracleInfo(uint256 origtxid) { - UniValue result(UniValue::VOBJ),a(UniValue::VARR),obj(UniValue::VOBJ); + UniValue result(UniValue::VOBJ),a(UniValue::VARR); std::vector > unspentOutputs; CMutableTransaction mtx; CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); @@ -877,6 +877,7 @@ UniValue OracleInfo(uint256 origtxid) { if ( regtx.vout.size() > 0 && DecodeOraclesOpRet(regtx.vout[regtx.vout.size()-1].scriptPubKey,oracletxid,pk,datafee) == 'R' && oracletxid == origtxid ) { + UniValue obj(UniValue::VOBJ); obj.push_back(Pair("publisher",pubkey33_str(str,(uint8_t *)pk.begin()))); Getscriptaddress(batonaddr,regtx.vout[1].scriptPubKey); batontxid = OracleBatonUtxo(10000,cp,oracletxid,batonaddr,pk,data); From 951627d7cb22a3e4ad4975033aad9e8ca4421626 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Thu, 18 Oct 2018 16:17:17 +0700 Subject: [PATCH 35/41] this space made tests failing --- qa/rpc-tests/cryptoconditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index e7d3065cc..cb83b7243 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -602,4 +602,4 @@ class CryptoConditionsTest (BitcoinTestFramework): if __name__ == '__main__': - CryptoConditionsTest ().main () + CryptoConditionsTest ().main() From 8b8b7f048ec8ae9110f2eeddb63db17bfcb8383e Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 19 Oct 2018 13:30:28 +0700 Subject: [PATCH 36/41] added validation for oraclesinfo --- src/cc/oracles.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 6db1d0b6c..7cccad0f6 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -859,6 +859,13 @@ UniValue OracleInfo(uint256 origtxid) CMutableTransaction mtx; CTransaction regtx,tx; std::string name,description,format; uint256 hashBlock,txid,oracletxid,batontxid; CPubKey pk; struct CCcontract_info *cp,C; int64_t datafee,funding; char str[67],markeraddr[64],numstr[64],batonaddr[64]; std::vector data; cp = CCinit(&C,EVAL_ORACLES); CCtxidaddr(markeraddr,origtxid); + if ( GetTransaction(origtxid,tx,hashBlock,false) == 0 ) + { + fprintf(stderr,"cant find oracleid\n"); + result.push_back(Pair("result","error")); + result.push_back(Pair("error","cant find oracleid")); + return(result); + } if ( GetTransaction(origtxid,tx,hashBlock,false) != 0 ) { if ( tx.vout.size() > 0 && DecodeOraclesCreateOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,name,description,format) == 'C' ) From a3ee81a87385539e22620bad54ae7efbdabd629a Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 19 Oct 2018 17:13:32 +0700 Subject: [PATCH 37/41] added oracle data type validation --- src/wallet/rpcwallet.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e7c8e2bdd..c7d4f8a16 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5733,6 +5733,24 @@ UniValue oraclescreate(const UniValue& params, bool fHelp) ERR_RESULT("oracles format must be <= 4096 characters"); return(result); } + // list of oracle valid formats from oracles.cpp -> oracle_format + const UniValue valid_formats[13] = {"s","S","d","D","c","C","t","T","i","I","l","L","h"}; + const UniValue header_type = "Ihh"; + // checking if oracle data type is valid + bool is_valid_format = false; + for ( int i = 0; i < 13; ++i ) { + if ( valid_formats[i].get_str() == format ) { + is_valid_format = true; + } + } + // additional check for special Ihh data type + if ( format == header_type.get_str() ) { + is_valid_format = true; + } + if ( !is_valid_format ) { + ERR_RESULT("oracles format not valid"); + return(result); + } hex = OracleCreate(0,name,description,format); if ( hex.size() > 0 ) { From 8c2c4c7ecce80d68248418a9474f0f4326e9bad4 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Fri, 19 Oct 2018 18:24:58 +0700 Subject: [PATCH 38/41] added oracles creation rpc tests --- qa/rpc-tests/cryptoconditions.py | 57 ++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index cb83b7243..1d2f68777 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -3,6 +3,7 @@ # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. + from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ @@ -11,6 +12,8 @@ from test_framework.util import assert_equal, assert_greater_than, \ import time from decimal import Decimal +from random import choice +from string import ascii_uppercase def assert_success(result): assert_equal(result['result'], 'success') @@ -18,6 +21,11 @@ def assert_success(result): def assert_error(result): assert_equal(result['result'], 'error') +def generate_random_string(length): + random_string = ''.join(choice(ascii_uppercase) for i in range(length)) + return random_string + + class CryptoConditionsTest (BitcoinTestFramework): def setup_chain(self): @@ -470,7 +478,6 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenbalance(tokenid,randompubkey) assert_equal(result["balance"], 1) - def run_rewards_tests(self): rpc = self.nodes[0] result = rpc.rewardsaddress() @@ -581,6 +588,51 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid) assert_error(result) + def run_oracles_tests(self): + rpc = self.nodes[0] + result = rpc.oraclesaddress() + assert_success(result) + for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.oraclesaddress(self.pubkey) + assert_success(result) + for x in ['OraclesCCaddress', 'Oraclesmarker', 'myCCaddress', 'myaddress']: + assert_equal(result[x][0], 'R') + + # there are no oracles created yet + result = rpc.oracleslist() + assert_equal(result, []) + + # looking up non-existent oracle should return error. + result = rpc.oraclesinfo("none") + assert_error(result) + + # attempt to create oracle with not valid data type should return error + result = rpc.oraclescreate("Test", "Test", "Test") + assert_error(result) + + # attempt to create oracle with description > 32 symbols should return error + too_long_name = generate_random_string(33) + result = rpc.oraclescreate(too_long_name, "Test", "s") + + + # attempt to create oracle with description > 4096 symbols should return error + too_long_description = generate_random_string(4100) + result = rpc.oraclescreate("Test", too_long_description, "s") + assert_error(result) + + # valid creating oracles of different types + # using such naming to re-use it for data publishing / reading (e.g. oracle_s for s type) + valid_formats = ["s", "S", "d", "D", "c", "C", "t", "T", "i", "I", "l", "L", "h", "Ihh"] + for f in valid_formats: + result = rpc.oraclescreate("Test", "Test", f) + assert_success(result) + globals()["oracle_{}".format(f)] = self.send_and_mine(result['hex']) + + + + def run_test (self): print("Mining blocks...") @@ -594,11 +646,12 @@ class CryptoConditionsTest (BitcoinTestFramework): print("Importing privkey") rpc.importprivkey(self.privkey) -# self.run_faucet_tests() + #self.run_faucet_tests() self.run_rewards_tests() self.run_dice_tests() self.run_token_tests() self.run_faucet_tests() + self.run_oracles_tests() if __name__ == '__main__': From 7b8cefe19280659e2c3e7564478106b6009c23dc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 19 Oct 2018 06:37:24 -1100 Subject: [PATCH 39/41] Wallettx2json raw confirmations --- src/cc/gateways.cpp | 2 +- src/wallet/rpcwallet.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index d2c43ad56..1db08532a 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -191,7 +191,7 @@ uint8_t DecodeGatewaysBindOpRet(char *depositaddr,const CScript &scriptPubKey,st if ( N > 1 ) { strcpy(depositaddr,CBitcoinAddress(CScriptID(GetScriptForMultisig(M,pubkeys))).ToString().c_str()); - Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); + //Getscriptaddress(depositaddr,GetScriptForMultisig(M,pubkeys)); fprintf(stderr,"f.%c M.%d of N.%d size.%d -> %s\n",f,M,N,(int32_t)pubkeys.size(),depositaddr); } else Getscriptaddress(depositaddr,CScript() << ParseHex(HexStr(pubkeys[0])) << OP_CHECKSIG); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c7d4f8a16..c9bffbb33 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -90,7 +90,8 @@ void WalletTxToJSON(const CWalletTx& wtx, UniValue& entry) { //int32_t i,n,txheight; uint32_t locktime; uint64_t interest = 0; int confirms = wtx.GetDepthInMainChain(); - entry.push_back(Pair("confirmations", confirms)); + entry.push_back(Pair("rawconfirmations", confirms)); + entry.push_back(Pair("confirmations", komodo_dpowconfs((int32_t)mapBlockIndex[wtx.hashBlock]->nHeight,confirms))); if (wtx.IsCoinBase()) entry.push_back(Pair("generated", true)); if (confirms > 0) From 3448cd83bbcf3ebe995ba83aadcf0a426a50d9c1 Mon Sep 17 00:00:00 2001 From: Alrighttt Date: Fri, 19 Oct 2018 23:03:20 +0200 Subject: [PATCH 40/41] comment out spamming print --- src/cc/oracles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 7cccad0f6..0c7d9e6e2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -666,7 +666,7 @@ int64_t AddOracleInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPub std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); - fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr); + //fprintf(stderr,"addoracleinputs from (%s)\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; From fac14d5dc4abd1c47f031596d15b2798445f14d6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Wed, 24 Oct 2018 12:16:36 +0800 Subject: [PATCH 41/41] add pubkey to getinfo for all pubkeys, not just notary --- src/rpcmisc.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index a42afbb61..a1d576d58 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -64,6 +64,7 @@ extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,AS UniValue getinfo(const UniValue& params, bool fHelp) { uint256 notarized_hash,notarized_desttxid; int32_t prevMoMheight,notarized_height,longestchain,kmdnotarized_height,txid_height; + extern std::string NOTARY_PUBKEY; extern uint8_t NOTARY_PUBKEY33[]; if (fHelp || params.size() != 0) throw runtime_error( "getinfo\n" @@ -158,6 +159,8 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("pubkey", pubkeystr)); if ( KOMODO_LASTMINED != 0 ) obj.push_back(Pair("lastmined", KOMODO_LASTMINED)); + } else if ( NOTARY_PUBKEY33[0] != 0 ) { + obj.push_back(Pair("pubkey", NOTARY_PUBKEY)); } } if ( ASSETCHAINS_CC != 0 )