feat(state): Update Proposal with BlobID#7
Conversation
Regenerated the proto files as well. Moved the proto definition of `BlobID` to the `types.proto` file to fix an import cycle.
Since `BlobID` is not used in the consensus logic yet, this change is harmless. However, it allows us to keep this PR focused solely on `Proposal`-related changes. In a future PR, we’ll handle the proper creation of `BlobID` by implementing blob splitting into multiple parts. Additionally, this PR includes a refactor for improved readability.
The `Proposal` sub-test was using an incorrect hex string to check the test's results. The string changed because we added the `BlobID` field to the `Proposal` type, thus changing its encoding to protobuf. Also rearrenged the code for better readability.
It was using an incorrect hex string to check the test's results. The string changed because we added the `BlobID` field to the `Proposal` type, thus changing its encoding to protobuf. Also rearrenged the code for better readability.
The sub-tests "Proposal Request", "Proposal Response", and "Proposal Response with error" were was using an incorrect hex string to check the test's results. The string changed because we added the `BlobID` field to the `Proposal` type, thus changing its encoding to protobuf. Also rearrenged the code for better readability.
|
The linter is failing, but that's not a real problem. |
| p.POLRound = pp.PolRound // FIXME: names do not match | ||
| p.Timestamp = pp.Timestamp | ||
| p.Signature = pp.Signature | ||
| blobID, err := BlobIDFromProto(&pp.BlobID) |
There was a problem hiding this comment.
Same as above, should we be checking if it is nil (maybe the check is performed inside BlobIDFromProto? ) ?
There was a problem hiding this comment.
yes, BlobIDFromProto checks if the given argument is nil and returns an error if it is.
There was a problem hiding this comment.
But can we not have a valid scenario where the blobID is nil (no blob in this proposal) and therefore it is ok that this is nil ? It should just be properly marshalled somehow.
There was a problem hiding this comment.
The BlobID field in the Proposal struct is a concrete type, not a pointer. Therefore, it can't be nil. Similarly, the BlobID field of the
the ToProto() and FromProto() methods of type BlobID return a concrete type, not a pointer. So I don't see how it could be set to nil.
If this is not supposed to be part of this PR, I would remove it from the description |
melekes
left a comment
There was a problem hiding this comment.
LGTM minus comments from Jasmina
I was thinking whether to include this change or not in this PR 🤔 |
Rationale: If a block has an associated blob, we set the `BlobID` in `Proposal` after returning from `PrepareProposal()`, causing the `IsNil()` check to return false. If the block does not have a blob, the `BlobID` field in `Proposal` will remain its zero value, making `IsNil()` return true. If a blob is present, `cs.ProposalBlob.IsNil()` will always return true until `cs.ProposalBlob` is assigned a non-empty `[]byte` slice. This assignment happens only after we have received all the blob parts and we have successfully reconstructed the blob.
Update, I pushed the change in this PR. See the last commit. |
| // wait for the blob before marking the proposal as complete. | ||
| if !cs.Proposal.BlobID.IsNil() { | ||
| return !cs.ProposalBlob.IsNil() | ||
| } |
There was a problem hiding this comment.
Rationale: If a block has an associated blob, we set the BlobID in Proposal
after returning from PrepareProposal(), causing the IsNil() check to
return false. If the block does not have a blob, the BlobID field in
Proposal will remain its zero value, making IsNil() return true.
If a blob is present, cs.ProposalBlob.IsNil() will always return true until
cs.ProposalBlob is assigned a non-empty []byte slice. This assignment
happens only after we have received all the blob parts and we have successfully
reconstructed the blob.
Part of the work of berachain#26.
Context
A
Proposalrepresents a block proposal that peers vote on during consensus. To be valid, it must be signed by the correct proposer for the given height and round.A
Proposalincludes aBlockID, which uniquely identifies the proposed block. ThisBlockIDcontains the Merkle root hash of the block’s parts, ensuring integrity as the block is split and gossiped across the network.Since blocks can now have an associated blob, we introduce a unique identifier for the blob in the
Proposalstruct. This allows peers to correctly associate a blob with its corresponding block during gossip. Additionally, because theProposalis signed, this prevents malicious actors from altering or replacing the blob linked to a specific block.Changes
This PR extends the
Proposalstruct and its methods with aBlobIDfield.