From c9b8b8b04bd97c808ab7d8eb77a94525d57dd4f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 18 Oct 2016 12:02:37 -0300 Subject: [PATCH] test --- src/komodo.h | 29 ++++++++--------- src/main.cpp | 92 +++------------------------------------------------- 2 files changed, 19 insertions(+), 102 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 4e9138fcd..05dacb914 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -23,30 +23,29 @@ int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,NOTARIZED_HEIGHT; std::string NOTARY_PUBKEY; uint256 NOTARIZED_HASH; -int32_t komodo_checkmsg(void *bitcoinpeer,uint8_t *data,int32_t datalen) +int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp) { - fprintf(stderr,"KOMODO.[%d] message from peer.%p\n",datalen,bitcoinpeer); + CBlock block; + if ( ReadBlockFromDisk(block,pindex) == 0 ) + return(-1); + // extract height from coinbase + // extract miner's pubkey from vout[0] + // compare against elected notary pubkeys as of height + + // 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS + // -1 -> invalid, ie, prior to notarized block return(0); } -void komodo_connectblock(CBlock *block) +void komodo_connectblock(CBlockIndex *pindex,CBlock& block) { // update voting results and official (height, notaries[]) } -int32_t komodo_blockindexcheck(CBlockIndex *pindex,uint32_t *nBitsp) -{ - // extract height from coinbase - // extract miner's pubkey from vout[0] - // compare against elected notary pubkeys as of height - return(0); // normal PoW block -} - int32_t komodo_is_notaryblock(CBlockHeader& blockhdr) { - // 1 -> valid notary block, change nBits to KOMODO_MINDIFF_NBITS - // -1 -> invalid, ie, prior to notarized block - return(0); + uint32_t nBits = 0; + return(komodo_blockindexcheck(mapBlockIndex[blockhdr.GetHash()],&nBits)); } int32_t komodo_blockhdrcheck(CBlockHeader& blockhdr,uint32_t *nBitsp) @@ -58,7 +57,7 @@ int32_t komodo_blockhdrcheck(CBlockHeader& blockhdr,uint32_t *nBitsp) int32_t komodo_blockcheck(CBlock& block,uint32_t *nBitsp) { - komodo_blockhdrcheck(block,nBitsp); + return(komodo_blockhdrcheck(block,nBitsp)); } #endif diff --git a/src/main.cpp b/src/main.cpp index 2cbe439f8..4704e76cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2493,7 +2493,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * mempool.removeForBlock(pblock->vtx, pindexNew->nHeight, txConflicted, !IsInitialBlockDownload()); mempool.check(pcoinsTip); // Update chainActive & related variables. - UpdateTip(pindexNew); + UpdateTip(pindexNew,block); // Tell wallet about transactions that went from mempool // to conflicted: BOOST_FOREACH(const CTransaction &tx, txConflicted) { @@ -2503,7 +2503,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * BOOST_FOREACH(const CTransaction &tx, pblock->vtx) { SyncWithWallets(tx, pblock); } - komodo_connectblock(pblock); + komodo_connectblock(pindexNew); // Update cached incremental witnesses GetMainSignals().ChainTip(pindexNew, pblock, oldTree, true); @@ -2946,7 +2946,7 @@ bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, unsigne bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW) { - int32_t retval; uint32_t nBits; //CBlockIndex *bindex = new CBlockIndex(block); + int32_t retval; uint32_t nBits; // Check timestamp if (block.GetBlockTime() > GetAdjustedTime() + 60) return state.Invalid(error("CheckBlockHeader(): block timestamp too far in the future"),REJECT_INVALID, "time-too-new"); @@ -5075,12 +5075,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } } } - else if (strCommand == "komodo") + /*else if (strCommand == "komodo") { vector vData; vRecv >> vData; komodo_checkmsg(pfrom,vData.data(),vData.size()); - } + }*/ else { LogPrint("net", "Unknown \"%s\" from peer=%d\n", SanitizeString(strCommand),pfrom->id); @@ -5494,90 +5494,8 @@ public: } } instance_of_cmaincleanup; -int32_t SuperNET_retval = 0; - extern "C" const char* getDataDir() { return GetDataDir().string().c_str(); } -#ifdef needs_to_be_ported // send komodo message -void set_pubaddr(CPubAddr &pubaddr,std::string msg,int32_t duration) -{ - pubaddr.teleportMsg = msg; - pubaddr.nPriority = 1; - pubaddr.nID = rand() % 100000001; - pubaddr.nVersion = PROTOCOL_VERSION; - pubaddr.nRelayUntil = pubaddr.nExpiration = (GetAdjustedTime() + duration); - CDataStream sMsg(SER_NETWORK,PROTOCOL_VERSION); - sMsg << (CUnsignedPubAddr)pubaddr; - pubaddr.vchMsg = vector(sMsg.begin(),sMsg.end()); - if(!pubaddr.CheckSignature()) - throw runtime_error("Failed to Unserialize PubAddr"); - //if ( pubaddr.ProcessPubAddr() == 0 ) - // throw runtime_error("set_pubaddr: Failed to process pubaddr.\n"); -} - -void broadcastPubAddr(char *msg,int32_t duration) -{ - CPubAddr *pubaddr = new CPubAddr; - set_pubaddr(*pubaddr,std::string(msg),duration); - printf("Komodo BROADCAST.(%s)\n",msg); - // Relay pubaddr to all peers - { - LOCK(cs_vNodes); - BOOST_FOREACH(CNode *pnode,vNodes) - { - pubaddr->RelayTo(pnode); - } - } - delete pubaddr; -} - -extern "C" int32_t SuperNET_broadcast(char *msg,int32_t duration) -{ - printf("inside SuperNET_broadcast.(%s) retval.%d\n",msg,SuperNET_retval); - if ( SuperNET_retval <= 0 ) - return(-1); - broadcastPubAddr(msg,duration); - return(0); -} - -extern "C" int32_t SuperNET_narrowcast(char *destip,unsigned char *msg,int32_t len) //Send a PubAddr message to a specific peer -{ - int32_t retflag = 0; - CPubAddr *pubaddr = new CPubAddr; - std::string supernetmsg = ""; - CNode *peer; - if ( SuperNET_retval <= 0 ) - return(-1); - peer = FindNode((CService)destip); - if ( peer == NULL ) - { - std::cout << "<<<<<<< narrowcast sent to null peer. Trying to find node " << destip << std::endl; - CService *serv = new CService(destip); - CAddress *addrConnect = new CAddress(*serv); - peer = ConnectNode(*addrConnect, destip); - free(serv); - free(addrConnect); - // opennetworkconnection((CService)destip); - // peer = FindNode((CService)destip); - } - if ( peer == NULL ) - { - std::cout << destip << " could not be located for narrowcast." << std::endl; - return(-1); // Not a known peer - } - std::cout << destip << " was located for narrowcast." << std::endl; - for(int32_t i=0; iRelayTo(peer) != true ) - retflag = -2; - delete pubaddr; - //printf("SuperNET_narrowcast relay error\n"); - return(retflag); -} -#endif - -