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

Commit d9f20e9

Browse files
behzadnouriwillhickey
authored andcommitted
refreshes ContactInfo.outset before initializing validator (#3135)
Nodes join gossip during bootstrap process with a stub contact-info which in particular has invalid TVU socket address. Once the bootstrap is done they re-join gossip a 2nd time with a fully populated contact-info, but this contact-info has an outset timestamp older than the 1st one because it was initiated earlier. In v2.0 the outset timestamp determines which contact-info overrides the other, so the v2.0 nodes refrain from updating their CRDS table with the fully initialized contact-info. The commit refreshes ContactInfo.outset before initializing the validator so that it overrides the one pushed to the gossip by the bootstrap stage.
1 parent cafb5ef commit d9f20e9

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

gossip/src/cluster_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl ClusterInfo {
666666
*instance = NodeInstance::new(&mut thread_rng(), id, timestamp());
667667
}
668668
*self.keypair.write().unwrap() = new_keypair;
669-
self.my_contact_info.write().unwrap().set_pubkey(id);
669+
self.my_contact_info.write().unwrap().hot_swap_pubkey(id);
670670

671671
self.insert_self();
672672
self.push_message(CrdsValue::new_signed(

gossip/src/contact_info.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,7 @@ impl ContactInfo {
181181
Self {
182182
pubkey,
183183
wallclock,
184-
outset: {
185-
let now = SystemTime::now();
186-
let elapsed = now.duration_since(UNIX_EPOCH).unwrap();
187-
u64::try_from(elapsed.as_micros()).unwrap()
188-
},
184+
outset: get_node_outset(),
189185
shred_version,
190186
version: solana_version::Version::default(),
191187
addrs: Vec::<IpAddr>::default(),
@@ -210,8 +206,11 @@ impl ContactInfo {
210206
self.shred_version
211207
}
212208

213-
pub fn set_pubkey(&mut self, pubkey: Pubkey) {
214-
self.pubkey = pubkey
209+
pub fn hot_swap_pubkey(&mut self, pubkey: Pubkey) {
210+
self.pubkey = pubkey;
211+
// Need to update ContactInfo.outset so that this node's contact-info
212+
// will override older node with the same pubkey.
213+
self.outset = get_node_outset();
215214
}
216215

217216
pub fn set_wallclock(&mut self, wallclock: u64) {
@@ -409,6 +408,12 @@ impl ContactInfo {
409408
}
410409
}
411410

411+
fn get_node_outset() -> u64 {
412+
let now = SystemTime::now();
413+
let elapsed = now.duration_since(UNIX_EPOCH).unwrap();
414+
u64::try_from(elapsed.as_micros()).unwrap()
415+
}
416+
412417
impl<'de> Deserialize<'de> for ContactInfo {
413418
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
414419
where

turbine/src/cluster_nodes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ pub fn make_test_cluster<R: Rng>(
547547
.collect();
548548
nodes.shuffle(rng);
549549
let keypair = Arc::new(Keypair::new());
550-
nodes[0].set_pubkey(keypair.pubkey());
550+
nodes[0] = ContactInfo::new_localhost(&keypair.pubkey(), /*wallclock:*/ timestamp());
551551
let this_node = nodes[0].clone();
552552
let mut stakes: HashMap<Pubkey, u64> = nodes
553553
.iter()

validator/src/main.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,13 @@ pub fn main() {
19011901
return;
19021902
}
19031903

1904+
// Bootstrap code above pushes a contact-info with more recent timestamp to
1905+
// gossip. If the node is staked the contact-info lingers in gossip causing
1906+
// false duplicate nodes error.
1907+
// Below line refreshes the timestamp on contact-info so that it overrides
1908+
// the one pushed by bootstrap.
1909+
node.info.hot_swap_pubkey(identity_keypair.pubkey());
1910+
19041911
let validator = Validator::new(
19051912
node,
19061913
identity_keypair,

0 commit comments

Comments
 (0)