From 0b7a53c1ac2b774554c65a55b216ae76b484cd51 Mon Sep 17 00:00:00 2001 From: Fangyu Gai Date: Wed, 18 Dec 2024 20:49:24 +0800 Subject: [PATCH] fix tests --- finality-provider/config/config.go | 4 ++-- finality-provider/service/app.go | 28 ------------------------ finality-provider/service/fp_instance.go | 7 +++--- itest/test_manager.go | 2 +- 4 files changed, 7 insertions(+), 34 deletions(-) diff --git a/finality-provider/config/config.go b/finality-provider/config/config.go index 179895c4..e3fba79e 100644 --- a/finality-provider/config/config.go +++ b/finality-provider/config/config.go @@ -27,7 +27,7 @@ const ( defaultConfigFileName = "fpd.conf" defaultNumPubRand = 70000 // support running of 1 week with block production time as 10s defaultNumPubRandMax = 100000 - defaultMinRandHeightGap = 35000 + defaultTimestampingDelayBlocks = 6000 // 100 BTC blocks * 600s / 10s defaultBatchSubmissionSize = 1000 defaultRandomInterval = 30 * time.Second defaultSubmitRetryInterval = 1 * time.Second @@ -92,7 +92,7 @@ func DefaultConfigWithHome(homePath string) Config { PollerConfig: &pollerCfg, NumPubRand: defaultNumPubRand, NumPubRandMax: defaultNumPubRandMax, - TimestampingDelayBlocks: defaultMinRandHeightGap, + TimestampingDelayBlocks: defaultTimestampingDelayBlocks, BatchSubmissionSize: defaultBatchSubmissionSize, RandomnessCommitInterval: defaultRandomInterval, SubmissionRetryInterval: defaultSubmitRetryInterval, diff --git a/finality-provider/service/app.go b/finality-provider/service/app.go index a88af85b..c05734e9 100644 --- a/finality-provider/service/app.go +++ b/finality-provider/service/app.go @@ -7,7 +7,6 @@ import ( "sync" sdkmath "cosmossdk.io/math" - "github.com/avast/retry-go/v4" bbntypes "github.com/babylonlabs-io/babylon/types" bstypes "github.com/babylonlabs-io/babylon/x/btcstaking/types" "github.com/btcsuite/btcd/btcec/v2" @@ -26,7 +25,6 @@ import ( "github.com/babylonlabs-io/finality-provider/finality-provider/store" fpkr "github.com/babylonlabs-io/finality-provider/keyring" "github.com/babylonlabs-io/finality-provider/metrics" - "github.com/babylonlabs-io/finality-provider/types" ) type FinalityProviderApp struct { @@ -545,32 +543,6 @@ func (app *FinalityProviderApp) setFinalityProviderJailed(fpi *FinalityProviderI } } -func (app *FinalityProviderApp) getLatestBlockWithRetry() (*types.BlockInfo, error) { - var ( - latestBlock *types.BlockInfo - err error - ) - - if err := retry.Do(func() error { - latestBlock, err = app.cc.QueryBestBlock() - if err != nil { - return err - } - return nil - }, RtyAtt, RtyDel, RtyErr, retry.OnRetry(func(n uint, err error) { - app.logger.Debug( - "failed to query the consumer chain for the latest block", - zap.Uint("attempt", n+1), - zap.Uint("max_attempts", RtyAttNum), - zap.Error(err), - ) - })); err != nil { - return nil, err - } - - return latestBlock, nil -} - // 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, "") diff --git a/finality-provider/service/fp_instance.go b/finality-provider/service/fp_instance.go index 181a3fd1..160d701c 100644 --- a/finality-provider/service/fp_instance.go +++ b/finality-provider/service/fp_instance.go @@ -325,13 +325,14 @@ func (fp *FinalityProviderInstance) ShouldCommitRandomness() (bool, uint64, erro tipHeightWithDelay := tipHeight + uint64(fp.cfg.TimestampingDelayBlocks) var startHeight uint64 - if lastCommittedHeight < tipHeightWithDelay { + switch { + case lastCommittedHeight < tipHeightWithDelay: // the start height should consider the timestamping delay // as it is only available to use after tip height + estimated timestamping delay startHeight = tipHeightWithDelay - } else if lastCommittedHeight < tipHeightWithDelay+uint64(fp.cfg.NumPubRand) { + case lastCommittedHeight < tipHeightWithDelay+uint64(fp.cfg.NumPubRand): startHeight = lastCommittedHeight + 1 - } else { + default: // the randomness is sufficient, no need to make another commit fp.logger.Debug( "the finality-provider has sufficient public randomness, skip committing more", diff --git a/itest/test_manager.go b/itest/test_manager.go index dc66aaab..72579b3c 100644 --- a/itest/test_manager.go +++ b/itest/test_manager.go @@ -807,7 +807,7 @@ func defaultFpConfig(keyringDir, homeDir string) *fpcfg.Config { cfg.NumPubRand = 1000 cfg.NumPubRandMax = 1000 - cfg.TimestampingDelayBlocks = 500 + cfg.TimestampingDelayBlocks = 0 cfg.BitcoinNetwork = "simnet" cfg.BTCNetParams = chaincfg.SimNetParams