Avoid Printing Binary String to Logs (#1576)
Converts the graffiti binary data to string before printing to logs. ## Issue Addressed #1566 ## Proposed Changes Rather than converting graffiti to a vector the binary data less the last character is passed to String::from_utf_lossy(). This then allows us to call the to_string() function directly to give us the string ## Additional Info Rust skills are fairly weak
This commit is contained in:
parent
2627463366
commit
638daa87fe
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -348,6 +348,7 @@ dependencies = [
|
|||||||
"rand 0.7.3",
|
"rand 0.7.3",
|
||||||
"rand_core 0.5.1",
|
"rand_core 0.5.1",
|
||||||
"rayon",
|
"rayon",
|
||||||
|
"regex",
|
||||||
"safe_arith",
|
"safe_arith",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
|
@ -58,3 +58,4 @@ environment = { path = "../../lighthouse/environment" }
|
|||||||
bus = "2.2.3"
|
bus = "2.2.3"
|
||||||
derivative = "2.1.1"
|
derivative = "2.1.1"
|
||||||
itertools = "0.9.0"
|
itertools = "0.9.0"
|
||||||
|
regex = "1.3.9"
|
||||||
|
@ -31,6 +31,7 @@ use fork_choice::ForkChoice;
|
|||||||
use itertools::process_results;
|
use itertools::process_results;
|
||||||
use operation_pool::{OperationPool, PersistedOperationPool};
|
use operation_pool::{OperationPool, PersistedOperationPool};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
use regex::bytes::Regex;
|
||||||
use slog::{crit, debug, error, info, trace, warn, Logger};
|
use slog::{crit, debug, error, info, trace, warn, Logger};
|
||||||
use slot_clock::SlotClock;
|
use slot_clock::SlotClock;
|
||||||
use state_processing::{
|
use state_processing::{
|
||||||
@ -1319,8 +1320,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
block: SignedBeaconBlock<T::EthSpec>,
|
block: SignedBeaconBlock<T::EthSpec>,
|
||||||
) -> Result<GossipVerifiedBlock<T>, BlockError<T::EthSpec>> {
|
) -> Result<GossipVerifiedBlock<T>, BlockError<T::EthSpec>> {
|
||||||
let slot = block.message.slot;
|
let slot = block.message.slot;
|
||||||
let graffiti_string = String::from_utf8(block.message.body.graffiti[..].to_vec())
|
#[allow(clippy::invalid_regex)]
|
||||||
.unwrap_or_else(|_| format!("{:?}", &block.message.body.graffiti[..]));
|
let re = Regex::new("\\p{C}").expect("regex is valid");
|
||||||
|
let graffiti_string =
|
||||||
|
String::from_utf8_lossy(&re.replace_all(&block.message.body.graffiti[..], &b""[..]))
|
||||||
|
.to_string();
|
||||||
|
|
||||||
match GossipVerifiedBlock::new(block, self) {
|
match GossipVerifiedBlock::new(block, self) {
|
||||||
Ok(verified) => {
|
Ok(verified) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user