Skip to content
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

Support deletes #68

Merged
merged 4 commits into from
Nov 22, 2024
Merged

Support deletes #68

merged 4 commits into from
Nov 22, 2024

Conversation

sanjayprabhu
Copy link
Contributor

@sanjayprabhu sanjayprabhu commented Nov 21, 2024

Reflect store operations in the trie and refactor engine to create multiple transactions.

@sanjayprabhu sanjayprabhu marked this pull request as ready for review November 22, 2024 01:17
@@ -308,6 +390,15 @@ impl ShardEngine {
}
}

pub fn sync_id_exists(&mut self, sync_id: &Vec<u8>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for test use, or public use? If test, I'd go with pub(crate).

Otherwise, probably best to surface the error back to the caller instead of logging and returning false. I think trie.exists should only fail under extreme conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test, I'll fix

@@ -47,6 +47,7 @@ threadpool = "1.8.1"
rand = "0.8.5"
humantime-serde = "1.1.1"
humantime = "2.1.0"
itertools = "0.13.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think this made it into the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did. This is what implements into_group_map_by

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's one of those things that adds magic behind the scenes. Still getting used to that.

}

impl snapchain::ValidatorMessage {
pub fn fid(&self) -> u32 {
Copy link
Contributor

@suurkivi suurkivi Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. I might prefer something like below for improved readability:
impl snapchain::ValidatorMessage {
    pub fn fid(&self) -> u32 {
        if let Some(fname) = &self.fname_transfer {
            return fname.fid as u32;
        }
        if let Some(event) = &self.on_chain_event {
            return event.fid as u32;
        }
        0
    }
}

I think upon seeing the unwrap there I really have to scrutinize the code, and it took me a moment to realize that it was indeed safe due to the is_some() above.

I think we can probably remove most of the unwraps() in this file with similar refactors and it will be MUCH faster to reason about, especially at a glance.

  1. What to do in the fall through case? Should we return an error or even panic? We don't expect this to ever be either? Can we model as actual enum in protobuf?

Maybe 0 is fine, but perhaps a comment? Or a TODO for end state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Ah, much cleaner. Fixed.
  2. I think if we use oneof it will use enums. We should probably switch to that actually. But even if we did, it won't solve the problem because it's acceptable to have 0 as a value in the protobuf, so callers have to handle fid 0 (which is not valid for the application, fids start from 1). So, I think defaulting to 0 is fine here.

}
let mut snap_txns = self.create_transactions_from_mempool(messages);
for snap_txn in &mut snap_txns {
self.replay_snap_txn(&snap_txn, txn_batch)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, this is really nice, same logic applied in all three of the main functions.

}
}
let mut snap_txns = self.create_transactions_from_mempool(messages);
for snap_txn in &mut snap_txns {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is snap_txn short for snapchain_txn? I might prefer the longer form as snap_txn implies (on first read) to be introducing a new concept.

) -> Result<(), EngineError> {
match event.body {
Some(hub_event::hub_event::Body::MergeMessageBody(merge)) => {
if let Some(msg) = merge.message {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect merge.message to ever be None here? Should we return an error or panic in the missing case, or do you think it's ok or even normal to ignore?

Copy link
Contributor Author

@sanjayprabhu sanjayprabhu Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's possible for it to be None. e.g. registering your fid for the first time will generate only an onchain event, or similarly, registering your fname will only have an fname transfer. Quite normal

}
}
_ => {
return Err(EngineError::UnsupportedEvent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any value in attaching what kind of event it is, similar to how we handle UnsupportedMessageType?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a placeholder until we implement the other event types, we will not have the fallback case at all. So not worth it. I'll add a todo.

@sanjayprabhu sanjayprabhu enabled auto-merge (squash) November 22, 2024 03:48
@sanjayprabhu sanjayprabhu enabled auto-merge (squash) November 22, 2024 03:53
@sanjayprabhu sanjayprabhu merged commit 881b0ee into main Nov 22, 2024
2 checks passed
@sanjayprabhu sanjayprabhu deleted the support_deletes branch November 22, 2024 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants