move RPC scanning cache to borsh

This commit is contained in:
Boog900 2023-12-18 14:36:22 +00:00
parent e264a40feb
commit 84343a8297
No known key found for this signature in database
GPG key ID: 5401367FB7302004
4 changed files with 8 additions and 33 deletions

27
Cargo.lock generated
View file

@ -157,25 +157,6 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
[[package]]
name = "bincode"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f11ea1a0346b94ef188834a65c068a03aec181c94896d481d7a0a40d85b0ce95"
dependencies = [
"bincode_derive",
"serde",
]
[[package]]
name = "bincode_derive"
version = "2.0.0-rc.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e30759b3b99a1b802a7a3aa21c85c3ded5c28e1c83170d82d70f08bbf7f3e4c"
dependencies = [
"virtue",
]
[[package]] [[package]]
name = "bit-set" name = "bit-set"
version = "0.5.3" version = "0.5.3"
@ -472,7 +453,7 @@ dependencies = [
name = "cuprate-consensus" name = "cuprate-consensus"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"bincode", "borsh",
"clap", "clap",
"crypto-bigint", "crypto-bigint",
"cuprate-common", "cuprate-common",
@ -2237,12 +2218,6 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "virtue"
version = "0.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dcc60c0624df774c82a0ef104151231d37da4962957d691c011c852b2473314"
[[package]] [[package]]
name = "wait-timeout" name = "wait-timeout"
version = "0.2.0" version = "0.2.0"

View file

@ -35,7 +35,7 @@ opt-level = 3
[workspace.dependencies] [workspace.dependencies]
async-trait = { version = "0.1.74" } async-trait = { version = "0.1.74" }
bincode = { version = "2.0.0-rc.3" } borsh = { version = "1.2.1" }
bytes = { version = "1.5.0" } bytes = { version = "1.5.0" }
clap = { version = "4.4.7" } clap = { version = "4.4.7" }
chrono = { version = "0.4.31" } chrono = { version = "0.4.31" }

View file

@ -21,7 +21,7 @@ binaries = [
"dep:serde", "dep:serde",
"dep:monero-epee-bin-serde", "dep:monero-epee-bin-serde",
"dep:monero-wire", "dep:monero-wire",
"dep:bincode", "dep:borsh",
"dep:dirs", "dep:dirs",
"dep:clap" "dep:clap"
] ]
@ -57,7 +57,7 @@ monero-epee-bin-serde = { workspace = true , optional = true}
serde_json = {version = "1", optional = true} serde_json = {version = "1", optional = true}
serde = {version = "1", optional = true, features = ["derive"]} serde = {version = "1", optional = true, features = ["derive"]}
tracing-subscriber = {version = "0.3", optional = true} tracing-subscriber = {version = "0.3", optional = true}
bincode = {version = "2.0.0-rc.3", optional = true} borsh = { workspace = true, optional = true}
dirs = {version="5.0", optional = true} dirs = {version="5.0", optional = true}
clap = { version = "4.4.8", optional = true, features = ["derive"] } clap = { version = "4.4.8", optional = true, features = ["derive"] }
# here to help cargo to pick a version - remove me # here to help cargo to pick a version - remove me

View file

@ -7,7 +7,7 @@ use std::{
sync::Arc, sync::Arc,
}; };
use bincode::{Decode, Encode}; use borsh::{BorshDeserialize, BorshSerialize};
use monero_serai::transaction::{Input, Timelock, Transaction}; use monero_serai::transaction::{Input, Timelock, Transaction};
use tracing_subscriber::fmt::MakeWriter; use tracing_subscriber::fmt::MakeWriter;
@ -18,7 +18,7 @@ use crate::transactions::TransactionVerificationData;
/// Because we are using a RPC interface with a node we need to keep track /// Because we are using a RPC interface with a node we need to keep track
/// of certain data that the node doesn't hold or give us like the number /// of certain data that the node doesn't hold or give us like the number
/// of outputs at a certain time. /// of outputs at a certain time.
#[derive(Debug, Default, Clone, Encode, Decode)] #[derive(Debug, Default, Clone, BorshSerialize, BorshDeserialize)]
pub struct ScanningCache { pub struct ScanningCache {
// network: u8, // network: u8,
numb_outs: HashMap<u64, usize>, numb_outs: HashMap<u64, usize>,
@ -37,7 +37,7 @@ impl ScanningCache {
.create(true) .create(true)
.open(file)?; .open(file)?;
let mut writer = BufWriter::new(file.make_writer()); let mut writer = BufWriter::new(file.make_writer());
bincode::encode_into_std_write(self, &mut writer, bincode::config::standard())?; borsh::to_writer(&mut writer, &self)?;
writer.flush()?; writer.flush()?;
Ok(()) Ok(())
} }
@ -45,7 +45,7 @@ impl ScanningCache {
pub fn load(file: &Path) -> Result<ScanningCache, tower::BoxError> { pub fn load(file: &Path) -> Result<ScanningCache, tower::BoxError> {
let mut file = std::fs::OpenOptions::new().read(true).open(file)?; let mut file = std::fs::OpenOptions::new().read(true).open(file)?;
bincode::decode_from_std_read(&mut file, bincode::config::standard()).map_err(Into::into) Ok(borsh::from_reader(&mut file)?)
} }
pub fn add_new_block_data( pub fn add_new_block_data(