Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sds): add retrieval hint to causal history #2299

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 75 additions & 3 deletions packages/proto/src/generated/sds_message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,81 @@
import { type Codec, decodeMessage, type DecodeOptions, encodeMessage, MaxLengthError, message } from 'protons-runtime'
import type { Uint8ArrayList } from 'uint8arraylist'

export interface HistoryEntry {
messageId: string
retrievalHint?: Uint8Array
}

export namespace HistoryEntry {
let _codec: Codec<HistoryEntry>

export const codec = (): Codec<HistoryEntry> => {
if (_codec == null) {
_codec = message<HistoryEntry>((obj, w, opts = {}) => {
if (opts.lengthDelimited !== false) {
w.fork()
}

if ((obj.messageId != null && obj.messageId !== '')) {
w.uint32(10)
w.string(obj.messageId)
}

if (obj.retrievalHint != null) {
w.uint32(18)
w.bytes(obj.retrievalHint)
}

if (opts.lengthDelimited !== false) {
w.ldelim()
}
}, (reader, length, opts = {}) => {
const obj: any = {
messageId: ''
}

const end = length == null ? reader.len : reader.pos + length

while (reader.pos < end) {
const tag = reader.uint32()

switch (tag >>> 3) {
case 1: {
obj.messageId = reader.string()
break
}
case 2: {
obj.retrievalHint = reader.bytes()
break
}
default: {
reader.skipType(tag & 7)
break
}
}
}

return obj
})
}

return _codec
}

export const encode = (obj: Partial<HistoryEntry>): Uint8Array => {
return encodeMessage(obj, HistoryEntry.codec())
}

export const decode = (buf: Uint8Array | Uint8ArrayList, opts?: DecodeOptions<HistoryEntry>): HistoryEntry => {
return decodeMessage(buf, HistoryEntry.codec(), opts)
}
}

export interface SdsMessage {
messageId: string
channelId: string
lamportTimestamp?: number
causalHistory: string[]
causalHistory: HistoryEntry[]
bloomFilter?: Uint8Array
content?: Uint8Array
}
Expand Down Expand Up @@ -44,7 +114,7 @@ export namespace SdsMessage {
if (obj.causalHistory != null) {
for (const value of obj.causalHistory) {
w.uint32(90)
w.string(value)
HistoryEntry.codec().encode(value, w)
}
}

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

obj.causalHistory.push(reader.string())
obj.causalHistory.push(HistoryEntry.codec().decode(reader, reader.uint32(), {
limits: opts.limits?.causalHistory$
}))
break
}
case 12: {
Expand Down
7 changes: 6 additions & 1 deletion packages/proto/src/lib/sds_message.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
syntax = "proto3";

message HistoryEntry {
string message_id = 1; // Unique identifier of the SDS message, as defined in `Message`
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
}

message SdsMessage {
// 1 Reserved for sender/participant id
string message_id = 2; // Unique identifier of the message
string channel_id = 3; // Identifier of the channel to which the message belongs
optional int32 lamport_timestamp = 10; // Logical timestamp for causal ordering in channel
repeated string causal_history = 11; // List of preceding message IDs that this message causally depends on. Generally 2 or 3 message IDs are included.
repeated HistoryEntry causal_history = 11; // List of preceding message IDs that this message causally depends on. Generally 2 or 3 message IDs are included.
optional bytes bloom_filter = 12; // Bloom filter representing received message IDs in channel
optional bytes content = 20; // Actual content of the message
}
1 change: 1 addition & 0 deletions packages/sds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"node": ">=20"
},
"dependencies": {
"@libp2p/interface": "^2.7.0",
"@noble/hashes": "^1.7.1",
"@waku/message-hash": "^0.1.17",
"@waku/proto": "^0.0.8",
Expand Down
Loading
Loading