charge offenders randomly

This commit is contained in:
Evan Duffield 2014-11-17 12:54:56 -07:00
parent 5a5db74fa7
commit a32990e4ad

View File

@ -605,7 +605,6 @@ void CDarkSendPool::Check()
void CDarkSendPool::ChargeFees(){ void CDarkSendPool::ChargeFees(){
if(fMasterNode) { if(fMasterNode) {
//we don't need to charge collateral for every offence. //we don't need to charge collateral for every offence.
int r = rand()%100;
int offences = 0; int offences = 0;
if(state == POOL_STATUS_ACCEPTING_ENTRIES){ if(state == POOL_STATUS_ACCEPTING_ENTRIES){
@ -637,12 +636,21 @@ void CDarkSendPool::ChargeFees(){
} }
} }
int r = rand()%100;
int target = 0;
//mostly offending? //mostly offending?
if(offences >= POOL_MAX_TRANSACTIONS-1 && r > 33) return; if(offences >= POOL_MAX_TRANSACTIONS-1 && r > 33) return;
//everyone is an offender? That's not right //everyone is an offender? That's not right
if(offences >= POOL_MAX_TRANSACTIONS) return; if(offences >= POOL_MAX_TRANSACTIONS) return;
//charge one of the offenders randomly
if(offences > 1) target = 50;
//pick random client to charge
r = rand()%100;
if(state == POOL_STATUS_ACCEPTING_ENTRIES){ if(state == POOL_STATUS_ACCEPTING_ENTRIES){
BOOST_FOREACH(const CTransaction& txCollateral, vecSessionCollateral) { BOOST_FOREACH(const CTransaction& txCollateral, vecSessionCollateral) {
bool found = false; bool found = false;
@ -653,7 +661,7 @@ void CDarkSendPool::ChargeFees(){
} }
// This queue entry didn't send us the promised transaction // This queue entry didn't send us the promised transaction
if(!found){ if(!found && r > target){
LogPrintf("CDarkSendPool::ChargeFees -- found uncooperative node (didn't send transaction). charging fees.\n"); LogPrintf("CDarkSendPool::ChargeFees -- found uncooperative node (didn't send transaction). charging fees.\n");
CWalletTx wtxCollateral = CWalletTx(pwalletMain, txCollateral); CWalletTx wtxCollateral = CWalletTx(pwalletMain, txCollateral);
@ -674,7 +682,7 @@ void CDarkSendPool::ChargeFees(){
// who didn't sign? // who didn't sign?
BOOST_FOREACH(const CDarkSendEntry v, entries) { BOOST_FOREACH(const CDarkSendEntry v, entries) {
BOOST_FOREACH(const CDarkSendEntryVin s, v.sev) { BOOST_FOREACH(const CDarkSendEntryVin s, v.sev) {
if(!s.isSigSet){ if(!s.isSigSet && r > target){
LogPrintf("CDarkSendPool::ChargeFees -- found uncooperative node (didn't sign). charging fees.\n"); LogPrintf("CDarkSendPool::ChargeFees -- found uncooperative node (didn't sign). charging fees.\n");
CWalletTx wtxCollateral = CWalletTx(pwalletMain, v.collateral); CWalletTx wtxCollateral = CWalletTx(pwalletMain, v.collateral);