Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[narwhal] swap PublicKey usage with index approach (MystenLabs#9576)
## Description Resolves: MystenLabs#9348 Given the latest findings that dictate significant serialisation/deserialisation cost for Narwhal entities (Certificate, Header etc) that bear `PublicKey` values (as the EC point conversions appear to be costly) , this PR is swapping the use of them with something much more lightweight that will still allow us to deterministically identify the authorities. Basically wherever we would use a `PublicKey` we instead use an `AuthorityIdentifier` . This uniquely identifies an authority but is cheap is terms of ser/des. For the Narwhal purposes we chose `u16` for this type which is large enough to identify the authorities in our network , but also small an simple enough to serialisation costs. As this is a quite large PR (although mostly swap changes have taken place - not much of new functionality) I would advise to look first at: * The Committee changes . It has been extracted from the `narwhal/config/src/lib.rs` and is now on an independent file [narwhal/config/src/committee.rs](https://github.com/MystenLabs/sui/pull/9576/files#r1144796971). I've made both the `Authority` and `Committee` properties `private` and now everything should be accessed via public methods. This was a conscious decision to ensure safety since some values of both Authority and Committee get initialised after construction. * Introduced the [CommitteeBuilder](https://github.com/MystenLabs/sui/pull/9576/files#diff-bf39a5ebab429076e198116328c16f4d2d6176154e4d649250ff9cc00e93c8c3R406) which from now on should be the de-facto way of building a Committee. Again for safety reasons - to ensure that when a user accesses an Authority it will be properly initialised. * The [AuthorityIdentifier](https://github.com/MystenLabs/sui/pull/9576/files#diff-bf39a5ebab429076e198116328c16f4d2d6176154e4d649250ff9cc00e93c8c3R143) is chosen to be a simple `u16` value. We follow the natural sorting of the `PublicKey` to assign the corresponding incremental id value. It has to be noted that the implementation is generic enough, so if we need in the future to change the type we can easily do without touching any other part of the code (ex making the `AuthorityIdentifier = AuthorityPublicKeyBytes` - it would just work). It's easy-peasy to derive the authority's details by just querying the [committee](https://github.com/MystenLabs/sui/pull/9576/files#diff-bf39a5ebab429076e198116328c16f4d2d6176154e4d649250ff9cc00e93c8c3R160) by whatever identifier we have defined. * I've deliberately not touched the `WorkerCache` where we still identify the workers by the authority's `PublicKey` - to note that there is not conversion taken place here - I might address as separate PR to ensure uniformity, avoided doing for now to reduce the scope of the PR * I've done a small refactoring on the way we used the `name` before - now we are using the term `authority_id` to decouple the semantics (feedback is needed here). Also in some places , like the [primary.rs](https://github.com/MystenLabs/sui/pull/9576/files#diff-ea7fbf16c23e1a2466afa04456a57c35115d6b406eb2897821be4bfc83673a3aR102) , [worker.rs](https://github.com/MystenLabs/sui/pull/9576/files#diff-6fec58b362511100ea42543a8030e7f11bbc476202f47ebd9589ef690463cc32R54) I am now passing "our" whole `Authority` object which bears the full set of details - so we have access to variety of properties and we can easily derive things like the authority's `id` , or `public_key` etc. We could keep this as a practice across our narwhal codebase instead of just injecting the `id` - no additional cost here. * Things might be a bit ugly on the interface with SUI ([authority_scoring](https://github.com/MystenLabs/sui/pull/9576/files#diff-3ed6074eee064ff17c26fa5b98012562d6f430beeb739cf93ed45d855bad246fR57) , [consensus_handler](https://github.com/MystenLabs/sui/pull/9576/files#diff-8ccde7467e1b7899685cdb5469dc530bc63b1945339660881ad1267287d4e2e7R204) as we need to do the necessary conversions by consulting the `narwhal Comittee` in order to translate the `AuthorityIdentifier` to the `AuthorityName` that SUI uses - but I tried to make things as nice as possible. ## Test Plan Updated all the existing unit & integration tests. --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [x] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information