Skip to content

Commit 96bf945

Browse files
committed
Simplify GetActiveFundingStreamElements.
Signed-off-by: Daira-Emma Hopwood <[email protected]>
1 parent e368a29 commit 96bf945

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/consensus/params.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ namespace Consensus {
349349
// Funding streams are disabled if Canopy is not active.
350350
if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
351351
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
352+
// The following indexed access is safe as Consensus::MAX_FUNDING_STREAMS is used
353+
// in the definition of vFundingStreams.
352354
auto fs = vFundingStreams[idx];
355+
356+
// Funding period is [startHeight, endHeight).
353357
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
354358
activeStreams.push_back(std::make_pair(FundingStreamInfo[idx], fs.value()));
355359
}
@@ -372,16 +376,10 @@ namespace Consensus {
372376

373377
// Funding streams are disabled if Canopy is not active.
374378
if (NetworkUpgradeActive(nHeight, Consensus::UPGRADE_CANOPY)) {
375-
for (uint32_t idx = Consensus::FIRST_FUNDING_STREAM; idx < Consensus::MAX_FUNDING_STREAMS; idx++) {
376-
// The following indexed access is safe as Consensus::MAX_FUNDING_STREAMS is used
377-
// in the definition of vFundingStreams.
378-
auto fs = vFundingStreams[idx];
379-
// Funding period is [startHeight, endHeight)
380-
if (fs && nHeight >= fs.value().GetStartHeight() && nHeight < fs.value().GetEndHeight()) {
381-
requiredElements.insert(std::make_pair(
382-
fs.value().Recipient(*this, nHeight),
383-
FundingStreamInfo[idx].Value(blockSubsidy)));
384-
}
379+
for (const auto& [fsinfo, fs] : GetActiveFundingStreams(nHeight)) {
380+
requiredElements.insert(std::make_pair(
381+
fs.Recipient(*this, nHeight),
382+
fsinfo.Value(blockSubsidy)));
385383
}
386384
}
387385

0 commit comments

Comments
 (0)