diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a67acb98d7..beeafd21f8a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,7 +54,7 @@ jobs: - uses: actions/checkout@v4 # Install all the required tools - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just,cargo-nextest,cargo-llvm-cov @@ -107,7 +107,7 @@ jobs: with: python-version: 3.11 cache: pip - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: cargo-llvm-cov - run: pip3 install --user -r pytest/requirements.txt @@ -133,7 +133,7 @@ jobs: with: python-version: 3.11 cache: pip - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: cargo-llvm-cov - run: pip3 install --user -r pytest/requirements.txt @@ -163,7 +163,7 @@ jobs: with: python-version: 3.11 cache: pip - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: cargo-llvm-cov - run: pip3 install --user -r pytest/requirements.txt @@ -195,7 +195,7 @@ jobs: with: python-version: 3.11 cache: pip - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: cargo-llvm-cov - run: pip3 install --user -r pytest/requirements.txt @@ -217,7 +217,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just - uses: actions/setup-python@v4 @@ -236,7 +236,7 @@ jobs: with: python-version: 3.11 cache: pip - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: cargo-llvm-cov - run: pip3 install --user -r pytest/requirements.txt @@ -258,7 +258,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just - run: just check-rpc-errors-schema @@ -277,7 +277,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just - run: just check-cargo-fmt @@ -287,7 +287,7 @@ jobs: runs-on: ubuntu-22.04-8core steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just - run: just check-cargo-clippy @@ -297,7 +297,7 @@ jobs: runs-on: ubuntu-22.04-8core steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just - run: just doctests @@ -307,7 +307,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just,cargo-deny - run: just check-cargo-deny @@ -317,7 +317,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just - run: just check-themis @@ -327,7 +327,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just - run: just check-non-default @@ -337,7 +337,7 @@ jobs: runs-on: ubuntu-22.04-8core steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: just,cargo-udeps - run: just check-cargo-udeps @@ -347,7 +347,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: cargo-audit - run: cargo audit -D warnings @@ -373,7 +373,7 @@ jobs: with: name: coverage-profraw path: coverage/profraw - - uses: taiki-e/install-action@91af8c38814c3998cb755869e5cbeffd3ab0e462 + - uses: taiki-e/install-action@9b5b983efc779f85e5e5d11539f005e85ccb27ff with: tool: cargo-llvm-cov - uses: actions/setup-python@v4 diff --git a/Cargo.toml b/Cargo.toml index 73ed4457d5d..01f706b667b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ version = "0.0.0" # managed by cargo-workspaces, see below authors = ["Near Inc "] edition = "2021" -rust-version = "1.76.0" +rust-version = "1.77.0" repository = "https://github.com/near/nearcore" license = "MIT OR Apache-2.0" diff --git a/chain/chain/src/store.rs b/chain/chain/src/store.rs index f4ccab48a7f..a19600f35b5 100644 --- a/chain/chain/src/store.rs +++ b/chain/chain/src/store.rs @@ -2772,8 +2772,7 @@ mod tests { let mut chain = get_chain(Clock::real()); let genesis = chain.get_block_by_height(0).unwrap(); let signer = Arc::new(create_test_signer("test1")); - let short_fork = - vec![TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build()]; + let short_fork = [TestBlockBuilder::new(Clock::real(), &genesis, signer.clone()).build()]; let mut store_update = chain.mut_chain_store().store_update(); store_update.save_block_header(short_fork[0].header().clone()).unwrap(); store_update.commit().unwrap(); diff --git a/chain/chain/src/tests/garbage_collection.rs b/chain/chain/src/tests/garbage_collection.rs index de2ab720d21..1894731227c 100644 --- a/chain/chain/src/tests/garbage_collection.rs +++ b/chain/chain/src/tests/garbage_collection.rs @@ -601,7 +601,7 @@ fn test_fork_far_away_from_epoch_end() { let max_changes = 1; let fork_clean_step = 100; let epoch_length = fork_clean_step + 10; - let simple_chains = vec![ + let simple_chains = [ SimpleChain { from: 0, length: 5, is_removed: false }, SimpleChain { from: 5, length: 2, is_removed: true }, // We want the chain to end up exactly at the new epoch start. diff --git a/chain/client/src/adapter.rs b/chain/client/src/adapter.rs index fdc59b7c63f..16987651e08 100644 --- a/chain/client/src/adapter.rs +++ b/chain/client/src/adapter.rs @@ -3,30 +3,6 @@ use crate::view_client::ViewClientActor; use near_async::actix::AddrWithAutoSpanContextExt; use near_async::messaging::IntoSender; use near_network::client::ClientSenderForNetwork; -use near_network::types::{ - PartialEncodedChunkForwardMsg, PartialEncodedChunkRequestMsg, PartialEncodedChunkResponseMsg, -}; -use near_primitives::hash::CryptoHash; -use near_primitives::sharding::PartialEncodedChunk; - -#[derive(actix::Message, Debug)] -#[rtype(result = "()")] -pub(crate) struct RecvPartialEncodedChunkForward(pub PartialEncodedChunkForwardMsg); - -#[derive(actix::Message, Debug)] -#[rtype(result = "()")] -pub(crate) struct RecvPartialEncodedChunk(pub PartialEncodedChunk); - -#[derive(actix::Message, Debug)] -#[rtype(result = "()")] -pub(crate) struct RecvPartialEncodedChunkResponse( - pub PartialEncodedChunkResponseMsg, - pub std::time::Instant, -); - -#[derive(actix::Message, Debug)] -#[rtype(result = "()")] -pub(crate) struct RecvPartialEncodedChunkRequest(pub PartialEncodedChunkRequestMsg, pub CryptoHash); pub fn client_sender_for_network( client_addr: actix::Addr, diff --git a/chain/client/src/sync/external.rs b/chain/client/src/sync/external.rs index c03727e230e..af8c08ec510 100644 --- a/chain/client/src/sync/external.rs +++ b/chain/client/src/sync/external.rs @@ -151,7 +151,11 @@ impl ExternalConnection { if let Some(parent_dir) = path.parent() { std::fs::create_dir_all(parent_dir)?; } - let mut file = std::fs::OpenOptions::new().write(true).create(true).open(&path)?; + let mut file = std::fs::OpenOptions::new() + .write(true) + .create(true) + .truncate(true) + .open(&path)?; file.write_all(data)?; tracing::debug!(target: "state_sync_dump", shard_id, part_length = data.len(), ?location, ?file_type, "Wrote a state part to a file"); Ok(()) diff --git a/chain/epoch-manager/src/tests/mod.rs b/chain/epoch-manager/src/tests/mod.rs index 7beffe89ab6..c090c6af9d7 100644 --- a/chain/epoch-manager/src/tests/mod.rs +++ b/chain/epoch-manager/src/tests/mod.rs @@ -2296,7 +2296,7 @@ fn test_protocol_version_switch_with_shard_layout_change() { } epoch_manager.record_block_info(block_info, [0; 32]).unwrap(); } - let epochs = vec![EpochId::default(), EpochId(h[2]), EpochId(h[4])]; + let epochs = [EpochId::default(), EpochId(h[2]), EpochId(h[4])]; assert_eq!( epoch_manager.get_epoch_info(&epochs[1]).unwrap().protocol_version(), new_protocol_version - 1 diff --git a/chain/network/src/network_protocol/tests.rs b/chain/network/src/network_protocol/tests.rs index 81e54691787..2d339b1b2cc 100644 --- a/chain/network/src/network_protocol/tests.rs +++ b/chain/network/src/network_protocol/tests.rs @@ -24,7 +24,7 @@ fn deduplicate_edges() { let bc1 = data::make_edge(&b, &c, 1); let mut want = vec![ab5.clone(), ac9.clone(), bc1.clone()]; want.sort_by_key(|e| e.key().clone()); - let input = vec![ab1, ab3, ab5, ac7, ac9, bc1]; + let input = [ab1, ab3, ab5, ac7, ac9, bc1]; for p in input.iter().permutations(input.len()) { let mut got = Edge::deduplicate(p.into_iter().cloned().collect()); got.sort_by_key(|e| e.key().clone()); diff --git a/chain/network/src/peer/peer_actor.rs b/chain/network/src/peer/peer_actor.rs index dcc99931635..a96b785aeda 100644 --- a/chain/network/src/peer/peer_actor.rs +++ b/chain/network/src/peer/peer_actor.rs @@ -1795,6 +1795,7 @@ impl actix::Handler> for PeerActor { type InboundHandshakePermit = tokio::sync::OwnedSemaphorePermit; #[derive(Debug)] +#[allow(dead_code)] enum ConnectingStatus { Inbound(InboundHandshakePermit), Outbound { _permit: connection::OutboundHandshakePermit, handshake_spec: HandshakeSpec }, @@ -1813,6 +1814,7 @@ enum ConnectingStatus { /// For the exact process of establishing a connection between peers, /// see PoolSnapshot in chain/network/src/peer_manager/connection.rs. #[derive(Debug)] +#[allow(dead_code)] enum PeerStatus { /// Handshake in progress. Connecting(HandshakeSignalSender, ConnectingStatus), diff --git a/core/crypto/src/key_file.rs b/core/crypto/src/key_file.rs index c3c7795ed14..e56f80f3d81 100644 --- a/core/crypto/src/key_file.rs +++ b/core/crypto/src/key_file.rs @@ -26,7 +26,7 @@ impl KeyFile { #[cfg(unix)] fn create(path: &Path) -> io::Result { use std::os::unix::fs::OpenOptionsExt; - std::fs::File::options().mode(0o600).write(true).create(true).open(path) + std::fs::File::options().mode(0o600).write(true).create(true).truncate(true).open(path) } #[cfg(not(unix))] diff --git a/core/store/src/db/refcount.rs b/core/store/src/db/refcount.rs index 80278847ae4..c7844220003 100644 --- a/core/store/src/db/refcount.rs +++ b/core/store/src/db/refcount.rs @@ -35,16 +35,19 @@ use crate::DBCol; /// In builds with debug assertions enabled, panics if `bytes` are non-empty but /// too short to fit 64-bit reference count. pub fn decode_value_with_rc(bytes: &[u8]) -> (Option<&[u8]>, i64) { - if bytes.len() < 8 { - debug_assert!(bytes.is_empty()); - return (None, 0); - } - let (head, tail) = stdx::rsplit_slice::<8>(bytes); - let rc = i64::from_le_bytes(*tail); - if rc <= 0 { - (None, rc) - } else { - (Some(head), rc) + match bytes.split_last_chunk::<8>() { + None => { + debug_assert!(bytes.is_empty()); + return (None, 0); + } + Some((head, tail)) => { + let rc = i64::from_le_bytes(*tail); + if rc <= 0 { + (None, rc) + } else { + (Some(head), rc) + } + } } } diff --git a/core/store/src/trie/mod.rs b/core/store/src/trie/mod.rs index 41bcebb4c6e..f8be9140c09 100644 --- a/core/store/src/trie/mod.rs +++ b/core/store/src/trie/mod.rs @@ -563,7 +563,7 @@ pub struct ApplyStatePartResult { } enum NodeOrValue { - Node(Box), + Node, Value(std::sync::Arc<[u8]>), } @@ -812,7 +812,7 @@ impl Trie { to: &Option<&AccountId>, ) { match self.debug_retrieve_raw_node_or_value(hash) { - Ok(NodeOrValue::Node(_)) => { + Ok(NodeOrValue::Node) => { let mut prefix: Vec = Vec::new(); let mut limit = limit.unwrap_or(u32::MAX); self.print_recursive_internal( @@ -1115,7 +1115,7 @@ impl Trie { ) -> Result { let bytes = self.internal_retrieve_trie_node(hash, true)?; match RawTrieNodeWithSize::try_from_slice(&bytes) { - Ok(node) => Ok(NodeOrValue::Node(Box::new(node))), + Ok(_) => Ok(NodeOrValue::Node), Err(_) => Ok(NodeOrValue::Value(bytes)), } } diff --git a/runtime/near-vm-runner/src/instrument/stack_height/mod.rs b/runtime/near-vm-runner/src/instrument/stack_height/mod.rs index a0da4859330..d6856d98f98 100644 --- a/runtime/near-vm-runner/src/instrument/stack_height/mod.rs +++ b/runtime/near-vm-runner/src/instrument/stack_height/mod.rs @@ -90,6 +90,7 @@ mod thunk; /// /// This means that the module is invalid. #[derive(Debug)] +#[allow(dead_code)] pub struct Error(String); pub(crate) struct Context { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 5e2dfe6908b..f84ea34e80d 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,6 +2,6 @@ # This specifies the version of Rust we use to build. # Individual crates in the workspace may support a lower version, as indicated by `rust-version` field in each crate's `Cargo.toml`. # The version specified below, should be at least as high as the maximum `rust-version` within the workspace. -channel = "1.76.0" +channel = "1.77.0" components = [ "rustfmt", "clippy" ] targets = [ "wasm32-unknown-unknown" ] diff --git a/utils/stdx/src/lib.rs b/utils/stdx/src/lib.rs index a31eb9a7581..ecf027e1f13 100644 --- a/utils/stdx/src/lib.rs +++ b/utils/stdx/src/lib.rs @@ -27,45 +27,10 @@ pub fn split_array_mut( (left.try_into().unwrap(), right.try_into().unwrap()) } -/// Splits `&[u8]` into `(&[u8; N], &[u8])`. **Panics** if slice is shorter -/// than `N`. -pub fn split_slice(slice: &[u8]) -> (&[u8; N], &[u8]) { - let (head, tail) = slice.split_at(N); - (head.try_into().unwrap(), tail) -} - -/// Splits `&[u8]` into `(&[u8], &[u8; N])`. **Panics** if slice is shorter -/// than `N`. -pub fn rsplit_slice(slice: &[u8]) -> (&[u8], &[u8; N]) { - let index = slice.len().checked_sub(N).expect("len to be ≥ N"); - let (head, tail) = slice.split_at(index); - (head, tail.try_into().unwrap()) -} - -/// Splits `&[u8]` into `(&[u8; N], &[u8])`. **Panics** if slice is shorter -/// than `N`. -pub fn split_slice_mut(slice: &mut [u8]) -> (&mut [u8; N], &mut [u8]) { - let (head, tail) = slice.split_at_mut(N); - (head.try_into().unwrap(), tail) -} - -/// Splits `&[u8]` into `(&[u8], &[u8; N])`. **Panics** if slice is shorter -/// than `N`. -pub fn rsplit_slice_mut(slice: &mut [u8]) -> (&mut [u8], &mut [u8; N]) { - let index = slice.len().checked_sub(N).expect("len to be ≥ N"); - let (head, tail) = slice.split_at_mut(index); - (head, tail.try_into().unwrap()) -} - #[test] fn test_split() { assert_eq!((&[0, 1], &[2, 3, 4]), split_array(&[0, 1, 2, 3, 4])); assert_eq!((&mut [0, 1], &mut [2, 3, 4]), split_array_mut(&mut [0, 1, 2, 3, 4])); - - assert_eq!((&[0, 1], &[2, 3, 4][..]), split_slice(&[0, 1, 2, 3, 4])); - assert_eq!((&[0, 1][..], &[2, 3, 4]), rsplit_slice(&[0, 1, 2, 3, 4])); - assert_eq!((&mut [0, 1], &mut [2, 3, 4][..]), split_slice_mut(&mut [0, 1, 2, 3, 4])); - assert_eq!((&mut [0, 1][..], &mut [2, 3, 4]), rsplit_slice_mut(&mut [0, 1, 2, 3, 4])); } /// Joins `[u8; L]` and `[u8; R]` into `[u8; L + R]`.