@@ -1189,87 +1189,108 @@ bool IsMiningAllowed(CWallet *pwallet)
1189
1189
1190
1190
// This function parses the config file for the directives for side staking. It is used
1191
1191
// in StakeMiner for the miner loop and also called by rpc getmininginfo.
1192
- bool GetSideStakingStatusAndAlloc (SideStakeAlloc& vSideStakeAlloc )
1192
+ SideStakeAlloc GetSideStakingStatusAndAlloc ()
1193
1193
{
1194
- vector<string> vSubParam;
1195
- std::string sAddress ;
1196
- double dAllocation = 0.0 ;
1194
+ SideStakeAlloc vSideStakeAlloc;
1195
+ std::vector<std::pair<std::string, std::string>> raw_vSideStakeAlloc;
1197
1196
double dSumAllocation = 0.0 ;
1198
1197
1199
- bool fEnableSideStaking = gArgs . GetBoolArg ( " -enablesidestaking " );
1200
- LogPrint (BCLog::LogFlags::MINER, " StakeMiner: fEnableSideStaking = %u " , fEnableSideStaking );
1198
+ // Parse destinations and allocations. We don't need to worry about any that are rejected other than a warning
1199
+ // message, because any unallocated rewards will go back into the coinstake output(s).
1201
1200
1202
- // If side staking is enabled, parse destinations and allocations. We don't need to worry about any that are rejected
1203
- // other than a warning message, because any unallocated rewards will go back into the coinstake output(s).
1204
- if (fEnableSideStaking )
1201
+ // If -sidestakeaddresses and -sidestakeallocations is set in either the config file or the r-w settings file
1202
+ // and the settings are not empty and they are the same size, this will take precedence over the multiple entry
1203
+ // -sidestake format.
1204
+ std::vector<std::string> addresses;
1205
+ std::vector<std::string> allocations;
1206
+
1207
+ ParseString (gArgs .GetArg (" -sidestakeaddresses" , " " ), ' ,' , addresses);
1208
+ ParseString (gArgs .GetArg (" -sidestakeallocations" , " " ), ' ,' , allocations);
1209
+
1210
+ if (addresses.size () != allocations.size ())
1211
+ {
1212
+ LogPrintf (" WARN: %s: Malformed new style sidestaking configuration entries. Reverting to original format." ,
1213
+ __func__);
1214
+ }
1215
+
1216
+ if (addresses.size () && addresses.size () == allocations.size ())
1217
+ {
1218
+ for (unsigned int i = 0 ; i < addresses.size (); ++i)
1219
+ {
1220
+ raw_vSideStakeAlloc.push_back (std::make_pair (addresses[i], allocations[i]));
1221
+ }
1222
+ }
1223
+ else if (gArgs .GetArgs (" -sidestake" ).size ())
1205
1224
{
1206
- if ( gArgs .GetArgs (" -sidestake" ). size ( ))
1225
+ for ( auto const & sSubParam : gArgs .GetArgs (" -sidestake" ))
1207
1226
{
1208
- for (auto const & sSubParam : gArgs .GetArgs (" -sidestake" ))
1227
+ std::vector<std::string> vSubParam;
1228
+
1229
+ ParseString (sSubParam , ' ,' , vSubParam);
1230
+ if (vSubParam.size () != 2 )
1209
1231
{
1210
- ParseString (sSubParam , ' ,' , vSubParam);
1211
- if (vSubParam.size () != 2 )
1212
- {
1213
- LogPrintf (" WARN: StakeMiner: Incompletely SideStake Allocation specified. Skipping SideStake entry." );
1214
- vSubParam.clear ();
1215
- continue ;
1216
- }
1232
+ LogPrintf (" WARN: %s: Incomplete SideStake Allocation specified. Skipping SideStake entry." , __func__);
1233
+ continue ;
1234
+ }
1217
1235
1218
- sAddress = vSubParam[0 ];
1236
+ raw_vSideStakeAlloc.push_back (std::make_pair (vSubParam[0 ], vSubParam[1 ]));
1237
+ }
1238
+ }
1219
1239
1220
- CBitcoinAddress address (sAddress );
1221
- if (!address.IsValid ())
1222
- {
1223
- LogPrintf (" WARN: StakeMiner: ignoring sidestake invalid address %s." , sAddress .c_str ());
1224
- vSubParam.clear ();
1225
- continue ;
1226
- }
1240
+ for (auto const & entry : raw_vSideStakeAlloc)
1241
+ {
1242
+ std::string sAddress ;
1243
+ double dAllocation = 0.0 ;
1227
1244
1228
- try
1229
- {
1230
- dAllocation = stof (vSubParam[1 ]) / 100.0 ;
1231
- }
1232
- catch (...)
1233
- {
1234
- LogPrintf (" WARN: StakeMiner: Invalid allocation provided. Skipping allocation." );
1235
- vSubParam.clear ();
1236
- continue ;
1237
- }
1245
+ sAddress = entry.first ;
1238
1246
1239
- if (dAllocation <= 0 )
1240
- {
1241
- LogPrintf ( " WARN: StakeMiner: Negative or zero allocation provided. Skipping allocation. " );
1242
- vSubParam. clear ( );
1243
- continue ;
1244
- }
1247
+ CBitcoinAddress address ( sAddress );
1248
+ if (!address. IsValid ())
1249
+ {
1250
+ LogPrintf ( " WARN: %s: ignoring sidestake invalid address %s. " , __func__, sAddress );
1251
+ continue ;
1252
+ }
1245
1253
1246
- // The below will stop allocations if someone has made a mistake and the total adds up to more than 100%.
1247
- // Note this same check is also done in SplitCoinStakeOutput, but it needs to be done here for two reasons:
1248
- // 1. Early alertment in the debug log, rather than when the first kernel is found, and 2. When the UI is
1249
- // hooked up, the SideStakeAlloc vector will be filled in by other than reading the config file and will
1250
- // skip the above code.
1251
- dSumAllocation += dAllocation;
1252
- if (dSumAllocation > 1.0 )
1253
- {
1254
- LogPrintf (" WARN: StakeMiner: allocation percentage over 100\%, ending sidestake allocations." );
1255
- break ;
1256
- }
1254
+ try
1255
+ {
1256
+ dAllocation = stof (entry.second ) / 100.0 ;
1257
+ }
1258
+ catch (...)
1259
+ {
1260
+ LogPrintf (" WARN: %s: Invalid allocation provided. Skipping allocation." , __func__);
1261
+ continue ;
1262
+ }
1257
1263
1258
- vSideStakeAlloc.push_back (std::pair<std::string, double >(sAddress , dAllocation));
1259
- LogPrint (BCLog::LogFlags::MINER, " StakeMiner: SideStakeAlloc Address %s, Allocation %f" ,
1260
- sAddress .c_str (), dAllocation);
1264
+ if (dAllocation <= 0 )
1265
+ {
1266
+ LogPrintf (" WARN: %s: Negative or zero allocation provided. Skipping allocation." , __func__);
1267
+ continue ;
1268
+ }
1261
1269
1262
- vSubParam.clear ();
1263
- }
1270
+ // The below will stop allocations if someone has made a mistake and the total adds up to more than 100%.
1271
+ // Note this same check is also done in SplitCoinStakeOutput, but it needs to be done here for two reasons:
1272
+ // 1. Early alertment in the debug log, rather than when the first kernel is found, and 2. When the UI is
1273
+ // hooked up, the SideStakeAlloc vector will be filled in by other than reading the config file and will
1274
+ // skip the above code.
1275
+ dSumAllocation += dAllocation;
1276
+ if (dSumAllocation > 1.0 )
1277
+ {
1278
+ LogPrintf (" WARN: %s: allocation percentage over 100\%, ending sidestake allocations." , __func__);
1279
+ break ;
1264
1280
}
1265
- // If we get here and dSumAllocation is zero then the enablesidestaking flag was set, but no VALID distribution
1266
- // was provided in the config file, so warn in the debug log.
1267
- if (!dSumAllocation)
1268
- LogPrintf (" WARN: StakeMiner: enablesidestaking was set in config but nothing has been allocated for"
1269
- " distribution!" );
1281
+
1282
+ vSideStakeAlloc.push_back (std::pair<std::string, double >(sAddress , dAllocation));
1283
+ LogPrint (BCLog::LogFlags::MINER, " INFO: %s: SideStakeAlloc Address %s, Allocation %f" ,
1284
+ __func__, sAddress , dAllocation);
1270
1285
}
1271
1286
1272
- return fEnableSideStaking ;
1287
+ // If we get here and dSumAllocation is zero then the enablesidestaking flag was set, but no VALID distribution
1288
+ // was provided in the config file, so warn in the debug log.
1289
+ if (!dSumAllocation)
1290
+ LogPrintf (" WARN: %s: enablesidestaking was set in config but nothing has been allocated for"
1291
+ " distribution!" );
1292
+
1293
+ return vSideStakeAlloc;
1273
1294
}
1274
1295
1275
1296
// This function parses the config file for the directives for stake splitting. It is used
@@ -1325,17 +1346,21 @@ void StakeMiner(CWallet *pwallet)
1325
1346
int64_t nMinStakeSplitValue = 0 ;
1326
1347
double dEfficiency = 0 ;
1327
1348
int64_t nDesiredStakeOutputValue = 0 ;
1328
- SideStakeAlloc vSideStakeAlloc = {};
1329
-
1330
- // nMinStakeSplitValue and dEfficiency are out parameters.
1331
- bool fEnableStakeSplit = GetStakeSplitStatusAndParams (nMinStakeSplitValue, dEfficiency, nDesiredStakeOutputValue);
1332
-
1333
- // vSideStakeAlloc is an out parameter.
1334
- bool fEnableSideStaking = GetSideStakingStatusAndAlloc (vSideStakeAlloc);
1349
+ SideStakeAlloc vSideStakeAlloc;
1335
1350
1336
1351
while (!fShutdown )
1337
1352
{
1338
- // wait for next round
1353
+ // nMinStakeSplitValue and dEfficiency are out parameters.
1354
+ bool fEnableStakeSplit = GetStakeSplitStatusAndParams (nMinStakeSplitValue, dEfficiency, nDesiredStakeOutputValue);
1355
+
1356
+ bool fEnableSideStaking = gArgs .GetBoolArg (" -enablesidestaking" );
1357
+
1358
+ LogPrint (BCLog::LogFlags::MINER, " StakeMiner: fEnableSideStaking = %u" , fEnableSideStaking );
1359
+
1360
+ // vSideStakeAlloc is an out parameter.
1361
+ if (fEnableSideStaking ) vSideStakeAlloc = GetSideStakingStatusAndAlloc ();
1362
+
1363
+ // wait for next round
1339
1364
MilliSleep (nMinerSleep);
1340
1365
1341
1366
g_timer.InitTimer (" miner" , LogInstance ().WillLogCategory (BCLog::LogFlags::MISC));
0 commit comments