From 2e2cfeb7af8b6c9e6b708f346041ccc32222cd5b Mon Sep 17 00:00:00 2001 From: Jesse Abramowitz Date: Mon, 29 Jul 2024 12:57:24 -0400 Subject: [PATCH] add keyshare store and test --- .../threshold-signature-server/src/validator/api.rs | 11 +++++++++-- .../src/validator/tests.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/threshold-signature-server/src/validator/api.rs b/crates/threshold-signature-server/src/validator/api.rs index f83b1f4de..8b5fb9d78 100644 --- a/crates/threshold-signature-server/src/validator/api.rs +++ b/crates/threshold-signature-server/src/validator/api.rs @@ -203,9 +203,16 @@ pub async fn new_reshare( .map_err(|_| ValidatorErr::ProtocolError("Error executing protocol".to_string()))? .0 .ok_or(ValidatorErr::NoOutputFromReshareProtocol)?; - let _serialized_key_share = key_serialize(&new_key_share) + let serialized_key_share = key_serialize(&new_key_share) .map_err(|_| ProtocolErr::KvSerialize("Kv Serialize Error".to_string()))?; - // TODO: do reshare call confirm_reshare (delete key when done) see #941 + let network_parent_key = hex::encode(NETWORK_PARENT_KEY); + // TODO: should this be a two step process? see # https://github.com/entropyxyz/entropy-core/issues/968 + if app_state.kv_store.kv().exists(&network_parent_key).await? { + app_state.kv_store.kv().delete(&network_parent_key).await? + }; + + let reservation = app_state.kv_store.kv().reserve_key(network_parent_key).await?; + app_state.kv_store.kv().put(reservation, serialized_key_share.clone()).await?; // TODO: Error handling really complex needs to be thought about. confirm_key_reshare(&api, &rpc, &signer).await?; diff --git a/crates/threshold-signature-server/src/validator/tests.rs b/crates/threshold-signature-server/src/validator/tests.rs index 28897d8a6..34c791361 100644 --- a/crates/threshold-signature-server/src/validator/tests.rs +++ b/crates/threshold-signature-server/src/validator/tests.rs @@ -21,18 +21,16 @@ use crate::{ helpers::{ launch::{development_mnemonic, ValidatorName, FORBIDDEN_KEYS}, substrate::submit_transaction, - tests::initialize_test_logger, + tests::{initialize_test_logger, spawn_testing_validators, unsafe_get}, validator::get_signer_and_x25519_secret_from_mnemonic, }, validator::errors::ValidatorErr, }; use entropy_kvdb::clean_tests; -use entropy_shared::{OcwMessageReshare, EVE_VERIFYING_KEY, MIN_BALANCE}; +use entropy_shared::{OcwMessageReshare, EVE_VERIFYING_KEY, MIN_BALANCE, NETWORK_PARENT_KEY}; use entropy_testing_utils::{ constants::{ALICE_STASH_ADDRESS, RANDOM_ACCOUNT}, - spawn_testing_validators, - substrate_context::{testing_context, test_node_process_testing_state}, - test_context_stationary, + substrate_context::{test_node_process_testing_state, testing_context}, }; use futures::future::join_all; use parity_scale_codec::Encode; @@ -57,6 +55,7 @@ async fn test_reshare() { let client = reqwest::Client::new(); let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1; + let key_share_before = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3001).await; let onchain_reshare_request = OcwMessageReshare { new_signer: alice.public().encode(), block_number }; @@ -77,6 +76,9 @@ async fn test_reshare() { for response_result in response_results { assert_eq!(response_result.unwrap().text().await.unwrap(), ""); } + let key_share_after = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3001).await; + assert_ne!(key_share_before, key_share_after); + clean_tests(); }