Skip to content

Commit

Permalink
Merge branch 'master' into forknet-logs
Browse files Browse the repository at this point in the history
  • Loading branch information
tayfunelmas committed May 22, 2024
2 parents 0d25b7d + 8fd58cb commit beba4f1
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 43 deletions.
20 changes: 1 addition & 19 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ ed25519-dalek = { version = "2.1.0", default-features = false, features = [
"hazmat",
"rand_core",
] }
elastic-array = "0.11"
enum-map = "2.1.0"
enumset = "1.0"
ethabi = "18"
Expand Down
2 changes: 1 addition & 1 deletion core/store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ borsh.workspace = true
bytesize.workspace = true
crossbeam.workspace = true
derive_more.workspace = true
elastic-array.workspace = true
smallvec.workspace = true
enum-map.workspace = true
hex.workspace = true
itoa.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions core/store/src/trie/mem/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use super::freelist::{ReusableVecU8, VecU8Freelist};
use super::node::MemTrieNodeId;
use crate::trie::mem::node::InputMemTrieNode;
use crate::NibbleSlice;
use elastic_array::ElasticArray4;
use near_primitives::state::FlatStateValue;
use smallvec::SmallVec;

/// Algorithm to construct a trie from a given stream of sorted leaf values.
///
Expand Down Expand Up @@ -85,7 +85,7 @@ struct TrieConstructionSegment {
value: Option<FlatStateValue>,
// Only used if is_branch is true. The children that are already
// constructed. The last child currently being constructed is not in here.
children: ElasticArray4<(u8, MemTrieNodeId)>,
children: SmallVec<[(u8, MemTrieNodeId); 4]>,
// Only used for extension nodes; the child that is already constructed.
child: Option<MemTrieNodeId>,
}
Expand Down
5 changes: 3 additions & 2 deletions core/store/src/trie/mem/node/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use crate::trie::mem::flexible_data::value::EncodedValueHeader;
use crate::trie::mem::flexible_data::FlexibleDataHeader;
use crate::trie::TRIE_COSTS;
use borsh::{BorshDeserialize, BorshSerialize};
use elastic_array::ElasticArray16;
use near_primitives::hash::CryptoHash;
use near_primitives::state::FlatStateValue;

use smallvec::SmallVec;

#[derive(PartialEq, Eq, Clone, Copy, Debug, BorshSerialize, BorshDeserialize)]
pub(crate) enum NodeKind {
Leaf,
Expand Down Expand Up @@ -256,7 +257,7 @@ impl MemTrieNodeId {
header.refcount = new_refcount;
decoder.overwrite(header);
if new_refcount == 0 {
let mut children_to_unref = ElasticArray16::new();
let mut children_to_unref: SmallVec<[ArenaPos; 16]> = SmallVec::new();
let node_ptr = self.as_ptr(arena.memory());
for child in node_ptr.view().iter_children() {
children_to_unref.push(child.id().pos);
Expand Down
2 changes: 1 addition & 1 deletion core/store/src/trie/mem/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl MemTrieNodeId {
}

/// This is for internal use only, so that we can put `MemTrieNodeId` in an
/// ElasticArray.
/// SmallVec.
impl Default for MemTrieNodeId {
fn default() -> Self {
Self { pos: ArenaPos::invalid() }
Expand Down
32 changes: 16 additions & 16 deletions core/store/src/trie/nibble_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

//! Nibble-orientated view onto byte-slice, allowing nibble-precision offsets.

use elastic_array::ElasticArray36;
use smallvec::SmallVec;
use std::cmp::*;
use std::fmt;

Expand Down Expand Up @@ -129,9 +129,9 @@ impl<'a> NibbleSlice<'a> {

/// Encode while nibble slice in prefixed hex notation, noting whether it `is_leaf`.
#[inline]
pub fn encode_nibbles(nibbles: &[u8], is_leaf: bool) -> ElasticArray36<u8> {
pub fn encode_nibbles(nibbles: &[u8], is_leaf: bool) -> SmallVec<[u8; 36]> {
let l = nibbles.len();
let mut r = ElasticArray36::new();
let mut r: SmallVec<[u8; 36]> = SmallVec::new();
let mut i = l % 2;
r.push(if i == 1 { 0x10 + nibbles[0] } else { 0 } + if is_leaf { 0x20 } else { 0 });
while i < l {
Expand All @@ -143,8 +143,8 @@ impl<'a> NibbleSlice<'a> {

/// Encode while nibble slice in prefixed hex notation, noting whether it `is_leaf`.
#[inline]
pub fn encoded(&self, is_leaf: bool) -> ElasticArray36<u8> {
let mut to = ElasticArray36::new();
pub fn encoded(&self, is_leaf: bool) -> SmallVec<[u8; 36]> {
let mut to: SmallVec<[u8; 36]> = SmallVec::new();
let l = self.len();
let parity = l % 2;
let mut first_byte: u8 = 0;
Expand All @@ -156,7 +156,7 @@ impl<'a> NibbleSlice<'a> {
}
to.push(first_byte);
let from_byte = (self.offset + parity) / 2;
to.append_slice(&self.data[from_byte..]);
to.extend_from_slice(&self.data[from_byte..]);
to
}

Expand All @@ -178,9 +178,9 @@ impl<'a> NibbleSlice<'a> {
to.extend_from_slice(&self.data[from_byte..]);
}

pub fn merge_encoded(&self, other: &Self, is_leaf: bool) -> ElasticArray36<u8> {
pub fn merge_encoded(&self, other: &Self, is_leaf: bool) -> SmallVec<[u8; 36]> {
let l = self.len() + other.len();
let mut r = ElasticArray36::new();
let mut r: SmallVec<[u8; 36]> = SmallVec::new();
let mut i = l % 2;
r.push(if i == 1 { 0x10 + self.at(0) } else { 0 } + if is_leaf { 0x20 } else { 0 });
while i < l {
Expand All @@ -203,9 +203,9 @@ impl<'a> NibbleSlice<'a> {

/// Encode only the leftmost `n` bytes of the nibble slice in prefixed hex notation,
/// noting whether it `is_leaf`.
pub fn encoded_leftmost(&self, n: usize, is_leaf: bool) -> ElasticArray36<u8> {
pub fn encoded_leftmost(&self, n: usize, is_leaf: bool) -> SmallVec<[u8; 36]> {
let l = min(self.len(), n);
let mut r = ElasticArray36::new();
let mut r: SmallVec<[u8; 36]> = SmallVec::new();
let mut i = l % 2;
r.push(if i == 1 { 0x10 + self.at(0) } else { 0 } + if is_leaf { 0x20 } else { 0 });
while i < l {
Expand All @@ -230,7 +230,7 @@ impl<'a> NibbleSlice<'a> {
// Helper to convert nibbles to bytes.
pub fn nibbles_to_bytes(nibbles: &[u8]) -> Vec<u8> {
assert_eq!(nibbles.len() % 2, 0);
let encoded = NibbleSlice::encode_nibbles(&nibbles, false);
let encoded: SmallVec<[u8; 36]> = NibbleSlice::encode_nibbles(&nibbles, false);
// Ignore first element returned by `encode_nibbles` because it contains only
// `is_leaf` info for even length.
encoded[1..].to_vec()
Expand Down Expand Up @@ -279,8 +279,8 @@ impl fmt::Debug for NibbleSlice<'_> {
#[cfg(test)]
mod tests {
use super::NibbleSlice;
use elastic_array::ElasticArray36;
use rand::{thread_rng, Rng};
use smallvec::SmallVec;

static D: &[u8; 3] = &[0x01u8, 0x23, 0x45];

Expand Down Expand Up @@ -324,15 +324,15 @@ mod tests {
#[test]
fn encoded() {
let n = NibbleSlice::new(D);
assert_eq!(n.encoded(false), ElasticArray36::from_slice(&[0x00, 0x01, 0x23, 0x45]));
assert_eq!(n.encoded(true), ElasticArray36::from_slice(&[0x20, 0x01, 0x23, 0x45]));
assert_eq!(n.encoded(false), SmallVec::<[u8; 36]>::from_slice(&[0x00, 0x01, 0x23, 0x45]));
assert_eq!(n.encoded(true), SmallVec::<[u8; 36]>::from_slice(&[0x20, 0x01, 0x23, 0x45]));
let mut v = vec![];
n.encode_to(false, &mut v);
assert_eq!(v, vec![0x00, 0x01, 0x23, 0x45]);
n.encode_to(true, &mut v);
assert_eq!(v, vec![0x20, 0x01, 0x23, 0x45]);
assert_eq!(n.mid(1).encoded(false), ElasticArray36::from_slice(&[0x11, 0x23, 0x45]));
assert_eq!(n.mid(1).encoded(true), ElasticArray36::from_slice(&[0x31, 0x23, 0x45]));
assert_eq!(n.mid(1).encoded(false), SmallVec::<[u8; 36]>::from_slice(&[0x11, 0x23, 0x45]));
assert_eq!(n.mid(1).encoded(true), SmallVec::<[u8; 36]>::from_slice(&[0x31, 0x23, 0x45]));
}

#[test]
Expand Down
6 changes: 5 additions & 1 deletion pytest/tests/mocknet/helpers/neard_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,12 @@ def start_neard(self, batch_interval_millis=None):
self.source_near_home_path(),
'--target-home',
self.target_near_home_path(),
'--no-secret',
]
if os.path.exists(self.setup_path('mirror-secret.json')):
cmd.append('--secret-file')
cmd.append(self.setup_path('mirror-secret.json'))
else:
cmd.append('--no-secret')
if batch_interval_millis is not None:
with open(self.target_near_home_path('mirror-config.json'),
'w') as f:
Expand Down

0 comments on commit beba4f1

Please sign in to comment.