Skip to content

Commit

Permalink
[spellcheck] Part 2: Spell check directory core (#12786)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyan-gupta authored Jan 24, 2025
1 parent 618ef69 commit 5318b06
Show file tree
Hide file tree
Showing 68 changed files with 314 additions and 131 deletions.
8 changes: 4 additions & 4 deletions core/async-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn derive_multi_send_impl(input: proc_macro2::TokenStream) -> proc_macro2::Token
}
};

let mut impls = Vec::new();
let mut tokens = Vec::new();
for (i, field) in input.fields.into_iter().enumerate() {
let field_name = field.ident.as_ref().map(|ident| quote!(#ident)).unwrap_or_else(|| {
let index = syn::Index::from(i);
Expand All @@ -133,7 +133,7 @@ fn derive_multi_send_impl(input: proc_macro2::TokenStream) -> proc_macro2::Token
};
if last_segment.ident == "Sender" {
let message_type = arguments[0].clone();
impls.push(quote! {
tokens.push(quote! {
#(#cfg_attrs)*
impl near_async::messaging::CanSend<#message_type> for #struct_name {
fn send(&self, message: #message_type) {
Expand All @@ -146,7 +146,7 @@ fn derive_multi_send_impl(input: proc_macro2::TokenStream) -> proc_macro2::Token
let result_type = arguments[1].clone();
let outer_msg_type =
quote!(near_async::messaging::MessageWithCallback<#message_type, #result_type>);
impls.push(quote! {
tokens.push(quote! {
#(#cfg_attrs)*
impl near_async::messaging::CanSend<#outer_msg_type> for #struct_name {
fn send(&self, message: #outer_msg_type) {
Expand All @@ -158,7 +158,7 @@ fn derive_multi_send_impl(input: proc_macro2::TokenStream) -> proc_macro2::Token
}
}

quote! {#(#impls)*}
quote! {#(#tokens)*}
}

fn extract_cfg_attributes(attrs: &[syn::Attribute]) -> Vec<syn::Attribute> {
Expand Down
4 changes: 2 additions & 2 deletions core/async/src/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::fmt::{Debug, Display};
use std::sync::Arc;
use tokio::sync::oneshot;

/// Trait for an actor. An actor is a struct that can handle messages and implementes the Handler or
/// Trait for an actor. An actor is a struct that can handle messages and implements the Handler or
/// HandlerWithContext trait. We can optionally implement the start_actor trait which is executed in
/// the beginning of the actor's lifecycle.
/// This corresponds to the actix::Actor trait `started` function.
Expand Down Expand Up @@ -41,7 +41,7 @@ where
/// This is similar to the [`Handler`] trait, but it allows the handler to access the delayed action
/// runner that is used to schedule actions to be run in the future. For actix::Actor, the context
/// defined as actix::Context<Self> implements DelayedActionRunner<T>.
/// Note that the implementer for hander of a message only needs to implement either of Handler or
/// Note that the implementer for handler of a message only needs to implement either of Handler or
/// HandlerWithContext, not both.
pub trait HandlerWithContext<M: actix::Message>
where
Expand Down
2 changes: 1 addition & 1 deletion core/async/src/test_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
//! invoke timers without waiting for the actual duration. This makes tests run
//! much faster than asynchronous tests.
//!
//! - Versatilty:
//! - Versatility:
//! - A test can be constructed with any combination of components. The framework does
//! not dictate what components should exist, or how many instances there should be.
//! This allows for both small and focused tests, and large multi-instance tests.
Expand Down
2 changes: 1 addition & 1 deletion core/async/src/test_loop/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::PendingEventsSender;
use futures::FutureExt;

/// TestLoopSender implements the CanSend methods for an actor that can Handle them. This is
/// similar to our pattern of having an ActixWarpper around an actor to send messages to it.
/// similar to our pattern of having an ActixWrapper around an actor to send messages to it.
///
/// ```rust, ignore
/// let actor = TestActor::new();
Expand Down
3 changes: 3 additions & 0 deletions core/crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ impl Signature {
}
}
(Signature::SECP256K1(signature), PublicKey::SECP256K1(public_key)) => {
// cspell:ignore rsig pdata
let rec_id =
match secp256k1::ecdsa::RecoveryId::from_i32(i32::from(signature.0[64])) {
Ok(r) => r,
Expand Down Expand Up @@ -846,6 +847,7 @@ mod tests {

let sk = SecretKey::from_seed(KeyType::SECP256K1, "test");
let pk = sk.public_key();
// cspell:disable-next-line
let expected = "\"secp256k1:5ftgm7wYK5gtVqq1kxMGy7gSudkrfYCbpsjL6sH1nwx2oj5NR2JktohjzB6fbEhhRERQpiwJcpwnQjxtoX3GS3cQ\"";
assert_eq!(serde_json::to_string(&pk).unwrap(), expected);
assert_eq!(pk, serde_json::from_str(expected).unwrap());
Expand Down Expand Up @@ -886,6 +888,7 @@ mod tests {

#[test]
fn test_invalid_data() {
// cspell:disable-next-line
let invalid = "\"secp256k1:2xVqteU8PWhadHTv99TGh3bSf\"";
assert!(serde_json::from_str::<PublicKey>(invalid).is_err());
assert!(serde_json::from_str::<SecretKey>(invalid).is_err());
Expand Down
1 change: 1 addition & 0 deletions core/crypto/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub use curve25519_dalek::scalar::Scalar;

use near_account_id::AccountType;

// cspell:words vmul vartime multiscalar
pub fn vmul2(s1: Scalar, p1: &Point, s2: Scalar, p2: &Point) -> Point {
Point::vartime_multiscalar_mul(&[s1, s2], [p1, p2].iter().copied())
}
Expand Down
2 changes: 2 additions & 0 deletions core/crypto/src/vrf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl PublicKey {

// FIXME: no clear fix is available here -- the underlying library runs a non-trivial amount of
// unchecked arithmetic inside and provides no apparent way to do it in a checked manner.
// cspell:words vmul
#[allow(clippy::arithmetic_side_effects)]
fn is_valid(&self, input: &[u8], value: &Value, proof: &Proof) -> bool {
let p = unwrap_or_return_false!(unpack(&value.0));
Expand All @@ -44,6 +45,7 @@ impl PublicKey {
// FIXME: no clear fix is available here -- the underlying library runs a non-trivial amount of
// unchecked arithmetic inside and provides no apparent way to do it in a checked or wrapping
// manner.
// cspell:words basemul
#[allow(clippy::arithmetic_side_effects)]
fn basemul(s: Scalar) -> Point {
&s * &*GT
Expand Down
1 change: 1 addition & 0 deletions core/o11y/benches/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn inc_counter_vec_with_label_values_itoa(bench: &mut Bencher) {
});
}

// cspell:words smartstring
fn inc_counter_vec_with_label_values_smartstring(bench: &mut Bencher) {
use std::fmt::Write;
bench.iter(|| {
Expand Down
6 changes: 3 additions & 3 deletions core/o11y/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro_rules! io_trace {
/// Asserts that the condition is true, logging an error otherwise.
///
/// This macro complements `assert!` and `debug_assert`. All three macros should
/// only be used for conditions, whose violation signifise a programming error.
/// only be used for conditions, whose violation signifies a programming error.
/// All three macros are no-ops if the condition is true.
///
/// The behavior when the condition is false (i.e. when the assert fails) is
Expand All @@ -64,12 +64,12 @@ macro_rules! io_trace {
/// invariants, whose violation signals a bug in the code, where we'd rather
/// avoid shutting the whole node down.
///
/// For example, `log_assert` is a great choice to use in some auxilary code
/// For example, `log_assert` is a great choice to use in some auxiliary code
/// paths -- would be a shame if a bug in, eg, metrics collection code brought
/// the whole network down.
///
/// Another use case is adding new asserts to the old code -- if you are only
/// 99% sure that the assert is correct, and there's evidance that the old code
/// 99% sure that the assert is correct, and there's evidence that the old code
/// is working fine in practice, `log_assert!` is the right choice!
///
/// References:
Expand Down
2 changes: 1 addition & 1 deletion core/o11y/src/log_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{fs::File, io::Write};
/// Configures logging.
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
pub struct LogConfig {
/// Comma-separated list of EnvFitler directives.
/// Comma-separated list of EnvFilter directives.
pub rust_log: Option<String>,
/// Some("") enables global debug logging.
/// Some("module") enables debug logging for "module".
Expand Down
2 changes: 1 addition & 1 deletion core/o11y/src/testonly/tracing_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl TracingCapture {
///
/// The intended use-case is for testing multithreaded code: by *blocking*
/// in the `on_log` for specific log-lines, the test can maneuver the
/// threads into particularly interesting interleavings.
/// threads into particularly interesting interleaving.
pub fn set_callback(&mut self, on_log: impl Fn(&str) + Send + Sync + 'static) {
self.captured.lock().unwrap().on_log = Arc::new(on_log)
}
Expand Down
4 changes: 2 additions & 2 deletions core/parameters/src/config_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ mod tests {
let mut files = file_versions
.into_iter()
.map(|de| {
de.expect("direntry should read successfully")
de.expect("dir entry should read successfully")
.path()
.file_name()
.expect("direntry should have a filename")
.expect("dir entry should have a filename")
.to_string_lossy()
.into_owned()
})
Expand Down
2 changes: 1 addition & 1 deletion core/parameters/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub struct LimitConfig {
/// If present, stores max number of locals declared globally in one contract
#[serde(skip_serializing_if = "Option::is_none")]
pub max_locals_per_contract: Option<u64>,
/// Whether to enforce account_id well-formedness where it wasn't enforced
/// Whether to enforce account_id well-formed-ness where it wasn't enforced
/// historically.
#[serde(default = "AccountIdValidityRulesVersion::v0")]
pub account_id_validity_rules_version: AccountIdValidityRulesVersion,
Expand Down
4 changes: 2 additions & 2 deletions core/primitives-core/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl Account {
/// differentiate AccountVersion V1 from newer versions.
const SERIALIZATION_SENTINEL: u128 = u128::MAX;

// TODO(nonrefundable) Consider using consider some additional newtypes
// TODO(nonrefundable) Consider using consider some additional new types
// or a different way to write down constructor (e.g. builder pattern.)
pub fn new(
amount: Balance,
Expand Down Expand Up @@ -466,7 +466,7 @@ pub struct FunctionCallPermission {

// This isn't an AccountId because already existing records in testnet genesis have invalid
// values for this field (see: https://github.com/near/nearcore/pull/4621#issuecomment-892099860)
// we accomodate those by using a string, allowing us to read and parse genesis.
// we accommodate those by using a string, allowing us to read and parse genesis.
/// The access key only allows transactions with the given receiver's account id.
pub receiver_id: String,

Expand Down
10 changes: 5 additions & 5 deletions core/primitives-core/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl CryptoHash {
CryptoHash(sha2::Sha256::digest(bytes).into())
}

/// Calculates hash of borsh-serialised representation of an object.
/// Calculates hash of borsh-serialized representation of an object.
///
/// Note that using this function with an array may lead to unexpected
/// results. For example, `CryptoHash::hash_borsh(&[1u32, 2, 3])` hashes
Expand All @@ -48,10 +48,10 @@ impl CryptoHash {
CryptoHash(hasher.finalize().into())
}

/// Calculates hash of a borsh-serialised representation of list of objects.
/// Calculates hash of a borsh-serialized representation of list of objects.
///
/// This behaves as if it first collected all the items in the iterator into
/// a vector and then calculating hash of borsh-serialised representation of
/// a vector and then calculating hash of borsh-serialized representation of
/// that vector.
///
/// Panics if the iterator lies about its length.
Expand Down Expand Up @@ -82,7 +82,7 @@ impl CryptoHash {
/// visitor returns.
fn to_base58_impl<Out>(self, visitor: impl FnOnce(&str) -> Out) -> Out {
// base58-encoded string is at most 1.4 times longer than the binary
// sequence. We’re serialising 32 bytes so ⌈32 * 1.4⌉ = 45 should be
// sequence. We’re serializing 32 bytes so ⌈32 * 1.4⌉ = 45 should be
// enough.
let mut buffer = [0u8; 45];
let len = bs58::encode(self).into(&mut buffer[..]).unwrap();
Expand Down Expand Up @@ -324,7 +324,7 @@ mod tests {
}

#[test]
fn test_serde_deserialise_failures() {
fn test_serde_deserialize_failures() {
fn test(input: &str, want_err: &str) {
match serde_json::from_str::<CryptoHash>(input) {
Ok(got) => panic!("‘{input}’ should have failed; got ‘{got}’"),
Expand Down
28 changes: 14 additions & 14 deletions core/primitives-core/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ pub fn from_base64(encoded: &str) -> Result<Vec<u8>, base64::DecodeError> {
BASE64_STANDARD.decode(encoded)
}

/// Serialises number as a string; deserialises either as a string or number.
/// Serializes number as a string; deserializes either as a string or number.
///
/// This format works for `u64`, `u128`, `Option<u64>` and `Option<u128>` types.
/// When serialising, numbers are serialised as decimal strings. When
/// deserialising, strings are parsed as decimal numbers while numbers are
/// When serializing, numbers are serialized as decimal strings. When
/// deserializing, strings are parsed as decimal numbers while numbers are
/// interpreted as is.
pub mod dec_format {
use serde::de;
Expand All @@ -29,7 +29,7 @@ pub mod dec_format {
#[error("cannot parse from unit")]
pub struct ParseUnitError;

/// Abstraction between integers that we serialise.
/// Abstraction between integers that we serialize.
pub trait DecType: Sized {
/// Formats number as a decimal string; passes `None` as is.
fn serialize(&self) -> Option<String>;
Expand Down Expand Up @@ -138,7 +138,7 @@ fn test_u64_dec_format() {

assert_round_trip("{\"field\":\"42\"}", Test { field: 42 });
assert_round_trip("{\"field\":\"18446744073709551615\"}", Test { field: u64::MAX });
assert_deserialise("{\"field\":42}", Test { field: 42 });
assert_deserialize("{\"field\":42}", Test { field: 42 });
assert_de_error::<Test>("{\"field\":18446744073709551616}");
assert_de_error::<Test>("{\"field\":\"18446744073709551616\"}");
assert_de_error::<Test>("{\"field\":42.0}");
Expand All @@ -155,7 +155,7 @@ fn test_u128_dec_format() {
assert_round_trip("{\"field\":\"42\"}", Test { field: 42 });
assert_round_trip("{\"field\":\"18446744073709551615\"}", Test { field: u64::MAX as u128 });
assert_round_trip("{\"field\":\"18446744073709551616\"}", Test { field: 18446744073709551616 });
assert_deserialise("{\"field\":42}", Test { field: 42 });
assert_deserialize("{\"field\":42}", Test { field: 42 });
assert_de_error::<Test>("{\"field\":null}");
assert_de_error::<Test>("{\"field\":42.0}");
}
Expand All @@ -178,31 +178,31 @@ fn test_option_u128_dec_format() {
"{\"field\":\"18446744073709551616\"}",
Test { field: Some(18446744073709551616) },
);
assert_deserialise("{\"field\":42}", Test { field: Some(42) });
assert_deserialize("{\"field\":42}", Test { field: Some(42) });
assert_de_error::<Test>("{\"field\":42.0}");
}

#[cfg(test)]
#[track_caller]
fn assert_round_trip<'a, T>(serialised: &'a str, obj: T)
fn assert_round_trip<'a, T>(serialized: &'a str, obj: T)
where
T: serde::Deserialize<'a> + serde::Serialize + std::fmt::Debug + std::cmp::PartialEq,
{
assert_eq!(serialised, serde_json::to_string(&obj).unwrap());
assert_eq!(obj, serde_json::from_str(serialised).unwrap());
assert_eq!(serialized, serde_json::to_string(&obj).unwrap());
assert_eq!(obj, serde_json::from_str(serialized).unwrap());
}

#[cfg(test)]
#[track_caller]
fn assert_deserialise<'a, T>(serialised: &'a str, obj: T)
fn assert_deserialize<'a, T>(serialized: &'a str, obj: T)
where
T: serde::Deserialize<'a> + std::fmt::Debug + std::cmp::PartialEq,
{
assert_eq!(obj, serde_json::from_str(serialised).unwrap());
assert_eq!(obj, serde_json::from_str(serialized).unwrap());
}

#[cfg(test)]
#[track_caller]
fn assert_de_error<'a, T: serde::Deserialize<'a> + std::fmt::Debug>(serialised: &'a str) {
serde_json::from_str::<T>(serialised).unwrap_err();
fn assert_de_error<'a, T: serde::Deserialize<'a> + std::fmt::Debug>(serialized: &'a str) {
serde_json::from_str::<T>(serialized).unwrap_err();
}
4 changes: 2 additions & 2 deletions core/primitives-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub type ShardIndex = usize;
/// a number in the range 0..NUM_SHARDS. The shard ids do not need to be
/// sequential or contiguous.
///
/// The shard id is wrapped in a newtype to prevent the old pattern of using
/// The shard id is wrapped in a new type to prevent the old pattern of using
/// indices in range 0..NUM_SHARDS and casting to ShardId. Once the transition
/// if fully complete it potentially may be simplified to a regular type alias.
#[derive(
Expand Down Expand Up @@ -219,7 +219,7 @@ mod tests {

// Check that the ShardId is serialized the same as u64. This is to make
// sure that the transition from ShardId being a type alias to being a
// newtype is not a protocol upgrade.
// new type is not a protocol upgrade.
#[test]
fn test_shard_id_borsh() {
let shard_id_u64 = 42;
Expand Down
2 changes: 1 addition & 1 deletion core/primitives/src/action/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {

/// A serialized `Action::Delegate(SignedDelegateAction)` for testing.
///
/// We want this to be parseable and accepted by protocol versions with meta
/// We want this to be parsable and accepted by protocol versions with meta
/// transactions enabled. But it should fail either in parsing or in
/// validation when this is included in a receipt for a block of an earlier
/// version. For now, it just fails to parse, as a test below checks.
Expand Down
4 changes: 2 additions & 2 deletions core/primitives/src/action/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub enum GlobalContractDeployMode {
/// Users will be able reference it by that hash.
/// This effectively makes the contract immutable.
CodeHash,
/// Contract is deployed under the onwer account id.
/// Contract is deployed under the owner account id.
/// Users will be able reference it by that account id.
/// This allows the owner to update the contract for all its users.
AccountId,
Expand Down Expand Up @@ -316,7 +316,7 @@ pub enum Action {
const _: () = assert!(
// 1 word for tag plus the largest variant `DeployContractAction` which is a 3-word `Vec`.
// The `<=` check covers platforms that have pointers smaller than 8 bytes as well as random
// freak nightlies that somehow find a way to pack everything into one less word.
// freak night lies that somehow find a way to pack everything into one less word.
std::mem::size_of::<Action>() <= 32,
"Action <= 32 bytes for performance reasons, see #9451"
);
Expand Down
8 changes: 4 additions & 4 deletions core/primitives/src/bandwidth_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,11 @@ mod tests {

// When requesting bandwidth that is between two values on the list, the request
// should ask for the first value that is bigger than the needed bandwidth.
let inbetween_value = (values[values.len() / 2] + values[values.len() / 2 + 1]) / 2;
assert!(!values.contains(&inbetween_value));
let inbetween_size_receipt = [inbetween_value];
let in_between_value = (values[values.len() / 2] + values[values.len() / 2 + 1]) / 2;
assert!(!values.contains(&in_between_value));
let in_between_size_receipt = [in_between_value];
assert_eq!(
get_request(&inbetween_size_receipt),
get_request(&in_between_size_receipt),
Some(make_request_with_ones(&[values.len() / 2 + 1]))
);

Expand Down
Loading

0 comments on commit 5318b06

Please sign in to comment.