Skip to content

Commit

Permalink
caches Merkle shreds signature verifications (solana-labs#230)
Browse files Browse the repository at this point in the history
Merkle shreds sign the Merkle root of the erasure batch, so all shreds
within the same erasure batch have the same signature. The commit
improves shreds signature verification by adding an LRU cache.
  • Loading branch information
behzadnouri authored Apr 19, 2024
1 parent 9d953cb commit a94e221
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 36 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ jsonrpc-derive = "18.0.0"
jsonrpc-http-server = "18.0.0"
jsonrpc-ipc-server = "18.0.0"
jsonrpc-pubsub = "18.0.0"
lazy-lru = "0.1.2"
lazy_static = "1.4.0"
libc = "0.2.153"
libloading = "0.7.4"
Expand Down
10 changes: 6 additions & 4 deletions core/src/repair/repair_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mod test {
super::*,
solana_ledger::{
shred::{Shred, ShredFlags},
sigverify_shreds::verify_shred_cpu,
sigverify_shreds::{verify_shred_cpu, LruCache},
},
solana_sdk::{
packet::PacketFlags,
Expand All @@ -64,11 +64,13 @@ mod test {
std::{
collections::HashMap,
net::{IpAddr, Ipv4Addr},
sync::RwLock,
},
};

fn run_test_sigverify_shred_cpu_repair(slot: Slot) {
solana_logger::setup();
let cache = RwLock::new(LruCache::new(/*capacity:*/ 128));
let mut shred = Shred::new_from_data(
slot,
0xc0de,
Expand All @@ -93,14 +95,14 @@ mod test {
packet.meta_mut().flags |= PacketFlags::REPAIR;

let leader_slots = HashMap::from([(slot, keypair.pubkey())]);
assert!(verify_shred_cpu(&packet, &leader_slots));
assert!(verify_shred_cpu(&packet, &leader_slots, &cache));

let wrong_keypair = Keypair::new();
let leader_slots = HashMap::from([(slot, wrong_keypair.pubkey())]);
assert!(!verify_shred_cpu(&packet, &leader_slots));
assert!(!verify_shred_cpu(&packet, &leader_slots, &cache));

let leader_slots = HashMap::new();
assert!(!verify_shred_cpu(&packet, &leader_slots));
assert!(!verify_shred_cpu(&packet, &leader_slots, &cache));
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ eager = { workspace = true }
fs_extra = { workspace = true }
futures = { workspace = true }
itertools = { workspace = true }
lazy-lru = { workspace = true }
lazy_static = { workspace = true }
libc = { workspace = true }
log = { workspace = true }
Expand Down
Loading

0 comments on commit a94e221

Please sign in to comment.