Skip to content

Commit

Permalink
change some safe as_u64 to low_u64 & cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Nov 24, 2023
1 parent a022710 commit 93a966b
Show file tree
Hide file tree
Showing 63 changed files with 727 additions and 762 deletions.
30 changes: 13 additions & 17 deletions common/apm-derive/src/rpc_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,29 @@ pub fn expand_rpc_metrics(attr: TokenStream, func: TokenStream) -> TokenStream {
let func_block = &func.block;
let func_output = &func_sig.output;
let func_return = PinBoxFutRet::parse(func_output);
let func_ret_ty =
match func_output {
ReturnType::Default => quote! { () },
ReturnType::Type(_, ty) => quote! { #ty },
};
let func_ret_ty = match func_output {
ReturnType::Default => quote! { () },
ReturnType::Type(_, ty) => quote! { #ty },
};
let ret_ty = func_return.return_type();
let args = func_sig
.inputs
.iter()
.filter_map(|arg| match arg {
syn::FnArg::Receiver(_) => None,
syn::FnArg::Typed(inner) => {
match &*inner.pat {
syn::Pat::Ident(pat) => Some(pat.ident.clone()),
_ => None,
}
}
syn::FnArg::Typed(inner) => match &*inner.pat {
syn::Pat::Ident(pat) => Some(pat.ident.clone()),
_ => None,
},
})
.collect::<Vec<_>>();

let fn_name = func_ident.to_string();
let mut debug =
if args.is_empty() {
"call rpc {}".to_string()
} else {
"call rpc {} with args,".to_string()
};
let mut debug = if args.is_empty() {
"call rpc {}".to_string()
} else {
"call rpc {} with args,".to_string()
};
for (index, name) in args.iter().enumerate() {
if index != 0 {
debug.push(',')
Expand Down
9 changes: 4 additions & 5 deletions common/apm-derive/src/trace_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ pub fn expand_trace_span(attr: TokenStream, func: TokenStream) -> TokenStream {
let func_block = &func.block;
let func_output = &func_sig.output;
let func_return = PinBoxFutRet::parse(func_output);
let func_ret_ty =
match func_output {
ReturnType::Default => quote! { () },
ReturnType::Type(_, ty) => quote! { #ty },
};
let func_ret_ty = match func_output {
ReturnType::Default => quote! { () },
ReturnType::Type(_, ty) => quote! { #ty },
};
let trace_info = TraceAttrs::new(&attr);
let trace_name = trace_info.trace_name(&func_sig.ident);
let span_tag_stmts = trace_info.span_tags();
Expand Down
28 changes: 13 additions & 15 deletions common/apm/src/metrics/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,19 @@ make_auto_flush_static_metric! {
}

lazy_static! {
pub static ref API_REQUEST_RESULT_COUNTER_VEC: CounterVec =
register_counter_vec!(
"axon_api_request_result_total",
"Total number of request result",
&["type", "result"]
)
.expect("request result total");
pub static ref API_REQUEST_TIME_HISTOGRAM_VEC: HistogramVec =
register_histogram_vec!(
"axon_api_request_time_cost_seconds",
"Request process time cost",
&["type"],
exponential_buckets(0.001, 2.0, 20).expect("api req time expontial")
)
.expect("request time cost");
pub static ref API_REQUEST_RESULT_COUNTER_VEC: CounterVec = register_counter_vec!(
"axon_api_request_result_total",
"Total number of request result",
&["type", "result"]
)
.expect("request result total");
pub static ref API_REQUEST_TIME_HISTOGRAM_VEC: HistogramVec = register_histogram_vec!(
"axon_api_request_time_cost_seconds",
"Request process time cost",
&["type"],
exponential_buckets(0.001, 2.0, 20).expect("api req time expontial")
)
.expect("request time cost");
}

lazy_static! {
Expand Down
11 changes: 5 additions & 6 deletions common/apm/src/metrics/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ lazy_static! {
register_int_gauge!("axon_consensus_height", "Height of axon").unwrap();
pub static ref ENGINE_EXECUTING_BLOCK_GAUGE: IntGauge =
register_int_gauge!("axon_executing_block_count", "The executing blocks").unwrap();
pub static ref ENGINE_COMMITTED_TX_COUNTER: IntCounter =
register_int_counter!(
"axon_consensus_committed_tx_total",
"The committed transactions"
)
.unwrap();
pub static ref ENGINE_COMMITTED_TX_COUNTER: IntCounter = register_int_counter!(
"axon_consensus_committed_tx_total",
"The committed transactions"
)
.unwrap();
pub static ref ENGINE_ORDER_TX_GAUGE: IntGauge =
register_int_gauge!("axon_proposal_order_tx_len", "The ordered transactions len").unwrap();
pub static ref ENGINE_SYNC_TX_GAUGE: IntGauge =
Expand Down
15 changes: 7 additions & 8 deletions common/apm/src/metrics/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ lazy_static! {
exponential_buckets(0.05, 2.0, 10).expect("mempool time expontial")
)
.expect("mempool time cost");
pub static ref MEMPOOL_PACKAGE_SIZE_VEC: HistogramVec =
register_histogram_vec!(
"axon_mempool_package_size_vec",
"Package size",
&["type"],
exponential_buckets(0.05, 2.0, 10).expect("mempool package size exponential")
)
.expect("mempool package size");
pub static ref MEMPOOL_PACKAGE_SIZE_VEC: HistogramVec = register_histogram_vec!(
"axon_mempool_package_size_vec",
"Package size",
&["type"],
exponential_buckets(0.05, 2.0, 10).expect("mempool package size exponential")
)
.expect("mempool package size");
pub static ref MEMPOOL_CURRENT_SIZE_VEC: HistogramVec = register_histogram_vec!(
"axon_mempool_current_size_vec",
"Current size",
Expand Down
11 changes: 5 additions & 6 deletions common/config-parser/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@ impl TypedValueParser for ConfigValueParser {
.parse_ref(cmd, arg, value)
.map(PathBuf::from)?;
let dir_path = file_path.parent().ok_or_else(|| {
let err =
{
let kind = io::ErrorKind::Other;
let msg = format!("no parent directory of {}", file_path.display());
io::Error::new(kind, msg)
};
let err = {
let kind = io::ErrorKind::Other;
let msg = format!("no parent directory of {}", file_path.display());
io::Error::new(kind, msg)
};
let kind = clap::error::ErrorKind::InvalidValue;
clap::Error::raw(kind, err)
})?;
Expand Down
9 changes: 4 additions & 5 deletions common/config-parser/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ where
.map(PathBuf::from)?;
parse_file(&file_path, true).map_err(|err| {
let kind = clap::error::ErrorKind::InvalidValue;
let msg =
format!(
"failed to parse JSON file {} since {err}",
file_path.display()
);
let msg = format!(
"failed to parse JSON file {} since {err}",
file_path.display()
);
clap::Error::raw(kind, msg)
})
}
Expand Down
9 changes: 4 additions & 5 deletions common/config-parser/src/types/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ impl TypedValueParser for ChainSpecValueParser {
.map(PathBuf::from)?;
parse_file(&file_path, false).map_err(|err| {
let kind = clap::error::ErrorKind::InvalidValue;
let msg =
format!(
"failed to parse chain spec file {} since {err}",
file_path.display()
);
let msg = format!(
"failed to parse chain spec file {} since {err}",
file_path.display()
);
clap::Error::raw(kind, msg)
})
}
Expand Down
21 changes: 10 additions & 11 deletions core/api/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,14 @@ where
.map(|p| U256::from(p.low_u64()))
.unwrap_or_else(U256::one);

let backend =
AxonExecutorReadOnlyAdapter::from_root(
state_root,
Arc::clone(&self.trie_db),
Arc::clone(&self.storage),
exec_ctx,
)?;
let backend = AxonExecutorReadOnlyAdapter::from_root(
state_root,
Arc::clone(&self.trie_db),
Arc::clone(&self.storage),
exec_ctx,
)?;
let gas_limit = gas_limit
.map(|gas| gas.as_u64())
.map(|gas| gas.low_u64())
.unwrap_or(MAX_BLOCK_GAS_LIMIT);

Ok(AxonExecutor.call(&backend, gas_limit, from, to, value, data))
Expand Down Expand Up @@ -280,9 +279,9 @@ where
.get(hash.as_bytes())?
.map(|v| H256::from_slice(&v))
.ok_or_else(|| {
Into::<ProtocolError>::into(
APIError::Adapter("Can't find this position".to_string())
)
Into::<ProtocolError>::into(APIError::Adapter(
"Can't find this position".to_string(),
))
})?,
proof: storage_mpt_tree
.get_proof(hash.as_bytes())?
Expand Down
51 changes: 25 additions & 26 deletions core/api/src/jsonrpc/impl/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<Adapter: APIAdapter + 'static> AxonRpcServer for AxonRpcImpl<Adapter> {
BlockId::Hash(hash) => self.adapter.get_block_by_hash(Context::new(), hash).await,
BlockId::Num(num) => {
self.adapter
.get_block_by_number(Context::new(), Some(num.as_u64()))
.get_block_by_number(Context::new(), Some(num.low_u64()))
.await
}
BlockId::Latest => self.adapter.get_block_by_number(Context::new(), None).await,
Expand All @@ -52,7 +52,7 @@ impl<Adapter: APIAdapter + 'static> AxonRpcServer for AxonRpcImpl<Adapter> {
async fn get_metadata_by_number(&self, block_number: U256) -> RpcResult<Metadata> {
let ret = self
.adapter
.get_metadata_by_number(Context::new(), Some(block_number.as_u64()))
.get_metadata_by_number(Context::new(), Some(block_number.low_u64()))
.await
.map_err(|e| RpcError::Internal(e.to_string()))?;

Expand Down Expand Up @@ -278,33 +278,32 @@ mod test {
});
assert_eq!(vd31, H256::zero());

let v4 =
vec![
HardforkInfoInner {
block_number: 0,
flags: {
let mut a = [0; 32];
a[0] = 0b10;
H256::from(a)
},
let v4 = vec![
HardforkInfoInner {
block_number: 0,
flags: {
let mut a = [0; 32];
a[0] = 0b10;
H256::from(a)
},
HardforkInfoInner {
block_number: 5,
flags: {
let mut a = [0; 32];
a[0] = 0b11;
H256::from(a)
},
},
HardforkInfoInner {
block_number: 5,
flags: {
let mut a = [0; 32];
a[0] = 0b11;
H256::from(a)
},
HardforkInfoInner {
block_number: 10,
flags: {
let mut a = [0; 32];
a[0] = 0b111;
H256::from(a)
},
},
HardforkInfoInner {
block_number: 10,
flags: {
let mut a = [0; 32];
a[0] = 0b111;
H256::from(a)
},
];
},
];

let (ve4, vd4) = enabled_and_determined(&v4, 0);

Expand Down
4 changes: 2 additions & 2 deletions core/api/src/jsonrpc/impl/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ where

match from {
BlockId::Num(n) => {
if n.as_u64() < header.number {
if n.low_u64() < header.number {
filter.from_block = Some(BlockId::Num(U64::from(header.number + 1)));
}
}
Expand Down Expand Up @@ -302,7 +302,7 @@ where
let (start, end) = {
let convert = |id: &BlockId| -> BlockNumber {
match id {
BlockId::Num(n) => n.as_u64(),
BlockId::Num(n) => n.low_u64(),
BlockId::Earliest => 0,
_ => latest_number,
}
Expand Down
Loading

0 comments on commit 93a966b

Please sign in to comment.