MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ProcessTxMessage

Function ProcessTxMessage

src/p2p/chainmessage.cpp:464–510  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462}
463
464bool ProcessTxMessage(CNode *pFrom, string strCommand, CDataStream &vRecv) {
465 std::shared_ptr<CBaseTx> pBaseTx;
466 try {
467 vRecv >> pBaseTx;
468 } catch(const runtime_error &e) {
469 // TODO: record the misebehaving or ban the peer node.
470 return ERRORMSG("Unknown transaction type from peer %s, ignore! %s", pFrom->addr.ToString(), e.what());
471 }
472
473 if (pBaseTx->IsRelayForbidden()) {
474 return ERRORMSG("Forbid transaction=%s from network from peer %s, txid=%s, raw: %s", pBaseTx->GetTxTypeName(),
475 pFrom->addr.ToString(), pBaseTx->GetHash().ToString(), HexStr(vRecv.begin(), vRecv.end()));
476 }
477
478 CInv inv(MSG_TX, pBaseTx->GetHash());
479 pFrom->AddInventoryKnown(inv);
480
481 if(IsInitialBlockDownload()){
482 RelayTransaction(pBaseTx.get(), inv.hash);
483 return true;
484 }
485
486 LOCK(cs_main);
487 CValidationState state;
488 if (AcceptToMemoryPool(mempool, state, pBaseTx.get(), true)) {
489 RelayTransaction(pBaseTx.get(), inv.hash);
490 mapAlreadyAskedFor.erase(inv);
491
492 LogPrint(BCLog::NET, "[%d]~ %s %s : accepted %s (poolsz %u)\n", pBaseTx->valid_height, pFrom->addr.ToString(),
493 pFrom->cleanSubVer, pBaseTx->GetHash().ToString(), mempool.memPoolTxs.size());
494 }
495
496 int32_t nDoS = 0;
497 if (state.IsInvalid(nDoS)) {
498 LogPrint(BCLog::NET, "[%d]~ %s from %s %s not accepted into mempool: %s\n",
499 pBaseTx->GetHash().ToString(), pBaseTx->valid_height,
500 pFrom->addr.ToString(), pFrom->cleanSubVer, state.GetRejectReason());
501
502 pFrom->PushMessage(NetMsgType::REJECT, strCommand, state.GetRejectCode(), state.GetRejectReason(), inv.hash);
503 // if (nDoS > 0) {
504 // LogPrint(BCLog::INFO, "Misebehaving, add to tx hash %s mempool error, Misbehavior add %d",
505 // pBaseTx->GetHash().GetHex(), nDoS); Misbehaving(pFrom->GetId(), nDoS);
506 // }
507 }
508
509 return true;
510}
511
512bool ProcessGetHeadersMessage(CNode *pFrom, CDataStream &vRecv) {
513 CBlockLocator locator;

Callers 1

ProcessMessageFunction · 0.85

Calls 15

HexStrFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
RelayTransactionFunction · 0.85
AcceptToMemoryPoolFunction · 0.85
IsRelayForbiddenMethod · 0.80
AddInventoryKnownMethod · 0.80
IsInvalidMethod · 0.80
GetRejectReasonMethod · 0.80
PushMessageMethod · 0.80
GetRejectCodeMethod · 0.80
ToStringMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected