Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Oct 10, 2024
2 parents 7f1281c + e694b2c commit c6dff0b
Show file tree
Hide file tree
Showing 19 changed files with 327 additions and 329 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/backport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Adapted from https://github.com/marketplace/actions/backporting
#
# Usage:
# - Let's say you want to backport a pull request on a branch named `production`.
# - Then label it with `backport production`.
# - That's it! When the pull request gets merged, it will be backported to
# the `production` branch. If the pull request cannot be backported, a comment
# explaining why will automatically be posted.
#
# Note: multiple backport labels can be added. For example, if a pull request
# has the labels `backport staging` and `backport production` it will be
# backported to both branches: `staging` and `production`.
name: Backport
on:
pull_request_target:
types:
- closed
- labeled

jobs:
backport:
name: Backport
runs-on: ubuntu-latest
# Only react to merged PRs for security reasons.
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target.
if: >
github.event.pull_request.merged
&& (
github.event.action == 'closed'
|| (
github.event.action == 'labeled'
&& contains(github.event.label.name, 'backport')
)
)
steps:
- uses: tibdex/backport@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.6.0
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.7.0
with:
run-unit-tests: true
run-integration-tests: true
Expand All @@ -16,8 +16,12 @@ jobs:
run-gosec: true
gosec-args: "-exclude-generated -exclude-dir=itest -exclude-dir=testutil ./..."

changelog_reminder:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
secrets: inherit

docker_pipeline:
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.6.0
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.7.0
secrets: inherit
with:
publish: false
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: goreleaser

on:
push:
tags:
- '*'

jobs:
release:
uses: babylonlabs-io/.github/.github/workflows/[email protected]
secrets: inherit
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
lint_test:
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.6.0
uses: babylonlabs-io/.github/.github/workflows/reusable_go_lint_test.yml@v0.7.0
with:
run-unit-tests: true
run-integration-tests: true
Expand All @@ -20,7 +20,7 @@ jobs:

docker_pipeline:
needs: ["lint_test"]
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.6.0
uses: babylonlabs-io/.github/.github/workflows/reusable_docker_pipeline.yml@v0.7.0
secrets: inherit
with:
publish: true
Expand Down
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
Guiding Principles:
Changelogs are for humans, not machines.
There should be an entry for every single version.
The same types of changes should be grouped.
Versions and sections should be linkable.
The latest version comes first.
The release date of each version is displayed.
Mention whether you follow Semantic Versioning.
Usage:
Change log entries are to be added to the Unreleased section under the
appropriate stanza (see below). Each entry should have following format:
* [#PullRequestNumber](PullRequestLink) message
Types of changes (Stanzas):
"Features" for new features.
"Improvements" for changes in existing functionality.
"Deprecated" for soon-to-be removed features.
"Bug Fixes" for any bug fixes.
"Client Breaking" for breaking CLI commands and REST routes used by end-users.
"API Breaking" for breaking exported APIs used by developers building on SDK.
"State Machine Breaking" for any changes that result in a different AppState
given same genesisState and txList.
Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased
32 changes: 14 additions & 18 deletions finality-provider/cmd/fpd/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,31 @@ func startApp(
fpApp *service.FinalityProviderApp,
fpPkStr, passphrase string,
) error {
// only start the app without starting any finality-provider instance
// as there might be no finality-provider registered yet
// only start the app without starting any finality provider instance
// this is needed for new finality provider registration or unjailing
// finality providers
if err := fpApp.Start(); err != nil {
return fmt.Errorf("failed to start the finality-provider app: %w", err)
return fmt.Errorf("failed to start the finality provider app: %w", err)
}

if fpPkStr != "" {
// start the finality-provider instance with the given public key
fpPk, err := types.NewBIP340PubKeyFromHex(fpPkStr)
if err != nil {
return fmt.Errorf("invalid finality-provider public key %s: %w", fpPkStr, err)
}
// no fp instance will be started if public key is not specified
if fpPkStr == "" {
return nil
}

if err := fpApp.StartHandlingFinalityProvider(fpPk, passphrase); err != nil {
if errors.Is(err, service.ErrFinalityProviderJailed) {
fpApp.Logger().Error("failed to start finality provider", zap.Error(err))
// do not return error as we still want the service to start
return nil
}
return fmt.Errorf("failed to start the finality-provider instance %s: %w", fpPkStr, err)
}
// start the finality-provider instance with the given public key
fpPk, err := types.NewBIP340PubKeyFromHex(fpPkStr)
if err != nil {
return fmt.Errorf("invalid finality provider public key %s: %w", fpPkStr, err)
}

if err := fpApp.StartHandlingAll(); err != nil {
if err := fpApp.StartHandlingFinalityProvider(fpPk, passphrase); err != nil {
if errors.Is(err, service.ErrFinalityProviderJailed) {
fpApp.Logger().Error("failed to start finality provider", zap.Error(err))
// do not return error as we still want the service to start
return nil
}
return fmt.Errorf("failed to start the finality-provider instance %s: %w", fpPkStr, err)
}

return nil
Expand Down
3 changes: 0 additions & 3 deletions finality-provider/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const (
defaultMaxSubmissionRetries = 20
defaultBitcoinNetwork = "signet"
defaultDataDirname = "data"
defaultMaxNumFinalityProviders = 3
)

var (
Expand Down Expand Up @@ -69,7 +68,6 @@ type Config struct {
FastSyncLimit uint32 `long:"fastsynclimit" description:"The maximum number of blocks to catch up for each fast sync"`
FastSyncGap uint64 `long:"fastsyncgap" description:"The block gap that will trigger the fast sync"`
EOTSManagerAddress string `long:"eotsmanageraddress" description:"The address of the remote EOTS manager; Empty if the EOTS manager is running locally"`
MaxNumFinalityProviders uint32 `long:"maxnumfinalityproviders" description:"The maximum number of finality-provider instances running concurrently within the daemon"`
SyncFpStatusInterval time.Duration `long:"syncfpstatusinterval" description:"The duration of time that it should sync FP status with the client blockchain"`

BitcoinNetwork string `long:"bitcoinnetwork" description:"Bitcoin network to run on" choise:"mainnet" choice:"regtest" choice:"testnet" choice:"simnet" choice:"signet"`
Expand Down Expand Up @@ -112,7 +110,6 @@ func DefaultConfigWithHome(homePath string) Config {
BTCNetParams: defaultBTCNetParams,
EOTSManagerAddress: defaultEOTSManagerAddress,
RpcListener: DefaultRpcListener,
MaxNumFinalityProviders: defaultMaxNumFinalityProviders,
Metrics: metrics.DefaultFpConfig(),
SyncFpStatusInterval: defaultSyncFpStatusInterval,
}
Expand Down
14 changes: 3 additions & 11 deletions finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ func (app *FinalityProviderApp) Logger() *zap.Logger {
return app.logger
}

func (app *FinalityProviderApp) ListFinalityProviderInstances() []*FinalityProviderInstance {
return app.fpManager.ListFinalityProviderInstances()
}

func (app *FinalityProviderApp) ListAllFinalityProvidersInfo() ([]*proto.FinalityProviderInfo, error) {
return app.fpManager.AllFinalityProviders()
}
Expand All @@ -164,8 +160,8 @@ func (app *FinalityProviderApp) GetFinalityProviderInfo(fpPk *bbntypes.BIP340Pub
}

// GetFinalityProviderInstance returns the finality-provider instance with the given Babylon public key
func (app *FinalityProviderApp) GetFinalityProviderInstance(fpPk *bbntypes.BIP340PubKey) (*FinalityProviderInstance, error) {
return app.fpManager.GetFinalityProviderInstance(fpPk)
func (app *FinalityProviderApp) GetFinalityProviderInstance() (*FinalityProviderInstance, error) {
return app.fpManager.GetFinalityProviderInstance()
}

func (app *FinalityProviderApp) RegisterFinalityProvider(fpPkStr string) (*RegisterFinalityProviderResponse, error) {
Expand Down Expand Up @@ -220,16 +216,12 @@ func (app *FinalityProviderApp) RegisterFinalityProvider(fpPkStr string) (*Regis
}
}

// StartHandlingFinalityProvider starts a finality-provider instance with the given Babylon public key
// StartHandlingFinalityProvider starts a finality provider instance with the given EOTS public key
// Note: this should be called right after the finality-provider is registered
func (app *FinalityProviderApp) StartHandlingFinalityProvider(fpPk *bbntypes.BIP340PubKey, passphrase string) error {
return app.fpManager.StartFinalityProvider(fpPk, passphrase)
}

func (app *FinalityProviderApp) StartHandlingAll() error {
return app.fpManager.StartAll()
}

// NOTE: this is not safe in production, so only used for testing purpose
func (app *FinalityProviderApp) getFpPrivKey(fpPk []byte) (*btcec.PrivateKey, error) {
record, err := app.eotsManager.KeyRecord(fpPk, "")
Expand Down
4 changes: 2 additions & 2 deletions finality-provider/service/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func FuzzRegisterFinalityProvider(f *testing.F) {
err = app.StartHandlingFinalityProvider(fp.GetBIP340BTCPK(), passphrase)
require.NoError(t, err)

fpAfterReg, err := app.GetFinalityProviderInstance(fp.GetBIP340BTCPK())
fpAfterReg, err := app.GetFinalityProviderInstance()
require.NoError(t, err)
require.Equal(t, proto.FinalityProviderStatus_REGISTERED, fpAfterReg.GetStoreFinalityProvider().Status)

Expand Down Expand Up @@ -210,7 +210,7 @@ func FuzzSyncFinalityProviderStatus(f *testing.F) {
if noVotingPowerTable {
expectedStatus = proto.FinalityProviderStatus_REGISTERED
}
fpInstance, err := app.GetFinalityProviderInstance(fpPk)
fpInstance, err := app.GetFinalityProviderInstance()
if err != nil {
return false
}
Expand Down
7 changes: 3 additions & 4 deletions finality-provider/service/fp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ func NewFinalityProviderInstance(
) (*FinalityProviderInstance, error) {
sfp, err := s.GetFinalityProvider(fpPk.MustToBTCPK())
if err != nil {
return nil, fmt.Errorf("failed to retrive the finality-provider %s from DB: %w", fpPk.MarshalHex(), err)
return nil, fmt.Errorf("failed to retrive the finality provider %s from DB: %w", fpPk.MarshalHex(), err)
}

// ensure the finality-provider has been registered
if sfp.Status < proto.FinalityProviderStatus_REGISTERED {
return nil, fmt.Errorf("the finality-provider %s has not been registered", sfp.KeyName)
if !sfp.ShouldStart() {
return nil, fmt.Errorf("the finality provider instance cannot be initiated with status %s", sfp.Status.String())
}

return &FinalityProviderInstance{
Expand Down
3 changes: 1 addition & 2 deletions finality-provider/service/fp_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/babylonlabs-io/babylon/testutil/datagen"
ftypes "github.com/babylonlabs-io/babylon/x/finality/types"

"github.com/babylonlabs-io/finality-provider/clientcontroller"
"github.com/babylonlabs-io/finality-provider/eotsmanager"
eotscfg "github.com/babylonlabs-io/finality-provider/eotsmanager/config"
Expand Down Expand Up @@ -120,8 +121,6 @@ func startFinalityProviderAppWithRegisteredFp(t *testing.T, r *rand.Rand, cc cli
require.NoError(t, err)
err = app.Start()
require.NoError(t, err)
err = app.StartHandlingAll()
require.NoError(t, err)

// create registered finality-provider
fp := testutil.GenStoredFinalityProvider(r, t, app, passphrase, hdPath, nil)
Expand Down
Loading

0 comments on commit c6dff0b

Please sign in to comment.