Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: nlreturn lint #251

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ linters:
- misspell
- nakedret
- nilerr
# - nlreturn # Style wise I personally like this one, todo(lazar): unlax at somepoint, good practice
- nlreturn
- noctx
- nonamedreturns
- nosprintfhostport
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased

### Improvements

* [#251](https://github.com/babylonlabs-io/finality-provider/pull/251) chore: nlreturn lint

## v0.14.2

### Bug Fixes
Expand Down
5 changes: 5 additions & 0 deletions clientcontroller/babylon.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func NewBabylonController(
func (bc *BabylonController) mustGetTxSigner() string {
signer := bc.GetKeyAddress()
prefix := bc.cfg.AccountPrefix

return sdk.MustBech32ifyAddressBytes(prefix, signer)
}

Expand Down Expand Up @@ -288,6 +289,7 @@ func (bc *BabylonController) QueryFinalityProviderVotingPower(fpPk *btcec.Public
// therefore, it should be treated as the fp having 0 voting power
if strings.Contains(err.Error(), finalitytypes.ErrVotingPowerTableNotUpdated.Error()) {
bc.logger.Info("the voting power table not updated yet")

return 0, nil
}

Expand Down Expand Up @@ -338,6 +340,7 @@ func (bc *BabylonController) QueryBlocks(startHeight, endHeight uint64, limit ui
if count > uint64(limit) {
count = uint64(limit)
}

return bc.queryLatestBlocks(sdk.Uint64ToBigEndian(startHeight), count, finalitytypes.QueriedBlockStatus_ANY, false)
}

Expand Down Expand Up @@ -367,6 +370,7 @@ func (bc *BabylonController) queryLatestBlocks(startKey []byte, count uint64, st

func getContextWithCancel(timeout time.Duration) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithTimeout(context.Background(), timeout)

return ctx, cancel
}

Expand Down Expand Up @@ -558,6 +562,7 @@ func (bc *BabylonController) EditFinalityProvider(fpPk *btcec.PublicKey,
if reqValue != "" {
return reqValue
}

return defaultValue
}

Expand Down
2 changes: 2 additions & 0 deletions clientcontroller/retry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (e ExpectedError) Error() string {
if e.error == nil {
return "expected error"
}

return e.error.Error()
}

Expand All @@ -52,6 +53,7 @@ func (e ExpectedError) Unwrap() error {
// Is adds support for errors.Is usage on isExpected
func (ExpectedError) Is(err error) bool {
_, isExpected := err.(ExpectedError)

return isExpected
}

Expand Down
1 change: 1 addition & 0 deletions eotsmanager/client/rpcclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func (c *EOTSManagerGRpcClient) SaveEOTSKeyName(pk *btcec.PublicKey, keyName str
EotsPk: pk.SerializeUncompressed(),
}
_, err := c.client.SaveEOTSKeyName(context.Background(), req)

return err
}

Expand Down
2 changes: 2 additions & 0 deletions eotsmanager/cmd/eotsd/daemon/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func saveKeyOnPostRun(cmd *cobra.Command, commandName string) {
subCmd.PostRunE = func(cmd *cobra.Command, args []string) error {
keyName := args[0]
_, err := saveKeyNameMapping(cmd, keyName)

return err
}
}
Expand Down Expand Up @@ -246,6 +247,7 @@ func printFromKey(cmd *cobra.Command, keyName string, eotsPk *types.BIP340PubKey
ctx := cmd.Context()
mnemonic := ctx.Value(mnemonicCtxKey).(string) //nolint: forcetypeassert
showMnemonic := ctx.Value(mnemonicShowCtxKey).(bool)

return printCreatePubKeyHex(cmd, k, eotsPk, showMnemonic, mnemonic, clientCtx.OutputFormat)
}

Expand Down
4 changes: 4 additions & 0 deletions eotsmanager/cmd/eotsd/daemon/keysadd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func runAddCmdPrepare(cmd *cobra.Command, args []string) error {
}

buf := bufio.NewReader(clientCtx.Input)

return runAddCmd(clientCtx, cmd, args, buf)
}

Expand Down Expand Up @@ -297,6 +298,7 @@ func runAddCmd(ctx client.Context, cmd *cobra.Command, args []string, inBuf *buf
// used later for printing the values if needed
ctxWithValues := context.WithValue(cmd.Context(), mnemonicCtxKey, mnemonic) //nolint: revive,staticcheck
cmd.SetContext(context.WithValue(ctxWithValues, mnemonicShowCtxKey, showMnemonic)) //nolint: revive,staticcheck

return nil
}

Expand All @@ -308,6 +310,7 @@ func validateMultisigThreshold(k, nKeys int) error {
return fmt.Errorf(
"threshold k of n multisignature: %d < %d", nKeys, k)
}

return nil
}

Expand All @@ -322,5 +325,6 @@ func readMnemonicFromFile(filePath string) (string, error) {
if err != nil {
return "", err
}

return string(bz), nil
}
1 change: 1 addition & 0 deletions eotsmanager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@ func DefaultConfigWithHomePath(homePath string) *Config {
if err := cfg.Validate(); err != nil {
panic(err)
}

return cfg
}
6 changes: 6 additions & 0 deletions eotsmanager/localmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func LoadBIP340PubKeyFromKeyName(kr keyring.Keyring, keyName string) (*bbntypes.
return nil, err
}
eotsPk = bbntypes.NewBIP340PubKeyFromBTCPK(pk)

return eotsPk, nil
default:
return nil, fmt.Errorf("unsupported key type in keyring")
Expand Down Expand Up @@ -286,6 +287,7 @@ func (lm *LocalEOTSManager) SignSchnorrSig(fpPk []byte, msg []byte, passphrase s
func (lm *LocalEOTSManager) signSchnorrSigFromPrivKey(privKey *btcec.PrivateKey, fpPk []byte, msg []byte) (*schnorr.Signature, error) {
// Update metrics
lm.metrics.IncrementEotsFpTotalSchnorrSignCounter(hex.EncodeToString(fpPk))

return schnorr.Sign(privKey, msg)
}

Expand All @@ -306,6 +308,7 @@ func (lm *LocalEOTSManager) SignSchnorrSigFromKeyname(keyName, passphrase string
if err != nil {
return nil, nil, fmt.Errorf("failed to schnorr sign: %w", err)
}

return signature, eotsPk, nil
}

Expand All @@ -320,6 +323,7 @@ func (lm *LocalEOTSManager) getRandomnessPair(fpPk []byte, chainID []byte, heigh
return nil, nil, err
}
privRand, pubRand := randgenerator.GenerateRandomness(record.PrivKey.Serialize(), chainID, height)

return privRand, pubRand, nil
}

Expand Down Expand Up @@ -363,6 +367,7 @@ func (lm *LocalEOTSManager) eotsPrivKeyFromKeyName(keyName string) (*btcec.Priva
switch v := privKeyCached.(type) {
case *secp256k1.PrivKey:
privKey, _ = btcec.PrivKeyFromBytes(v.Key)

return privKey, nil
default:
return nil, fmt.Errorf("unsupported key type in keyring")
Expand All @@ -371,6 +376,7 @@ func (lm *LocalEOTSManager) eotsPrivKeyFromKeyName(keyName string) (*btcec.Priva

func (lm *LocalEOTSManager) keyExists(name string) bool {
_, err := lm.kr.Key(name)

return err == nil
}

Expand Down
1 change: 1 addition & 0 deletions eotsmanager/service/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func newRPCServer(
func (r *rpcServer) RegisterWithGrpcServer(grpcServer *grpc.Server) error {
// Register the main RPC server.
proto.RegisterEOTSManagerServer(grpcServer, r)

return nil
}

Expand Down
2 changes: 2 additions & 0 deletions eotsmanager/store/eotsstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (s *EOTSStore) GetEOTSKeyName(pk []byte) (string, error) {
}

keyName = string(keyNameBytes)

return nil
}, func() {})

Expand Down Expand Up @@ -190,6 +191,7 @@ func (s *EOTSStore) GetSignRecord(eotsPk, chainID []byte, height uint64) (*Signi
if errors.Is(err, ErrSignRecordNotFound) {
return nil, false, nil
}

return nil, false, err
}

Expand Down
2 changes: 2 additions & 0 deletions finality-provider/cmd/fpd/daemon/commit_pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ WARNING: this can drain the finality provider's balance if the target height is
RunE: runCommandCommitPubRand,
}
cmd.Flags().Uint64("start-height", math.MaxUint64, "The block height to start committing pubrand from (optional)")

return cmd
}

Expand Down Expand Up @@ -99,5 +100,6 @@ func runCommandCommitPubRand(cmd *cobra.Command, args []string) error {
if startHeight == math.MaxUint64 {
return fp.TestCommitPubRand(targetHeight)
}

return fp.TestCommitPubRandWithStartHeight(startHeight, targetHeight)
}
9 changes: 9 additions & 0 deletions finality-provider/cmd/fpd/daemon/daemon_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func CommandGetDaemonInfo() *cobra.Command {
RunE: runCommandGetDaemonInfo,
}
cmd.Flags().String(fpdDaemonAddressFlag, defaultFpdDaemonAddress, "The RPC server address of fpd")

return cmd
}

Expand All @@ -65,6 +66,7 @@ func runCommandGetDaemonInfo(cmd *cobra.Command, _ []string) error {
}

printRespJSON(info)

return nil
}

Expand Down Expand Up @@ -139,6 +141,7 @@ Where finality-provider.json contains:
return err
}
}

return nil
}

Expand Down Expand Up @@ -195,6 +198,7 @@ func runCommandCreateFP(ctx client.Context, cmd *cobra.Command, _ []string) erro
}

printRespJSON(res)

return nil
}

Expand Down Expand Up @@ -265,6 +269,7 @@ func getDescriptionFromFlags(f *pflag.FlagSet) (stakingtypes.Description, error)
}

description := stakingtypes.NewDescription(monikerStr, identityStr, websiteStr, securityContactStr, detailsStr)

return description.EnsureLength()
}

Expand All @@ -279,6 +284,7 @@ func CommandLsFP() *cobra.Command {
RunE: runCommandLsFP,
}
cmd.Flags().String(fpdDaemonAddressFlag, defaultFpdDaemonAddress, "The RPC server address of fpd")

return cmd
}

Expand Down Expand Up @@ -318,6 +324,7 @@ func CommandInfoFP() *cobra.Command {
RunE: runCommandInfoFP,
}
cmd.Flags().String(fpdDaemonAddressFlag, defaultFpdDaemonAddress, "The RPC server address of fpd")

return cmd
}

Expand Down Expand Up @@ -552,6 +559,7 @@ func printRespJSON(resp interface{}) {
jsonBytes, err := json.MarshalIndent(resp, "", " ")
if err != nil {
fmt.Println("unable to decode response: ", err)

return
}

Expand Down Expand Up @@ -579,6 +587,7 @@ func loadKeyName(homeDir string, cmd *cobra.Command) (string, error) {
if keyName == "" {
return "", fmt.Errorf("the key in config is empty")
}

return keyName, nil
}

Expand Down
1 change: 1 addition & 0 deletions finality-provider/cmd/fpd/daemon/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func CommandInit() *cobra.Command {
RunE: fpcmd.RunEWithClientCtx(runInitCmd),
}
cmd.Flags().Bool(forceFlag, false, "Override existing configuration")

return cmd
}

Expand Down
1 change: 1 addition & 0 deletions finality-provider/cmd/fpd/daemon/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ func CommandKeys() *cobra.Command {
}

keyAddCmd.Long += "\nIf this key is needed to run as the default for the finality-provider daemon, remind to update the fpd.conf"

return keysCmd
}
2 changes: 2 additions & 0 deletions finality-provider/cmd/fpd/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func CommandStart() *cobra.Command {
cmd.Flags().String(fpEotsPkFlag, "", "The EOTS public key of the finality-provider to start")
cmd.Flags().String(passphraseFlag, "", "The pass phrase used to decrypt the private key")
cmd.Flags().String(rpcListenerFlag, "", "The address that the RPC server listens to")

return cmd
}

Expand Down Expand Up @@ -97,6 +98,7 @@ func runStartCmd(ctx client.Context, cmd *cobra.Command, _ []string) error {
}

fpServer := service.NewFinalityProviderServer(cfg, logger, fpApp, dbBackend, shutdownInterceptor)

return fpServer.RunUntilShutdown()
}

Expand Down
3 changes: 3 additions & 0 deletions finality-provider/proto/finality_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ func (sfp *FinalityProvider) MustGetBTCPK() *btcec.PublicKey {
if err != nil {
panic(fmt.Errorf("failed to parse BTC PK: %w", err))
}

return btcPubKey
}

func (sfp *FinalityProvider) MustGetBIP340BTCPK() *bbn.BIP340PubKey {
btcPK := sfp.MustGetBTCPK()

return bbn.NewBIP340PubKeyFromBTCPK(btcPK)
}

Expand All @@ -27,6 +29,7 @@ func NewFinalityProviderInfo(sfp *FinalityProvider) (*FinalityProviderInfo, erro
if err := des.Unmarshal(sfp.Description); err != nil {
return nil, err
}

return &FinalityProviderInfo{
FpAddr: sfp.FpAddr,
BtcPkHex: sfp.MustGetBIP340BTCPK().MarshalHex(),
Expand Down
5 changes: 5 additions & 0 deletions finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func NewFinalityProviderAppFromConfig(
}

logger.Info("successfully connected to a remote EOTS manager", zap.String("address", cfg.EOTSManagerAddress))

return NewFinalityProviderApp(cfg, cc, em, db, logger)
}

Expand Down Expand Up @@ -223,6 +224,7 @@ func (app *FinalityProviderApp) SyncAllFinalityProvidersStatus() error {
zap.Uint64("power", power),
)
}

continue
}
slashed, jailed, err := app.cc.QueryFinalityProviderSlashedOrJailed(fp.BtcPk)
Expand Down Expand Up @@ -299,6 +301,7 @@ func (app *FinalityProviderApp) Stop() error {

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

return
}

Expand All @@ -308,11 +311,13 @@ func (app *FinalityProviderApp) Stop() error {
app.logger.Debug("Stopping EOTS manager")
if err := app.eotsManager.Close(); err != nil {
stopErr = fmt.Errorf("failed to close the EOTS manager: %w", err)

return
}

app.logger.Debug("FinalityProviderApp successfully stopped")
})

return stopErr
}

Expand Down
1 change: 1 addition & 0 deletions finality-provider/service/benchmark_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (fp *FinalityProviderInstance) HelperCommitPubRand(tipHeight uint64) (*type
zap.Uint64("block_height", tipHeight),
zap.Uint64("last_committed_height", lastCommittedHeight),
)

return nil, nil, nil
}

Expand Down
Loading
Loading