Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: accomodate BTC-timestamping #40

Merged
merged 6 commits into from
Sep 3, 2024
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
27 changes: 27 additions & 0 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ func (bc *BabylonController) QueryBtcLightClientTip() (*btclctypes.BTCHeaderInfo
return res.Header, nil
}

func (bc *BabylonController) QueryCurrentEpoch() (uint64, error) {
res, err := bc.bbnClient.QueryClient.CurrentEpoch()
if err != nil {
return 0, fmt.Errorf("failed to query BTC tip: %v", err)
}

return res.CurrentEpoch, nil
}

func (bc *BabylonController) QueryVotesAtHeight(height uint64) ([]bbntypes.BIP340PubKey, error) {
res, err := bc.bbnClient.QueryClient.VotesAtHeight(height)
if err != nil {
Expand Down Expand Up @@ -589,3 +598,21 @@ func (bc *BabylonController) SubmitCovenantSigs(

return &types.TxResponse{TxHash: res.TxHash, Events: res.Events}, nil
}

func (bc *BabylonController) GetBBNClient() *bbnclient.Client {
return bc.bbnClient
}

func (bc *BabylonController) InsertSpvProofs(submitter string, proofs []*btcctypes.BTCSpvProof) (*provider.RelayerTxResponse, error) {
msg := &btcctypes.MsgInsertBTCSpvProof{
Submitter: submitter,
Proofs: proofs,
}

res, err := bc.reliablySendMsg(msg, emptyErrs, emptyErrs)
if err != nil {
return nil, err
}

return res, nil
}
1 change: 1 addition & 0 deletions clientcontroller/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.uber.org/zap"

finalitytypes "github.com/babylonlabs-io/babylon/x/finality/types"

fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config"
"github.com/babylonlabs-io/finality-provider/types"
)
Expand Down
2 changes: 1 addition & 1 deletion eotsmanager/proto/eotsmanager.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions eotsmanager/proto/eotsmanager_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions finality-provider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const (
defaultFinalityProviderKeyName = "finality-provider"
DefaultRPCPort = 12581
defaultConfigFileName = "fpd.conf"
defaultNumPubRand = 100
defaultNumPubRandMax = 200
defaultMinRandHeightGap = 20
defaultNumPubRand = 70000 // support running of 1 week with block production time as 10s
defaultNumPubRandMax = 100000
defaultMinRandHeightGap = 35000
defaultStatusUpdateInterval = 20 * time.Second
defaultRandomInterval = 30 * time.Second
defaultSubmitRetryInterval = 1 * time.Second
Expand Down
2 changes: 1 addition & 1 deletion finality-provider/proto/finality_providers.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 28 additions & 14 deletions finality-provider/proto/finality_providers_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions finality-provider/service/fastsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ func (fp *FinalityProviderInstance) FastSync(startHeight, endHeight uint64) (*Fa
fp.metrics.IncrementFpTotalBlocksWithoutVotingPower(fp.GetBtcPkHex())
continue
}
// check whether the randomness has been committed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: we can stop checking the randomness has been committed, because we don't need to send randomness for past blocks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because in ADR-024, a fp can only have voting power if it has BTC-timestamped pub rand for the height. At Line 57, we have already checked whether the fp has voting power. This indicates whether the fp has timestamped pub rand or not, so we don't need to check randomness here

hasRand, err := fp.hasRandomness(b)
if err != nil {
return nil, err
}
if !hasRand {
break
}
// all good, add the block for catching up
catchUpBlocks = append(catchUpBlocks, b)
}
Expand Down
11 changes: 9 additions & 2 deletions finality-provider/service/fastsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ func FuzzFastSync_NoRandomness(f *testing.F) {
_, err := fpIns.CommitPubRand(randomStartingHeight)
require.NoError(t, err)

mockClientController.EXPECT().QueryFinalityProviderVotingPower(fpIns.GetBtcPk(), gomock.Any()).
Return(uint64(1), nil).AnyTimes()
// the last height with pub rand is a random value inside [finalizedHeight+1, currentHeight]
lastHeightWithPubRand := uint64(rand.Intn(int(currentHeight)-int(finalizedHeight))) + finalizedHeight + 1
for i := randomStartingHeight; i <= currentHeight; i++ {
if i <= lastHeightWithPubRand {
mockClientController.EXPECT().QueryFinalityProviderVotingPower(fpIns.GetBtcPk(), i).
Return(uint64(1), nil).AnyTimes()
} else {
mockClientController.EXPECT().QueryFinalityProviderVotingPower(fpIns.GetBtcPk(), i).
Return(uint64(0), nil).AnyTimes()
}
}
lastCommittedPubRandMap := make(map[uint64]*ftypes.PubRandCommitResponse)
lastCommittedPubRandMap[lastHeightWithPubRand-10] = &ftypes.PubRandCommitResponse{
NumPubRand: 10 + 1,
Expand Down
Loading
Loading