diff --git a/bridge-history-api/abi/backend_abi.go b/bridge-history-api/abi/backend_abi.go index 940cd2df10..c4615862ff 100644 --- a/bridge-history-api/abi/backend_abi.go +++ b/bridge-history-api/abi/backend_abi.go @@ -45,7 +45,7 @@ var ( L2BatchWithdrawERC721Sig common.Hash L2BatchWithdrawERC1155Sig common.Hash - // scroll mono repo + // scroll monorepo // ScrollChainABI holds information about ScrollChain's context and available invokable methods. ScrollChainABI *abi.ABI @@ -323,7 +323,7 @@ type L1RelayedMessageEvent struct { MessageHash common.Hash } -// L2AppendMessageEvent represents a AppendMessage event raised by the L2MessageQueue contract. +// L2AppendMessageEvent represents an AppendMessage event raised by the L2MessageQueue contract. type L2AppendMessageEvent struct { Index *big.Int MessageHash common.Hash diff --git a/bridge-history-api/utils/database.go b/bridge-history-api/utils/database.go index 916372e042..5d7383c165 100644 --- a/bridge-history-api/utils/database.go +++ b/bridge-history-api/utils/database.go @@ -74,6 +74,8 @@ func InitDB(config *config.DBConfig) (*gorm.DB, error) { return nil, pingErr } + sqlDB.SetConnMaxLifetime(time.Minute * 10) + sqlDB.SetConnMaxIdleTime(time.Minute * 5) sqlDB.SetMaxOpenConns(config.MaxOpenNum) sqlDB.SetMaxIdleConns(config.MaxIdleNum) diff --git a/common/cmd/cmd.go b/common/cmd/cmd.go index ba6301fe40..15750fea7b 100644 --- a/common/cmd/cmd.go +++ b/common/cmd/cmd.go @@ -15,7 +15,7 @@ var verbose bool func init() { v := os.Getenv("LOG_DOCKER") - if v == "true" || v == "TRUE" { + if strings.ToLower(v) == "true" { verbose = true } } diff --git a/common/database/db.go b/common/database/db.go index 8d5a54842a..322ba27115 100644 --- a/common/database/db.go +++ b/common/database/db.go @@ -70,6 +70,9 @@ func InitDB(config *Config) (*gorm.DB, error) { return nil, pingErr } + sqlDB.SetConnMaxLifetime(time.Minute * 10) + sqlDB.SetConnMaxIdleTime(time.Minute * 5) + sqlDB.SetMaxOpenConns(config.MaxOpenNum) sqlDB.SetMaxIdleConns(config.MaxIdleNum) diff --git a/common/libzkp/impl/Cargo.lock b/common/libzkp/impl/Cargo.lock index d1174c0bda..a990eafea7 100644 --- a/common/libzkp/impl/Cargo.lock +++ b/common/libzkp/impl/Cargo.lock @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "aggregator" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "ark-std", "env_logger 0.10.0", @@ -333,7 +333,7 @@ checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bus-mapping" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "eth-types", "ethers-core", @@ -959,7 +959,7 @@ dependencies = [ [[package]] name = "eth-types" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "ethers-core", "ethers-signers", @@ -1116,7 +1116,7 @@ dependencies = [ [[package]] name = "external-tracer" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "eth-types", "geth-utils", @@ -1296,7 +1296,7 @@ dependencies = [ [[package]] name = "gadgets" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "digest 0.7.6", "eth-types", @@ -1328,7 +1328,7 @@ dependencies = [ [[package]] name = "geth-utils" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "env_logger 0.9.3", "gobuild 0.1.0-alpha.2 (git+https://github.com/scroll-tech/gobuild.git)", @@ -1937,7 +1937,7 @@ dependencies = [ [[package]] name = "keccak256" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "env_logger 0.9.3", "eth-types", @@ -2135,7 +2135,7 @@ dependencies = [ [[package]] name = "mock" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "eth-types", "ethers-core", @@ -2151,7 +2151,7 @@ dependencies = [ [[package]] name = "mpt-zktrie" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "eth-types", "halo2-mpt-circuits", @@ -2582,7 +2582,7 @@ dependencies = [ [[package]] name = "prover" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "aggregator", "anyhow", @@ -4125,7 +4125,7 @@ checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" [[package]] name = "zkevm-circuits" version = "0.1.0" -source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.7#2055cc0bb970aa28d597c945b6078e2469af8862" +source = "git+https://github.com/scroll-tech/zkevm-circuits.git?tag=v0.9.8#8f17df87ba70f5a8fcaa23f4fcb7fb112f5a815a" dependencies = [ "array-init", "bus-mapping", diff --git a/common/libzkp/impl/Cargo.toml b/common/libzkp/impl/Cargo.toml index 227c001568..1c2e28dad9 100644 --- a/common/libzkp/impl/Cargo.toml +++ b/common/libzkp/impl/Cargo.toml @@ -21,7 +21,7 @@ halo2curves = { git = "https://github.com/scroll-tech/halo2curves.git", branch = [dependencies] halo2_proofs = { git = "https://github.com/scroll-tech/halo2.git", branch = "develop" } -prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.9.7", default-features = false, features = ["parallel_syn", "scroll", "shanghai"] } +prover = { git = "https://github.com/scroll-tech/zkevm-circuits.git", tag = "v0.9.8", default-features = false, features = ["parallel_syn", "scroll", "shanghai", "strict-ccc"] } base64 = "0.13.0" env_logger = "0.9.0" diff --git a/common/version/version.go b/common/version/version.go index 7e18ebb7e3..a97953e2db 100644 --- a/common/version/version.go +++ b/common/version/version.go @@ -5,7 +5,7 @@ import ( "runtime/debug" ) -var tag = "v4.3.40" +var tag = "v4.3.43" var commit = func() string { if info, ok := debug.ReadBuildInfo(); ok { diff --git a/prover/core/prover_test.go b/prover/core/prover_test.go index 12fd1a56b1..2643391381 100644 --- a/prover/core/prover_test.go +++ b/prover/core/prover_test.go @@ -92,7 +92,9 @@ func TestFFI(t *testing.T) { func readChunkTrace(filePat string, as *assert.Assertions) []*types.BlockTrace { f, err := os.Open(filePat) as.NoError(err) - defer as.NoError(f.Close()) + defer func() { + as.NoError(f.Close()) + }() byt, err := io.ReadAll(f) as.NoError(err) @@ -105,7 +107,9 @@ func readChunkTrace(filePat string, as *assert.Assertions) []*types.BlockTrace { func readVk(filePat string, as *assert.Assertions) string { f, err := os.Open(filePat) as.NoError(err) - defer as.NoError(f.Close()) + defer func() { + as.NoError(f.Close()) + }() byt, err := io.ReadAll(f) as.NoError(err) diff --git a/rollup/internal/controller/relayer/l2_relayer.go b/rollup/internal/controller/relayer/l2_relayer.go index ca10f6ba89..fdcf637926 100644 --- a/rollup/internal/controller/relayer/l2_relayer.go +++ b/rollup/internal/controller/relayer/l2_relayer.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "math/big" + "sort" "sync" "time" @@ -488,7 +489,7 @@ func (r *Layer2Relayer) finalizeBatch(batch *orm.Batch, withProof bool) error { // Check batch status before send `finalizeBatch` tx. if r.cfg.ChainMonitor.Enabled { var batchStatus bool - batchStatus, err := r.getBatchStatusByIndex(batch.Index) + batchStatus, err := r.getBatchStatusByIndex(batch) if err != nil { r.metrics.rollupL2ChainMonitorLatestFailedCall.Inc() log.Warn("failed to get batch status, please check chain_monitor api server", "batch_index", batch.Index, "err", err) @@ -602,9 +603,32 @@ type batchStatusResponse struct { Data bool `json:"data"` } -func (r *Layer2Relayer) getBatchStatusByIndex(batchIndex uint64) (bool, error) { +func (r *Layer2Relayer) getBatchStatusByIndex(batch *orm.Batch) (bool, error) { + chunks, getChunkErr := r.chunkOrm.GetChunksInRange(r.ctx, batch.StartChunkIndex, batch.EndChunkIndex) + if getChunkErr != nil { + log.Error("Layer2Relayer.getBatchStatusByIndex get chunks range failed", "startChunkIndex", batch.StartChunkIndex, "endChunkIndex", batch.EndChunkIndex, "err", getChunkErr) + return false, getChunkErr + } + if len(chunks) == 0 { + log.Error("Layer2Relayer.getBatchStatusByIndex get empty chunks", "startChunkIndex", batch.StartChunkIndex, "endChunkIndex", batch.EndChunkIndex) + return false, fmt.Errorf("startChunksIndex:%d endChunkIndex:%d get empty chunks", batch.StartChunkIndex, batch.EndChunkIndex) + } + + sort.Slice(chunks, func(i, j int) bool { + return chunks[i].StartBlockNumber < chunks[j].StartBlockNumber + }) + + startBlockNum := chunks[0].StartBlockNumber + endBlockNum := chunks[len(chunks)-1].EndBlockNumber var response batchStatusResponse - resp, err := r.chainMonitorClient.R().SetResult(&response).Get(fmt.Sprintf("%s/v1/batch_status?batch_index=%d", r.cfg.ChainMonitor.BaseURL, batchIndex)) + resp, err := r.chainMonitorClient.R(). + SetQueryParams(map[string]string{ + "batch_index": fmt.Sprintf("%d", batch.Index), + "start_block_number": fmt.Sprintf("%d", startBlockNum), + "end_block_number": fmt.Sprintf("%d", endBlockNum), + }). + SetResult(&response). + Get(fmt.Sprintf("%s/v1/batch_status", r.cfg.ChainMonitor.BaseURL)) if err != nil { return false, err } diff --git a/rollup/internal/controller/relayer/l2_relayer_test.go b/rollup/internal/controller/relayer/l2_relayer_test.go index 5b46be7946..6bd81aa648 100644 --- a/rollup/internal/controller/relayer/l2_relayer_test.go +++ b/rollup/internal/controller/relayer/l2_relayer_test.go @@ -423,12 +423,30 @@ func testGetBatchStatusByIndex(t *testing.T) { db := setupL2RelayerDB(t) defer database.CloseDB(db) + l2BlockOrm := orm.NewL2Block(db) + err := l2BlockOrm.InsertL2Blocks(context.Background(), []*types.WrappedBlock{wrappedBlock1, wrappedBlock2}) + assert.NoError(t, err) + chunkOrm := orm.NewChunk(db) + dbChunk1, err := chunkOrm.InsertChunk(context.Background(), chunk1) + assert.NoError(t, err) + dbChunk2, err := chunkOrm.InsertChunk(context.Background(), chunk2) + assert.NoError(t, err) + batchMeta := &types.BatchMeta{ + StartChunkIndex: 0, + StartChunkHash: dbChunk1.Hash, + EndChunkIndex: 1, + EndChunkHash: dbChunk2.Hash, + } + batchOrm := orm.NewBatch(db) + batch, err := batchOrm.InsertBatch(context.Background(), []*types.Chunk{chunk1, chunk2}, batchMeta) + assert.NoError(t, err) + cfg.L2Config.RelayerConfig.ChainMonitor.Enabled = true relayer, err := NewLayer2Relayer(context.Background(), l2Cli, db, cfg.L2Config.RelayerConfig, false, nil) assert.NoError(t, err) assert.NotNil(t, relayer) - status, err := relayer.getBatchStatusByIndex(1) + status, err := relayer.getBatchStatusByIndex(batch) assert.NoError(t, err) assert.Equal(t, true, status) }