-
Notifications
You must be signed in to change notification settings - Fork 628
feat: add blob storage service #1672
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9aee0d6
feat: add blob uploader service
yiweichi 4bf4196
feat: add blob uploader aws s3
yiweichi 385d97c
chores
yiweichi 2acce16
feat: add start batch
yiweichi e8e7fb1
fix: app.go
yiweichi b9fa8c8
fix: database migrate
yiweichi a8c913f
fix: database migrate
yiweichi 6c68f3c
debug logs
yiweichi e84a2b8
debug logs
yiweichi d623baf
fix: GetFirstUnuploadedAndFailedBatch
yiweichi 6a499fa
rm logs
yiweichi b6bf805
fix: ci
yiweichi 03410b7
fix: database test
yiweichi 030742c
feat: support multi codec version
yiweichi b1a8ba7
fix: ci
yiweichi ef88fef
fix: address comments
yiweichi 1d8a48a
fix: constructBlobCodec
yiweichi 0570525
Update rollup/cmd/blob_uploader/app/app.go
yiweichi a434b2c
Apply suggestions from code review
yiweichi 4f9a98e
fix: address comments
yiweichi 1ba262a
fix: remove left join
yiweichi 8964e3f
Merge branch 'develop' into feat-add-blob-storage-service
yiweichi 94c8e4a
fix: ci
yiweichi bf8a149
fix: typo
yiweichi c4c765f
perfect logs
yiweichi 8ac3181
fix: typo
yiweichi 6d08239
fix: logs
yiweichi 66ebecf
feat: add blob-uploader docker ci
yiweichi 4c5a1bf
fix: address comments
yiweichi 4c988a9
fix: address comments
yiweichi b6e7c3e
fix: use unique key
yiweichi 19b59b9
chore: auto version bump [bot]
yiweichi 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 hidden or 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,30 @@ | ||
| # Download Go dependencies | ||
| FROM scrolltech/go-rust-builder:go-1.22-rust-nightly-2023-12-03 as base | ||
|
|
||
| WORKDIR /src | ||
| COPY go.work* ./ | ||
| COPY ./rollup/go.* ./rollup/ | ||
| COPY ./common/go.* ./common/ | ||
| COPY ./coordinator/go.* ./coordinator/ | ||
| COPY ./database/go.* ./database/ | ||
| COPY ./tests/integration-test/go.* ./tests/integration-test/ | ||
| COPY ./bridge-history-api/go.* ./bridge-history-api/ | ||
| RUN go mod download -x | ||
|
|
||
| # Build blob_uploader | ||
| FROM base as builder | ||
|
|
||
| RUN --mount=target=. \ | ||
| --mount=type=cache,target=/root/.cache/go-build \ | ||
| cd /src/rollup/cmd/blob_uploader/ && CGO_LDFLAGS="-ldl" go build -v -p 4 -o /bin/blob_uploader | ||
|
|
||
| # Pull blob_uploader into a second stage deploy ubuntu container | ||
| FROM ubuntu:20.04 | ||
|
|
||
| RUN apt update && apt install vim netcat-openbsd net-tools curl ca-certificates -y | ||
|
|
||
| ENV CGO_LDFLAGS="-ldl" | ||
|
|
||
| COPY --from=builder /bin/blob_uploader /bin/ | ||
| WORKDIR /app | ||
| ENTRYPOINT ["blob_uploader"] |
This file contains hidden or 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,5 @@ | ||
| assets/ | ||
| docs/ | ||
| l2geth/ | ||
| rpc-gateway/ | ||
| *target/* |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,23 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "fmt" | ||
|
|
||
| "github.com/scroll-tech/go-ethereum/crypto/kzg4844" | ||
| ) | ||
|
|
||
| // CalculateVersionedBlobHash calculate the kzg4844 versioned blob hash from a blob | ||
| func CalculateVersionedBlobHash(blob kzg4844.Blob) ([32]byte, error) { | ||
| // calculate kzg4844 commitment from blob | ||
| commit, err := kzg4844.BlobToCommitment(&blob) | ||
| if err != nil { | ||
| return [32]byte{}, fmt.Errorf("failed to get blob commitment, err: %w", err) | ||
| } | ||
|
|
||
| // calculate kzg4844 versioned blob hash from blob commitment | ||
| hasher := sha256.New() | ||
| vh := kzg4844.CalcBlobHashV1(hasher, &commit) | ||
|
|
||
| return vh, nil | ||
| } |
This file contains hidden or 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,52 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "encoding/hex" | ||
| "encoding/json" | ||
| "fmt" | ||
yiweichi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/scroll-tech/go-ethereum/crypto/kzg4844" | ||
| ) | ||
|
|
||
| type BlobData struct { | ||
| VersionedBlobHash string `json:"versionedBlobHash"` | ||
| BlobData string `json:"blobData"` | ||
| } | ||
|
|
||
| // TestCalculateVersionedBlobHash tests the CalculateVersionedBlobHash function | ||
| func TestCalculateVersionedBlobHash(t *testing.T) { | ||
| // Read the test data | ||
| data, err := os.ReadFile("../testdata/blobdata.json") | ||
| if err != nil { | ||
| t.Fatalf("Failed to read blobdata.json: %v", err) | ||
| } | ||
|
|
||
| var blobData BlobData | ||
| if err := json.Unmarshal(data, &blobData); err != nil { | ||
| t.Fatalf("Failed to parse blobdata.json: %v", err) | ||
| } | ||
|
|
||
| blobBytes, err := hex.DecodeString(blobData.BlobData) | ||
| if err != nil { | ||
| t.Fatalf("Failed to decode blob data: %v", err) | ||
| } | ||
|
|
||
| // Convert []byte to kzg4844.Blob | ||
| var blob kzg4844.Blob | ||
| copy(blob[:], blobBytes) | ||
yiweichi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Calculate the hash | ||
| calculatedHashBytes, err := CalculateVersionedBlobHash(blob) | ||
| if err != nil { | ||
| t.Fatalf("Failed to calculate versioned blob hash: %v", err) | ||
| } | ||
|
|
||
| calculatedHash := hex.EncodeToString(calculatedHashBytes[:]) | ||
|
|
||
| if calculatedHash != blobData.VersionedBlobHash { | ||
| t.Fatalf("Hash mismatch: got %s, want %s", calculatedHash, blobData.VersionedBlobHash) | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package types | |
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "scroll-tech/common/types/message" | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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,37 @@ | ||
| -- +goose Up | ||
| -- +goose StatementBegin | ||
|
|
||
| CREATE TABLE blob_upload ( | ||
| batch_index BIGINT NOT NULL, | ||
|
|
||
| platform SMALLINT NOT NULL, | ||
| status SMALLINT NOT NULL, | ||
|
|
||
| -- metadata | ||
| created_at TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| updated_at TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| deleted_at TIMESTAMP(0) DEFAULT NULL | ||
|
|
||
| PRIMARY KEY (batch_index, platform) | ||
yiweichi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
|
|
||
| COMMENT ON COLUMN blob_upload.status IS 'undefined, pending, uploaded, failed'; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_blob_upload_batch_index ON blob_upload(batch_index) WHERE deleted_at IS NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_blob_upload_platform ON blob_upload(platform) WHERE deleted_at IS NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_blob_upload_status ON blob_upload(status) WHERE deleted_at IS NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_blob_upload_updated_at ON blob_upload(updated_at) WHERE deleted_at IS NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_blob_upload_status_platform ON blob_upload(status, platform) WHERE deleted_at IS NULL; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_blob_upload_batch_index_status_platform ON blob_upload(batch_index, status, platform) WHERE deleted_at IS NULL; | ||
|
|
||
| -- +goose StatementEnd | ||
|
|
||
| -- +goose Down | ||
| -- +goose StatementBegin | ||
| DROP TABLE blob_upload; | ||
| -- +goose StatementEnd | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| go 1.22 | ||
|
|
||
| toolchain go1.22.2 | ||
| go 1.22.4 | ||
|
|
||
| use ( | ||
| ./bridge-history-api | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.