Skip to content

Commit

Permalink
Add exponential backoff to payins
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Jun 24, 2024
1 parent 6e21e5b commit ab6229a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/Console/Commands/CheckPendingPayins.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ public function handle()
$controller = new LnAddressController();

foreach ($pendingPayins as $payin) {

$last_check = $payin->last_check;
$retry = $payin->retry_check;

$expectedDelaySeconds = min(10 * (2 ** $retry), 600);

if (now()->timestamp - $last_check->timestamp < $expectedDelaySeconds) {
continue;
}

$payin->last_check = now();
$payin->retry_check = $retry + 1;
$payin->save();

$invoiceStatus = $controller->getInvoiceStatus($payin->payment_hash);

if (! $invoiceStatus) {
Expand All @@ -44,7 +58,7 @@ public function handle()

Log::info('Payin settled: '.$payin->id);
} else {
// Log::info('Payin still pending: '.$payin->id);
Log::info('Payin still pending: '.$payin->id);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('payins', function (Blueprint $table) {
$table->timestamp('last_check')->after('updated_at')->useCurrent();
$table->integer('retry_check')->default(0)->after('last_check');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('payins', function (Blueprint $table) {
$table->dropColumn('last_check');
$table->dropColumn('retry_check');
});
}
};

0 comments on commit ab6229a

Please sign in to comment.