Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1cce5416e | ||
|
|
670c87f144 |
@ -4,6 +4,7 @@ using NBitcoin.RPC;
|
||||
using NBXplorer.Backend;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NBXplorer.Logging;
|
||||
|
||||
namespace NBXplorer
|
||||
{
|
||||
@ -60,15 +61,21 @@ namespace NBXplorer
|
||||
var logger = LoggerFactory.CreateLogger($"NBXplorer.Broadcaster.{network.CryptoCode}");
|
||||
var rpc = indexer.GetConnectedClient();
|
||||
if (rpc is null)
|
||||
{
|
||||
Logs.Explorer.LogInformation($"NO RPC");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool broadcast = true;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var accepted = await rpc.TestMempoolAcceptAsync(tx);
|
||||
Logs.Explorer.LogInformation($"Tested");
|
||||
if (!accepted.IsAllowed)
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Not allowed for reason {accepted.RejectReason}");
|
||||
var rejectReason = GetRejectReason(accepted.RejectReason);
|
||||
SetResult(rejectReason, result);
|
||||
broadcast = rejectReason is Reject.Unknown;
|
||||
|
||||
@ -5,6 +5,8 @@ using NBXplorer.Backend;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NBXplorer.Logging;
|
||||
|
||||
namespace NBXplorer.HostedServices
|
||||
{
|
||||
@ -42,15 +44,19 @@ namespace NBXplorer.HostedServices
|
||||
}
|
||||
}
|
||||
|
||||
Logs.Explorer.LogInformation($"Tx to broadcast: {txs.Count}");
|
||||
foreach (var tx in txs)
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Broadcast: {tx.Id}");
|
||||
var result = await Broadcaster.Broadcast(tx.Network, tx.Tx, tx.Id);
|
||||
if (result.MempoolConflict)
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Conflict");
|
||||
await conn.ExecuteAsync("UPDATE txs SET replaced_by=@unk_tx_id WHERE code=@code AND tx_id=@tx_id AND mempool IS TRUE AND replaced_by IS NULL", new { code = tx.Network.CryptoCode, tx_id = tx.Id.ToString(), unk_tx_id = NBXplorerNetwork.UnknownTxId.ToString() });
|
||||
}
|
||||
else if (result.MissingInput || result.UnknownError)
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Missing input");
|
||||
await conn.ExecuteAsync("UPDATE txs SET mempool='f' WHERE code=@code AND tx_id=@tx_id AND mempool IS TRUE", new { code = tx.Network.CryptoCode, tx_id = tx.Id.ToString() });
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
using NBitcoin.Logging;
|
||||
using Logs = NBXplorer.Logging.Logs;
|
||||
|
||||
namespace NBXplorer.HostedServices
|
||||
{
|
||||
@ -28,18 +30,21 @@ namespace NBXplorer.HostedServices
|
||||
foreach (var task in ServiceProvider.GetServices<ScheduledTask>())
|
||||
jobs.Writer.TryWrite(task);
|
||||
|
||||
loop = Task.WhenAll(Enumerable.Range(0, 3).Select(_ => Loop(cts.Token)).ToArray());
|
||||
loop = Task.WhenAll(Enumerable.Range(0, 3).Select(i => Loop(cts.Token, i)).ToArray());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
Task loop;
|
||||
private async Task Loop(CancellationToken token)
|
||||
private async Task Loop(CancellationToken token, int i)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Starting loop {i}");
|
||||
await foreach (var job in jobs.Reader.ReadAllAsync(token))
|
||||
{
|
||||
Logs.Explorer.LogInformation($"{i}: Run job {job.PeriodicTaskType}");
|
||||
if (job.NextScheduled <= DateTimeOffset.UtcNow)
|
||||
{
|
||||
Logs.Explorer.LogInformation($"{i}: GO! {job.PeriodicTaskType}");
|
||||
var t = (IPeriodicTask)ServiceProvider.GetService(job.PeriodicTaskType);
|
||||
try
|
||||
{
|
||||
@ -56,9 +61,11 @@ namespace NBXplorer.HostedServices
|
||||
finally
|
||||
{
|
||||
job.NextScheduled = DateTimeOffset.UtcNow + job.Every;
|
||||
Logs.Explorer.LogInformation($"{i}: Rescheduled for {job.NextScheduled:u}");
|
||||
}
|
||||
}
|
||||
_ = Wait(job, token);
|
||||
Logs.Explorer.LogInformation($"{i}: NEEXT");
|
||||
}
|
||||
}
|
||||
catch when (token.IsCancellationRequested)
|
||||
@ -71,13 +78,19 @@ namespace NBXplorer.HostedServices
|
||||
var timeToWait = job.NextScheduled - DateTimeOffset.UtcNow;
|
||||
try
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Wait for {job.PeriodicTaskType} for {timeToWait.TotalMinutes} minutes");
|
||||
await Task.Delay(timeToWait, token);
|
||||
}
|
||||
catch { }
|
||||
Logs.Explorer.LogInformation($"Wait to write");
|
||||
while (await jobs.Writer.WaitToWriteAsync())
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Writing");
|
||||
if (jobs.Writer.TryWrite(job))
|
||||
{
|
||||
Logs.Explorer.LogInformation($"Write!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user