Skip to content

Commit

Permalink
update for comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lesterli committed Aug 27, 2024
1 parent e55b40b commit 612f8c4
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions clientcontroller/opstackl2/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
"math/big"

sdkErr "cosmossdk.io/errors"
Expand Down Expand Up @@ -358,19 +359,19 @@ func (cc *OPStackL2ConsumerController) QueryActivatedHeight() (uint64, error) {
finalityGadgetClient, err := fgclient.NewFinalityGadgetGrpcClient(cc.Cfg.BabylonFinalityGadgetRpc)
if err != nil {
cc.logger.Error("failed to initialize Babylon Finality Gadget Grpc client", zap.Error(err))
return 0, err
return math.MaxUint64, err
}

activatedTimestamp, err := finalityGadgetClient.QueryBtcStakingActivatedTimestamp()
if err != nil {
cc.logger.Error("failed to query BTC staking activate timestamp", zap.Error(err))
return 0, err
return math.MaxUint64, err
}

l2BlockNumber, err := cc.GetBlockNumberByTimestamp(context.Background(), activatedTimestamp)
if err != nil {
cc.logger.Error("failed to convert L2 block number from the given BTC staking activation timestamp", zap.Error(err))
return 0, err
return math.MaxUint64, err
}

return l2BlockNumber, nil
Expand Down Expand Up @@ -439,18 +440,18 @@ func (cc *OPStackL2ConsumerController) GetBlockNumberByTimestamp(ctx context.Con
// Check if the target timestamp is after the latest block
latestBlock, err := cc.opl2Client.HeaderByNumber(ctx, nil)
if err != nil {
return 0, err
return math.MaxUint64, err
}
if targetTimestamp > latestBlock.Time {
return 0, nil
return math.MaxUint64, fmt.Errorf("target timestamp %d is after the latest block timestamp %d", targetTimestamp, latestBlock.Time)
}
// Check if the target timestamp is before the first block
firstBlock, err := cc.opl2Client.HeaderByNumber(ctx, big.NewInt(1))
if err != nil {
return 0, err
return math.MaxUint64, err
}
if targetTimestamp < firstBlock.Time {
return 0, nil
return uint64(1), nil
}

lowerBound := uint64(1)
Expand All @@ -460,7 +461,7 @@ func (cc *OPStackL2ConsumerController) GetBlockNumberByTimestamp(ctx context.Con
midBlockNumber := (lowerBound + upperBound) / 2
block, err := cc.opl2Client.HeaderByNumber(ctx, big.NewInt(int64(midBlockNumber)))
if err != nil {
return 0, err
return math.MaxUint64, err
}

if block.Time < targetTimestamp {
Expand Down

0 comments on commit 612f8c4

Please sign in to comment.