-
Notifications
You must be signed in to change notification settings - Fork 0
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
send personhood to node template #37
base: master
Are you sure you want to change the base?
Changes from 6 commits
5dbd7bf
52ca3b6
8b31434
87f596a
6da0d0e
784cdd0
6a518bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use crate::{ | ||
command_utils::{get_accountid_from_str, get_chain_api, get_worker_api_direct}, | ||
Cli, | ||
}; | ||
use codec::{Decode, Encode}; | ||
use encointer_primitives::communities::CommunityIdentifier; | ||
use itc_rpc_client::direct_client::DirectApi; | ||
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue}; | ||
use itp_types::DirectRequestStatus; | ||
use itp_utils::FromHexPrefixed; | ||
use log::*; | ||
use std::str::FromStr; | ||
|
||
#[derive(Debug, Clone, Parser)] | ||
pub struct IssueNodeTemplateXtCmd { | ||
pub account: String, | ||
pub node_template_idx: u32, | ||
pub cid: String, | ||
// TODO add proofs | ||
// pub proofs: Vec<ProofOfAttendance> | ||
} | ||
|
||
use crate::personhood_oracle::commands::fetch_reputation::get_ceremony_index; | ||
|
||
impl IssueNodeTemplateXtCmd { | ||
pub fn run(&self, cli: &Cli) { | ||
//todo!(); | ||
let api = get_chain_api(cli); | ||
let direct_api = get_worker_api_direct(cli); | ||
let cindex = get_ceremony_index(&api); | ||
|
||
let cid = CommunityIdentifier::from_str(&self.cid).unwrap(); | ||
let account = get_accountid_from_str(&self.account); | ||
let node_template_idx = self.node_template_idx; | ||
|
||
let rpc_params = | ||
vec![cid.encode(), cindex.encode(), account.encode(), node_template_idx.encode()]; | ||
trace!("rpc_params is : {:?}", &rpc_params); | ||
|
||
let rpc_params = rpc_params | ||
.into_iter() | ||
.map(|p| itp_utils::hex::hex_encode(p.as_slice())) | ||
.collect(); | ||
Comment on lines
+53
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uii, if this is necessary for our rpc api, then we have to improve it, but it indeed seems that we use a similar approach in the worker. |
||
|
||
let rpc_method = "personhoodoracle_issueNodeTemplateXt".to_owned(); | ||
let jsonrpc_call: String = | ||
RpcRequest::compose_jsonrpc_call(rpc_method, rpc_params).unwrap(); | ||
|
||
let rpc_response_str_result = direct_api.get(&jsonrpc_call); | ||
debug!("rpc_response_str_result is:{:?}", &rpc_response_str_result); | ||
let rpc_response_str = rpc_response_str_result.unwrap(); | ||
|
||
// Decode RPC response. | ||
let Ok(rpc_response) = serde_json::from_str::<RpcResponse>(&rpc_response_str) else { | ||
panic!("Can't parse RPC response: '{rpc_response_str}'"); | ||
}; | ||
let rpc_return_value = match RpcReturnValue::from_hex(&rpc_response.result) { | ||
Ok(rpc_return_value) => rpc_return_value, | ||
Err(e) => panic!("Failed to decode RpcReturnValue: {:?}", e), | ||
}; | ||
|
||
match rpc_return_value.status { | ||
DirectRequestStatus::Ok => { | ||
println!("NodeTemplate Index has been issued successfully."); | ||
}, | ||
_ => { | ||
let error_msg = "Node Template Xt issuance failed"; | ||
error!("{}", &error_msg); | ||
let inner_error_msg: String = | ||
Decode::decode(&mut rpc_return_value.value.as_slice()) | ||
.expect("Failed to decode node tempölate xt issuing RPC error msg"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo |
||
error!("Node Template issuing failed: {:#?}", &inner_error_msg); | ||
}, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ use itp_node_api::{ | |
}; | ||
use itp_nonce_cache::{MutateNonce, Nonce}; | ||
use itp_types::{parentchain::AccountId, OpaqueCall}; | ||
use log::*; | ||
use sp_core::H256; | ||
use sp_runtime::{generic::Era, OpaqueExtrinsic}; | ||
use std::{sync::Arc, vec::Vec}; | ||
|
@@ -112,6 +113,16 @@ where | |
(m.get_runtime_version(), m.get_runtime_transaction_version()) | ||
})?; | ||
|
||
debug!( | ||
"extrinsic factory creates {} extrinsics for chain with genesis hash: {:?}", | ||
calls.len(), | ||
self.genesis_hash | ||
); | ||
trace!("runtime_spec_version: {}", runtime_spec_version); | ||
trace!("runtime_transaction_version: {}", runtime_spec_version); | ||
trace!("additional extrinsic params: {:?}", additional_extrinsic_params); | ||
trace!("start with nonce: {:?}", nonce_value); | ||
|
||
let extrinsics_buffer: Vec<OpaqueExtrinsic> = calls | ||
.iter() | ||
.map(|call| { | ||
|
@@ -123,17 +134,24 @@ where | |
additional_extrinsic_params, | ||
); | ||
let xt = compose_extrinsic_offline!(&self.signer, call, extrinsic_params).encode(); | ||
trace!( | ||
"encoded extrinsic with nonce {}: 0x{}", | ||
nonce_value, | ||
hex::encode(xt.clone()) | ||
Comment on lines
+137
to
+140
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd remove this trace as it introduces a clone There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the idea here is to format the encoded call exactly the way it could be copy-pasted and inspected with js/apps. So I'd rather leave it as is - unless you have a way to achieve exactly the same without the clone |
||
); | ||
nonce_value += 1; | ||
xt | ||
}) | ||
.map(|xt| { | ||
OpaqueExtrinsic::from_bytes(&xt) | ||
.expect("A previously encoded extrinsic has valid codec; qed.") | ||
let oe = OpaqueExtrinsic::from_bytes(&xt) | ||
.expect("A previously encoded extrinsic has valid codec; qed."); | ||
trace!("opaque extrinsic: {:?}", oe); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this the log that is empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. possibly |
||
oe | ||
}) | ||
.collect(); | ||
|
||
*nonce_lock = Nonce(nonce_value); | ||
|
||
trace!("created {} extrinsics", extrinsics_buffer.len()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have the same log outside of the enclave, do we want to keep this one? |
||
Ok(extrinsics_buffer) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,9 @@ use codec::{Decode, Encode}; | |
use sp_runtime::{generic::Header as HeaderG, traits::BlakeTwo256, MultiAddress, MultiSignature}; | ||
use sp_std::vec::Vec; | ||
|
||
#[cfg(feature = "std")] | ||
use std::fmt::Display; | ||
|
||
pub type StorageProof = Vec<Vec<u8>>; | ||
|
||
// Basic Types. | ||
|
@@ -52,6 +55,18 @@ pub enum ParentchainId { | |
TargetB, | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
impl Display for ParentchainId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
let message = match self { | ||
ParentchainId::Integritee => "L1:Integritee", | ||
ParentchainId::TargetA => "L1:Encointer", | ||
ParentchainId::TargetB => "L1:NodeTemplate", | ||
}; | ||
write!(f, "{}", message) | ||
} | ||
} | ||
|
||
Comment on lines
+58
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like this to be upstreamed and customizeable. but it should work inside enclave too and should replace all log prefixes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Display is part of I am unsure if it makes sense to replace the general log prefixes. It is not the same as in the substrate runtime, where we know that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pardon, I didn't mean the pallet log prefixes. I meant the ones where we deliberately printed TargetA/B/Integritee before. |
||
pub trait IdentifyParentchain { | ||
fn parentchain_id(&self) -> ParentchainId; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ use itp_component_container::ComponentGetter; | |
use itp_ocall_api::EnclaveOnChainOCallApi; | ||
use itp_stf_primitives::types::AccountId; | ||
use itp_storage::{storage_double_map_key, StorageHasher}; | ||
use itp_types::{WorkerRequest, WorkerResponse, parentchain::ParentchainId}; | ||
use itp_types::{parentchain::ParentchainId, WorkerRequest, WorkerResponse}; | ||
use log::*; | ||
use std::cmp::min; | ||
|
||
|
@@ -52,12 +52,7 @@ fn get_reputation_ocall_api( | |
cid: CommunityIdentifier, | ||
cindex: CeremonyIndexType, | ||
) -> Reputation { | ||
println!( | ||
"requesting reputation for {:?}: cid is :{}, cindex is: {}", | ||
prover, | ||
cid, | ||
cindex.clone() | ||
); | ||
info!("requesting reputation for {:?}: cid is :{}, cindex is: {}", prover, cid, cindex.clone()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cindex is a copy type, so we shouldn't need the clone. |
||
let unverified_reputation = Reputation::Unverified; | ||
|
||
let ocall_api = GLOBAL_OCALL_API_COMPONENT.get(); | ||
|
@@ -77,13 +72,14 @@ fn get_reputation_ocall_api( | |
trace!("storage_hash is : {}", hex::encode(storage_hash.clone())); | ||
|
||
let requests = vec![WorkerRequest::ChainStorage(storage_hash, None)]; | ||
let mut resp: Vec<WorkerResponse<Vec<u8>>> = match ocall_api.worker_request(requests, &ParentchainId::TargetA) { | ||
Ok(response) => response, | ||
Err(e) => { | ||
error!("Worker response decode failed. Error: {:?}", e); | ||
return unverified_reputation | ||
}, | ||
}; | ||
let mut resp: Vec<WorkerResponse<Vec<u8>>> = | ||
match ocall_api.worker_request(requests, &ParentchainId::TargetA) { | ||
Ok(response) => response, | ||
Err(e) => { | ||
error!("Worker response decode failed. Error: {:?}", e); | ||
return unverified_reputation | ||
}, | ||
}; | ||
|
||
let first = match resp.pop() { | ||
None => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this todo about?