@@ -906,50 +906,53 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake
906906 // Initialize nOutputUsed at 1, because one is already used for the empty coinstake flag output.
907907 unsigned int nOutputsUsed = 1 ;
908908
909- // Compute the mandatory sidestake spec using BlockRewardRules — the shared invariant computation that
910- // both miner and validator consume. This replaces the separate ActiveSideStakeEntries() call and manual
911- // dust/address filtering that previously lived only here, eliminating the class of drift bugs where the
912- // miner and validator made different eligibility decisions (see #2848).
913- CTxDestination coinstake_dest;
914- bool have_coinstake_dest = ExtractDestination (CoinStakeScriptPubKey, coinstake_dest);
915- if (!have_coinstake_dest) {
916- LogPrintf (" WARN: SplitCoinStakeOutput: could not extract coinstake destination, "
917- " skipping mandatory sidestake spec computation." );
918- }
919-
920- GRC::BlockRewardRules rules (pindexBest, blocknew.nVersion , blocknew.nTime );
921-
909+ // Mandatory and local sidestake computation — only needed when sidestaking is active.
922910 std::vector<GRC::BlockRewardRules::MandatorySidestakeSpec> mandatory_specs;
911+ SideStakeAlloc local_sidestakes;
912+ unsigned int nMandatoryOutputLimit = GetMandatorySideStakeOutputLimit (blocknew.nVersion );
923913
924- if (have_coinstake_dest) {
925- mandatory_specs = GRC::BlockRewardRules::FilterEligible (
926- rules.ComputeEligibleMandatorySidestakes (coinstake_dest, nReward));
927- }
914+ if (fEnableSideStaking ) {
915+ // Compute the mandatory sidestake spec using BlockRewardRules — the shared invariant computation that
916+ // both miner and validator consume. This replaces the separate ActiveSideStakeEntries() call and manual
917+ // dust/address filtering that previously lived only here, eliminating the class of drift bugs where the
918+ // miner and validator made different eligibility decisions (see #2848).
919+ CTxDestination coinstake_dest;
920+ bool have_coinstake_dest = ExtractDestination (CoinStakeScriptPubKey, coinstake_dest);
921+ if (!have_coinstake_dest) {
922+ LogPrintf (" WARN: SplitCoinStakeOutput: could not extract coinstake destination, "
923+ " skipping mandatory sidestake spec computation." );
924+ }
928925
929- unsigned int nMandatoryOutputLimit = GetMandatorySideStakeOutputLimit (blocknew.nVersion );
926+ if (have_coinstake_dest) {
927+ GRC::BlockRewardRules rules (pindexBest, blocknew.nVersion , blocknew.nTime );
930928
931- // Shuffle when over the limit — non-deterministic selection. The validator cannot reproduce the shuffle
932- // and doesn't need to; it matches against the eligible set regardless of order.
933- if (mandatory_specs.size () > nMandatoryOutputLimit) {
934- Shuffle (mandatory_specs.begin (), mandatory_specs.end (), FastRandomContext ());
935- }
929+ mandatory_specs = GRC::BlockRewardRules::FilterEligible (
930+ rules.ComputeEligibleMandatorySidestakes (coinstake_dest, nReward));
931+ }
936932
937- // If the number of voluntary sidestaking allocation entries exceeds the remaining output capacity, then
938- // shuffle the list to support sidestaking with more than the available number of entries. This is a super
939- // simple solution but has some disadvantages. If the person made a mistake and has the entries in the config
940- // file add up to more than 100%, then those entries resulting in a cumulative total over 100% will always be
941- // excluded, not just randomly excluded, because the cumulative check is done in the order of the entries in
942- // the config file. This is not regarded as a big issue, because all of the entries are supposed to add up to
943- // less than or equal to 100%. Also when there are more than the available number of entries, the residual
944- // returned to the coinstake will vary when the entries are shuffled, because the total percentage of the
945- // selected entries will be randomized. No attempt to renormalize the percentages is done.
946- SideStakeAlloc local_sidestakes
947- = GRC::GetSideStakeRegistry ().ActiveSideStakeEntries (GRC::SideStake::FilterFlag::LOCAL, false );
948-
949- if (local_sidestakes.size () > nMaxSideStakeOutputs
950- - std::min<unsigned int >(nMandatoryOutputLimit,
951- mandatory_specs.size ())) {
952- Shuffle (local_sidestakes.begin (), local_sidestakes.end (), FastRandomContext ());
933+ // Shuffle when over the limit — non-deterministic selection. The validator cannot reproduce the shuffle
934+ // and doesn't need to; it matches against the eligible set regardless of order.
935+ if (mandatory_specs.size () > nMandatoryOutputLimit) {
936+ Shuffle (mandatory_specs.begin (), mandatory_specs.end (), FastRandomContext ());
937+ }
938+
939+ // If the number of voluntary sidestaking allocation entries exceeds the remaining output capacity, then
940+ // shuffle the list to support sidestaking with more than the available number of entries. This is a super
941+ // simple solution but has some disadvantages. If the person made a mistake and has the entries in the config
942+ // file add up to more than 100%, then those entries resulting in a cumulative total over 100% will always be
943+ // excluded, not just randomly excluded, because the cumulative check is done in the order of the entries in
944+ // the config file. This is not regarded as a big issue, because all of the entries are supposed to add up to
945+ // less than or equal to 100%. Also when there are more than the available number of entries, the residual
946+ // returned to the coinstake will vary when the entries are shuffled, because the total percentage of the
947+ // selected entries will be randomized. No attempt to renormalize the percentages is done.
948+ local_sidestakes
949+ = GRC::GetSideStakeRegistry ().ActiveSideStakeEntries (GRC::SideStake::FilterFlag::LOCAL, false );
950+
951+ if (local_sidestakes.size () > nMaxSideStakeOutputs
952+ - std::min<unsigned int >(nMandatoryOutputLimit,
953+ mandatory_specs.size ())) {
954+ Shuffle (local_sidestakes.begin (), local_sidestakes.end (), FastRandomContext ());
955+ }
953956 }
954957
955958 // Initialize remaining stake output value to the total value of output for stake, which also includes
0 commit comments