Browse Source

WIP with lots of debugging

pull/138/head
Team ChainStrike 6 years ago
parent
commit
80db4aead0
  1. 108
      src/komodo_validation011.h

108
src/komodo_validation011.h

@ -81,7 +81,6 @@ void ImportAddress(CWallet* const pwallet, const CBitcoinAddress& address, const
int32_t gettxout_scriptPubKey(int32_t height,uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n) int32_t gettxout_scriptPubKey(int32_t height,uint8_t *scriptPubKey,int32_t maxsize,uint256 txid,int32_t n)
{ {
static uint256 zero; int32_t i,m; uint8_t *ptr; CTransaction tx; uint256 hashBlock; static uint256 zero; int32_t i,m; uint8_t *ptr; CTransaction tx; uint256 hashBlock;
CTransactionRef txref=0;
LOCK(cs_main); LOCK(cs_main);
if ( KOMODO_TXINDEX != 0 ) if ( KOMODO_TXINDEX != 0 )
{ {
@ -100,23 +99,29 @@ int32_t gettxout_scriptPubKey(int32_t height,uint8_t *scriptPubKey,int32_t maxsi
if ( it != pwallet->mapWallet.end() ) if ( it != pwallet->mapWallet.end() )
{ {
const CWalletTx& wtx = it->second; const CWalletTx& wtx = it->second;
txref = wtx.tx; tx = *wtx.tx;
fprintf(stderr,"found tx in wallet\n"); fprintf(stderr,"found tx in wallet\n");
} }
} }
} }
if ( txref != 0 && n >= 0 && n <= (int32_t)txref->vout.size() ) // vout.size() seems off by 1 if ( &tx != 0 && n >= 0 && n <= (int32_t)tx.vout.size() ) // vout.size() seems off by 1
{ {
ptr = (uint8_t *)txref->vout[n].scriptPubKey.data(); ptr = (uint8_t *)tx.vout[n].scriptPubKey.data();
m = txref->vout[n].scriptPubKey.size(); m = tx.vout[n].scriptPubKey.size();
for (i=0; i<maxsize&&i<m; i++)
fprintf(stderr,"m=%d\n", m);
fprintf(stderr,"maxsize=%d\n", maxsize);
for (i=0; i<maxsize&&i<m; i++) {
fprintf(stderr,"%02x",ptr[i]);
scriptPubKey[i] = ptr[i]; scriptPubKey[i] = ptr[i];
}
fprintf(stderr,"\n");
fprintf(stderr,"got scriptPubKey[%d] via rawtransaction ht.%d %s\n",m,height,txid.GetHex().c_str()); fprintf(stderr,"got scriptPubKey[%d] via rawtransaction ht.%d %s\n",m,height,txid.GetHex().c_str());
return(i); return(i);
} }
else if ( txref != 0 ) else if ( &tx != 0 )
fprintf(stderr,"gettxout_scriptPubKey ht.%d n.%d > voutsize.%d\n",height,n,(int32_t)txref->vout.size()); fprintf(stderr,"gettxout_scriptPubKey ht.%d n.%d > voutsize.%d\n",height,n,(int32_t)tx.vout.size());
return(-1); return(-1);
} }
@ -748,15 +753,14 @@ void komodo_importpubkeys()
if ( (m= (int32_t)strlen((char *)Notaries_elected1[i][offset])) > 0 ) if ( (m= (int32_t)strlen((char *)Notaries_elected1[i][offset])) > 0 )
{ {
pubkey = (char*) Notaries_elected1[i][offset]; pubkey = (char*) Notaries_elected1[i][offset];
//fprintf(stderr,"pubkey=%s\n", pubkey );
const std::vector<unsigned char> vPubkey(pubkey, pubkey + m); const std::vector<unsigned char> vPubkey(pubkey, pubkey + m);
std::string addr = CBitcoinAddress(CPubKey(ParseHex(pubkey)).GetID()).ToString(); std::string addr = CBitcoinAddress(CPubKey(ParseHex(pubkey)).GetID()).ToString();
//fprintf(stderr,"addr=%s\n", addr.c_str() ); fprintf(stderr,"pubkey=%s, addr=%s\n", pubkey, addr.c_str() );
if ( (val= komodo_importaddress(addr)) < 0 ) if ( (val= komodo_importaddress(addr)) < 0 )
fprintf(stderr,"error importing (%s)\n",addr.c_str()); LogPrintf("dpow: error importing (%s)\n",addr.c_str());
else if ( val == 0 ) else if ( val == 0 )
dispflag++; dispflag++;
} }
@ -842,8 +846,8 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
did0 = 1; did0 = 1;
} }
memcpy(pubkeys,elected_pubkeys0,n0 * 33); memcpy(pubkeys,elected_pubkeys0,n0 * 33);
//if ( ASSETCHAINS_SYMBOL[0] != 0 ) if ( ASSETCHAINS_SYMBOL[0] != 0 )
// fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0); fprintf(stderr,"%s height.%d t.%u elected.%d notaries\n",ASSETCHAINS_SYMBOL,height,timestamp,n0);
return(n0); return(n0);
} }
else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 ) else //if ( (timestamp != 0 && timestamp <= KOMODO_NOTARIES_TIMESTAMP2) || height <= KOMODO_NOTARIES_HEIGHT2 )
@ -853,7 +857,7 @@ int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height,uint32_t timestam
n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1)); n1 = (int32_t)(sizeof(Notaries_elected1)/sizeof(*Notaries_elected1));
for (i=0; i<n1; i++) for (i=0; i<n1; i++)
decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]); decode_hex(elected_pubkeys1[i],33,(char *)Notaries_elected1[i][1]);
if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) if ( ASSETCHAINS_SYMBOL[0] != 0 )
fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1); fprintf(stderr,"%s height.%d t.%u elected.%d notaries2\n",ASSETCHAINS_SYMBOL,height,timestamp,n1);
did1 = 1; did1 = 1;
} }
@ -956,7 +960,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n
{ {
if ( NPOINTS[i].nHeight >= nHeight ) if ( NPOINTS[i].nHeight >= nHeight )
{ {
LogPrintf("flag.1 i.%d np->ht %d [%d].ht %d >= nHeight.%d, last.%d num.%d\n",i,np->nHeight,i,NPOINTS[i].nHeight,nHeight,last_NPOINTSi,NUM_NPOINTS); LogPrintf("dpow: flag.1 i.%d np->ht %d [%d].ht %d >= nHeight.%d, last.%d num.%d\n",i,np->nHeight,i,NPOINTS[i].nHeight,nHeight,last_NPOINTSi,NUM_NPOINTS);
flag = 1; flag = 1;
break; break;
} }
@ -996,6 +1000,7 @@ int32_t komodo_notarizeddata(int32_t nHeight,uint256 *notarized_hashp,uint256 *n
void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid,uint256 MoM,int32_t MoMdepth) void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 notarized_hash,uint256 notarized_desttxid,uint256 MoM,int32_t MoMdepth)
{ {
static int didinit; static uint256 zero; static FILE *fp; CBlockIndex *pindex; struct notarized_checkpoint *np,N; long fpos; static int didinit; static uint256 zero; static FILE *fp; CBlockIndex *pindex; struct notarized_checkpoint *np,N; long fpos;
LogPrintf("dpow: komodod_notarized_update\n");
if ( didinit == 0 ) if ( didinit == 0 )
{ {
char fname[512];int32_t latestht = 0; char fname[512];int32_t latestht = 0;
@ -1006,7 +1011,7 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
#else #else
sprintf(fname,"%s/notarizations",GetDefaultDataDir().string().c_str()); sprintf(fname,"%s/notarizations",GetDefaultDataDir().string().c_str());
#endif #endif
// printf("fname.(%s)\n",fname); LogPrintf("dpow: fname.(%s)\n",fname);
if ( (fp= fopen(fname,"rb+")) == 0 ) if ( (fp= fopen(fname,"rb+")) == 0 )
fp = fopen(fname,"wb+"); fp = fopen(fname,"wb+");
else else
@ -1029,7 +1034,7 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
NOTARIZED_MOMDEPTH = np->MoMdepth; NOTARIZED_MOMDEPTH = np->MoMdepth;
fprintf(stderr,"%d ",np->notarized_height); fprintf(stderr,"%d ",np->notarized_height);
fpos = ftell(fp); fpos = ftell(fp);
} //else fprintf(stderr,"%s error with notarization ht.%d %s\n",ASSETCHAINS_SYMBOL,N.notarized_height,pindex->GetBlockHash().ToString().c_str()); } else LogPrintf("dpow: %s error with notarization ht.%d %s\n",ASSETCHAINS_SYMBOL,N.notarized_height,pindex->GetBlockHash().ToString().c_str());
} }
if ( ftell(fp) != fpos ) if ( ftell(fp) != fpos )
fseek(fp,fpos,SEEK_SET); fseek(fp,fpos,SEEK_SET);
@ -1038,19 +1043,22 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
didinit = 1; didinit = 1;
} }
if ( notarized_height == 0 ) if ( notarized_height == 0 )
{
LogPrintf("dpow: notarized_height=0, aborting\n");
return; return;
}
if ( notarized_height >= nHeight ) if ( notarized_height >= nHeight )
{ {
fprintf(stderr,"komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight); LogPrintf("dpow: komodo_notarized_update REJECT notarized_height %d > %d nHeight\n",notarized_height,nHeight);
return; return;
} }
pindex = komodo_chainactive(notarized_height); pindex = komodo_chainactive(notarized_height);
if ( pindex == 0 || pindex->GetBlockHash() != notarized_hash || notarized_height != pindex->nHeight ) if ( pindex == 0 || pindex->GetBlockHash() != notarized_hash || notarized_height != pindex->nHeight )
{ {
fprintf(stderr,"komodo_notarized_update reject nHeight.%d notarized_height.%d:%d\n",nHeight,notarized_height,(int32_t)pindex->nHeight); LogPrintf("dpow: komodo_notarized_update reject nHeight.%d notarized_height.%d:%d\n",nHeight,notarized_height,(int32_t)pindex->nHeight);
return; return;
} }
fprintf(stderr,"komodo_notarized_update nHeight.%d notarized_height.%d prev.%d\n",nHeight,notarized_height,NPOINTS!=0?NPOINTS[NUM_NPOINTS-1].notarized_height:-1); LogPrintf("dpow: komodo_notarized_update nHeight.%d notarized_height.%d prev.%d\n",nHeight,notarized_height,NPOINTS!=0?NPOINTS[NUM_NPOINTS-1].notarized_height:-1);
portable_mutex_lock(&komodo_mutex); portable_mutex_lock(&komodo_mutex);
NPOINTS = (struct notarized_checkpoint *)realloc(NPOINTS,(NUM_NPOINTS+1) * sizeof(*NPOINTS)); NPOINTS = (struct notarized_checkpoint *)realloc(NPOINTS,(NUM_NPOINTS+1) * sizeof(*NPOINTS));
np = &NPOINTS[NUM_NPOINTS++]; np = &NPOINTS[NUM_NPOINTS++];
@ -1059,6 +1067,7 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
NOTARIZED_HEIGHT = np->notarized_height = notarized_height; NOTARIZED_HEIGHT = np->notarized_height = notarized_height;
NOTARIZED_HASH = np->notarized_hash = notarized_hash; NOTARIZED_HASH = np->notarized_hash = notarized_hash;
NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid; NOTARIZED_DESTTXID = np->notarized_desttxid = notarized_desttxid;
printf("NOTARIZED (HEIGHT,HASH,DESTTXID) = (%d, %s, %s)\n", NOTARIZED_HEIGHT, NOTARIZED_HASH.GetHex().c_str(), NOTARIZED_DESTTXID.GetHex().c_str());
if ( MoM != zero && MoMdepth > 0 ) if ( MoM != zero && MoMdepth > 0 )
{ {
NOTARIZED_MOM = np->MoM = MoM; NOTARIZED_MOM = np->MoM = MoM;
@ -1068,7 +1077,7 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
{ {
if ( fwrite(np,1,sizeof(*np),fp) == sizeof(*np) ) if ( fwrite(np,1,sizeof(*np),fp) == sizeof(*np) )
fflush(fp); fflush(fp);
else printf("error writing notarization to %d\n",(int32_t)ftell(fp)); else LogPrintf("dpow: error writing notarization to %d\n",(int32_t)ftell(fp));
} }
// add to stored notarizations // add to stored notarizations
portable_mutex_unlock(&komodo_mutex); portable_mutex_unlock(&komodo_mutex);
@ -1076,7 +1085,6 @@ void komodo_notarized_update(int32_t nHeight,int32_t notarized_height,uint256 no
int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash)
{ {
int32_t notarized_height; uint256 zero,notarized_hash,notarized_desttxid; CBlockIndex *notary; CBlockIndex *pindex; int32_t notarized_height; uint256 zero,notarized_hash,notarized_desttxid; CBlockIndex *notary; CBlockIndex *pindex;
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
//komodo_notarized_update(0,0,zero,zero,zero,0); //komodo_notarized_update(0,0,zero,zero,zero,0);
@ -1126,7 +1134,7 @@ void komodo_voutupdate(int32_t txi,int32_t vout,uint8_t *scriptbuf,int32_t scrip
opretlen = scriptbuf[len++]; opretlen = scriptbuf[len++];
opretlen += (scriptbuf[len++] << 8); opretlen += (scriptbuf[len++] << 8);
} }
//printf("opretlen.%d vout.%d [%s].(%s)\n",opretlen,vout,(char *)&scriptbuf[len+32*2+4],ASSETCHAINS_SYMBOL); printf("opretlen.%d vout.%d [%s].(%s)\n",opretlen,vout,(char *)&scriptbuf[len+32*2+4],ASSETCHAINS_SYMBOL);
if ( vout == 1 && opretlen-3 >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 ) if ( vout == 1 && opretlen-3 >= 32*2+4 && strcmp(ASSETCHAINS_SYMBOL,(char *)&scriptbuf[len+32*2+4]) == 0 )
{ {
len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&hash); len += iguana_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&hash);
@ -1152,12 +1160,12 @@ void komodo_voutupdate(int32_t txi,int32_t vout,uint8_t *scriptbuf,int32_t scrip
} }
else else
{ {
fprintf(stderr,"VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,MoM.ToString().c_str(),MoMdepth); LogPrintf("dpow: VALID %s MoM.%s [%d]\n",ASSETCHAINS_SYMBOL,MoM.ToString().c_str(),MoMdepth);
} }
} }
komodo_notarized_update(height,*notarizedheightp,hash,desttxid,MoM,MoMdepth); komodo_notarized_update(height,*notarizedheightp,hash,desttxid,MoM,MoMdepth);
fprintf(stderr,"%s ht.%d NOTARIZED.%d %s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,hash.ToString().c_str(),"KMD",desttxid.ToString().c_str(),opretlen,len); LogPrintf("dpow: %s ht.%d NOTARIZED.%d %s %sTXID.%s lens.(%d %d)\n",ASSETCHAINS_SYMBOL,height,*notarizedheightp,hash.ToString().c_str(),"KMD",desttxid.ToString().c_str(),opretlen,len);
} else fprintf(stderr,"notarized.%d ht %d vs prev %d vs height.%d\n",notarized,*notarizedheightp,NOTARIZED_HEIGHT,height); } else LogPrintf("dpow: notarized.%d ht %d vs prev %d vs height.%d\n",notarized,*notarizedheightp,NOTARIZED_HEIGHT,height);
} }
} }
} }
@ -1175,6 +1183,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
komodo_notarized_update(0,0,zero,zero,zero,0); komodo_notarized_update(0,0,zero,zero,zero,0);
numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime()); numnotaries = komodo_notaries(pubkeys,pindex->nHeight,pindex->GetBlockTime());
fprintf(stderr, "numnotaries=%d\n", numnotaries);
if ( pindex->nHeight > hwmheight ) if ( pindex->nHeight > hwmheight )
hwmheight = pindex->nHeight; hwmheight = pindex->nHeight;
@ -1188,7 +1197,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
{ {
height = pindex->nHeight; height = pindex->nHeight;
txn_count = block.vtx.size(); txn_count = block.vtx.size();
//fprintf(stderr, "txn_count=%d\n", txn_count); fprintf(stderr, "txn_count=%d\n", txn_count);
for (i=0; i<txn_count; i++) for (i=0; i<txn_count; i++)
{ {
//txhash = block.vtx[i]->GetHash(); //txhash = block.vtx[i]->GetHash();
@ -1196,30 +1205,47 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block)
specialtx = notarizedheight = notarized = 0; specialtx = notarizedheight = notarized = 0;
signedmask = 0; signedmask = 0;
numvins = block.vtx[i].vin.size(); numvins = block.vtx[i].vin.size();
//fprintf(stderr, "tx=%d, numvouts=%d, numvins=%d\n", i, numvouts, numvins ); fprintf(stderr, "tx=%d, numvouts=%d, numvins=%d\n", i, numvouts, numvins );
for (j=0; j<numvins; j++) for (j=0; j<numvins; j++)
{ {
if ( i == 0 && j == 0 ) if ( i == 0 && j == 0 )
continue; continue;
if ( block.vtx[i].vin[j].prevout.hash != zero && (scriptlen= gettxout_scriptPubKey(height,scriptPubKey,sizeof(scriptPubKey),block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n)) == 35 ) bool nonzero = (block.vtx[i].vin[j].prevout.hash != zero);
{
for (k=0; k<numnotaries; k++) if (nonzero) {
if ( memcmp(&scriptPubKey[1],pubkeys[k],33) == 0 ) scriptlen = gettxout_scriptPubKey(height,scriptPubKey,sizeof(scriptPubKey),block.vtx[i].vin[j].prevout.hash,block.vtx[i].vin[j].prevout.n);
{ fprintf(stderr, "scriptlen=%d\n", scriptlen);
signedmask |= (1LL << k); if (scriptlen == 35)
break; {
} for (k=0; k<numnotaries; k++) {
}// else if ( block.vtx[i].vin[j].prevout.hash != zero ) printf("%s cant get scriptPubKey for ht.%d txi.%d vin.%d\n",ASSETCHAINS_SYMBOL,height,i,j); fprintf(stderr,"pubkeys[%d]=", k);
for (i=0; i<33; i++) {
fprintf(stderr,"%02x",pubkeys[k][i]) ;
}
fprintf(stderr,"\n");
fprintf(stderr,"memcmp\n");
if ( memcmp(&scriptPubKey[1],pubkeys[k],33) == 0 )
{
fprintf(stderr,"setting signedmask\n");
signedmask |= (1LL << k);
break;
} else {
fprintf(stderr,"memcmp failed\n");
}
}
fprintf(stderr,"done checking pubkeys\n");
}
} else if ( block.vtx[i].vin[j].prevout.hash != zero ) printf("%s cant get scriptPubKey for ht.%d txi.%d vin.%d\n",ASSETCHAINS_SYMBOL,height,i,j);
} }
numvalid = bitweight(signedmask); numvalid = bitweight(signedmask);
if ( numvalid >= KOMODO_MINRATIFY ) if ( numvalid >= KOMODO_MINRATIFY )
notarized = 1; notarized = 1;
if ( NOTARY_PUBKEY33[0] != 0 ) //if ( NOTARY_PUBKEY33[0] != 0 )
printf("(tx.%d: ",i); // printf("(tx.%d: ",i);
for (j=0; j<numvouts; j++) for (j=0; j<numvouts; j++)
{ {
if ( NOTARY_PUBKEY33[0] != 0 ) //if ( NOTARY_PUBKEY33[0] != 0 )
printf("%.8f ",dstr(block.vtx[i].vout[j].nValue)); // printf("%.8f ",dstr(block.vtx[i].vout[j].nValue));
len = block.vtx[i].vout[j].scriptPubKey.size(); len = block.vtx[i].vout[j].scriptPubKey.size();
if ( len >= (int32_t)sizeof(uint32_t) && len <= (int32_t)sizeof(scriptbuf) ) if ( len >= (int32_t)sizeof(uint32_t) && len <= (int32_t)sizeof(scriptbuf) )
{ {

Loading…
Cancel
Save