diff --git a/src/komodo_nSPV.h b/src/komodo_nSPV.h index 9b23cb018..3da37e7b4 100644 --- a/src/komodo_nSPV.h +++ b/src/komodo_nSPV.h @@ -255,6 +255,7 @@ int32_t NSPV_rwntz(int32_t rwflag,uint8_t *serialized,struct NSPV_ntz *ptr) len += iguana_rwbignum(rwflag,&serialized[len],sizeof(ptr->othertxid),(uint8_t *)&ptr->othertxid); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->txidheight),&ptr->txidheight); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->timestamp),&ptr->timestamp); return(len); } @@ -286,7 +287,8 @@ int32_t NSPV_rwinforesp(int32_t rwflag,uint8_t *serialized,struct NSPV_inforesp len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->height),&ptr->height); len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->hdrheight),&ptr->hdrheight); len += NSPV_rwequihdr(rwflag,&serialized[len],&ptr->H); -//fprintf(stderr,"hdr rwlen.%d\n",len); + len += iguana_rwnum(rwflag,&serialized[len],sizeof(ptr->version),&ptr->version); +//fprintf(stderr,"getinfo rwlen.%d\n",len); return(len); } diff --git a/src/komodo_nSPV_defs.h b/src/komodo_nSPV_defs.h index 8eeed8292..282e58cab 100644 --- a/src/komodo_nSPV_defs.h +++ b/src/komodo_nSPV_defs.h @@ -17,6 +17,7 @@ #ifndef KOMODO_NSPV_DEFSH #define KOMODO_NSPV_DEFSH +#define NSPV_PROTOCOL_VERSION 0x00000002 #define NSPV_POLLITERS 100 #define NSPV_POLLMICROS 30000 #define NSPV_MAXVINS 64 @@ -110,6 +111,7 @@ struct NSPV_ntz { uint256 blockhash,txid,othertxid; int32_t height,txidheight; + uint32_t timestamp; }; struct NSPV_ntzsresp @@ -124,6 +126,7 @@ struct NSPV_inforesp uint256 blockhash; int32_t height,hdrheight; struct NSPV_equihdr H; + uint32_t version; }; struct NSPV_txproof diff --git a/src/komodo_nSPV_fullnode.h b/src/komodo_nSPV_fullnode.h index 5e4ec0b25..263c45d71 100644 --- a/src/komodo_nSPV_fullnode.h +++ b/src/komodo_nSPV_fullnode.h @@ -69,11 +69,14 @@ int32_t NSPV_notarized_bracket(struct NSPV_ntzargs *prev,struct NSPV_ntzargs *ne int32_t NSPV_ntzextract(struct NSPV_ntz *ptr,uint256 ntztxid,int32_t txidht,uint256 desttxid,int32_t ntzheight) { + CBlockIndex *pindex; ptr->blockhash = *chainActive[ntzheight]->phashBlock; ptr->height = ntzheight; ptr->txidheight = txidht; ptr->othertxid = desttxid; ptr->txid = ntztxid; + if ( (pindex= komodo_chainactive(ptr->txidheight)) != 0 ) + ptr->timestamp = pindex->nTime; return(0); } @@ -121,7 +124,7 @@ int32_t NSPV_setequihdr(struct NSPV_equihdr *hdr,int32_t height) int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) { - int32_t prevMoMheight,len = 0; CBlockIndex *pindex; struct NSPV_ntzsresp pair; + int32_t prevMoMheight,len = 0; CBlockIndex *pindex, *pindex2; struct NSPV_ntzsresp pair; if ( (pindex= chainActive.LastTip()) != 0 ) { ptr->height = pindex->GetHeight(); @@ -130,9 +133,13 @@ int32_t NSPV_getinfo(struct NSPV_inforesp *ptr,int32_t reqheight) if ( NSPV_getntzsresp(&pair,ptr->height-1) < 0 ) return(-1); ptr->notarization = pair.prevntz; + if ( (pindex2= komodo_chainactive(ptr->notarization.txidheight)) != 0 ) + ptr->notarization.timestamp = pindex->nTime; + //fprintf(stderr, "timestamp.%i\n", ptr->notarization.timestamp ); if ( reqheight == 0 ) reqheight = ptr->height; ptr->hdrheight = reqheight; + ptr->version = NSPV_PROTOCOL_VERSION; if ( NSPV_setequihdr(&ptr->H,reqheight) < 0 ) return(-1); return(sizeof(*ptr)); @@ -537,7 +544,7 @@ void komodo_nSPVreq(CNode *pfrom,std::vector request) // received a req { response.resize(1 + slen); response[0] = NSPV_INFORESP; - //fprintf(stderr,"slen.%d\n",slen); + //fprintf(stderr,"slen.%d version.%d\n",slen,I.version); if ( NSPV_rwinforesp(1,&response[1],&I) == slen ) { //fprintf(stderr,"send info resp to id %d\n",(int32_t)pfrom->id); diff --git a/src/komodo_nSPV_superlite.h b/src/komodo_nSPV_superlite.h index d7f11c41b..24ceeb6b8 100644 --- a/src/komodo_nSPV_superlite.h +++ b/src/komodo_nSPV_superlite.h @@ -139,7 +139,7 @@ void komodo_nSPVresp(CNode *pfrom,std::vector response) // received a r switch ( response[0] ) { case NSPV_INFORESP: - //fprintf(stderr,"got info response %u size.%d height.%d\n",timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status + fprintf(stderr,"got version.%d info response %u size.%d height.%d\n",NSPV_inforesult.version,timestamp,(int32_t)response.size(),NSPV_inforesult.height); // update current height and ntrz status I = NSPV_inforesult; NSPV_inforesp_purge(&NSPV_inforesult); NSPV_rwinforesp(0,&response[1],&NSPV_inforesult); @@ -370,6 +370,7 @@ UniValue NSPV_getinfo_json(struct NSPV_inforesp *ptr) result.push_back(Pair("chaintip",ptr->blockhash.GetHex())); result.push_back(Pair("notarization",NSPV_ntz_json(&ptr->notarization))); result.push_back(Pair("header",NSPV_header_json(&ptr->H,ptr->hdrheight))); + result.push_back(Pair("protocolversion",(int64_t)ptr->version)); result.push_back(Pair("lastpeer",NSPV_lastpeer)); return(result); }