-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Light client consensus types #14512
Light client consensus types #14512
Conversation
header interfaces.LightClientHeader | ||
currentSyncCommitteeBranch interfaces.LightClientSyncCommitteeBranch |
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.
I added fields for object that would have to be re-created every time the getter is called. That's one pointer to a wrapper with one pointer field for each header, and at most 6*32 bytes
for branches.
if len(p.CurrentSyncCommitteeBranch) != interfaces.SyncCommitteeBranchNumOfLeaves { | ||
return nil, fmt.Errorf( | ||
"sync committee branch has %d leaves instead of expected %d", | ||
len(p.CurrentSyncCommitteeBranch), | ||
interfaces.SyncCommitteeBranchNumOfLeaves, | ||
) | ||
} | ||
branch := interfaces.LightClientSyncCommitteeBranch{} | ||
for i, leaf := range p.CurrentSyncCommitteeBranch { | ||
if len(leaf) != fieldparams.RootLength { | ||
return nil, fmt.Errorf("sync committee branch leaf at index %d has length %d instead of expected %d", i, len(leaf), fieldparams.RootLength) | ||
} | ||
branch[i] = bytesutil.ToBytes32(leaf) | ||
} |
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.
This pattern appears many times, I will de-duplicate it in a future commit
ExecutionBranchNumOfLeaves = 4 | ||
SyncCommitteeBranchNumOfLeaves = 5 | ||
FinalityBranchNumOfLeaves = 6 |
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.
I should probably move this to fieldparams
, rename NumOfLeaves
to Depth
and rename SyncCommitteeBranch
to NextSyncCommitteeBranch
for clarity.
@@ -33,7 +33,9 @@ const ( | |||
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen | |||
BlobSidecarSize = 131928 // defined to match blob sidecar size in bazel ssz codegen | |||
KzgCommitmentInclusionProofDepth = 17 // Merkle proof depth for blob_kzg_commitments list item | |||
NextSyncCommitteeBranchDepth = 5 // NextSyncCommitteeBranchDepth defines the depth of the next sync committee branch. | |||
ExecutionBranchDepth = 4 // ExecutionBranchDepth defines the number of leaves in a merkle proof of the execution payload header. | |||
SyncCommitteeBranchDepth = 5 // SyncCommitteeBranchDepth defines the number of leaves in a merkle proof of a sync committee. |
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.
The spec defines a CurrentSyncCommitteeBranch
and NextSyncCommitteeBranch
, but since the depth is the same, we might as well keep one variable. Even if we defined two separate types in the interfaces package, they would both alias [5][32]byte
and thus would be assignable to each other, so compiler won't catch slip-ups.
Closing in favor of #14518 |
What type of PR is this?
Other
What does this PR do? Why is it needed?
This PR creates a foundation for changing how we interact with light client types in the codebase. Currently we use protobuf-generated objects everywhere, but this has some problems:
LightClientHeader
is defined using aoneof
, which makes it impossible to generate SSZ for this type or any type referencing the header. Without this, we can't return SSZ-serialized objects from the Beacon API.This PR's design is largely influenced by https://github.com/prysmaticlabs/prysm/blob/develop/consensus-types/blocks/execution.go. Main components:
v1alpha1
with one type per fork instead of using aoneof
. The reason for having them inv1alpha1
is that it is the default directory for protobuf definitions. Theeth/v1
andeth/v2
directories are an artifact of some previous work and should be removed ultimately.ssz.Marshaler
interface:LightClientHeader
LightClientBootstrap
LightClientUpdate
LightClientFinalityUpdate
LightClientOptimisticUpdate
Which issues(s) does this PR fix?
Part of #12991
Acknowledgements