Update to latest common
This commit is contained in:
parent
4c49cf1596
commit
de5eb1b8cd
24
src/api.rs
24
src/api.rs
@ -708,7 +708,7 @@ fn create_diffs(process: &Process, new_state: &ProcessState) -> AnyhowResult<Vec
|
|||||||
vec![]
|
vec![]
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_state_root = &new_state.merkle_root;
|
let new_state_root = &new_state.state_id;
|
||||||
let new_state_decrypted = match new_state.decrypt_pcd() {
|
let new_state_decrypted = match new_state.decrypt_pcd() {
|
||||||
Ok(val) => val,
|
Ok(val) => val,
|
||||||
Err(_) => Map::new()
|
Err(_) => Map::new()
|
||||||
@ -855,7 +855,7 @@ fn handle_prd(
|
|||||||
PrdType::Update => {
|
PrdType::Update => {
|
||||||
// Compute the merkle tree root for the proposed new state to see if we already know about it
|
// Compute the merkle tree root for the proposed new state to see if we already know about it
|
||||||
let update_merkle_root = prd.pcd_commitments.create_merkle_tree()?.root().ok_or(AnyhowError::msg("Invalid merkle tree"))?.to_lower_hex_string();
|
let update_merkle_root = prd.pcd_commitments.create_merkle_tree()?.root().ok_or(AnyhowError::msg("Invalid merkle tree"))?.to_lower_hex_string();
|
||||||
if relevant_process.get_state_for_commitments_root(&update_merkle_root).is_ok() {
|
if relevant_process.get_state_for_id(&update_merkle_root).is_ok() {
|
||||||
// We already know about that state
|
// We already know about that state
|
||||||
return Err(AnyhowError::msg("Received update for a state we already know"));
|
return Err(AnyhowError::msg("Received update for a state we already know"));
|
||||||
}
|
}
|
||||||
@ -870,7 +870,7 @@ fn handle_prd(
|
|||||||
let new_state = ProcessState {
|
let new_state = ProcessState {
|
||||||
commited_in,
|
commited_in,
|
||||||
pcd_commitment: prd.pcd_commitments,
|
pcd_commitment: prd.pcd_commitments,
|
||||||
merkle_root: update_merkle_root.clone(),
|
state_id: update_merkle_root.clone(),
|
||||||
keys: prd.keys,
|
keys: prd.keys,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@ -927,7 +927,7 @@ fn handle_prd(
|
|||||||
let updated_process = UpdatedProcess {
|
let updated_process = UpdatedProcess {
|
||||||
commitment_tx: OutPoint::from_str(&prd.root_commitment)?,
|
commitment_tx: OutPoint::from_str(&prd.root_commitment)?,
|
||||||
current_process: relevant_process.clone(),
|
current_process: relevant_process.clone(),
|
||||||
modified_state: Some(updated_state.merkle_root),
|
modified_state: Some(updated_state.state_id),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -977,7 +977,7 @@ pub fn update_process_state(init_commitment: String, state_id: String, hash2valu
|
|||||||
// Get the state
|
// Get the state
|
||||||
let state = process.get_latest_concurrent_states_mut()?
|
let state = process.get_latest_concurrent_states_mut()?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|state| state.merkle_root == state_id)
|
.find(|state| state.state_id == state_id)
|
||||||
.ok_or(ApiError::new("Unknown state".to_owned()))?;
|
.ok_or(ApiError::new("Unknown state".to_owned()))?;
|
||||||
|
|
||||||
// Update each value
|
// Update each value
|
||||||
@ -1031,7 +1031,7 @@ pub fn update_process_state(init_commitment: String, state_id: String, hash2valu
|
|||||||
// If every value we can decrypt is valid, then we return the new state and diffs
|
// If every value we can decrypt is valid, then we return the new state and diffs
|
||||||
// We borrow it again immutably
|
// We borrow it again immutably
|
||||||
let process = processes.get(&outpoint).unwrap();
|
let process = processes.get(&outpoint).unwrap();
|
||||||
let state = process.get_latest_concurrent_states()?.into_iter().find(|s| s.merkle_root == state_id).unwrap();
|
let state = process.get_latest_concurrent_states()?.into_iter().find(|s| s.state_id == state_id).unwrap();
|
||||||
let diffs = create_diffs(&process, &state)?;
|
let diffs = create_diffs(&process, &state)?;
|
||||||
|
|
||||||
let udpated_process = UpdatedProcess {
|
let udpated_process = UpdatedProcess {
|
||||||
@ -1273,15 +1273,15 @@ pub fn update_process(
|
|||||||
let new_state = ProcessState::new(prev_state.commited_in, clear_new_state.to_value_object()?, last_state_descriptions.clone())?;
|
let new_state = ProcessState::new(prev_state.commited_in, clear_new_state.to_value_object()?, last_state_descriptions.clone())?;
|
||||||
|
|
||||||
// We compare the new state with the previous one
|
// We compare the new state with the previous one
|
||||||
let last_state_merkle_root = &prev_state.merkle_root;
|
let last_state_merkle_root = &prev_state.state_id;
|
||||||
|
|
||||||
if *last_state_merkle_root == new_state.merkle_root {
|
if *last_state_merkle_root == new_state.state_id {
|
||||||
return Err(ApiError::new("new proposed state is identical to the previous commited state".to_owned()));
|
return Err(ApiError::new("new proposed state is identical to the previous commited state".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We check that we don't have already a similar concurrent state
|
// We check that we don't have already a similar concurrent state
|
||||||
let concurrent_processes = process.get_latest_concurrent_states()?;
|
let concurrent_processes = process.get_latest_concurrent_states()?;
|
||||||
if concurrent_processes.iter().any(|p| p.merkle_root == new_state.merkle_root) {
|
if concurrent_processes.iter().any(|p| p.state_id == new_state.state_id) {
|
||||||
return Err(ApiError::new("New state already known".to_owned()));
|
return Err(ApiError::new("New state already known".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1316,7 +1316,7 @@ pub fn create_update_message(
|
|||||||
let process = processes.get_mut(&outpoint)
|
let process = processes.get_mut(&outpoint)
|
||||||
.ok_or(ApiError::new("Unknown process".to_owned()))?;
|
.ok_or(ApiError::new("Unknown process".to_owned()))?;
|
||||||
|
|
||||||
let update_state = process.get_state_for_commitments_root(&merkle_root_hex)?;
|
let update_state = process.get_state_for_id(&merkle_root_hex)?;
|
||||||
|
|
||||||
// We must have at least the key for the roles field, otherwise we don't know who to send the message to
|
// We must have at least the key for the roles field, otherwise we don't know who to send the message to
|
||||||
let clear_state = update_state.decrypt_pcd()?;
|
let clear_state = update_state.decrypt_pcd()?;
|
||||||
@ -1435,7 +1435,7 @@ fn add_validation_token(init_commitment: String, merkle_root_hex: String, approv
|
|||||||
.ok_or(ApiError::new("Unknown process".to_owned()))?;
|
.ok_or(ApiError::new("Unknown process".to_owned()))?;
|
||||||
|
|
||||||
{
|
{
|
||||||
let update_state: &mut ProcessState = process.get_state_for_commitments_root_mut(&merkle_root_hex)?;
|
let update_state: &mut ProcessState = process.get_state_for_id_mut(&merkle_root_hex)?;
|
||||||
|
|
||||||
let mut merkle_root = [0u8; 32];
|
let mut merkle_root = [0u8; 32];
|
||||||
|
|
||||||
@ -1476,7 +1476,7 @@ pub fn create_response_prd(init_commitment: String, merkle_root_hex: String) ->
|
|||||||
let process = processes.get_mut(&outpoint)
|
let process = processes.get_mut(&outpoint)
|
||||||
.ok_or(ApiError::new("Unknown process".to_owned()))?;
|
.ok_or(ApiError::new("Unknown process".to_owned()))?;
|
||||||
|
|
||||||
let update_state: &mut ProcessState = process.get_state_for_commitments_root_mut(&merkle_root_hex)?;
|
let update_state: &mut ProcessState = process.get_state_for_id_mut(&merkle_root_hex)?;
|
||||||
|
|
||||||
// We must have at least the key for the roles field, otherwise we don't know who to send the message to
|
// We must have at least the key for the roles field, otherwise we don't know who to send the message to
|
||||||
let clear_state = update_state.decrypt_pcd()?;
|
let clear_state = update_state.decrypt_pcd()?;
|
||||||
|
@ -8,8 +8,6 @@ use sdk_common::crypto::AnkSharedSecretHash;
|
|||||||
use sdk_common::log::debug;
|
use sdk_common::log::debug;
|
||||||
use sdk_common::pcd::{Member, Pcd, RoleDefinition};
|
use sdk_common::pcd::{Member, Pcd, RoleDefinition};
|
||||||
use sdk_common::secrets::SecretsStore;
|
use sdk_common::secrets::SecretsStore;
|
||||||
use sdk_common::sp_client::bitcoin::hex::FromHex;
|
|
||||||
use sdk_common::sp_client::bitcoin::OutPoint;
|
|
||||||
use serde_json::{json, Map, Value};
|
use serde_json::{json, Map, Value};
|
||||||
|
|
||||||
use wasm_bindgen_test::*;
|
use wasm_bindgen_test::*;
|
||||||
@ -234,7 +232,7 @@ fn test_pairing() {
|
|||||||
// We have to cheat here and let Bob access Alice process cache
|
// We have to cheat here and let Bob access Alice process cache
|
||||||
let process = alice_process_cache.get(&updated_process.commitment_tx).unwrap();
|
let process = alice_process_cache.get(&updated_process.commitment_tx).unwrap();
|
||||||
|
|
||||||
let state = process.get_state_for_commitments_root(&new_state_id).unwrap();
|
let state = process.get_state_for_id(&new_state_id).unwrap();
|
||||||
|
|
||||||
let hash2values: Map<String, Value> = bob_diff_cache.iter()
|
let hash2values: Map<String, Value> = bob_diff_cache.iter()
|
||||||
.filter(|diff| diff.new_state_merkle_root == *new_state_id)
|
.filter(|diff| diff.new_state_merkle_root == *new_state_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user