From bfd4917613ae58e6c4d49354f2efb9406aec141d Mon Sep 17 00:00:00 2001 From: ca333 Date: Sun, 20 Jan 2019 06:41:11 +0100 Subject: [PATCH 01/41] [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 02/41] [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 03/41] [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 04/41] 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 05/41] 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 06/41] 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 07/41] 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 08/41] -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 09/41] 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 10/41] () --- 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 11/41] -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 12/41] 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 13/41] 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 14/41] 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 15/41] 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 16/41] +/- 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 17/41] 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 18/41] 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 19/41] 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 20/41] 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 21/41] 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 9f663ad841dc2f3cde6bdf8465b370df8df23b8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:00:37 -1100 Subject: [PATCH 22/41] 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 2367a5cc0b78880dbdbec6f4b5e3e0a6c1f7c840 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 24 Jan 2019 02:14:31 -1100 Subject: [PATCH 23/41] 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 24/41] 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 25/41] +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 26/41] 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 27/41] 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 28/41] 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 29/41] 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 30/41] 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 31/41] 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 32/41] 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 33/41] -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 34/41] 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 35/41] 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 36/41] 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 37/41] +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 38/41] 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 39/41] 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 40/41] 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 07a05ccd6b65afcf01e4683d06996e599a9864e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 25 Jan 2019 01:27:55 -1100 Subject: [PATCH 41/41] -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())