From c1e694dd80b5dd3b77e37bfe929f3ef267201e94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 16 Dec 2018 04:59:04 -1100 Subject: [PATCH 01/68] Update zmigrate --- src/cc/dapps/zmigrate.c | 67 +++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 81de2c13d..8a57ebda5 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -20,18 +20,18 @@ #include "cJSON.c" /* -z_migrate: the purpose of z_migrate is to make converting of all sprout outputs into sapling. the usage would be for the user to specify a sapling address and call z_migrate zsaddr, until it returns that there is nothing left to be done. - -its main functionality is quite similar to a z_mergetoaddress ANY_ZADDR -> onetime_taddr followed by a z_sendmany onetime_taddr -> zsaddr - -since the z_mergetoaddress will take time, it would just queue up an async operation. When it starts, it should see if there are any onetime_taddr with 10000.0001 funds in it, that is a signal for it to do the sapling tx and it can just do that without async as it is fast enough, especially with a taddr input. Maybe it limits itself to one, or it does all possible taddr -> sapling as fast as it can. either is fine as it will be called over and over anyway. - -It might be that there is nothing to do, but some operations are pending. in that case it would return such a status. as soon as the operation finishes, there would be more work to do. - -the amount sent to the taddr, should be 10000.0001 - -The GUI or user would be expected to generate a sapling address and then call z_migrate saplingaddr in a loop, until it returns that it is all done. this loop should pause for 10 seconds or so, if z_migrate is just waiting for opid to complete. -*/ + z_migrate: the purpose of z_migrate is to make converting of all sprout outputs into sapling. the usage would be for the user to specify a sapling address and call z_migrate zsaddr, until it returns that there is nothing left to be done. + + its main functionality is quite similar to a z_mergetoaddress ANY_ZADDR -> onetime_taddr followed by a z_sendmany onetime_taddr -> zsaddr + + since the z_mergetoaddress will take time, it would just queue up an async operation. When it starts, it should see if there are any onetime_taddr with 10000.0001 funds in it, that is a signal for it to do the sapling tx and it can just do that without async as it is fast enough, especially with a taddr input. Maybe it limits itself to one, or it does all possible taddr -> sapling as fast as it can. either is fine as it will be called over and over anyway. + + It might be that there is nothing to do, but some operations are pending. in that case it would return such a status. as soon as the operation finishes, there would be more work to do. + + the amount sent to the taddr, should be 10000.0001 + + The GUI or user would be expected to generate a sapling address and then call z_migrate saplingaddr in a loop, until it returns that it is all done. this loop should pause for 10 seconds or so, if z_migrate is just waiting for opid to complete. + */ bits256 zeroid; @@ -331,7 +331,7 @@ cJSON *get_komodocli(char *refcoin,char **retstrp,char *acname,char *method,char system(cmdstr); *retstrp = 0; if ( (jsonstr= filestr(&fsize,fname)) != 0 ) - { + { jsonstr[strlen(jsonstr)-1]='\0'; //fprintf(stderr,"%s -> jsonstr.(%s)\n",cmdstr,jsonstr); if ( (jsonstr[0] != '{' && jsonstr[0] != '[') || (retjson= cJSON_Parse(jsonstr)) == 0 ) @@ -599,13 +599,13 @@ int32_t validateaddress(char *refcoin,char *acname,char *depositaddr, char* comp cJSON *retjson; char *retstr; int32_t res=0; if ( (retjson= get_komodocli(refcoin,&retstr,acname,"validateaddress",depositaddr,"","","")) != 0 ) { - if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1; + if (is_cJSON_True(jobj(retjson,compare)) != 0 ) res=1; free_json(retjson); } else if ( retstr != 0 ) { fprintf(stderr,"validateaddress.(%s) %s error.(%s)\n",refcoin,acname,retstr); - free(retstr); + free(retstr); } return (res); } @@ -670,6 +670,7 @@ int64_t find_onetime_amount(char *coinstr,char *coinaddr) coinaddr[0] = 0; if ( (array= get_listunspent(coinstr,"")) != 0 ) { + //printf("got listunspent.(%s)\n",jprint(array,0)); if ( (n= cJSON_GetArraySize(array)) > 0 ) { for (i=0; i %s\n",srcaddr,params); if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_sendmany",addr,params,"","")) != 0 ) { printf("unexpected json z_sendmany.(%s)\n",jprint(retjson,0)); @@ -797,7 +799,7 @@ int32_t tx_has_voutaddress(char *refcoin,char *acname,bits256 txid,char *coinadd if ( (vouts= jarray(&numarray,txobj,"vout")) != 0 ) { for (i=0; i txfee ) @@ -930,14 +932,33 @@ again: if ( (amount= find_sprout_amount(coinstr,zcaddr)) > txfee ) { // generate taddr, send max of 10000.0001 - if ( amount > stdamount+txfee ) - amount = stdamount + txfee; + static int64_t lastamount,lastamount2,lastamount3,lastamount4,refamount = 5000 * SATOSHIDEN; + stdamount = refamount; + if ( amount == lastamount && amount == lastamount2 ) + { + stdamount /= 10; + if ( amount == lastamount3 && amount == lastamount4 ) + stdamount /= 10; + } + if ( stdamount < COIN ) + { + stdamount = COIN; + refamount = COIN * 50; + } + if ( stdamount < refamount ) + refamount = stdamount; + lastamount4 = lastamount3; + lastamount3 = lastamount2; + lastamount2 = lastamount; + lastamount = amount; + if ( amount > stdamount+2*txfee ) + amount = stdamount + 2*txfee; if ( getnewaddress(coinaddr,coinstr,"") == 0 ) { z_sendmany(opidstr,coinstr,"",zcaddr,coinaddr,amount-txfee); lastopid = (uint32_t)time(NULL); } else printf("couldnt getnewaddress!\n"); - sleep(30); + sleep(3); continue; } if ( time(NULL) > lastopid+600 ) From e9b100e50fac7772b4080c0d182f751f21d0ec58 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 16 Dec 2018 05:51:21 -1100 Subject: [PATCH 02/68] COIN -> SATOSHIDEN --- src/cc/dapps/zmigrate.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 8a57ebda5..d492163c4 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -940,10 +940,10 @@ again: if ( amount == lastamount3 && amount == lastamount4 ) stdamount /= 10; } - if ( stdamount < COIN ) + if ( stdamount < SATOSHIDEN ) { - stdamount = COIN; - refamount = COIN * 50; + stdamount = SATOSHIDEN; + refamount = SATOSHIDEN * 50; } if ( stdamount < refamount ) refamount = stdamount; From fe32a3be6c8950266d759103d2fb2beda635967e Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 16 Dec 2018 07:39:54 -1100 Subject: [PATCH 03/68] Fix stuck sync for nodes that are doing full sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sapling height is calculated near the sapling activation timestamp. Until it is set, the node doesn’t know when sapling should be active. Depending on the speed at which you get blocks from the future, it was possible that you could see a sapling active block before the sapling height was set. This would happen only if syncing from a node that didn’t know the sapling height and a full resync with the most peers and most variety of incoming block sources was most likely hit by this. The net effect was that the blocks after sapling activation were marked as invalid, so by the time the node synced up to the sapling height, it couldn’t advance. --- src/main.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 6c33feb08..d822c8686 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5043,6 +5043,19 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C auto verifier = libzcash::ProofVerifier::Disabled(); if ((!CheckBlock(futureblockp,pindex->GetHeight(),pindex,block, state, verifier,0)) || !ContextualCheckBlock(block, state, pindex->pprev)) { + static int32_t saplinght = -1; + CBlockIndex *tmpptr; + if ( saplinght == -1 ) + saplinght = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight; + if ( saplinght < 0 ) + *futureblockp = 1; + // the problem is when a future sapling block comes in before we detected saplinght + if ( saplinght > 0 && (tmpptr= chainActive.LastTip()) != 0 ) + { + fprintf(stderr,"saplinght.%d tipht.%d blockht.%d cmp.%d\n",saplinght,(int32_t)tmpptr->GetHeight(),pindex->GetHeight(),pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720)); + if ( pindex->GetHeight() < 0 || pindex->GetHeight() >= saplinght || (tmpptr->GetHeight() > saplinght-720 && tmpptr->GetHeight() < saplinght+720) ) + *futureblockp = 1; + } if ( *futureblockp == 0 ) { if (state.IsInvalid() && !state.CorruptionPossible()) { From b3837525ee282e12144c868edcdd5fbce9ceb2ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Dec 2018 09:00:04 -1100 Subject: [PATCH 04/68] New migrate --- .gitignore | 2 + src/cc/dapps/zmigrate.c | 86 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 01e45a168..cd2641c22 100644 --- a/.gitignore +++ b/.gitignore @@ -124,3 +124,5 @@ src/komodo-tx.exe #output during builds, symbol tables? *.dSYM + +src/cryptoconditions/compile diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index d492163c4..441b51b19 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -647,6 +647,25 @@ int64_t z_getbalance(char *refcoin,char *acname,char *coinaddr) return (amount); } +int32_t z_exportkey(char *privkey,char *refcoin,char *acname,char *zaddr) +{ + cJSON *retjson; char *retstr,cmpstr[64]; int64_t amount=0; + privkey[0] = 0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_exportkey",zaddr,"","","")) != 0 ) + { + fprintf(stderr,"z_exportkey.(%s) %s returned json!\n",refcoin,acname); + free_json(retjson); + return(-1); + } + else if ( retstr != 0 ) + { + //printf("retstr %s -> %.8f\n",retstr,dstr(amount)); + strcpy(privkey,retstr); + free(retstr); + return(0); + } +} + int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname) { cJSON *retjson; char *retstr; int64_t amount=0; @@ -664,6 +683,23 @@ int32_t getnewaddress(char *coinaddr,char *refcoin,char *acname) } } +int32_t z_getnewaddress(char *coinaddr,char *refcoin,char *acname,char *typestr) +{ + cJSON *retjson; char *retstr; int64_t amount=0; + if ( (retjson= get_komodocli(refcoin,&retstr,acname,"z_getnewaddress",typestr,"","","")) != 0 ) + { + fprintf(stderr,"z_getnewaddress.(%s) %s returned json!\n",refcoin,acname); + free_json(retjson); + return(-1); + } + else if ( retstr != 0 ) + { + strcpy(coinaddr,retstr); + free(retstr); + return(0); + } +} + int64_t find_onetime_amount(char *coinstr,char *coinaddr) { cJSON *array,*item; int32_t i,n; char *addr; int64_t amount = 0; @@ -751,6 +787,39 @@ int32_t z_sendmany(char *opidstr,char *coinstr,char *acname,char *srcaddr,char * } } +int32_t z_mergetoaddress(char *opidstr,char *coinstr,char *acname,char *destaddr) +{ + cJSON *retjson; char *retstr,addr[128],*opstr; int32_t retval = -1; + sprintf(addr,"[\\\"ANY_SPROUT\\\"]"); + //printf("z_sendmany from.(%s) -> %s\n",addr,destaddr); + if ( (retjson= get_komodocli(coinstr,&retstr,acname,"z_mergetoaddress",addr,destaddr,"","")) != 0 ) + { + /*{ + "remainingUTXOs": 0, + "remainingTransparentValue": 0.00000000, + "remainingNotes": 222, + "remainingShieldedValue": 5413.39093055, + "mergingUTXOs": 0, + "mergingTransparentValue": 0.00000000, + "mergingNotes": 10, + "mergingShieldedValue": 822.47447172, + "opid": "opid-f28f6261-4120-436c-aca5-859870a40a70" + }*/ + if ( (opstr= jstr(retjson,"opid")) != 0 ) + strcpy(opidstr,opstr); + retval = jint(retjson,"remainingNotes"); + fprintf(stderr,"%s\n",jprint(retjson,0)); + free_json(retjson); + } + else if ( retstr != 0 ) + { + fprintf(stderr,"z_mergetoaddress.(%s) -> opid.(%s)\n",coinstr,retstr); + strcpy(opidstr,retstr); + free(retstr); + } + return(retval); +} + int32_t empty_mempool(char *coinstr,char *acname) { cJSON *array; int32_t n; @@ -907,10 +976,25 @@ int32_t main(int32_t argc,char **argv) } zsaddr = clonestr(argv[2]); printf("%s: %s %s\n",REFCOIN_CLI,coinstr,zsaddr); - uint32_t lastopid; char coinaddr[64],zcaddr[128],opidstr[128]; int32_t finished; int64_t amount,stdamount,txfee; + uint32_t lastopid; char coinaddr[64],privkey[1024],zcaddr[128],opidstr[128]; int32_t finished; int64_t amount,stdamount,txfee; //stdamount = 500 * SATOSHIDEN; txfee = 10000; again: + if ( z_getnewaddress(zcaddr,coinstr,"","sprout") == 0 ) + { + z_exportkey(privkey,coinstr,"",zcaddr); + printf("zcaddr.(%s) -> z_exportkey.(%s)\n",zcaddr,privkey); + while ( 1 ) + { + if ( have_pending_opid(coinstr,0) != 0 ) + { + sleep(10); + continue; + } + if ( z_mergetoaddress(opidstr,coinstr,"",zcaddr) <= 0 ) + break; + } + } printf("start processing zmigrate\n"); lastopid = (uint32_t)time(NULL); finished = 0; From 97658a0c03a35073bdfe45f3922e05af1ed3ea6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Dec 2018 09:03:54 -1100 Subject: [PATCH 05/68] z_mergetoaddress fix --- src/wallet/rpcwallet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f8b507403..f431bce81 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4789,9 +4789,11 @@ UniValue z_mergetoaddress(const UniValue& params, bool fHelp) if (useAnySprout || useAnySapling || zaddrs.size() > 0) { // Get available notes std::vector sproutEntries; - std::vector saplingEntries; - pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs); - + //std::vector saplingEntries; + //pwalletMain->GetFilteredNotes(sproutEntries, saplingEntries, zaddrs); + std::vector saplingEntries,skipsapling; + pwalletMain->GetFilteredNotes(sproutEntries, useAnySprout == 0 ? saplingEntries : skipsapling, zaddrs); + // If Sapling is not active, do not allow sending from a sapling addresses. if (!saplingActive && saplingEntries.size() > 0) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, Sapling has not activated"); From 93f18db31afd9afb3103c89b3118c3932e7ab43e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 19 Dec 2018 09:25:38 -1100 Subject: [PATCH 06/68] Skip unspendable addresses in migrate --- src/cc/dapps/zmigrate.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index 441b51b19..6fa3c3cc8 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -712,6 +712,10 @@ int64_t find_onetime_amount(char *coinstr,char *coinaddr) for (i=0; i Date: Sun, 6 Jan 2019 22:10:59 +0100 Subject: [PATCH 07/68] Fixed a 404'd libsodium link --- depends/packages/libsodium.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/libsodium.mk b/depends/packages/libsodium.mk index 67e096fae..76f0d9a28 100644 --- a/depends/packages/libsodium.mk +++ b/depends/packages/libsodium.mk @@ -9,7 +9,7 @@ $(package)_config_opts= else package=libsodium $(package)_version=1.0.15 -$(package)_download_path=https://download.libsodium.org/libsodium/releases +$(package)_download_path=https://download.libsodium.org/libsodium/releases/old $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_sha256_hash=fb6a9e879a2f674592e4328c5d9f79f082405ee4bb05cb6e679b90afe9e178f4 $(package)_dependencies= From 7d56db54d1c89218992616f271dbb320f19a5b8e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Jan 2019 07:33:23 -1100 Subject: [PATCH 08/68] Messages --- src/net.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/net.h b/src/net.h index e2fbdb0bd..02714e20f 100644 --- a/src/net.h +++ b/src/net.h @@ -48,7 +48,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024; +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ From ce5995738b3b4c5dbb953e58b4df590f0c143ffe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 7 Jan 2019 07:43:15 -1100 Subject: [PATCH 09/68] Update version --- src/rpc/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 7bfb98f7b..323540790 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -56,7 +56,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); -#define KOMODO_VERSION "0.3.1" +#define KOMODO_VERSION "0.3.3" #define VERUS_VERSION "0.4.0g" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; From 8e172149f632cdcb7944b563c2f0e5819b8abbf9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:19:28 -1100 Subject: [PATCH 10/68] Add context check in connectTip --- src/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 20f28d46a..8dcd3cc10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3170,6 +3170,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } + if ( fCheckPOW != 0 && pindex->nTime > 1548979200 && !ContextualCheckBlock(block, state, pindex->pprev) ) // activate check Feb 1, 2019 + { + fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); + return false; + } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); From cb64a2dc5673b7e9d94704fdd34013ebbdabf669 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 Jan 2019 23:20:34 -1100 Subject: [PATCH 11/68] Activate jan 15th --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 8dcd3cc10..861fb7eab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3170,7 +3170,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - if ( fCheckPOW != 0 && pindex->nTime > 1548979200 && !ContextualCheckBlock(block, state, pindex->pprev) ) // activate check Feb 1, 2019 + if ( fCheckPOW != 0 && pindex->nTime > 1547510400 && !ContextualCheckBlock(block, state, pindex->pprev) ) // activate check Jan 15, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); return false; From 0e49163d4af4fba54bce04c47e21c8d2e9cb2067 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 00:04:30 -1100 Subject: [PATCH 12/68] Jan 15th activation of stricter block checks --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 861fb7eab..fe6fb4030 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3170,10 +3170,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin //fprintf(stderr,"checkblock failure in connectblock futureblock.%d\n",futureblock); return false; } - if ( fCheckPOW != 0 && pindex->nTime > 1547510400 && !ContextualCheckBlock(block, state, pindex->pprev) ) // activate check Jan 15, 2019 + if ( fCheckPOW != 0 && !ContextualCheckBlock(block, state, pindex->pprev) ) // Activate Jan 15th, 2019 { fprintf(stderr,"ContextualCheckBlock failed ht.%d\n",(int32_t)pindex->GetHeight()); - return false; + if ( pindex->nTime > 1547510400 ) + return false; + fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); } // verify that the view's current state corresponds to the previous block From 8a5f7bdf6a35a967c0fad805424a500ce3a8aad4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 00:05:22 -1100 Subject: [PATCH 13/68] Version 0.3.3b --- src/rpc/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 323540790..e29abc60e 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -56,7 +56,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; uint32_t komodo_segid32(char *coinaddr); int64_t komodo_coinsupply(int64_t *zfundsp,int64_t *sproutfundsp,int32_t height); int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp); -#define KOMODO_VERSION "0.3.3" +#define KOMODO_VERSION "0.3.3b" #define VERUS_VERSION "0.4.0g" extern uint16_t ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT; extern uint32_t ASSETCHAINS_CC; From 1f46aa58e6913856f4a921305329b407d3af28fc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:26:25 -1100 Subject: [PATCH 14/68] Allow tunable maxreorg --- src/komodo_utils.h | 1 + src/main.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 19941a172..aa887bba3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1701,6 +1701,7 @@ void komodo_args(char *argv0) } } KOMODO_STOPAT = GetArg("-stopat",0); + MAX_REORG_LENGTH = GetArg("-maxreorg",MAX_REORG_LENGTH); ASSETCHAINS_CC = GetArg("-ac_cc",0); KOMODO_CCACTIVATE = GetArg("-ac_ccactivate",0); ASSETCHAINS_PUBLIC = GetArg("-ac_public",0); diff --git a/src/main.h b/src/main.h index fdd9fcae8..775b31eb6 100644 --- a/src/main.h +++ b/src/main.h @@ -63,7 +63,7 @@ static const bool DEFAULT_ALERTS = true; /** Minimum alert priority for enabling safe mode. */ static const int ALERT_PRIORITY_SAFE_MODE = 4000; /** Maximum reorg length we will accept before we shut down and alert the user. */ -static const unsigned int MAX_REORG_LENGTH = _COINBASE_MATURITY - 1; +static unsigned int MAX_REORG_LENGTH = _COINBASE_MATURITY - 1; /** Maximum number of signature check operations in an IsStandard() P2SH script */ static const unsigned int MAX_P2SH_SIGOPS = 15; /** The maximum number of sigops we're willing to relay/mine in a single tx */ From ba1b2b5c5674af96051eb7a22ce86d1b707566d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 01:43:10 -1100 Subject: [PATCH 15/68] -Static assert --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fe6fb4030..3d2f19b55 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4078,7 +4078,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo // then pindexFork will be null, and we would need to remove the entire chain including // our genesis block. In practice this (probably) won't happen because of checks elsewhere. auto reorgLength = pindexOldTip ? pindexOldTip->GetHeight() - (pindexFork ? pindexFork->GetHeight() : -1) : 0; - static_assert(MAX_REORG_LENGTH > 0, "We must be able to reorg some distance"); + assert(MAX_REORG_LENGTH > 0);//, "We must be able to reorg some distance"); if (reorgLength > MAX_REORG_LENGTH) { int32_t notarizedht,prevMoMheight; uint256 notarizedhash,txid; From 9040d03af61ceec11d5c352dca337b480ae8acad Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 02:21:47 -1100 Subject: [PATCH 16/68] Match WITNESS_CACHE_SIZE to maxreorg --- src/komodo_utils.h | 1 + src/wallet/wallet.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index aa887bba3..d15f7d7e4 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1650,6 +1650,7 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } extern int64_t MAX_MONEY; +extern unsigned int WITNESS_CACHE_SIZE; void komodo_args(char *argv0) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index c5cfedda8..5f040dded 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -61,7 +61,7 @@ static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; // Should be large enough that we can expect not to reorg beyond our cache // unless there is some exceptional network disruption. #define _COINBASE_MATURITY 100 -static const unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; +unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; //! Size of HD seed in bytes static const size_t HD_WALLET_SEED_LENGTH = 32; From 93b616becd062079d1ed44edc9d865617f3c75b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 9 Jan 2019 02:32:11 -1100 Subject: [PATCH 17/68] Move WITNESS_CACHE_SIZE --- src/komodo_globals.h | 1 + src/komodo_utils.h | 1 - src/wallet/wallet.h | 3 +-- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 3e9b84db1..ff3748729 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -44,6 +44,7 @@ struct komodo_state KOMODO_STATES[34]; #define _COINBASE_MATURITY 100 int COINBASE_MATURITY = _COINBASE_MATURITY;//100; +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; diff --git a/src/komodo_utils.h b/src/komodo_utils.h index d15f7d7e4..aa887bba3 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1650,7 +1650,6 @@ uint64_t komodo_ac_block_subsidy(int nHeight) } extern int64_t MAX_MONEY; -extern unsigned int WITNESS_CACHE_SIZE; void komodo_args(char *argv0) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 5f040dded..7adfb4e35 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -60,8 +60,7 @@ static const unsigned int MAX_FREE_TRANSACTION_CREATE_SIZE = 1000; //! Size of witness cache // Should be large enough that we can expect not to reorg beyond our cache // unless there is some exceptional network disruption. -#define _COINBASE_MATURITY 100 -unsigned int WITNESS_CACHE_SIZE = _COINBASE_MATURITY+10; +extern unsigned int WITNESS_CACHE_SIZE; //! Size of HD seed in bytes static const size_t HD_WALLET_SEED_LENGTH = 32; From 7598204bf98d5316c3dad7c40a458810b6c71d55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 10 Jan 2019 18:49:38 -1100 Subject: [PATCH 18/68] Fix bip44 code --- src/chainparams.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index a04e4131a..02b73f04b 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -92,7 +92,8 @@ public: strNetworkID = "main"; strCurrencyUnits = "KMD"; - bip44CoinType = 133; // 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; From bfd4917613ae58e6c4d49354f2efb9406aec141d Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 06:41:11 +0100 Subject: [PATCH 19/68] [update] cclib OSX makefile --- src/cc/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index 3522a0c08..a3c54d81d 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -1,7 +1,8 @@ SHELL = /bin/sh CC = gcc +CC_DARWIN = g++-6 CC_WIN = x86_64-w64-mingw32-gcc-posix -CFLAGS_DARWIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c +CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c DEBUGFLAGS = -O0 -D _DEBUG @@ -19,13 +20,13 @@ all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib to src/) ifeq ($(OS),Darwin) - $(CC) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host else - $(info else) - #$(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) + $(info WINDOWS) + $(CC_WIN) $(CFLAGS_WIN) $(DEBUGFLAGS) -o $(TARGET_WIN) $(SOURCES) endif clean: From 28195d218b86a35b4d61993ba0e72661c85bdef1 Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 07:11:58 +0100 Subject: [PATCH 20/68] [add] cclib README --- src/cc/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/cc/README.md diff --git a/src/cc/README.md b/src/cc/README.md new file mode 100644 index 000000000..d12a75c43 --- /dev/null +++ b/src/cc/README.md @@ -0,0 +1,7 @@ +## CCLIB +Please follow the below instructions to build the cryptoconditions library into the Komodo source directory `komodo/src` - supported operating systems are Linux, OSX and Windows (mingw crossbuild): + +``` +make clean +make +``` From 923b87a6ecf93b294522207f668d3a3be5be75fc Mon Sep 17 00:00:00 2001 From: ca333 Date: Mon, 21 Jan 2019 13:04:18 +0100 Subject: [PATCH 21/68] [add] dylib --- src/cc/Makefile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/cc/Makefile b/src/cc/Makefile index a3c54d81d..92fbe0da9 100644 --- a/src/cc/Makefile +++ b/src/cc/Makefile @@ -2,7 +2,7 @@ SHELL = /bin/sh CC = gcc CC_DARWIN = g++-6 CC_WIN = x86_64-w64-mingw32-gcc-posix -CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup +CFLAGS_DARWIN = -std=c++11 -arch x86_64 -I/usr/local/Cellar/gcc\@6/6.4.0_2/include/c++/6.4.0/ -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -c -Wl,-undefined -Wl,dynamic_lookup -dynamiclib CFLAGS = -std=c++11 -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c CFLAGS_WIN = -std=c++11 -I../../depends/$(shell echo `../..//depends/config.guess`/include) -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c DEBUGFLAGS = -O0 -D _DEBUG @@ -10,8 +10,9 @@ RELEASEFLAGS = -O2 -D NDEBUG -combine -fwhole-program $(info $(OS)) OS := $(shell uname -s) $(info $(OS)) -TARGET = ../cclib.so -TARGET_WIN = ../cclib.dll +TARGET = ../libcc.so +TARGET_DARWIN = ../libcc.dylib +TARGET_WIN = ../libcc.dll SOURCES = cclib.cpp #HEADERS = $(shell echo ../cryptoconditions/include/*.h) @@ -20,7 +21,7 @@ all: $(TARGET) $(TARGET): $(SOURCES) $(info Building cclib to src/) ifeq ($(OS),Darwin) - $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) + $(CC_DARWIN) $(CFLAGS_DARWIN) $(DEBUGFLAGS) -o $(TARGET_DARWIN) $(SOURCES) else ifeq ($(OS),Linux) $(CC) $(CFLAGS) $(DEBUGFLAGS) -o $(TARGET) $(SOURCES) #else ifeq ($(WIN_HOST),True) - todo: pass ENV var from build.sh if WIN host From d8289cd12813f6f440559541e5f04d62ddfc8ae5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:13:58 -1100 Subject: [PATCH 22/68] Test --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 01ff9da0c..ab0a770c1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1707,6 +1707,7 @@ void static BitcoinMiner() for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," Invalid block mined, try again\n"); + break; return(false); } KOMODO_CHOSEN_ONE = 1; From ba46fa56d9734204ee7ae748980960130d504810 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:18:38 -1100 Subject: [PATCH 23/68] Got invalid --- src/miner.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ab0a770c1..05d324075 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1604,16 +1604,12 @@ void static BitcoinMiner() fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } + int32_t gotinvalid = 0; while (true) { - /*if ( KOMODO_INSYNC == 0 ) - { - KOMODO_LONGESTCHAIN = komodo_longestchain(); - fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height); - if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN ) - KOMODO_INSYNC = Mining_height; - sleep(3); - }*/ + fprintf(stderr,"gotinvalid.%d\n",gotinvalid); + if ( gotinvalid != 0 ) + break; komodo_longestchain(); // Hash state KOMODO_CHOSEN_ONE = 0; @@ -1707,7 +1703,7 @@ void static BitcoinMiner() for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&h)[z]); fprintf(stderr," Invalid block mined, try again\n"); - break; + gotinvalid = 1; return(false); } KOMODO_CHOSEN_ONE = 1; From 8706511de79c1fe073f023390f03397562fd7507 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:19:29 -1100 Subject: [PATCH 24/68] Static --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 05d324075..9db051d78 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1604,7 +1604,7 @@ void static BitcoinMiner() fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } - int32_t gotinvalid = 0; + static int32_t gotinvalid = 0; while (true) { fprintf(stderr,"gotinvalid.%d\n",gotinvalid); From c2d4129409d7c1de25d085372392ebb83e26b7c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:36:41 -1100 Subject: [PATCH 25/68] Got invalid as global --- src/miner.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9db051d78..a6ef345bb 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1396,6 +1396,8 @@ void static BitcoinMiner_noeq() miningTimer.stop(); } +int32_t gotinvalid; + #ifdef ENABLE_WALLET void static BitcoinMiner(CWallet *pwallet) #else @@ -1604,7 +1606,7 @@ void static BitcoinMiner() fprintf(stderr," PoW for staked coin PoS %d%% vs target %d%% ht.%d\n",percPoS,(int32_t)ASSETCHAINS_STAKED,Mining_height); } } - static int32_t gotinvalid = 0; + gotinvalid = 0; while (true) { fprintf(stderr,"gotinvalid.%d\n",gotinvalid); From 6bfe8357db2a8d8c2d119b6cb07932d51115e4d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:40:36 -1100 Subject: [PATCH 26/68] -print --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index a6ef345bb..7ffcaebc2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1609,7 +1609,7 @@ void static BitcoinMiner() gotinvalid = 0; while (true) { - fprintf(stderr,"gotinvalid.%d\n",gotinvalid); + //fprintf(stderr,"gotinvalid.%d\n",gotinvalid); if ( gotinvalid != 0 ) break; komodo_longestchain(); From a84a48e48ffcc6d13998b91296949a52fdc1a63f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:43:01 -1100 Subject: [PATCH 27/68] Reset staker for marmara --- 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 c9a91d289..1fe6af409 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2120,7 +2120,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { CBlockIndex* pblockindex = chainActive[tipindex->GetHeight()]; CBlock block; CTxDestination addressout; - if( ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) + if( ASSETCHAINS_MARMARA != 0 || ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) { resetstaker = true; fprintf(stderr, "Reset ram staker after mining a block!\n"); From 7e6d9ff0650c24c7d7a672a83defd934aba2edf5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:43:38 -1100 Subject: [PATCH 28/68] () --- 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 1fe6af409..26f010d1d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2120,7 +2120,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { CBlockIndex* pblockindex = chainActive[tipindex->GetHeight()]; CBlock block; CTxDestination addressout; - if( ASSETCHAINS_MARMARA != 0 || ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) + if( ASSETCHAINS_MARMARA != 0 || (ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0) ) { resetstaker = true; fprintf(stderr, "Reset ram staker after mining a block!\n"); From 8496dc63a4909ff47032ae227830c32284e5c773 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Jan 2019 23:44:38 -1100 Subject: [PATCH 29/68] -print --- src/komodo_bitcoind.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 26f010d1d..c530db4fb 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -2120,7 +2120,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { CBlockIndex* pblockindex = chainActive[tipindex->GetHeight()]; CBlock block; CTxDestination addressout; - if( ASSETCHAINS_MARMARA != 0 || (ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0) ) + if ( ASSETCHAINS_MARMARA != 0 ) + resetstaker = true; + else if( ReadBlockFromDisk(block, pblockindex, 1) && komodo_WhoStaked(&block, addressout) != 0 && IsMine(*pwalletMain,addressout) != 0 ) { resetstaker = true; fprintf(stderr, "Reset ram staker after mining a block!\n"); From 088ea2bfb49f19ab83c8bd5ecc66f138f73d988e Mon Sep 17 00:00:00 2001 From: ca333 Date: Wed, 23 Jan 2019 19:02:05 +0100 Subject: [PATCH 30/68] update cclib to match autotools/libtools naming convention --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 96ab3f1fa..ad9842f09 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -572,7 +572,7 @@ komodod_LDADD += \ $(LIBVERUS_CRYPTO) \ $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ - cclib.so + libcc.so if ENABLE_PROTON komodod_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) From 0d1effd93b42f2dcd8991ecd996a3c10fa410ca7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Jan 2019 22:04:21 -1100 Subject: [PATCH 31/68] Text --- src/sendalert.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sendalert.cpp b/src/sendalert.cpp index 700146338..6525cb356 100644 --- a/src/sendalert.cpp +++ b/src/sendalert.cpp @@ -103,7 +103,7 @@ void ThreadSendAlert() // 4000 or higher will put the RPC into safe mode alert.nPriority = 4000; alert.strComment = ""; - alert.strStatusBar = "Your client version has degraded networking behavior. Please update to the most recent version of Verus (0.3.2 or later)."; + alert.strStatusBar = "Your client version has degraded networking behavior. Please update to the most recent version of Komodo (0.3.3 or later)."; alert.strRPCError = alert.strStatusBar; // Set specific client version/versions here. If setSubVer is empty, no filtering on subver is done: From c3df1b8747750b8ef4a43738be8cfc28f8dffc88 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 24 Jan 2019 17:16:42 +0800 Subject: [PATCH 32/68] add auto purge of orphans from before notarisation. --- src/komodo.h | 2 ++ src/main.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.h | 2 +- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/komodo.h b/src/komodo.h index 4a8bd7d96..62310a0ed 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -707,6 +707,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth); if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); + if (RemoveOrphanedBlocks(*notarizedheightp)) + fprintf(stderr, "Sucessfully removed all known orphaned blocks before height %d\n",*notarizedheightp); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) diff --git a/src/main.cpp b/src/main.cpp index 614f13d44..a2980dea8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1979,6 +1979,72 @@ bool GetAddressUnspent(uint160 addressHash, int type, return true; } +struct CompareBlocksByHeightMain +{ + bool operator()(const CBlockIndex* a, const CBlockIndex* b) const + { + /* Make sure that unequal blocks with the same height do not compare + equal. Use the pointers themselves to make a distinction. */ + + if (a->GetHeight() != b->GetHeight()) + return (a->GetHeight() > b->GetHeight()); + + return a < b; + } +}; + +bool RemoveOrphanedBlocks(int32_t notarized_height) +{ + LOCK(cs_main); + std::vector prunedblocks; + std::set setTips; + int32_t n = 0; + // get notarised timestamp and use this as a backup incase the forked block has no height. + // we -600 to make sure the time is within future block constraints. + uint32_t notarized_timestamp = komodo_heightstamp(notarized_height)-600; + fprintf(stderr, "removing oprhans from before %d\n", notarized_height); + // Most of this code is a direct copy from GetChainTips RPC. Which gives a return of all + // blocks that are not in the main chain. + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + n++; + setTips.insert(item.second); + } + n = 0; + BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) + { + const CBlockIndex* pprev=0; + n++; + if ( item.second != 0 ) + pprev = item.second->pprev; + if (pprev) + setTips.erase(pprev); + } + const CBlockIndex *forked; + BOOST_FOREACH(const CBlockIndex* block, setTips) + { + // We skip anything over notarised height to avoid breaking normal consensus rules. + if ( block->GetHeight() > notarized_height || block->nTime > notarized_timestamp ) + continue; + // We can also check if the block is in the active chain as a backup test. + forked = chainActive.FindFork(block); + // Here we save each forked block to a vector for removal later. + if ( forked != 0 ) + prunedblocks.push_back(block); + } + if (pblocktree->EraseBatchSync(prunedblocks)) + { + // Blocks cleared from disk succesfully, using internal DB batch erase function. Which exists, but has never been used before. + // We need to try and clear the block index from mapBlockIndex now, otherwise node will need a restart. + BOOST_FOREACH(const CBlockIndex* block, prunedblocks) + { + mapBlockIndex.erase(block->GetBlockHash()); + } + return true; + } + return false; +} + /*uint64_t myGettxout(uint256 hash,int32_t n) { CCoins coins; diff --git a/src/main.h b/src/main.h index 463c91237..35c01c23a 100644 --- a/src/main.h +++ b/src/main.h @@ -806,7 +806,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart); bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,bool checkPOW); bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW); - +bool RemoveOrphanedBlocks(int32_t notarized_height); /** Functions for validating blocks and updating the block tree */ From effb3a2a10269cc627c80baf225375cd684f7cc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Jan 2019 22:20:21 -1100 Subject: [PATCH 33/68] Tweak error check --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a2980dea8..1da977ab9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4658,7 +4658,7 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, *futureblockp = 0; if (blockhdr.GetBlockTime() > GetAdjustedTime() + 60) { - CBlockIndex *tipindex; + /*CBlockIndex *tipindex; //fprintf(stderr,"ht.%d future block %u vs time.%u + 60\n",height,(uint32_t)blockhdr.GetBlockTime(),(uint32_t)GetAdjustedTime()); if ( (tipindex= chainActive.Tip()) != 0 && tipindex->GetBlockHash() == blockhdr.hashPrevBlock && blockhdr.GetBlockTime() < GetAdjustedTime() + 60 + 5 ) { @@ -4667,9 +4667,9 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, sleep(1); //fprintf(stderr,"now its valid\n"); } - else + else*/ { - if (blockhdr.GetBlockTime() < GetAdjustedTime() + 600) + if (blockhdr.GetBlockTime() < GetAdjustedTime() + 300) *futureblockp = 1; //LogPrintf("CheckBlockHeader block from future %d error",blockhdr.GetBlockTime() - GetAdjustedTime()); return false; //state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); From 1a9476e844df4d83dfc4c33924333e0ae95bd782 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Jan 2019 22:22:52 -1100 Subject: [PATCH 34/68] +/- prints --- src/komodo.h | 4 +++- src/main.cpp | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 62310a0ed..35fee05ad 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -708,7 +708,9 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr if ( ASSETCHAINS_SYMBOL[0] != 0 ) printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),ASSETCHAINS_SYMBOL[0]==0?"BTC":"KMD",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); if (RemoveOrphanedBlocks(*notarizedheightp)) - fprintf(stderr, "Sucessfully removed all known orphaned blocks before height %d\n",*notarizedheightp); + { + //fprintf(stderr, "Sucessfully removed all known orphaned blocks before height %d\n",*notarizedheightp); + } if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( signedfp == 0 ) diff --git a/src/main.cpp b/src/main.cpp index 1da977ab9..be2317891 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1998,12 +1998,11 @@ bool RemoveOrphanedBlocks(int32_t notarized_height) LOCK(cs_main); std::vector prunedblocks; std::set setTips; - int32_t n = 0; + int32_t m=0,n = 0; // get notarised timestamp and use this as a backup incase the forked block has no height. // we -600 to make sure the time is within future block constraints. uint32_t notarized_timestamp = komodo_heightstamp(notarized_height)-600; - fprintf(stderr, "removing oprhans from before %d\n", notarized_height); - // Most of this code is a direct copy from GetChainTips RPC. Which gives a return of all + // Most of this code is a direct copy from GetChainTips RPC. Which gives a return of all // blocks that are not in the main chain. BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex) { @@ -2038,8 +2037,10 @@ bool RemoveOrphanedBlocks(int32_t notarized_height) // We need to try and clear the block index from mapBlockIndex now, otherwise node will need a restart. BOOST_FOREACH(const CBlockIndex* block, prunedblocks) { + m++; mapBlockIndex.erase(block->GetBlockHash()); } + fprintf(stderr, "%s removed %d of %d orphans from before %d\n",ASSETCHAINS_SYMBOL,m,n, notarized_height); return true; } return false; From 2a36abaf5d0a50ad612a04ac7fab2f248a54e7e4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Jan 2019 22:51:10 -1100 Subject: [PATCH 35/68] skip Zero pruned blocks --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index be2317891..4bd7ed3e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2031,7 +2031,7 @@ bool RemoveOrphanedBlocks(int32_t notarized_height) if ( forked != 0 ) prunedblocks.push_back(block); } - if (pblocktree->EraseBatchSync(prunedblocks)) + if (prunedblocks.size() > 0 && pblocktree->EraseBatchSync(prunedblocks)) { // Blocks cleared from disk succesfully, using internal DB batch erase function. Which exists, but has never been used before. // We need to try and clear the block index from mapBlockIndex now, otherwise node will need a restart. @@ -2040,7 +2040,7 @@ bool RemoveOrphanedBlocks(int32_t notarized_height) m++; mapBlockIndex.erase(block->GetBlockHash()); } - fprintf(stderr, "%s removed %d of %d orphans from before %d\n",ASSETCHAINS_SYMBOL,m,n, notarized_height); + fprintf(stderr, "%s removed %d orphans from %d blocks before %d\n",ASSETCHAINS_SYMBOL,m,n, notarized_height); return true; } return false; From d192f1d1f35db442f7a747288a51db671fd34701 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 23 Jan 2019 23:46:45 -1100 Subject: [PATCH 36/68] Rawtx->hex for marmara --- src/cc/marmara.cpp | 12 ++++++------ src/main.cpp | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cc/marmara.cpp b/src/cc/marmara.cpp index 8f8de12e2..0e301ba97 100644 --- a/src/cc/marmara.cpp +++ b/src/cc/marmara.cpp @@ -496,7 +496,7 @@ UniValue MarmaraLock(uint64_t txfee,int64_t amount,int32_t height) else { result.push_back(Pair("result",(char *)"success")); - result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("hex",rawtx)); return(result); } } else errorstr = (char *)"insufficient funds"; @@ -600,7 +600,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) mtx.vout.push_back(MakeCC1of2vout(EVAL_MARMARA,change,Marmarapk,pk)); rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('S',createtxid,mypk,0,refmatures,currency),pubkeys); result.push_back(Pair("result",(char *)"success")); - result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("hex",rawtx)); return(result); } else remaining -= inputsum; if ( mtx.vin.size() >= CC_MAXVINS - MARMARA_VINS ) @@ -616,7 +616,7 @@ UniValue MarmaraSettlement(uint64_t txfee,uint256 refbatontxid) rawtx = FinalizeCCTx(0,cp,mtx,mypk,txfee,MarmaraLoopOpret('D',createtxid,mypk,-remaining,refmatures,currency),pubkeys); result.push_back(Pair("result",(char *)"error")); result.push_back(Pair("error",(char *)"insufficient funds")); - result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("hex",rawtx)); result.push_back(Pair("remaining",ValueFromAmount(remaining))); } else @@ -731,7 +731,7 @@ UniValue MarmaraReceive(uint64_t txfee,CPubKey senderpk,int64_t amount,std::stri else { result.push_back(Pair("result",(char *)"success")); - result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("hex",rawtx)); result.push_back(Pair("funcid","R")); result.push_back(Pair("createtxid",createtxid.GetHex())); if ( batontxid != zeroid ) @@ -787,7 +787,7 @@ UniValue MarmaraIssue(uint64_t txfee,uint8_t funcid,CPubKey receiverpk,int64_t a else { result.push_back(Pair("result",(char *)"success")); - result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("hex",rawtx)); char str[2]; str[0] = funcid, str[1] = 0; result.push_back(Pair("funcid",str)); result.push_back(Pair("createtxid",createtxid.GetHex())); @@ -1025,7 +1025,7 @@ UniValue MarmaraPoolPayout(uint64_t txfee,int32_t firstheight,double perc,char * else { result.push_back(Pair("result",(char *)"success")); - result.push_back(Pair("rawtx",rawtx)); + result.push_back(Pair("hex",rawtx)); if ( totalpayout > 0 && total > totalpayout-txfee ) { result.push_back(Pair("firstheight",firstheight)); diff --git a/src/main.cpp b/src/main.cpp index 4bd7ed3e3..b4f0acef0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5662,7 +5662,6 @@ bool static LoadBlockIndexDB() if (pindex->nStatus & BLOCK_HAVE_DATA) { setBlkDataFiles.insert(pindex->nFile); } - //komodo_pindex_init(pindex,(int32_t)pindex->GetHeight()); } //fprintf(stderr,"load blockindexDB %u\n",(uint32_t)time(NULL)); for (std::set::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++) From 0f6ee83311bad26912256c7e6b9080d66c5a9b05 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 01:44:20 -1100 Subject: [PATCH 37/68] Tmp files --- src/chain.h | 1 + src/main.cpp | 79 +++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/chain.h b/src/chain.h index 49b206480..45db77720 100644 --- a/src/chain.h +++ b/src/chain.h @@ -115,6 +115,7 @@ enum BlockStatus: uint32_t { BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD, BLOCK_ACTIVATES_UPGRADE = 128, //! block activates a network upgrade + BLOCK_IN_TMPFILE = 256 }; //! Short-hand for the highest consensus validity we implement. diff --git a/src/main.cpp b/src/main.cpp index b4f0acef0..29096308b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,6 +76,7 @@ using namespace std; * Global state */ +#define TMPFILE_START 100000000 CCriticalSection cs_main; extern uint8_t NOTARY_PUBKEY33[33]; extern int32_t KOMODO_LOADINGBLOCKS,KOMODO_LONGESTCHAIN,KOMODO_INSYNC,KOMODO_CONNECTING,KOMODO_EXTRASATOSHI; @@ -182,8 +183,9 @@ namespace { multimap mapBlocksUnlinked; CCriticalSection cs_LastBlockFile; - std::vector vinfoBlockFile; + std::vector vinfoBlockFile,tmpBlockFiles; int nLastBlockFile = 0; + int nLastTmpFile = 0; /** Global flag to indicate we should check to see if there are * block/undo files that should be deleted. Set on startup * or if we allocate more file space when we're in prune mode @@ -3256,6 +3258,17 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return false; fprintf(stderr,"grandfathered exception, until jan 15th 2019\n"); } + if ( (pindex->nStatus & BLOCK_IN_TMPFILE) != 0 ) + { + unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); + CDiskBlockPos blockPos; + if (!FindBlockPos(1,state, blockPos, nBlockSize+8, pindex->GetHeight(), block.GetBlockTime(),false)) + return error("ConnectBlock(): FindBlockPos failed"); + if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) + return error("ConnectBlock(): FindBlockPos failed"); + pindex->nStatus &= (~BLOCK_IN_TMPFILE); + fprintf(stderr,"added ht.%d copy of tmpfile\n",pindex->GetHeight()); + } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); if ( hashPrevBlock != view.GetBestBlock() ) @@ -4550,43 +4563,57 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl return true; } -bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) +bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) { + std::vector *ptr; int *lastfilep; LOCK(cs_LastBlockFile); - unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile; - if (vinfoBlockFile.size() <= nFile) { - vinfoBlockFile.resize(nFile + 1); + unsigned int nFile; + if ( tmpflag != 0 ) + { + ptr = &tmpBlockFiles; + nFile = nLastTmpFile; + lastfilep = &nLastTmpFile; + } + else + { + ptr = &vinfoBlockFile; + lastfilep = &nLastBlockFile; + nFile = fKnown ? pos.nFile : nLastBlockFile; + if (vinfoBlockFile.size() <= nFile) { + vinfoBlockFile.resize(nFile + 1); + } } - if (!fKnown) { - while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) { + while ((*ptr)[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) { nFile++; - if (vinfoBlockFile.size() <= nFile) { - vinfoBlockFile.resize(nFile + 1); + if ((*ptr).size() <= nFile) { + (*ptr).resize(nFile + 1); } } - pos.nFile = nFile; - pos.nPos = vinfoBlockFile[nFile].nSize; + pos.nFile = nFile + tmpflag*TMPFILE_START; + pos.nPos = (*ptr)[nFile].nSize; + if ( tmpflag != 0 ) + fprintf(stderr,"pos.nFile %d nPos %u\n",pos.nFile,pos.nPos); } - if (nFile != nLastBlockFile) { + if (nFile != *lastfilep) { if (!fKnown) { - LogPrintf("Leaving block file %i: %s\n", nFile, vinfoBlockFile[nFile].ToString()); + LogPrintf("Leaving block file %i: %s\n", nFile, (*ptr)[nFile].ToString()); } FlushBlockFile(!fKnown); - nLastBlockFile = nFile; + *lastfilep = nFile; } - vinfoBlockFile[nFile].AddBlock(nHeight, nTime); + (*ptr)[nFile].AddBlock(nHeight, nTime); if (fKnown) - vinfoBlockFile[nFile].nSize = std::max(pos.nPos + nAddSize, vinfoBlockFile[nFile].nSize); + (*ptr)[nFile].nSize = std::max(pos.nPos + nAddSize, (*ptr)[nFile].nSize); else - vinfoBlockFile[nFile].nSize += nAddSize; + (*ptr)[nFile].nSize += nAddSize; if (!fKnown) { unsigned int nOldChunks = (pos.nPos + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; - unsigned int nNewChunks = (vinfoBlockFile[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; + unsigned int nNewChunks = ((*ptr)[nFile].nSize + BLOCKFILE_CHUNK_SIZE - 1) / BLOCKFILE_CHUNK_SIZE; if (nNewChunks > nOldChunks) { if (fPruneMode) fCheckForPruning = true; @@ -4603,12 +4630,17 @@ bool FindBlockPos(CValidationState &state, CDiskBlockPos &pos, unsigned int nAdd } } - setDirtyFileInfo.insert(nFile); + setDirtyFileInfo.insert(nFile + tmpflag*TMPFILE_START); return true; } bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize) { + if ( nFile >= TMPFILE_START ) + { + fprintf(stderr,"FindUndoPos unexpected tmpfile %d\n",nFile); + return(false); + } pos.nFile = nFile; LOCK(cs_LastBlockFile); @@ -5171,13 +5203,14 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C CDiskBlockPos blockPos; if (dbp != NULL) blockPos = *dbp; - if (!FindBlockPos(state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL)) + if (!FindBlockPos(1,state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL)) return error("AcceptBlock(): FindBlockPos failed"); if (dbp == NULL) if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) AbortNode(state, "Failed to write block"); if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock(): ReceivedBlockTransactions failed"); + pindex->nStatus |= BLOCK_IN_TMPFILE; } catch (const std::runtime_error& e) { return AbortNode(state, std::string("System error: ") + e.what()); } @@ -5495,7 +5528,7 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes) FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly) { - static int32_t didinit[64]; + static int32_t didinit[256]; if (pos.IsNull()) return NULL; boost::filesystem::path path = GetBlockPosFilename(pos, prefix); @@ -6002,6 +6035,7 @@ void UnloadBlockIndex() nSyncStarted = 0; mapBlocksUnlinked.clear(); vinfoBlockFile.clear(); + tmpBlockFiles.clear(); nLastBlockFile = 0; nBlockSequenceId = 1; mapBlockSource.clear(); @@ -6037,6 +6071,7 @@ bool LoadBlockIndex() bool InitBlockIndex() { const CChainParams& chainparams = Params(); LOCK(cs_main); + tmpBlockFiles.clear(); // Initialize global variables that cannot be constructed at startup. recentRejects.reset(new CRollingBloomFilter(120000, 0.000001)); @@ -6069,7 +6104,7 @@ bool InitBlockIndex() { unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); CDiskBlockPos blockPos; CValidationState state; - if (!FindBlockPos(state, blockPos, nBlockSize+8, 0, block.GetBlockTime())) + if (!FindBlockPos(0,state, blockPos, nBlockSize+8, 0, block.GetBlockTime())) return error("LoadBlockIndex(): FindBlockPos failed"); if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) return error("LoadBlockIndex(): writing genesis block to disk failed"); From 82bc38fabf051317f9b1b6ca230c5ffa3cdb4e4e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 01:51:33 -1100 Subject: [PATCH 38/68] Syntax --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 29096308b..9d4e1f243 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3226,6 +3226,7 @@ static int64_t nTimeConnect = 0; static int64_t nTimeIndex = 0; static int64_t nTimeCallbacks = 0; static int64_t nTimeTotal = 0; +bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false); bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { @@ -3264,7 +3265,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin CDiskBlockPos blockPos; if (!FindBlockPos(1,state, blockPos, nBlockSize+8, pindex->GetHeight(), block.GetBlockTime(),false)) return error("ConnectBlock(): FindBlockPos failed"); - if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) + if (!WriteBlockToDisk((CBlock)block, blockPos, chainparams.MessageStart())) return error("ConnectBlock(): FindBlockPos failed"); pindex->nStatus &= (~BLOCK_IN_TMPFILE); fprintf(stderr,"added ht.%d copy of tmpfile\n",pindex->GetHeight()); From 669f5c4d391f112dc1c549703c8297547196f31d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 01:55:15 -1100 Subject: [PATCH 39/68] Const --- src/main.cpp | 4 ++-- src/main.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9d4e1f243..43cca5266 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2195,7 +2195,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock // CBlock and CBlockIndex // -bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart) +bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart) { // Open history file to append CAutoFile fileout(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION); @@ -3265,7 +3265,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin CDiskBlockPos blockPos; if (!FindBlockPos(1,state, blockPos, nBlockSize+8, pindex->GetHeight(), block.GetBlockTime(),false)) return error("ConnectBlock(): FindBlockPos failed"); - if (!WriteBlockToDisk((CBlock)block, blockPos, chainparams.MessageStart())) + if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) return error("ConnectBlock(): FindBlockPos failed"); pindex->nStatus &= (~BLOCK_IN_TMPFILE); fprintf(stderr,"added ht.%d copy of tmpfile\n",pindex->GetHeight()); diff --git a/src/main.h b/src/main.h index 35c01c23a..40170fa70 100644 --- a/src/main.h +++ b/src/main.h @@ -803,7 +803,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, std::vector > &unspentOutputs); /** Functions for disk access for blocks */ -bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart); +bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart); bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,bool checkPOW); bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW); bool RemoveOrphanedBlocks(int32_t notarized_height); From 3c1e3aede1cfd767d6c7d6f25f328600de3e88c4 Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Thu, 24 Jan 2019 19:55:55 +0700 Subject: [PATCH 40/68] initial heir tests --- qa/pull-tester/cc-tests.sh | 1 + qa/rpc-tests/cryptoconditions_heir.py | 121 ++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100755 qa/rpc-tests/cryptoconditions_heir.py diff --git a/qa/pull-tester/cc-tests.sh b/qa/pull-tester/cc-tests.sh index 9bc8c155d..742763f1d 100755 --- a/qa/pull-tester/cc-tests.sh +++ b/qa/pull-tester/cc-tests.sh @@ -18,6 +18,7 @@ testScripts=( 'cryptoconditions_rewards.py' 'cryptoconditions_token.py' #'cryptoconditions_gateways.py' + 'cryptoconditions_hair.py' # TODO: cant reconnect nodes back in channels test because of crash (seems regtest only specific) 'cryptoconditions_channels.py' ); diff --git a/qa/rpc-tests/cryptoconditions_heir.py b/qa/rpc-tests/cryptoconditions_heir.py new file mode 100755 index 000000000..95b90b397 --- /dev/null +++ b/qa/rpc-tests/cryptoconditions_heir.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python2 +# Copyright (c) 2018 SuperNET developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +import time +from test_framework.test_framework import CryptoconditionsTestFramework +from test_framework.authproxy import JSONRPCException +from test_framework.util import assert_equal, assert_greater_than, \ + initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ + stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises +from cryptoconditions import assert_success, assert_error, generate_random_string + + +class CryptoconditionsHeirTest(CryptoconditionsTestFramework): + + def run_heir_tests(self): + + rpc = self.nodes[0] + rpc1 = self.nodes[1] + + result = rpc.heiraddress() + assert_success(result) + # verify all keys look like valid AC addrs, could be better + for x in ['myCCaddress', 'HeirCCaddress', 'Heirmarker', 'myaddress']: + assert_equal(result[x][0], 'R') + + result = rpc.heiraddress(self.pubkey) + assert_success(result) + # test that additional CCaddress key is returned + for x in ['myCCaddress', 'HeirCCaddress', 'Heirmarker', 'myaddress', 'CCaddress']: + assert_equal(result[x][0], 'R') + + # getting empty heir list + result = rpc.heirlist() + assert_equal(len(result), 1) + assert_success(result) + + # valid heirfund case with coins + result = rpc.heirfund("0", "1000", "UNITHEIR", self.pubkey1, "10") + assert_success(result) + + heir_fund_txid = self.send_and_mine(result["hextx"], rpc) + assert heir_fund_txid, "got heir funding txid" + + # heir fund txid should be in heirlist now + result = rpc.heirlist() + assert_equal(len(result), 2) + assert_success(result) + assert_equal(result["fundingtxid"], heir_fund_txid) + + # checking heirinfo + result = rpc.heirinfo(heir_fund_txid) + assert_success(result) + assert_equal(result["fundingtxid"], heir_fund_txid) + assert_equal(result["name"], "UNITHEIR") + assert_equal(result["owner"], self.pubkey) + assert_equal(result["heir"], self.pubkey1) + assert_equal(result["funding total in coins"], "1000.00000000") + assert_equal(result["funding available in coins"], "1000.00000000") + assert_equal(result["inactivity time setting, sec"], "10") + assert_equal(result["spending allowed for the heir"], "false") + + # TODO: heirlist keys are duplicating now + + # waiting for 11 seconds to be sure that needed time passed for heir claiming + time.sleep(11) + rpc.generate(1) + self.sync_all() + result = rpc.heirinfo(heir_fund_txid) + assert_equal(result["funding available in coins"], "1000.00000000") + assert_equal(result["spending allowed for the heir"], "true") + + # have to check that second node have coins to cover txfee at least + rpc.sendtoaddress(rpc1.getnewaddress(), 1) + rpc.sendtoaddress(rpc1.getnewaddress(), 1) + rpc.generate(2) + self.sync_all() + second_node_balance = rpc1.getbalance() + assert_greater_than(second_node_balance, 0.1) + + # let's claim whole heir sum from second node + result = rpc1.heirclaim("0", "1000", heir_fund_txid) + assert_success(result) + + heir_claim_txid = self.send_and_mine(result["hextx"], rpc1) + assert heir_claim_txid, "got claim txid" + + # balance of second node after heirclaim should increase for 1000 coins - txfees + # + get one block reward when broadcasted heir_claim_txid + result = round(rpc1.getbalance()) - round(second_node_balance) + assert_greater_than(result, 100999) + + self.sync_all() + + # no more funds should be available for claiming + result = rpc.heirinfo(heir_fund_txid) + assert_equal(result["funding available in coins"], "0.00000000") + + # TODO: valid heirfund case with tokens + + def run_test(self): + print("Mining blocks...") + rpc = self.nodes[0] + rpc1 = self.nodes[1] + # utxos from block 1 become mature in block 101 + if not self.options.noshutdown: + rpc.generate(101) + self.sync_all() + rpc.getinfo() + rpc1.getinfo() + # this corresponds to -pubkey above + print("Importing privkeys") + rpc.importprivkey(self.privkey) + rpc1.importprivkey(self.privkey1) + self.run_heir_tests() + + +if __name__ == '__main__': + CryptoconditionsHeirTest().main() From 9f663ad841dc2f3cde6bdf8465b370df8df23b8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:00:37 -1100 Subject: [PATCH 41/68] Remove fKnown = false --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 43cca5266..cef3e29ab 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4564,7 +4564,7 @@ bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBl return true; } -bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false) +bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown) { std::vector *ptr; int *lastfilep; LOCK(cs_LastBlockFile); From 87a12db2d1e667f66ea78490c823e8c72f23046b Mon Sep 17 00:00:00 2001 From: Anton Lysakov Date: Thu, 24 Jan 2019 20:11:42 +0700 Subject: [PATCH 42/68] Omg --- qa/pull-tester/cc-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/pull-tester/cc-tests.sh b/qa/pull-tester/cc-tests.sh index 742763f1d..d68671e12 100755 --- a/qa/pull-tester/cc-tests.sh +++ b/qa/pull-tester/cc-tests.sh @@ -18,7 +18,7 @@ testScripts=( 'cryptoconditions_rewards.py' 'cryptoconditions_token.py' #'cryptoconditions_gateways.py' - 'cryptoconditions_hair.py' + 'cryptoconditions_heir.py' # TODO: cant reconnect nodes back in channels test because of crash (seems regtest only specific) 'cryptoconditions_channels.py' ); From 2367a5cc0b78880dbdbec6f4b5e3e0a6c1f7c840 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:14:31 -1100 Subject: [PATCH 43/68] Create first entry for tmpBlockfiles --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index cef3e29ab..73f910d10 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5673,6 +5673,7 @@ bool static LoadBlockIndexDB() // Load block file info pblocktree->ReadLastBlockFile(nLastBlockFile); vinfoBlockFile.resize(nLastBlockFile + 1); + tmpBlockFiles.resize(nLastTmpFile + 1); LogPrintf("%s: last block file = %i\n", __func__, nLastBlockFile); for (int nFile = 0; nFile <= nLastBlockFile; nFile++) { pblocktree->ReadBlockFileInfo(nFile, vinfoBlockFile[nFile]); From 420158a628c9c23be84487e6ae3d6514bf71004d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:29:23 -1100 Subject: [PATCH 44/68] Undo for tmp files --- src/main.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 73f910d10..fe1503434 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4637,18 +4637,18 @@ bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, u bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigned int nAddSize) { + std::vector *ptr; int *lastfilep; + LOCK(cs_LastBlockFile); if ( nFile >= TMPFILE_START ) { - fprintf(stderr,"FindUndoPos unexpected tmpfile %d\n",nFile); - return(false); - } + nFile %= TMPFILE_START; + ptr = &tmpBlockFiles; + } else ptr = &vinfoBlockFile; + pos.nFile = nFile; - - LOCK(cs_LastBlockFile); - unsigned int nNewSize; - pos.nPos = vinfoBlockFile[nFile].nUndoSize; - nNewSize = vinfoBlockFile[nFile].nUndoSize += nAddSize; + pos.nPos = (*ptr)[nFile].nUndoSize; + nNewSize = (*ptr)[nFile].nUndoSize += nAddSize; setDirtyFileInfo.insert(nFile); unsigned int nOldChunks = (pos.nPos + UNDOFILE_CHUNK_SIZE - 1) / UNDOFILE_CHUNK_SIZE; From 05371f93bd144fd85dffc622443b364388ca7196 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:30:39 -1100 Subject: [PATCH 45/68] +print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index fe1503434..d10166ab3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3268,7 +3268,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) return error("ConnectBlock(): FindBlockPos failed"); pindex->nStatus &= (~BLOCK_IN_TMPFILE); - fprintf(stderr,"added ht.%d copy of tmpfile\n",pindex->GetHeight()); + fprintf(stderr,"added ht.%d copy of tmpfile to %d.%d\n",pindex->GetHeight(),blockPos.nFile,blockPos.nPos); } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); From 86ee8f65502f3d039fa7165c97a383d47f3b7bec Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:33:21 -1100 Subject: [PATCH 46/68] Switch to main file from temp files --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d10166ab3..cc37ba316 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3263,7 +3263,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin { unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); CDiskBlockPos blockPos; - if (!FindBlockPos(1,state, blockPos, nBlockSize+8, pindex->GetHeight(), block.GetBlockTime(),false)) + if (!FindBlockPos(0,state, blockPos, nBlockSize+8, pindex->GetHeight(), block.GetBlockTime(),false)) return error("ConnectBlock(): FindBlockPos failed"); if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) return error("ConnectBlock(): FindBlockPos failed"); From f9e2487fdde647734b8417319f5fe05d1d6a1a0f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:37:35 -1100 Subject: [PATCH 47/68] Mark new file as dirty --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cc37ba316..f243cef8e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3268,7 +3268,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) return error("ConnectBlock(): FindBlockPos failed"); pindex->nStatus &= (~BLOCK_IN_TMPFILE); - fprintf(stderr,"added ht.%d copy of tmpfile to %d.%d\n",pindex->GetHeight(),blockPos.nFile,blockPos.nPos); + setDirtyFileInfo.insert(blockPos.nFile); + //fprintf(stderr,"added ht.%d copy of tmpfile to %d.%d\n",pindex->GetHeight(),blockPos.nFile,blockPos.nPos); } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); @@ -4594,7 +4595,7 @@ bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, u } pos.nFile = nFile + tmpflag*TMPFILE_START; pos.nPos = (*ptr)[nFile].nSize; - if ( tmpflag != 0 ) + if ( 0 && tmpflag != 0 ) fprintf(stderr,"pos.nFile %d nPos %u\n",pos.nFile,pos.nPos); } From b963af2269d4d0ee20305bff25aa29a6981bc8e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:41:08 -1100 Subject: [PATCH 48/68] Tmp undo file --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f243cef8e..3d5128de2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4640,13 +4640,13 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne { std::vector *ptr; int *lastfilep; LOCK(cs_LastBlockFile); + pos.nFile = nFile; if ( nFile >= TMPFILE_START ) { nFile %= TMPFILE_START; ptr = &tmpBlockFiles; } else ptr = &vinfoBlockFile; - pos.nFile = nFile; unsigned int nNewSize; pos.nPos = (*ptr)[nFile].nUndoSize; nNewSize = (*ptr)[nFile].nUndoSize += nAddSize; From 4c4c50cbd7bb543631045b6da911d19b47b0aa35 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:01:02 -1100 Subject: [PATCH 49/68] Receive transactions --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3d5128de2..945243351 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3230,6 +3230,7 @@ bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, u bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { + CDiskBlockPos blockPos; const CChainParams& chainparams = Params(); if ( KOMODO_STOPAT != 0 && pindex->GetHeight() > KOMODO_STOPAT ) return(false); @@ -3262,12 +3263,15 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if ( (pindex->nStatus & BLOCK_IN_TMPFILE) != 0 ) { unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); - CDiskBlockPos blockPos; if (!FindBlockPos(0,state, blockPos, nBlockSize+8, pindex->GetHeight(), block.GetBlockTime(),false)) return error("ConnectBlock(): FindBlockPos failed"); if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) return error("ConnectBlock(): FindBlockPos failed"); pindex->nStatus &= (~BLOCK_IN_TMPFILE); + pindex->nFile = blockPos.nFile; + pindex->nPos = blockPos.nPos; + if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) + return error("AcceptBlock(): ReceivedBlockTransactions failed"); setDirtyFileInfo.insert(blockPos.nFile); //fprintf(stderr,"added ht.%d copy of tmpfile to %d.%d\n",pindex->GetHeight(),blockPos.nFile,blockPos.nPos); } From f44e95a3f585169c01c833744db4cb7f68c9d640 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:02:21 -1100 Subject: [PATCH 50/68] nDataPos --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 945243351..850aa1c1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3269,7 +3269,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return error("ConnectBlock(): FindBlockPos failed"); pindex->nStatus &= (~BLOCK_IN_TMPFILE); pindex->nFile = blockPos.nFile; - pindex->nPos = blockPos.nPos; + pindex->nDataPos = blockPos.nPos; if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock(): ReceivedBlockTransactions failed"); setDirtyFileInfo.insert(blockPos.nFile); From eda67fa9d67d514587afa84680ef6d5922c1f840 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:04:10 -1100 Subject: [PATCH 51/68] bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos) --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 850aa1c1b..91d90aa14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3227,6 +3227,7 @@ static int64_t nTimeIndex = 0; static int64_t nTimeCallbacks = 0; static int64_t nTimeTotal = 0; bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false); +bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos); bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { From df9d2ddc97eb80b7b3442eac7c4c91faf092b8cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:11:31 -1100 Subject: [PATCH 52/68] Test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 91d90aa14..bfb1a0535 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4648,6 +4648,8 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne pos.nFile = nFile; if ( nFile >= TMPFILE_START ) { + fprintf(stderr,"skip tmp undo\n"); + return(false); nFile %= TMPFILE_START; ptr = &tmpBlockFiles; } else ptr = &vinfoBlockFile; From f5ad6948fcb2690df7ca03c0872b0160b095df51 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:28:26 -1100 Subject: [PATCH 53/68] -recvtx --- src/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bfb1a0535..71c04aa56 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3274,7 +3274,8 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock(): ReceivedBlockTransactions failed"); setDirtyFileInfo.insert(blockPos.nFile); - //fprintf(stderr,"added ht.%d copy of tmpfile to %d.%d\n",pindex->GetHeight(),blockPos.nFile,blockPos.nPos); + FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files + fprintf(stderr,"added ht.%d copy of tmpfile to %d.%d\n",pindex->GetHeight(),blockPos.nFile,blockPos.nPos); } // verify that the view's current state corresponds to the previous block uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash(); @@ -5217,8 +5218,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if (dbp == NULL) if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) AbortNode(state, "Failed to write block"); - if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) - return error("AcceptBlock(): ReceivedBlockTransactions failed"); + //if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) + // return error("AcceptBlock(): ReceivedBlockTransactions failed"); pindex->nStatus |= BLOCK_IN_TMPFILE; } catch (const std::runtime_error& e) { return AbortNode(state, std::string("System error: ") + e.what()); From d8611d936de13c7832efced30870a062b5fa3660 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:30:17 -1100 Subject: [PATCH 54/68] FlushStateMode --- src/main.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 71c04aa56..45ec46b45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3229,6 +3229,14 @@ static int64_t nTimeTotal = 0; bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false); bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos); + +enum FlushStateMode { + FLUSH_STATE_NONE, + FLUSH_STATE_IF_NEEDED, + FLUSH_STATE_PERIODIC, + FLUSH_STATE_ALWAYS +}; + bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { CDiskBlockPos blockPos; @@ -3670,12 +3678,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return true; } -enum FlushStateMode { - FLUSH_STATE_NONE, - FLUSH_STATE_IF_NEEDED, - FLUSH_STATE_PERIODIC, - FLUSH_STATE_ALWAYS -}; /** * Update the on-disk chain state. From 10b7fff5bc24b0dc820380044f2feef73f14ec73 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:32:22 -1100 Subject: [PATCH 55/68] Static --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 45ec46b45..4bd49b557 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3236,6 +3236,7 @@ enum FlushStateMode { FLUSH_STATE_PERIODIC, FLUSH_STATE_ALWAYS }; +bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode); bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { From d797bce94d35b61b108029a7d26ff0e41307f680 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:34:10 -1100 Subject: [PATCH 56/68] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 4bd49b557..e9af9231f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5221,8 +5221,8 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C if (dbp == NULL) if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) AbortNode(state, "Failed to write block"); - //if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) - // return error("AcceptBlock(): ReceivedBlockTransactions failed"); + if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) + return error("AcceptBlock(): ReceivedBlockTransactions failed"); pindex->nStatus |= BLOCK_IN_TMPFILE; } catch (const std::runtime_error& e) { return AbortNode(state, std::string("System error: ") + e.what()); From d682dfd830f92659512847ed70bf793779c5b09c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 03:42:27 -1100 Subject: [PATCH 57/68] +print --- src/main.cpp | 16 ++++++---------- src/txdb.cpp | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e9af9231f..0198c046d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3229,15 +3229,6 @@ static int64_t nTimeTotal = 0; bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false); bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos); - -enum FlushStateMode { - FLUSH_STATE_NONE, - FLUSH_STATE_IF_NEEDED, - FLUSH_STATE_PERIODIC, - FLUSH_STATE_ALWAYS -}; -bool static FlushStateToDisk(CValidationState &state, FlushStateMode mode); - bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { CDiskBlockPos blockPos; @@ -3283,7 +3274,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock(): ReceivedBlockTransactions failed"); setDirtyFileInfo.insert(blockPos.nFile); - FlushStateToDisk(state, FLUSH_STATE_NONE); // we just allocated more disk space for block files fprintf(stderr,"added ht.%d copy of tmpfile to %d.%d\n",pindex->GetHeight(),blockPos.nFile,blockPos.nPos); } // verify that the view's current state corresponds to the previous block @@ -3679,6 +3669,12 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return true; } +enum FlushStateMode { + FLUSH_STATE_NONE, + FLUSH_STATE_IF_NEEDED, + FLUSH_STATE_PERIODIC, + FLUSH_STATE_ALWAYS +}; /** * Update the on-disk chain state. diff --git a/src/txdb.cpp b/src/txdb.cpp index 164167c29..4d84b1cd2 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -686,7 +686,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() pindexNew->nTx = diskindex.nTx; pindexNew->nSproutValue = diskindex.nSproutValue; pindexNew->nSaplingValue = diskindex.nSaplingValue; - +fprintf(stderr,"loadguts ht.%d\n",pindexNew->GetHeight()); // Consistency checks auto header = pindexNew->GetBlockHeader(); if (header.GetHash() != pindexNew->GetBlockHash()) From ed73fd8423d455775f2b429f707011bae0caf830 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 04:16:01 -1100 Subject: [PATCH 58/68] Undo tmpfile --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0198c046d..adf445255 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5212,14 +5212,14 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C CDiskBlockPos blockPos; if (dbp != NULL) blockPos = *dbp; - if (!FindBlockPos(1,state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL)) + if (!FindBlockPos(0,state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL)) return error("AcceptBlock(): FindBlockPos failed"); if (dbp == NULL) if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) AbortNode(state, "Failed to write block"); if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock(): ReceivedBlockTransactions failed"); - pindex->nStatus |= BLOCK_IN_TMPFILE; + //pindex->nStatus |= BLOCK_IN_TMPFILE; } catch (const std::runtime_error& e) { return AbortNode(state, std::string("System error: ") + e.what()); } From 1b53f34527a7cdeb986c7a26790e91781367fcae Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 04:18:54 -1100 Subject: [PATCH 59/68] Use tmp --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index adf445255..344224902 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5206,20 +5206,22 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C } int nHeight = pindex->GetHeight(); + int32_t usetmp = 0; // Write block to history file try { unsigned int nBlockSize = ::GetSerializeSize(block, SER_DISK, CLIENT_VERSION); CDiskBlockPos blockPos; if (dbp != NULL) blockPos = *dbp; - if (!FindBlockPos(0,state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL)) + if (!FindBlockPos(usetmp,state, blockPos, nBlockSize+8, nHeight, block.GetBlockTime(), dbp != NULL)) return error("AcceptBlock(): FindBlockPos failed"); if (dbp == NULL) if (!WriteBlockToDisk(block, blockPos, chainparams.MessageStart())) AbortNode(state, "Failed to write block"); if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock(): ReceivedBlockTransactions failed"); - //pindex->nStatus |= BLOCK_IN_TMPFILE; + if ( usetmp != 0 ) + pindex->nStatus |= BLOCK_IN_TMPFILE; } catch (const std::runtime_error& e) { return AbortNode(state, std::string("System error: ") + e.what()); } From b4a9c7e5043b9b857c93146dfed55e9f07a52f7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 00:57:40 -1100 Subject: [PATCH 60/68] Init nonz --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 289a84d7c..3701f5257 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1654,7 +1654,7 @@ extern int64_t MAX_MONEY; void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; uint64_t ccenables[256]; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); memset(ccenables,0,sizeof(ccenables)); memset(disablebits,0,sizeof(disablebits)); From 9dda24f9134a506c55cffb113ba4935be70f05f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 01:23:36 -1100 Subject: [PATCH 61/68] set nonz = 0 --- src/komodo_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_utils.h b/src/komodo_utils.h index 289a84d7c..3701f5257 100644 --- a/src/komodo_utils.h +++ b/src/komodo_utils.h @@ -1654,7 +1654,7 @@ extern int64_t MAX_MONEY; void komodo_args(char *argv0) { extern const char *Notaries_elected1[][2]; - std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz,baseid,len,n,extralen = 0; uint64_t ccenables[256]; + std::string name,addn; char *dirname,fname[512],arg0str[64],magicstr[9]; uint8_t magic[4],extrabuf[8192],disablebits[32],*extraptr=0; FILE *fp; uint64_t val; uint16_t port; int32_t i,nonz=0,baseid,len,n,extralen = 0; uint64_t ccenables[256]; IS_KOMODO_NOTARY = GetBoolArg("-notary", false); memset(ccenables,0,sizeof(ccenables)); memset(disablebits,0,sizeof(disablebits)); From 07a05ccd6b65afcf01e4683d06996e599a9864e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 01:27:55 -1100 Subject: [PATCH 62/68] -print --- src/txdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index 4d84b1cd2..c86ee9bfa 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -686,7 +686,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts() pindexNew->nTx = diskindex.nTx; pindexNew->nSproutValue = diskindex.nSproutValue; pindexNew->nSaplingValue = diskindex.nSaplingValue; -fprintf(stderr,"loadguts ht.%d\n",pindexNew->GetHeight()); +//fprintf(stderr,"loadguts ht.%d\n",pindexNew->GetHeight()); // Consistency checks auto header = pindexNew->GetBlockHeader(); if (header.GetHash() != pindexNew->GetBlockHash()) From a6e7da55e27cfac3bfb2f6f77c7109717cd9043d Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sat, 26 Jan 2019 03:09:54 +0300 Subject: [PATCH 63/68] fix gcc-8 / g++-8 build --- src/chain.h | 2 +- src/consensus/params.h | 4 ++-- src/crypto/verus_hash.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/chain.h b/src/chain.h index 0b6e2b046..d5310e4e5 100644 --- a/src/chain.h +++ b/src/chain.h @@ -335,7 +335,7 @@ public: nSolution = block.nSolution; } - int32_t SetHeight(int32_t height) + void SetHeight(int32_t height) { this->chainPower.nHeight = height; } diff --git a/src/consensus/params.h b/src/consensus/params.h index b7dc8b475..0ea5b1fff 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -115,8 +115,8 @@ struct Params { int64_t AveragingWindowTimespan() const { return nPowAveragingWindow * nPowTargetSpacing; } int64_t MinActualTimespan() const { return (AveragingWindowTimespan() * (100 - nPowMaxAdjustUp )) / 100; } int64_t MaxActualTimespan() const { return (AveragingWindowTimespan() * (100 + nPowMaxAdjustDown)) / 100; } - int32_t SetSaplingHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; } - int32_t SetOverwinterHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = height; } + void SetSaplingHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; } + void SetOverwinterHeight(int32_t height) { vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = height; } uint256 nMinimumChainWork; }; } // namespace Consensus diff --git a/src/crypto/verus_hash.h b/src/crypto/verus_hash.h index 5ac49c209..2f1f2cd26 100644 --- a/src/crypto/verus_hash.h +++ b/src/crypto/verus_hash.h @@ -86,6 +86,7 @@ class CVerusHashV2 result = buf2; curPos = 0; std::fill(buf1, buf1 + sizeof(buf1), 0); + return *this; } int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } From 52cfb02f408de11c81a59bb1e0976e299491e2e0 Mon Sep 17 00:00:00 2001 From: DeckerSU Date: Sat, 26 Jan 2019 04:21:55 +0300 Subject: [PATCH 64/68] komodo_activate_sapling return value fix --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3d2f19b55..84f1b611a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3839,7 +3839,8 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { int32_t komodo_activate_sapling(CBlockIndex *pindex) { - uint32_t blocktime,prevtime; CBlockIndex *prev; int32_t i,transition=0,height,prevht,activation = 0; + uint32_t blocktime,prevtime; CBlockIndex *prev; int32_t i,transition=0,height,prevht; + int32_t activation = 0; if ( pindex == 0 ) { fprintf(stderr,"komodo_activate_sapling null pindex\n"); @@ -3897,6 +3898,7 @@ int32_t komodo_activate_sapling(CBlockIndex *pindex) fprintf(stderr,"%s sapling activation at %d\n",ASSETCHAINS_SYMBOL,activation); ASSETCHAINS_SAPLING = activation; } + return activation; } static int64_t nTimeReadFromDisk = 0; From 524342f7ba685dad74d2c4388c548b8680bfafb2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 16:43:57 -1100 Subject: [PATCH 65/68] Single #define _MAX_BLOCK_SIZE to set max block size --- src/chainparams.cpp | 2 +- src/net.h | 3 ++- src/util.h | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c7232761b..d01b9af1a 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -229,7 +229,7 @@ int32_t MAX_BLOCK_SIZE(int32_t height) // make sure to change MAX_PROTOCOL_MESSA { //fprintf(stderr,"MAX_BLOCK_SIZE %d vs. %d\n",height,mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight); if ( height <= 0 || (mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight > 0 && height >= mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) ) - return(4096 * 1024); + return(_MAX_BLOCK_SIZE); else return(2000000); } diff --git a/src/net.h b/src/net.h index 3f30175c3..ff47737d8 100644 --- a/src/net.h +++ b/src/net.h @@ -33,6 +33,7 @@ #include "sync.h" #include "uint256.h" #include "utilstrencodings.h" +#include "util.h" #include #include @@ -63,7 +64,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; // depends on MAX_BLOCK_SIZE +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = _MAX_BLOCK_SIZE; /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ diff --git a/src/util.h b/src/util.h index bd1a2542a..dc421092a 100644 --- a/src/util.h +++ b/src/util.h @@ -3,6 +3,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/****************************************************************************** + * Copyright © 2014-2019 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + /** * Server/client environment: argument handling, config file parsing, * logging, thread wrappers @@ -29,6 +44,8 @@ #include #include +#define _MAX_BLOCK_SIZE (4096 * 1024) // changing just _MAX_BLOCK_SIZE will hardfork to that size + static const bool DEFAULT_LOGTIMEMICROS = false; static const bool DEFAULT_LOGIPS = false; static const bool DEFAULT_LOGTIMESTAMPS = true; From 91f213c4b8209d5a91bee592ea97ff883c4fe83d Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 16:54:42 -1100 Subject: [PATCH 66/68] +// --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 344224902..8c652350e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5220,7 +5220,7 @@ bool AcceptBlock(int32_t *futureblockp,CBlock& block, CValidationState& state, C AbortNode(state, "Failed to write block"); if (!ReceivedBlockTransactions(block, state, pindex, blockPos)) return error("AcceptBlock(): ReceivedBlockTransactions failed"); - if ( usetmp != 0 ) + if ( usetmp != 0 ) // not during initialdownload or if futureflag==0 and contextchecks ok pindex->nStatus |= BLOCK_IN_TMPFILE; } catch (const std::runtime_error& e) { return AbortNode(state, std::string("System error: ") + e.what()); From 352c93f2c4d58fd6bcb245fab1b3db67fd82868c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 16:59:55 -1100 Subject: [PATCH 67/68] -<<<<< HEAD --- src/net.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/net.h b/src/net.h index b3df42df7..ff47737d8 100644 --- a/src/net.h +++ b/src/net.h @@ -64,11 +64,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -<<<<<<< HEAD static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = _MAX_BLOCK_SIZE; -======= -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 4 * 1024 * 1024; ->>>>>>> origin/FSM /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */ From 932b3582437021f3c52c101f2d72f406dca0bc36 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 17:15:56 -1100 Subject: [PATCH 68/68] +comments how to update to 8MB blocks --- src/chainparams.cpp | 25 +++++++++++++++++++++++-- src/net.h | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index d01b9af1a..5c9efb276 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -225,11 +225,32 @@ void CChainParams::SetCheckpointData(CChainParams::CCheckpointData checkpointDat CChainParams::checkpointData = checkpointData; } -int32_t MAX_BLOCK_SIZE(int32_t height) // make sure to change MAX_PROTOCOL_MESSAGE_LENGTH also!!!! +/* + To change the max block size, all that needs to be updated is the #define _MAX_BLOCK_SIZE in utils.h + + However, doing that without any other changes will allow forking non-updated nodes by creating a larger block. So, make sure to height activate the new blocksize properly. + + Assuming it is 8MB, then: + #define _OLD_MAX_BLOCK_SIZE (4096 * 1024) + #define _MAX_BLOCK_SIZE (2 * 4096 * 1024) + + change the body of if: + { + if ( height < saplinght+1000000 ) // activates 8MB blocks 1 million blocks after saplinght + return(_OLD_MAX_BLOCK_SIZE); + else return(_MAX_BLOCK_SIZE); + } + +*/ + +int32_t MAX_BLOCK_SIZE(int32_t height) { + int32_t saplinght = mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight; //fprintf(stderr,"MAX_BLOCK_SIZE %d vs. %d\n",height,mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight); - if ( height <= 0 || (mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight > 0 && height >= mainParams.consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight) ) + if ( height <= 0 || (saplinght > 0 && height >= saplinght) ) + { return(_MAX_BLOCK_SIZE); + } else return(2000000); } diff --git a/src/net.h b/src/net.h index ff47737d8..3e06e9831 100644 --- a/src/net.h +++ b/src/net.h @@ -64,7 +64,7 @@ static const unsigned int MAX_INV_SZ = 50000; /** The maximum number of new addresses to accumulate before announcing. */ static const unsigned int MAX_ADDR_TO_SEND = 1000; /** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */ -static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = _MAX_BLOCK_SIZE; +static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = (_MAX_BLOCK_SIZE + 24); // 24 is msgheader size /** Maximum length of strSubVer in `version` message */ static const unsigned int MAX_SUBVERSION_LENGTH = 256; /** -listen default */