Skip to content

Commit

Permalink
fix lint/test
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianElvis committed Sep 24, 2024
1 parent d884717 commit fe9b9c6
Show file tree
Hide file tree
Showing 12 changed files with 1,899 additions and 264 deletions.
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.4-alpine as builder
FROM golang:1.22.7-alpine as builder

Check warning on line 1 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker_pipeline / docker_build

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

# Version to build. Default is the Git HEAD.
ARG VERSION="HEAD"
Expand All @@ -12,15 +12,11 @@ RUN apk add --no-cache --update openssh git make build-base linux-headers libc-d
libzmq-static libsodium-static gcc


RUN mkdir -p /root/.ssh && ssh-keyscan github.com >> /root/.ssh/known_hosts
RUN git config --global url."[email protected]:".insteadOf "https://github.com/"
ENV GOPRIVATE=github.com/babylonlabs-io/*

# Build
WORKDIR /go/src/github.com/babylonlabs-io/finality-provider
# Cache dependencies
COPY go.mod go.sum /go/src/github.com/babylonlabs-io/finality-provider/
RUN --mount=type=secret,id=sshKey,target=/root/.ssh/id_rsa go mod download
RUN go mod download
# Copy the rest of the files
COPY ./ /go/src/github.com/babylonlabs-io/finality-provider/

Expand Down
6 changes: 4 additions & 2 deletions finality-provider/service/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ func FuzzRegisterFinalityProvider(f *testing.F) {
f.Fuzz(func(t *testing.T, seed int64) {
r := rand.New(rand.NewSource(seed))

logger := zap.NewNop()
logger, err := zap.NewDevelopment()
require.NoError(t, err)
// create an EOTS manager
eotsHomeDir := filepath.Join(t.TempDir(), "eots-home")
eotsCfg := eotscfg.DefaultConfigWithHomePath(eotsHomeDir)
Expand Down Expand Up @@ -151,7 +152,8 @@ func FuzzSyncFinalityProviderStatus(f *testing.F) {
f.Fuzz(func(t *testing.T, seed int64) {
r := rand.New(rand.NewSource(seed))

logger := zap.NewNop()
logger, err := zap.NewDevelopment()
require.NoError(t, err)

pathSuffix := datagen.GenRandomHexStr(r, 10)
// create an EOTS manager
Expand Down
14 changes: 10 additions & 4 deletions finality-provider/service/chain_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ func FuzzChainPoller_Start(f *testing.F) {
mockConsumerController.EXPECT().QueryBlock(i).Return(resBlock, nil).AnyTimes()
}

logger, err := zap.NewDevelopment()
require.NoError(t, err)

// TODO: use mock metrics
m := metrics.NewFpMetrics()
pollerCfg := fpcfg.DefaultChainPollerConfig()
pollerCfg.PollInterval = 10 * time.Millisecond
poller := service.NewChainPoller(zap.NewNop(), &pollerCfg, mockBabylonController, mockConsumerController, m)
err := poller.Start(startHeight)
poller := service.NewChainPoller(logger, &pollerCfg, mockBabylonController, mockConsumerController, m)
err = poller.Start(startHeight)
require.NoError(t, err)
defer func() {
err := poller.Stop()
Expand Down Expand Up @@ -93,13 +96,16 @@ func FuzzChainPoller_SkipHeight(f *testing.F) {
mockConsumerController.EXPECT().QueryBlock(i).Return(resBlock, nil).AnyTimes()
}

logger, err := zap.NewDevelopment()
require.NoError(t, err)

// TODO: use mock metrics
m := metrics.NewFpMetrics()
pollerCfg := fpcfg.DefaultChainPollerConfig()
pollerCfg.PollInterval = 1 * time.Second
poller := service.NewChainPoller(zap.NewNop(), &pollerCfg, mockBabylonController, mockConsumerController, m)
poller := service.NewChainPoller(logger, &pollerCfg, mockBabylonController, mockConsumerController, m)
// should expect error if the poller is not started
err := poller.SkipToHeight(skipHeight)
err = poller.SkipToHeight(skipHeight)
require.Error(t, err)
err = poller.Start(startHeight)
require.NoError(t, err)
Expand Down
89 changes: 0 additions & 89 deletions finality-provider/service/fp_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,24 +459,6 @@ func (fp *FinalityProviderInstance) hasVotingPower(blockHeight uint64) (bool, er
return true, nil
}

func (fp *FinalityProviderInstance) hasRandomness(b *types.BlockInfo) (bool, error) {
lastCommittedHeight, err := fp.GetLastCommittedHeight()
if err != nil {
return false, err
}
if b.Height > lastCommittedHeight {
fp.logger.Debug(
"the finality provider has not committed public randomness for the height",
zap.String("pk", fp.GetBtcPkHex()),
zap.Uint64("block_height", b.Height),
zap.Uint64("last_committed_height", lastCommittedHeight),
)
return false, nil
}

return true, nil
}

func (fp *FinalityProviderInstance) reportCriticalErr(err error) {
fp.criticalErrChan <- &CriticalError{
err: err,
Expand All @@ -489,77 +471,6 @@ func (fp *FinalityProviderInstance) checkLagging(currentBlockHeight uint64) bool
return currentBlockHeight >= fp.GetLastProcessedHeight()+fp.cfg.FastSyncGap
}

// retryQueryingRandomnessUntilBlockFinalized periodically checks whether
// the randomness has been committed to the target block until the block is
// finalized
// error will be returned if maximum retries have been reached or the query to
// the consumer chain fails
func (fp *FinalityProviderInstance) retryCheckRandomnessUntilBlockFinalized(targetBlock *types.BlockInfo) (bool, error) {
var numRetries uint32

// we break the for loop if the block is finalized or the randomness is successfully committed
// error will be returned if maximum retries have been reached or the query to the consumer chain fails
for {
fp.logger.Debug(
"checking randomness",
zap.String("pk", fp.GetBtcPkHex()),
zap.Uint64("target_block_height", targetBlock.Height),
)
hasRand, err := fp.hasRandomness(targetBlock)
if err != nil {
fp.logger.Debug(
"failed to check last committed randomness",
zap.String("pk", fp.GetBtcPkHex()),
zap.Uint32("current_failures", numRetries),
zap.Uint64("target_block_height", targetBlock.Height),
zap.Error(err),
)

numRetries += 1
if numRetries > uint32(fp.cfg.MaxSubmissionRetries) {
return false, fmt.Errorf("reached max failed cycles with err: %w", err)
}
} else if !hasRand {
fp.logger.Debug(
"randomness does not exist",
zap.String("pk", fp.GetBtcPkHex()),
zap.Uint32("current_retries", numRetries),
zap.Uint64("target_block_height", targetBlock.Height),
)

numRetries += 1
if numRetries > uint32(fp.cfg.MaxSubmissionRetries) {
return false, fmt.Errorf("reached max retries but randomness still not existed")
}
} else {
// the randomness has been successfully committed
return false, nil
}
select {
case <-time.After(fp.cfg.SubmissionRetryInterval):
// periodically query the index block to be later checked whether it is Finalized
finalized, err := fp.consumerCon.QueryIsBlockFinalized(targetBlock.Height)
if err != nil {
return false, fmt.Errorf("failed to query block finalization at height %v: %w", targetBlock.Height, err)
}
if finalized {
fp.logger.Debug(
"the block is already finalized, skip checking randomness",
zap.String("pk", fp.GetBtcPkHex()),
zap.Uint64("target_height", targetBlock.Height),
)
// TODO: returning nil here is to safely break the loop
// the error still exists
return true, nil
}

case <-fp.quit:
fp.logger.Debug("the finality-provider instance is closing", zap.String("pk", fp.GetBtcPkHex()))
return false, ErrFinalityProviderShutDown
}
}
}

// retrySubmitFinalitySignatureUntilBlockFinalized periodically tries to submit finality signature until success or the block is finalized
// error will be returned if maximum retries have been reached or the query to the consumer chain fails
func (fp *FinalityProviderInstance) retrySubmitFinalitySignatureUntilBlockFinalized(targetBlock *types.BlockInfo) (*types.TxResponse, error) {
Expand Down
3 changes: 2 additions & 1 deletion finality-provider/service/fp_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ func FuzzSubmitFinalitySig(f *testing.F) {
}

func startFinalityProviderAppWithRegisteredFp(t *testing.T, r *rand.Rand, cc ccapi.ClientController, consumerCon ccapi.ConsumerController, startingHeight uint64) (*service.FinalityProviderApp, *service.FinalityProviderInstance, func()) {
logger := zap.NewNop()
logger, err := zap.NewDevelopment()
require.NoError(t, err)
// create an EOTS manager
eotsHomeDir := filepath.Join(t.TempDir(), "eots-home")
eotsCfg := eotscfg.DefaultConfigWithHomePath(eotsHomeDir)
Expand Down
3 changes: 2 additions & 1 deletion finality-provider/service/fp_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func waitForStatus(t *testing.T, fpIns *service.FinalityProviderInstance, s prot
}

func newFinalityProviderManagerWithRegisteredFp(t *testing.T, r *rand.Rand, cc ccapi.ClientController, consumerCon ccapi.ConsumerController) (*service.FinalityProviderManager, *bbntypes.BIP340PubKey, func()) {
logger := zap.NewNop()
logger, err := zap.NewDevelopment()
require.NoError(t, err)
// create an EOTS manager
eotsHomeDir := filepath.Join(t.TempDir(), "eots-home")
eotsCfg := eotscfg.DefaultConfigWithHomePath(eotsHomeDir)
Expand Down
15 changes: 10 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ require (
github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-20240429153234-e1e6da7e4ead // indirect
github.com/ethereum/go-verkle v0.1.1-0.20240306133620-7d920df305f0 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/protolambda/ctxlock v0.1.0 // indirect
github.com/shamaton/msgpack/v2 v2.2.0 // indirect
)
Expand Down Expand Up @@ -345,14 +346,14 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect
github.com/pierrec/lz4/v4 v4.1.8 // indirect
github.com/pierrec/lz4/v4 v4.1.15 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.2 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.11.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
Expand Down Expand Up @@ -399,7 +400,7 @@ require (
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
Expand All @@ -426,11 +427,11 @@ require (
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.2 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.20.3 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
modernc.org/token v1.1.0 // indirect
nhooyr.io/websocket v1.8.17 // indirect
pgregory.net/rapid v1.1.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
Expand All @@ -445,4 +446,8 @@ replace (
github.com/ethereum/go-ethereum => github.com/ethereum-optimism/op-geth v1.101407.0-rc.1.0.20240812224053-8d99ca68bb1a
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

// avoid v1.66 that has a breaking change for protobuf. That change breaks the relayer.
// https://github.com/grpc/grpc-go/issues/7569
google.golang.org/grpc => google.golang.org/grpc v1.65.0
)
Loading

0 comments on commit fe9b9c6

Please sign in to comment.