mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-29 16:13:47 +00:00
* port changes from #1013 * port changes from #1068 * go.mod tidy * fix compile error * fix goimports * fix log * address review comments * upgrade golang.org/x/net to 0.23.0 * port changes from #1018 * fix tests and linter errors * address review comments * refactor rollup sync service / verifier to use CalldataBlobSource to retrieve data from L1 * add configuration and initialize blob clients * fix unit tests * remove unused code * address review comments * address more review comments * implement first version of new da-codec and to handle multiple batches submitted in one transaction * add CommitBatchDAV7 and handle multiple commit events submitted in a single transactions * fix bug due to previous batch being empty when processing the first batch within a set of batches * Allow using MPT * update to latest da-codec * add field to CommittedBatchMeta to store LastL1MessageQueueHash for CodecV7 batches * adjust rollup verifier to support CodecV7 batches * address review comments * fix issues after merge * go mod tidy * fix unit tests * update da-codec * add test TestValidateBatchCodecV7 * go mod tidy * do not log error on shutdown * add sanity check for version to deserialization of committedBatchMetaV7 * chore: auto version bump [bot] * address review comments * chore: auto version bump [bot] --------- Co-authored-by: Ömer Faruk Irmak <omerfirmak@gmail.com> Co-authored-by: Thegaram <Thegaram@users.noreply.github.com> Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
90 lines
2.8 KiB
Go
90 lines
2.8 KiB
Go
package da
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"fmt"
|
|
|
|
"github.com/scroll-tech/da-codec/encoding"
|
|
|
|
"github.com/scroll-tech/go-ethereum/rollup/da_syncer/blob_client"
|
|
"github.com/scroll-tech/go-ethereum/rollup/l1"
|
|
|
|
"github.com/scroll-tech/go-ethereum/common"
|
|
"github.com/scroll-tech/go-ethereum/crypto/kzg4844"
|
|
"github.com/scroll-tech/go-ethereum/ethdb"
|
|
)
|
|
|
|
type CommitBatchDAV1 struct {
|
|
*CommitBatchDAV0
|
|
|
|
versionedHashes []common.Hash
|
|
}
|
|
|
|
func NewCommitBatchDAV1(ctx context.Context, db ethdb.Database,
|
|
blobClient blob_client.BlobClient,
|
|
codec encoding.Codec,
|
|
commitEvent *l1.CommitBatchEvent,
|
|
parentBatchHeader []byte,
|
|
chunks [][]byte,
|
|
skippedL1MessageBitmap []byte,
|
|
versionedHashes []common.Hash,
|
|
l1BlockTime uint64,
|
|
) (*CommitBatchDAV1, error) {
|
|
decodedChunks, err := codec.DecodeDAChunksRawTx(chunks)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to unpack chunks: %v, err: %w", commitEvent.BatchIndex().Uint64(), err)
|
|
}
|
|
|
|
// with CommitBatchDAV1 we expect only one versioned hash as we commit only one blob per batch submission
|
|
if len(versionedHashes) != 1 {
|
|
return nil, fmt.Errorf("unexpected number of versioned hashes: %d", len(versionedHashes))
|
|
}
|
|
versionedHash := versionedHashes[0]
|
|
|
|
blob, err := blobClient.GetBlobByVersionedHashAndBlockTime(ctx, versionedHash, l1BlockTime)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to fetch blob from blob client, err: %w", err)
|
|
}
|
|
if blob == nil {
|
|
return nil, fmt.Errorf("unexpected, blob == nil and err != nil, batch index: %d, versionedHash: %s, blobClient: %T", commitEvent.BatchIndex().Uint64(), versionedHash.String(), blobClient)
|
|
}
|
|
|
|
// compute blob versioned hash and compare with one from tx
|
|
c, err := kzg4844.BlobToCommitment(blob)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to create blob commitment: %w", err)
|
|
}
|
|
blobVersionedHash := common.Hash(kzg4844.CalcBlobHashV1(sha256.New(), &c))
|
|
if blobVersionedHash != versionedHash {
|
|
return nil, fmt.Errorf("blobVersionedHash from blob source is not equal to versionedHash from tx, correct versioned hash: %s, fetched blob hash: %s", versionedHash.String(), blobVersionedHash.String())
|
|
}
|
|
|
|
// decode txs from blob
|
|
err = codec.DecodeTxsFromBlob(blob, decodedChunks)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to decode txs from blob: %w", err)
|
|
}
|
|
|
|
if decodedChunks == nil {
|
|
return nil, fmt.Errorf("decodedChunks is nil after decoding")
|
|
}
|
|
|
|
v0, err := NewCommitBatchDAV0WithChunks(db, codec.Version(), commitEvent.BatchIndex().Uint64(), parentBatchHeader, decodedChunks, skippedL1MessageBitmap, commitEvent)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &CommitBatchDAV1{
|
|
CommitBatchDAV0: v0,
|
|
versionedHashes: versionedHashes,
|
|
}, nil
|
|
}
|
|
|
|
func (c *CommitBatchDAV1) Type() Type {
|
|
return CommitBatchWithBlobType
|
|
}
|
|
|
|
func (c *CommitBatchDAV1) BlobVersionedHashes() []common.Hash {
|
|
return c.versionedHashes
|
|
}
|