Skip to content

Commit

Permalink
feat: contract is now upgradeable through participants voting for upd…
Browse files Browse the repository at this point in the history
…ates (#714)

* Moved contract various states to state.rs

* Added near-rng crate

* Added ability to deploy and update contract configs
  • Loading branch information
ChaoticTempest authored Jul 24, 2024
1 parent c0abf1d commit 84ff24c
Show file tree
Hide file tree
Showing 8 changed files with 521 additions and 83 deletions.
7 changes: 7 additions & 0 deletions chain-signatures/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chain-signatures/contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ schemars = "0.8"
k256 = { version = "0.13.1", features = ["sha256", "ecdsa", "serde", "arithmetic", "expose-field"] }
crypto-shared = { path = "../crypto-shared" }
near-gas = { version = "0.2.5", features = ["serde", "borsh", "schemars"] }
near-rng = "0.1.1"
thiserror = "1"

[dev-dependencies]
Expand Down
30 changes: 30 additions & 0 deletions chain-signatures/contract/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use borsh::{self, BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
pub struct Config {
/// Timeout for triple generation in milliseconds.
pub triple_timeout: u64,
/// Timeout for presignature generation in milliseconds.
pub presignature_timeout: u64,
/// Timeout for signature generation in milliseconds.
pub signature_timeout: u64,
}

impl Default for Config {
fn default() -> Self {
Self {
triple_timeout: min_to_ms(20),
presignature_timeout: secs_to_ms(30),
signature_timeout: secs_to_ms(30),
}
}
}

pub const fn secs_to_ms(secs: u64) -> u64 {
secs * 1000
}

pub const fn min_to_ms(min: u64) -> u64 {
min * 60 * 1000
}
12 changes: 11 additions & 1 deletion chain-signatures/contract/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,18 @@ pub enum VoteError {
EpochMismatch,
#[error("Number of participants cannot go below threshold.")]
ParticipantsBelowThreshold,
#[error("Update not found.")]
UpdateNotFound,
#[error("Unexpected protocol state: {0}")]
UnexpectedProtocolState(String),
#[error("Unexpected: {0}")]
Unexpected(String),
}

impl near_sdk::FunctionError for VoteError {
fn panic(&self) -> ! {
crate::env::panic_str(&self.to_string())
}
}

#[derive(Debug, thiserror::Error)]
Expand All @@ -77,7 +87,7 @@ pub enum MpcContractError {
#[error("respond fn error: {0}")]
RespondError(RespondError),
#[error("vote_* fn error: {0}")]
VoteError(VoteError),
VoteError(#[from] VoteError),
#[error("init fn error: {0}")]
InitError(InitError),
#[error("join fn error: {0}")]
Expand Down
Loading

0 comments on commit 84ff24c

Please sign in to comment.