Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
waiting for change delay
Browse files Browse the repository at this point in the history
  • Loading branch information
dkackman committed Nov 20, 2023
1 parent 8e29d5b commit f6c76c6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions DlMirrorSync/ChiaService.cs
Expand Up @@ -16,16 +16,16 @@ public async Task<ulong> GetFee(ulong cost, CancellationToken stoppingToken)
{
try
{
int[] targetTimes = { 300 }; // five minutes
int[] targetTimes = [300]; // five minutes
var fee = await _fullNode.GetFeeEstimate(cost, targetTimes, stoppingToken);
return fee.estimates.First();
}
catch (Exception ex)
{
_logger.LogWarning("Could not connect to full node {Message}", ex.Message);
_logger.LogWarning("Could not connect to full node. Using fee amount from config: {Message}", ex.InnerException?.Message ?? ex.Message);
return _configuration.GetValue<ulong>("DlMirrorSync:DefaultFee", 500000);
}
}

public Wallet GetWallet(uint walletId) => new Wallet(walletId, _wallet);
public Wallet GetWallet(uint walletId) => new(walletId, _wallet);
}
9 changes: 8 additions & 1 deletion DlMirrorSync/SyncService.cs
Expand Up @@ -48,10 +48,17 @@ await foreach (var id in _mirrorService.FetchLatest(stoppingToken))
_logger.LogInformation("Adding mirror {id}", id);
await _dataLayer.AddMirror(id, addMirrorAmount, Enumerable.Empty<string>(), fee, stoppingToken);
}
else if (balance.SpendableBalance == 0 && addMirrorAmount + fee < balance.PendingChange)
{
// no more spendable funds but we have change incoming, pause and see if it has arrived
var waitingForChangeDelaylMinutes = _configuration.GetValue("App:WaitingForChangeDelaylMinutes", 2);
_logger.LogWarning("Waiting for change {WaitingForChangePollingIntervalMinutes} minutes", waitingForChangeDelaylMinutes);
await Task.Delay(TimeSpan.FromMinutes(waitingForChangeDelaylMinutes), stoppingToken);
}
else
{
_logger.LogWarning("Insufficient funds to add mirror {id}. Balance={SpendableBalance}, Cost={addMirrorAmount}, Fee={fee}", id, balance.SpendableBalance, addMirrorAmount, fee);
_logger.LogWarning("Stopping mirror sync for now.");
_logger.LogWarning("Pausing sync for now");

// stop trying to add mirrors until we have more funds
return;
Expand Down
1 change: 1 addition & 0 deletions DlMirrorSync/appsettings.Development.json
Expand Up @@ -14,6 +14,7 @@
}
},
"DlMirrorSync": {
"WaitingForChangeDelaylMinutes": 2,
"PollingIntervalMinutes": 1,
"MirrorServiceUri": "https://api.datalayer.storage/mirrors/v1/list_all",
"DefaultFee": 500000,
Expand Down
1 change: 1 addition & 0 deletions DlMirrorSync/appsettings.json
Expand Up @@ -15,6 +15,7 @@
}
},
"DlMirrorSync": {
"WaitingForChangeDelaylMinutes": 2,
"PollingIntervalMinutes": 1440,
"MirrorServiceUri": "https://api.datalayer.storage/mirrors/v1/list_all",
"DefaultFee": 500000,
Expand Down

0 comments on commit f6c76c6

Please sign in to comment.