From 87ad368643c80bab29896bd0313f7e413650f6b1 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 24 May 2016 03:08:16 +0300 Subject: [PATCH] Optimize processing of a (potentially) new MN: - Move heavy `IsVinAssociatedWithPubkey` deep inside of `CheckInputsAndAdd` to be actually executed only once per masternode and only after much simpler checks were executed; - Verify `GetInputAge` (it uses cache) before trying to enter `AcceptToMemoryPool` (which hash many ifs and checks inside). --- src/masternode.cpp | 22 ++++++++++++++++------ src/masternodeman.cpp | 8 -------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/masternode.cpp b/src/masternode.cpp index f00beeaf41..5ffa887e2e 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -462,6 +462,14 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos) else mnodeman.Remove(pmn->vin); } + if(GetInputAge(vin) < Params().GetConsensus().nMasternodeMinimumConfirmations){ + LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Input must have at least %d confirmations\n", Params().GetConsensus().nMasternodeMinimumConfirmations); + // maybe we miss few blocks, let this mnb to be checked again later + mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); + masternodeSync.mapSeenSyncMNB.erase(GetHash()); + return false; + } + CValidationState state; CMutableTransaction tx = CMutableTransaction(); CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey); @@ -485,13 +493,14 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos) } } - LogPrint("masternode", "CMasternodeBroadcast::CheckInputsAndAdd - Accepted Masternode entry\n"); + LogPrint("masternode", "CMasternodeBroadcast::CheckInputsAndAdd - Accepted Masternode entry to mempool (dry-run mode)\n"); - if(GetInputAge(vin) < Params().GetConsensus().nMasternodeMinimumConfirmations){ - LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Input must have at least %d confirmations\n", Params().GetConsensus().nMasternodeMinimumConfirmations); - // maybe we miss few blocks, let this mnb to be checked again later - mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); - masternodeSync.mapSeenSyncMNB.erase(GetHash()); + + // make sure the vout that was signed is related to the transaction that spawned the Masternode + // - this is expensive, so it's only done once per Masternode + if(!darkSendSigner.IsVinAssociatedWithPubkey(vin, pubkey)) { + LogPrintf("CMasternodeMan::CheckInputsAndAdd - Got mismatched pubkey and vin\n"); + nDos = 33; return false; } @@ -515,6 +524,7 @@ bool CMasternodeBroadcast::CheckInputsAndAdd(int& nDos) } } } + LogPrintf("CMasternodeBroadcast::CheckInputsAndAdd - Got NEW Masternode entry - %s - %s - %s - %lli \n", GetHash().ToString(), addr.ToString(), vin.ToString(), sigTime); CMasternode mn(*this); mnodeman.Add(mn); diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index d1d6680cf3..c949a084e4 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -840,14 +840,6 @@ bool CMasternodeMan::CheckMnbAndUpdateMasternodeList(CMasternodeBroadcast mnb, i return false; } - // make sure the vout that was signed is related to the transaction that spawned the Masternode - // - this is expensive, so it's only done once per Masternode - if(!darkSendSigner.IsVinAssociatedWithPubkey(mnb.vin, mnb.pubkey)) { - LogPrintf("CMasternodeMan::CheckMnbAndUpdateMasternodeList - Got mismatched pubkey and vin\n"); - nDos = 33; - return false; - } - // make sure it's still unspent // - this is checked later by .check() in many places and by ThreadCheckDarkSendPool() if(mnb.CheckInputsAndAdd(nDos)) {