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

Update logging #30

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Lantern.Beacon.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static async Task Main()
.WithEntry(EnrEntryKey.Id, new EntryId("v4"))
.WithEntry(EnrEntryKey.Secp256K1, new EntrySecp256K1(sessionOptions.Signer.PublicKey));
var discv5LoggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(LogLevel.None));

// Beacon client options
var syncProtocolOptions = new SyncProtocolOptions
{
Expand Down
12 changes: 6 additions & 6 deletions src/Lantern.Beacon/BeaconClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public async Task InitAsync()

customDiscoveryProtocol.OnAddPeer = HandleDiscoveredPeer;

_logger.LogInformation("Beacon client manager started with address {Address}", LocalPeer.Address);
_logger.LogInformation("Client started with address {Address}", LocalPeer.Address);
}
catch (Exception e)
{
Expand Down Expand Up @@ -165,7 +165,7 @@ private async Task DisplaySyncStatus(CancellationToken token)

private async Task ProcessPeerDiscoveryAsync(CancellationToken token)
{
_logger.LogInformation("Running peer discovery...");
_logger.LogDebug("Running peer discovery...");
var semaphore = new SemaphoreSlim(clientOptions.MaxParallelDials);

while (!token.IsCancellationRequested)
Expand Down Expand Up @@ -310,15 +310,15 @@ private async Task DialPeer(Multiaddress peer, CancellationToken token = default

if (completedTask != timeoutTask)
{
_logger.LogInformation("Successfully dialed peer /ip4/{Ip4}/tcp/{TcpPort}/p2p/{PeerId}", ip4, tcpPort,
_logger.LogDebug("Successfully dialed peer /ip4/{Ip4}/tcp/{TcpPort}/p2p/{PeerId}", ip4, tcpPort,
peerIdString);

var remotePeerId = dialTask.Result.Address.GetPeerId();
var result = peerState.PeerProtocols.TryRemove(remotePeerId!, out var peerProtocols);

if (!result)
{
_logger.LogInformation("No protocols found for peer /ip4/{Ip4}/tcp/{TcpPort}/p2p/{PeerId}", ip4,
_logger.LogDebug("No protocols found for peer /ip4/{Ip4}/tcp/{TcpPort}/p2p/{PeerId}", ip4,
tcpPort, peerIdString);
await dialTask.Result.DisconnectAsync();
return;
Expand All @@ -330,7 +330,7 @@ private async Task DialPeer(Multiaddress peer, CancellationToken token = default
if (supportsLightClientProtocols)
{
_logger.LogInformation(
"Peer /ip4/{Ip4}/tcp/{TcpPort}/p2p/{PeerId} supports all light client protocols", ip4, tcpPort,
"Found peer /ip4/{Ip4}/tcp/{TcpPort}/p2p/{PeerId} that supports all light client protocols", ip4, tcpPort,
peerIdString);

discoveryProtocol.OnAddPeer?.Invoke([peer]);
Expand All @@ -352,7 +352,7 @@ private async Task DialPeer(Multiaddress peer, CancellationToken token = default
}
else
{
_logger.LogInformation(
_logger.LogDebug(
"Peer /ip4/{Ip4}/tcp/{TcpPort}/p2p/{PeerId} does not support all light client protocols. Disconnecting...",
ip4, tcpPort, peerIdString);
await dialTask.Result.DisconnectAsync();
Expand Down
28 changes: 3 additions & 25 deletions src/Lantern.Beacon/Networking/Discovery/CustomDiscoveryProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<bool> InitAsync()

public async Task GetDiscoveredNodesAsync(Multiaddress localPeerAddr, CancellationToken token = default)
{
_logger.LogInformation("Starting discovery with local peer address: {LocalPeerAddr}", localPeerAddr);
_logger.LogDebug("Starting discovery with local peer address: {LocalPeerAddr}", localPeerAddr);

try
{
Expand All @@ -58,7 +58,7 @@ public async Task GetDiscoveredNodesAsync(Multiaddress localPeerAddr, Cancellati
break;
}

_logger.LogInformation("Found {Count} peers to dial so far...", multiaddresses.Count);
_logger.LogInformation("Discovered {Count} peers so far...", multiaddresses.Count);

var batchNodes = nodes.Skip(i).Take(beaconOptions.MaxParallelDials).ToList();
var tasks = batchNodes.Select(node => discv5Protocol.SendFindNodeAsync(node, randomNodeId)).ToList();
Expand Down Expand Up @@ -107,33 +107,11 @@ public async Task GetDiscoveredNodesAsync(Multiaddress localPeerAddr, Cancellati
discoveredNodes.Clear();
}
}

// var multiaddresses = new List<Multiaddress>();
// var bootNodes = new[]
// {
// "/ip4/162.55.138.93/tcp/9000/p2p/16Uiu2HAmTUhE91q42JaTWBSHAu8zoPcFiZdnvLD9ujc6dPNBWcoy",
// "/ip4/198.244.165.204/tcp/9000/p2p/16Uiu2HAmEP83jeVdeSiwrgqSaUX8SQgEqUAhe4tTZKm1w7y7vUeL",
// "/ip4/102.218.213.140/tcp/32000/p2p/16Uiu2HAmDdPDsuxkewTeNNqq1rL9A5PdKFD486P6BvqyyVppY89w",
// "/ip4/185.177.124.120/tcp/9000/p2p/16Uiu2HAmF59QpFcwjTPeU7iXMpkBqwUALy5rNW5j8i6AQVi8nG7e",
// "/ip4/140.228.71.48/tcp/9000/p2p/16Uiu2HAmP4jwhWtYRgR7Lkp4H75S7vXDV8NBN9gdZH6k2di124PB",
// "/ip4/121.134.209.218/tcp/9000/p2p/16Uiu2HAmMM3xTjNbYipQLjWXC7zHB6ygtDVMZJpQ6EeSG6jDiYSR",
// };
//
// foreach (var bootNode in bootNodes)
// {
// var multiaddress = Multiaddress.Decode(bootNode);
// if (multiaddress == null)
// {
// continue;
// }
//
// multiaddresses.Add(multiaddress);
// }

if (multiaddresses.Count != 0)
{
OnAddPeer?.Invoke(multiaddresses.ToArray());
_logger.LogInformation("Found {Count} peers to dial", multiaddresses.Count);
_logger.LogInformation("Discovery completed. Found {Count} peers for dialing", multiaddresses.Count);
}
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions src/Lantern.Beacon/Networking/Gossip/GossipSubManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void Start(CancellationToken token = default)
};

_ = Task.Run(() => router.RunAsync(beaconClientManager.LocalPeer, discoveryProtocol, settings, token), token);
_logger.LogInformation("Running GossipSub protocol");
_logger.LogDebug("Running GossipSub protocol");
}

public async Task StopAsync()
Expand Down Expand Up @@ -185,7 +185,7 @@ private void CheckIfPeerExistsInGossip(PeerId peerId)

if (!foundLivePeer)
{
_logger?.LogInformation("Adding peer {PeerId} to 'GossipPeers'", peerId);
_logger?.LogInformation("Adding peer {PeerId} to GossipPeers", peerId);
peerState.GossipPeers.TryAdd(peerId, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@ public abstract class CustomPubsubProtocol : IProtocol
{
private readonly ILogger? _logger;
private readonly CustomPubsubRouter router;
private readonly IPeerState _peerState;
private readonly SyncProtocolOptions _syncProtocolOptions;

public string Id { get; }

public CustomPubsubProtocol(SyncProtocolOptions syncProtocolOptions, IPeerState peerState, string protocolId, CustomPubsubRouter router, ILoggerFactory? loggerFactory = null)
public CustomPubsubProtocol(string protocolId, CustomPubsubRouter router, ILoggerFactory? loggerFactory = null)
{
_syncProtocolOptions = syncProtocolOptions;
_peerState = peerState;
_logger = loggerFactory?.CreateLogger(GetType());
Id = protocolId;
this.router = router;
Expand Down Expand Up @@ -98,10 +94,10 @@ public override string ToString()
}
}

public class FloodsubProtocol(SyncProtocolOptions syncProtocolOptions, IPeerState peerState, CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(syncProtocolOptions, peerState, CustomPubsubRouter.FloodsubProtocolVersion, router, loggerFactory);
public class FloodsubProtocol(CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(CustomPubsubRouter.FloodsubProtocolVersion, router, loggerFactory);

public class GossipsubProtocol(SyncProtocolOptions syncProtocolOptions, IPeerState peerState, CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(syncProtocolOptions, peerState, CustomPubsubRouter.GossipsubProtocolVersionV10, router, loggerFactory);
public class GossipsubProtocol(CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(CustomPubsubRouter.GossipsubProtocolVersionV10, router, loggerFactory);

public class GossipsubProtocolV11(SyncProtocolOptions syncProtocolOptions, IPeerState peerState, CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(syncProtocolOptions, peerState, CustomPubsubRouter.GossipsubProtocolVersionV11, router, loggerFactory);
public class GossipsubProtocolV11(CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(CustomPubsubRouter.GossipsubProtocolVersionV11, router, loggerFactory);

public class GossipsubProtocolV12(SyncProtocolOptions syncProtocolOptions, IPeerState peerState, CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(syncProtocolOptions, peerState, CustomPubsubRouter.GossipsubProtocolVersionV12, router, loggerFactory);
public class GossipsubProtocolV12(CustomPubsubRouter router, ILoggerFactory? loggerFactory = null) : CustomPubsubProtocol(CustomPubsubRouter.GossipsubProtocolVersionV12, router, loggerFactory);
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ public async Task RunAsync(ILocalPeer localPeer, IDiscoveryProtocol discoveryPro

_ = localPeer.ListenAsync(localPeer.Address, token);
_ = StartDiscoveryAsync(discoveryProtocol, token);
logger?.LogInformation("Started");

// reconnection if needed

_ = Task.Run(async () =>
{
while (!token.IsCancellationRequested)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected override async Task ConnectAsync(IChannel downChannel, IChannelFactory
peerState.InitiatorChannels.Clear();
peerState.ReceiverChannels.Clear();

_logger?.LogInformation("Connection with peer {PeerId} has been closed", context.RemotePeer.Address.GetPeerId()!.ToString());
_logger?.LogDebug("Connection with peer {PeerId} has been closed", context.RemotePeer.Address.GetPeerId()!.ToString());
}

private void HandleSubDialRequests(IPeerContext context, IChannelFactory channelFactory, bool isListener, IChannel downChannel, PeerConnectionState peerState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task ListenAsync(IChannel downChannel, IChannelFactory? upChannelFa
await downChannel.WriteAsync(rawData, cts.Token);
await downChannel.CloseAsync();

_logger?.LogInformation("Sent status response to {PeerId} with forkDigest={forkDigest}, finalizedRoot={finalizedRoot}, finalizedEpoch={finalizedEpoch}, headRoot={headRoot}, headSlot={headSlot}",
_logger?.LogDebug("Sent status response to {PeerId} with forkDigest={forkDigest}, finalizedRoot={finalizedRoot}, finalizedEpoch={finalizedEpoch}, headRoot={headRoot}, headSlot={headSlot}",
context.RemotePeer.Address.Get<P2P>(),
Convert.ToHexString(forkDigest),
Convert.ToHexString(finalisedRoot),
Expand Down
8 changes: 0 additions & 8 deletions test/Lantern.Beacon.Tests/BeaconClientManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ public async Task InitAsync_ShouldInitializeCorrectly()
_beaconClientManager = new BeaconClientManager(new BeaconClientOptions(), _mockManualDiscoveryProtocol.Object, _mockLiteDbService.Object, _mockCustomDiscoveryProtocol.Object, _mockPeerState.Object, _mockSyncProtocol.Object,_mockPeerFactory.Object, _mockIdentityManager.Object, _mockLoggerFactory.Object);

await _beaconClientManager.InitAsync();

_mockLogger.Verify(log => log.Log(
LogLevel.Information,
It.IsAny<EventId>(),
It.Is<It.IsAnyType>((v, t) => v.ToString().Contains("Beacon client manager started with address")),
null,
It.IsAny<Func<It.IsAnyType, Exception, string>>()),
Times.Once);
}

[Test]
Expand Down
Loading