Skip to content

Commit 802e9b4

Browse files
committed
fix(contract): migrate old Config layout and bump reshare gas
Adding the verifier-vote cleanup broke two things: - The sixth detached cleanup promise in vote_reshared pushed total cleanup gas to 39 TGas, over the fixed GAS_FOR_VOTE_RESHARED test budget. Raise it to 50 TGas (production attaches max gas, so it is unaffected). - The new remove_non_participant_tee_verifier_votes_tera_gas field changed Config's borsh layout, so migrate() could no longer deserialize production state written with the old layout. Shadow the old 13-field Config as OldConfig in the v3.12.0 migration state and convert it into the current Config, defaulting the new field.
1 parent 76fa0c7 commit 802e9b4

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

crates/contract/src/v3_12_0_state.rs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use near_mpc_contract_interface::types::{Metrics, VerifyForeignTransactionReques
1212
use near_sdk::store::{Lazy, LookupMap};
1313

1414
use crate::{
15-
Config, SupportedForeignChainsByNode,
15+
SupportedForeignChainsByNode,
1616
foreign_chain_rpc::ForeignChainRpcWhitelist,
1717
foreign_chains_metadata::ForeignChainsMetadata,
1818
node_migrations::NodeMigrations,
@@ -26,6 +26,54 @@ use crate::{
2626
update::ProposedUpdates,
2727
};
2828

29+
/// The `Config` layout written by the `3.12.0` contract, before
30+
/// `remove_non_participant_tee_verifier_votes_tera_gas` was appended.
31+
#[derive(Debug, BorshSerialize, BorshDeserialize)]
32+
pub struct OldConfig {
33+
key_event_timeout_blocks: u64,
34+
tee_upgrade_deadline_duration_seconds: u64,
35+
contract_upgrade_deposit_tera_gas: u64,
36+
sign_call_gas_attachment_requirement_tera_gas: u64,
37+
ckd_call_gas_attachment_requirement_tera_gas: u64,
38+
return_signature_and_clean_state_on_success_call_tera_gas: u64,
39+
return_ck_and_clean_state_on_success_call_tera_gas: u64,
40+
fail_on_timeout_tera_gas: u64,
41+
clean_tee_status_tera_gas: u64,
42+
clean_invalid_attestations_tera_gas: u64,
43+
cleanup_orphaned_node_migrations_tera_gas: u64,
44+
remove_non_participant_update_votes_tera_gas: u64,
45+
clean_foreign_chain_data_tera_gas: u64,
46+
}
47+
48+
impl From<OldConfig> for crate::Config {
49+
fn from(old: OldConfig) -> Self {
50+
crate::Config {
51+
key_event_timeout_blocks: old.key_event_timeout_blocks,
52+
tee_upgrade_deadline_duration_seconds: old.tee_upgrade_deadline_duration_seconds,
53+
contract_upgrade_deposit_tera_gas: old.contract_upgrade_deposit_tera_gas,
54+
sign_call_gas_attachment_requirement_tera_gas: old
55+
.sign_call_gas_attachment_requirement_tera_gas,
56+
ckd_call_gas_attachment_requirement_tera_gas: old
57+
.ckd_call_gas_attachment_requirement_tera_gas,
58+
return_signature_and_clean_state_on_success_call_tera_gas: old
59+
.return_signature_and_clean_state_on_success_call_tera_gas,
60+
return_ck_and_clean_state_on_success_call_tera_gas: old
61+
.return_ck_and_clean_state_on_success_call_tera_gas,
62+
fail_on_timeout_tera_gas: old.fail_on_timeout_tera_gas,
63+
clean_tee_status_tera_gas: old.clean_tee_status_tera_gas,
64+
clean_invalid_attestations_tera_gas: old.clean_invalid_attestations_tera_gas,
65+
cleanup_orphaned_node_migrations_tera_gas: old
66+
.cleanup_orphaned_node_migrations_tera_gas,
67+
remove_non_participant_update_votes_tera_gas: old
68+
.remove_non_participant_update_votes_tera_gas,
69+
clean_foreign_chain_data_tera_gas: old.clean_foreign_chain_data_tera_gas,
70+
// New in this version: default the gas for the verifier-vote cleanup
71+
// promise added after `3.12.0`.
72+
..crate::Config::default()
73+
}
74+
}
75+
}
76+
2977
/// Keep this module in sync with [`crate::MpcContract`]: the moment a field's borsh
3078
/// layout diverges, shadow the old type here (see this module's history for examples) so
3179
/// state written by the `3.12.0` contract still deserializes during migration.
@@ -37,7 +85,7 @@ pub struct MpcContract {
3785
pending_verify_foreign_tx_requests: LookupMap<VerifyForeignTransactionRequest, Vec<YieldIndex>>,
3886
proposed_updates: ProposedUpdates,
3987
node_foreign_chain_support: SupportedForeignChainsByNode,
40-
config: Config,
88+
config: OldConfig,
4189
tee_state: TeeState,
4290
accept_requests: bool,
4391
node_migrations: NodeMigrations,
@@ -54,7 +102,7 @@ impl From<MpcContract> for crate::MpcContract {
54102
pending_verify_foreign_tx_requests: old.pending_verify_foreign_tx_requests,
55103
proposed_updates: old.proposed_updates,
56104
node_foreign_chain_support: old.node_foreign_chain_support,
57-
config: old.config,
105+
config: old.config.into(),
58106
tee_state: old.tee_state,
59107
accept_requests: old.accept_requests,
60108
node_migrations: old.node_migrations,

crates/contract/tests/sandbox/utils/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub const ALL_PROTOCOLS: &[Protocol; 4] = &[
1717
/// gas attachment; in practice, nodes usually attach the maximum available gas. For testing,
1818
/// we use this constant to attach a fixed amount to each call and detect if gas usage
1919
/// increases unexpectedly in the future.
20-
pub const GAS_FOR_VOTE_RESHARED: Gas = Gas::from_tgas(44);
20+
pub const GAS_FOR_VOTE_RESHARED: Gas = Gas::from_tgas(50);
2121
pub const GAS_FOR_VOTE_PK: Gas = Gas::from_tgas(22);
2222
pub const GAS_FOR_VOTE_CANCEL_KEYGEN: Gas = Gas::from_tgas(5);
2323
pub const GAS_FOR_VOTE_CANCEL_RESHARING: Gas = Gas::from_tgas(5);

0 commit comments

Comments
 (0)