Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow offchain worker requests to all TSS nodes in entropy-tss test environment #1147

Merged
merged 17 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions crates/client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
},
staking_extension::events,
},
get_api, get_rpc, EntropyConfig,
get_api, get_rpc,
},
change_endpoint, change_threshold_accounts, get_oracle_headings, register, remove_program,
request_attestation, store_program,
Expand All @@ -20,8 +20,7 @@ use crate::{
use entropy_shared::{QuoteContext, QuoteInputData};
use entropy_testing_utils::{
constants::{TEST_PROGRAM_WASM_BYTECODE, TSS_ACCOUNTS, X25519_PUBLIC_KEYS},
helpers::encode_verifying_key,
jump_start_network, spawn_testing_validators,
helpers::{encode_verifying_key, spawn_tss_nodes_and_start_chain},
substrate_context::test_context_stationary,
test_node_process_testing_state, ChainSpecType,
};
Expand All @@ -32,7 +31,7 @@ use rand::{
use serial_test::serial;
use sp_core::{sr25519, Pair, H256};
use sp_keyring::AccountKeyring;
use subxt::{tx::PairSigner, utils::AccountId32};
use subxt::utils::AccountId32;

#[tokio::test]
#[serial]
Expand Down Expand Up @@ -211,18 +210,8 @@ async fn test_store_and_remove_program() {
async fn test_remove_program_reference_counter() {
let program_owner = AccountKeyring::Ferdie.pair();

let (_validator_ips, _validator_ids) =
spawn_testing_validators(ChainSpecType::Integration).await;

let force_authoring = true;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();

// Jumpstart the network
let alice = AccountKeyring::Alice;
let signer = PairSigner::<EntropyConfig, sr25519::Pair>::new(alice.clone().into());
jump_start_network(&api, &rpc, &signer).await;
let (_ctx, api, rpc, _validator_ips, _validator_ids) =
spawn_tss_nodes_and_start_chain(ChainSpecType::IntegrationJumpStarted).await;

// Store a program
let program_pointer = store_program(
Expand Down Expand Up @@ -274,9 +263,11 @@ async fn test_remove_program_reference_counter() {
#[serial]
async fn test_get_oracle_headings() {
let force_authoring = true;
let substrate_context = &test_node_process_testing_state(force_authoring).await[0];
let api = get_api(&substrate_context.ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context.ws_url).await.unwrap();
let context =
test_node_process_testing_state(ChainSpecType::IntegrationJumpStarted, force_authoring)
.await;
let api = get_api(&context[0].ws_url).await.unwrap();
let rpc = get_rpc(&context[0].ws_url).await.unwrap();

let mut current_block = 0;
while current_block < 2 {
Expand Down
6 changes: 5 additions & 1 deletion crates/protocol/src/execute_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub async fn execute_reshare(
(ThresholdKeyShare<KeyParams, PartyId>, AuxInfo<KeyParams, PartyId>),
ProtocolExecutionErr,
> {
tracing::debug!("Executing proactive refresh");
tracing::info!("Executing reshare");
tracing::debug!("Signing with {:?}", &threshold_pair.public());

let pair = PairWrapper(threshold_pair.clone());
Expand All @@ -400,9 +400,13 @@ pub async fn execute_reshare(
.map_err(ProtocolExecutionErr::SessionCreation)?;

let (new_key_share, chans) = execute_protocol_generic(chans, session, session_id_hash).await?;

tracing::info!("Completed reshare protocol");

let aux_info = if let Some(aux_info) = aux_info_option {
aux_info
} else {
tracing::info!("Executing aux gen session as part of reshare");
// Now run an aux gen session
let session_id_hash_aux_data = session_id.blake2(Some(Subsession::AuxGen))?;
let session = make_aux_gen_session(
Expand Down
8 changes: 4 additions & 4 deletions crates/shared/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ pub const DAVE_VERIFYING_KEY: EncodedVerifyingKey = [
3, 42, 97, 187, 199, 208, 95, 166, 102, 15, 38, 146, 173, 111, 175, 123, 62, 132, 178, 237,
150, 199, 194, 240, 153, 30, 113, 104, 57, 63, 54, 2, 65,
];
// This key is associated with a constant key share generation from DETERMINISTIC_KEY_SHARE_EVE
pub const EVE_VERIFYING_KEY: EncodedVerifyingKey = [
// This key is associated with a constant key share generation from DETERMINISTIC_KEY_SHARE_NETWORK
pub const PREGENERATED_NETWORK_VERIFYING_KEY: EncodedVerifyingKey = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just renamed for clarity

2, 78, 59, 129, 175, 156, 34, 52, 202, 208, 157, 103, 156, 230, 3, 94, 209, 57, 35, 71, 206,
100, 206, 64, 95, 93, 205, 54, 34, 138, 37, 222, 110,
];
Expand All @@ -22,7 +22,7 @@ pub const DEFAULT_VERIFYING_KEY: EncodedVerifyingKey = [0; VERIFICATION_KEY_LENG

lazy_static! {
// key used to create a deterministic key share for EVE taken from here https://docs.rs/k256/latest/k256/ecdsa/index.html
pub static ref DETERMINISTIC_KEY_SHARE_EVE: [u8; 32] = hex!("4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318");
pub static ref DETERMINISTIC_KEY_SHARE_NETWORK: [u8; 32] = hex!("4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318");
// key used to create a deterministic key for DAVE - this is random 32 bytes
pub static ref DETERMINISTIC_KEY_SHARE_DAVE: [u8; 32] = hex!("06b07fd12cdfb94fbde3ff2098e9f19bb11b00959680cfbd15c914b025f298d7");
// hash used to find DEVICE_KEY_PROXY onchain
Expand Down Expand Up @@ -75,7 +75,7 @@ pub const MAX_SIGNERS: u8 = 15;
pub const SIGNER_THRESHOLD: u8 = 2;

/// For testing to line up chain mock data and reshare_test
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 11;
pub const TEST_RESHARE_BLOCK_NUMBER: u32 = 10;

/// Program version number, must be incremented if version number changes
pub const PROGRAM_VERSION_NUMBER: u8 = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember there was a README or something as part of the script that generates these. Does that need to be updated in any way to account for these changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
43 changes: 20 additions & 23 deletions crates/testing-utils/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use crate::{
chain_api::{get_api, get_rpc, EntropyConfig},
spawn_testing_validators,
substrate_context::{test_context_stationary, test_node_process_testing_state},
ChainSpecType,
substrate_context::test_node_process_testing_state,
ChainSpecType, TestNodeProcess,
};
use entropy_protocol::PartyId;
use rand::{rngs::StdRng, SeedableRng};
Expand All @@ -26,31 +26,28 @@ pub use tdx_quote::encode_verifying_key;

/// A helper for setting up tests which starts both a set of TS servers and a chain node and returns
/// the chain API as well as IP addresses and PartyId of the started validators
///
/// Note that since this function does not reside in entropy-tss, cfg(test) will be false when the
/// TSS nodes are set up, meaning the unsafe API will not be enabled
Comment on lines +30 to +31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not introduce a testing feature and change the cfg clause to be #[cfg(any(feature = "testing", test))]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good idea

pub async fn spawn_tss_nodes_and_start_chain(
chain_spec_type: ChainSpecType,
) -> (OnlineClient<EntropyConfig>, LegacyRpcMethods<EntropyConfig>, Vec<String>, Vec<PartyId>) {
) -> (
Vec<TestNodeProcess<EntropyConfig>>,
OnlineClient<EntropyConfig>,
LegacyRpcMethods<EntropyConfig>,
Vec<String>,
Vec<PartyId>,
Comment on lines +35 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we should probably move these into a struct, or at least typedef it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good idea. But could turn into quite a big change, because once having a struct we may as well pass it to test helper functions.

Generally, we could bundle api and rpc together into a struct and use it in all client functions.

The validator_ips and validator_ids we actually very rarely use because we know what are going to be. So i think they could be ditched from here and replaced with constants.

I would maybe do that in a followup.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validator_ips and validator_ids we actually very rarely use because we know what are going to be. So i think they could be ditched from here and replaced with constants.

When I was trying to parallelize the tests I was using them because they would change between runs. Ofc if you open a PR with them hardcoded as they are now it won't be a problem, but it would be a bonus if we did provide some flexibility for them.

) {
let (validator_ips, validator_ids) = spawn_testing_validators(chain_spec_type).await;

let (api, rpc) = match chain_spec_type {
ChainSpecType::Development => {
let substrate_context = test_context_stationary().await;
(
get_api(&substrate_context.node_proc.ws_url).await.unwrap(),
get_rpc(&substrate_context.node_proc.ws_url).await.unwrap(),
)
},
ChainSpecType::Integration => {
// Here we need to use `--chain=integration-tests` and force authoring otherwise we won't be
// able to get our chain in the right state to be jump started.
let force_authoring = true;
let substrate_context = &&test_node_process_testing_state(force_authoring).await[0];
(
get_api(&substrate_context.ws_url).await.unwrap(),
get_rpc(&substrate_context.ws_url).await.unwrap(),
)
},
};
(api, rpc, validator_ips, validator_ids)
// Here we need to force authoring otherwise we won't be able to get our chain in the right
// state to be jump started.
let force_authoring = true;
let substrate_context = test_node_process_testing_state(chain_spec_type, force_authoring).await;
let api = get_api(&substrate_context[0].ws_url).await.unwrap();
let rpc = get_rpc(&substrate_context[0].ws_url).await.unwrap();

(substrate_context, api, rpc, validator_ips, validator_ids)
}

/// Get the mock PCK that will be used for a given TSS account ID
Expand Down
4 changes: 1 addition & 3 deletions crates/testing-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ pub mod create_test_keyshares;
pub mod helpers;
mod node_proc;
pub mod substrate_context;
pub use entropy_tss::helpers::tests::{
jump_start_network_with_signer as jump_start_network, spawn_testing_validators, ChainSpecType,
};
pub use entropy_tss::helpers::tests::{spawn_testing_validators, ChainSpecType};
pub use node_proc::TestNodeProcess;
pub use substrate_context::*;

Expand Down
18 changes: 9 additions & 9 deletions crates/testing-utils/src/substrate_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use entropy_tss::helpers::tests::ChainSpecType;
use sp_keyring::AccountKeyring;
use subxt::{config::substrate::SubstrateExtrinsicParams, OnlineClient};

Expand Down Expand Up @@ -110,43 +111,42 @@ pub async fn test_node_process_stationary() -> TestNodeProcess<EntropyConfig> {
///
/// Allowing `force_authoring` will produce blocks.
pub async fn test_node_process_testing_state(
chain_spec_type: ChainSpecType,
force_authoring: bool,
) -> Vec<TestNodeProcess<EntropyConfig>> {
let alice_bootnode = Some(
"/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWM7EoKJfwgzAR1nAVmYRuuFq2f3GpJPLrdfhQaRsKjn38"
.to_string(),
);
// reduses message from chain to same TSS cleaning up a lot of logging
let fuck_off_tss_ip = Some("127.0.0.1:4010".to_string());
let result = test_node(
AccountKeyring::Alice,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
None,
)
.await;
let result_bob = test_node_process_with(
AccountKeyring::Bob,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
Some("http://127.0.0.1:3002".into()),
)
.await;
let result_charlie = test_node_process_with(
AccountKeyring::Charlie,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
Some("http://127.0.0.1:3003".into()),
)
.await;
let result_dave = test_node_process_with(
AccountKeyring::Dave,
"--chain=integration-tests".to_string(),
format!("--chain={}", chain_spec_type),
force_authoring,
alice_bootnode.clone(),
fuck_off_tss_ip.clone(),
Some("http://127.0.0.1:3004".into()),
)
.await;

Expand Down
Loading
Loading