zellular-xyz / zsequencer

PoC implementation of the Zellular sequencing protocol
https://zellular.xyz
3 stars 0 forks source link

Fix the thread-safety issue in the prune_old_batches function. #45

Open mchitgarha78 opened 2 months ago

mchitgarha78 commented 2 months ago

The function now looks like this:

def prune_old_batches(self, app_name: str, remove_border: int) -> None:
        """Helper function to prune old batches from memory."""
        self.apps[app_name]["batches"] = {
            batch["hash"]: batch
            for batch in self.apps[app_name]["batches"].values()
            if batch["state"] != "finalized" or batch["index"] > remove_border
        }

The issue lies in the assignment to self.apps[app_name]["batches"], as routes of the node may want to initialize some batches of transactions and append them to the dictionary using the batch hash as the key.