Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More logs #1926

Merged
merged 1 commit into from Jul 17, 2019
Merged

More logs #1926

Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

More logs

  • Loading branch information...
lontivero committed Jul 16, 2019
commit b3cc68fe846b24a61ece6aeb6d01ab4af2628a40
@@ -1449,42 +1449,51 @@ public async Task SendTransactionAsync(SmartTransaction transaction)
}

Logger.LogInfo<WalletService>($"Trying to broadcast transaction with random node ({node.RemoteSocketAddress}):{transaction.GetHash()}");
Mempool.TryAddToBroadcastStore(transaction.Transaction, node.RemoteSocketEndpoint.ToString()); // So we'll reply to INV with this transaction.
var addedToBroadcastStore = Mempool.TryAddToBroadcastStore(transaction.Transaction, node.RemoteSocketEndpoint.ToString()); // So we'll reply to INV with this transaction.
if(!addedToBroadcastStore)
{
Logger.LogWarning<WalletService>($"Transaction {transaction.GetHash()} was already present in the broadcast store.");
}
var invPayload = new InvPayload(transaction.Transaction);
// Give 7 seconds to send the inv payload.
using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(7)))
{
await node.SendMessageAsync(invPayload).WithCancellation(cts.Token); // ToDo: It's dangerous way to cancel. Implement proper cancellation to NBitcoin!
}

// Give 7 seconds for serving.
var timeout = 0;
Mempool.TryGetFromBroadcastStore(transaction.GetHash(), out TransactionBroadcastEntry entry);
while (!entry.IsBroadcasted())
if(Mempool.TryGetFromBroadcastStore(transaction.GetHash(), out TransactionBroadcastEntry entry))
{
if (timeout > 7)
// Give 7 seconds for serving.
var timeout = 0;
while (!entry.IsBroadcasted())
{
throw new TimeoutException("Did not serve the transaction.");
if (timeout > 7)
{
throw new TimeoutException("Did not serve the transaction.");
}
await Task.Delay(1_000);
timeout++;
}
await Task.Delay(1000);
timeout++;
}
node.DisconnectAsync("Thank you!");
Logger.LogInfo<MempoolBehavior>($"Disconnected node: {node.RemoteSocketAddress}. Successfully broadcasted transaction: {transaction.GetHash()}.");

// Give 21 seconds for propagation.
timeout = 0;
while (entry.GetPropagationConfirmations() < 2)
{
if (timeout > 21)
node.DisconnectAsync("Thank you!");
Logger.LogInfo<MempoolBehavior>($"Disconnected node: {node.RemoteSocketAddress}. Successfully broadcasted transaction: {transaction.GetHash()}.");

// Give 21 seconds for propagation.
timeout = 0;
while (entry.GetPropagationConfirmations() < 2)
{
throw new TimeoutException("Did not serve the transaction.");
if (timeout > 21)
{
throw new TimeoutException("Did not serve the transaction.");
}
await Task.Delay(1_000);
timeout++;
}
await Task.Delay(1000);
timeout++;
Logger.LogInfo<MempoolBehavior>($"Transaction is successfully propagated: {transaction.GetHash()}.");
}
else
{
Logger.LogWarning<WalletService>($"Expected transaction {transaction.GetHash()} was not found in the broadcast store.");
}
Logger.LogInfo<MempoolBehavior>($"Transaction is successfully propagated: {transaction.GetHash()}.");

break;
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.