-
-
Notifications
You must be signed in to change notification settings - Fork 428
Description
Problem description
Right now lodestar couples with PublicKey and Signature classes generated by napi-rs @chainsafe/blst. This is not great when we integrate lodestar-z where it uses blst-z there and we may end up 2 blst implementations in the same application
The reason we have to track those classes in lodestar is because rust binding of blst always want PublicKey or Signature instances. But in lodestar, the vast majority of signature sets are verified on worker thread, it means some inefficiencies here: serialize() pubkeys on the main thread, deserialize() pubkeys and signatures on worker threads on NodeJS, then pass to native
Solution description
Track pubkeys and signatures as Uint8Array in NodeJS so that we don't have to serialize() and deserialize() passing through worker boundary, native layers have to deserialize them. This is better for performance (will post later) and provides a way to use bls implementation when we switch to lodestar-z
Additional context
- for non-aggregated validatorpubkey, we can maintain a List of pubkeys in native layer so that we don't have to deserialize there
- for aggregated pubkey, we can use a
Map<Uint8Array, PublicKey>at native layer to skip deserializing pubkeys there: cache them on the main thread and lookup/delete on the worker thread. This is optional though, on-the-flight deserialization is already faster than the current flow (see benchmark below)