Skip to content

Commit

Permalink
feat: add an instrument to portal-bridge for more clear logs
Browse files Browse the repository at this point in the history
  • Loading branch information
KolbyML committed Jan 6, 2024
1 parent ed6cf91 commit 611b537
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion portal-bridge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
Process to feed the portal network by gossiping data retrieved from a trusted provider. Currently, this is only compatible with `Trin` & `Fluffy` clients.

ex.
```
```sh
git clone https://github.com/ethereum/portal-accumulators.git
cargo run -p portal-bridge -- --node-count 1 --executable-path ./target/debug/trin --epoch-accumulator-path ./portal-accumulators trin
```

Expand Down
6 changes: 5 additions & 1 deletion portal-bridge/src/bridge/beacon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use jsonrpsee::http_client::HttpClient;
use serde_json::Value;
use ssz_types::VariableList;
use tokio::time::{interval, sleep, Duration, MissedTickBehavior};
use tracing::{info, warn};
use tracing::{info, warn, Instrument};

use crate::api::consensus::ConsensusApi;
use crate::constants::BEACON_GENESIS_TIME;
Expand Down Expand Up @@ -153,6 +153,7 @@ impl BeaconBridge {
&finalized_block_root,
slot_stats_clone,
)
.in_current_span()
.await
.or_else(|err| {
warn!("Failed to serve light client bootstrap: {err}");
Expand All @@ -173,6 +174,7 @@ impl BeaconBridge {
current_period,
slot_stats_clone,
)
.in_current_span()
.await
.or_else(|err| {
warn!("Failed to serve light client update: {err}");
Expand All @@ -192,6 +194,7 @@ impl BeaconBridge {
finalized_slot,
slot_stats_clone,
)
.in_current_span()
.await
.or_else(|err| {
warn!("Failed to serve light client finality update: {err}");
Expand All @@ -205,6 +208,7 @@ impl BeaconBridge {
let optimistic_update = tokio::spawn(async move {
if let Err(err) =
Self::serve_light_client_optimistic_update(api, portal_clients, slot_stats_clone)
.in_current_span()
.await
{
warn!("Failed to serve light client optimistic update: {err}");
Expand Down
11 changes: 8 additions & 3 deletions portal-bridge/src/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::{Arc, Mutex};

use jsonrpsee::http_client::HttpClient;
use tokio::time::{sleep, Duration};
use tracing::{debug, warn};
use tracing::{debug, warn, Instrument};

use crate::stats::{BeaconSlotStats, HistoryBlockStats, StatsReporter};
use ethportal_api::jsonrpsee::core::Error;
Expand All @@ -28,7 +28,9 @@ pub async fn gossip_beacon_content(
let client = client.clone();
let content_key = content_key.clone();
let content_value = content_value.clone();
let result = tokio::spawn(beacon_trace_gossip(client, content_key, content_value)).await?;
let result =
tokio::spawn(beacon_trace_gossip(client, content_key, content_value).in_current_span())
.await?;
results.push(result);
}
if let Ok(mut data) = slot_stats.lock() {
Expand Down Expand Up @@ -91,7 +93,10 @@ pub async fn gossip_history_content(
let client = client.clone();
let content_key = content_key.clone();
let content_value = content_value.clone();
let result = tokio::spawn(history_trace_gossip(client, content_key, content_value)).await?;
let result = tokio::spawn(
history_trace_gossip(client, content_key, content_value).in_current_span(),
)
.await?;
results.push(result);
}
if let Ok(mut data) = block_stats.lock() {
Expand Down
11 changes: 9 additions & 2 deletions portal-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use clap::Parser;
use tokio::time::{sleep, Duration};
use tracing::Instrument;

use ethportal_api::jsonrpsee::http_client::{HttpClient, HttpClientBuilder};
use ethportal_api::types::cli::{DEFAULT_DISCOVERY_PORT, DEFAULT_WEB3_HTTP_PORT};
Expand Down Expand Up @@ -64,7 +65,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let beacon_bridge =
BeaconBridge::new(consensus_api, bridge_mode, Arc::new(portal_clients));

beacon_bridge.launch().await;
beacon_bridge
.launch()
.instrument(tracing::info_span!("beacon"))
.await;
});

bridge_tasks.push(bridge_handle);
Expand All @@ -86,7 +90,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
bridge_config.epoch_acc_path,
);

bridge.launch().await;
bridge
.launch()
.instrument(tracing::info_span!("history"))
.await;
});

bridge_tasks.push(bridge_handle);
Expand Down

0 comments on commit 611b537

Please sign in to comment.