Skip to content

Commit

Permalink
merge v1 and v2
Browse files Browse the repository at this point in the history
re-introduce hard limit
handle signature requests from V1 gracefully

rebase conflicts

added pytest for trailing signatures
  • Loading branch information
kevindeforth committed Feb 4, 2025
1 parent 60659f1 commit 62c4e4b
Show file tree
Hide file tree
Showing 13 changed files with 490 additions and 303 deletions.
Binary file not shown.
Binary file not shown.
Binary file modified libs/chain-signatures/compiled-contracts/v1.wasm
Binary file not shown.
Binary file removed libs/chain-signatures/compiled-contracts/v2.wasm
Binary file not shown.
32 changes: 31 additions & 1 deletion libs/chain-signatures/contract/src/config/impls.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use borsh::{self, BorshDeserialize, BorshSerialize};

use super::{
Config, DynamicValue, PresignatureConfig, ProtocolConfig, SignatureConfig, TripleConfig,
Config, ConfigV1, DynamicValue, InitConfigV1, PresignatureConfig, ProtocolConfig,
SignatureConfig, TripleConfig,
};

/// This is maximum expected participants we aim to support right now. This can be different
Expand All @@ -12,6 +13,35 @@ const MAX_EXPECTED_PARTICIPANTS: u32 = 32;
/// that should be in the network.
const NETWORK_MULTIPLIER: u32 = 128;

// Default delay of five minutes, after that, request is removed from the contract state
const DEFAULT_REQUEST_TIMEOUT_BLOCKS: u64 = 200;

// The maximum number of requests to remove during a call
const MAX_NUM_REQUESTS_TO_REMOVE: u32 = 100;

impl Default for ConfigV1 {
fn default() -> Self {
ConfigV1 {
max_num_requests_to_remove: MAX_NUM_REQUESTS_TO_REMOVE,
request_timeout_blocks: DEFAULT_REQUEST_TIMEOUT_BLOCKS,
}
}
}
impl From<Option<InitConfigV1>> for ConfigV1 {
fn from(value: Option<InitConfigV1>) -> Self {
match value {
None => ConfigV1::default(),
Some(init_config) => ConfigV1 {
max_num_requests_to_remove: init_config
.max_num_requests_to_remove
.unwrap_or(MAX_NUM_REQUESTS_TO_REMOVE),
request_timeout_blocks: init_config
.request_timeout_blocks
.unwrap_or(DEFAULT_REQUEST_TIMEOUT_BLOCKS),
},
}
}
}
impl Config {
pub fn get(&self, key: &str) -> Option<serde_json::Value> {
match key {
Expand Down
12 changes: 12 additions & 0 deletions libs/chain-signatures/contract/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ use near_sdk::serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct DynamicValue(serde_json::Value);

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
pub struct ConfigV1 {
pub max_num_requests_to_remove: u32,
pub request_timeout_blocks: u64,
}

#[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq)]
pub struct InitConfigV1 {
pub max_num_requests_to_remove: Option<u32>,
pub request_timeout_blocks: Option<u64>,
}

#[derive(
Clone, Default, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq,
)]
Expand Down
Loading

0 comments on commit 62c4e4b

Please sign in to comment.