From c194fd74cbcd5135ddb8fa1f93ed9455b8996892 Mon Sep 17 00:00:00 2001 From: colinlyguo Date: Tue, 19 Dec 2023 06:39:04 +0800 Subject: [PATCH] testing fixes --- .../internal/controller/fetcher/l1_fetcher.go | 2 +- .../internal/logic/l1_reorg_handling.go | 10 +++++----- .../internal/logic/l2_reorg_handling.go | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bridge-history-api/internal/controller/fetcher/l1_fetcher.go b/bridge-history-api/internal/controller/fetcher/l1_fetcher.go index 3212c77ae..c502ff70b 100644 --- a/bridge-history-api/internal/controller/fetcher/l1_fetcher.go +++ b/bridge-history-api/internal/controller/fetcher/l1_fetcher.go @@ -54,7 +54,7 @@ func (c *L1MessageFetcher) Start() { if batchSyncedHeight > l1SyncHeight { l1SyncHeight = batchSyncedHeight } - if c.cfg.StartHeight > c.l1SyncHeight { + if c.cfg.StartHeight > l1SyncHeight { l1SyncHeight = c.cfg.StartHeight - 1 } diff --git a/bridge-history-api/internal/logic/l1_reorg_handling.go b/bridge-history-api/internal/logic/l1_reorg_handling.go index 934c497a3..b08ff58c4 100644 --- a/bridge-history-api/internal/logic/l1_reorg_handling.go +++ b/bridge-history-api/internal/logic/l1_reorg_handling.go @@ -34,11 +34,11 @@ func (l *L1ReorgHandlingLogic) HandleL1Reorg(ctx context.Context, blockNumber ui } if reorgDetected { - resyncHeight := uint64(1) + var resyncHeight uint64 if blockNumber > L1ReorgSafeDepth { resyncHeight = blockNumber - L1ReorgSafeDepth } - return true, resyncHeight - 1, nil + return true, resyncHeight, nil } return false, 0, nil @@ -47,17 +47,17 @@ func (l *L1ReorgHandlingLogic) HandleL1Reorg(ctx context.Context, blockNumber ui func (l *L1ReorgHandlingLogic) detectReorg(ctx context.Context, blockNumber uint64, blockHash common.Hash) (bool, error) { currentHeader, err := l.client.HeaderByNumber(ctx, big.NewInt(0).SetUint64(blockNumber)) if err != nil { - log.Error("failed to get header by number", "height", blockNumber, "err", err) + log.Error("failed to get L1 header by number", "height", blockNumber, "err", err) return false, err } if currentHeader == nil { - log.Warn("cannot fetch remote block header", "height", blockNumber, "last block hash", blockHash.String()) + log.Warn("cannot fetch current L1 block header", "height", blockNumber, "last block hash", blockHash.String()) return true, nil } if blockHash != currentHeader.Hash() { - log.Warn("block hash mismatch, reorg happened", "height", blockNumber, "last block hash", blockHash.String(), "current block hash", currentHeader.Hash().String()) + log.Warn("block hash mismatch, L1 reorg happened", "height", blockNumber, "last block hash", blockHash.String(), "current block hash", currentHeader.Hash().String()) return true, nil } diff --git a/bridge-history-api/internal/logic/l2_reorg_handling.go b/bridge-history-api/internal/logic/l2_reorg_handling.go index 53099cbf0..ec7c229f5 100644 --- a/bridge-history-api/internal/logic/l2_reorg_handling.go +++ b/bridge-history-api/internal/logic/l2_reorg_handling.go @@ -34,11 +34,11 @@ func (l *L2ReorgHandlingLogic) HandleL2Reorg(ctx context.Context, blockNumber ui } if l2ReorgDetected { - startHeight := uint64(1) + var resyncHeight uint64 if blockNumber > L2ReorgSafeDepth { - startHeight = blockNumber - L2ReorgSafeDepth + resyncHeight = blockNumber - L2ReorgSafeDepth } - return true, startHeight - 1, nil + return true, resyncHeight, nil } return false, 0, nil @@ -47,17 +47,17 @@ func (l *L2ReorgHandlingLogic) HandleL2Reorg(ctx context.Context, blockNumber ui func (l *L2ReorgHandlingLogic) detectL2Reorg(ctx context.Context, blockNumber uint64, blockHash common.Hash) (bool, error) { currentHeader, err := l.client.HeaderByNumber(ctx, big.NewInt(0).SetUint64(blockNumber)) if err != nil { - log.Error("failed to get header by number", "height", blockNumber, "err", err) + log.Error("failed to get L2 header by number", "height", blockNumber, "err", err) return false, err } if currentHeader == nil { - log.Warn("cannot fetch remote block header", "height", blockNumber, "last block hash", blockHash.String()) + log.Warn("cannot fetch current L2 block header", "height", blockNumber, "last block hash", blockHash.String()) return true, nil } if blockHash != currentHeader.Hash() { - log.Warn("block hash mismatch, reorg happened", "height", blockNumber, "last block hash", blockHash.String(), "current block hash", currentHeader.Hash().String()) + log.Warn("block hash mismatch, L2 reorg happened", "height", blockNumber, "last block hash", blockHash.String(), "current block hash", currentHeader.Hash().String()) return true, nil }