mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-12 23:48:15 -05:00
Compare commits
8 Commits
test/code
...
env1-sampl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cccdf7003 | ||
|
|
6cc1f424d7 | ||
|
|
af8437aa9d | ||
|
|
133547c91c | ||
|
|
fcbf83bf3d | ||
|
|
330fde44a9 | ||
|
|
122cffe489 | ||
|
|
b4dac7ab82 |
@@ -42,4 +42,7 @@ type BatchProposerConfig struct {
|
|||||||
MaxL1CommitCalldataSizePerBatch uint64 `json:"max_l1_commit_calldata_size_per_batch"`
|
MaxL1CommitCalldataSizePerBatch uint64 `json:"max_l1_commit_calldata_size_per_batch"`
|
||||||
BatchTimeoutSec uint64 `json:"batch_timeout_sec"`
|
BatchTimeoutSec uint64 `json:"batch_timeout_sec"`
|
||||||
GasCostIncreaseMultiplier float64 `json:"gas_cost_increase_multiplier"`
|
GasCostIncreaseMultiplier float64 `json:"gas_cost_increase_multiplier"`
|
||||||
|
|
||||||
|
EnableTestEnvSamplingFeature bool `json:"enable_test_env_sampling_feature,omitempty"`
|
||||||
|
SamplingPercentage uint64 `json:"sampling_percentage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ type RelayerConfig struct {
|
|||||||
EnableTestEnvBypassFeatures bool `json:"enable_test_env_bypass_features"`
|
EnableTestEnvBypassFeatures bool `json:"enable_test_env_bypass_features"`
|
||||||
// The timeout in seconds for finalizing a batch without proof, only used when EnableTestEnvBypassFeatures is true.
|
// The timeout in seconds for finalizing a batch without proof, only used when EnableTestEnvBypassFeatures is true.
|
||||||
FinalizeBatchWithoutProofTimeoutSec uint64 `json:"finalize_batch_without_proof_timeout_sec"`
|
FinalizeBatchWithoutProofTimeoutSec uint64 `json:"finalize_batch_without_proof_timeout_sec"`
|
||||||
|
|
||||||
|
EnableTestEnvSamplingFeature bool `json:"enable_test_env_sampling_feature,omitempty"`
|
||||||
|
SamplingPercentage uint64 `json:"sampling_percentage,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GasOracleConfig The config for updating gas price oracle.
|
// GasOracleConfig The config for updating gas price oracle.
|
||||||
@@ -128,6 +131,10 @@ func (r *RelayerConfig) UnmarshalJSON(input []byte) error {
|
|||||||
return fmt.Errorf("error converting and checking finalize sender private key: %w", err)
|
return fmt.Errorf("error converting and checking finalize sender private key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.SamplingPercentage == 0 {
|
||||||
|
r.SamplingPercentage = 100
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -464,8 +464,9 @@ func (r *Layer2Relayer) ProcessCommittedBatches() {
|
|||||||
case types.ProvingTaskVerified:
|
case types.ProvingTaskVerified:
|
||||||
log.Info("Start to roll up zk proof", "hash", batch.Hash)
|
log.Info("Start to roll up zk proof", "hash", batch.Hash)
|
||||||
r.metrics.rollupL2RelayerProcessCommittedBatchesFinalizedTotal.Inc()
|
r.metrics.rollupL2RelayerProcessCommittedBatchesFinalizedTotal.Inc()
|
||||||
if err := r.finalizeBatch(batch, true); err != nil {
|
skipProof := r.cfg.EnableTestEnvSamplingFeature && ((batch.Index % 100) >= r.cfg.SamplingPercentage)
|
||||||
log.Error("Failed to finalize batch with proof", "index", batch.Index, "hash", batch.Hash, "err", err)
|
if err := r.finalizeBatch(batch, !skipProof); err != nil {
|
||||||
|
log.Error("Failed to finalize batch", "index", batch.Index, "hash", batch.Hash, "withProof", !skipProof, "err", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case types.ProvingTaskFailed:
|
case types.ProvingTaskFailed:
|
||||||
@@ -586,22 +587,22 @@ func (r *Layer2Relayer) finalizeBatch(dbBatch *orm.Batch, withProof bool) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updating the proving status when finalizing without proof, thus the coordinator could omit this task.
|
// // Updating the proving status when finalizing without proof, thus the coordinator could omit this task.
|
||||||
// it isn't a necessary step, so don't put in a transaction with UpdateFinalizeTxHashAndRollupStatus
|
// // it isn't a necessary step, so don't put in a transaction with UpdateFinalizeTxHashAndRollupStatus
|
||||||
if !withProof {
|
// if !withProof {
|
||||||
txErr := r.db.Transaction(func(tx *gorm.DB) error {
|
// txErr := r.db.Transaction(func(tx *gorm.DB) error {
|
||||||
if updateErr := r.batchOrm.UpdateProvingStatus(r.ctx, dbBatch.Hash, types.ProvingTaskVerified); updateErr != nil {
|
// if updateErr := r.batchOrm.UpdateProvingStatus(r.ctx, dbBatch.Hash, types.ProvingTaskVerified); updateErr != nil {
|
||||||
return updateErr
|
// return updateErr
|
||||||
}
|
// }
|
||||||
if updateErr := r.chunkOrm.UpdateProvingStatusByBatchHash(r.ctx, dbBatch.Hash, types.ProvingTaskVerified); updateErr != nil {
|
// if updateErr := r.chunkOrm.UpdateProvingStatusByBatchHash(r.ctx, dbBatch.Hash, types.ProvingTaskVerified); updateErr != nil {
|
||||||
return updateErr
|
// return updateErr
|
||||||
}
|
// }
|
||||||
return nil
|
// return nil
|
||||||
})
|
// })
|
||||||
if txErr != nil {
|
// if txErr != nil {
|
||||||
log.Error("Updating chunk and batch proving status when finalizing without proof failure", "batchHash", dbBatch.Hash, "err", txErr)
|
// log.Error("Updating chunk and batch proving status when finalizing without proof failure", "batchHash", dbBatch.Hash, "err", txErr)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
r.metrics.rollupL2RelayerProcessCommittedBatchesFinalizedSuccessTotal.Inc()
|
r.metrics.rollupL2RelayerProcessCommittedBatchesFinalizedSuccessTotal.Inc()
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
|
||||||
"scroll-tech/common/forks"
|
"scroll-tech/common/forks"
|
||||||
|
"scroll-tech/common/types"
|
||||||
"scroll-tech/common/types/encoding"
|
"scroll-tech/common/types/encoding"
|
||||||
|
|
||||||
"scroll-tech/rollup/internal/config"
|
"scroll-tech/rollup/internal/config"
|
||||||
@@ -37,6 +38,7 @@ type BatchProposer struct {
|
|||||||
gasCostIncreaseMultiplier float64
|
gasCostIncreaseMultiplier float64
|
||||||
forkMap map[uint64]bool
|
forkMap map[uint64]bool
|
||||||
|
|
||||||
|
cfg *config.BatchProposerConfig
|
||||||
chainCfg *params.ChainConfig
|
chainCfg *params.ChainConfig
|
||||||
|
|
||||||
batchProposerCircleTotal prometheus.Counter
|
batchProposerCircleTotal prometheus.Counter
|
||||||
@@ -74,6 +76,7 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, chai
|
|||||||
batchTimeoutSec: cfg.BatchTimeoutSec,
|
batchTimeoutSec: cfg.BatchTimeoutSec,
|
||||||
gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier,
|
gasCostIncreaseMultiplier: cfg.GasCostIncreaseMultiplier,
|
||||||
forkMap: forkMap,
|
forkMap: forkMap,
|
||||||
|
cfg: cfg,
|
||||||
chainCfg: chainCfg,
|
chainCfg: chainCfg,
|
||||||
|
|
||||||
batchProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
batchProposerCircleTotal: promauto.With(reg).NewCounter(prometheus.CounterOpts{
|
||||||
@@ -144,6 +147,27 @@ func (p *BatchProposer) updateDBBatchInfo(batch *encoding.Batch, codecVersion en
|
|||||||
log.Warn("BatchProposer.UpdateBatchHashInRange update the chunk's batch hash failure", "hash", batch.Hash, "error", dbErr)
|
log.Warn("BatchProposer.UpdateBatchHashInRange update the chunk's batch hash failure", "hash", batch.Hash, "error", dbErr)
|
||||||
return dbErr
|
return dbErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
skipProof := false
|
||||||
|
if p.cfg.EnableTestEnvSamplingFeature && ((batch.Index % 100) >= p.cfg.SamplingPercentage) {
|
||||||
|
skipProof = true
|
||||||
|
}
|
||||||
|
if skipProof {
|
||||||
|
dbErr = p.batchOrm.UpdateProvingStatus(p.ctx, batch.Hash, types.ProvingTaskVerified, dbTX)
|
||||||
|
if dbErr != nil {
|
||||||
|
log.Warn("BatchProposer.updateBatchInfoInDB update batch proving_status failure",
|
||||||
|
"batch hash", batch.Hash, "error", dbErr)
|
||||||
|
return dbErr
|
||||||
|
}
|
||||||
|
dbErr = p.chunkOrm.UpdateProvingStatusInRange(p.ctx, batch.StartChunkIndex, batch.EndChunkIndex, types.ProvingTaskVerified, dbTX)
|
||||||
|
if dbErr != nil {
|
||||||
|
log.Warn("BatchProposer.updateBatchInfoInDB update chunk proving_status failure",
|
||||||
|
"start chunk index", batch.StartChunkIndex, "end chunk index", batch.EndChunkIndex,
|
||||||
|
"batch hash", batch.Hash, "error", dbErr)
|
||||||
|
return dbErr
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -306,3 +306,28 @@ func (o *Chunk) UpdateBatchHashInRange(ctx context.Context, startIndex uint64, e
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (o *Chunk) UpdateProvingStatusInRange(ctx context.Context, startIndex uint64, endIndex uint64, status types.ProvingStatus, dbTX ...*gorm.DB) error {
|
||||||
|
db := o.db
|
||||||
|
if len(dbTX) > 0 && dbTX[0] != nil {
|
||||||
|
db = dbTX[0]
|
||||||
|
}
|
||||||
|
db = db.WithContext(ctx)
|
||||||
|
db = db.Model(&Chunk{})
|
||||||
|
db = db.Where("index >= ? AND index <= ?", startIndex, endIndex)
|
||||||
|
|
||||||
|
updateFields := make(map[string]interface{})
|
||||||
|
updateFields["proving_status"] = int(status)
|
||||||
|
switch status {
|
||||||
|
case types.ProvingTaskAssigned:
|
||||||
|
updateFields["prover_assigned_at"] = time.Now()
|
||||||
|
case types.ProvingTaskUnassigned:
|
||||||
|
updateFields["prover_assigned_at"] = nil
|
||||||
|
case types.ProvingTaskVerified:
|
||||||
|
updateFields["proved_at"] = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := db.Updates(updateFields).Error; err != nil {
|
||||||
|
return fmt.Errorf("Chunk.UpdateProvingStatusInRange error: %w, start index: %v, end index: %v, status: %v", err, startIndex, endIndex, status.String())
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user