mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: clippy fixes and make benches compile again (#1449)
This commit is contained in:
@ -648,7 +648,7 @@ mod tests {
|
|||||||
let chain_spec = ChainSpecBuilder::mainnet().shanghai_activated().build();
|
let chain_spec = ChainSpecBuilder::mainnet().shanghai_activated().build();
|
||||||
|
|
||||||
let header = Header {
|
let header = Header {
|
||||||
base_fee_per_gas: Some(1337u64.into()),
|
base_fee_per_gas: Some(1337u64),
|
||||||
withdrawals_root: Some(proofs::calculate_withdrawals_root(&[])),
|
withdrawals_root: Some(proofs::calculate_withdrawals_root(&[])),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -182,10 +182,10 @@ mod tests {
|
|||||||
let mut buf = [0u8; 4];
|
let mut buf = [0u8; 4];
|
||||||
|
|
||||||
client.write_all(b"ping").await.unwrap();
|
client.write_all(b"ping").await.unwrap();
|
||||||
server.read(&mut buf).await.unwrap();
|
server.read_exact(&mut buf).await.unwrap();
|
||||||
|
|
||||||
server.write_all(b"pong").await.unwrap();
|
server.write_all(b"pong").await.unwrap();
|
||||||
client.read(&mut buf).await.unwrap();
|
client.read_exact(&mut buf).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_bandwidth_counts(
|
fn assert_bandwidth_counts(
|
||||||
@ -236,7 +236,7 @@ mod tests {
|
|||||||
|
|
||||||
let mut buf = [0u8; 4];
|
let mut buf = [0u8; 4];
|
||||||
|
|
||||||
metered_server_stream.read(&mut buf).await.unwrap();
|
metered_server_stream.read_exact(&mut buf).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(metered_server_stream.meter.total_inbound(), client_meter.total_outbound());
|
assert_eq!(metered_server_stream.meter.total_inbound(), client_meter.total_outbound());
|
||||||
});
|
});
|
||||||
|
|||||||
@ -906,16 +906,15 @@ mod tests {
|
|||||||
|
|
||||||
let unauthed_stream = UnauthedP2PStream::new(stream);
|
let unauthed_stream = UnauthedP2PStream::new(stream);
|
||||||
match unauthed_stream.handshake(server_hello.clone()).await {
|
match unauthed_stream.handshake(server_hello.clone()).await {
|
||||||
Ok((_, hello)) => panic!(
|
Ok((_, hello)) => {
|
||||||
"expected handshake to fail, instead got a successful Hello: {:?}",
|
panic!("expected handshake to fail, instead got a successful Hello: {hello:?}")
|
||||||
hello
|
}
|
||||||
),
|
|
||||||
Err(P2PStreamError::MismatchedProtocolVersion { expected, got }) => {
|
Err(P2PStreamError::MismatchedProtocolVersion { expected, got }) => {
|
||||||
assert_eq!(expected, server_hello.protocol_version as u8);
|
assert_eq!(expected, server_hello.protocol_version as u8);
|
||||||
assert_ne!(expected, got);
|
assert_ne!(expected, got);
|
||||||
}
|
}
|
||||||
Err(other_err) => {
|
Err(other_err) => {
|
||||||
panic!("expected mismatched protocol version error, got {:?}", other_err)
|
panic!("expected mismatched protocol version error, got {other_err:?}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -931,14 +930,14 @@ mod tests {
|
|||||||
let unauthed_stream = UnauthedP2PStream::new(sink);
|
let unauthed_stream = UnauthedP2PStream::new(sink);
|
||||||
match unauthed_stream.handshake(client_hello.clone()).await {
|
match unauthed_stream.handshake(client_hello.clone()).await {
|
||||||
Ok((_, hello)) => {
|
Ok((_, hello)) => {
|
||||||
panic!("expected handshake to fail, instead got a successful Hello: {:?}", hello)
|
panic!("expected handshake to fail, instead got a successful Hello: {hello:?}")
|
||||||
}
|
}
|
||||||
Err(P2PStreamError::MismatchedProtocolVersion { expected, got }) => {
|
Err(P2PStreamError::MismatchedProtocolVersion { expected, got }) => {
|
||||||
assert_eq!(expected, client_hello.protocol_version as u8);
|
assert_eq!(expected, client_hello.protocol_version as u8);
|
||||||
assert_ne!(expected, got);
|
assert_ne!(expected, got);
|
||||||
}
|
}
|
||||||
Err(other_err) => {
|
Err(other_err) => {
|
||||||
panic!("expected mismatched protocol version error, got {:?}", other_err)
|
panic!("expected mismatched protocol version error, got {other_err:?}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -501,7 +501,7 @@ mod test {
|
|||||||
/// Serde tests
|
/// Serde tests
|
||||||
#[test]
|
#[test]
|
||||||
fn serde_blockid_tags() {
|
fn serde_blockid_tags() {
|
||||||
let block_ids = [Latest, Finalized, Safe, Pending].map(|id| BlockId::from(id));
|
let block_ids = [Latest, Finalized, Safe, Pending].map(BlockId::from);
|
||||||
for block_id in &block_ids {
|
for block_id in &block_ids {
|
||||||
let serialized = serde_json::to_string(&block_id).unwrap();
|
let serialized = serde_json::to_string(&block_id).unwrap();
|
||||||
let deserialized: BlockId = serde_json::from_str(&serialized).unwrap();
|
let deserialized: BlockId = serde_json::from_str(&serialized).unwrap();
|
||||||
@ -539,7 +539,7 @@ mod test {
|
|||||||
let hash =
|
let hash =
|
||||||
H256::from_str("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
|
H256::from_str("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3")
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(BlockId::from(hash.clone()), block_id);
|
assert_eq!(BlockId::from(hash), block_id);
|
||||||
let serialized = serde_json::to_string(&BlockId::from(hash)).unwrap();
|
let serialized = serde_json::to_string(&BlockId::from(hash)).unwrap();
|
||||||
assert_eq!("{\"blockHash\":\"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3\"}", serialized)
|
assert_eq!("{\"blockHash\":\"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3\"}", serialized)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -561,8 +561,8 @@ mod tests {
|
|||||||
let b1 = 1_150_000;
|
let b1 = 1_150_000;
|
||||||
let b2 = 1_920_000;
|
let b2 = 1_920_000;
|
||||||
|
|
||||||
let h0 = ForkId { hash: ForkHash(hex!("fc64ec04")), next: b1.into() };
|
let h0 = ForkId { hash: ForkHash(hex!("fc64ec04")), next: b1 };
|
||||||
let h1 = ForkId { hash: ForkHash(hex!("97c2c34c")), next: b2.into() };
|
let h1 = ForkId { hash: ForkHash(hex!("97c2c34c")), next: b2 };
|
||||||
let h2 = ForkId { hash: ForkHash(hex!("91d1f948")), next: 0 };
|
let h2 = ForkId { hash: ForkHash(hex!("91d1f948")), next: 0 };
|
||||||
|
|
||||||
let mut fork_filter = ForkFilter::new(
|
let mut fork_filter = ForkFilter::new(
|
||||||
|
|||||||
@ -74,7 +74,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn success_init_genesis_mainnet() {
|
fn success_init_genesis_mainnet() {
|
||||||
let db = create_test_rw_db();
|
let db = create_test_rw_db();
|
||||||
let genesis_hash = init_genesis(db.clone(), MAINNET.clone()).unwrap();
|
let genesis_hash = init_genesis(db, MAINNET.clone()).unwrap();
|
||||||
|
|
||||||
// actual, expected
|
// actual, expected
|
||||||
assert_eq!(genesis_hash, MAINNET_GENESIS);
|
assert_eq!(genesis_hash, MAINNET_GENESIS);
|
||||||
@ -83,7 +83,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn success_init_genesis_goerli() {
|
fn success_init_genesis_goerli() {
|
||||||
let db = create_test_rw_db();
|
let db = create_test_rw_db();
|
||||||
let genesis_hash = init_genesis(db.clone(), GOERLI.clone()).unwrap();
|
let genesis_hash = init_genesis(db, GOERLI.clone()).unwrap();
|
||||||
|
|
||||||
// actual, expected
|
// actual, expected
|
||||||
assert_eq!(genesis_hash, GOERLI_GENESIS);
|
assert_eq!(genesis_hash, GOERLI_GENESIS);
|
||||||
@ -92,7 +92,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn success_init_genesis_sepolia() {
|
fn success_init_genesis_sepolia() {
|
||||||
let db = create_test_rw_db();
|
let db = create_test_rw_db();
|
||||||
let genesis_hash = init_genesis(db.clone(), SEPOLIA.clone()).unwrap();
|
let genesis_hash = init_genesis(db, SEPOLIA.clone()).unwrap();
|
||||||
|
|
||||||
// actual, expected
|
// actual, expected
|
||||||
assert_eq!(genesis_hash, SEPOLIA_GENESIS);
|
assert_eq!(genesis_hash, SEPOLIA_GENESIS);
|
||||||
|
|||||||
@ -40,8 +40,7 @@ fn senders(c: &mut Criterion) {
|
|||||||
|
|
||||||
for batch in [1000usize, 10_000, 100_000, 250_000] {
|
for batch in [1000usize, 10_000, 100_000, 250_000] {
|
||||||
let num_blocks = 10_000;
|
let num_blocks = 10_000;
|
||||||
let mut stage = SenderRecoveryStage::default();
|
let stage = SenderRecoveryStage { commit_threshold: num_blocks, ..Default::default() };
|
||||||
stage.commit_threshold = num_blocks;
|
|
||||||
let label = format!("SendersRecovery-batch-{batch}");
|
let label = format!("SendersRecovery-batch-{batch}");
|
||||||
measure_stage(&mut group, stage, num_blocks, label);
|
measure_stage(&mut group, stage, num_blocks, label);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ pub fn prepare_account_hashing(
|
|||||||
(path, AccountHashingStage::default(), stage_range)
|
(path, AccountHashingStage::default(), stage_range)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_stage_range(db: &PathBuf) -> (ExecInput, UnwindInput) {
|
fn find_stage_range(db: &Path) -> (ExecInput, UnwindInput) {
|
||||||
let mut stage_range = None;
|
let mut stage_range = None;
|
||||||
TestTransaction::new(db)
|
TestTransaction::new(db)
|
||||||
.tx
|
.tx
|
||||||
|
|||||||
@ -110,7 +110,7 @@ mod tests {
|
|||||||
fn current_status(&self) -> Head {
|
fn current_status(&self) -> Head {
|
||||||
let status_lock = self.status.try_lock().expect("competing for status lock");
|
let status_lock = self.status.try_lock().expect("competing for status lock");
|
||||||
let status = status_lock.as_ref().expect("no status receiver set").borrow();
|
let status = status_lock.as_ref().expect("no status receiver set").borrow();
|
||||||
status.clone()
|
*status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,10 @@ use criterion::{
|
|||||||
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
|
black_box, criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
|
||||||
};
|
};
|
||||||
use pprof::criterion::{Output, PProfProfiler};
|
use pprof::criterion::{Output, PProfProfiler};
|
||||||
use reth_db::cursor::{DbDupCursorRO, DbDupCursorRW};
|
use reth_db::{
|
||||||
|
cursor::{DbCursorRO, DbCursorRW, DbDupCursorRO, DbDupCursorRW},
|
||||||
|
tables::*,
|
||||||
|
};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
criterion_group! {
|
criterion_group! {
|
||||||
@ -64,11 +67,12 @@ where
|
|||||||
b.iter_with_setup(
|
b.iter_with_setup(
|
||||||
|| input.clone(),
|
|| input.clone(),
|
||||||
|input| {
|
|input| {
|
||||||
black_box({
|
{
|
||||||
for (k, _, _, _) in input {
|
for (k, _, _, _) in input {
|
||||||
k.encode();
|
k.encode();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
black_box(());
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -77,11 +81,12 @@ where
|
|||||||
b.iter_with_setup(
|
b.iter_with_setup(
|
||||||
|| input.clone(),
|
|| input.clone(),
|
||||||
|input| {
|
|input| {
|
||||||
black_box({
|
{
|
||||||
for (_, k, _, _) in input {
|
for (_, k, _, _) in input {
|
||||||
let _ = <T as Table>::Key::decode(k);
|
let _ = <T as Table>::Key::decode(k);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
black_box(());
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -90,11 +95,12 @@ where
|
|||||||
b.iter_with_setup(
|
b.iter_with_setup(
|
||||||
|| input.clone(),
|
|| input.clone(),
|
||||||
|input| {
|
|input| {
|
||||||
black_box({
|
{
|
||||||
for (_, _, v, _) in input {
|
for (_, _, v, _) in input {
|
||||||
v.compress();
|
v.compress();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
black_box(());
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -103,11 +109,12 @@ where
|
|||||||
b.iter_with_setup(
|
b.iter_with_setup(
|
||||||
|| input.clone(),
|
|| input.clone(),
|
||||||
|input| {
|
|input| {
|
||||||
black_box({
|
{
|
||||||
for (_, _, _, v) in input {
|
for (_, _, _, v) in input {
|
||||||
let _ = <T as Table>::Value::decompress(v);
|
let _ = <T as Table>::Value::decompress(v);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
black_box(());
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -177,13 +184,14 @@ where
|
|||||||
// Create TX
|
// Create TX
|
||||||
let tx = db.tx().expect("tx");
|
let tx = db.tx().expect("tx");
|
||||||
|
|
||||||
black_box({
|
{
|
||||||
let mut cursor = tx.cursor_read::<T>().expect("cursor");
|
let mut cursor = tx.cursor_read::<T>().expect("cursor");
|
||||||
let walker = cursor.walk(Some(input.first().unwrap().0.clone())).unwrap();
|
let walker = cursor.walk(Some(input.first().unwrap().0.clone())).unwrap();
|
||||||
for element in walker {
|
for element in walker {
|
||||||
element.unwrap();
|
element.unwrap();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
black_box(());
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -194,12 +202,13 @@ where
|
|||||||
// Create TX
|
// Create TX
|
||||||
let tx = db.tx().expect("tx");
|
let tx = db.tx().expect("tx");
|
||||||
|
|
||||||
black_box({
|
{
|
||||||
for index in RANDOM_INDEXES {
|
for index in RANDOM_INDEXES {
|
||||||
let mut cursor = tx.cursor_read::<T>().expect("cursor");
|
let mut cursor = tx.cursor_read::<T>().expect("cursor");
|
||||||
cursor.seek_exact(input.get(index).unwrap().0.clone()).unwrap();
|
cursor.seek_exact(input.get(index).unwrap().0.clone()).unwrap();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
black_box(());
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -267,13 +276,14 @@ where
|
|||||||
// Create TX
|
// Create TX
|
||||||
let tx = db.tx().expect("tx");
|
let tx = db.tx().expect("tx");
|
||||||
|
|
||||||
black_box({
|
{
|
||||||
let mut cursor = tx.cursor_dup_read::<T>().expect("cursor");
|
let mut cursor = tx.cursor_dup_read::<T>().expect("cursor");
|
||||||
let walker = cursor.walk_dup(None, Some(T::SubKey::default())).unwrap();
|
let walker = cursor.walk_dup(None, Some(T::SubKey::default())).unwrap();
|
||||||
for element in walker {
|
for element in walker {
|
||||||
element.unwrap();
|
element.unwrap();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
black_box(());
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -11,8 +11,9 @@ use proptest::{
|
|||||||
test_runner::TestRunner,
|
test_runner::TestRunner,
|
||||||
};
|
};
|
||||||
use reth_db::{
|
use reth_db::{
|
||||||
cursor::{DbDupCursorRO, DbDupCursorRW},
|
cursor::{DbCursorRW, DbDupCursorRO, DbDupCursorRW},
|
||||||
mdbx::Env,
|
mdbx::Env,
|
||||||
|
TxHashNumber,
|
||||||
};
|
};
|
||||||
use std::{collections::HashSet, time::Instant};
|
use std::{collections::HashSet, time::Instant};
|
||||||
use test_fuzz::runtime::num_traits::Zero;
|
use test_fuzz::runtime::num_traits::Zero;
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
use reth_db::{
|
use reth_db::{
|
||||||
cursor::{DbCursorRO, DbCursorRW},
|
|
||||||
database::Database,
|
database::Database,
|
||||||
mdbx::{test_utils::create_test_db_with_path, EnvKind, WriteMap},
|
mdbx::{test_utils::create_test_db_with_path, EnvKind, WriteMap},
|
||||||
table::*,
|
table::*,
|
||||||
tables::*,
|
|
||||||
transaction::{DbTx, DbTxMut},
|
transaction::{DbTx, DbTxMut},
|
||||||
};
|
};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
@ -44,6 +42,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets up a clear database at `bench_db_path`.
|
/// Sets up a clear database at `bench_db_path`.
|
||||||
|
#[allow(clippy::ptr_arg)]
|
||||||
fn set_up_db<T>(
|
fn set_up_db<T>(
|
||||||
bench_db_path: &Path,
|
bench_db_path: &Path,
|
||||||
pair: &Vec<(<T as Table>::Key, bytes::Bytes, <T as Table>::Value, bytes::Bytes)>,
|
pair: &Vec<(<T as Table>::Key, bytes::Bytes, <T as Table>::Value, bytes::Bytes)>,
|
||||||
|
|||||||
@ -210,7 +210,7 @@ mod tests {
|
|||||||
assert!(first.is_some(), "First should be our put");
|
assert!(first.is_some(), "First should be our put");
|
||||||
|
|
||||||
// Walk
|
// Walk
|
||||||
let walk = cursor.walk(Some(key.into())).unwrap();
|
let walk = cursor.walk(Some(key)).unwrap();
|
||||||
let first = walk.into_iter().next().unwrap().unwrap();
|
let first = walk.into_iter().next().unwrap().unwrap();
|
||||||
assert_eq!(first.1, value, "First next should be put value");
|
assert_eq!(first.1, value, "First next should be put value");
|
||||||
}
|
}
|
||||||
@ -636,18 +636,15 @@ mod tests {
|
|||||||
|
|
||||||
// PUT (0,0)
|
// PUT (0,0)
|
||||||
let value00 = StorageEntry::default();
|
let value00 = StorageEntry::default();
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key, value00.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key, value00).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// PUT (2,2)
|
// PUT (2,2)
|
||||||
let value22 = StorageEntry { key: H256::from_low_u64_be(2), value: U256::from(2) };
|
let value22 = StorageEntry { key: H256::from_low_u64_be(2), value: U256::from(2) };
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key, value22.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key, value22).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// PUT (1,1)
|
// PUT (1,1)
|
||||||
let value11 = StorageEntry { key: H256::from_low_u64_be(1), value: U256::from(1) };
|
let value11 = StorageEntry { key: H256::from_low_u64_be(1), value: U256::from(1) };
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key, value11.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key, value11).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Iterate with cursor
|
// Iterate with cursor
|
||||||
{
|
{
|
||||||
@ -656,7 +653,7 @@ mod tests {
|
|||||||
|
|
||||||
// Notice that value11 and value22 have been ordered in the DB.
|
// Notice that value11 and value22 have been ordered in the DB.
|
||||||
assert!(Some(value00) == cursor.next_dup_val().unwrap());
|
assert!(Some(value00) == cursor.next_dup_val().unwrap());
|
||||||
assert!(Some(value11.clone()) == cursor.next_dup_val().unwrap());
|
assert!(Some(value11) == cursor.next_dup_val().unwrap());
|
||||||
assert!(Some(value22) == cursor.next_dup_val().unwrap());
|
assert!(Some(value22) == cursor.next_dup_val().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,18 +682,15 @@ mod tests {
|
|||||||
|
|
||||||
// PUT key1 (0,0)
|
// PUT key1 (0,0)
|
||||||
let value00 = StorageEntry::default();
|
let value00 = StorageEntry::default();
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key1, value00.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key1, value00).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// PUT key1 (1,1)
|
// PUT key1 (1,1)
|
||||||
let value11 = StorageEntry { key: H256::from_low_u64_be(1), value: U256::from(1) };
|
let value11 = StorageEntry { key: H256::from_low_u64_be(1), value: U256::from(1) };
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key1, value11.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key1, value11).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// PUT key2 (2,2)
|
// PUT key2 (2,2)
|
||||||
let value22 = StorageEntry { key: H256::from_low_u64_be(2), value: U256::from(2) };
|
let value22 = StorageEntry { key: H256::from_low_u64_be(2), value: U256::from(2) };
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key2, value22.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key2, value22).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Iterate with walk_dup
|
// Iterate with walk_dup
|
||||||
{
|
{
|
||||||
@ -705,8 +699,8 @@ mod tests {
|
|||||||
let mut walker = cursor.walk_dup(None, None).unwrap();
|
let mut walker = cursor.walk_dup(None, None).unwrap();
|
||||||
|
|
||||||
// Notice that value11 and value22 have been ordered in the DB.
|
// Notice that value11 and value22 have been ordered in the DB.
|
||||||
assert_eq!(Some(Ok((key1, value00.clone()))), walker.next());
|
assert_eq!(Some(Ok((key1, value00))), walker.next());
|
||||||
assert_eq!(Some(Ok((key1, value11.clone()))), walker.next());
|
assert_eq!(Some(Ok((key1, value11))), walker.next());
|
||||||
// NOTE: Dup cursor does NOT iterates on all values but only on duplicated values of the
|
// NOTE: Dup cursor does NOT iterates on all values but only on duplicated values of the
|
||||||
// same key. assert_eq!(Ok(Some(value22.clone())), walker.next());
|
// same key. assert_eq!(Ok(Some(value22.clone())), walker.next());
|
||||||
assert_eq!(None, walker.next());
|
assert_eq!(None, walker.next());
|
||||||
@ -732,13 +726,11 @@ mod tests {
|
|||||||
|
|
||||||
// PUT key1 (0,1)
|
// PUT key1 (0,1)
|
||||||
let value01 = StorageEntry { key: H256::from_low_u64_be(0), value: U256::from(1) };
|
let value01 = StorageEntry { key: H256::from_low_u64_be(0), value: U256::from(1) };
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key1, value01.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key1, value01).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// PUT key1 (0,0)
|
// PUT key1 (0,0)
|
||||||
let value00 = StorageEntry::default();
|
let value00 = StorageEntry::default();
|
||||||
env.update(|tx| tx.put::<PlainStorageState>(key1, value00.clone()).expect(ERROR_PUT))
|
env.update(|tx| tx.put::<PlainStorageState>(key1, value00).expect(ERROR_PUT)).unwrap();
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Iterate with walk
|
// Iterate with walk
|
||||||
{
|
{
|
||||||
@ -748,7 +740,7 @@ mod tests {
|
|||||||
let mut walker = cursor.walk(Some(first.0)).unwrap();
|
let mut walker = cursor.walk(Some(first.0)).unwrap();
|
||||||
|
|
||||||
// NOTE: Both values are present
|
// NOTE: Both values are present
|
||||||
assert_eq!(Some(Ok((key1, value00.clone()))), walker.next());
|
assert_eq!(Some(Ok((key1, value00))), walker.next());
|
||||||
assert_eq!(Some(Ok((key1, value01))), walker.next());
|
assert_eq!(Some(Ok((key1, value01))), walker.next());
|
||||||
assert_eq!(None, walker.next());
|
assert_eq!(None, walker.next());
|
||||||
}
|
}
|
||||||
@ -759,7 +751,7 @@ mod tests {
|
|||||||
let mut cursor = tx.cursor_dup_read::<PlainStorageState>().unwrap();
|
let mut cursor = tx.cursor_dup_read::<PlainStorageState>().unwrap();
|
||||||
|
|
||||||
// NOTE: There are two values with same SubKey but only first one is shown
|
// NOTE: There are two values with same SubKey but only first one is shown
|
||||||
assert_eq!(Ok(Some(value00.clone())), cursor.seek_by_key_subkey(key1, value00.key));
|
assert_eq!(Ok(Some(value00)), cursor.seek_by_key_subkey(key1, value00.key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -118,7 +118,7 @@ mod test {
|
|||||||
bytes[..8].copy_from_slice(&num.to_be_bytes());
|
bytes[..8].copy_from_slice(&num.to_be_bytes());
|
||||||
bytes[8..].copy_from_slice(&hash.0);
|
bytes[8..].copy_from_slice(&hash.0);
|
||||||
|
|
||||||
let encoded = Encode::encode(key.clone());
|
let encoded = Encode::encode(key);
|
||||||
assert_eq!(encoded, bytes);
|
assert_eq!(encoded, bytes);
|
||||||
|
|
||||||
let decoded: TransitionIdAddress = Decode::decode(encoded.to_vec()).unwrap();
|
let decoded: TransitionIdAddress = Decode::decode(encoded.to_vec()).unwrap();
|
||||||
|
|||||||
@ -117,7 +117,7 @@ fn bench_put_rand_raw(c: &mut Criterion) {
|
|||||||
|
|
||||||
criterion_group! {
|
criterion_group! {
|
||||||
name = benches;
|
name = benches;
|
||||||
config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
|
config = Criterion::default().with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None)));
|
||||||
targets = bench_get_rand, bench_get_rand_raw, bench_put_rand, bench_put_rand_raw
|
targets = bench_get_rand, bench_get_rand_raw, bench_put_rand, bench_put_rand_raw
|
||||||
}
|
}
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
|
|||||||
@ -44,6 +44,7 @@ mod tests {
|
|||||||
|
|
||||||
fn assert_state_provider<T: StateProvider>() {}
|
fn assert_state_provider<T: StateProvider>() {}
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
|
#[allow(clippy::extra_unused_lifetimes)]
|
||||||
fn assert_chain_state_provider<'txn>() {
|
fn assert_chain_state_provider<'txn>() {
|
||||||
assert_state_provider::<ChainState<'txn>>();
|
assert_state_provider::<ChainState<'txn>>();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user