Update to latest common

This commit is contained in:
Sosthene 2024-11-19 17:01:10 +01:00
parent 93ae65ece7
commit 0d522182d6

View File

@ -904,8 +904,14 @@ fn handle_pcd(pcd: Value) -> AnyhowResult<ApiReturn> {
} else { } else {
continue; continue;
} }
debug!("Updating process states with {:#?}", updated_prd); let new_state = ProcessState {
process.insert_state(&updated_prd)?; commited_in: *outpoint,
pcd_commitment: updated_prd.pcd_commitments,
encrypted_pcd: pcd,
keys: updated_prd.keys,
validation_tokens: vec![]
};
process.insert_concurrent_state(new_state)?;
process.prune_impending_requests(); process.prune_impending_requests();
return Ok(ApiReturn { return Ok(ApiReturn {
updated_process: Some((outpoint.to_string(), process.clone())), updated_process: Some((outpoint.to_string(), process.clone())),
@ -1151,8 +1157,8 @@ pub fn update_process(
let new_state_val = Value::from_str(&new_state)?; let new_state_val = Value::from_str(&new_state)?;
// We hash all the new values // We hash all the new values
let pcd_commitment = new_state_val.hash_fields(outpoint)?; let pcd_commitment = Value::Object(new_state_val.hash_fields(outpoint)?);
let new_state_merkle_root = <Value as Pcd>::create_merkle_tree(&Value::Object(pcd_commitment))?.root().unwrap(); let new_state_merkle_root = <Value as Pcd>::create_merkle_tree(&pcd_commitment)?.root().unwrap();
// We compare the new state with the previous one // We compare the new state with the previous one
let last_state_merkle_root = <Value as Pcd>::create_merkle_tree(last_state_commitments)?.root().unwrap(); let last_state_merkle_root = <Value as Pcd>::create_merkle_tree(last_state_commitments)?.root().unwrap();
@ -1172,25 +1178,26 @@ pub fn update_process(
.collect(); .collect();
new_state_val.encrypt_fields(&fields_to_encrypt, &mut fields2keys, &mut fields2cipher); new_state_val.encrypt_fields(&fields_to_encrypt, &mut fields2keys, &mut fields2cipher);
let encrypted_pcd = Value::Object(fields2cipher);
// We create an encrypted values merkle root // We create an encrypted values merkle root
let new_state_encrypted_commitments = Value::Object(fields2cipher).hash_fields(OutPoint::null())?; let new_state_encrypted_commitments = encrypted_pcd.hash_fields(OutPoint::null())?;
let new_state_encrypted_root = <Value as Pcd>::create_merkle_tree(&Value::Object(new_state_encrypted_commitments.clone()))?.root().unwrap(); let new_state_encrypted_root = <Value as Pcd>::create_merkle_tree(&Value::Object(new_state_encrypted_commitments.clone()))?.root().unwrap();
let to_update = process.get_latest_state().unwrap(); // This is an empty state with `commited_in` set as the last unspent output let to_update = process.get_latest_state().unwrap(); // This is an empty state with `commited_in` set as the last unspent output
let device = lock_local_device()?; let device = lock_local_device()?;
let sender = device.to_member();
let update_prd = Prd::new_update( let new_state = ProcessState {
outpoint, commited_in: outpoint,
serde_json::to_string(&sender)?, pcd_commitment: pcd_commitment,
new_state_encrypted_root.to_lower_hex_string(), encrypted_pcd: encrypted_pcd,
fields2keys, keys: fields2keys,
Value::Object(new_state_encrypted_commitments), validation_tokens: vec![]
); };
// Add the new state to the process // Add the new state to the process
process.insert_state(&update_prd); process.insert_concurrent_state(new_state)?;
Ok(ApiReturn { Ok(ApiReturn {
updated_process: Some((init_commitment, process.clone())), updated_process: Some((init_commitment, process.clone())),