Skip to content

Commit

Permalink
Add log
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Dec 27, 2023
1 parent 01fef5b commit 0557f73
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions crates/phactory/src/prpc_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2039,12 +2039,15 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> PhactoryApi for Rpc
let mut phactory = self.lock_phactory(false, true)?;
let runtime_state = phactory.runtime_state()?;
let council_members = runtime_state.chain_storage.council_members();
if request.signatures.len() > council_members.len() {
return Err(from_display("Too many signatures"));
}
let genesis_hash = hex::encode(runtime_state.genesis_block_hash);
let mr_to = hex::encode(&request.measurement);
let mr_from = hex::encode(my_measurement()?);
let signed_message = format!("Allow pRuntime to handover from 0x{mr_from} to 0x{mr_to} on chain of genesis 0x{genesis_hash}").into_bytes();
debug!("Signed message : {:?}", hex::encode(&signed_message));
let mut indivaduals = std::collections::BTreeSet::new();
debug!("Signed message: {:?}", hex::encode(&signed_message));
let mut signers = std::collections::BTreeSet::new();
for sig in &request.signatures {
let sig_type = pb::SignatureType::from_i32(sig.signature_type)
.ok_or_else(|| from_display("Invalid signature type"))?;
Expand All @@ -2055,13 +2058,14 @@ impl<Platform: pal::Platform + Serialize + DeserializeOwned> PhactoryApi for Rpc
sig_type,
&sig.signature,
)
.map_err(|_| from_display(format!("Invalid signature of {:?}", &sig.pubkey)))?;
.map_err(|_| from_display("Invalid signature"))?;
if !council_members.contains(&signer) {
return Err(from_display("Not a council member"));
}
indivaduals.insert(signer);
debug!("Signed by {signer:?}");
signers.insert(signer);
}
let percent = indivaduals.len() * 100 / council_members.len();
let percent = signers.len() * 100 / council_members.len();
if percent < 50 {
return Err(from_display("Not enough signatures"));
}
Expand Down
4 changes: 2 additions & 2 deletions docs/pruntime-handover-by-council.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Suppose we have two version of pRuntime A and B, where A is stucked, and we want

SGX MR of A: 0x10c24c0e6bf8a86634417fcd8f934e62439c62907a6f1bc726906a50b054ddf10000000083d719e77deaca1470f6baf62a4d774303c899db69020f9c70ee1dfc08c7ce9e
SGX MR of B: 0xf42f7e095735702d1d3c6ac5fa3b4581d3c3673d3c5ce261a43fe782ccb3e1dc0000000083d719e77deaca1470f6baf62a4d774303c899db69020f9c70ee1dfc08c7ce9e
Genisis block hash: 0x0a15d23307d533d581291ff6dedca9ca10927c7dff6f4df9e8c3bf00bc5a6ded (This can be get in the log of pruntime)
Genisis block hash: 0x0a15d23307d533d581291ff6dedca9ca10927c7dff6f4df9e8c3bf00bc5a6ded (Can be found in prpc::get_info)

Then the workflow would be:
Then the steps would be:

1. Ask at least half of the council members to sign a message as below:
```
Expand Down

0 comments on commit 0557f73

Please sign in to comment.