Skip to content

Commit

Permalink
Merge branch 'main' into devops/add-docker-sec
Browse files Browse the repository at this point in the history
  • Loading branch information
huynaism authored Nov 20, 2024
2 parents 7ee8a99 + e052ab3 commit 8e621e7
Show file tree
Hide file tree
Showing 60 changed files with 2,613 additions and 1,157 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
with:
go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: true
run-lint: true
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
with:
go-version: '1.23'
go-lint-version: 'v1.60.2'
run-unit-tests: true
run-integration-tests: true
run-lint: true
Expand Down
81 changes: 81 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
run:
timeout: 5m

linters:
disable-all: true
enable:
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- dogsled
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- forbidigo
- forcetypeassert
- goconst
- gocritic
- gocyclo
- goheader
- gomodguard
- goprintffuncname
- gosimple
- govet
- grouper
- importas
- ineffassign
- loggercheck
- maintidx
- makezero
- misspell
- nakedret
- nilerr
# - nlreturn # Style wise I personally like this one, todo(lazar): unlax at somepoint, good practice
- noctx
- nonamedreturns
- nosprintfhostport
- paralleltest
- reassign
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- stylecheck
- tenv
- testableexamples
- tparallel
- typecheck
- unconvert
- unparam
- usestdlibvars
- unused
- wastedassign
- whitespace
# - wrapcheck # we really should be using this, lax for now todo(lazar): unlax at somepoint, good practice

issues:
max-same-issues: 0
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude-dirs:
- e2etest
- itest
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- nonamedreturns
- unparam
- path-except: _test\.go
linters:
- forbidigo
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#132](https://github.com/babylonlabs-io/finality-provider/pull/132) Replace fast sync with batch processing

### Documentation

[#120](https://github.com/babylonlabs-io/finality-provider/pull/120) Spec of
finality vote submission

## v0.11.0

### Improvements

* [#126](https://github.com/babylonlabs-io/finality-provider/pull/126) Adds linting config
* [#128](https://github.com/babylonlabs-io/finality-provider/pull/128) Upgrade Babylon to v0.16.0

### Documentation

* [#117](https://github.com/babylonlabs-io/finality-provider/pull/117) Spec of
commit public randomness

### Bug Fixes

* [#124](https://github.com/babylonlabs-io/finality-provider/pull/124) Ignore
duplicated finality vote error

## v0.10.0

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The following graphic demonstrates the interconnections between the above progra

### Prerequisites

This project requires Go version 1.21 or later.
This project requires Go version 1.23 or later.

Install Go by following the instructions on
the [official Go installation guide](https://golang.org/doc/install).
Expand Down
70 changes: 28 additions & 42 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
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"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/btcutil"
Expand All @@ -29,6 +27,9 @@ import (
"github.com/cosmos/relayer/v2/relayer/provider"
"go.uber.org/zap"
protobuf "google.golang.org/protobuf/proto"

fpcfg "github.com/babylonlabs-io/finality-provider/finality-provider/config"
"github.com/babylonlabs-io/finality-provider/types"
)

var _ ClientController = &BabylonController{}
Expand All @@ -47,7 +48,6 @@ func NewBabylonController(
btcParams *chaincfg.Params,
logger *zap.Logger,
) (*BabylonController, error) {

bbnConfig := fpcfg.BBNConfigToBabylonConfig(cfg)

bc, err := bbnclient.New(
Expand Down Expand Up @@ -186,33 +186,10 @@ func (bc *BabylonController) SubmitFinalitySig(
proof []byte, // TODO: have a type for proof
sig *btcec.ModNScalar,
) (*types.TxResponse, error) {
cmtProof := cmtcrypto.Proof{}
if err := cmtProof.Unmarshal(proof); err != nil {
return nil, err
}

msg := &finalitytypes.MsgAddFinalitySig{
Signer: bc.mustGetTxSigner(),
FpBtcPk: bbntypes.NewBIP340PubKeyFromBTCPK(fpPk),
BlockHeight: block.Height,
PubRand: bbntypes.NewSchnorrPubRandFromFieldVal(pubRand),
Proof: &cmtProof,
BlockAppHash: block.Hash,
FinalitySig: bbntypes.NewSchnorrEOTSSigFromModNScalar(sig),
}

unrecoverableErrs := []*sdkErr.Error{
finalitytypes.ErrInvalidFinalitySig,
finalitytypes.ErrPubRandNotFound,
btcstakingtypes.ErrFpAlreadySlashed,
}

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

return &types.TxResponse{TxHash: res.TxHash, Events: res.Events}, nil
return bc.SubmitBatchFinalitySigs(
fpPk, []*types.BlockInfo{block}, []*btcec.FieldVal{pubRand},
[][]byte{proof}, []*btcec.ModNScalar{sig},
)
}

// SubmitBatchFinalitySigs submits a batch of finality signatures to Babylon
Expand Down Expand Up @@ -252,11 +229,19 @@ func (bc *BabylonController) SubmitBatchFinalitySigs(
btcstakingtypes.ErrFpAlreadySlashed,
}

res, err := bc.reliablySendMsgs(msgs, emptyErrs, unrecoverableErrs)
expectedErrs := []*sdkErr.Error{
finalitytypes.ErrDuplicatedFinalitySig,
}

res, err := bc.reliablySendMsgs(msgs, expectedErrs, unrecoverableErrs)
if err != nil {
return nil, err
}

if res == nil {
return &types.TxResponse{}, nil
}

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

Expand All @@ -281,11 +266,12 @@ func (bc *BabylonController) UnjailFinalityProvider(fpPk *btcec.PublicKey) (*typ
return &types.TxResponse{TxHash: res.TxHash, Events: res.Events}, nil
}

func (bc *BabylonController) QueryFinalityProviderSlashedOrJailed(fpPk *btcec.PublicKey) (slashed bool, jailed bool, err error) {
// QueryFinalityProviderSlashedOrJailed - returns if the fp has been slashed, jailed, err
func (bc *BabylonController) QueryFinalityProviderSlashedOrJailed(fpPk *btcec.PublicKey) (bool, bool, error) {
fpPubKey := bbntypes.NewBIP340PubKeyFromBTCPK(fpPk)
res, err := bc.bbnClient.QueryClient.FinalityProvider(fpPubKey.MarshalHex())
if err != nil {
return false, false, fmt.Errorf("failed to query the finality provider %s: %v", fpPubKey.MarshalHex(), err)
return false, false, fmt.Errorf("failed to query the finality provider %s: %w", fpPubKey.MarshalHex(), err)
}

return res.FinalityProvider.SlashedBtcHeight > 0, res.FinalityProvider.Jailed, nil
Expand Down Expand Up @@ -347,7 +333,7 @@ func (bc *BabylonController) queryLatestBlocks(startKey []byte, count uint64, st

res, err := bc.bbnClient.QueryClient.ListBlocks(status, pagination)
if err != nil {
return nil, fmt.Errorf("failed to query finalized blocks: %v", err)
return nil, fmt.Errorf("failed to query finalized blocks: %w", err)
}

for _, b := range res.Blocks {
Expand Down Expand Up @@ -509,7 +495,7 @@ func (bc *BabylonController) QueryFinalityProviders() ([]*btcstakingtypes.Finali
for {
res, err := bc.bbnClient.QueryClient.FinalityProviders(pagination)
if err != nil {
return nil, fmt.Errorf("failed to query finality providers: %v", err)
return nil, fmt.Errorf("failed to query finality providers: %w", err)
}
fps = append(fps, res.FinalityProviders...)
if res.Pagination == nil || res.Pagination.NextKey == nil {
Expand All @@ -526,7 +512,7 @@ func (bc *BabylonController) QueryFinalityProvider(fpPk *btcec.PublicKey) (*btcs
fpPubKey := bbntypes.NewBIP340PubKeyFromBTCPK(fpPk)
res, err := bc.bbnClient.QueryClient.FinalityProvider(fpPubKey.MarshalHex())
if err != nil {
return nil, fmt.Errorf("failed to query the finality provider %s: %v", fpPubKey.MarshalHex(), err)
return nil, fmt.Errorf("failed to query the finality provider %s: %w", fpPubKey.MarshalHex(), err)
}

return res, nil
Expand Down Expand Up @@ -580,7 +566,7 @@ func (bc *BabylonController) EditFinalityProvider(fpPk *btcec.PublicKey,

_, err = bc.reliablySendMsg(msg, emptyErrs, emptyErrs)
if err != nil {
return nil, fmt.Errorf("failed to query the finality provider %s: %v", fpPk.SerializeCompressed(), err)
return nil, fmt.Errorf("failed to query the finality provider %s: %w", fpPk.SerializeCompressed(), err)
}

return msg, nil
Expand All @@ -589,7 +575,7 @@ func (bc *BabylonController) EditFinalityProvider(fpPk *btcec.PublicKey,
func (bc *BabylonController) QueryBtcLightClientTip() (*btclctypes.BTCHeaderInfoResponse, error) {
res, err := bc.bbnClient.QueryClient.BTCHeaderChainTip()
if err != nil {
return nil, fmt.Errorf("failed to query BTC tip: %v", err)
return nil, fmt.Errorf("failed to query BTC tip: %w", err)
}

return res.Header, nil
Expand All @@ -598,7 +584,7 @@ func (bc *BabylonController) QueryBtcLightClientTip() (*btclctypes.BTCHeaderInfo
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 0, fmt.Errorf("failed to query BTC tip: %w", err)
}

return res.CurrentEpoch, nil
Expand Down Expand Up @@ -631,7 +617,7 @@ func (bc *BabylonController) queryDelegationsWithStatus(status btcstakingtypes.B

res, err := bc.bbnClient.QueryClient.BTCDelegations(status, pagination)
if err != nil {
return nil, fmt.Errorf("failed to query BTC delegations: %v", err)
return nil, fmt.Errorf("failed to query BTC delegations: %w", err)
}

return res.BtcDelegations, nil
Expand All @@ -641,13 +627,13 @@ func (bc *BabylonController) QueryStakingParams() (*types.StakingParams, error)
// query btc checkpoint params
ckptParamRes, err := bc.bbnClient.QueryClient.BTCCheckpointParams()
if err != nil {
return nil, fmt.Errorf("failed to query params of the btccheckpoint module: %v", err)
return nil, fmt.Errorf("failed to query params of the btccheckpoint module: %w", err)
}

// query btc staking params
stakingParamRes, err := bc.bbnClient.QueryClient.BTCStakingParams()
if err != nil {
return nil, fmt.Errorf("failed to query staking params: %v", err)
return nil, fmt.Errorf("failed to query staking params: %w", err)
}

covenantPks := make([]*btcec.PublicKey, 0, len(stakingParamRes.Params.CovenantPks))
Expand Down
1 change: 1 addition & 0 deletions clientcontroller/retry_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

func TestExpectedErr(t *testing.T) {
t.Parallel()
expectedErr := Expected(fmt.Errorf("some error"))
require.True(t, IsExpected(expectedErr))
wrappedErr := fmt.Errorf("expected: %w", expectedErr)
Expand Down
Loading

0 comments on commit 8e621e7

Please sign in to comment.