Merge pull request #13 from gardencmp/anselm/gar-106-remove-hash-from-sync-messages

Remove need to communicate session hash
This commit is contained in:
Anselm Eickhoff
2023-08-15 15:07:54 +01:00
committed by GitHub
4 changed files with 14 additions and 21 deletions

View File

@@ -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",

View File

@@ -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,
},
];

View File

@@ -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,
};
}

View File

@@ -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
);