Skip to content

Commit 4da382d

Browse files
authored
Merge pull request #2299 from waku-org/feat/sds-message-history
feat(sds): add retrieval hint to causal history
2 parents 18e08f9 + 408be95 commit 4da382d

File tree

6 files changed

+165
-64
lines changed

6 files changed

+165
-64
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/proto/src/generated/sds_message.ts

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,81 @@
77
import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime'
88
import type { Uint8ArrayList } from 'uint8arraylist'
99

10+
export interface HistoryEntry {
11+
messageId: string
12+
retrievalHint?: Uint8Array
13+
}
14+
15+
export namespace HistoryEntry {
16+
let _codec: Codec<HistoryEntry>
17+
18+
export const codec = (): Codec<HistoryEntry> => {
19+
if (_codec == null) {
20+
_codec = message<HistoryEntry>((obj, w, opts = {}) => {
21+
if (opts.lengthDelimited !== false) {
22+
w.fork()
23+
}
24+
25+
if ((obj.messageId != null && obj.messageId !== '')) {
26+
w.uint32(10)
27+
w.string(obj.messageId)
28+
}
29+
30+
if (obj.retrievalHint != null) {
31+
w.uint32(18)
32+
w.bytes(obj.retrievalHint)
33+
}
34+
35+
if (opts.lengthDelimited !== false) {
36+
w.ldelim()
37+
}
38+
}, (reader, length, opts = {}) => {
39+
const obj: any = {
40+
messageId: ''
41+
}
42+
43+
const end = length == null ? reader.len : reader.pos + length
44+
45+
while (reader.pos < end) {
46+
const tag = reader.uint32()
47+
48+
switch (tag >>> 3) {
49+
case 1: {
50+
obj.messageId = reader.string()
51+
break
52+
}
53+
case 2: {
54+
obj.retrievalHint = reader.bytes()
55+
break
56+
}
57+
default: {
58+
reader.skipType(tag & 7)
59+
break
60+
}
61+
}
62+
}
63+
64+
return obj
65+
})
66+
}
67+
68+
return _codec
69+
}
70+
71+
export const encode = (obj: Partial<HistoryEntry>): Uint8Array => {
72+
return encodeMessage(obj, HistoryEntry.codec())
73+
}
74+
75+
export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<HistoryEntry>): HistoryEntry => {
76+
return decodeMessage(buf, HistoryEntry.codec(), opts)
77+
}
78+
}
79+
1080
export interface SdsMessage {
1181
messageId: string
1282
channelId: string
1383
lamportTimestamp?: number
14-
causalHistory: string[]
84+
causalHistory: HistoryEntry[]
1585
bloomFilter?: Uint8Array
1686
content?: Uint8Array
1787
}
@@ -44,7 +114,7 @@ export namespace SdsMessage {
44114
if (obj.causalHistory != null) {
45115
for (const value of obj.causalHistory) {
46116
w.uint32(90)
47-
w.string(value)
117+
HistoryEntry.codec().encode(value, w)
48118
}
49119
}
50120

@@ -91,7 +161,9 @@ export namespace SdsMessage {
91161
throw new MaxLengthError('Decode error - map field "causalHistory" had too many elements')
92162
}
93163

94-
obj.causalHistory.push(reader.string())
164+
obj.causalHistory.push(HistoryEntry.codec().decode(reader, reader.uint32(), {
165+
limits: opts.limits?.causalHistory$
166+
}))
95167
break
96168
}
97169
case 12: {
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
syntax = "proto3";
22

3+
message HistoryEntry {
4+
string message_id = 1; // Unique identifier of the SDS message, as defined in `Message`
5+
optional bytes retrieval_hint = 2; // Optional information to help remote parties retrieve this SDS message; For example, A Waku deterministic message hash or routing payload hash
6+
}
7+
38
message SdsMessage {
49
// 1 Reserved for sender/participant id
510
string message_id = 2; // Unique identifier of the message
611
string channel_id = 3; // Identifier of the channel to which the message belongs
712
optional int32 lamport_timestamp = 10; // Logical timestamp for causal ordering in channel
8-
repeated string causal_history = 11; // List of preceding message IDs that this message causally depends on. Generally 2 or 3 message IDs are included.
13+
repeated HistoryEntry causal_history = 11; // List of preceding message IDs that this message causally depends on. Generally 2 or 3 message IDs are included.
914
optional bytes bloom_filter = 12; // Bloom filter representing received message IDs in channel
1015
optional bytes content = 20; // Actual content of the message
1116
}

packages/sds/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"node": ">=20"
6060
},
6161
"dependencies": {
62-
"@libp2p/interface": "^2.7.0",
62+
"@libp2p/interface": "2.7.0",
6363
"@noble/hashes": "^1.7.1",
6464
"@waku/message-hash": "^0.1.18",
6565
"@waku/proto": "^0.0.9",

0 commit comments

Comments
 (0)