Clean fix and speedup
This commit is contained in:
@@ -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 *
|
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
|
||||||
* the top-level directory of this distribution for the individual copyright *
|
* the top-level directory of this distribution for the individual copyright *
|
||||||
@@ -662,7 +662,9 @@ int32_t komodo_block2height(CBlock *block)
|
|||||||
void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
|
void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block)
|
||||||
{
|
{
|
||||||
int32_t n;
|
int32_t n;
|
||||||
memset(pubkey33,0,33);
|
if ( KOMODO_LOADINGBLOCKS == 0 )
|
||||||
|
memset(pubkey33,0xff,33);
|
||||||
|
else memset(pubkey33,0,33);
|
||||||
if ( block.vtx[0].vout.size() > 0 )
|
if ( block.vtx[0].vout.size() > 0 )
|
||||||
{
|
{
|
||||||
#ifdef KOMODO_ZCASH
|
#ifdef KOMODO_ZCASH
|
||||||
@@ -722,60 +724,68 @@ uint32_t komodo_heightstamp(int32_t height)
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
|
void komodo_pindex_init(CBlockIndex *pindex,int32_t height)
|
||||||
{
|
{
|
||||||
CBlock block; int32_t num,i; uint8_t pubkeys[64][33];
|
int32_t i,num; uint8_t pubkeys[64][33]; CBlock block;
|
||||||
//komodo_init(height);
|
if ( pindex->didinit != 0 )
|
||||||
memset(pubkey33,0,33);
|
|
||||||
if ( pindex != 0 )
|
|
||||||
{
|
|
||||||
if ( pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3 )
|
|
||||||
{
|
|
||||||
memcpy(pubkey33,pindex->pubkey33,33);
|
|
||||||
return;
|
return;
|
||||||
}
|
//printf("pindex.%d komodo_pindex_init notary.%d from height.%d\n",pindex->nHeight,pindex->notaryid,height);
|
||||||
if ( komodo_blockload(block,pindex) == 0 )
|
if ( pindex->didinit == 0 )
|
||||||
{
|
|
||||||
komodo_block2pubkey33(pubkey33,block);
|
|
||||||
if ( (pubkey33[0] == 2 || pubkey33[0] == 3) )
|
|
||||||
{
|
|
||||||
memcpy(pindex->pubkey33,pubkey33,33);
|
|
||||||
if ( (num= komodo_notaries(pubkeys,(int32_t)pindex->nHeight,(uint32_t)pindex->nTime)) > 0 )
|
|
||||||
{
|
{
|
||||||
pindex->notaryid = -1;
|
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);
|
||||||
|
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++)
|
for (i=0; i<num; i++)
|
||||||
{
|
{
|
||||||
if ( memcmp(pubkeys[i],pubkey33,33) == 0 )
|
if ( memcmp(pubkeys[i],pindex->pubkey33,33) == 0 )
|
||||||
{
|
{
|
||||||
pindex->notaryid = i;
|
pindex->notaryid = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if ( 0 && i == num )
|
||||||
} else pindex->notaryid = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// height -> pubkey33
|
for (i=0; i<33; i++)
|
||||||
//printf("extending chaintip komodo_index2pubkey33 height.%d need to get pubkey33\n",height);
|
fprintf(stderr,"%02x",pindex->pubkey33[i]);
|
||||||
|
fprintf(stderr," unmatched pubkey at height %d/%d\n",pindex->nHeight,height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void komodo_connectpindex(CBlockIndex *pindex)
|
void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height)
|
||||||
{
|
{
|
||||||
CBlock block;
|
CBlock block; int32_t num,i;
|
||||||
if ( komodo_blockload(block,pindex) == 0 )
|
memset(pubkey33,0,33);
|
||||||
komodo_connectblock(pindex,block);
|
if ( pindex != 0 )
|
||||||
}*/
|
{
|
||||||
|
if ( pindex->didinit != 0 )
|
||||||
|
{
|
||||||
|
memcpy(pubkey33,pindex->pubkey33,33);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
komodo_pindex_init(pindex,height);
|
||||||
|
memcpy(pubkey33,pindex->pubkey33,33);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int8_t komodo_minerid(int32_t height,uint8_t *pubkey33)
|
int8_t komodo_minerid(int32_t height,uint8_t *pubkey33)
|
||||||
{
|
{
|
||||||
int32_t num,i,numnotaries; CBlockIndex *pindex; uint32_t timestamp=0; uint8_t _pubkey33[33],pubkeys[64][33];
|
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= chainActive[height]) != 0 )
|
||||||
{
|
{
|
||||||
if ( (pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3) )
|
if ( pindex->didinit != 0 )
|
||||||
{
|
{
|
||||||
if ( pubkey33 != 0 )
|
if ( pubkey33 != 0 )
|
||||||
memcpy(pubkey33,pindex->pubkey33,33);
|
memcpy(pubkey33,pindex->pubkey33,33);
|
||||||
@@ -802,7 +812,7 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *non
|
|||||||
{
|
{
|
||||||
if ( (pindex= komodo_chainactive(height-i)) != 0 )
|
if ( (pindex= komodo_chainactive(height-i)) != 0 )
|
||||||
{
|
{
|
||||||
if ( pindex->notaryid >= 0 && (pindex->pubkey33[0] == 2 || pindex->pubkey33[0] == 3) )
|
if ( pindex->notaryid >= 0 && pindex->didinit != 0 )
|
||||||
{
|
{
|
||||||
memcpy(pubkeys[i],pindex->pubkey33,33);
|
memcpy(pubkeys[i],pindex->pubkey33,33);
|
||||||
mids[i] = pindex->notaryid;
|
mids[i] = pindex->notaryid;
|
||||||
@@ -810,8 +820,9 @@ int32_t komodo_eligiblenotary(uint8_t pubkeys[66][33],int32_t *mids,int32_t *non
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
komodo_index2pubkey33(pubkey33,pindex,height-i);
|
komodo_pindex_init(pindex,height-i);
|
||||||
memcpy(pubkeys[i],pubkey33,33);
|
//komodo_index2pubkey33(pubkey33,pindex,height-i);
|
||||||
|
memcpy(pubkeys[i],pindex->pubkey33,33);
|
||||||
if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 )
|
if ( (mids[i]= komodo_minerid(height-i,pubkey33)) >= 0 )
|
||||||
{
|
{
|
||||||
//mids[i] = *(int32_t *)pubkey33;
|
//mids[i] = *(int32_t *)pubkey33;
|
||||||
@@ -837,13 +848,16 @@ int32_t komodo_minerids(uint8_t *minerids,int32_t height,int32_t width) // depre
|
|||||||
minerids[i] = komodo_minerid(height - i,0);
|
minerids[i] = komodo_minerid(height - i,0);
|
||||||
}
|
}
|
||||||
return(n);*/
|
return(n);*/
|
||||||
|
fprintf(stderr,"komodo_minerids is deprecated\n");
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp)
|
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp)
|
||||||
{
|
{
|
||||||
int32_t i,notaryid=0,minerid,limit,nid; //uint8_t _pubkey33[33];
|
int32_t i,notaryid=0,minerid,limit,nid; //uint8_t _pubkey33[33];
|
||||||
if ( height >= 790000 )
|
if ( height >= 225000 )
|
||||||
|
komodo_chosennotary(¬aryid,height,pubkey33,timestamp);
|
||||||
|
if ( height >= 700000 )
|
||||||
{
|
{
|
||||||
if ( mids[0] >= 0 )
|
if ( mids[0] >= 0 )
|
||||||
{
|
{
|
||||||
@@ -862,8 +876,6 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t heigh
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( height >= 225000 )
|
|
||||||
komodo_chosennotary(¬aryid,height,pubkey33,timestamp);
|
|
||||||
if ( height >= 34000 && notaryid >= 0 )
|
if ( height >= 34000 && notaryid >= 0 )
|
||||||
{
|
{
|
||||||
if ( height < 79693 )
|
if ( height < 79693 )
|
||||||
@@ -889,10 +901,10 @@ int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t heigh
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight)
|
int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,int32_t nHeight,uint256 *MoMoMp,int32_t *MoMoMoffsetp,int32_t *MoMoMdepthp,int32_t *kmdstartip,int32_t *kmdendip)
|
||||||
{
|
{
|
||||||
int32_t depth,notarized_ht; uint256 MoM,kmdtxid;
|
int32_t depth,notarized_ht; uint256 MoM,kmdtxid;
|
||||||
depth = komodo_MoMdata(¬arized_ht,&MoM,&kmdtxid,nHeight);
|
depth = komodo_MoMdata(¬arized_ht,&MoM,&kmdtxid,nHeight,MoMoMp,MoMoMoffsetp,MoMoMdepthp,kmdstartip,kmdendip);
|
||||||
memset(MoMp,0,sizeof(*MoMp));
|
memset(MoMp,0,sizeof(*MoMp));
|
||||||
memset(kmdtxidp,0,sizeof(*kmdtxidp));
|
memset(kmdtxidp,0,sizeof(*kmdtxidp));
|
||||||
*notarized_heightp = 0;
|
*notarized_heightp = 0;
|
||||||
|
|||||||
24
src/main.cpp
24
src/main.cpp
@@ -53,6 +53,7 @@ using namespace std;
|
|||||||
|
|
||||||
CCriticalSection cs_main;
|
CCriticalSection cs_main;
|
||||||
extern uint8_t NOTARY_PUBKEY33[33];
|
extern uint8_t NOTARY_PUBKEY33[33];
|
||||||
|
extern int32_t KOMODO_LOADINGBLOCKS;
|
||||||
|
|
||||||
BlockMap mapBlockIndex;
|
BlockMap mapBlockIndex;
|
||||||
CChain chainActive;
|
CChain chainActive;
|
||||||
@@ -4037,6 +4038,7 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes)
|
|||||||
|
|
||||||
FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
|
FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
|
||||||
{
|
{
|
||||||
|
static int32_t didinit; long fsize,fpos; int32_t incr = 16*1024*1024;
|
||||||
if (pos.IsNull())
|
if (pos.IsNull())
|
||||||
return NULL;
|
return NULL;
|
||||||
boost::filesystem::path path = GetBlockPosFilename(pos, prefix);
|
boost::filesystem::path path = GetBlockPosFilename(pos, prefix);
|
||||||
@@ -4048,6 +4050,27 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
|
|||||||
LogPrintf("Unable to open file %s\n", path.string());
|
LogPrintf("Unable to open file %s\n", path.string());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if ( didinit == 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,"loaded %ld bytes set fpos.%ld loading.%d\n",(long)ftell(file),(long)fpos,KOMODO_LOADINGBLOCKS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fseek(file,fpos,SEEK_SET);
|
||||||
|
KOMODO_LOADINGBLOCKS = 0;
|
||||||
|
didinit = 1;
|
||||||
|
}
|
||||||
if (pos.nPos) {
|
if (pos.nPos) {
|
||||||
if (fseek(file, pos.nPos, SEEK_SET)) {
|
if (fseek(file, pos.nPos, SEEK_SET)) {
|
||||||
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
|
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
|
||||||
@@ -4491,7 +4514,6 @@ void UnloadBlockIndex()
|
|||||||
|
|
||||||
bool LoadBlockIndex()
|
bool LoadBlockIndex()
|
||||||
{
|
{
|
||||||
extern int32_t KOMODO_LOADINGBLOCKS;
|
|
||||||
// Load block index from databases
|
// Load block index from databases
|
||||||
KOMODO_LOADINGBLOCKS = 1;
|
KOMODO_LOADINGBLOCKS = 1;
|
||||||
if (!fReindex && !LoadBlockIndexDB())
|
if (!fReindex && !LoadBlockIndexDB())
|
||||||
|
|||||||
31
src/pow.cpp
31
src/pow.cpp
@@ -116,6 +116,7 @@ bool CheckEquihashSolution(const CBlockHeader *pblock, const CChainParams& param
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void komodo_pindex_init(CBlockIndex *pindex,int32_t height);
|
||||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
|
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
|
||||||
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp);
|
int32_t komodo_is_special(uint8_t pubkeys[66][33],int32_t mids[66],int32_t height,uint8_t pubkey33[33],uint32_t timestamp);
|
||||||
int32_t komodo_currentheight();
|
int32_t komodo_currentheight();
|
||||||
@@ -134,7 +135,7 @@ extern std::string NOTARY_PUBKEY;
|
|||||||
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
|
bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params)
|
||||||
{
|
{
|
||||||
extern int32_t KOMODO_REWIND;
|
extern int32_t KOMODO_REWIND;
|
||||||
bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,flag = 0, mids[66]; uint32_t timestamp = 0;
|
bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,flag = 0, mids[66]; uint32_t timestamp = 0; CBlockIndex *pindex;
|
||||||
arith_uint256 bnTarget; uint8_t pubkeys[66][33];
|
arith_uint256 bnTarget; uint8_t pubkeys[66][33];
|
||||||
timestamp = komodo_chainactive_timestamp();
|
timestamp = komodo_chainactive_timestamp();
|
||||||
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
|
||||||
@@ -145,6 +146,13 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
}
|
}
|
||||||
if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary
|
if ( height > 34000 && ASSETCHAINS_SYMBOL[0] == 0 ) // 0 -> non-special notary
|
||||||
{
|
{
|
||||||
|
if ( KOMODO_LOADINGBLOCKS == 0 )
|
||||||
|
return(true);
|
||||||
|
if ( (pindex= komodo_chainactive(height)) != 0 )
|
||||||
|
{
|
||||||
|
komodo_pindex_init(pindex,height);
|
||||||
|
memcpy(pubkey33,pindex->pubkey33,33);
|
||||||
|
}
|
||||||
special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp);
|
special = komodo_chosennotary(¬aryid,height,pubkey33,timestamp);
|
||||||
for (i=0; i<33; i++)
|
for (i=0; i<33; i++)
|
||||||
{
|
{
|
||||||
@@ -158,7 +166,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
}
|
}
|
||||||
flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height);
|
flag = komodo_eligiblenotary(pubkeys,mids,&nonzpkeys,height);
|
||||||
special2 = komodo_is_special(pubkeys,mids,height,pubkey33,timestamp);
|
special2 = komodo_is_special(pubkeys,mids,height,pubkey33,timestamp);
|
||||||
//fprintf(stderr,"ht.%d notaryid.%d special.%d flag.%d special2.%d\n",height,notaryid,special,flag,special2);
|
fprintf(stderr,"ht.%d notaryid.%d special.%d flag.%d special2.%d\n",height,notaryid,special,flag,special2);
|
||||||
if ( notaryid >= 0 )
|
if ( notaryid >= 0 )
|
||||||
{
|
{
|
||||||
if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) )
|
if ( height > 10000 && height < 80000 && (special != 0 || special2 > 0) )
|
||||||
@@ -182,7 +190,26 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in
|
|||||||
return error("CheckProofOfWork(): nBits below minimum work");
|
return error("CheckProofOfWork(): nBits below minimum work");
|
||||||
// Check proof of work matches claimed amount
|
// Check proof of work matches claimed amount
|
||||||
if ( UintToArith256(hash) > bnTarget )
|
if ( UintToArith256(hash) > bnTarget )
|
||||||
|
{
|
||||||
|
for (i=31; i>=0; i--)
|
||||||
|
printf("%02x",((uint8_t *)&hash)[i]);
|
||||||
|
printf(" hash vs ");
|
||||||
|
for (i=31; i>=0; i--)
|
||||||
|
printf("%02x",((uint8_t *)&bnTarget)[i]);
|
||||||
|
printf(" ht.%d special.%d notaryid.%d ht.%d mod.%d error\n",height,special,notaryid,height,(height % 35));
|
||||||
|
if ( pindex != 0 )
|
||||||
|
{
|
||||||
|
pindex->didinit = 0;
|
||||||
|
komodo_pindex_init(pindex,height);
|
||||||
|
}
|
||||||
|
for (i=0; i<33; i++)
|
||||||
|
printf("%02x",pubkey33[i]);
|
||||||
|
printf(" <- pubkey\n");
|
||||||
|
for (i=0; i<66; i++)
|
||||||
|
printf("%d ",mids[i]);
|
||||||
|
printf(" minerids from ht.%d pindex.%p\n",height,pindex);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user