Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Add push and get methods for RestartLastVotedForkSlots #33613

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dcccabb
Add push and get methods for RestartLastVotedForkSlots
wen-coding Oct 10, 2023
75018a2
Improve expression format.
wen-coding Oct 12, 2023
ad641b1
Remove fill() from RestartLastVotedForkSlots and move into constructor.
wen-coding Oct 13, 2023
0924388
Update ABI signature.
wen-coding Oct 13, 2023
ead61eb
Use flate2 compress directly instead of relying on CompressedSlots.
wen-coding Oct 18, 2023
c1bf8bf
Make constructor of RestartLastVotedForkSlots return error if necessary.
wen-coding Oct 19, 2023
2b181c7
Use minmax and remove unnecessary code.
wen-coding Oct 24, 2023
513116e
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Oct 24, 2023
6491d5f
Replace flate2 with run-length encoding in RestartLastVotedForkSlots.
wen-coding Oct 24, 2023
d78a00e
Remove accidentally added file.
wen-coding Oct 25, 2023
03056b6
The passed in last_voted_fork don't need to be mutable any more.
wen-coding Oct 25, 2023
e788b3e
Switch to different type of run-length encoding.
wen-coding Oct 25, 2023
756d9f2
Fix typo.
wen-coding Oct 25, 2023
7920971
Move constant into RestartLastVotedForkSlots.
wen-coding Oct 26, 2023
73cd8b7
Use BitVec in RawOffsets.
wen-coding Oct 26, 2023
07f3ed2
Remove the unnecessary clone.
wen-coding Oct 26, 2023
f4df7f3
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Oct 27, 2023
6155485
Use iter functions for RLE.
wen-coding Nov 7, 2023
6107deb
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Nov 8, 2023
def82a0
Use take_while instead of loop.
wen-coding Nov 9, 2023
4407db4
Change Run length encoding to iterator implementation.
wen-coding Nov 9, 2023
dd8181c
Allow one slot in RestartLastVotedForkSlots.
wen-coding Nov 9, 2023
692f78e
Various simplifications.
wen-coding Nov 13, 2023
9bf13d6
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Nov 13, 2023
eb15284
Fix various errors and use customized error type.
wen-coding Nov 14, 2023
f8e2437
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Nov 14, 2023
5f54d95
Various simplifications.
wen-coding Nov 15, 2023
4a66754
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Nov 15, 2023
789d3d1
Return error from push_get_restart_last_voted_fork_slots and
wen-coding Nov 16, 2023
1ded7a8
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Nov 16, 2023
be92ca6
Allow 81k slots on RestartLastVotedForkSlots.
wen-coding Nov 16, 2023
3352222
Merge branch 'master' into push_get_restart_last_voted_fork_slots
wen-coding Nov 16, 2023
60e9a3c
Limit MAX_SLOTS to 65535 so we can go back to u16.
wen-coding Nov 16, 2023
99c19f6
Use u16::MAX instead of 65535.
wen-coding Nov 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 106 additions & 2 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use {
},
crds_value::{
self, AccountsHashes, CrdsData, CrdsValue, CrdsValueLabel, EpochSlotsIndex, LowestSlot,
NodeInstance, SnapshotHashes, Version, Vote, MAX_WALLCLOCK,
NodeInstance, RestartLastVotedForkSlots, SnapshotHashes, Version, Vote, MAX_WALLCLOCK,
},
duplicate_shred::DuplicateShred,
epoch_slots::EpochSlots,
Expand Down Expand Up @@ -267,7 +267,7 @@ pub fn make_accounts_hashes_message(
pub(crate) type Ping = ping_pong::Ping<[u8; GOSSIP_PING_TOKEN_SIZE]>;

// TODO These messages should go through the gpu pipeline for spam filtering
#[frozen_abi(digest = "CVvKB495YW6JN4w1rWwajyZmG5wvNhmD97V99rSv9fGw")]
#[frozen_abi(digest = "gPgpX5XKdNFsiqDWuz21oTNkiuR6abKQwqnoRgZgihJ")]
#[derive(Serialize, Deserialize, Debug, AbiEnumVisitor, AbiExample)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum Protocol {
Expand Down Expand Up @@ -965,6 +965,25 @@ impl ClusterInfo {
}
}

pub fn push_restart_last_voted_fork_slots(
&self,
update: &mut [Slot],
last_vote_bankhash: Hash,
) {
let now = timestamp();
let last_voted_fork_slots = RestartLastVotedForkSlots::new(
self.id(),
now,
update,
last_vote_bankhash,
self.my_shred_version(),
);
self.push_message(CrdsValue::new_signed(
CrdsData::RestartLastVotedForkSlots(last_voted_fork_slots),
&self.keypair(),
));
}

fn time_gossip_read_lock<'a>(
&'a self,
label: &'static str,
Expand Down Expand Up @@ -1217,6 +1236,24 @@ impl ClusterInfo {
.collect()
}

pub fn get_restart_last_voted_fork_slots(
&self,
cursor: &mut Cursor,
) -> Vec<RestartLastVotedForkSlots> {
let self_shred_version = self.my_shred_version();
let gossip_crds = self.gossip.crds.read().unwrap();
gossip_crds
.get_entries(cursor)
.filter_map(|entry| {
let CrdsData::RestartLastVotedForkSlots(slots) = &entry.value.data else {
return None;
};
(slots.shred_version == self_shred_version).then_some(slots)
})
.cloned()
.collect()
}

/// Returns duplicate-shreds inserted since the given cursor.
pub(crate) fn get_duplicate_shreds(&self, cursor: &mut Cursor) -> Vec<DuplicateShred> {
let gossip_crds = self.gossip.crds.read().unwrap();
Expand Down Expand Up @@ -3162,6 +3199,7 @@ mod tests {
crds_gossip_pull::tests::MIN_NUM_BLOOM_FILTERS,
crds_value::{CrdsValue, CrdsValueLabel, Vote as CrdsVote},
duplicate_shred::{self, tests::new_rand_shred, MAX_DUPLICATE_SHREDS},
epoch_slots::MAX_SLOTS_PER_ENTRY,
},
itertools::izip,
solana_ledger::shred::Shredder,
Expand Down Expand Up @@ -4559,4 +4597,70 @@ mod tests {
assert_eq!(shred_data.chunk_index() as usize, i);
}
}

#[test]
fn test_push_restart_last_voted_fork_slots() {
let keypair = Arc::new(Keypair::new());
let contact_info = ContactInfo::new_localhost(&keypair.pubkey(), 0);
let cluster_info = ClusterInfo::new(contact_info, keypair, SocketAddrSpace::Unspecified);
let slots = cluster_info.get_restart_last_voted_fork_slots(&mut Cursor::default());
assert!(slots.is_empty());
let mut update: Vec<Slot> = vec![0];
for i in 0..81 {
for j in 0..1000 {
update.push(i * 1050 + j);
}
}
cluster_info.push_restart_last_voted_fork_slots(&mut update, Hash::default());
cluster_info.flush_push_queue();

let mut cursor = Cursor::default();
let slots = cluster_info.get_restart_last_voted_fork_slots(&mut cursor);
assert_eq!(slots.len(), 1);
let retrieved_slots = slots[0].to_slots(0);
assert!(retrieved_slots.len() < MAX_SLOTS_PER_ENTRY);
assert!(retrieved_slots[0] < 69000);
assert_eq!(retrieved_slots.last(), Some(84999).as_ref());

let slots = cluster_info.get_restart_last_voted_fork_slots(&mut cursor);
assert!(slots.is_empty());

// Test with different shred versions.
let mut rng = rand::thread_rng();
let node_pubkey = Pubkey::new_unique();
let mut node = LegacyContactInfo::new_rand(&mut rng, Some(node_pubkey));
node.set_shred_version(42);
let mut slots = RestartLastVotedForkSlots::new_rand(&mut rng, Some(node_pubkey));
slots.shred_version = 42;
let entries = vec![
CrdsValue::new_unsigned(CrdsData::LegacyContactInfo(node)),
CrdsValue::new_unsigned(CrdsData::RestartLastVotedForkSlots(slots)),
];
{
let mut gossip_crds = cluster_info.gossip.crds.write().unwrap();
for entry in entries {
assert!(gossip_crds
.insert(entry, /*now=*/ 0, GossipRoute::LocalMessage)
.is_ok());
}
}
// Should exclude other node's last-voted-fork-slot because of different
// shred-version.
let slots = cluster_info.get_restart_last_voted_fork_slots(&mut Cursor::default());
assert_eq!(slots.len(), 1);
assert_eq!(slots[0].from, cluster_info.id());

// Match shred versions.
{
let mut node = cluster_info.my_contact_info.write().unwrap();
node.set_shred_version(42);
}
cluster_info.push_restart_last_voted_fork_slots(&mut update, Hash::default());
cluster_info.flush_push_queue();
// Should now include both slots.
let slots = cluster_info.get_restart_last_voted_fork_slots(&mut Cursor::default());
assert_eq!(slots.len(), 2);
assert_eq!(slots[0].from, node_pubkey);
assert_eq!(slots[1].from, cluster_info.id());
}
}
Loading