Skip to content

Commit b842f39

Browse files
committed
chore(c-bridge): polish logs
1 parent 71be57f commit b842f39

File tree

7 files changed

+56
-48
lines changed

7 files changed

+56
-48
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bridges/centralized-ethereum/src/actors/dr_database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl Actor for DrDatabase {
122122
|dr_database_from_storage, act, _| match dr_database_from_storage {
123123
Ok(dr_database_from_storage) => {
124124
if let Some(mut dr_database_from_storage) = dr_database_from_storage {
125-
log::info!("Load database from storage");
125+
log::info!("Database loaded from storage");
126126
act.dr = std::mem::take(&mut dr_database_from_storage.dr);
127127
act.max_dr_id = dr_database_from_storage.max_dr_id;
128128
} else {

bridges/centralized-ethereum/src/actors/dr_reporter.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Handler<DrReporterMsg> for DrReporter {
123123
msg.reports.retain(|report| {
124124
if self.pending_dr_reports.contains(&report.dr_id) {
125125
// Timeout is not over yet, no action is needed
126-
log::debug!("[{}]: currently being reported...", report.dr_id);
126+
log::debug!("[{}] => ignored as it's currently being reported", report.dr_id);
127127

128128
false
129129
} else {
@@ -228,14 +228,13 @@ impl Handler<DrReporterMsg> for DrReporter {
228228
)
229229
.await;
230230

231-
log::debug!(
232-
"[{:?}] will be reported in {} transactions",
233-
dr_ids,
234-
batched_reports.len()
231+
log::info!(
232+
"{:?} will be reported in {} transactions",
233+
dr_ids, batched_reports.len(),
235234
);
236235

237236
for (batched_report, eth_gas_limit) in batched_reports {
238-
log::debug!("Executing reportResultBatch {:?}", batched_report);
237+
// log::debug!("Executing reportResultBatch {:?}", batched_report);
239238

240239
let receipt_fut = wrb_contract.call_with_confirmations(
241240
"reportResultBatch",
@@ -251,7 +250,7 @@ impl Handler<DrReporterMsg> for DrReporter {
251250
let receipt = tokio::time::timeout(eth_tx_timeout, receipt_fut).await;
252251
match receipt {
253252
Ok(Ok(receipt)) => {
254-
log::debug!("[{:?}]: tx receipt: {:?}", dr_ids, receipt);
253+
log::debug!("{:?} <> {:?}", dr_ids, receipt);
255254
match handle_receipt(&receipt).await {
256255
Ok(()) => {
257256
let mut dismissed_dr_reports: HashSet<DrId> = Default::default();
@@ -261,7 +260,7 @@ impl Handler<DrReporterMsg> for DrReporter {
261260
{
262261
if dismissed_dr_reports.insert(dismissed_dr_id) {
263262
log::warn!(
264-
"[{}]: dismissed => {}",
263+
"[{}] >< dismissed due to \"{}\" ...",
265264
dismissed_dr_id,
266265
reason
267266
);
@@ -282,7 +281,7 @@ impl Handler<DrReporterMsg> for DrReporter {
282281
} else {
283282
// Finalize data requests that got successfully reported
284283
log::info!(
285-
"[{}]: success => drTallyTxHash: {}",
284+
"[{}] <= dr_tally_tx = {}",
286285
report.dr_id,
287286
report.dr_tally_tx_hash
288287
);
@@ -298,8 +297,7 @@ impl Handler<DrReporterMsg> for DrReporter {
298297
}
299298
Err(()) => {
300299
log::error!(
301-
"[{:?}]: evm tx failed: {}",
302-
dr_ids,
300+
"reportResultBatch(..) tx reverted: {}",
303301
receipt.transaction_hash
304302
);
305303
}
@@ -309,29 +307,32 @@ impl Handler<DrReporterMsg> for DrReporter {
309307
// Error in call_with_confirmations
310308
log::error!(
311309
"{}: {:?}",
312-
format!("reportResultBatch{:?}", &batched_report),
310+
format!("Cannot call reportResultBatch{:?}", &batched_report),
313311
e
314312
);
315313
}
316314
Err(elapsed) => {
317315
// Timeout is over
318-
log::warn!("[{:?}]: evm tx timeout after {}", dr_ids, elapsed);
316+
log::warn!(
317+
"Timeout ({} secs) when calling reportResultBatch{:?}",
318+
elapsed, &batched_report
319+
);
319320
}
320321
}
321322
}
322323

323324
if let Ok(x) = eth.balance(eth_from, None).await {
324325
if x < eth_from_balance {
325326
log::warn!(
326-
"EVM address {} loss: -{} ETH",
327+
"EVM address {} loss = -{} ETH",
327328
eth_from,
328329
Unit::Wei(&(eth_from_balance - x).to_string())
329330
.to_eth_str()
330331
.unwrap_or_default()
331332
);
332-
} else {
333+
} else if x > eth_from_balance {
333334
log::debug!(
334-
"EVM address {} revenue: +{} ETH",
335+
"EVM address {} revenue = +{} ETH",
335336
eth_from,
336337
Unit::Wei(&(x - eth_from_balance).to_string())
337338
.to_eth_str()
@@ -425,8 +426,9 @@ async fn split_by_gas_limit(
425426
if let Err(e) = estimated_gas {
426427
if batch_params.len() <= 1 {
427428
// Skip this single-query batch if still not possible to estimate gas
428-
log::error!("Cannot estimate gas limit: {:?}", e);
429-
log::warn!("Skipping report: {:?}", batch_params);
429+
log::error!("Cannot estimate gas limit: {:?}", e);
430+
log::warn!("Skipping report batch: {:?}", batch_params);
431+
430432
} else {
431433
// Split batch in half if gas estimation is not possible
432434
let (batch_tuples_1, batch_tuples_2) =
@@ -440,7 +442,7 @@ async fn split_by_gas_limit(
440442

441443
let estimated_gas = estimated_gas.unwrap();
442444
log::debug!(
443-
"reportResultBatch (x{} drs) estimated gas: {:?}",
445+
"reportResultBatch (x{} drs) estimated gas: {:?}",
444446
batch_params.len(),
445447
estimated_gas
446448
);
@@ -499,11 +501,11 @@ async fn split_by_gas_limit(
499501
v.push((batch_params, estimated_gas));
500502
continue;
501503
}
502-
Ok(_) => {
503-
if batch_params.len() <= 1 {
504-
log::warn!("Skipping unprofitable report: {:?}", batch_params);
505-
}
506-
}
504+
// Ok(_) => {
505+
// if batch_params.len() <= 1 {
506+
// log::warn!("Skipping unprofitable report: {:?}", batch_params);
507+
// }
508+
// }
507509
Err(e) => {
508510
if batch_params.len() <= 1 {
509511
log::error!("Cannot estimate report profit: {:?}", e);

bridges/centralized-ethereum/src/actors/dr_sender.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ impl DrSender {
9292
let res = witnet_client.send(req).await;
9393
witnet_node_pkh = match res {
9494
Ok(Ok(res)) => match serde_json::from_value::<String>(res) {
95-
Ok(pkh) => Some(pkh),
95+
Ok(pkh) => {
96+
log::info!("Pkh is {}", pkh);
97+
98+
Some(pkh)
99+
}
96100
Err(_) => None,
97101
},
98102
Ok(Err(_)) => {
@@ -108,10 +112,12 @@ impl DrSender {
108112
};
109113
} else {
110114
// TODO: alert if number of big enough utxos is less number of drs to broadcast
111-
// let req = jsonrpc::Request::method("getUtxoInfo")
115+
// let req = jsonrpc::Request::method("getBalance")
112116
// .timeout(Duration::from_millis(5_000))
113-
// .params(witnet_node_pkh.unwrap())
117+
// .params(witnet_node_pkh.clone().unwrap())
114118
// .expect("getUtxoInfo params failed serialization");
119+
// let res = witnet_client.send(req).await;
120+
// log::debug!("Balance of {:?}: {:?} nanoWIT", witnet_node_pkh.unwrap(), res)
115121
}
116122

117123
// process latest drs added or set as New in the database
@@ -145,6 +151,7 @@ impl DrSender {
145151
Ok(dr_tx) => {
146152
match serde_json::from_value::<DRTransaction>(dr_tx) {
147153
Ok(dr_tx) => {
154+
log::info!("[{}] => dr_tx = {}", dr_id, dr_tx.hash());
148155
// Save dr_tx_hash in database and set state to Pending
149156
dr_database_addr
150157
.send(SetDrInfoBridge(
@@ -161,22 +168,22 @@ impl DrSender {
161168
}
162169
Err(e) => {
163170
// Unexpected error deserializing hash
164-
panic!("[{}]: cannot deserialize dr_tx: {}", dr_id, e);
171+
panic!("[{}] >< cannot deserialize dr_tx: {}", dr_id, e);
165172
}
166173
}
167174
}
168175
Err(e) => {
169176
// Error sending transaction: node not synced, not enough balance, etc.
170177
// Do nothing, will retry later.
171-
log::error!("[{}]: cannot broadcast dr_tx: {}", dr_id, e);
178+
log::error!("[{}] >< cannot broadcast dr_tx: {}", dr_id, e);
172179
continue;
173180
}
174181
}
175182
}
176183
Err(err) => {
177184
// Error deserializing or validating data request: mark data request as
178185
// error and report error as result to ethereum.
179-
log::error!("[{}]: unacceptable data request bytecode: {}", dr_id, err);
186+
log::error!("[{}] >< unacceptable data request bytecode: {}", dr_id, err);
180187
let result = err.encode_cbor();
181188
// In this case there is no data request transaction, so
182189
// we set both the dr_tx_hash and dr_tally_tx_hash to zero values.

bridges/centralized-ethereum/src/actors/eth_poller.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,13 @@ impl EthPoller {
7575
}
7676

7777
fn check_new_requests_from_ethereum(&self, ctx: &mut Context<Self>, period: Duration) {
78-
log::debug!("Checking posted queries on the WitnetOracle contract...");
7978

8079
let wrb_contract = self.wrb_contract.clone().unwrap();
8180
let skip_first = U256::from(self.skip_first);
8281
let max_batch_size = self.max_batch_size;
8382

83+
log::debug!("Polling WitnetOracle at {:?}", wrb_contract.address());
84+
8485
// Check requests
8586
let fut = async move {
8687
let dr_database_addr = DrDatabase::from_registry();
@@ -118,7 +119,7 @@ impl EthPoller {
118119
next_dr_id = last_dr_id + max_batch_size;
119120
}
120121
let init_index = usize::try_from(last_dr_id + 1).unwrap();
121-
let last_index = usize::try_from(next_dr_id + 1).unwrap();
122+
let last_index = usize::try_from(next_dr_id).unwrap();
122123
let ids = init_index..last_index;
123124
let ids: Vec<Token> = ids.map(|id| Token::Uint(id.into())).collect();
124125

@@ -139,14 +140,14 @@ impl EthPoller {
139140
let status: u8 = status.to_string().parse().unwrap();
140141
match WitnetQueryStatus::from_code(status) {
141142
WitnetQueryStatus::Unknown => {
142-
log::debug!("[{}]: not available.", query_id);
143+
log::warn!("Skipped unavailable query [{}]", query_id);
143144
}
144145
WitnetQueryStatus::Posted => {
145-
log::info!("[{}]: not yet reported.", query_id);
146+
log::info!("Detected new query [{}]", query_id);
146147
posted_ids.push(Token::Uint(query_id));
147148
}
148149
WitnetQueryStatus::Reported | WitnetQueryStatus::Finalized => {
149-
log::debug!("[{}]: already reported.", query_id);
150+
log::info!("Skipped already solved query [{}]", query_id);
150151
dr_database_addr.do_send(SetDrState {
151152
dr_id: query_id,
152153
dr_state: DrState::Finished,
@@ -177,7 +178,7 @@ impl EthPoller {
177178
}
178179
} else {
179180
log::error!(
180-
"Fail to extract Witnet Data Request bytecodes from queries {:?}",
181+
"Fail to extract Witnet request bytecodes from queries {:?}",
181182
posted_ids
182183
);
183184
}
@@ -186,7 +187,7 @@ impl EthPoller {
186187
log::error!(
187188
"Fail to get status of queries #{} to #{}: {}",
188189
init_index,
189-
last_index,
190+
next_dr_id,
190191
queries_status.unwrap_err().to_string()
191192
);
192193
}

bridges/centralized-ethereum/src/actors/wit_poller.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ impl WitPoller {
104104
..
105105
})) => {
106106
log::info!(
107-
"[{}]: found tally {} for dr_tx {}",
107+
"[{}] <= dr_tx = {}",
108108
dr_id,
109-
&tally.hash(),
110109
dr_tx_hash
111110
);
112111

@@ -137,7 +136,7 @@ impl WitPoller {
137136
}
138137
Err(e) => {
139138
log::error!(
140-
"[{}]: cannot deserialize dataRequestReport([{}]): {:?}",
139+
"[{}] => cannot deserialize dr_tx = {}: {:?}",
141140
dr_id,
142141
dr_tx_hash,
143142
e
@@ -146,17 +145,16 @@ impl WitPoller {
146145
};
147146
} else {
148147
log::debug!(
149-
"[{}]: dataRequestReport([{}]) call error: {}",
148+
"[{}] <> dr_tx = {}",
150149
dr_id,
151-
dr_tx_hash,
152-
report.unwrap_err().to_string()
150+
dr_tx_hash
153151
);
154152
}
155153

156154
let elapsed_secs = current_timestamp - dr_tx_creation_timestamp;
157155
if elapsed_secs >= timeout_secs {
158-
log::debug!(
159-
"[{}]: retrying new dr_tx after {} secs",
156+
log::warn!(
157+
"[{}] => will retry new dr_tx after {} secs",
160158
dr_id,
161159
elapsed_secs
162160
);

node/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "witnet_node"
3-
version = "1.7.1"
3+
version = "2.0.0"
44
authors = ["Witnet Foundation <info@witnet.foundation>"]
55
workspace = ".."
66
description = "node component"

0 commit comments

Comments
 (0)