Repository navigation
refactor: clarify that tee_state contains attestations for not just active participants
#1695
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -72,7 +72,10 @@ pub struct TeeState { | |||||
| pub(crate) allowed_docker_image_hashes: AllowedDockerImageHashes, | ||||||
| pub(crate) allowed_launcher_compose_hashes: Vec<LauncherDockerComposeHash>, | ||||||
| pub(crate) votes: CodeHashesVotes, | ||||||
| pub participants_attestations: IterableMap<near_sdk::PublicKey, (NodeId, Attestation)>, | ||||||
| /// Mapping of TLS public key of a participant to its NodeId and Attestation. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will fix in #1663 |
||||||
| /// Attestations are stored for any valid participant that has submitted one, not | ||||||
| /// just for the currently active participants. | ||||||
| pub(crate) stored_attestations: IterableMap<near_sdk::PublicKey, (NodeId, Attestation)>, | ||||||
| } | ||||||
|
|
||||||
| impl Default for TeeState { | ||||||
|
|
@@ -81,7 +84,7 @@ impl Default for TeeState { | |||||
| allowed_docker_image_hashes: AllowedDockerImageHashes::default(), | ||||||
| allowed_launcher_compose_hashes: vec![], | ||||||
| votes: CodeHashesVotes::default(), | ||||||
| participants_attestations: IterableMap::new(StorageKey::TeeParticipantAttestation), | ||||||
| stored_attestations: IterableMap::new(StorageKey::TeeParticipantAttestation), | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -108,7 +111,7 @@ impl TeeState { | |||||
| }); | ||||||
|
|
||||||
| Self { | ||||||
| participants_attestations, | ||||||
| stored_attestations: participants_attestations, | ||||||
| ..Default::default() | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -148,7 +151,7 @@ impl TeeState { | |||||
| self.get_allowed_mpc_docker_image_hashes(tee_upgrade_deadline_duration); | ||||||
| let allowed_launcher_compose_hashes = &self.allowed_launcher_compose_hashes; | ||||||
|
|
||||||
| let participant_attestation = self.participants_attestations.get(&node_id.tls_public_key); | ||||||
| let participant_attestation = self.stored_attestations.get(&node_id.tls_public_key); | ||||||
| let Some(participant_attestation) = participant_attestation else { | ||||||
| return TeeQuoteStatus::Invalid("participant has no attestation".to_string()); | ||||||
| }; | ||||||
|
|
@@ -251,10 +254,10 @@ impl TeeState { | |||||
| pub fn add_participant(&mut self, node_id: NodeId, attestation: Attestation) -> bool { | ||||||
| let tls_pk = node_id.tls_public_key.clone(); | ||||||
|
|
||||||
| let is_new = !self.participants_attestations.contains_key(&tls_pk); | ||||||
| let is_new = !self.stored_attestations.contains_key(&tls_pk); | ||||||
|
|
||||||
| // Must pass owned values, not references | ||||||
| self.participants_attestations | ||||||
| self.stored_attestations | ||||||
| .insert(tls_pk, (node_id, attestation)); | ||||||
|
|
||||||
| is_new | ||||||
|
|
@@ -311,30 +314,30 @@ impl TeeState { | |||||
|
|
||||||
| // Collect TLS keys that are *not* in the active participants list | ||||||
| let stale_keys: Vec<near_sdk::PublicKey> = self | ||||||
| .participants_attestations | ||||||
| .stored_attestations | ||||||
| .keys() | ||||||
| .filter(|tls_pk| !active_tls_keys.contains(*tls_pk)) | ||||||
| .cloned() | ||||||
| .collect(); | ||||||
|
|
||||||
| // Remove all stale TEE entries | ||||||
| for tls_pk in stale_keys { | ||||||
| self.participants_attestations.remove(&tls_pk); | ||||||
| self.stored_attestations.remove(&tls_pk); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Returns the list of accounts that currently have TEE attestations stored. | ||||||
| /// Note: This may include accounts that are no longer active protocol participants. | ||||||
| pub fn get_tee_accounts(&self) -> Vec<NodeId> { | ||||||
| self.participants_attestations | ||||||
| self.stored_attestations | ||||||
| .values() | ||||||
| .map(|(node_id, _)| node_id.clone()) | ||||||
| .collect() | ||||||
| } | ||||||
|
|
||||||
| /// Find a NodeId by its TLS public key. | ||||||
| pub fn find_node_id_by_tls_key(&self, tls_public_key: &near_sdk::PublicKey) -> Option<NodeId> { | ||||||
| self.participants_attestations | ||||||
| self.stored_attestations | ||||||
| .get(tls_public_key) | ||||||
| .map(|(node_id, _)| node_id.clone()) | ||||||
| } | ||||||
|
|
@@ -350,7 +353,7 @@ impl TeeState { | |||||
| match participants.info(&signer_id) { | ||||||
| None => false, | ||||||
| Some(info) => { | ||||||
| match self.participants_attestations.get(&info.sign_pk) { | ||||||
| match self.stored_attestations.get(&info.sign_pk) { | ||||||
| None => false, | ||||||
| Some((node_id, _attestation)) => { | ||||||
| node_id.account_id == signer_id | ||||||
|
|
@@ -408,28 +411,28 @@ mod tests { | |||||
| tee_state.add_participant(non_participant_uid.clone(), local_attestation.clone()); | ||||||
|
|
||||||
| // Verify all 4 accounts have TEE info initially | ||||||
| assert_eq!(tee_state.participants_attestations.len(), 4); | ||||||
| assert_eq!(tee_state.stored_attestations.len(), 4); | ||||||
| for node_id in &participant_nodes { | ||||||
| assert!(tee_state | ||||||
| .participants_attestations | ||||||
| .stored_attestations | ||||||
| .contains_key(&node_id.tls_public_key)); | ||||||
| } | ||||||
| assert!(tee_state | ||||||
| .participants_attestations | ||||||
| .stored_attestations | ||||||
| .contains_key(&non_participant_uid.tls_public_key)); | ||||||
|
|
||||||
| // Clean non-participants | ||||||
| tee_state.clean_non_participants(&participants); | ||||||
|
|
||||||
| // Verify only participants remain | ||||||
| assert_eq!(tee_state.participants_attestations.len(), 3); | ||||||
| assert_eq!(tee_state.stored_attestations.len(), 3); | ||||||
| for node_id in &participant_nodes { | ||||||
| assert!(tee_state | ||||||
| .participants_attestations | ||||||
| .stored_attestations | ||||||
| .contains_key(&node_id.tls_public_key)); | ||||||
| } | ||||||
| assert!(!tee_state | ||||||
| .participants_attestations | ||||||
| .stored_attestations | ||||||
| .contains_key(&non_participant_uid.tls_public_key)); | ||||||
| } | ||||||
| } | ||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.