Skip to content

Commit e916576

Browse files
authored
Feature/dkg snapshot epoch (#5900)
* define storage item for holding historical DKG state * make all epoch storage operations go through proxy functions * make each saving action also apply to the historical item * removed usage of update_epoch function * test correct save heights * exposed query for the epoch state at specified height * regenerated contract schema * restored default cw-plus behaviour as in hindsight it makes more sense
1 parent 6c11497 commit e916576

File tree

23 files changed

+1013
-152
lines changed

23 files changed

+1013
-152
lines changed

common/client-libs/validator-client/src/nyxd/contract_traits/dkg_query_client.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ pub trait DkgQueryClient {
4141
self.query_dkg_contract(request).await
4242
}
4343

44+
async fn get_epoch_at_height(&self, height: u64) -> Result<Option<Epoch>, NyxdError> {
45+
let request = DkgQueryMsg::GetEpochStateAtHeight { height };
46+
self.query_dkg_contract(request).await
47+
}
48+
4449
async fn can_advance_state(&self) -> Result<StateAdvanceResponse, NyxdError> {
4550
let request = DkgQueryMsg::CanAdvanceState {};
4651
self.query_dkg_contract(request).await
@@ -299,6 +304,9 @@ mod tests {
299304
match msg {
300305
DkgQueryMsg::GetState {} => client.get_state().ignore(),
301306
DkgQueryMsg::GetCurrentEpochState {} => client.get_current_epoch().ignore(),
307+
DkgQueryMsg::GetEpochStateAtHeight { height } => {
308+
client.get_epoch_at_height(height).ignore()
309+
}
302310
DkgQueryMsg::CanAdvanceState {} => client.can_advance_state().ignore(),
303311
DkgQueryMsg::GetCurrentEpochThreshold {} => {
304312
client.get_current_epoch_threshold().ignore()

common/cosmwasm-smart-contracts/coconut-dkg/src/msg.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ pub enum QueryMsg {
8484
#[cfg_attr(feature = "schema", returns(Epoch))]
8585
GetCurrentEpochState {},
8686

87+
#[cfg_attr(feature = "schema", returns(Option<Epoch>))]
88+
GetEpochStateAtHeight { height: u64 },
89+
8790
#[cfg_attr(feature = "schema", returns(u64))]
8891
GetCurrentEpochThreshold {},
8992

contracts/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/coconut-dkg/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ cw4 = { workspace = true }
2929
thiserror = { workspace = true }
3030

3131
[dev-dependencies]
32+
anyhow = { workspace = true }
3233
easy-addr = { path = "../../common/cosmwasm-smart-contracts/easy_addr" }
3334
cw-multi-test = { workspace = true }
3435
cw4-group = { path = "../multisig/cw4-group" }

contracts/coconut-dkg/schema/nym-coconut-dkg.json

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,29 @@
361361
},
362362
"additionalProperties": false
363363
},
364+
{
365+
"type": "object",
366+
"required": [
367+
"get_epoch_state_at_height"
368+
],
369+
"properties": {
370+
"get_epoch_state_at_height": {
371+
"type": "object",
372+
"required": [
373+
"height"
374+
],
375+
"properties": {
376+
"height": {
377+
"type": "integer",
378+
"format": "uint64",
379+
"minimum": 0.0
380+
}
381+
},
382+
"additionalProperties": false
383+
}
384+
},
385+
"additionalProperties": false
386+
},
364387
{
365388
"type": "object",
366389
"required": [
@@ -2036,6 +2059,271 @@
20362059
}
20372060
}
20382061
},
2062+
"get_epoch_state_at_height": {
2063+
"$schema": "http://json-schema.org/draft-07/schema#",
2064+
"title": "Nullable_Epoch",
2065+
"anyOf": [
2066+
{
2067+
"$ref": "#/definitions/Epoch"
2068+
},
2069+
{
2070+
"type": "null"
2071+
}
2072+
],
2073+
"definitions": {
2074+
"Epoch": {
2075+
"type": "object",
2076+
"required": [
2077+
"epoch_id",
2078+
"state",
2079+
"state_progress",
2080+
"time_configuration"
2081+
],
2082+
"properties": {
2083+
"deadline": {
2084+
"anyOf": [
2085+
{
2086+
"$ref": "#/definitions/Timestamp"
2087+
},
2088+
{
2089+
"type": "null"
2090+
}
2091+
]
2092+
},
2093+
"epoch_id": {
2094+
"type": "integer",
2095+
"format": "uint64",
2096+
"minimum": 0.0
2097+
},
2098+
"state": {
2099+
"$ref": "#/definitions/EpochState"
2100+
},
2101+
"state_progress": {
2102+
"$ref": "#/definitions/StateProgress"
2103+
},
2104+
"time_configuration": {
2105+
"$ref": "#/definitions/TimeConfiguration"
2106+
}
2107+
},
2108+
"additionalProperties": false
2109+
},
2110+
"EpochState": {
2111+
"oneOf": [
2112+
{
2113+
"type": "string",
2114+
"enum": [
2115+
"waiting_initialisation",
2116+
"in_progress"
2117+
]
2118+
},
2119+
{
2120+
"type": "object",
2121+
"required": [
2122+
"public_key_submission"
2123+
],
2124+
"properties": {
2125+
"public_key_submission": {
2126+
"type": "object",
2127+
"required": [
2128+
"resharing"
2129+
],
2130+
"properties": {
2131+
"resharing": {
2132+
"type": "boolean"
2133+
}
2134+
},
2135+
"additionalProperties": false
2136+
}
2137+
},
2138+
"additionalProperties": false
2139+
},
2140+
{
2141+
"type": "object",
2142+
"required": [
2143+
"dealing_exchange"
2144+
],
2145+
"properties": {
2146+
"dealing_exchange": {
2147+
"type": "object",
2148+
"required": [
2149+
"resharing"
2150+
],
2151+
"properties": {
2152+
"resharing": {
2153+
"type": "boolean"
2154+
}
2155+
},
2156+
"additionalProperties": false
2157+
}
2158+
},
2159+
"additionalProperties": false
2160+
},
2161+
{
2162+
"type": "object",
2163+
"required": [
2164+
"verification_key_submission"
2165+
],
2166+
"properties": {
2167+
"verification_key_submission": {
2168+
"type": "object",
2169+
"required": [
2170+
"resharing"
2171+
],
2172+
"properties": {
2173+
"resharing": {
2174+
"type": "boolean"
2175+
}
2176+
},
2177+
"additionalProperties": false
2178+
}
2179+
},
2180+
"additionalProperties": false
2181+
},
2182+
{
2183+
"type": "object",
2184+
"required": [
2185+
"verification_key_validation"
2186+
],
2187+
"properties": {
2188+
"verification_key_validation": {
2189+
"type": "object",
2190+
"required": [
2191+
"resharing"
2192+
],
2193+
"properties": {
2194+
"resharing": {
2195+
"type": "boolean"
2196+
}
2197+
},
2198+
"additionalProperties": false
2199+
}
2200+
},
2201+
"additionalProperties": false
2202+
},
2203+
{
2204+
"type": "object",
2205+
"required": [
2206+
"verification_key_finalization"
2207+
],
2208+
"properties": {
2209+
"verification_key_finalization": {
2210+
"type": "object",
2211+
"required": [
2212+
"resharing"
2213+
],
2214+
"properties": {
2215+
"resharing": {
2216+
"type": "boolean"
2217+
}
2218+
},
2219+
"additionalProperties": false
2220+
}
2221+
},
2222+
"additionalProperties": false
2223+
}
2224+
]
2225+
},
2226+
"StateProgress": {
2227+
"type": "object",
2228+
"required": [
2229+
"registered_dealers",
2230+
"registered_resharing_dealers",
2231+
"submitted_dealings",
2232+
"submitted_key_shares",
2233+
"verified_keys"
2234+
],
2235+
"properties": {
2236+
"registered_dealers": {
2237+
"description": "Counts the number of dealers that have registered in this epoch.",
2238+
"type": "integer",
2239+
"format": "uint32",
2240+
"minimum": 0.0
2241+
},
2242+
"registered_resharing_dealers": {
2243+
"description": "Counts the number of resharing dealers that have registered in this epoch. This field is only populated during a resharing exchange. It is always <= registered_dealers.",
2244+
"type": "integer",
2245+
"format": "uint32",
2246+
"minimum": 0.0
2247+
},
2248+
"submitted_dealings": {
2249+
"description": "Counts the number of fully received dealings (i.e. full chunks) from all the allowed dealers.",
2250+
"type": "integer",
2251+
"format": "uint32",
2252+
"minimum": 0.0
2253+
},
2254+
"submitted_key_shares": {
2255+
"description": "Counts the number of submitted verification key shared from the dealers.",
2256+
"type": "integer",
2257+
"format": "uint32",
2258+
"minimum": 0.0
2259+
},
2260+
"verified_keys": {
2261+
"description": "Counts the number of verified key shares.",
2262+
"type": "integer",
2263+
"format": "uint32",
2264+
"minimum": 0.0
2265+
}
2266+
},
2267+
"additionalProperties": false
2268+
},
2269+
"TimeConfiguration": {
2270+
"type": "object",
2271+
"required": [
2272+
"dealing_exchange_time_secs",
2273+
"in_progress_time_secs",
2274+
"public_key_submission_time_secs",
2275+
"verification_key_finalization_time_secs",
2276+
"verification_key_submission_time_secs",
2277+
"verification_key_validation_time_secs"
2278+
],
2279+
"properties": {
2280+
"dealing_exchange_time_secs": {
2281+
"type": "integer",
2282+
"format": "uint64",
2283+
"minimum": 0.0
2284+
},
2285+
"in_progress_time_secs": {
2286+
"type": "integer",
2287+
"format": "uint64",
2288+
"minimum": 0.0
2289+
},
2290+
"public_key_submission_time_secs": {
2291+
"type": "integer",
2292+
"format": "uint64",
2293+
"minimum": 0.0
2294+
},
2295+
"verification_key_finalization_time_secs": {
2296+
"type": "integer",
2297+
"format": "uint64",
2298+
"minimum": 0.0
2299+
},
2300+
"verification_key_submission_time_secs": {
2301+
"type": "integer",
2302+
"format": "uint64",
2303+
"minimum": 0.0
2304+
},
2305+
"verification_key_validation_time_secs": {
2306+
"type": "integer",
2307+
"format": "uint64",
2308+
"minimum": 0.0
2309+
}
2310+
},
2311+
"additionalProperties": false
2312+
},
2313+
"Timestamp": {
2314+
"description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```",
2315+
"allOf": [
2316+
{
2317+
"$ref": "#/definitions/Uint64"
2318+
}
2319+
]
2320+
},
2321+
"Uint64": {
2322+
"description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```",
2323+
"type": "string"
2324+
}
2325+
}
2326+
},
20392327
"get_epoch_threshold": {
20402328
"$schema": "http://json-schema.org/draft-07/schema#",
20412329
"title": "uint64",

contracts/coconut-dkg/schema/raw/query.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@
2828
},
2929
"additionalProperties": false
3030
},
31+
{
32+
"type": "object",
33+
"required": [
34+
"get_epoch_state_at_height"
35+
],
36+
"properties": {
37+
"get_epoch_state_at_height": {
38+
"type": "object",
39+
"required": [
40+
"height"
41+
],
42+
"properties": {
43+
"height": {
44+
"type": "integer",
45+
"format": "uint64",
46+
"minimum": 0.0
47+
}
48+
},
49+
"additionalProperties": false
50+
}
51+
},
52+
"additionalProperties": false
53+
},
3154
{
3255
"type": "object",
3356
"required": [

0 commit comments

Comments
 (0)