From 46a3ee29bc7e04d015369eec0c3408df3d3cd797 Mon Sep 17 00:00:00 2001 From: James Dorfman Date: Mon, 27 May 2024 09:25:31 +0000 Subject: [PATCH] improve efficiency by gating locks with --- src/dynafed.cpp | 7 ++++--- src/pegins.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/dynafed.cpp b/src/dynafed.cpp index 60f1cbbc4c..d719795149 100644 --- a/src/dynafed.cpp +++ b/src/dynafed.cpp @@ -2,6 +2,7 @@ #include #include #include +#include bool NextBlockIsParameterTransition(const CBlockIndex* pindexPrev, const Consensus::Params& consensus, DynaFedParamEntry& winning_entry) { @@ -16,7 +17,7 @@ bool NextBlockIsParameterTransition(const CBlockIndex* pindexPrev, const Consens for (int32_t height = next_height - 1; height >= (int32_t)(next_height - consensus.dynamic_epoch_length); --height) { const CBlockIndex* p_epoch_walk = pindexPrev->GetAncestor(height); assert(p_epoch_walk); - { + if (node::fTrimHeaders) { LOCK(cs_main); ForceUntrimHeader(p_epoch_walk); } @@ -65,7 +66,7 @@ DynaFedParamEntry ComputeNextBlockFullCurrentParameters(const CBlockIndex* pinde // may be pre-dynafed params const CBlockIndex* p_epoch_start = pindexPrev->GetAncestor(epoch_start_height); assert(p_epoch_start); - { + if (node::fTrimHeaders) { LOCK(cs_main); ForceUntrimHeader(p_epoch_start); } @@ -102,7 +103,7 @@ DynaFedParamEntry ComputeNextBlockCurrentParameters(const CBlockIndex* pindexPre { assert(pindexPrev); - { + if (node::fTrimHeaders) { LOCK(cs_main); ForceUntrimHeader(pindexPrev); } diff --git a/src/pegins.cpp b/src/pegins.cpp index c5e2794dc7..72551d2c3b 100644 --- a/src/pegins.cpp +++ b/src/pegins.cpp @@ -489,7 +489,7 @@ std::vector> GetValidFedpegScripts(const CBlockIndex break; } - { + if (node::fTrimHeaders) { LOCK(cs_main); ForceUntrimHeader(p_epoch_start); }