Skip to content

Commit

Permalink
fix: Don't add deleted fnames to sync trie (#1617)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayprabhu authored Jan 11, 2024
1 parent 7379a05 commit 11a1e0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-spies-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@farcaster/hubble": patch
---

fix: Don't add deleted fnames to sync trie
7 changes: 5 additions & 2 deletions apps/hubble/src/network/sync/syncEngine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,15 @@ describe("SyncEngine", () => {
expect((await syncEngine.getDbStats()).numFnames).toEqual(1);
});
test("does not add a deleted fname to the trie", async () => {
userNameProof = Factories.UserNameProof.build({
await engine.mergeUserNameProof(userNameProof);
const deletionProof = Factories.UserNameProof.build({
type: UserNameType.USERNAME_TYPE_FNAME,
name: userNameProof.name,
timestamp: userNameProof.timestamp + 10,
fid: 0,
});
expect(await syncEngine.trie.exists(SyncId.fromFName(userNameProof))).toBeFalsy();
await engine.mergeUserNameProof(userNameProof);
await engine.mergeUserNameProof(deletionProof);
expect(await syncEngine.trie.exists(SyncId.fromFName(userNameProof))).toBeFalsy();
expect((await syncEngine.getDbStats()).numFnames).toEqual(0);
});
Expand Down
3 changes: 2 additions & 1 deletion apps/hubble/src/network/sync/syncEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ class SyncEngine extends TypedEmitter<SyncEvents> {
}
if (
event.mergeUsernameProofBody.usernameProof &&
event.mergeUsernameProofBody.usernameProof.type === UserNameType.USERNAME_TYPE_FNAME
event.mergeUsernameProofBody.usernameProof.type === UserNameType.USERNAME_TYPE_FNAME &&
event.mergeUsernameProofBody.usernameProof.fid !== 0 // Deletes should not be added to the trie
) {
this._syncTrieQ += 1;
statsd().gauge("merkle_trie.merge_q", this._syncTrieQ);
Expand Down

0 comments on commit 11a1e0d

Please sign in to comment.