Skip to content

Commit

Permalink
⚡ Add Enigma annoucement message skeleton \n Fix up PoW validation
Browse files Browse the repository at this point in the history
  • Loading branch information
akyo8 committed Feb 18, 2021
1 parent 7d8a10a commit 1a85d7c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/net_processing.cpp
Expand Up @@ -506,6 +506,11 @@ static void PushNodeVersion(CNode& pnode, CConnman& connman, int64_t nTime)
connman.PushMessage(&pnode, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::VERSION, PROTOCOL_VERSION, (uint64_t)nLocalNodeServices, nTime, addrYou, addrMe,
nonce, strSubVersion, nNodeStartingHeight, ::g_relay_txes && pnode.m_tx_relay != nullptr));

if (strCommand == NetMsgType::ENG_ANNOUNCEMENT) {
// Enigma Announcement
return true;
}

if (fLogIPs) {
LogPrint(BCLog::NET, "send version message: version %d, blocks=%d, us=%s, them=%s, peer=%d\n", PROTOCOL_VERSION, nNodeStartingHeight, addrMe.ToString(), addrYou.ToString(), nodeid);
} else {
Expand Down Expand Up @@ -3475,8 +3480,15 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
}
headers.resize(nCount);
for (unsigned int n = 0; n < nCount; n++) {
vRecv >> headers[n];
ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
//vRecv >> headers[n];
//ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
CBlock b;
vRecv >> b;
ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
headers[n] = b.GetBlockHeader();
// int size = ReadCompactSize(vRecv); // ignore tx count; assume it is 0.
int xx = 1;

}

return ProcessHeadersMessage(pfrom, headers, /*via_compact_block=*/false);
Expand Down Expand Up @@ -4139,6 +4151,9 @@ bool PeerManager::SendMessages(CNode* pto)
// Start block sync
if (pindexBestHeader == nullptr)
pindexBestHeader = ::ChainActive().Tip();

bool canHandlePoSHeaders = pto->nVersion >= VERSION_GETHEADERS_POS;

bool fFetch = state.fPreferredDownload || (nPreferredDownload == 0 && !pto->fClient && !pto->IsAddrFetchConn()); // Download if this is a nice peer, or we have no nice peers and this one might do.
if (!state.fSyncStarted && !pto->fClient && !fImporting && !fReindex) {
// Only actively request headers from a single peer, unless we're close to today.
Expand Down Expand Up @@ -4174,7 +4189,10 @@ bool PeerManager::SendMessages(CNode* pto)
// add all to the inv queue.
LOCK(pto->cs_inventory);
std::vector<CBlock> vHeaders;
bool fRevertToInv = ((!state.fPreferHeaders &&

bool canHandlePoSHeaders = pto->nVersion >= VERSION_GETHEADERS_POS;
bool fRevertToInv = (canHandlePoSHeaders == false ||
(!state.fPreferHeaders &&
(!state.fPreferHeaderAndIDs || pto->vBlockHashesToAnnounce.size() > 1)) ||
pto->vBlockHashesToAnnounce.size() > MAX_BLOCKS_TO_ANNOUNCE);
const CBlockIndex *pBestIndex = nullptr; // last header queued for delivery
Expand Down
2 changes: 2 additions & 0 deletions src/protocol.cpp
Expand Up @@ -38,6 +38,7 @@ const char *SENDCMPCT="sendcmpct";
const char *CMPCTBLOCK="cmpctblock";
const char *GETBLOCKTXN="getblocktxn";
const char *BLOCKTXN="blocktxn";
const char* ENG_ANNOUNCEMENT = "announcement";
const char *GETCFILTERS="getcfilters";
const char *CFILTER="cfilter";
const char *GETCFHEADERS="getcfheaders";
Expand Down Expand Up @@ -85,6 +86,7 @@ const static std::string allNetMessageTypes[] = {
NetMsgType::GETCFCHECKPT,
NetMsgType::CFCHECKPT,
NetMsgType::WTXIDRELAY,
NetMsgType::ENG_ANNOUNCEMENT,
};
const static std::vector<std::string> allNetMessageTypesVec(allNetMessageTypes, allNetMessageTypes+ARRAYLEN(allNetMessageTypes));

Expand Down
2 changes: 2 additions & 0 deletions src/protocol.h
Expand Up @@ -218,6 +218,8 @@ extern const char* GETBLOCKTXN;
* @since protocol version 70014 as described by BIP 152
*/
extern const char* BLOCKTXN;
extern const char* ENG_ANNOUNCEMENT;

/**
* getcfilters requests compact filters for a range of blocks.
* Only available with service bit NODE_COMPACT_FILTERS as described by
Expand Down
8 changes: 8 additions & 0 deletions src/validation.cpp
Expand Up @@ -3500,6 +3500,14 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio

// Check proof of work
const Consensus::Params& consensusParams = params.GetConsensus();

// Check proof of work matches claimed amount
CBlockIndex pblock = CBlockIndex(block);

//if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
if (pblock.IsProofOfWork() && !CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work");

if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
return state.Invalid(BlockValidationResult::BLOCK_INVALID_HEADER, "bad-diffbits", "incorrect proof of work");

Expand Down

0 comments on commit 1a85d7c

Please sign in to comment.