This commit is contained in:
jl777
2019-07-04 02:41:54 -11:00
parent 14815c3a5c
commit c617e6e959
2 changed files with 20 additions and 6 deletions

View File

@@ -227,6 +227,7 @@ int32_t NSPV_rwtxproof(int32_t rwflag,uint8_t *serialized,struct NSPV_txproof *p
len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height);
len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txlen,&ptr->tx);
len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof); len += iguana_rwuint8vec(rwflag,&serialized[len],&ptr->txprooflen,&ptr->txproof);
fprintf(stderr,"rwtxproof len.%d\n",len);
return(len); return(len);
} }
@@ -472,8 +473,11 @@ uint8_t *NSPV_getrawtx(uint256 &hashBlock,uint16_t *txlenp,uint256 txid)
return(0); return(0);
string strHex = EncodeHexTx(tx); string strHex = EncodeHexTx(tx);
*txlenp = (int32_t)strHex.size() >> 1; *txlenp = (int32_t)strHex.size() >> 1;
rawtx = (uint8_t *)calloc(1,*txlenp); if ( *txlenp > 0 )
decode_hex(rawtx,*txlenp,(char *)strHex.c_str()); {
rawtx = (uint8_t *)calloc(1,*txlenp);
decode_hex(rawtx,*txlenp,(char *)strHex.c_str());
}
} }
return(rawtx); return(rawtx);
} }
@@ -504,8 +508,12 @@ int32_t NSPV_gettxproof(struct NSPV_txproof *ptr,uint256 txid,int32_t height)
ssMB << mb; ssMB << mb;
std::vector<uint8_t> proof(ssMB.begin(), ssMB.end()); std::vector<uint8_t> proof(ssMB.begin(), ssMB.end());
ptr->txprooflen = (int32_t)proof.size(); ptr->txprooflen = (int32_t)proof.size();
ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen); if ( ptr->txprooflen > 0 )
memcpy(ptr->txproof,&proof[0],ptr->txprooflen); {
ptr->txproof = (uint8_t *)calloc(1,ptr->txprooflen);
memcpy(ptr->txproof,&proof[0],ptr->txprooflen);
}
fprintf(stderr,"gettxproof slen.%d\n",(int32_t)(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen));
return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen); return(sizeof(*ptr) - sizeof(ptr->tx) - sizeof(ptr->txproof) + ptr->txlen + ptr->txprooflen);
} }
} }
@@ -693,11 +701,13 @@ void komodo_nSPVreq(CNode *pfrom,std::vector<uint8_t> request) // received a req
{ {
iguana_rwnum(0,&request[1],sizeof(height),&height); iguana_rwnum(0,&request[1],sizeof(height),&height);
iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid); iguana_rwbignum(0,&request[1+sizeof(height)],sizeof(txid),(uint8_t *)&txid);
fprintf(stderr,"got txid ht.%d\n",txid.GetHex().c_str(),height);
memset(&P,0,sizeof(P)); memset(&P,0,sizeof(P));
if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 ) if ( (slen= NSPV_gettxproof(&P,txid,height)) > 0 )
{ {
response.resize(1 + slen); response.resize(1 + slen);
response[0] = NSPV_TXPROOFRESP; response[0] = NSPV_TXPROOFRESP;
fprintf(stderr,"slen.%d\n",slen);
if ( NSPV_rwtxproof(1,&response[1],&P) == slen ) if ( NSPV_rwtxproof(1,&response[1],&P) == slen )
{ {
pfrom->PushMessage("nSPV",response); pfrom->PushMessage("nSPV",response);
@@ -1015,13 +1025,17 @@ UniValue NSPV_txproof(uint256 txid,int32_t height)
msg[len++] = NSPV_TXPROOF; msg[len++] = NSPV_TXPROOF;
len += iguana_rwnum(1,&msg[len],sizeof(height),&height); len += iguana_rwnum(1,&msg[len],sizeof(height),&height);
len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid); len += iguana_rwbignum(1,&msg[len],sizeof(txid),(uint8_t *)&txid);
fprintf(stderr,"req txproof %s at height.%d\n",txid.GetHex().c_str(),height);
if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 ) if ( NSPV_req(0,msg,len,NODE_NSPV,msg[0]>>1) != 0 )
{ {
for (i=0; i<10; i++) for (i=0; i<10; i++)
{ {
usleep(100000); usleep(100000);
if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height ) if ( NSPV_txproofresult.txid == txid && NSPV_txproofresult.height == height )
{
fprintf(stderr,"got txproof\n");
return(NSPV_txproof_json(&NSPV_txproofresult)); return(NSPV_txproof_json(&NSPV_txproofresult));
}
} }
} }
memset(&P,0,sizeof(P)); memset(&P,0,sizeof(P));

View File

@@ -7053,8 +7053,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
const CChainParams& chainparams = Params(); const CChainParams& chainparams = Params();
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id); LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
//if ( KOMODO_NSPV != 0 ) //if ( KOMODO_NSPV != 0 )
if ( strCommand != "version" && strCommand != "verack" ) //if ( strCommand != "version" && strCommand != "verack" )
fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId()); // fprintf(stderr, "recv: %s peer=%d\n", SanitizeString(strCommand).c_str(), (int32_t)pfrom->GetId());
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0) if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{ {
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");