这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Improvements

* [#517](https://github.com/babylonlabs-io/finality-provider/pull/518) feat: rollup BSN finality provider setup
* [#493](https://github.com/babylonlabs-io/finality-provider/pull/493) chore: key migration for test keyring
* [#501](https://github.com/babylonlabs-io/finality-provider/pull/501) chore: signing context
* [#500](https://github.com/babylonlabs-io/finality-provider/pull/500) feat: fpd abstract poller implementation
Expand All @@ -52,6 +51,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
* [515](https://github.com/babylonlabs-io/finality-provider/pull/515) chore: abstract randomness committer
* [#522](https://github.com/babylonlabs-io/finality-provider/pull/522) cli: refactor CLIs and generalise for rollup FPs
* [516](https://github.com/babylonlabs-io/finality-provider/pull/516) chore: abstract bootstrap
* [#517](https://github.com/babylonlabs-io/finality-provider/pull/518) feat: rollup BSN finality provider setup
* [#526](https://github.com/babylonlabs-io/finality-provider/pull/526) rollup: remove dependency to finality gadget

## v1.1.0-rc.1

Expand Down
73 changes: 7 additions & 66 deletions bsn/rollup-finality-provider/clientcontroller/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"math"
"math/big"

sdkErr "cosmossdk.io/errors"
Expand All @@ -31,10 +30,6 @@ import (
"go.uber.org/zap"
)

const (
BabylonChainName = "Babylon"
)

var _ api.ConsumerController = &RollupBSNController{}

// nolint:revive // Ignore stutter warning - full name provides clarity
Expand Down Expand Up @@ -98,8 +93,9 @@ func (cc *RollupBSNController) ReliablySendMsg(ctx context.Context, msg sdk.Msg,
return cc.reliablySendMsgs(ctx, []sdk.Msg{msg}, expectedErrs, unrecoverableErrs)
}

// QueryContractConfig queries the finality contract for its config
func (cc *RollupBSNController) QueryContractConfig(ctx context.Context) (*Config, error) {
// queryContractConfig queries the finality contract for its config
// nolint:unused
func (cc *RollupBSNController) queryContractConfig(ctx context.Context) (*Config, error) {
query := QueryMsg{
Config: &Config{},
}
Expand Down Expand Up @@ -207,7 +203,7 @@ func (cc *RollupBSNController) SubmitBatchFinalitySigs(
FpPubkeyHex: fpPkHex,
Height: block.GetHeight(),
PubRand: bbntypes.NewSchnorrPubRandFromFieldVal(req.PubRandList[i]).MustMarshal(),
Proof: ConvertProof(cmtProof),
Proof: convertProof(cmtProof),
BlockHash: block.Hash,
Signature: bbntypes.NewSchnorrEOTSSigFromModNScalar(req.Sigs[i]).MustMarshal(),
},
Expand Down Expand Up @@ -399,7 +395,8 @@ func (cc *RollupBSNController) QueryBlock(ctx context.Context, height uint64) (t

// Note: this is specific to the RollupBSNController and only used for testing
// QueryBlock returns the Ethereum block from a RPC call
func (cc *RollupBSNController) QueryEthBlock(ctx context.Context, height uint64) (*ethtypes.Header, error) {
// nolint:unused
func (cc *RollupBSNController) queryEthBlock(ctx context.Context, height uint64) (*ethtypes.Header, error) {
return cc.ethClient.HeaderByNumber(ctx, new(big.Int).SetUint64(height))
}

Expand Down Expand Up @@ -497,7 +494,7 @@ func (cc *RollupBSNController) UnjailFinalityProvider(_ context.Context, _ *btce
return nil, nil
}

func ConvertProof(cmtProof cmtcrypto.Proof) Proof {
func convertProof(cmtProof cmtcrypto.Proof) Proof {
return Proof{
Total: uint64(cmtProof.Total), // #nosec G115
Index: uint64(cmtProof.Index), // #nosec G115
Expand All @@ -506,62 +503,6 @@ func ConvertProof(cmtProof cmtcrypto.Proof) Proof {
}
}

// GetBlockNumberByTimestamp returns the L2 block number for the given BTC staking activation timestamp.
// It uses a binary search to find the block number.
func (cc *RollupBSNController) GetBlockNumberByTimestamp(ctx context.Context, targetTimestamp uint64) (uint64, error) {
// Check if the target timestamp is after the latest block
latestBlock, err := cc.ethClient.HeaderByNumber(ctx, nil)
if err != nil {
return math.MaxUint64, err
}
if targetTimestamp > latestBlock.Time {
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.ethClient.HeaderByNumber(ctx, big.NewInt(1))
if err != nil {
return math.MaxUint64, err
}

// let's say block 0 is at t0 and block 1 at t1
// if t0 < targetTimestamp < t1, the activated height should be block 1
if targetTimestamp < firstBlock.Time {
return uint64(1), nil
}

// binary search between block 1 and the latest block
// start from block 1, b/c some L2s such as OP mainnet, block 0 is genesis block with timestamp 0
lowerBound := uint64(1)
upperBound := latestBlock.Number.Uint64()

for lowerBound <= upperBound {
midBlockNumber := (lowerBound + upperBound) / 2
block, err := cc.ethClient.HeaderByNumber(ctx, big.NewInt(int64(midBlockNumber))) // #nosec G115
if err != nil {
return math.MaxUint64, err
}

switch {
case block.Time < targetTimestamp:
lowerBound = midBlockNumber + 1
case block.Time > targetTimestamp:
upperBound = midBlockNumber - 1
default:
return midBlockNumber, nil
}
}

return lowerBound, nil
}

// QueryFinalityProviderSlashedOrJailed - returns if the fp has been slashed, jailed, err
// nolint:revive // Ignore stutter warning - full name provides clarity
func (cc *RollupBSNController) QueryFinalityProviderSlashedOrJailed(fpPk *btcec.PublicKey) (bool, bool, error) {
// TODO: implement slashed or jailed feature in rollup BSN
return false, false, nil
}

func (cc *RollupBSNController) Close() error {
cc.ethClient.Close()

Expand Down
5 changes: 2 additions & 3 deletions bsn/rollup-finality-provider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ const (
)

type RollupFPConfig struct {
RollupNodeRPCAddress string `long:"rollup-node-rpc-address" description:"the rpc address of the rollup node to connect to"`
BabylonFinalityGadgetRpc string `long:"babylon-finality-gadget-rpc" description:"the rpc address of rollup finality gadget"` //nolint:stylecheck,revive
FinalityContractAddress string `long:"finality-contract-address" description:"the contract address of the rollup finality contract"`
RollupNodeRPCAddress string `long:"rollup-node-rpc-address" description:"the rpc address of the rollup node to connect to"`
FinalityContractAddress string `long:"finality-contract-address" description:"the contract address of the rollup finality contract"`

// Below configurations are needed for the Babylon client
Common *fpcfg.Config
Expand Down
4 changes: 1 addition & 3 deletions bsn/rollup-finality-provider/e2e/op_test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,7 @@ func createRollupFpConfig(
FinalityContractAddress: "",
// it must be a dialable RPC address checked by NewRollupBSNController
RollupNodeRPCAddress: "https://optimism-sepolia.drpc.org",
// the value does not matter for the test
BabylonFinalityGadgetRpc: "127.0.0.1:50051",
Common: cfg,
Common: cfg,
}

return opConsumerCfg
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
cosmossdk.io/math v1.5.3
github.com/avast/retry-go/v4 v4.5.1
github.com/babylonlabs-io/babylon-sdk/demo v0.0.0-20250710070516-a8ad676746c1
github.com/babylonlabs-io/finality-gadget v0.1.1
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.6
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,6 @@ github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20250407051200-a5d652116d6d h1:9z
github.com/babylonlabs-io/babylon-sdk/x v0.0.0-20250407051200-a5d652116d6d/go.mod h1:ks4/p72aNJTIN8+CnCFxNX0HqfgHdClEwU4LxAxryJQ=
github.com/babylonlabs-io/babylon/v3 v3.0.0-snapshot.250711 h1:l95QWwd3hGek0LYiYGp+8I8ljADXApRbshugjMg+1Oo=
github.com/babylonlabs-io/babylon/v3 v3.0.0-snapshot.250711/go.mod h1:/X1bVC4WUKDBxRTazXvZd/6WINc2tqXAtZOBJknM8OA=
github.com/babylonlabs-io/finality-gadget v0.1.1 h1:izW+sxtrsVPC9FlGx0wzWTJqRk+buEw9zfV7nXKQmWA=
github.com/babylonlabs-io/finality-gadget v0.1.1/go.mod h1:+BICJA7mUJpfYOSYds1G5w6nLO0gKVe9XwdmpIUiXmk=
github.com/babylonlabs-io/tokenfactory v0.50.6-wasmvm2 h1:7wtBLjwncBsYgc+LlW4eir/bGcycrhpbz7PkUVADzBc=
github.com/babylonlabs-io/tokenfactory v0.50.6-wasmvm2/go.mod h1:L8XfncoH1M6fOrzqfRVQZePqo54ZlTDdatUpEr0Iz/E=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down