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

[FlexiDag] The relationship store write the relationships in two steps leading to data inconsistent #4125

Open
jackzhhuang opened this issue May 29, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@jackzhhuang
Copy link
Collaborator

jackzhhuang commented May 29, 2024

Bug Report

impl RelationsStore for DbRelationsStore {
    /// See `insert_batch` as well
    /// TODO: use one function with DbWriter for both this function and insert_batch
    fn insert(&self, hash: Hash, parents: BlockHashes) -> Result<(), StoreError> {
        if self.has(hash)? {
            return Err(StoreError::KeyAlreadyExists(hash.to_string()));
        }

        // Insert a new entry for `hash`
        self.parents_access
            .write(DirectDbWriter::new(&self.db), hash, parents.clone())?;

        // The new hash has no children yet
        self.children_access.write(
            DirectDbWriter::new(&self.db),
            hash,
            BlockHashes::new(Vec::new()),
        )?;

        // Update `children` for each parent
        for parent in parents.iter().cloned() {
            let mut children = (*self.get_children(parent)?).clone();
            children.push(hash);
            self.children_access.write(
                DirectDbWriter::new(&self.db),
                parent,
                BlockHashes::new(children),
            )?;
        }

        Ok(())
    }
}

self.parents_access.write and self.children_access.write are two steps.

The data might be inconsistent if self.children_access.write fails and self.parents_access.write succeeds.

@jackzhhuang jackzhhuang added the bug Something isn't working label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants