-
Notifications
You must be signed in to change notification settings - Fork 45
feat: update light push to match v3 spec #2404
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,6 @@ packages/discovery/mock_local_storage | |
.giga | ||
.cursor | ||
.DS_Store | ||
CLAUDE.md | ||
CLAUDE.md | ||
packages/discovery/scratch/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
export { LightPushCore, LightPushCodec, PushResponse } from "./light_push.js"; | ||
export { | ||
LightPushCore, | ||
LightPushCodec, | ||
LightPushCoreV2, | ||
LightPushCodecV2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's not add aliases |
||
PushResponse | ||
} from "./light_push.js"; | ||
|
||
export { LightPushCoreV3 } from "./light_push_v3.js"; | ||
export { PushRpcV3 } from "./push_rpc_v3.js"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the point of importing |
||
export { | ||
lightPushStatusCodeToProtocolErrorV3, | ||
lightPushStatusDescriptionsV3, | ||
getLightPushStatusDescriptionV3 | ||
} from "./status_codes_v3.js"; | ||
export { | ||
LightPushStatusCode, | ||
lightPushStatusCodeToProtocolError, | ||
lightPushStatusDescriptions, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this needs to be exported? I assume this mapping is internal for LigthPushCore and LigthPushSDK just accepts response There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same other methods let's not pollute our export space with not needed stuff |
||
getLightPushStatusDescription, | ||
isSuccessStatusCode | ||
} from "./status_codes.js"; |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,14 +1,14 @@ | ||||
import type { PeerId, Stream } from "@libp2p/interface"; | ||||
import { | ||||
type CoreProtocolResult, | ||||
type CoreProtocolResultWithMeta, | ||||
type IEncoder, | ||||
type IMessage, | ||||
type Libp2p, | ||||
ProtocolError, | ||||
PubsubTopic, | ||||
type ThisOrThat | ||||
} from "@waku/interfaces"; | ||||
import { PushResponse } from "@waku/proto"; | ||||
import { proto_lightpush_v2, PushResponse } from "@waku/proto"; | ||||
import { isMessageSizeUnderCap } from "@waku/utils"; | ||||
import { Logger } from "@waku/utils"; | ||||
import all from "it-all"; | ||||
|
@@ -18,19 +18,17 @@ import { Uint8ArrayList } from "uint8arraylist"; | |||
|
||||
import { StreamManager } from "../stream_manager/index.js"; | ||||
|
||||
import { PushRpc } from "./push_rpc.js"; | ||||
import { isRLNResponseError } from "./utils.js"; | ||||
import { PushRpcV2 } from "./push_rpc_v2.js"; | ||||
import { mapInfoToProtocolError } from "./utils.js"; | ||||
|
||||
const log = new Logger("light-push"); | ||||
|
||||
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1"; | ||||
export { PushResponse }; | ||||
|
||||
type PreparePushMessageResult = ThisOrThat<"query", PushRpc>; | ||||
export const LightPushCodecV2 = LightPushCodec; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||||
|
||||
type PreparePushMessageResult = ThisOrThat<"query", PushRpcV2>; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it doesn't seem to be used at all
Suggested change
|
||||
|
||||
/** | ||||
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/). | ||||
*/ | ||||
export class LightPushCore { | ||||
private readonly streamManager: StreamManager; | ||||
|
||||
|
@@ -67,7 +65,7 @@ export class LightPushCore { | |||
}; | ||||
} | ||||
|
||||
const query = PushRpc.createRequest(protoMessage, encoder.pubsubTopic); | ||||
const query = PushRpcV2.createRequest(protoMessage, encoder.pubsubTopic); | ||||
return { query, error: null }; | ||||
} catch (error) { | ||||
log.error("Failed to prepare push message", error); | ||||
|
@@ -83,7 +81,7 @@ export class LightPushCore { | |||
encoder: IEncoder, | ||||
message: IMessage, | ||||
peerId: PeerId | ||||
): Promise<CoreProtocolResult> { | ||||
): Promise<CoreProtocolResultWithMeta> { | ||||
const { query, error: preparationError } = await this.preparePushMessage( | ||||
encoder, | ||||
message | ||||
|
@@ -95,7 +93,8 @@ export class LightPushCore { | |||
failure: { | ||||
error: preparationError, | ||||
peerId | ||||
} | ||||
}, | ||||
protocolUsed: LightPushCodec | ||||
}; | ||||
} | ||||
|
||||
|
@@ -109,7 +108,8 @@ export class LightPushCore { | |||
failure: { | ||||
error: ProtocolError.NO_STREAM_AVAILABLE, | ||||
peerId: peerId | ||||
} | ||||
}, | ||||
protocolUsed: LightPushCodec | ||||
}; | ||||
} | ||||
|
||||
|
@@ -123,14 +123,14 @@ export class LightPushCore { | |||
async (source) => await all(source) | ||||
); | ||||
} catch (err) { | ||||
// can fail only because of `stream` abortion | ||||
log.error("Failed to send waku light push request", err); | ||||
return { | ||||
success: null, | ||||
failure: { | ||||
error: ProtocolError.STREAM_ABORTED, | ||||
peerId: peerId | ||||
} | ||||
}, | ||||
protocolUsed: LightPushCodec | ||||
}; | ||||
} | ||||
|
||||
|
@@ -139,17 +139,18 @@ export class LightPushCore { | |||
bytes.append(chunk); | ||||
}); | ||||
|
||||
let response: PushResponse | undefined; | ||||
let response: proto_lightpush_v2.PushResponse | undefined; | ||||
try { | ||||
response = PushRpc.decode(bytes).response; | ||||
response = PushRpcV2.decode(bytes).response; | ||||
} catch (err) { | ||||
log.error("Failed to decode push reply", err); | ||||
return { | ||||
success: null, | ||||
failure: { | ||||
error: ProtocolError.DECODE_FAILED, | ||||
peerId: peerId | ||||
} | ||||
}, | ||||
protocolUsed: LightPushCodec | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is it added? let's remove it as |
||||
}; | ||||
} | ||||
|
||||
|
@@ -160,32 +161,35 @@ export class LightPushCore { | |||
failure: { | ||||
error: ProtocolError.NO_RESPONSE, | ||||
peerId: peerId | ||||
} | ||||
}; | ||||
} | ||||
|
||||
if (isRLNResponseError(response.info)) { | ||||
log.error("Remote peer fault: RLN generation"); | ||||
return { | ||||
success: null, | ||||
failure: { | ||||
error: ProtocolError.RLN_PROOF_GENERATION, | ||||
peerId: peerId | ||||
} | ||||
}, | ||||
protocolUsed: LightPushCodec | ||||
}; | ||||
} | ||||
|
||||
if (!response.isSuccess) { | ||||
log.error("Remote peer rejected the message: ", response.info); | ||||
const errorMessage = response.info || "Message rejected"; | ||||
log.error("Remote peer rejected the message: ", errorMessage); | ||||
|
||||
// Use pattern matching to determine the appropriate error type | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
const error = mapInfoToProtocolError(response.info); | ||||
|
||||
return { | ||||
success: null, | ||||
failure: { | ||||
error: ProtocolError.REMOTE_PEER_REJECTED, | ||||
error: error, | ||||
peerId: peerId | ||||
} | ||||
}, | ||||
protocolUsed: LightPushCodec | ||||
}; | ||||
} | ||||
|
||||
return { success: peerId, failure: null }; | ||||
return { | ||||
success: peerId, | ||||
failure: null, | ||||
protocolUsed: LightPushCodec | ||||
}; | ||||
} | ||||
} | ||||
|
||||
export const LightPushCoreV2 = LightPushCore; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also not really needed to introduce another alias export |
||||
export { PushResponse }; |
Uh oh!
There was an error while loading. Please reload this page.