Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion crates/contract-history/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub const fn current_mainnet() -> &'static [u8] {
version_3_2_0()
version_3_3_2()
}

pub const fn current_testnet() -> &'static [u8] {
Expand Down
77 changes: 3 additions & 74 deletions crates/contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ pub mod tee;
pub mod update;
#[cfg(feature = "dev-utils")]
pub mod utils;
pub mod v3_0_2_state;
pub mod v3_2_0_state;
pub mod v3_3_2_state;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not 100% if we were leaving the old states on purpose, but taking into account that our contract size is already near dangerous sizes, I opted for only leaving the necessary code there

Copy link
Contributor

Choose a reason for hiding this comment

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

We had a window where 3_0_2 was on mainnet and 3_2_0 was on testnet.

We can and should delete both the previous state modules in this PR now that they are unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ouch, I thought I had done so 🙃


#[cfg(feature = "bench-contract-methods")]
mod bench;
Expand Down Expand Up @@ -1285,19 +1284,11 @@ impl MpcContract {
pub fn migrate() -> Result<Self, Error> {
log!("migrating contract");

match try_state_read::<v3_0_2_state::MpcContract>() {
match try_state_read::<v3_3_2_state::MpcContract>() {
Ok(Some(state)) => return Ok(state.into()),
Ok(None) => return Err(InvalidState::ContractStateIsMissing.into()),
Err(err) => {
log!("failed to deserialize state into 3_0_2 state: {:?}", err);
}
};

match try_state_read::<v3_2_0_state::MpcContract>() {
Ok(Some(state)) => return Ok(state.into()),
Ok(None) => return Err(InvalidState::ContractStateIsMissing.into()),
Err(err) => {
log!("failed to deserialize state into 3_2_0 state: {:?}", err);
log!("failed to deserialize state into 3_3_2 state: {:?}", err);
}
};

Expand All @@ -1308,19 +1299,6 @@ impl MpcContract {
}
}

/// Removes stale data from the contract to be removed after a contract upgrade. Some
/// containers are expensive to run destructors on, thus we don't include it in the contract upgrade itself,
/// as it can run out of gas. Thus we create methods to run these destructors manually post upgrade.
pub fn post_upgrade_cleanup(&mut self) {
let Some(mut attestations) = self.stale_data.participant_attestations.take() else {
panic!("stale participant_attestations data has already been cleared");
};

attestations.clear();

log!("Successfully cleared stale TEE attestations.");
}

pub fn state(&self) -> &ProtocolContractState {
&self.protocol_state
}
Expand Down Expand Up @@ -3545,55 +3523,6 @@ mod tests {
assert_eq!(*resharing_state, expected_resharing_state);
}

#[test]
fn test_post_upgrade_cleanup_success() {
// given
let mut contract = MpcContract::init(
ThresholdParameters::new(gen_participants(3), Threshold::new(2)).unwrap(),
None,
)
.unwrap();

let mut mock_stale_map = IterableMap::new(StorageKey::_DeprecatedTeeParticipantAttestation);
let node_pk = bogus_ed25519_near_public_key();
let node_id = NodeId {
account_id: gen_account_id(),
tls_public_key: bogus_ed25519_near_public_key(),
account_public_key: Some(bogus_ed25519_near_public_key()),
};
let attestation = mpc_attestation::attestation::Attestation::Mock(
mpc_attestation::attestation::MockAttestation::Valid,
);

mock_stale_map.insert(node_pk.clone(), (node_id, attestation));

contract.stale_data.participant_attestations = Some(mock_stale_map);

// when
contract.post_upgrade_cleanup();

// then
assert_matches::assert_matches!(contract.stale_data.participant_attestations, None);
}

#[test]
#[should_panic(expected = "stale participant_attestations data has already been cleared")]
fn test_post_upgrade_cleanup_panics_if_already_cleared() {
// given
let mut contract = MpcContract::init(
ThresholdParameters::new(gen_participants(3), Threshold::new(2)).unwrap(),
None,
)
.unwrap();

contract.stale_data.participant_attestations = None;

// when
contract.post_upgrade_cleanup();

// then panic
}

/// Sets up a complete TEE test environment with contract, accounts, mock dstack attestation, TLS key and the node's near public key.
/// This is a helper function that provides all the common components needed for TEE-related tests.
fn setup_tee_test() -> (
Expand Down
215 changes: 0 additions & 215 deletions crates/contract/src/v3_0_2_state.rs

This file was deleted.

Loading
Loading