mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-21 03:47:59 -05:00
feat(coordinator) retry verifying StatusProved batches on coordinator restart(startup)
This commit is contained in:
@@ -189,7 +189,9 @@ func testL2RelayerProcessCommittedBatches(t *testing.T) {
|
||||
|
||||
tProof := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
tInstanceCommitments := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, 100)
|
||||
finalPair := []byte{0, 1}
|
||||
vk := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, finalPair, vk, 100)
|
||||
assert.NoError(t, err)
|
||||
err = db.UpdateProvingStatus(batchID, orm.ProvingTaskVerified)
|
||||
assert.NoError(t, err)
|
||||
@@ -229,7 +231,9 @@ func testL2RelayerSkipBatches(t *testing.T) {
|
||||
|
||||
tProof := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
tInstanceCommitments := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, 100)
|
||||
finalPair := []byte{0, 1}
|
||||
vk := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, finalPair, vk, 100)
|
||||
assert.NoError(t, err)
|
||||
err = db.UpdateProvingStatus(batchID, provingStatus)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -105,7 +105,9 @@ func testRelayL2MessageSucceed(t *testing.T) {
|
||||
// add dummy proof
|
||||
tProof := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
tInstanceCommitments := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, 100)
|
||||
finalPair := []byte{0, 1}
|
||||
vk := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, finalPair, vk, 100)
|
||||
assert.NoError(t, err)
|
||||
err = db.UpdateProvingStatus(batchID, orm.ProvingTaskVerified)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -107,7 +107,9 @@ func testCommitBatchAndFinalizeBatch(t *testing.T) {
|
||||
// add dummy proof
|
||||
tProof := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
tInstanceCommitments := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, 100)
|
||||
finalPair := []byte{0, 1}
|
||||
vk := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
|
||||
err = db.UpdateProofByID(context.Background(), batchID, tProof, tInstanceCommitments, finalPair, vk, 100)
|
||||
assert.NoError(t, err)
|
||||
err = db.UpdateProvingStatus(batchID, orm.ProvingTaskVerified)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -206,6 +206,41 @@ func (m *Manager) restorePrevSessions() {
|
||||
}
|
||||
|
||||
go m.CollectProofs(sess)
|
||||
|
||||
id := sess.info.ID
|
||||
batches, err := m.orm.GetBlockBatches(map[string]interface{}{"id": id})
|
||||
if err != nil || len(batches) == 0 {
|
||||
log.Error("Failed to GetBlockBatches", "batch_id", id, "err", err)
|
||||
continue
|
||||
}
|
||||
m.tryVerify(batches[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TryVerify verifies a proof for batch received form roller if previous verification had interrupted
|
||||
func (m *Manager) tryVerify(batch *orm.BlockBatch) {
|
||||
proof := &message.AggProof{
|
||||
Proof: batch.Proof,
|
||||
Instance: batch.InstanceCommitments,
|
||||
FinalPair: batch.FinalPair,
|
||||
Vk: batch.Vk,
|
||||
}
|
||||
success, err := m.verifier.VerifyProof(proof)
|
||||
if err != nil {
|
||||
success = false
|
||||
log.Error("Failed to verify zk proof", "proof id", batch.ID, "error", err)
|
||||
} else {
|
||||
log.Info("Verify zk proof successfully", "verification result", success, "proof id", batch.ID)
|
||||
}
|
||||
|
||||
if success {
|
||||
if dbErr := m.orm.UpdateProvingStatus(batch.ID, orm.ProvingTaskVerified); dbErr != nil {
|
||||
log.Error(
|
||||
"failed to update proving_status",
|
||||
"msg.ID", batch.ID,
|
||||
"status", orm.ProvingTaskVerified,
|
||||
"error", dbErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,7 +317,7 @@ func (m *Manager) handleZkProof(pk string, msg *message.ProofDetail) error {
|
||||
}
|
||||
|
||||
// store proof content
|
||||
if dbErr = m.orm.UpdateProofByID(m.ctx, msg.ID, msg.Proof.Proof, msg.Proof.FinalPair, proofTimeSec); dbErr != nil {
|
||||
if dbErr = m.orm.UpdateProofByID(m.ctx, msg.ID, msg.Proof.Proof, msg.Proof.Instance, msg.Proof.FinalPair, msg.Proof.Vk, proofTimeSec); dbErr != nil {
|
||||
log.Error("failed to store proof into db", "error", dbErr)
|
||||
return dbErr
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ create table block_batch
|
||||
proving_status INTEGER DEFAULT 1,
|
||||
proof BYTEA DEFAULT NULL,
|
||||
instance_commitments BYTEA DEFAULT NULL,
|
||||
final_pair BYTEA DEFAULT NULL,
|
||||
vk BYTEA DEFAULT NULL,
|
||||
proof_time_sec INTEGER DEFAULT 0,
|
||||
rollup_status INTEGER DEFAULT 1,
|
||||
commit_tx_hash VARCHAR DEFAULT NULL,
|
||||
|
||||
@@ -89,6 +89,8 @@ type BlockBatch struct {
|
||||
ProvingStatus ProvingStatus `json:"proving_status" db:"proving_status"`
|
||||
Proof []byte `json:"proof" db:"proof"`
|
||||
InstanceCommitments []byte `json:"instance_commitments" db:"instance_commitments"`
|
||||
FinalPair []byte `json:"final_pair" db:"final_pair"`
|
||||
Vk []byte `json:"vk" db:"vk"`
|
||||
ProofTimeSec uint64 `json:"proof_time_sec" db:"proof_time_sec"`
|
||||
RollupStatus RollupStatus `json:"rollup_status" db:"rollup_status"`
|
||||
CommitTxHash sql.NullString `json:"commit_tx_hash" db:"commit_tx_hash"`
|
||||
@@ -159,11 +161,11 @@ func (o *blockBatchOrm) GetVerifiedProofAndInstanceByID(id string) ([]byte, []by
|
||||
return proof, instance, nil
|
||||
}
|
||||
|
||||
func (o *blockBatchOrm) UpdateProofByID(ctx context.Context, id string, proof, instanceCommitments []byte, proofTimeSec uint64) error {
|
||||
func (o *blockBatchOrm) UpdateProofByID(ctx context.Context, id string, proof, instanceCommitments, finalPair, vk []byte, proofTimeSec uint64) error {
|
||||
db := o.db
|
||||
if _, err := db.ExecContext(ctx,
|
||||
db.Rebind(`UPDATE block_batch set proof = ?, instance_commitments = ?, proof_time_sec = ? where id = ?;`),
|
||||
proof, instanceCommitments, proofTimeSec, id,
|
||||
db.Rebind(`UPDATE block_batch set proof = ?, instance_commitments = ?, final_pair = ?, vk = ?, proof_time_sec = ? where id = ?;`),
|
||||
proof, instanceCommitments, finalPair, vk, proofTimeSec, id,
|
||||
); err != nil {
|
||||
log.Error("failed to update proof", "err", err)
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ type BlockBatchOrm interface {
|
||||
GetBlockBatches(fields map[string]interface{}, args ...string) ([]*BlockBatch, error)
|
||||
GetProvingStatusByID(id string) (ProvingStatus, error)
|
||||
GetVerifiedProofAndInstanceByID(id string) ([]byte, []byte, error)
|
||||
UpdateProofByID(ctx context.Context, id string, proof, instanceCommitments []byte, proofTimeSec uint64) error
|
||||
UpdateProofByID(ctx context.Context, id string, proof, instanceCommitments, finalPair, vk []byte, proofTimeSec uint64) error
|
||||
UpdateProvingStatus(id string, status ProvingStatus) error
|
||||
ResetProvingStatusFor(before ProvingStatus) error
|
||||
NewBatchInDBTx(dbTx *sqlx.Tx, startBlock *BlockInfo, endBlock *BlockInfo, parentHash string, totalTxNum uint64, gasUsed uint64) (string, error)
|
||||
|
||||
@@ -298,7 +298,7 @@ func testOrmBlockBatch(t *testing.T) {
|
||||
provingStatus, err := ormBatch.GetProvingStatusByID(batchID1)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, orm.ProvingTaskUnassigned, provingStatus)
|
||||
err = ormBatch.UpdateProofByID(context.Background(), batchID1, []byte{1}, []byte{2}, 1200)
|
||||
err = ormBatch.UpdateProofByID(context.Background(), batchID1, []byte{1}, []byte{2}, []byte{3}, []byte{4}, 1200)
|
||||
assert.NoError(t, err)
|
||||
err = ormBatch.UpdateProvingStatus(batchID1, orm.ProvingTaskVerified)
|
||||
assert.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user