-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(static-sharding): filter peer connections per shards (#1626)
* add interface for `ShardInfo` * enr: add deserialization logic & setup getters * add sharding related utils * utils: add shard<-> bytes conversion helpers * pass `pubSubTopics` to `Waku` * add `rs`/`rsv` details during discovery * connection-manager: discard irrelevant peers * add tests for static sharding - peer exchange * update `ConnectionManager` tests to account for topic validity * add js suffix to import * address some comments * move shardInfo encoding to ENR * test: update for new API * enr: add tests for serialisation & deserialisation * address comment * update test * move getPeershardInfo to ConnectionManager and return ShardInfo instead of bytes * update encoding and decoding relay shards to also factor for shards>64 * relay shard encoding decoding: use DataView and verbose spec tests * improve tests for relay shard encoding decoding * rm: only * improve log message for unconfigured pubsub topic * minor improvement * fix: buffer <> Uint8array problems with shard decoding * fix: test * rm: only
- Loading branch information
1 parent
fe64da1
commit 124a29e
Showing
18 changed files
with
480 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,68 @@ | ||
import { expect } from "chai"; | ||
import fc from "fast-check"; | ||
|
||
import { decodeRelayShard, encodeRelayShard } from "./relay_shard_codec.js"; | ||
|
||
describe("Relay Shard codec", () => { | ||
// Boundary test case | ||
it("should handle a minimal index list", () => { | ||
const shardInfo = { cluster: 0, indexList: [0] }; | ||
const encoded = encodeRelayShard(shardInfo); | ||
const decoded = decodeRelayShard(encoded); | ||
expect(decoded).to.deep.equal( | ||
shardInfo, | ||
"Decoded shard info does not match the original for minimal index list" | ||
); | ||
}); | ||
|
||
// Property-based test for rs format (Index List) | ||
it("should correctly encode and decode relay shards using rs format (Index List)", () => { | ||
fc.assert( | ||
fc.property( | ||
fc.nat(65535), // cluster | ||
fc | ||
.array(fc.nat(1023), { minLength: 1, maxLength: 63 }) // indexList | ||
.map((arr) => [...new Set(arr)].sort((a, b) => a - b)), | ||
(cluster, indexList) => { | ||
const shardInfo = { cluster, indexList }; | ||
const encoded = encodeRelayShard(shardInfo); | ||
const decoded = decodeRelayShard(encoded); | ||
|
||
expect(decoded).to.deep.equal( | ||
shardInfo, | ||
"Decoded shard info does not match the original for rs format" | ||
); | ||
} | ||
) | ||
); | ||
}); | ||
|
||
// Property-based test for rsv format (Bit Vector) | ||
it("should correctly encode and decode relay shards using rsv format (Bit Vector)", () => { | ||
fc.assert( | ||
fc.property( | ||
fc.nat(65535), // cluster | ||
fc | ||
.array(fc.nat(1023), { minLength: 64, maxLength: 1024 }) // indexList | ||
.map((arr) => [...new Set(arr)].sort((a, b) => a - b)), | ||
(cluster, indexList) => { | ||
const shardInfo = { cluster, indexList }; | ||
const encoded = encodeRelayShard(shardInfo); | ||
const decoded = decodeRelayShard(encoded); | ||
|
||
expect(decoded).to.deep.equal( | ||
shardInfo, | ||
"Decoded shard info does not match the original for rsv format" | ||
); | ||
} | ||
) | ||
); | ||
}); | ||
|
||
// Error handling test case | ||
it("should throw an error for insufficient data", () => { | ||
expect(() => decodeRelayShard(new Uint8Array([0, 0]))).to.throw( | ||
"Insufficient data" | ||
); | ||
}); | ||
}); |
Oops, something went wrong.