diff --git a/package.json b/package.json index de210388f..0eeca5659 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "types": "src/index.ts", "type": "module", "license": "MIT", - "version": "0.0.11", + "version": "0.0.12", "devDependencies": { "@types/jest": "^29.5.3", "@typescript-eslint/eslint-plugin": "^6.2.1", diff --git a/src/coValue.ts b/src/coValue.ts index afea7cbeb..408b0c632 100644 --- a/src/coValue.ts +++ b/src/coValue.ts @@ -148,7 +148,7 @@ export class CoValue { tryAddTransactions( sessionID: SessionID, newTransactions: Transaction[], - newHash: Hash, + givenExpectedNewHash: Hash | undefined, newSignature: Signature ): boolean { const signerID = getAgentSignerID( @@ -171,16 +171,16 @@ export class CoValue { newTransactions ); - if (newHash !== expectedNewHash) { - console.warn("Invalid hash", { newHash, expectedNewHash }); + if (givenExpectedNewHash && givenExpectedNewHash !== expectedNewHash) { + console.warn("Invalid hash", { expectedNewHash, givenExpectedNewHash }); return false; } - if (!verify(newSignature, newHash, signerID)) { + if (!verify(newSignature, expectedNewHash, signerID)) { console.warn( "Invalid signature", newSignature, - newHash, + expectedNewHash, signerID ); return false; @@ -192,7 +192,7 @@ export class CoValue { this.sessions[sessionID] = { transactions, - lastHash: newHash, + lastHash: expectedNewHash, streamingHash: newStreamingHash, lastSignature: newSignature, }; @@ -517,7 +517,6 @@ export class CoValue { sessionID as SessionID ] || 0, newTransactions, - lastHash: log.lastHash, lastSignature: log.lastSignature, }, ]; diff --git a/src/sync.test.ts b/src/sync.test.ts index 92edce4d1..880703cd2 100644 --- a/src/sync.test.ts +++ b/src/sync.test.ts @@ -9,7 +9,12 @@ import { WritableStream, TransformStream, } from "isomorphic-streams"; -import { connectedPeers, newStreamPair, randomAnonymousAccountAndSessionID, shouldNotResolve } from "./testUtils.js"; +import { + connectedPeers, + newStreamPair, + randomAnonymousAccountAndSessionID, + shouldNotResolve, +} from "./testUtils.js"; import { AccountID } from "./account.js"; test("Node replies with initial tx and header to empty subscribe", async () => { @@ -86,7 +91,6 @@ test("Node replies with initial tx and header to empty subscribe", async () => { ], }, ], - lastHash: map.coValue.sessions[node.ownSessionID]!.lastHash!, lastSignature: map.coValue.sessions[node.ownSessionID]!.lastSignature!, }, @@ -165,7 +169,6 @@ test("Node replies with only new tx to subscribe with some known state", async ( ], }, ], - lastHash: map.coValue.sessions[node.ownSessionID]!.lastHash!, lastSignature: map.coValue.sessions[node.ownSessionID]!.lastSignature!, }, @@ -255,7 +258,6 @@ test("After subscribing, node sends own known state and new txs to peer", async ], }, ], - lastHash: map.coValue.sessions[node.ownSessionID]!.lastHash!, lastSignature: map.coValue.sessions[node.ownSessionID]!.lastSignature!, }, @@ -288,7 +290,6 @@ test("After subscribing, node sends own known state and new txs to peer", async ], }, ], - lastHash: map.coValue.sessions[node.ownSessionID]!.lastHash!, lastSignature: map.coValue.sessions[node.ownSessionID]!.lastSignature!, }, @@ -368,7 +369,6 @@ test("Client replies with known new content to tellKnownState from server", asyn ], }, ], - lastHash: map.coValue.sessions[node.ownSessionID]!.lastHash!, lastSignature: map.coValue.sessions[node.ownSessionID]!.lastSignature!, }, @@ -472,7 +472,6 @@ test("No matter the optimistic known state, node respects invalid known state me ], }, ], - lastHash: map.coValue.sessions[node.ownSessionID]!.lastHash!, lastSignature: map.coValue.sessions[node.ownSessionID]!.lastSignature!, }, @@ -576,7 +575,6 @@ test("If we add a server peer, all updates to all coValues are sent to it, even ], }, ], - lastHash: map.coValue.sessions[node.ownSessionID]!.lastHash!, lastSignature: map.coValue.sessions[node.ownSessionID]!.lastSignature!, }, @@ -1123,5 +1121,3 @@ function admStateEx(adminID: AccountID) { id: adminID, }; } - - diff --git a/src/sync.ts b/src/sync.ts index 2241806c5..c99b01bc2 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -52,8 +52,6 @@ export type NewContentMessage = { export type SessionNewContent = { after: number; newTransactions: Transaction[]; - // TODO: is lastHash needed here? - lastHash: Hash; lastSignature: Signature; }; export type DoneMessage = { @@ -426,7 +424,7 @@ export class SyncManager { const success = coValue.tryAddTransactions( sessionID, newTransactions, - newContentForSession.lastHash, + undefined, newContentForSession.lastSignature );