Skip to content
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

feat(rollup-relayer): finalize bundle #1411

Merged
merged 29 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a4995c2
add finalize bundle
colinlyguo Jun 28, 2024
651b6db
Merge branch 'feat/upgrade4' into finalize-bundle
colinlyguo Jul 2, 2024
c2e9948
Merge branch 'feat/upgrade4' into finalize-bundle
colinlyguo Jul 2, 2024
f5cfddb
update batches' rollup status when finalizing a bundle
colinlyguo Jul 2, 2024
f92402d
add bundle orm tests
colinlyguo Jul 3, 2024
3c8c8d2
ask chain-monitor to check all batches within a bundle
colinlyguo Jul 3, 2024
a9d1f89
add more assertions in db tests
colinlyguo Jul 3, 2024
2793616
add testBundleProposerRespectHardforks
colinlyguo Jul 3, 2024
b8b0980
add testBundleProposerLimits
colinlyguo Jul 4, 2024
24b15fc
add finalizeBundle
colinlyguo Jul 4, 2024
fcdc232
add l2 relayer unit tests
colinlyguo Jul 4, 2024
796a1df
add db unit tests
colinlyguo Jul 4, 2024
499b942
update submodule
colinlyguo Jul 4, 2024
e005fe0
testCommitTwoBatchesAndFinalizeByOneBundle
colinlyguo Jul 4, 2024
6d6e9e6
simplify unit tests without sacrificing coverage
colinlyguo Jul 5, 2024
4a4fddc
remove a log
colinlyguo Jul 5, 2024
1c7a191
fine tune error logs
colinlyguo Jul 6, 2024
11a719a
fix a typo
colinlyguo Jul 7, 2024
4a28add
some fixes
colinlyguo Jul 7, 2024
b16c355
fix error return and logs
colinlyguo Jul 7, 2024
b1c3244
fixes
colinlyguo Jul 7, 2024
d0f8777
add db indices
colinlyguo Jul 7, 2024
d0dc7a1
fix
colinlyguo Jul 7, 2024
bee5b1f
nit
colinlyguo Jul 7, 2024
b7efc8f
remove some assertions
colinlyguo Jul 7, 2024
b550615
add them back
colinlyguo Jul 7, 2024
d23b617
add BundleProposerConfig in L2Config
colinlyguo Jul 8, 2024
c96c4dd
change "indices" to "index fields"
colinlyguo Jul 8, 2024
9316e45
rename "index fields" to "index"
colinlyguo Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bridge-history-api/internal/logic/history_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (h *HistoryLogic) cacheTxsInfo(ctx context.Context, cacheKey string, txs []
return err
}
} else {
// The transactions are sorted, thus we set the score as their indices.
// The transactions are sorted, thus we set the score as their index.
for _, tx := range txs {
txBytes, err := json.Marshal(tx)
if err != nil {
Expand Down
36 changes: 28 additions & 8 deletions common/types/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ type BatchProof struct {
GitVersion string `json:"git_version,omitempty"`
}

// SanityCheck checks whether an BatchProof is in a legal format
// SanityCheck checks whether a BatchProof is in a legal format
func (ap *BatchProof) SanityCheck() error {
if ap == nil {
return errors.New("agg_proof is nil")
Expand All @@ -243,23 +243,18 @@ func (ap *BatchProof) SanityCheck() error {
if len(ap.Proof) == 0 {
return errors.New("proof not ready")
}

if len(ap.Proof)%32 != 0 {
return fmt.Errorf("proof buffer has wrong length, expected: 32, got: %d", len(ap.Proof))
return fmt.Errorf("proof buffer length must be a multiple of 32, got: %d", len(ap.Proof))
}

if len(ap.Instances) == 0 {
return errors.New("instance not ready")
}
if len(ap.Instances)%32 != 0 {
return fmt.Errorf("instance buffer has wrong length, expected: 32, got: %d", len(ap.Instances))
}

if len(ap.Vk) == 0 {
return errors.New("vk not ready")
}
if len(ap.Vk)%32 != 0 {
return fmt.Errorf("vk buffer has wrong length, expected: 32, got: %d", len(ap.Vk))
}

return nil
}
Expand All @@ -272,3 +267,28 @@ type BundleProof struct {
// cross-reference between cooridinator computation and prover compution
GitVersion string `json:"git_version,omitempty"`
}

// SanityCheck checks whether a BundleProof is in a legal format
func (ap *BundleProof) SanityCheck() error {
if ap == nil {
return errors.New("agg_proof is nil")
}

if len(ap.Proof) == 0 {
return errors.New("proof not ready")
}

if len(ap.Proof)%32 != 0 {
return fmt.Errorf("proof buffer length must be a multiple of 32, got: %d", len(ap.Proof))
}

if len(ap.Instances) == 0 {
return errors.New("instance not ready")
}

if len(ap.Vk) == 0 {
return errors.New("vk not ready")
}

return nil
}
4 changes: 2 additions & 2 deletions coordinator/internal/orm/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (*Batch) TableName() string {
}

// GetUnassignedBatch retrieves unassigned batch based on the specified limit.
// The returned batch are sorted in ascending order by their index.
// The returned batches are sorted in ascending order by their index.
func (o *Batch) GetUnassignedBatch(ctx context.Context, startChunkIndex, endChunkIndex uint64, maxActiveAttempts, maxTotalAttempts uint8) (*Batch, error) {
var batch Batch
db := o.db.WithContext(ctx)
Expand All @@ -93,7 +93,7 @@ func (o *Batch) GetUnassignedBatch(ctx context.Context, startChunkIndex, endChun
}

// GetAssignedBatch retrieves assigned batch based on the specified limit.
// The returned batch are sorted in ascending order by their index.
// The returned batches are sorted in ascending order by their index.
func (o *Batch) GetAssignedBatch(ctx context.Context, startChunkIndex, endChunkIndex uint64, maxActiveAttempts, maxTotalAttempts uint8) (*Batch, error) {
var batch Batch
db := o.db.WithContext(ctx)
Expand Down
12 changes: 9 additions & 3 deletions database/migrate/migrations/00021_bundle.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

CREATE TABLE bundle (
index BIGSERIAL PRIMARY KEY,
hash VARCHAR NOT NULL, -- Not part of DA hash, used for SQL query consistency and ease of use, derived using keccak256(concat(start_batch_hash, end_batch_hash)).
hash VARCHAR NOT NULL, -- Not part of DA hash, used for SQL query consistency and ease of use, derived using keccak256(concat(start_batch_hash_bytes, end_batch_hash_bytes)).
start_batch_index BIGINT NOT NULL,
end_batch_index BIGINT NOT NULL,
start_batch_hash VARCHAR NOT NULL,
end_batch_hash VARCHAR NOT NULL,
codec_version SMALLINT NOT NULL,

-- proof
batch_proofs_status SMALLINT NOT NULL DEFAULT 1,
Expand All @@ -28,8 +29,13 @@ CREATE TABLE bundle (
deleted_at TIMESTAMP(0) DEFAULT NULL
);

CREATE INDEX bundle_start_batch_index_idx ON bundle (start_batch_index) WHERE deleted_at IS NULL;
CREATE INDEX bundle_end_batch_index_idx ON bundle (end_batch_index) WHERE deleted_at IS NULL;
CREATE INDEX idx_bundle_index_rollup_status ON bundle(index, rollup_status) WHERE deleted_at IS NULL;
CREATE INDEX idx_bundle_hash ON bundle(hash) WHERE deleted_at IS NULL;
CREATE INDEX idx_bundle_hash_proving_status ON bundle(hash, proving_status) WHERE deleted_at IS NULL;
CREATE INDEX idx_bundle_index_desc ON bundle(index DESC) WHERE deleted_at IS NULL;
CREATE INDEX idx_bundle_batch_proofs_status ON bundle(batch_proofs_status) WHERE deleted_at IS NULL;
CREATE INDEX idx_bundle_start_batch_index ON bundle(start_batch_index) WHERE deleted_at IS NULL;
CREATE INDEX idx_bundle_end_batch_index ON bundle(end_batch_index) WHERE deleted_at IS NULL;

COMMENT ON COLUMN bundle.batch_proofs_status IS 'undefined, pending, ready';
COMMENT ON COLUMN bundle.proving_status IS 'undefined, unassigned, assigned, proved (deprecated), verified, failed';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- +goose Up
-- +goose StatementBegin

ALTER TABLE batch
ADD COLUMN bundle_hash VARCHAR DEFAULT '',
ADD COLUMN codec_version SMALLINT DEFAULT 0;

CREATE INDEX idx_batch_bundle_hash ON batch(bundle_hash);
CREATE INDEX idx_batch_index_codec_version ON batch(index, codec_version);

-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin

DROP INDEX IF EXISTS idx_batch_bundle_hash;
DROP INDEX IF EXISTS idx_batch_index_codec_version;

ALTER TABLE IF EXISTS batch
DROP COLUMN IF EXISTS bundle_hash,
DROP COLUMN IF EXISTS codec_version;

-- +goose StatementEnd
15 changes: 0 additions & 15 deletions database/migrate/migrations/00022_add_bundle_hash_to_batch.sql

This file was deleted.

Loading
Loading