-
Notifications
You must be signed in to change notification settings - Fork 431
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
Unified writer interface for Data Availability providers [NIT-1249] #2157
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3d2d427
Unified writer interface for Data Availability providers
ganeshvanahalli 9f10a93
resolve merge conflicts
ganeshvanahalli 6f08d8d
code refactor
ganeshvanahalli b6144fb
Merge branch 'master' into unified-daprovider-writer-interface
ganeshvanahalli 8c256b7
code refactor
ganeshvanahalli 26f3b80
address PR comments
ganeshvanahalli 7415458
resolve merge conflicts
ganeshvanahalli d3ffedc
address PR comments
ganeshvanahalli 3e1c15b
address PR comments and use reader interface in StatelessBlockValidator
ganeshvanahalli 00193d0
code refactor
ganeshvanahalli bae6788
code cleanup
ganeshvanahalli 37862dd
Merge branch 'master' into unified-daprovider-writer-interface
ganeshvanahalli d989692
merge master and resolve conflicts
ganeshvanahalli c6eb470
update geth pin
ganeshvanahalli 626c805
address PR comments
ganeshvanahalli b4c0aa1
merge master and resolve conflicts
ganeshvanahalli c92a15b
Merge branch 'master' into unified-daprovider-writer-interface
ganeshvanahalli 486d8a1
Merge branch 'master' into unified-daprovider-writer-interface
Tristan-Wilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,104 @@ | ||
// Copyright 2021-2022, Offchain Labs, Inc. | ||
// For license information, see https://github.com/nitro/blob/master/LICENSE | ||
|
||
package daprovider | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/offchainlabs/nitro/arbutil" | ||
"github.com/offchainlabs/nitro/util/blobs" | ||
) | ||
|
||
type Reader interface { | ||
// IsValidHeaderByte returns true if the given headerByte has bits corresponding to the DA provider | ||
IsValidHeaderByte(headerByte byte) bool | ||
|
||
// RecoverPayloadFromBatch fetches the underlying payload from the DA provider given the batch header information | ||
RecoverPayloadFromBatch( | ||
ctx context.Context, | ||
batchNum uint64, | ||
batchBlockHash common.Hash, | ||
sequencerMsg []byte, | ||
preimageRecorder PreimageRecorder, | ||
validateSeqMsg bool, | ||
) ([]byte, error) | ||
} | ||
|
||
// NewReaderForDAS is generally meant to be only used by nitro. | ||
// DA Providers should implement methods in the Reader interface independently | ||
func NewReaderForDAS(dasReader DASReader) *readerForDAS { | ||
return &readerForDAS{dasReader: dasReader} | ||
} | ||
|
||
type readerForDAS struct { | ||
dasReader DASReader | ||
} | ||
|
||
func (d *readerForDAS) IsValidHeaderByte(headerByte byte) bool { | ||
return IsDASMessageHeaderByte(headerByte) | ||
} | ||
|
||
func (d *readerForDAS) RecoverPayloadFromBatch( | ||
ctx context.Context, | ||
batchNum uint64, | ||
batchBlockHash common.Hash, | ||
sequencerMsg []byte, | ||
preimageRecorder PreimageRecorder, | ||
validateSeqMsg bool, | ||
) ([]byte, error) { | ||
return RecoverPayloadFromDasBatch(ctx, batchNum, sequencerMsg, d.dasReader, preimageRecorder, validateSeqMsg) | ||
} | ||
|
||
// NewReaderForBlobReader is generally meant to be only used by nitro. | ||
// DA Providers should implement methods in the Reader interface independently | ||
func NewReaderForBlobReader(blobReader BlobReader) *readerForBlobReader { | ||
return &readerForBlobReader{blobReader: blobReader} | ||
} | ||
|
||
type readerForBlobReader struct { | ||
blobReader BlobReader | ||
} | ||
|
||
func (b *readerForBlobReader) IsValidHeaderByte(headerByte byte) bool { | ||
return IsBlobHashesHeaderByte(headerByte) | ||
} | ||
|
||
func (b *readerForBlobReader) RecoverPayloadFromBatch( | ||
ctx context.Context, | ||
batchNum uint64, | ||
batchBlockHash common.Hash, | ||
sequencerMsg []byte, | ||
preimageRecorder PreimageRecorder, | ||
validateSeqMsg bool, | ||
) ([]byte, error) { | ||
blobHashes := sequencerMsg[41:] | ||
if len(blobHashes)%len(common.Hash{}) != 0 { | ||
return nil, ErrInvalidBlobDataFormat | ||
} | ||
versionedHashes := make([]common.Hash, len(blobHashes)/len(common.Hash{})) | ||
for i := 0; i*32 < len(blobHashes); i += 1 { | ||
copy(versionedHashes[i][:], blobHashes[i*32:(i+1)*32]) | ||
} | ||
kzgBlobs, err := b.blobReader.GetBlobs(ctx, batchBlockHash, versionedHashes) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get blobs: %w", err) | ||
} | ||
if preimageRecorder != nil { | ||
for i, blob := range kzgBlobs { | ||
// Prevent aliasing `blob` when slicing it, as for range loops overwrite the same variable | ||
// Won't be necessary after Go 1.22 with https://go.dev/blog/loopvar-preview | ||
b := blob | ||
preimageRecorder(versionedHashes[i], b[:], arbutil.EthVersionedHashPreimageType) | ||
} | ||
} | ||
payload, err := blobs.DecodeBlobs(kzgBlobs) | ||
if err != nil { | ||
log.Warn("Failed to decode blobs", "batchBlockHash", batchBlockHash, "versionedHashes", versionedHashes, "err", err) | ||
return nil, nil | ||
} | ||
return payload, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It seems unbalanced that
daprovider.Writer
is used only to write to the DAS anddaprovider.Reader
is used to read both DAS and blobs. I'm not sure how you'd structure it to be symmetric, though, since on one hand posting a batch to the DAS is a separate operation to posting the batch itself to L1, and with blobs both get posted together with the L1 tx.Additionally for blob batch posting there is some unique logic around deciding whether or not to post as a 4844 tx or not #2158 which is different to the logic around whether to post a DAS batch or not (falls back on error only), so that also would make it hard to unify.
This is just an observation, we should seek more feedback about this from others on the team.
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.
You are right, I could not find a way to wrap blob posting to follow a common writer interface that other DAs implement.