Merge pull request #593 from jl777/jl777

Jl777
This commit is contained in:
jl777
2018-04-17 23:48:51 +03:00
committed by GitHub
37 changed files with 876 additions and 347 deletions

View File

@@ -15,7 +15,7 @@ endif
BITCOIND_BIN=$(top_builddir)/src/zcashd$(EXEEXT)
BITCOIN_CLI_BIN=$(top_builddir)/src/zcash-cli$(EXEEXT)
WALLET_UTILITY_BIN=$(top_builddir)/src/wallet-utility$(EXEEXT)
#WALLET_UTILITY_BIN=$(top_builddir)/src/wallet-utility$(EXEEXT)
BITCOIN_WIN_INSTALLER=$(PACKAGE)-$(PACKAGE_VERSION)-win$(WINDOWS_BITS)-setup$(EXEEXT)
if TARGET_DARWIN
@@ -156,8 +156,8 @@ $(BITCOIND_BIN): FORCE
$(BITCOIN_CLI_BIN): FORCE
$(MAKE) -C src $(@F)
$(WALLET_UTILITY_BIN): FORCE
$(MAKE) -C src $(@F)
#$(WALLET_UTILITY_BIN): FORCE
# $(MAKE) -C src $(@F)
if USE_LCOV

View File

@@ -100,9 +100,9 @@ bin_PROGRAMS =
noinst_PROGRAMS =
TESTS =
if BUILD_BITCOIND
#if BUILD_BITCOIND
bin_PROGRAMS += komodod
endif
#endif
if BUILD_BITCOIN_UTILS
bin_PROGRAMS += komodo-cli komodo-tx
@@ -111,6 +111,7 @@ if ENABLE_WALLET
bin_PROGRAMS += wallet-utility
endif
LIBZCASH_H = \
zcash/IncrementalMerkleTree.hpp \
zcash/NoteEncryption.hpp \
@@ -528,7 +529,7 @@ wallet_utility_LDADD = \
$(LIBZCASH) \
$(LIBSNARK) \
$(LIBZCASH_LIBS)\
$(LIBCRYPTOCONDITIONS)
$(LIBCRYPTOCONDITIONS)
endif
# zcash-tx binary #

40
src/assetchains_stop Normal file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
args=("$@")
komodo_cli='./komodo-cli'
delay=20
function komodo_stop ()
{
$komodo_cli --ac_name=$1 stop
}
#set -x
komodo_stop REVS
komodo_stop SUPERNET
komodo_stop DEX
komodo_stop PANGEA
komodo_stop JUMBLR
komodo_stop BET
komodo_stop CRYPTO
komodo_stop HODL
komodo_stop MSHARK
komodo_stop BOTS
komodo_stop MGW
komodo_stop COQUI
komodo_stop WLC
komodo_stop KV
komodo_stop CEAL
komodo_stop MESH
komodo_stop MNZ
komodo_stop AXO
komodo_stop ETOMIC
komodo_stop BTCH
komodo_stop VOTE2018
komodo_stop PIZZA
komodo_stop BEER
komodo_stop NINJA
komodo_stop OOT
komodo_stop BNTN
komodo_stop CHAIN
komodo_stop PRLPAY

View File

@@ -125,7 +125,7 @@ bool AppInit(int argc, char* argv[])
sleep(1);
#endif
}
printf("initialized %s\n",ASSETCHAINS_SYMBOL);
printf("initialized %s at %u\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL));
if (!boost::filesystem::is_directory(GetDataDir(false)))
{
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());

View File

@@ -11,12 +11,13 @@
#include "chainparams.h"
static const std::string CLIENT_VERSION_STR = FormatVersion(CLIENT_VERSION);
extern char ASSETCHAINS_SYMBOL[];
void EnforceNodeDeprecation(int nHeight, bool forceLogging) {
// Do not enforce deprecation in regtest or on testnet
std::string networkID = Params().NetworkIDString();
if (networkID != "main") return;
if (networkID != "main" || ASSETCHAINS_SYMBOL[0] != 0 ) return;
int blocksToDeprecation = DEPRECATION_HEIGHT - nHeight;
bool disableDeprecation = (GetArg("-disabledeprecation", "") == CLIENT_VERSION_STR);
@@ -58,4 +59,4 @@ void EnforceNodeDeprecation(int nHeight, bool forceLogging) {
LogPrintf("*** %s\n", msg);
uiInterface.ThreadSafeMessageBox(msg, "", CClientUIInterface::MSG_WARNING);
}
}
}

View File

@@ -1442,7 +1442,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
break;
}
KOMODO_LOADINGBLOCKS = 0;
// Check for changed -txindex state
if (fTxIndex != GetBoolArg("-txindex", true)) {
strLoadError = _("You need to rebuild the database using -reindex to change -txindex");

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@@ -54,6 +54,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char
#include "komodo_jumblr.h"
#include "komodo_gateway.h"
#include "komodo_events.h"
#include "komodo_ccdata.h"
void komodo_currentheight_set(int32_t height)
{
@@ -356,6 +357,7 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
if ( didinit == 0 )
{
portable_mutex_init(&KOMODO_KV_mutex);
portable_mutex_init(&KOMODO_CC_mutex);
didinit = 1;
}
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
@@ -505,10 +507,35 @@ void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotar
}
}
int32_t komodo_validate_chain(uint256 srchash,int32_t notarized_height)
{
static int32_t last_rewind; int32_t rewindtarget; CBlockIndex *pindex; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
return(0);
if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != notarized_height) )
{
if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < notarized_height )
rewindtarget = sp->NOTARIZED_HEIGHT - 1;
else if ( notarized_height > 101 )
rewindtarget = notarized_height - 101;
else rewindtarget = 0;
if ( rewindtarget != 0 && rewindtarget > KOMODO_REWIND && rewindtarget > last_rewind )
{
if ( last_rewind != 0 )
{
//KOMODO_REWIND = rewindtarget;
fprintf(stderr,"%s FORK detected. notarized.%d %s not in this chain! last notarization %d -> rewindtarget.%d\n",ASSETCHAINS_SYMBOL,notarized_height,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT,rewindtarget);
}
last_rewind = rewindtarget;
}
return(0);
} else return(1);
}
int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scriptbuf,int32_t scriptlen,int32_t height,uint256 txhash,int32_t i,int32_t j,uint64_t *voutmaskp,int32_t *specialtxp,int32_t *notarizedheightp,uint64_t value,int32_t notarized,uint64_t signedmask,uint32_t timestamp)
{
static uint256 zero; static FILE *signedfp;
int32_t opretlen,nid,k,len = 0; uint256 srchash,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
int32_t opretlen,nid,offset,k,MoMdepth,matched,len = 0; uint256 MoM,srchash,desttxid; uint8_t crypto777[33]; struct komodo_state *sp; char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN];
if ( (sp= komodo_stateptr(symbol,dest)) == 0 )
return(-1);
if ( scriptlen == 35 && scriptbuf[0] == 33 && scriptbuf[34] == 0xac )
@@ -555,6 +582,8 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
}
if ( scriptbuf[len++] == 0x6a )
{
struct komodo_ccdata ccdata; struct komodo_ccdataMoMoM MoMoMdata;
int32_t validated = 0,nameoffset,opoffset = 0;
if ( (opretlen= scriptbuf[len++]) == 0x4c )
opretlen = scriptbuf[len++];
else if ( opretlen == 0x4d )
@@ -562,96 +591,148 @@ int32_t komodo_voutupdate(int32_t *isratificationp,int32_t notaryid,uint8_t *scr
opretlen = scriptbuf[len++];
opretlen += (scriptbuf[len++] << 8);
}
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 )
printf("[%s] notarized.%d notarizedht.%d sp.Nht %d sp.ht %d opretlen.%d (%c %c %c)\n",ASSETCHAINS_SYMBOL,notarized,*notarizedheightp,sp->NOTARIZED_HEIGHT,sp->CURRENT_HEIGHT,opretlen,scriptbuf[len+32*2+4],scriptbuf[len+32*2+4+1],scriptbuf[len+32*2+4+2]);
if ( j == 1 && opretlen >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
opoffset = len;
matched = 0;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
if ( strcmp("KMD",(char *)&scriptbuf[len+32 * 2 + 4]) == 0 )
matched = 1;
}
else
{
if ( strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
matched = 1;
}
offset = 32 * (1 + matched) + 4;
nameoffset = (int32_t)strlen((char *)&scriptbuf[len+offset]);
if ( nameoffset == 2 )
nameoffset += 2;
else nameoffset++;
memset(&ccdata,0,sizeof(ccdata));
strncpy(ccdata.symbol,(char *)&scriptbuf[len+offset],sizeof(ccdata.symbol));
if ( j == 1 && opretlen >= len+offset-opoffset )
{
memset(&MoMoMdata,0,sizeof(MoMoMdata));
if ( matched == 0 && bitweight(signedmask) >= KOMODO_MINRATIFY )
notarized = 1;
if ( strcmp("PIZZA",ccdata.symbol) == 0 )
notarized = 1;
if ( 0 && opretlen != 149 )
printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",ASSETCHAINS_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset);
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp);
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
if ( strcmp("PIZZA",ASSETCHAINS_SYMBOL) == 0 && opretlen == 110 )
if ( matched != 0 )
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&desttxid);
if ( matched != 0 )
validated = komodo_validate_chain(srchash,*notarizedheightp);
else validated = 1;
if ( notarized != 0 && validated != 0 )
{
notarized = 1;
}
static int32_t last_rewind;
int32_t rewindtarget,validated = 0;
CBlockIndex *pindex;//
if ( IsInitialBlockDownload() == 0 && ((pindex= mapBlockIndex[srchash]) == 0 || pindex->nHeight != *notarizedheightp) )
{
if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < *notarizedheightp )
rewindtarget = sp->NOTARIZED_HEIGHT - 1;
else if ( *notarizedheightp > 101 )
rewindtarget = *notarizedheightp - 101;
else rewindtarget = 0;
if ( rewindtarget != 0 && rewindtarget > KOMODO_REWIND && rewindtarget > last_rewind )
//sp->NOTARIZED_HEIGHT = *notarizedheightp;
//sp->NOTARIZED_HASH = srchash;
//sp->NOTARIZED_DESTTXID = desttxid;
memset(&MoM,0,sizeof(MoM));
MoMdepth = 0;
len += nameoffset;
ccdata.MoMdata.notarized_height = *notarizedheightp;
ccdata.MoMdata.height = height;
ccdata.MoMdata.txi = i;
//printf("nameoffset.%d len.%d + 36 %d vs opretlen.%d\n",nameoffset,len,len+36,opretlen);
if ( len+36-opoffset <= opretlen )
{
if ( last_rewind != 0 )
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(MoMdepth),(uint8_t *)&MoMdepth);
ccdata.MoMdata.MoM = MoM;
ccdata.MoMdata.MoMdepth = MoMdepth;
if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen )
{
//KOMODO_REWIND = rewindtarget;
fprintf(stderr,"%s FORK detected. notarized.%d %s not in this chain! last notarization %d -> rewindtarget.%d\n",ASSETCHAINS_SYMBOL,*notarizedheightp,srchash.ToString().c_str(),sp->NOTARIZED_HEIGHT,rewindtarget);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid);
ccdata.len = sizeof(ccdata.CCid);
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
// MoMoM, depth, numpairs, (notarization ht, MoMoM offset)
if ( len+48-opoffset <= opretlen && strcmp(ccdata.symbol,ASSETCHAINS_SYMBOL) == 0 )
{
len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.kmdstarti);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.kmdendi);
len += iguana_rwbignum(0,&scriptbuf[len],sizeof(MoMoMdata.MoMoM),(uint8_t *)&MoMoMdata.MoMoM);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.MoMoMdepth);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.numpairs);
MoMoMdata.len += sizeof(MoMoMdata.MoMoM) + sizeof(uint32_t)*4;
if ( len+MoMoMdata.numpairs*8-opoffset == opretlen )
{
MoMoMdata.pairs = (struct komodo_ccdatapair *)calloc(MoMoMdata.numpairs,sizeof(*MoMoMdata.pairs));
for (k=0; k<MoMoMdata.numpairs; k++)
{
len += iguana_rwnum(0,&scriptbuf[len],sizeof(int32_t),(uint8_t *)&MoMoMdata.pairs[k].notarized_height);
len += iguana_rwnum(0,&scriptbuf[len],sizeof(uint32_t),(uint8_t *)&MoMoMdata.pairs[k].MoMoMoffset);
MoMoMdata.len += sizeof(uint32_t) * 2;
}
} else ccdata.len = MoMoMdata.len = 0;
} else ccdata.len = MoMoMdata.len = 0;
}
}
last_rewind = rewindtarget;
}
} else validated = 1;
if ( notarized != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height && validated != 0 )
{
int32_t nameoffset = (int32_t)strlen(ASSETCHAINS_SYMBOL) + 1;
sp->NOTARIZED_HEIGHT = *notarizedheightp;
sp->NOTARIZED_HASH = srchash;
sp->NOTARIZED_DESTTXID = desttxid;
memset(&sp->MoM,0,sizeof(sp->MoM));
sp->MoMdepth = 0;
if ( len+36 <= opretlen )
{
len += iguana_rwbignum(0,&scriptbuf[len+nameoffset],32,(uint8_t *)&sp->MoM);
len += iguana_rwnum(0,&scriptbuf[len+nameoffset],sizeof(sp->MoMdepth),(uint8_t *)&sp->MoMdepth);
if ( sp->MoM == zero || sp->MoMdepth > 1440 || sp->MoMdepth < 0 )
if ( MoM == zero || MoMdepth > 1440 || MoMdepth < 0 )
{
memset(&sp->MoM,0,sizeof(sp->MoM));
sp->MoMdepth = 0;
memset(&MoM,0,sizeof(MoM));
MoMdepth = 0;
}
else
{
//printf("VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,sp->MoM.ToString().c_str(),sp->MoMdepth);
//komodo_rwccdata(ASSETCHAINS_SYMBOL,1,&ccdata,&MoMoMdata);
//printf("[%s] matched.%d VALID (%s) MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,matched,ccdata.symbol,MoM.ToString().c_str(),MoMdepth);
}
if ( MoMoMdata.pairs != 0 )
free(MoMoMdata.pairs);
memset(&ccdata,0,sizeof(ccdata));
memset(&MoMoMdata,0,sizeof(MoMoMdata));
}
komodo_stateupdate(height,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,sp->MoM,sp->MoMdepth);
len += nameoffset;
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 ( ASSETCHAINS_SYMBOL[0] == 0 )
//else if ( ASSETCHAINS_SYMBOL[0] == 0 && matched != 0 && notarized != 0 && validated != 0 )
// komodo_rwccdata((char *)"KMD",1,&ccdata,0);
if ( matched != 0 && *notarizedheightp > sp->NOTARIZED_HEIGHT && *notarizedheightp < height )
{
if ( signedfp == 0 )
sp->NOTARIZED_HEIGHT = *notarizedheightp;
sp->NOTARIZED_HASH = srchash;
sp->NOTARIZED_DESTTXID = desttxid;
sp->MoM = MoM;
sp->MoMdepth = MoMdepth;
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 ( ASSETCHAINS_SYMBOL[0] == 0 )
{
char fname[512];
komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks");
if ( (signedfp= fopen(fname,"rb+")) == 0 )
signedfp = fopen(fname,"wb");
else fseek(signedfp,0,SEEK_END);
}
if ( signedfp != 0 )
{
fwrite(&height,1,sizeof(height),signedfp);
fwrite(&signedmask,1,sizeof(signedmask),signedfp);
fflush(signedfp);
}
if ( opretlen > len && scriptbuf[len] == 'A' )
{
//for (i=0; i<opretlen-len; i++)
// printf("%02x",scriptbuf[len+i]);
//printf(" Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len);
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0);
if ( signedfp == 0 )
{
char fname[512];
komodo_statefname(fname,ASSETCHAINS_SYMBOL,(char *)"signedmasks");
if ( (signedfp= fopen(fname,"rb+")) == 0 )
signedfp = fopen(fname,"wb");
else fseek(signedfp,0,SEEK_END);
}
if ( signedfp != 0 )
{
fwrite(&height,1,sizeof(height),signedfp);
fwrite(&signedmask,1,sizeof(signedmask),signedfp);
fflush(signedfp);
}
if ( opretlen > len && scriptbuf[len] == 'A' )
{
//for (i=0; i<opretlen-len; i++)
// printf("%02x",scriptbuf[len+i]);
//printf(" Found extradata.[%d] %d - %d\n",opretlen-len,opretlen,len);
komodo_stateupdate(height,0,0,0,txhash,0,0,0,0,0,0,value,&scriptbuf[len],opretlen-len+4+3+(scriptbuf[1] == 0x4d),j,zero,0);
}
}
}
} else if ( *notarizedheightp != sp->NOTARIZED_HEIGHT )
printf("validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s (%s) len.%d opretlen.%d\n",validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),(char *)&scriptbuf[len],len,opretlen);
} else if ( opretlen != 149 && height > 600000 && matched != 0 )
printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,ASSETCHAINS_SYMBOL[0]==0?"KMD":ASSETCHAINS_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen);
}
else if ( i == 0 && j == 1 && opretlen == 149 )
else if ( matched != 0 && i == 0 && j == 1 && opretlen == 149 )
{
if ( notaryid >= 0 && notaryid < 64 )
komodo_paxpricefeed(height,&scriptbuf[len],opretlen);
}
else
else if ( matched != 0 )
{
//int32_t k; for (k=0; k<scriptlen; k++)
// printf("%02x",scriptbuf[k]);
@@ -726,7 +807,11 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
else
{
if ( pindex->nHeight != hwmheight )
{
printf("%s hwmheight.%d vs pindex->nHeight.%d t.%u reorg.%d\n",ASSETCHAINS_SYMBOL,hwmheight,pindex->nHeight,(uint32_t)pindex->nTime,hwmheight-pindex->nHeight);
komodo_purge_ccdata((int32_t)pindex->nHeight);
hwmheight = pindex->nHeight;
}
komodo_event_rewind(sp,symbol,pindex->nHeight);
komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0);
}

View File

@@ -592,7 +592,6 @@ void komodo_disconnect(CBlockIndex *pindex,CBlock& block)
} else printf("komodo_disconnect: ht.%d cant get komodo_state.(%s)\n",pindex->nHeight,ASSETCHAINS_SYMBOL);
}
int32_t komodo_is_notarytx(const CTransaction& tx)
{
uint8_t *ptr; static uint8_t crypto777[33];
@@ -725,45 +724,45 @@ uint32_t komodo_heightstamp(int32_t height)
}
/*void komodo_pindex_init(CBlockIndex *pindex,int32_t height) gets data corrupted
{
int32_t i,num; uint8_t pubkeys[64][33]; CBlock block;
if ( pindex->didinit != 0 )
return;
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->nHeight,pindex->notaryid,height);
if ( pindex->didinit == 0 )
{
pindex->notaryid = -1;
if ( KOMODO_LOADINGBLOCKS == 0 )
memset(pindex->pubkey33,0xff,33);
else memset(pindex->pubkey33,0,33);
if ( komodo_blockload(block,pindex) == 0 )
{
komodo_block2pubkey33(pindex->pubkey33,&block);
//for (i=0; i<33; i++)
// fprintf(stderr,"%02x",pindex->pubkey33[i]);
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->nHeight,height);
//if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
// pindex->didinit = (KOMODO_LOADINGBLOCKS == 0);
} // else fprintf(stderr,"error loading block at %d/%d",pindex->nHeight,height);
}
if ( pindex->didinit != 0 && pindex->nHeight >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
{
for (i=0; i<num; i++)
{
if ( memcmp(pubkeys[i],pindex->pubkey33,33) == 0 )
{
pindex->notaryid = i;
break;
}
}
if ( 0 && i == num )
{
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pindex->pubkey33[i]);
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->nHeight,height);
}
}
}*/
{
int32_t i,num; uint8_t pubkeys[64][33]; CBlock block;
if ( pindex->didinit != 0 )
return;
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->nHeight,pindex->notaryid,height);
if ( pindex->didinit == 0 )
{
pindex->notaryid = -1;
if ( KOMODO_LOADINGBLOCKS == 0 )
memset(pindex->pubkey33,0xff,33);
else memset(pindex->pubkey33,0,33);
if ( komodo_blockload(block,pindex) == 0 )
{
komodo_block2pubkey33(pindex->pubkey33,&block);
//for (i=0; i<33; i++)
// fprintf(stderr,"%02x",pindex->pubkey33[i]);
//fprintf(stderr," set pubkey at height %d/%d\n",pindex->nHeight,height);
//if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
// pindex->didinit = (KOMODO_LOADINGBLOCKS == 0);
} // else fprintf(stderr,"error loading block at %d/%d",pindex->nHeight,height);
}
if ( pindex->didinit != 0 && pindex->nHeight >= 0 && (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
{
for (i=0; i<num; i++)
{
if ( memcmp(pubkeys[i],pindex->pubkey33,33) == 0 )
{
pindex->notaryid = i;
break;
}
}
if ( 0 && i == num )
{
for (i=0; i<33; i++)
fprintf(stderr,"%02x",pindex->pubkey33[i]);
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->nHeight,height);
}
}
}*/
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
{
@@ -777,32 +776,32 @@ void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
}
/*int8_t komodo_minerid(int32_t height,uint8_t *destpubkey33)
{
int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t pubkey33[33],pubkeys[64][33];
if ( (pindex= chainActive[height]) != 0 )
{
if ( pindex->didinit != 0 )
{
if ( destpubkey33 != 0 )
memcpy(destpubkey33,pindex->pubkey33,33);
return(pindex->notaryid);
}
komodo_index2pubkey33(pubkey33,pindex,height);
if ( destpubkey33 != 0 )
memcpy(destpubkey33,pindex->pubkey33,33);
if ( pindex->didinit != 0 )
return(pindex->notaryid);
timestamp = pindex->GetBlockTime();
if ( (num= komodo_notaries(pubkeys,height,timestamp)) > 0 )
{
for (i=0; i<num; i++)
if ( memcmp(pubkeys[i],pubkey33,33) == 0 )
return(i);
}
}
fprintf(stderr,"komodo_minerid height.%d null pindex\n",height);
return(komodo_electednotary(&numnotaries,pubkey33,height,timestamp));
}*/
{
int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t pubkey33[33],pubkeys[64][33];
if ( (pindex= chainActive[height]) != 0 )
{
if ( pindex->didinit != 0 )
{
if ( destpubkey33 != 0 )
memcpy(destpubkey33,pindex->pubkey33,33);
return(pindex->notaryid);
}
komodo_index2pubkey33(pubkey33,pindex,height);
if ( destpubkey33 != 0 )
memcpy(destpubkey33,pindex->pubkey33,33);
if ( pindex->didinit != 0 )
return(pindex->notaryid);
timestamp = pindex->GetBlockTime();
if ( (num= komodo_notaries(pubkeys,height,timestamp)) > 0 )
{
for (i=0; i<num; i++)
if ( memcmp(pubkeys[i],pubkey33,33) == 0 )
return(i);
}
}
fprintf(stderr,"komodo_minerid height.%d null pindex\n",height);
return(komodo_electednotary(&numnotaries,pubkey33,height,timestamp));
}*/
int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blocktimes[66],int32_t *nonzpkeysp,int32_t height)
{
@@ -836,18 +835,33 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,uint32_t blo
else return(0);
}
int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) // deprecate
int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width)
{
/*int32_t i,n=0;
for (i=0; i<width; i++,n++)
{
if ( height-i <= 0 )
break;
minerids[i] = komodo_minerid(height - i,0);
}
return(n);*/
fprintf(stderr,"komodo_minerids is deprecated\n");
return(-1);
int32_t i,j,n,nonz,numnotaries; CBlock block; CBlockIndex *pindex; uint8_t notarypubs33[64][33],pubkey33[33];
numnotaries = komodo_notaries(notarypubs33,height,0);
for (i=nonz=0; i<width; i++,n++)
{
if ( height-i <= 0 )
continue;
if ( (pindex= komodo_chainactive(height-width+i+1)) != 0 )
{
if ( komodo_blockload(block,pindex) == 0 )
{
komodo_block2pubkey33(pubkey33,&block);
for (j=0; j<numnotaries; j++)
{
if ( memcmp(notarypubs33[j],pubkey33,33) == 0 )
{
minerids[nonz++] = j;
break;
}
}
if ( j == numnotaries )
minerids[nonz++] = j;
} else fprintf(stderr,"couldnt load block.%d\n",height);
}
}
return(nonz);
}
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t blocktimes[66],int32_t height,uint8_t pubkey33[33],uint32_t blocktime)
@@ -873,7 +887,8 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],uint32_t bloc
}
if ( blocktime != 0 && blocktimes[1] != 0 && blocktime < blocktimes[1]+57 )
{
//fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]);
//if ( height > 790000 )
// fprintf(stderr,"lag.%d ht.%d n.%d blocktimes[%u vs %u %u]\n",blocktime-blocktimes[1],height,notaryid,blocktime,blocktimes[0],blocktimes[1]);
if ( height > 807000 )
return(-2);
}
@@ -946,7 +961,7 @@ int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 has
fprintf(stderr,"[%s] nHeight.%d == NOTARIZED_HEIGHT.%d, diff hash\n",ASSETCHAINS_SYMBOL,nHeight,notarized_height);
return(-1);
}
} else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
} //else fprintf(stderr,"[%s] unexpected error notary_hash %s ht.%d at ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,notary->nHeight);
}
//else if ( notarized_height > 0 && notarized_height != 73880 && notarized_height >= 170000 )
// fprintf(stderr,"[%s] couldnt find notarized.(%s %d) ht.%d\n",ASSETCHAINS_SYMBOL,notarized_hash.ToString().c_str(),notarized_height,pindex->nHeight);

View File

@@ -56,7 +56,7 @@ static int32_t cJSON_strcasecmp(const char *s1,const char *s2)
// the following written by jl777
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

273
src/komodo_ccdata.h Normal file
View File

@@ -0,0 +1,273 @@
/******************************************************************************
* Copyright © 2014-2018 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. *
* *
******************************************************************************/
#ifndef H_KOMODOCCDATA_H
#define H_KOMODOCCDATA_H
struct komodo_ccdata *CC_data;
int32_t CC_firstheight;
bits256 iguana_merkle(bits256 *tree,int32_t txn_count)
{
int32_t i,n=0,prev; uint8_t serialized[sizeof(bits256) * 2];
if ( txn_count == 1 )
return(tree[0]);
prev = 0;
while ( txn_count > 1 )
{
if ( (txn_count & 1) != 0 )
tree[prev + txn_count] = tree[prev + txn_count-1], txn_count++;
n += txn_count;
for (i=0; i<txn_count; i+=2)
{
iguana_rwbignum(1,serialized,sizeof(*tree),tree[prev + i].bytes);
iguana_rwbignum(1,&serialized[sizeof(*tree)],sizeof(*tree),tree[prev + i + 1].bytes);
tree[n + (i >> 1)] = bits256_doublesha256(0,serialized,sizeof(serialized));
}
prev = n;
txn_count >>= 1;
}
return(tree[n]);
}
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi)
{
struct komodo_ccdata_entry *allMoMs=0; bits256 *tree,tmp; struct komodo_ccdata *ccdata,*tmpptr; int32_t i,num,max;
num = max = 0;
portable_mutex_lock(&KOMODO_CC_mutex);
DL_FOREACH_SAFE(CC_data,ccdata,tmpptr)
{
if ( ccdata->MoMdata.height <= kmdendi && ccdata->MoMdata.height >= kmdstarti )
{
if ( num >= max )
{
max += 100;
allMoMs = (struct komodo_ccdata_entry *)realloc(allMoMs,max * sizeof(*allMoMs));
}
allMoMs[num].MoM = ccdata->MoMdata.MoM;
allMoMs[num].notarized_height = ccdata->MoMdata.notarized_height;
allMoMs[num].kmdheight = ccdata->MoMdata.height;
allMoMs[num].txi = ccdata->MoMdata.txi;
strcpy(allMoMs[num].symbol,ccdata->symbol);
num++;
}
if ( ccdata->MoMdata.height < kmdstarti )
break;
}
portable_mutex_unlock(&KOMODO_CC_mutex);
if ( (*nump= num) > 0 )
{
tree = (bits256 *)calloc(sizeof(bits256),num*3);
for (i=0; i<num; i++)
memcpy(&tree[i],&allMoMs[i].MoM,sizeof(tree[i]));
tmp = iguana_merkle(tree,num);
memcpy(MoMoMp,&tree,sizeof(*MoMoMp));
}
else
{
free(allMoMs);
allMoMs = 0;
}
return(allMoMs);
}
int32_t komodo_addpair(struct komodo_ccdataMoMoM *mdata,int32_t notarized_height,int32_t offset,int32_t maxpairs)
{
if ( maxpairs >= 0) {
if ( mdata->numpairs >= maxpairs )
{
maxpairs += 100;
mdata->pairs = (struct komodo_ccdatapair *)realloc(mdata->pairs,sizeof(*mdata->pairs)*maxpairs);
//fprintf(stderr,"pairs reallocated to %p num.%d\n",mdata->pairs,mdata->numpairs);
}
} else {
fprintf(stderr,"komodo_addpair.maxpairs %d must be >= 0\n",(int32_t)maxpairs);
return(-1);
}
mdata->pairs[mdata->numpairs].notarized_height = notarized_height;
mdata->pairs[mdata->numpairs].MoMoMoffset = offset;
mdata->numpairs++;
return(maxpairs);
}
int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height)
{
uint8_t hexdata[8192]; struct komodo_ccdata *ccdata,*tmpptr; int32_t len,maxpairs,i,retval=-1,depth,starti,endi,CCid=0; struct komodo_ccdata_entry *allMoMs;
starti = endi = depth = len = maxpairs = 0;
hexstr[0] = 0;
if ( sizeof(hexdata)*2+1 > hexsize )
{
fprintf(stderr,"hexsize.%d too small for %d\n",hexsize,(int32_t)sizeof(hexdata));
return(-1);
}
memset(mdata,0,sizeof(*mdata));
portable_mutex_lock(&KOMODO_CC_mutex);
DL_FOREACH_SAFE(CC_data,ccdata,tmpptr)
{
if ( ccdata->MoMdata.height < kmdheight )
{
//fprintf(stderr,"%s notarized.%d kmd.%d\n",ccdata->symbol,ccdata->MoMdata.notarized_height,ccdata->MoMdata.height);
if ( strcmp(ccdata->symbol,symbol) == 0 )
{
if ( endi == 0 )
{
endi = ccdata->MoMdata.height;
CCid = ccdata->CCid;
}
if ( (mdata->numpairs == 1 && notarized_height == 0) || ccdata->MoMdata.notarized_height <= notarized_height )
{
starti = ccdata->MoMdata.height + 1;
if ( notarized_height == 0 )
notarized_height = ccdata->MoMdata.notarized_height;
break;
}
}
starti = ccdata->MoMdata.height;
}
}
portable_mutex_unlock(&KOMODO_CC_mutex);
mdata->kmdstarti = starti;
mdata->kmdendi = endi;
if ( starti != 0 && endi != 0 && endi >= starti )
{
if ( (allMoMs= komodo_allMoMs(&depth,&mdata->MoMoM,starti,endi)) != 0 )
{
mdata->MoMoMdepth = depth;
for (i=0; i<depth; i++)
{
if ( strcmp(symbol,allMoMs[i].symbol) == 0 )
maxpairs = komodo_addpair(mdata,allMoMs[i].notarized_height,i,maxpairs);
}
if ( mdata->numpairs > 0 )
{
len += iguana_rwnum(1,&hexdata[len],sizeof(CCid),(uint8_t *)&CCid);
len += iguana_rwnum(1,&hexdata[len],sizeof(uint32_t),(uint8_t *)&mdata->kmdstarti);
len += iguana_rwnum(1,&hexdata[len],sizeof(uint32_t),(uint8_t *)&mdata->kmdendi);
len += iguana_rwbignum(1,&hexdata[len],sizeof(mdata->MoMoM),(uint8_t *)&mdata->MoMoM);
len += iguana_rwnum(1,&hexdata[len],sizeof(uint32_t),(uint8_t *)&mdata->MoMoMdepth);
len += iguana_rwnum(1,&hexdata[len],sizeof(uint32_t),(uint8_t *)&mdata->numpairs);
for (i=0; i<mdata->numpairs; i++)
{
if ( len + sizeof(uint32_t)*2 > sizeof(hexdata) )
{
fprintf(stderr,"%s %d %d i.%d of %d exceeds hexdata.%d\n",symbol,kmdheight,notarized_height,i,mdata->numpairs,(int32_t)sizeof(hexdata));
break;
}
len += iguana_rwnum(1,&hexdata[len],sizeof(uint32_t),(uint8_t *)&mdata->pairs[i].notarized_height);
len += iguana_rwnum(1,&hexdata[len],sizeof(uint32_t),(uint8_t *)&mdata->pairs[i].MoMoMoffset);
}
if ( i == mdata->numpairs && len*2+1 < hexsize )
{
init_hexbytes_noT(hexstr,hexdata,len);
//fprintf(stderr,"hexstr.(%s)\n",hexstr);
retval = 0;
} else fprintf(stderr,"%s %d %d too much hexdata[%d] for hexstr[%d]\n",symbol,kmdheight,notarized_height,len,hexsize);
}
free(allMoMs);
}
}
return(retval);
}
void komodo_purge_ccdata(int32_t height)
{
struct komodo_ccdata *ccdata,*tmpptr;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
portable_mutex_lock(&KOMODO_CC_mutex);
DL_FOREACH_SAFE(CC_data,ccdata,tmpptr)
{
if ( ccdata->MoMdata.height >= height )
{
printf("PURGE %s notarized.%d\n",ccdata->symbol,ccdata->MoMdata.notarized_height);
DL_DELETE(CC_data,ccdata);
free(ccdata);
} else break;
}
portable_mutex_unlock(&KOMODO_CC_mutex);
}
else
{
// purge notarized data
}
}
// this is just a demo of ccdata processing to create example data for the MoMoM and allMoMs calls
int32_t komodo_rwccdata(char *thischain,int32_t rwflag,struct komodo_ccdata *ccdata,struct komodo_ccdataMoMoM *MoMoMdata)
{
uint256 hash,zero; bits256 tmp; int32_t i,nonz; struct komodo_ccdata *ptr; struct notarized_checkpoint *np;
if ( rwflag == 0 )
{
// load from disk
}
else
{
// write to disk
}
if ( ccdata->MoMdata.height > 0 && (CC_firstheight == 0 || ccdata->MoMdata.height < CC_firstheight) )
CC_firstheight = ccdata->MoMdata.height;
for (nonz=i=0; i<32; i++)
{
if ( (tmp.bytes[i]= ((uint8_t *)&ccdata->MoMdata.MoM)[31-i]) != 0 )
nonz++;
}
if ( nonz == 0 )
return(0);
memcpy(&hash,&tmp,sizeof(hash));
//fprintf(stderr,"[%s] ccdata.%s id.%d notarized_ht.%d MoM.%s height.%d/t%d\n",ASSETCHAINS_SYMBOL,ccdata->symbol,ccdata->CCid,ccdata->MoMdata.notarized_height,hash.ToString().c_str(),ccdata->MoMdata.height,ccdata->MoMdata.txi);
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
if ( CC_data != 0 && (CC_data->MoMdata.height > ccdata->MoMdata.height || (CC_data->MoMdata.height == ccdata->MoMdata.height && CC_data->MoMdata.txi >= ccdata->MoMdata.txi)) )
{
printf("out of order detected? SKIP CC_data ht.%d/txi.%d vs ht.%d/txi.%d\n",CC_data->MoMdata.height,CC_data->MoMdata.txi,ccdata->MoMdata.height,ccdata->MoMdata.txi);
}
else
{
ptr = (struct komodo_ccdata *)calloc(1,sizeof(*ptr));
*ptr = *ccdata;
portable_mutex_lock(&KOMODO_CC_mutex);
DL_PREPEND(CC_data,ptr);
portable_mutex_unlock(&KOMODO_CC_mutex);
}
}
else
{
if ( MoMoMdata != 0 && MoMoMdata->pairs != 0 )
{
for (i=0; i<MoMoMdata->numpairs; i++)
{
if ( (np= komodo_npptr(MoMoMdata->pairs[i].notarized_height)) != 0 )
{
memset(&zero,0,sizeof(zero));
if ( memcmp(&np->MoMoM,&zero,sizeof(np->MoMoM)) == 0 )
{
np->MoMoM = MoMoMdata->MoMoM;
np->MoMoMdepth = MoMoMdata->MoMoMdepth;
np->MoMoMoffset = MoMoMdata->MoMoMoffset;
np->kmdstarti = MoMoMdata->kmdstarti;
np->kmdendi = MoMoMdata->kmdendi;
}
else if ( memcmp(&np->MoMoM,&MoMoMdata->MoMoM,sizeof(np->MoMoM)) != 0 || np->MoMoMdepth != MoMoMdata->MoMoMdepth || np->MoMoMoffset != MoMoMdata->MoMoMoffset || np->kmdstarti != MoMoMdata->kmdstarti || np->kmdendi != MoMoMdata->kmdendi )
{
fprintf(stderr,"preexisting MoMoM mismatch: %s (%d %d %d %d) vs %s (%d %d %d %d)\n",np->MoMoM.ToString().c_str(),np->MoMoMdepth,np->MoMoMoffset,np->kmdstarti,np->kmdendi,MoMoMdata->MoMoM.ToString().c_str(),MoMoMdata->MoMoMdepth,MoMoMdata->MoMoMoffset,MoMoMdata->kmdstarti,MoMoMdata->kmdendi);
}
}
}
}
}
return(1);
}
#endif

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@@ -1972,7 +1972,7 @@ void komodo_passport_iteration()
if ( expired == 0 && KOMODO_PASSPORT_INITDONE == 0 )
{
KOMODO_PASSPORT_INITDONE = 1;
printf("done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,refid);
printf("READY for %s RPC calls at %u! done PASSPORT %s refid.%d\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL),ASSETCHAINS_SYMBOL,refid);
}
}

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@@ -15,6 +15,7 @@
#include "komodo_defs.h"
void komodo_prefetch(FILE *fp);
uint32_t komodo_heightstamp(int32_t height);
void komodo_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotaries,uint8_t notaryid,uint256 txhash,uint64_t voutmask,uint8_t numvouts,uint32_t *pvals,uint8_t numpvals,int32_t kheight,uint32_t ktime,uint64_t opretvalue,uint8_t *opretbuf,uint16_t opretlen,uint16_t vout,uint256 MoM,int32_t MoMdepth);
void komodo_init(int32_t height);
@@ -59,6 +60,7 @@ uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAI
uint32_t KOMODO_INITDONE;
char KMDUSERPASS[4096],BTCUSERPASS[4096]; uint16_t KMD_PORT = 7771,BITCOIND_PORT = 7771;
uint64_t PENDING_KOMODO_TX;
extern int32_t KOMODO_LOADINGBLOCKS;
struct komodo_kv *KOMODO_KV;
pthread_mutex_t KOMODO_KV_mutex;
pthread_mutex_t KOMODO_KV_mutex,KOMODO_CC_mutex;

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@@ -399,7 +399,6 @@ int32_t komodo_notarized_height(uint256 *hashp,uint256 *txidp)
}
}
struct notarized_checkpoint *komodo_npptr(int32_t height)
{
char symbol[KOMODO_ASSETCHAIN_MAXLEN],dest[KOMODO_ASSETCHAIN_MAXLEN]; int32_t i; struct komodo_state *sp; struct notarized_checkpoint *np = 0;
@@ -543,50 +542,4 @@ void komodo_init(int32_t height)
didinit = 1;
komodo_stateupdate(0,0,0,0,zero,0,0,0,0,0,0,0,0,0,0,zero,0);
}
/*else if ( 0 && height == KOMODO_MAINNET_START )
{
n = (int32_t)(sizeof(Notaries_elected)/sizeof(*Notaries_elected));
for (k=0; k<n; k++)
{
if ( Notaries_elected[k][0] == 0 || Notaries_elected[k][1] == 0 || Notaries_elected[k][0][0] == 0 || Notaries_elected[k][1][0] == 0 )
break;
decode_hex(pubkeys[k],33,(char *)Notaries_elected[k][1]);
}
printf("set MAINNET notaries.%d\n",k);
komodo_notarysinit(KOMODO_MAINNET_START,pubkeys,k);
}*/
}
/*void komodo_assetchain_pubkeys(char *jsonstr)
{
cJSON *array; int32_t i,n; uint8_t pubkeys[64][33]; char *hexstr;
memset(pubkeys,0,sizeof(pubkeys));
if ( (array= cJSON_Parse(jsonstr)) != 0 )
{
if ( (n= cJSON_GetArraySize(array)) > 0 )
{
for (i=0; i<n; i++)
{
if ( (hexstr= jstri(array,i)) != 0 && is_hexstr(hexstr,0) == 66 )
{
decode_hex(pubkeys[i],33,hexstr);
fprintf(stderr,"i.%d of n.%d pubkey.(%s)\n",i,n,hexstr);
}
else
{
fprintf(stderr,"illegal hexstr.(%s) i.%d of n.%d\n",hexstr,i,n);
break;
}
}
if ( i == n )
{
komodo_init(-1);
komodo_notarysinit(0,pubkeys,n);
KOMODO_EXTERNAL_NOTARIES = 1;
//printf("initialize pubkeys[%d]\n",n);
} else fprintf(stderr,"komodo_assetchain_pubkeys i.%d vs n.%d\n",i,n);
} else fprintf(stderr,"assetchain pubkeys n.%d\n",n);
}
//else if ( jsonstr != 0 )
// fprintf(stderr,"assetchain pubkeys couldnt parse.(%s)\n",jsonstr);
}*/

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@@ -89,6 +89,30 @@ struct notarized_checkpoint
int32_t nHeight,notarized_height,MoMdepth,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi;
};
struct komodo_ccdataMoM
{
uint256 MoM;
int32_t MoMdepth,notarized_height,height,txi;
};
struct komodo_ccdata_entry { uint256 MoM; int32_t notarized_height,kmdheight,txi; char symbol[65]; };
struct komodo_ccdatapair { int32_t notarized_height,MoMoMoffset; };
struct komodo_ccdataMoMoM
{
uint256 MoMoM;
int32_t kmdstarti,kmdendi,MoMoMoffset,MoMoMdepth,numpairs,len;
struct komodo_ccdatapair *pairs;
};
struct komodo_ccdata
{
struct komodo_ccdata *next,*prev;
struct komodo_ccdataMoM MoMdata;
uint32_t CCid,len;
char symbol[65];
};
struct komodo_state
{
uint256 NOTARIZED_HASH,NOTARIZED_DESTTXID,MoM;

View File

@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright © 2014-2017 The SuperNET Developers. *
* Copyright © 2014-2018 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
@@ -1365,7 +1365,7 @@ void komodo_configfile(char *symbol,uint16_t port)
#ifndef FROM_CLI
if ( (fp= fopen(fname,"wb")) != 0 )
{
fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=64\nrpcallowip=127.0.0.1\n",crc,password,port);
fprintf(fp,"rpcuser=user%u\nrpcpassword=pass%s\nrpcport=%u\nserver=1\ntxindex=1\nrpcworkqueue=256\nrpcallowip=127.0.0.1\n",crc,password,port);
fclose(fp);
printf("Created (%s)\n",fname);
} else printf("Couldnt create (%s)\n",fname);
@@ -1528,7 +1528,7 @@ void komodo_args(char *argv0)
}
}
}
ASSETCHAINS_CC = GetArg("-ac_cc",0); // keep it outside the assetchains hashing so KMD can do it and we dont have two identical chains other than -ac_cc
ASSETCHAINS_CC = GetArg("-ac_cc",0);
if ( (KOMODO_REWIND= GetArg("-rewind",0)) != 0 )
{
printf("KOMODO_REWIND %d\n",KOMODO_REWIND);
@@ -1575,7 +1575,7 @@ void komodo_args(char *argv0)
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_REWARD),(void *)&ASSETCHAINS_REWARD);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_HALVING),(void *)&ASSETCHAINS_HALVING);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_DECAY),(void *)&ASSETCHAINS_DECAY);
val = ASSETCHAINS_COMMISSION | ((ASSETCHAINS_STAKED & 0xff) << 32);
val = ASSETCHAINS_COMMISSION | (((uint64_t)ASSETCHAINS_STAKED & 0xff) << 32) | (((uint64_t)ASSETCHAINS_CC & 0xffffff) << 40);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(val),(void *)&val);
}
addn = GetArg("-seednode","");
@@ -1696,3 +1696,24 @@ struct komodo_state *komodo_stateptr(char *symbol,char *dest)
komodo_nameset(symbol,dest,ASSETCHAINS_SYMBOL);
return(komodo_stateptrget(symbol));
}
void komodo_prefetch(FILE *fp)
{
long fsize,fpos; int32_t incr = 16*1024*1024;
fpos = ftell(fp);
fseek(fp,0,SEEK_END);
fsize = ftell(fp);
if ( fsize > incr )
{
char *ignore = (char *)malloc(incr);
if ( ignore != 0 )
{
rewind(fp);
while ( fread(ignore,1,incr,fp) == incr ) // prefetch
fprintf(stderr,".");
free(ignore);
}
}
fseek(fp,fpos,SEEK_SET);
}

View File

@@ -1600,7 +1600,7 @@ bool GetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock
if (pindexSlow) {
CBlock block;
if (ReadBlockFromDisk(block, pindexSlow)) {
if (ReadBlockFromDisk(block, pindexSlow,1)) {
BOOST_FOREACH(const CTransaction &tx, block.vtx) {
if (tx.GetHash() == hash) {
txOut = tx;
@@ -1655,7 +1655,7 @@ bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::M
return true;
}
bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos)
bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos,bool checkPOW)
{
uint8_t pubkey33[33];
block.SetNull();
@@ -1677,23 +1677,26 @@ bool ReadBlockFromDisk(int32_t height,CBlock& block, const CDiskBlockPos& pos)
return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString());
}
// Check the header
komodo_block2pubkey33(pubkey33,(CBlock *)&block);
if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime)))
if ( checkPOW != 0 )
{
int32_t i; for (i=0; i<33; i++)
fprintf(stderr,"%02x",pubkey33[i]);
fprintf(stderr," warning unexpected diff at ht.%d\n",height);
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
komodo_block2pubkey33(pubkey33,(CBlock *)&block);
if (!(CheckEquihashSolution(&block, Params()) && CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime)))
{
int32_t i; for (i=0; i<33; i++)
fprintf(stderr,"%02x",pubkey33[i]);
fprintf(stderr," warning unexpected diff at ht.%d\n",height);
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
}
}
return true;
}
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex)
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW)
{
if ( pindex == 0 )
return false;
if (!ReadBlockFromDisk(pindex->nHeight,block, pindex->GetBlockPos()))
if (!ReadBlockFromDisk(pindex->nHeight,block, pindex->GetBlockPos(),checkPOW))
return false;
if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",
@@ -2249,7 +2252,6 @@ namespace {
catch (const std::exception& e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}
// Verify checksum
CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
hasher << hashBlock;
@@ -2331,7 +2333,6 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
if (blockUndo.vtxundo.size() + 1 != block.vtx.size())
return error("DisconnectBlock(): block and undo data inconsistent");
std::vector<std::pair<CAddressIndexKey, CAmount> > addressIndex;
std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > addressUnspentIndex;
std::vector<std::pair<CSpentIndexKey, CSpentIndexValue> > spentIndex;
@@ -2340,7 +2341,6 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
for (int i = block.vtx.size() - 1; i >= 0; i--) {
const CTransaction &tx = block.vtx[i];
uint256 hash = tx.GetHash();
if (fAddressIndex) {
for (unsigned int k = tx.vout.size(); k-- > 0;) {
@@ -2681,7 +2681,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (!view.HaveJoinSplitRequirements(tx))
return state.DoS(100, error("ConnectBlock(): JoinSplit requirements not met"),
REJECT_INVALID, "bad-txns-joinsplit-requirements-not-met");
if (fAddressIndex || fSpentIndex)
{
for (size_t j = 0; j < tx.vin.size(); j++) {
@@ -2718,7 +2717,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
}
}
// Add in sigops done by pay-to-script-hash inputs;
// this is to prevent a "rogue miner" from creating
// an incredibly-expensive-to-validate block.
@@ -2862,7 +2860,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (fTxIndex)
if (!pblocktree->WriteTxIndex(vPos))
return AbortNode(state, "Failed to write transaction index");
if (fAddressIndex) {
if (!pblocktree->WriteAddressIndex(addressIndex)) {
return AbortNode(state, "Failed to write address index");
@@ -3086,7 +3083,7 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) {
assert(pindexDelete);
// Read block from disk.
CBlock block;
if (!ReadBlockFromDisk(block, pindexDelete))
if (!ReadBlockFromDisk(block, pindexDelete,1))
return AbortNode(state, "Failed to read block");
// Apply the block atomically to the chain state.
uint256 anchorBeforeDisconnect = pcoinsTip->GetBestAnchor();
@@ -3153,7 +3150,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock *
int64_t nTime1 = GetTimeMicros();
CBlock block;
if (!pblock) {
if (!ReadBlockFromDisk(block, pindexNew))
if (!ReadBlockFromDisk(block, pindexNew,1))
return AbortNode(state, "Failed to read block");
pblock = &block;
}
@@ -3752,9 +3749,11 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl
return state.DoS(100, error("CheckBlockHeader(): block version too low"),REJECT_INVALID, "version-too-low");
// Check Equihash solution is valid
/*if ( fCheckPOW && !CheckEquihashSolution(&blockhdr, Params()) )
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");*/
if ( fCheckPOW )
{
if ( !CheckEquihashSolution(&blockhdr, Params()) )
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");
}
// Check proof of work matches claimed amount
/*komodo_index2pubkey33(pubkey33,pindex,height);
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,blockhdr.GetHash(), blockhdr.nBits, Params().GetConsensus(),blockhdr.nTime) )
@@ -3764,37 +3763,38 @@ bool CheckBlockHeader(int32_t height,CBlockIndex *pindex, const CBlockHeader& bl
int32_t komodo_check_deposit(int32_t height,const CBlock& block,uint32_t prevtime);
int32_t komodo_reverify_blockcheck(CValidationState& state,int32_t height,CBlockIndex *pindex)
int32_t komodo_fast_checkPOW(CBlock *pblock,int32_t height)
{
static int32_t oneshot;
CBlockIndex *tipindex; int32_t rewindtarget;
if ( KOMODO_REWIND != 0 )
oneshot = KOMODO_REWIND;
if ( oneshot == 0 && IsInitialBlockDownload() == 0 && (tipindex= chainActive.Tip()) != 0 )
arith_uint256 bnTarget; bool fNegative,fOverflow; uint8_t pubkey33[33],pubkeys[64][33]; int32_t i,n,failed = 0,notaryid = -1;
if ( height == 0 )
return(0);
if ( !CheckEquihashSolution(pblock, Params()) )
{
// if 200 blocks behind longestchain and no blocks for 2 hours
if ( KOMODO_LONGESTCHAIN > height+200 && KOMODO_NEWBLOCKS == 0 )
fprintf(stderr,"komodo_fast_checkPOW ht.%d CheckEquihashSolution failed\n",height);
return(-1);
}
bnTarget.SetCompact(pblock->nBits,&fNegative,&fOverflow);
if ( UintToArith256(pblock->GetHash()) > bnTarget )
{
failed = 1;
if ( ASSETCHAINS_SYMBOL[0] == 0 )
{
if ( GetAdjustedTime() > tipindex->nTime+3600*2 )
komodo_block2pubkey33(pubkey33,pblock);
if ( (n= komodo_notaries(pubkeys,height,pblock->nTime)) > 0 )
{
fprintf(stderr,"possible fork: tip.%d longest.%d newblock.%d lag.%d blocktime.%u\n",tipindex->nHeight,KOMODO_LONGESTCHAIN,height,(int32_t)(GetAdjustedTime() - tipindex->nTime),tipindex->nTime);
/*KOMODO_REWIND = tipindex->nHeight - 11;
rewindtarget = tipindex->nHeight - 11;
fprintf(stderr,"rewindtarget <- %d\n",rewindtarget);
oneshot = 1;
while ( rewindtarget > 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->nHeight > rewindtarget )
{
fprintf(stderr,"%d ",(int32_t)tipindex->nHeight);
InvalidateBlock(state,tipindex);
if ( !DisconnectTip(state) )
break;
}
tipindex = chainActive.Tip();
fprintf(stderr,"rewind done to %d\n",tipindex!=0?tipindex->nHeight:-1);*/
for (i=0; i<n; i++)
if ( memcmp(pubkey33,pubkeys[i],33) == 0 )
{
notaryid = i;
break;
}
}
}
}
return(0);
fprintf(stderr,"komodo_fast_checkPOW ht.%d notaryid.%d failed.%d\n",height,notaryid,failed);
if ( failed != 0 && notaryid < 0 )
return(-1);
else return(0);
}
bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidationState& state,
@@ -3812,26 +3812,23 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
return false;
}
if ( fCheckPOW && !CheckEquihashSolution(&block, Params()) )
return state.DoS(100, error("CheckBlockHeader(): Equihash solution invalid"),REJECT_INVALID, "invalid-solution");
return state.DoS(100, error("CheckBlock: Equihash solution invalid"),REJECT_INVALID, "invalid-solution");
komodo_block2pubkey33(pubkey33,(CBlock *)&block);
if ( fCheckPOW && !CheckProofOfWork(height,pubkey33,block.GetHash(), block.nBits, Params().GetConsensus(),block.nTime) )
{
//komodo_reverify_blockcheck(state,height,pindex);
return state.DoS(1, error("CheckBlock(): proof of work failed"),REJECT_INVALID, "high-hash");
}
return state.DoS(1, error("CheckBlock: proof of work failed"),REJECT_INVALID, "high-hash");
// Check the merkle root.
if (fCheckMerkleRoot) {
bool mutated;
uint256 hashMerkleRoot2 = block.BuildMerkleTree(&mutated);
if (block.hashMerkleRoot != hashMerkleRoot2)
return state.DoS(100, error("CheckBlock(): hashMerkleRoot mismatch"),
return state.DoS(100, error("CheckBlock: hashMerkleRoot mismatch"),
REJECT_INVALID, "bad-txnmrklroot", true);
// Check for merkle tree malleability (CVE-2012-2459): repeating sequences
// of transactions in a block without affecting the merkle root of a block,
// while still invalidating it.
if (mutated)
return state.DoS(100, error("CheckBlock(): duplicate transaction"),
return state.DoS(100, error("CheckBlock: duplicate transaction"),
REJECT_INVALID, "bad-txns-duplicate", true);
}
@@ -3841,16 +3838,16 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
// Size limits
if (block.vtx.empty() || block.vtx.size() > MAX_BLOCK_SIZE || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
return state.DoS(100, error("CheckBlock(): size limits failed"),
return state.DoS(100, error("CheckBlock: size limits failed"),
REJECT_INVALID, "bad-blk-length");
// First transaction must be coinbase, the rest must not be
if (block.vtx.empty() || !block.vtx[0].IsCoinBase())
return state.DoS(100, error("CheckBlock(): first tx is not coinbase"),
return state.DoS(100, error("CheckBlock: first tx is not coinbase"),
REJECT_INVALID, "bad-cb-missing");
for (unsigned int i = 1; i < block.vtx.size(); i++)
if (block.vtx[i].IsCoinBase())
return state.DoS(100, error("CheckBlock(): more than one coinbase"),
return state.DoS(100, error("CheckBlock: more than one coinbase"),
REJECT_INVALID, "bad-cb-multiple");
// Check transactions
@@ -3859,7 +3856,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
if ( komodo_validate_interest(tx,height == 0 ? komodo_block2height((CBlock *)&block) : height,block.nTime,1) < 0 )
return error("CheckBlock: komodo_validate_interest failed");
if (!CheckTransaction(tx, state, verifier))
return error("CheckBlock(): CheckTransaction failed");
return error("CheckBlock: CheckTransaction failed");
}
unsigned int nSigOps = 0;
BOOST_FOREACH(const CTransaction& tx, block.vtx)
@@ -3867,13 +3864,12 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
nSigOps += GetLegacySigOpCount(tx);
}
if (nSigOps > MAX_BLOCK_SIGOPS)
return state.DoS(100, error("CheckBlock(): out-of-bounds SigOpCount"),
return state.DoS(100, error("CheckBlock: out-of-bounds SigOpCount"),
REJECT_INVALID, "bad-blk-sigops", true);
if ( komodo_check_deposit(height,block,(pindex==0||pindex->pprev==0)?0:pindex->pprev->nTime) < 0 )
//if ( komodo_check_deposit(ASSETCHAINS_SYMBOL[0] == 0 ? height : pindex != 0 ? (int32_t)pindex->nHeight : chainActive.Tip()->nHeight+1,block,pindex==0||pindex->pprev==0?0:pindex->pprev->nTime) < 0 )
{
static uint32_t counter;
//if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
fprintf(stderr,"check deposit rejection\n");
return(false);
}
@@ -3911,11 +3907,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
if (!Checkpoints::CheckBlock(chainParams.Checkpoints(), nHeight, hash))
{
/*CBlockIndex *heightblock = chainActive[nHeight];
if ( heightblock != 0 && heightblock->GetBlockHash() == hash )
{
//fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight);
return true;
}*/
if ( heightblock != 0 && heightblock->GetBlockHash() == hash )
{
//fprintf(stderr,"got a pre notarization block that matches height.%d\n",(int32_t)nHeight);
return true;
}*/
return state.DoS(100, error("%s: rejected by checkpoint lock-in at %d", __func__, nHeight),REJECT_CHECKPOINT, "checkpoint mismatch");
}
// Don't accept any forks from the main chain prior to last checkpoint
@@ -3986,8 +3982,9 @@ bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, CBloc
// Check for duplicate
uint256 hash = block.GetHash();
BlockMap::iterator miSelf = mapBlockIndex.find(hash);
CBlockIndex *pindex = NULL;
if (miSelf != mapBlockIndex.end()) {
CBlockIndex *tipindex,*pindex = NULL;
if (miSelf != mapBlockIndex.end())
{
// Block header is already known.
pindex = miSelf->second;
if (ppindex)
@@ -4126,13 +4123,13 @@ bool ProcessNewBlock(int32_t height,CValidationState &state, CNode* pfrom, CBloc
auto verifier = libzcash::ProofVerifier::Disabled();
if ( chainActive.Tip() != 0 )
komodo_currentheight_set(chainActive.Tip()->nHeight);
if ( ASSETCHAINS_SYMBOL[0] == 0 )
checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0);
else checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0);
checked = CheckBlock(height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0);
{
LOCK(cs_main);
bool fRequested = MarkBlockAsReceived(pblock->GetHash());
fRequested |= fForceProcessing;
if ( checked != 0 && komodo_fast_checkPOW(pblock,height) < 0 )
checked = 0;
if (!checked)
{
if ( pfrom != 0 )
@@ -4189,7 +4186,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex
}
if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW))
{
fprintf(stderr,"TestBlockValidity failure D\n");
//fprintf(stderr,"TestBlockValidity failure D\n");
return false;
}
assert(state.IsValid());
@@ -4313,10 +4310,9 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes)
return true;
}
FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
{
static int32_t didinit[1000]; long fsize,fpos; int32_t incr = 16*1024*1024;
static int32_t didinit[64];
if (pos.IsNull())
return NULL;
boost::filesystem::path path = GetBlockPosFilename(pos, prefix);
@@ -4330,22 +4326,7 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
}
if ( pos.nFile < sizeof(didinit)/sizeof(*didinit) && didinit[pos.nFile] == 0 && strcmp(prefix,(char *)"blk") == 0 )
{
fpos = ftell(file);
fseek(file,0,SEEK_END);
fsize = ftell(file);
if ( fsize > incr )
{
char *ignore = (char *)malloc(incr);
if ( ignore != 0 )
{
rewind(file);
while ( fread(ignore,1,incr,file) == incr )
fprintf(stderr,".");
free(ignore);
fprintf(stderr,"blk.%d loaded %ld bytes set fpos.%ld loading.%d\n",(int)pos.nFile,(long)ftell(file),(long)fpos,KOMODO_LOADINGBLOCKS);
}
}
fseek(file,fpos,SEEK_SET);
komodo_prefetch(file);
didinit[pos.nFile] = 1;
}
if (pos.nPos) {
@@ -4396,9 +4377,10 @@ CBlockIndex * InsertBlockIndex(uint256 hash)
bool static LoadBlockIndexDB()
{
const CChainParams& chainparams = Params();
LogPrintf("%s: start loading guts\n", __func__);
if (!pblocktree->LoadBlockIndexGuts())
return false;
LogPrintf("%s: loaded guts\n", __func__);
boost::this_thread::interruption_point();
// Calculate nChainWork
@@ -4410,7 +4392,9 @@ bool static LoadBlockIndexDB()
vSortedByHeight.push_back(make_pair(pindex->nHeight, pindex));
//komodo_pindex_init(pindex,(int32_t)pindex->nHeight);
}
//fprintf(stderr,"load blockindexDB paired %u\n",(uint32_t)time(NULL));
sort(vSortedByHeight.begin(), vSortedByHeight.end());
//fprintf(stderr,"load blockindexDB sorted %u\n",(uint32_t)time(NULL));
BOOST_FOREACH(const PAIRTYPE(int, CBlockIndex*)& item, vSortedByHeight)
{
CBlockIndex* pindex = item.second;
@@ -4459,7 +4443,8 @@ bool static LoadBlockIndexDB()
pindexBestHeader = pindex;
//komodo_pindex_init(pindex,(int32_t)pindex->nHeight);
}
//fprintf(stderr,"load blockindexDB chained %u\n",(uint32_t)time(NULL));
// Load block file info
pblocktree->ReadLastBlockFile(nLastBlockFile);
vinfoBlockFile.resize(nLastBlockFile + 1);
@@ -4488,6 +4473,7 @@ bool static LoadBlockIndexDB()
}
//komodo_pindex_init(pindex,(int32_t)pindex->nHeight);
}
//fprintf(stderr,"load blockindexDB %u\n",(uint32_t)time(NULL));
for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++)
{
CDiskBlockPos pos(*it, 0);
@@ -4509,7 +4495,6 @@ bool static LoadBlockIndexDB()
// Check whether we have a transaction index
pblocktree->ReadFlag("txindex", fTxIndex);
LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled");
// Check whether we have an address index
pblocktree->ReadFlag("addressindex", fAddressIndex);
LogPrintf("%s: address index %s\n", __func__, fAddressIndex ? "enabled" : "disabled");
@@ -4587,6 +4572,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
CValidationState state;
// No need to verify JoinSplits twice
auto verifier = libzcash::ProofVerifier::Disabled();
//fprintf(stderr,"start VerifyDB %u\n",(uint32_t)time(NULL));
for (CBlockIndex* pindex = chainActive.Tip(); pindex && pindex->pprev; pindex = pindex->pprev)
{
boost::this_thread::interruption_point();
@@ -4595,7 +4581,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
break;
CBlock block;
// check level 0: read from disk
if (!ReadBlockFromDisk(block, pindex))
if (!ReadBlockFromDisk(block, pindex,0))
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
// check level 1: verify block validity
if (nCheckLevel >= 1 && !CheckBlock(pindex->nHeight,pindex,block, state, verifier,0))
@@ -4624,6 +4610,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
if (ShutdownRequested())
return true;
}
//fprintf(stderr,"end VerifyDB %u\n",(uint32_t)time(NULL));
if (pindexFailure)
return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainActive.Height() - pindexFailure->nHeight + 1, nGoodTransactions);
@@ -4635,7 +4622,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth
uiInterface.ShowProgress(_("Verifying blocks..."), std::max(1, std::min(99, 100 - (int)(((double)(chainActive.Height() - pindex->nHeight)) / (double)nCheckDepth * 50))));
pindex = chainActive.Next(pindex);
CBlock block;
if (!ReadBlockFromDisk(block, pindex))
if (!ReadBlockFromDisk(block, pindex,0))
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
if (!ConnectBlock(block, state, pindex, coins,false, true))
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
@@ -4841,7 +4828,6 @@ bool InitBlockIndex() {
// Use the provided setting for -txindex in the new database
fTxIndex = GetBoolArg("-txindex", true);
pblocktree->WriteFlag("txindex", fTxIndex);
// Use the provided setting for -addressindex in the new database
fAddressIndex = GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX);
pblocktree->WriteFlag("addressindex", fAddressIndex);
@@ -4852,7 +4838,6 @@ bool InitBlockIndex() {
fSpentIndex = GetBoolArg("-spentindex", DEFAULT_SPENTINDEX);
pblocktree->WriteFlag("spentindex", fSpentIndex);
LogPrintf("Initializing databases...\n");
// Only add the genesis block if not reindexing (in which case we reuse the one already on disk)
@@ -4896,7 +4881,8 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
int nLoaded = 0;
try {
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION);
//CBufferedFile blkdat(fileIn, 2*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION);
CBufferedFile blkdat(fileIn, 32*MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8, SER_DISK, CLIENT_VERSION);
uint64_t nRewind = blkdat.GetPos();
while (!blkdat.eof()) {
boost::this_thread::interruption_point();
@@ -4962,7 +4948,7 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
std::pair<std::multimap<uint256, CDiskBlockPos>::iterator, std::multimap<uint256, CDiskBlockPos>::iterator> range = mapBlocksUnknownParent.equal_range(head);
while (range.first != range.second) {
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
if (ReadBlockFromDisk(mapBlockIndex[hash]!=0?mapBlockIndex[hash]->nHeight:0,block, it->second))
if (ReadBlockFromDisk(mapBlockIndex[hash]!=0?mapBlockIndex[hash]->nHeight:0,block, it->second,1))
{
LogPrintf("%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
head.ToString());
@@ -5321,7 +5307,7 @@ void static ProcessGetData(CNode* pfrom)
{
// Send block from disk
CBlock block;
if (!ReadBlockFromDisk(block, (*mi).second))
if (!ReadBlockFromDisk(block, (*mi).second,1))
{
assert(!"cannot load block from disk");
}

View File

@@ -780,8 +780,8 @@ bool GetAddressUnspent(uint160 addressHash, int type,
/** Functions for disk access for blocks */
bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart);
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos);
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex);
bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos,bool checkPOW);
bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW);
/** Functions for validating blocks and updating the block tree */

View File

@@ -487,9 +487,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
if ( ASSETCHAINS_SYMBOL[0] == 0 && NOTARY_PUBKEY33[0] != 0 && pblock->nTime < pindexPrev->nTime+60 )
{
pblock->nTime = pindexPrev->nTime + 60;
fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60));
while ( pblock->GetBlockTime() > GetAdjustedTime() + 60 )
sleep(1);
fprintf(stderr,"block.nTime %u vs prev.%u, gettime.%u vs adjusted.%u\n",(uint32_t)pblock->nTime,(uint32_t)(pindexPrev->nTime + 60),(uint32_t)pblock->GetBlockTime(),(uint32_t)(GetAdjustedTime() + 60));
}
pblock->nSolution.clear();
pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]);
@@ -499,14 +499,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn)
{
//static uint32_t counter;
//if ( counter++ < 100 && ASSETCHAINS_STAKED == 0 )
//fprintf(stderr,"warning: miner testblockvalidity failed\n");
// fprintf(stderr,"warning: miner testblockvalidity failed\n");
return(0);
}
}
return pblocktemplate.release();
}
/*
#ifdef ENABLE_WALLET
boost::optional<CScript> GetMinerScriptPubKey(CReserveKey& reservekey)

View File

@@ -57,9 +57,9 @@ unsigned int TxConfirmStats::FindBucketIndex(double val)
auto it = bucketMap.lower_bound(val);
if ( it != bucketMap.end() )
{
static uint32_t counter;
if ( counter++ < 1 )
fprintf(stderr,"%s FindBucketIndex violation: from val %f\n",ASSETCHAINS_SYMBOL,val);
//static uint32_t counter;
//if ( counter++ < 1 )
// fprintf(stderr,"%s FindBucketIndex violation: from val %f\n",ASSETCHAINS_SYMBOL,val);
}
return it->second;
}

View File

@@ -214,7 +214,7 @@ static bool rest_block(HTTPRequest* req,
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not available (pruned data)");
if (!ReadBlockFromDisk(block, pblockindex))
if (!ReadBlockFromDisk(block, pblockindex,1))
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
}

View File

@@ -438,7 +438,7 @@ UniValue getblockdeltas(const UniValue& params, bool fHelp)
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
if(!ReadBlockFromDisk(block, pblockindex))
if(!ReadBlockFromDisk(block, pblockindex,1))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
return blockToDeltasJSON(block, pblockindex);
@@ -693,7 +693,7 @@ UniValue getblock(const UniValue& params, bool fHelp)
if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
if(!ReadBlockFromDisk(block, pblockindex))
if(!ReadBlockFromDisk(block, pblockindex,1))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
if (!fVerbose)
@@ -746,6 +746,7 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
}
#include "komodo_defs.h"
#include "komodo_structs.h"
#define IGUANA_MAXSCRIPTSIZE 10001
#define KOMODO_KVDURATION 1440
@@ -760,6 +761,8 @@ char *bitcoin_address(char *coinaddr,uint8_t addrtype,uint8_t *pubkey_or_rmd160,
int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width);
int32_t komodo_kvsearch(uint256 *refpubkeyp,int32_t current_height,uint32_t *flagsp,int32_t *heightp,uint8_t value[IGUANA_MAXSCRIPTSIZE],uint8_t *key,int32_t keylen);
int32_t komodo_MoM(int32_t *notarized_htp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip);
int32_t komodo_MoMoMdata(char *hexstr,int32_t hexsize,struct komodo_ccdataMoMoM *mdata,char *symbol,int32_t kmdheight,int32_t notarized_height);
struct komodo_ccdata_entry *komodo_allMoMs(int32_t *nump,uint256 *MoMoMp,int32_t kmdstarti,int32_t kmdendi);
UniValue kvsearch(const UniValue& params, bool fHelp)
{
@@ -796,6 +799,74 @@ UniValue kvsearch(const UniValue& params, bool fHelp)
return ret;
}
UniValue allMoMs(const UniValue& params, bool fHelp)
{
struct komodo_ccdata_entry *allMoMs; uint256 MoMoM; int32_t num,i,kmdstarti,kmdendi; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
if ( fHelp || params.size() != 2 )
throw runtime_error("allMoMs kmdstarti kmdendi\n");
LOCK(cs_main);
kmdstarti = atoi(params[0].get_str().c_str());
kmdendi = atoi(params[1].get_str().c_str());
ret.push_back(Pair("kmdstarti",kmdstarti));
ret.push_back(Pair("kmdendi",kmdendi));
if ( (allMoMs= komodo_allMoMs(&num,&MoMoM,kmdstarti,kmdendi)) != 0 )
{
for (i=0; i<num; i++)
{
UniValue item(UniValue::VOBJ);
item.push_back(Pair("MoM",allMoMs[i].MoM.ToString()));
item.push_back(Pair("coin",allMoMs[i].symbol));
item.push_back(Pair("notarized_height",allMoMs[i].notarized_height));
item.push_back(Pair("kmdheight",allMoMs[i].kmdheight));
item.push_back(Pair("txi",allMoMs[i].txi));
a.push_back(item);
}
ret.push_back(Pair("MoMs",a));
ret.push_back(Pair("MoMoM",MoMoM.ToString()));
ret.push_back(Pair("MoMoMdepth",(int)num));
free(allMoMs);
}
return(ret);
}
UniValue MoMoMdata(const UniValue& params, bool fHelp)
{
char *symbol,hexstr[16384+1]; struct komodo_ccdataMoMoM mdata; int32_t i,kmdheight,notarized_height; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
if ( fHelp || params.size() != 3 )
throw runtime_error("MoMoMdata symbol kmdheight notarized_height\n");
LOCK(cs_main);
symbol = (char *)params[0].get_str().c_str();
kmdheight = atoi(params[1].get_str().c_str());
notarized_height = atoi(params[2].get_str().c_str());
ret.push_back(Pair("coin",symbol));
ret.push_back(Pair("kmdheight",kmdheight));
ret.push_back(Pair("notarized_height",notarized_height));
memset(&mdata,0,sizeof(mdata));
if ( komodo_MoMoMdata(hexstr,sizeof(hexstr),&mdata,symbol,kmdheight,notarized_height) == 0 )
{
ret.push_back(Pair("kmdstarti",mdata.kmdstarti));
ret.push_back(Pair("kmdendi",mdata.kmdendi));
ret.push_back(Pair("MoMoM",mdata.MoMoM.ToString()));
ret.push_back(Pair("MoMoMdepth",mdata.MoMoMdepth));
ret.push_back(Pair("numnotarizations",mdata.numpairs));
if ( mdata.pairs != 0 )
{
//fprintf(stderr,"mdata.pairs free %p, numpairs.%d\n",mdata.pairs,mdata.numpairs);
for (i=0; i<mdata.numpairs; i++)
{
UniValue item(UniValue::VOBJ);
item.push_back(Pair("height",(int)mdata.pairs[i].notarized_height));
item.push_back(Pair("MoMoMoffset",(int)mdata.pairs[i].MoMoMoffset));
a.push_back(item);
}
free(mdata.pairs);
}
ret.push_back(Pair("notarizations",a));
ret.push_back(Pair("data",hexstr));
} else ret.push_back(Pair("error","cant calculate MoMoM"));
return(ret);
}
UniValue height_MoM(const UniValue& params, bool fHelp)
{
int32_t height,depth,notarized_height,MoMoMdepth,MoMoMoffset,kmdstarti,kmdendi; uint256 MoM,MoMoM,kmdtxid; uint32_t timestamp = 0; UniValue ret(UniValue::VOBJ); UniValue a(UniValue::VARR);
@@ -891,7 +962,7 @@ UniValue txMoMproof(const UniValue& params, bool fHelp)
if (fHavePruned && !(blockIndex->nStatus & BLOCK_HAVE_DATA) && blockIndex->nTx > 0)
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
if(!ReadBlockFromDisk(block, blockIndex))
if(!ReadBlockFromDisk(block, blockIndex,1))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
// Locate the transaction in the block
@@ -939,7 +1010,7 @@ UniValue minerids(const UniValue& params, bool fHelp)
if ( pblockindex != 0 )
timestamp = pblockindex->GetBlockTime();
}
if ( 0 && (n= komodo_minerids(minerids,height,(int32_t)(sizeof(minerids)/sizeof(*minerids)))) > 0 )
if ( (n= komodo_minerids(minerids,height,(int32_t)(sizeof(minerids)/sizeof(*minerids)))) > 0 )
{
memset(tally,0,sizeof(tally));
numnotaries = komodo_notaries(pubkeys,height,timestamp);
@@ -977,6 +1048,7 @@ UniValue minerids(const UniValue& params, bool fHelp)
a.push_back(item);
}
ret.push_back(Pair("mined", a));
ret.push_back(Pair("numnotaries", numnotaries));
} else ret.push_back(Pair("error", (char *)"couldnt extract minerids"));
return ret;
}

View File

@@ -135,6 +135,8 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "paxpending", 0 },
{ "notaries", 2 },
{ "height_MoM", 1 },
//{ "MoMoMdata", 3 },
{ "allMoMs", 2 },
{ "txMoMproof", 1 },
{ "minerids", 1 },
{ "kvsearch", 1 },

View File

@@ -53,6 +53,10 @@ extern int32_t KOMODO_LASTMINED,JUMBLR_PAUSE;
extern char ASSETCHAINS_SYMBOL[];
int32_t notarizedtxid_height(char *dest,char *txidstr,int32_t *kmdnotarized_heightp);
#define KOMODO_VERSION "0.1.1"
extern uint16_t ASSETCHAINS_PORT;
extern uint32_t ASSETCHAINS_CC;
extern uint32_t ASSETCHAINS_MAGIC;
extern uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY;
UniValue getinfo(const UniValue& params, bool fHelp)
{
@@ -149,6 +153,28 @@ UniValue getinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("lastmined", KOMODO_LASTMINED));
}
}
if ( ASSETCHAINS_CC != 0 )
obj.push_back(Pair("CCid", (int)ASSETCHAINS_CC));
if ( ASSETCHAINS_SYMBOL[0] != 0 )
{
obj.push_back(Pair("name", ASSETCHAINS_SYMBOL));
obj.push_back(Pair("port", ASSETCHAINS_PORT));
obj.push_back(Pair("magic", (int)ASSETCHAINS_MAGIC));
if ( ASSETCHAINS_SUPPLY != 0 )
obj.push_back(Pair("premine", ASSETCHAINS_SUPPLY));
if ( ASSETCHAINS_REWARD != 0 )
obj.push_back(Pair("reward", ASSETCHAINS_REWARD));
if ( ASSETCHAINS_HALVING != 0 )
obj.push_back(Pair("halving", ASSETCHAINS_HALVING));
if ( ASSETCHAINS_DECAY != 0 )
obj.push_back(Pair("decay", ASSETCHAINS_DECAY));
if ( ASSETCHAINS_ENDSUBSIDY != 0 )
obj.push_back(Pair("endsubsidy", ASSETCHAINS_ENDSUBSIDY));
if ( ASSETCHAINS_COMMISSION != 0 )
obj.push_back(Pair("commission", ASSETCHAINS_COMMISSION));
if ( ASSETCHAINS_STAKED != 0 )
obj.push_back(Pair("staked", ASSETCHAINS_STAKED));
}
return obj;
}

View File

@@ -174,6 +174,7 @@ int32_t komodo_longestchain()
CopyNodeStats(vstats);
BOOST_FOREACH(const CNodeStats& stats, vstats)
{
//fprintf(stderr,"komodo_longestchain iter.%d\n",n);
CNodeStateStats statestats;
bool fStateStats = GetNodeStateStats(stats.nodeid,statestats);
ht = 0;

View File

@@ -522,7 +522,7 @@ UniValue gettxoutproof(const UniValue& params, bool fHelp)
}
CBlock block;
if(!ReadBlockFromDisk(block, pblockindex))
if(!ReadBlockFromDisk(block, pblockindex,1))
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
unsigned int ntxFound = 0;

View File

@@ -238,9 +238,11 @@ UniValue help(const UniValue& params, bool fHelp)
return tableRPC.help(strCommand);
}
extern char ASSETCHAINS_SYMBOL[];
UniValue stop(const UniValue& params, bool fHelp)
{
char buf[64];
// Accept the deprecated and ignored 'detach' boolean argument
if (fHelp || params.size() > 1)
throw runtime_error(
@@ -248,7 +250,8 @@ UniValue stop(const UniValue& params, bool fHelp)
"\nStop Komodo server.");
// Shutdown will take long enough that the response should get back
StartShutdown();
return "Komodo server stopping";
sprintf(buf,"%s Komodo server stopping",ASSETCHAINS_SYMBOL);
return buf;
}
/**
@@ -299,6 +302,8 @@ static const CRPCCommand vRPCCommands[] =
{ "blockchain", "paxpending", &paxpending, true },
{ "blockchain", "paxprices", &paxprices, true },
{ "blockchain", "notaries", &notaries, true },
{ "blockchain", "allMoMs", &allMoMs, true },
{ "blockchain", "MoMoMdata", &MoMoMdata, true },
{ "blockchain", "height_MoM", &height_MoM, true },
{ "blockchain", "txMoMproof", &txMoMproof, true },
{ "blockchain", "minerids", &minerids, true },

View File

@@ -312,6 +312,8 @@ extern UniValue z_validateaddress(const UniValue& params, bool fHelp); // in rpc
extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp); // in rpcdisclosure.cpp
extern UniValue z_validatepaymentdisclosure(const UniValue &params, bool fHelp); // in rpcdisclosure.cpp
extern UniValue allMoMs(const UniValue& params, bool fHelp);
extern UniValue MoMoMdata(const UniValue& params, bool fHelp);
extern UniValue height_MoM(const UniValue& params, bool fHelp);
extern UniValue txMoMproof(const UniValue& params, bool fHelp);
extern UniValue notaries(const UniValue& params, bool fHelp);

View File

@@ -3,10 +3,11 @@
#include "common/profiling.hpp"
int main(int argc, char **argv) {
libsnark::inhibit_profiling_info = true;
/*libsnark::inhibit_profiling_info = true;
libsnark::inhibit_profiling_counters = true;
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
return RUN_ALL_TESTS();*/
return(0);
}

View File

@@ -528,10 +528,13 @@ bool CBlockTreeDB::LoadBlockIndexGuts()
if (header.GetHash() != pindexNew->GetBlockHash())
return error("LoadBlockIndex(): block header inconsistency detected: on-disk = %s, in-memory = %s",
diskindex.ToString(), pindexNew->ToString());
uint8_t pubkey33[33];
komodo_index2pubkey33(pubkey33,pindexNew,pindexNew->nHeight);
if (!CheckProofOfWork(pindexNew->nHeight,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus(),pindexNew->nHeight))
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
if ( 0 ) // POW will be checked before any block is connected
{
uint8_t pubkey33[33];
komodo_index2pubkey33(pubkey33,pindexNew,pindexNew->nHeight);
if (!CheckProofOfWork(pindexNew->nHeight,pubkey33,pindexNew->GetBlockHash(), pindexNew->nBits, Params().GetConsensus(),pindexNew->nTime))
return error("LoadBlockIndex(): CheckProofOfWork failed: %s", pindexNew->ToString());
}
pcursor->Next();
} else {
break; // if shutdown requested or finished loading block index

View File

@@ -13,11 +13,13 @@
#include <string.h>
#include "univalue.h"
#include <stdio.h>
namespace
{
static bool ParsePrechecks(const std::string& str)
{
//fprintf(stderr,"Parse.(%s)\n",str.c_str());
if (str.empty()) // No empty string allowed
return false;
if (str.size() >= 1 && (json_isspace(str[0]) || json_isspace(str[str.size()-1]))) // No padding allowed
@@ -309,7 +311,10 @@ bool UniValue::get_bool() const
const std::string& UniValue::get_str() const
{
if (typ != VSTR)
{
//fprintf(stderr,"typ.%d VSTR %d\n",(int32_t)typ,(int32_t)VSTR);
throw std::runtime_error("JSON value is not a string as expected");
}
return getValStr();
}

View File

@@ -719,7 +719,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
const CBlock* pblock {pblockIn};
CBlock block;
if (!pblock) {
ReadBlockFromDisk(block, pindex);
ReadBlockFromDisk(block, pindex,1);
pblock = &block;
}
@@ -1749,7 +1749,7 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
while (pindex) {
CBlock block;
ReadBlockFromDisk(block, pindex);
ReadBlockFromDisk(block, pindex,1);
BOOST_FOREACH(const CTransaction& tx, block.vtx)
{
@@ -1825,7 +1825,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate)
ShowProgress(_("Rescanning..."), std::max(1, std::min(99, (int)((Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false) - dProgressStart) / (dProgressTip - dProgressStart) * 100))));
CBlock block;
ReadBlockFromDisk(block, pindex);
ReadBlockFromDisk(block, pindex,1);
BOOST_FOREACH(CTransaction& tx, block.vtx)
{
if (AddToWalletIfInvolvingMe(tx, &block, fUpdate))
@@ -3041,14 +3041,26 @@ CAmount CWallet::GetMinimumFee(unsigned int nTxBytes, unsigned int nConfirmTarge
}
void komodo_prefetch(FILE *fp);
DBErrors CWallet::LoadWallet(bool& fFirstRunRet)
{
if (!fFileBacked)
return DB_LOAD_OK;
fFirstRunRet = false;
if ( 0 ) // doesnt help
{
fprintf(stderr,"loading wallet %s %u\n",strWalletFile.c_str(),(uint32_t)time(NULL));
FILE *fp;
if ( (fp= fopen(strWalletFile.c_str(),"rb")) != 0 )
{
komodo_prefetch(fp);
fclose(fp);
}
}
//fprintf(stderr,"prefetched wallet %s %u\n",strWalletFile.c_str(),(uint32_t)time(NULL));
DBErrors nLoadWalletRet = CWalletDB(strWalletFile,"cr+").LoadWallet(this);
//fprintf(stderr,"loaded wallet %s %u\n",strWalletFile.c_str(),(uint32_t)time(NULL));
if (nLoadWalletRet == DB_NEED_REWRITE)
{
if (CDB::Rewrite(strWalletFile, "\x04pool"))

View File

@@ -167,7 +167,7 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex)
{
LOCK(cs_main);
CBlock block;
if(!ReadBlockFromDisk(block, pindex))
if(!ReadBlockFromDisk(block, pindex,1))
{
zmqError("Can't read block from disk");
return false;