Skip to content

Commit

Permalink
backend: avoid to clear earnings during payouts (tpruvot#249)
Browse files Browse the repository at this point in the history
+ simplify payment code based on RavenMinerPool commit
  • Loading branch information
tpruvot committed Mar 24, 2018
1 parent 1b3f15f commit e5dd766
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions web/yaamp/core/backend/payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,19 @@ function BackendCoinPayments($coin)
if(!$user) continue;
if(!isset($addresses[$user->username])) continue;

$payment_amount = bitcoinvaluetoa($addresses[$user->username]);

$payout = new db_payouts;
$payout->account_id = $user->id;
$payout->time = time();
$payout->amount = bitcoinvaluetoa($user->balance*$coef);
$payout->amount = $payment_amount;
$payout->fee = 0;
$payout->idcoin = $coin->id;

if ($payout->save()) {
$payouts[$payout->id] = $user->id;

$user->balance = bitcoinvaluetoa(floatval($user->balance) - (floatval($user->balance)*$coef));
$user->balance = bitcoinvaluetoa(floatval($user->balance) - $payment_amount);
$user->save();
}
}
Expand Down
11 changes: 8 additions & 3 deletions web/yaamp/modules/thread/CronjobController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public function actionRunBlocks()
dborun("update jobs set active=false");

BackendBlockFind1();
BackendClearEarnings();
BackendRentingUpdate();
if(!memcache_get($this->memcache->memcache, 'balances_locked')) {
BackendClearEarnings();
BackendRentingUpdate();
}
BackendProcessList();
BackendBlocksUpdate();

Expand Down Expand Up @@ -209,10 +211,13 @@ public function actionRun()

sleep(10);
BackendDoBackup();

memcache_set($this->memcache->memcache, 'apache_locked', false);

// prevent user balances changes during payments (blocks thread)
memcache_set($this->memcache->memcache, 'balances_locked', true);
BackendPayments();
memcache_set($this->memcache->memcache, 'balances_locked', false);

BackendCleanDatabase();

// BackendOptimizeTables();
Expand Down

0 comments on commit e5dd766

Please sign in to comment.