Skip to content

Commit

Permalink
add multi fps in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Dec 11, 2024
1 parent 0c0b494 commit 889676b
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 107 deletions.
6 changes: 4 additions & 2 deletions docs/finality-provider-operation.md
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,12 @@ as a centralized key management system. When starting a finality provider instan
you specify which EOTS key to use through the `--eots-pk` flag. This allows you
to run different finality provider instances using different keys from the same
EOTS Manager. Note that someone having access to your EOTS Manager
RPC will have access to all the EOTS keys held within it
RPC will have access to all the EOTS keys held within it.

For example, after registering a finality provider, you can start its daemon by
providing the EOTS public key `fpd start --eots-pk <hex-string-of-eots-public-key>`
providing the EOTS public key `fpd start --eots-pk <hex-string-of-eots-public-key>`.
Note that a single finality provider daemon can only run with a single
finality provider instance at a time.

## 5. Finality Provider Operations

Expand Down
7 changes: 5 additions & 2 deletions finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (app *FinalityProviderApp) Stop() error {
app.logger.Info("stopping finality provider", zap.String("pk", pkHex))

if err := app.fpIns.Stop(); err != nil {
stopErr = err
stopErr = fmt.Errorf("failed to close the fp instance: %w", err)
return
}

Expand All @@ -313,7 +313,7 @@ func (app *FinalityProviderApp) Stop() error {

app.logger.Debug("Stopping EOTS manager")
if err := app.eotsManager.Close(); err != nil {
stopErr = err
stopErr = fmt.Errorf("failed to close the EOTS manager: %w", err)
return
}

Expand Down Expand Up @@ -473,6 +473,9 @@ func (app *FinalityProviderApp) startFinalityProviderInstance(
}

app.fpIns = fpIns
} else if !pk.Equals(app.fpIns.btcPk) {
return fmt.Errorf("the finality provider daemon is already bonded with the finality provider %s,"+
"please restart the daemon to switch to another instance", app.fpIns.btcPk.MarshalHex())
}

return app.fpIns.Start()
Expand Down
4 changes: 4 additions & 0 deletions finality-provider/service/fp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ func (fp *FinalityProviderInstance) Stop() error {
return nil
}

func (fp *FinalityProviderInstance) GetConfig() *fpcfg.Config {
return fp.cfg
}

func (fp *FinalityProviderInstance) IsRunning() bool {
return fp.isStarted.Load()
}
Expand Down
51 changes: 32 additions & 19 deletions itest/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//go:build e2e
// +build e2e

package e2etest

import (
Expand All @@ -13,6 +10,7 @@ import (
"time"

bbntypes "github.com/babylonlabs-io/babylon/types"
bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"

sdkmath "cosmossdk.io/math"
"github.com/babylonlabs-io/babylon/testutil/datagen"
Expand All @@ -32,29 +30,38 @@ var (
// creation -> registration -> randomness commitment ->
// activation with BTC delegation and Covenant sig ->
// vote submission -> block finalization
// The test runs 2 finality providers connecting to
// a single EOTS manager
func TestFinalityProviderLifeCycle(t *testing.T) {
tm, fpIns := StartManagerWithFinalityProvider(t)
n := 2
tm, fps := StartManagerWithFinalityProvider(t, n)
defer tm.Stop(t)

// check the public randomness is committed
tm.WaitForFpPubRandTimestamped(t, fpIns)
tm.WaitForFpPubRandTimestamped(t, fps[0])

// send a BTC delegation
_ = tm.InsertBTCDelegation(t, []*btcec.PublicKey{fpIns.GetBtcPk()}, stakingTime, stakingAmount)
for _, fp := range fps {
_ = tm.InsertBTCDelegation(t, []*btcec.PublicKey{fp.GetBtcPk()}, stakingTime, stakingAmount)
}

// check the BTC delegation is pending
delsResp := tm.WaitForNPendingDels(t, 1)
del, err := ParseRespBTCDelToBTCDel(delsResp[0])
require.NoError(t, err)

// send covenant sigs
tm.InsertCovenantSigForDelegation(t, del)
delsResp := tm.WaitForNPendingDels(t, n)
var dels []*bstypes.BTCDelegation
for _, delResp := range delsResp {
del, err := ParseRespBTCDelToBTCDel(delResp)
require.NoError(t, err)
dels = append(dels, del)
// send covenant sigs
tm.InsertCovenantSigForDelegation(t, del)
}

// check the BTC delegation is active
_ = tm.WaitForNActiveDels(t, 1)
_ = tm.WaitForNActiveDels(t, n)

// check the last voted block is finalized
lastVotedHeight := tm.WaitForFpVoteCast(t, fpIns)
lastVotedHeight := tm.WaitForFpVoteCast(t, fps[0])

tm.CheckBlockFinalization(t, lastVotedHeight, 1)
t.Logf("the block at height %v is finalized", lastVotedHeight)
}
Expand All @@ -63,9 +70,11 @@ func TestFinalityProviderLifeCycle(t *testing.T) {
// sends a finality vote over a conflicting block
// in this case, the BTC private key should be extracted by Babylon
func TestDoubleSigning(t *testing.T) {
tm, fpIns := StartManagerWithFinalityProvider(t)
tm, fps := StartManagerWithFinalityProvider(t, 1)
defer tm.Stop(t)

fpIns := fps[0]

// check the public randomness is committed
tm.WaitForFpPubRandTimestamped(t, fpIns)

Expand Down Expand Up @@ -121,9 +130,11 @@ func TestDoubleSigning(t *testing.T) {

// TestCatchingUp tests if a fp can catch up after restarted
func TestCatchingUp(t *testing.T) {
tm, fpIns := StartManagerWithFinalityProvider(t)
tm, fps := StartManagerWithFinalityProvider(t, 1)
defer tm.Stop(t)

fpIns := fps[0]

// check the public randomness is committed
tm.WaitForFpPubRandTimestamped(t, fpIns)

Expand Down Expand Up @@ -168,9 +179,11 @@ func TestCatchingUp(t *testing.T) {
}

func TestFinalityProviderEditCmd(t *testing.T) {
tm, fpIns := StartManagerWithFinalityProvider(t)
tm, fps := StartManagerWithFinalityProvider(t, 1)
defer tm.Stop(t)

fpIns := fps[0]

cmd := daemon.CommandEditFinalityDescription()

const (
Expand All @@ -192,7 +205,7 @@ func TestFinalityProviderEditCmd(t *testing.T) {

args := []string{
fpIns.GetBtcPkHex(),
"--" + fpdDaemonAddressFlag, tm.FpConfig.RPCListener,
"--" + fpdDaemonAddressFlag, fpIns.GetConfig().RPCListener,
"--" + monikerFlag, moniker,
"--" + websiteFlag, website,
"--" + securityContactFlag, securityContact,
Expand Down Expand Up @@ -248,7 +261,7 @@ func TestFinalityProviderEditCmd(t *testing.T) {
}

func TestFinalityProviderCreateCmd(t *testing.T) {
tm, _ := StartManagerWithFinalityProvider(t)
tm, _ := StartManagerWithFinalityProvider(t, 1)
defer tm.Stop(t)

cmd := daemon.CommandCreateFP()
Expand Down
7 changes: 6 additions & 1 deletion itest/eotsmanager_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ type EOTSServerHandler struct {
t *testing.T
interceptor *signal.Interceptor
eotsServer *service.Server
Cfg *config.Config
}

func NewEOTSServerHandler(t *testing.T, cfg *config.Config, eotsHomeDir string, shutdownInterceptor signal.Interceptor) *EOTSServerHandler {
dbBackend, err := cfg.DatabaseConfig.GetDBBackend()
require.NoError(t, err)
logger := zap.NewNop()
loggerConfig := zap.NewDevelopmentConfig()
loggerConfig.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
logger, err := loggerConfig.Build()
require.NoError(t, err)
eotsManager, err := eotsmanager.NewLocalEOTSManager(eotsHomeDir, cfg.KeyringBackend, dbBackend, logger)
require.NoError(t, err)

Expand All @@ -31,6 +35,7 @@ func NewEOTSServerHandler(t *testing.T, cfg *config.Config, eotsHomeDir string,
t: t,
eotsServer: eotsServer,
interceptor: &shutdownInterceptor,
Cfg: cfg,
}
}

Expand Down
Loading

0 comments on commit 889676b

Please sign in to comment.