Skip to content

Commit

Permalink
Fix server diff logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Nov 17, 2023
1 parent 60d64d6 commit f0a9bc6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
3 changes: 1 addition & 2 deletions tests/integration/sync/send_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ async fn integration_sync_send_events() -> Result<()> {
owner.address()
));

// Create the remote provider
// Create the remote provider
let origin = origin();
let remote_origin = origin.clone();
let provider = owner.create_remote_provider(&origin, None).await?;
owner.insert_remote(origin, Box::new(provider));

// Sync with a local account that does not exist on
// Sync a local account that does not exist on
// the remote which should create the account on the remote
owner.sync().await?;

Expand Down
39 changes: 39 additions & 0 deletions workspace/net/src/server/services/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,44 @@ impl Service for EventLogService {

let proof = event_log.tree().head().map_err(Box::from)?;

let comparison = event_log
.tree()
.compare(&client_proof)
.map_err(Box::from)?;

let patch: Option<Patch> = match comparison {
Comparison::Equal => {
Some(Default::default())
}
Comparison::Contains(_indices, _leaves) => {
let match_proof = event_log
.tree()
.contains(&client_proof)
.map_err(Box::from)?;

if match_proof.is_some() {
Some(event_log.patch_until(Some(&last_commit)).await?)
} else {
None
}
}
Comparison::Unknown => None,
};

if let Some(patch) = patch {
let buffer = encode(&patch).await?;
let reply = ResponseMessage::new(
request.id(),
StatusCode::OK,
Some(Ok(patch.0.len())),
Cow::Owned(buffer),
)?;
Ok(reply)
} else {
Ok((StatusCode::CONFLICT, request.id()).into())
}

/*
let match_proof = event_log
.tree()
.contains(&client_proof)
Expand All @@ -246,6 +284,7 @@ impl Service for EventLogService {
} else {
Ok((StatusCode::CONFLICT, request.id()).into())
}
*/
}
EVENT_LOG_PATCH => {
let (vault_id, commit_proof) =
Expand Down

0 comments on commit f0a9bc6

Please sign in to comment.