Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ValidatorInfo to PeerContacts. #3039

Open
wants to merge 16 commits into
base: albatross
Choose a base branch
from

Conversation

nibhar
Copy link
Member

@nibhar nibhar commented Nov 12, 2024

This PR adds Validators information to the PeerContacts exchanged during discovery. In this PR the information is not populated, neither is it utilized. It is intended as an additional means of retrieving validator information aside from just the dht.

In addition to that it changes how peer contact information gets discarded in case it is faulty. Not discarding everything, but only the faulty piece of data instead. As Validator contacts can only be verified when the state is complete, and only if the respective key has not been rotated out (or in) yet, an entry in the address book can be flagged as local_only in those cases where verification is not (yet) possible. They should be re-evaluated at a time, when the verification is possible. Local_only entries will not be put into discovery messages.

@nibhar nibhar force-pushed the nibhar/validator-discovery branch 4 times, most recently from bac56d8 to 2c0c433 Compare November 12, 2024 03:14
@nibhar nibhar force-pushed the nibhar/validator-discovery branch from 2c0c433 to 4d66caa Compare November 25, 2024 06:51
@ii-cruz ii-cruz force-pushed the nibhar/validator-discovery branch 2 times, most recently from aad39ad to 145c075 Compare November 25, 2024 09:20
@nibhar nibhar force-pushed the nibhar/validator-discovery branch from d1915ac to afaa762 Compare November 25, 2024 10:58
validator-network/src/network_impl.rs Outdated Show resolved Hide resolved
network-libp2p/src/discovery/peer_contacts.rs Outdated Show resolved Hide resolved
@nibhar nibhar force-pushed the nibhar/validator-discovery branch from 42e4099 to 10e9372 Compare November 25, 2024 18:07
@nibhar nibhar marked this pull request as ready for review November 25, 2024 18:28
validator/src/validator.rs Outdated Show resolved Hide resolved
network-libp2p/src/discovery/peer_contacts.rs Outdated Show resolved Hide resolved
if let Some(validator_info) = &info.contact.inner.validator_info {
self.validator_peer_ids
.entry(validator_info.validator_address.clone())
.or_insert(HashSet::new())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.or_insert(HashSet::new())
.or_default()

network-libp2p/src/discovery/peer_contacts.rs Outdated Show resolved Hide resolved
Comment on lines +731 to +736
contact.validator_info = self.validator_record_signing.as_ref().and_then(|callback| {
let tagged_signed = (callback)(contact.peer_id(), contact.timestamp);
Some(ValidatorInfo {
validator_address: tagged_signed.record.validator_address.clone(),
signature: tagged_signed.signature.clone(),
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contact.validator_info = self.validator_record_signing.as_ref().and_then(|callback| {
let tagged_signed = (callback)(contact.peer_id(), contact.timestamp);
Some(ValidatorInfo {
validator_address: tagged_signed.record.validator_address.clone(),
signature: tagged_signed.signature.clone(),
})
contact.validator_info = self.validator_record_signing.as_ref().map(|callback| {
let tagged_signed = (callback)(contact.peer_id(), contact.timestamp);
ValidatorInfo {
validator_address: tagged_signed.record.validator_address.clone(),
signature: tagged_signed.signature.clone(),
}

@@ -115,13 +115,18 @@ pub struct Behaviour {

/// Timer to do house-keeping in the peer address book.
house_keeping_timer: Interval,

/// dht verifier TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this TODO?

connection: CloseConnection::All,
}),
// Errors must not result in a closed connection as light clients are unable to verify ValidatorRecord.
HandlerOutEvent::Error(error) => log::trace!(?error, "Received invalid contact"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, but we panic if a light client tries to verify a validator record 🤔

let peer_contacts: Vec<SignedPeerContact> = peer_contacts
.into_iter()
.filter_map(filter_contact(
0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why zero?

let peer_contacts: Vec<SignedPeerContact> = peer_contacts
.into_iter()
.filter_map(filter_contact(
0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why zero?

@@ -526,7 +575,13 @@ impl ConnectionHandler for Handler {
peer_contacts,
} => {
// Check the peer contact for a valid signature.
if !peer_contact.verify() {
let Some(peer_contact) = filter_contact(
0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why zero?

}

let results = futures.collect::<Vec<Result<(), RequestError>>>().await;
if results.iter().any(|result| result.is_ok()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about clearing the peers that didn't work?

@@ -652,4 +654,16 @@ impl Network for MockNetwork {
) -> Result<Vec<Self::PeerId>, MockNetworkError> {
Ok(self.get_peers())
}

fn get_peers_by_validator(&self, _validator_address: &Address) -> Vec<Self::PeerId> {
// TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO
unimplemented!()

&self,
_callback: impl Fn(Self::PeerId, u64) -> TaggedSigned<ValidatorRecord<Self::PeerId>, KeyPair>,
) {
// TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO
unimplemented!()

@@ -115,13 +115,18 @@ pub struct Behaviour {

/// Timer to do house-keeping in the peer address book.
house_keeping_timer: Interval,

/// dht verifier TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// dht verifier TODO
/// DHT validator record verifier.

Copy link
Member

@ii-cruz ii-cruz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is failing on the Build crate features. Haven't looked at it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants