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

remove near-fmt dep from near-vm-runner #9266

Merged
merged 8 commits into from
Jul 11, 2023
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
4 changes: 3 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions core/o11y/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ publish = true

[dependencies]
near-crypto.workspace = true
near-fmt.workspace = true
near-primitives-core.workspace = true

actix.workspace = true
atty.workspace = true
base64.workspace = true
clap.workspace = true
once_cell.workspace = true
opentelemetry.workspace = true
Expand All @@ -37,10 +39,12 @@ smartstring.workspace = true

[features]
nightly_protocol = [
"near-fmt/nightly_protocol",
"near-primitives-core/nightly_protocol",
]
nightly = [
"nightly_protocol",
"near-fmt/nightly",
"near-primitives-core/nightly",
]
io_trace = []
Expand Down
11 changes: 10 additions & 1 deletion core/o11y/src/io_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! analysis. The estimator has a replay command that understands the output
//! produced by the IO trace.

use base64::Engine;
use std::collections::HashMap;
use std::io::Write;
use tracing::{span, Subscriber};
Expand Down Expand Up @@ -218,7 +219,15 @@ impl IoTraceLayer {
}
}
Some(IoEventType::StorageOp(storage_op)) => {
let key = visitor.key.as_deref().unwrap_or("?");
let key_bytes = visitor.key.map(|key| {
base64::engine::general_purpose::STANDARD
.decode(key)
.expect("key was not properly base64-encoded")
});
let key = key_bytes
.as_ref()
.map(|k| format!("{}", near_fmt::Bytes(&*k)))
.unwrap_or_else(|| String::from("?"));
let size = FormattedSize(visitor.size);
let tn_db_reads = visitor.tn_db_reads.unwrap();
let tn_mem_reads = visitor.tn_mem_reads.unwrap();
Expand Down
4 changes: 1 addition & 3 deletions runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ publish = true

[dependencies]
anyhow = { workspace = true, optional = true }
base64.workspace = true
bn.workspace = true
borsh.workspace = true
clap = { workspace = true, optional = true }
Expand All @@ -37,7 +38,6 @@ wasmtime = { workspace = true, optional = true }

near-account-id.workspace = true
near-crypto.workspace = true
near-fmt.workspace = true
near-primitives-core.workspace = true
near-rpc-error-macro.workspace = true

Expand Down Expand Up @@ -77,7 +77,6 @@ wat.workspace = true

[features]
nightly_protocol = [
"near-fmt/nightly_protocol",
"near-primitives-core/nightly_protocol",
]
# all vms enabled for now
Expand Down Expand Up @@ -122,7 +121,6 @@ protocol_feature_fix_contract_loading_cost = [
nightly = [
"nightly_protocol",
"protocol_feature_fix_contract_loading_cost",
"near-fmt/nightly",
"near-primitives-core/nightly",
]
sandbox = []
Expand Down
10 changes: 7 additions & 3 deletions runtime/near-vm-runner/src/logic/action.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use borsh::{BorshDeserialize, BorshSerialize};
use near_crypto::PublicKey;
use near_fmt::AbbrBytes;
use near_primitives_core::{
account::AccessKey,
serialize::dec_format,
Expand All @@ -10,6 +9,11 @@ use serde_with::base64::Base64;
use serde_with::serde_as;
use std::fmt;

fn base64(s: &[u8]) -> String {
use base64::Engine;
base64::engine::general_purpose::STANDARD.encode(s)
}

#[derive(
BorshSerialize,
BorshDeserialize,
Expand Down Expand Up @@ -83,7 +87,7 @@ pub struct DeployContractAction {
impl fmt::Debug for DeployContractAction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("DeployContractAction")
.field("code", &format_args!("{}", AbbrBytes(&self.code)))
.field("code", &format_args!("{}", base64(&self.code)))
.finish()
}
}
Expand All @@ -105,7 +109,7 @@ impl fmt::Debug for FunctionCallAction {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("FunctionCallAction")
.field("method_name", &format_args!("{}", &self.method_name))
.field("args", &format_args!("{}", AbbrBytes(&self.args)))
.field("args", &format_args!("{}", base64(&self.args)))
.field("gas", &format_args!("{}", &self.gas))
.field("deposit", &format_args!("{}", &self.deposit))
.finish()
Expand Down
14 changes: 10 additions & 4 deletions runtime/near-vm-runner/src/logic/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ use std::mem::size_of;

pub type Result<T, E = VMLogicError> = ::std::result::Result<T, E>;

#[cfg(feature = "io_trace")]
fn base64(s: &[u8]) -> String {
use base64::Engine;
base64::engine::general_purpose::STANDARD.encode(s)
}

pub struct VMLogic<'a> {
/// Provides access to the components outside the Wasm runtime for operations on the trie and
/// receipts creation.
Expand Down Expand Up @@ -2410,7 +2416,7 @@ impl<'a> VMLogic<'a> {
tracing::trace!(
target = "io_tracer",
storage_op = "write",
key = %near_fmt::Bytes(&key),
key = base64(&key),
size = value_len,
evicted_len = evicted.as_ref().map(Vec::len),
tn_mem_reads = nodes_delta.mem_reads,
Expand Down Expand Up @@ -2518,7 +2524,7 @@ impl<'a> VMLogic<'a> {
tracing::trace!(
target = "io_tracer",
storage_op = "read",
key = %near_fmt::Bytes(&key),
key = base64(&key),
jakmeier marked this conversation as resolved.
Show resolved Hide resolved
size = read.as_ref().map(Vec::len),
tn_db_reads = nodes_delta.db_reads,
tn_mem_reads = nodes_delta.mem_reads,
Expand Down Expand Up @@ -2592,7 +2598,7 @@ impl<'a> VMLogic<'a> {
tracing::trace!(
target = "io_tracer",
storage_op = "remove",
key = %near_fmt::Bytes(&key),
key = base64(&key),
evicted_len = removed.as_ref().map(Vec::len),
tn_mem_reads = nodes_delta.mem_reads,
tn_db_reads = nodes_delta.db_reads,
Expand Down Expand Up @@ -2665,7 +2671,7 @@ impl<'a> VMLogic<'a> {
tracing::trace!(
target = "io_tracer",
storage_op = "exists",
key = %near_fmt::Bytes(&key),
key = base64(&key),
tn_mem_reads = nodes_delta.mem_reads,
tn_db_reads = nodes_delta.db_reads,
);
Expand Down