From 368272b535b4bc29f236ee515b04dbb8b8a6f9a6 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Mon, 4 Sep 2023 14:53:32 +0800 Subject: [PATCH] fix(gas-oracle): fetch base fee of the latest block --- database/migrate/migrate_test.go | 2 +- .../00012_drop_unique_l1_block_number.sql | 15 +++++++++++++++ rollup/cmd/gas_oracle/app/app.go | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 database/migrate/migrations/00012_drop_unique_l1_block_number.sql diff --git a/database/migrate/migrate_test.go b/database/migrate/migrate_test.go index a38d0525b3..249e93fb9c 100644 --- a/database/migrate/migrate_test.go +++ b/database/migrate/migrate_test.go @@ -63,7 +63,7 @@ func testResetDB(t *testing.T) { cur, err := Current(pgDB.DB) assert.NoError(t, err) // total number of tables. - assert.Equal(t, 11, int(cur)) + assert.Equal(t, 12, int(cur)) } func testMigrate(t *testing.T) { diff --git a/database/migrate/migrations/00012_drop_unique_l1_block_number.sql b/database/migrate/migrations/00012_drop_unique_l1_block_number.sql new file mode 100644 index 0000000000..3ee799f1be --- /dev/null +++ b/database/migrate/migrations/00012_drop_unique_l1_block_number.sql @@ -0,0 +1,15 @@ +-- +goose Up +-- +goose StatementBegin +drop index if exists l1_block_number_uindex; + +create index l1_block_number_index +on l1_block (number) where deleted_at IS NULL; +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +drop index if exists l1_block_number_index; + +create unique index if not exists l1_block_number_uindex +on l1_block (number) where deleted_at IS NULL; +-- +goose StatementEnd diff --git a/rollup/cmd/gas_oracle/app/app.go b/rollup/cmd/gas_oracle/app/app.go index ea8038a604..d61befaa65 100644 --- a/rollup/cmd/gas_oracle/app/app.go +++ b/rollup/cmd/gas_oracle/app/app.go @@ -20,7 +20,6 @@ import ( "scroll-tech/rollup/internal/config" "scroll-tech/rollup/internal/controller/relayer" "scroll-tech/rollup/internal/controller/watcher" - butils "scroll-tech/rollup/internal/utils" ) var app *cli.App @@ -92,8 +91,9 @@ func action(ctx *cli.Context) error { } // Start l1 watcher process go utils.LoopWithContext(subCtx, 10*time.Second, func(ctx context.Context) { - number, loopErr := butils.GetLatestConfirmedBlockNumber(ctx, l1client, cfg.L1Config.Confirmations) - if loopErr != nil { + // Fetch the latest block number to decrease the delay when fetching gas prices + number, loopErr := l1client.BlockNumber(ctx) + if err != nil { log.Error("failed to get block number", "err", loopErr) return }