Skip to content

Commit

Permalink
feat(rollup-relayer): finalize bundle (#1411)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo authored Jul 8, 2024
1 parent beee0c2 commit bc9bc5d
Show file tree
Hide file tree
Showing 28 changed files with 2,088 additions and 610 deletions.
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

0 comments on commit bc9bc5d

Please sign in to comment.