-
-
Notifications
You must be signed in to change notification settings - Fork 291
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
Snappy frame encode big payloads as chunks as per the standard #3912
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4d8d055
Snappy frame encode big payloads as chunks as per standard
g11tech 42b1761
cleanup comments
g11tech d7c767c
moving the chunking upstream
g11tech 85202ac
upgrade to the new snappy steam version supporting stream chunking
g11tech 2d98f69
switch to async version to match the chunks
g11tech 105300e
fixing the uncompress test
g11tech a2895f4
update the package fix
g11tech 3f5114e
shift to sync compress version as it is almost 2x faster
g11tech 0652fdb
update comment
g11tech 66f1c3f
lint
g11tech 23b0882
flip async and sync chunks
g11tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...es/lodestar/test/unit-mainnet/network/reqresp/encodingStrategies/sszSnappy/decode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import chai, {expect} from "chai"; | ||
import chaiAsPromised from "chai-as-promised"; | ||
import varint from "varint"; | ||
import {BufferedSource} from "../../../../../../src/network/reqresp/utils"; | ||
import {readSszSnappyPayload} from "../../../../../../src/network/reqresp/encodingStrategies/sszSnappy"; | ||
import {isEqualSszType} from "../../../../../utils/ssz"; | ||
import {arrToSource} from "../../../../../../test/unit/network/reqresp/utils"; | ||
import {goerliShadowForkBlock13249} from "./testData"; | ||
|
||
chai.use(chaiAsPromised); | ||
|
||
describe("network / reqresp / sszSnappy / decode", () => { | ||
describe("Test data vectors (generated in a previous version)", () => { | ||
const testCases = [goerliShadowForkBlock13249]; | ||
|
||
for (const {id, type, bytes, streamedBody, body} of testCases) { | ||
const deserializedBody = body ?? type.deserialize(Buffer.from(bytes)); | ||
const streamedBytes = Buffer.concat([Buffer.from(varint.encode(bytes.length)), streamedBody]); | ||
|
||
it(id, async () => { | ||
const bufferedSource = new BufferedSource(arrToSource([streamedBytes])); | ||
const bodyResult = await readSszSnappyPayload(bufferedSource, type); | ||
expect(isEqualSszType(type, bodyResult, deserializedBody)).to.equal(true, "Wrong decoded body"); | ||
}); | ||
} | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...es/lodestar/test/unit-mainnet/network/reqresp/encodingStrategies/sszSnappy/encode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import all from "it-all"; | ||
import pipe from "it-pipe"; | ||
import {expect} from "chai"; | ||
import varint from "varint"; | ||
|
||
import {allForks, ssz} from "@chainsafe/lodestar-types"; | ||
|
||
import {reqRespBlockResponseSerializer} from "../../../../../../src/network/reqresp/types"; | ||
import {writeSszSnappyPayload} from "../../../../../../src/network/reqresp/encodingStrategies/sszSnappy"; | ||
import {goerliShadowForkBlock13249} from "./testData"; | ||
import {RequestOrOutgoingResponseBody} from "../../../../../../src/network/reqresp/types"; | ||
|
||
describe("network / reqresp / sszSnappy / encode", () => { | ||
describe("Test data vectors (generated in a previous version)", () => { | ||
const testCases = [goerliShadowForkBlock13249]; | ||
|
||
for (const testCase of testCases) { | ||
const {id, type, bytes, streamedBody, body} = testCase; | ||
const deserializedBody = body ?? type.deserialize(Buffer.from(bytes)); | ||
const reqrespBody = | ||
body ?? | ||
(type === ssz.bellatrix.SignedBeaconBlock | ||
? {slot: (deserializedBody as allForks.SignedBeaconBlock).message.slot, bytes} | ||
: deserializedBody); | ||
|
||
it(id, async () => { | ||
const encodedChunks = await pipe( | ||
writeSszSnappyPayload(reqrespBody as RequestOrOutgoingResponseBody, reqRespBlockResponseSerializer), | ||
all | ||
); | ||
const encodedStream = Buffer.concat(encodedChunks); | ||
const expectedStreamed = Buffer.concat([Buffer.from(varint.encode(bytes.length)), streamedBody]); | ||
expect(encodedStream).to.be.deep.equal(expectedStreamed); | ||
}); | ||
} | ||
}); | ||
}); |
Binary file added
BIN
+136 KB
...t/network/reqresp/encodingStrategies/sszSnappy/goerliShadowForkBlock.13249/serialized.ssz
Binary file not shown.
Binary file added
BIN
+51.1 KB
.../network/reqresp/encodingStrategies/sszSnappy/goerliShadowForkBlock.13249/streamed.snappy
Binary file not shown.
25 changes: 25 additions & 0 deletions
25
packages/lodestar/test/unit-mainnet/network/reqresp/encodingStrategies/sszSnappy/testData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
import {bellatrix, ssz} from "@chainsafe/lodestar-types"; | ||
import {RequestOrIncomingResponseBody, RequestOrResponseType} from "../../../../../../src/network/reqresp/types"; | ||
|
||
export interface ISszSnappyTestBlockData<T extends RequestOrIncomingResponseBody> { | ||
id: string; | ||
type: RequestOrResponseType; | ||
bytes: Buffer; | ||
streamedBody: Buffer; | ||
body?: T; | ||
} | ||
|
||
/** | ||
* A real big bellatrix block from goerli-shadow-fork-2 devnet, which is expected to be | ||
* encoded in multiple chunks. | ||
*/ | ||
|
||
export const goerliShadowForkBlock13249: ISszSnappyTestBlockData<bellatrix.SignedBeaconBlock> = { | ||
id: "goerli-shadow-fork-block-13249", | ||
type: ssz.bellatrix.SignedBeaconBlock, | ||
bytes: fs.readFileSync(path.join(__dirname, "/goerliShadowForkBlock.13249/serialized.ssz")), | ||
streamedBody: fs.readFileSync(path.join(__dirname, "/goerliShadowForkBlock.13249/streamed.snappy")), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for adding a nice reasoning comment! ❤️