Skip to content

Commit

Permalink
More fixers
Browse files Browse the repository at this point in the history
  • Loading branch information
JaredTate committed Dec 20, 2024
1 parent 7cf7d89 commit 334a770
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 32 deletions.
24 changes: 6 additions & 18 deletions src/dandelion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,15 @@ bool CConnman::isTxDandelionEmbargoed(const uint256& hash) const {
if (pair != mDandelionEmbargo.end()) {
auto current_time = GetTime<std::chrono::microseconds>();

// First check if we're still within minimum embargo period
// Check if still within embargo period
if (current_time < pair->second) {
return true;
return true;
}

// Only do probabilistic transition after minimum embargo has expired
if (current_time < pair->second + DANDELION_EMBARGO_MINIMUM) {
return true;
}

// Probabilistic fluff transition
// After embargo expires, use probabilistic fluffing
FastRandomContext rng;
static constexpr double FLUFF_PROBABILITY = 0.1;
bool should_fluff = rng.randrange(100) < (FLUFF_PROBABILITY * 100);
return !should_fluff;
return rng.randrange(100) >= (FLUFF_PROBABILITY * 100);
}
return false;
}
Expand All @@ -87,22 +81,16 @@ bool CConnman::insertDandelionEmbargo(const uint256& hash, std::chrono::microsec
LOCK(cs_vNodes);
auto current_time = GetTime<std::chrono::microseconds>();

// Set base embargo time
// Set minimum embargo time
embargo = current_time + DANDELION_EMBARGO_MINIMUM;

// Add random additional delay
FastRandomContext rng;
std::chrono::microseconds extra_delay =
std::chrono::microseconds(rng.randrange(DANDELION_EMBARGO_AVG_ADD.count()));
embargo += extra_delay;
embargo += std::chrono::microseconds(rng.randrange(DANDELION_EMBARGO_AVG_ADD.count()));

LogPrint(BCLog::DANDELION, "Setting embargo for %s until %ld\n",
hash.ToString(), embargo.count());

return mDandelionEmbargo.insert(std::make_pair(hash, embargo)).second;
}


bool CConnman::removeDandelionEmbargo(const uint256& hash)
{
bool removed = false;
Expand Down
22 changes: 8 additions & 14 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4093,25 +4093,19 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,

if (msg_type == NetMsgType::DANDELIONTX) {
if (m_connman.isDandelionInbound(&pfrom)) {
CMutableTransaction mtx;
vRecv >> mtx;
// Extract transaction from message
CTransactionRef ptx;
vRecv >> ptx;

CTransactionRef tx = MakeTransactionRef(std::move(mtx));
const uint256& txhash = tx->GetHash();
const uint256& txhash = ptx->GetHash();

// Enhanced embargo handling
if (m_connman.isTxDandelionEmbargoed(txhash)) {
// Critical: Send notfound for embargoed transactions
std::vector<CInv> vInv;
vInv.push_back(CInv(MSG_DANDELION_TX, txhash));
m_connman.PushMessage(&pfrom, CNetMsgMaker(INIT_PROTO_VERSION).Make(NetMsgType::NOTFOUND, vInv));
// Create inventory vector for notfound message
CInv inv(MSG_TX, txhash);
// Send notfound while in stem phase
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::NOTFOUND, inv));
return;
}

// Process only if not in stempool
if (!m_stempool.exists(txhash)) {
RelayDandelionTransaction(*tx, &pfrom);
}
}
}

Expand Down

0 comments on commit 334a770

Please sign in to comment.