privval: add ctx to privval interface (#6240)

## Description

- Add `context.Context` to Privval interface

This pr does not introduce context into our custom privval connection protocol because this will be removed in the next release. When this pr is released.
This commit is contained in:
Marko
2021-03-16 14:41:03 +00:00
committed by GitHub
parent fa781e6bb7
commit efd2fde474
43 changed files with 297 additions and 219 deletions

View File

@@ -1,6 +1,7 @@
package commands
import (
"context"
"fmt"
"github.com/spf13/cobra"
@@ -86,7 +87,11 @@ func initFilesWithConfig(config *cfg.Config) error {
PubKeyTypes: []string{types.ABCIPubKeyTypeSecp256k1},
}
}
pubKey, err := pv.GetPubKey()
ctx, cancel := context.WithTimeout(context.TODO(), ctxTimeout)
defer cancel()
pubKey, err := pv.GetPubKey(ctx)
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)
}

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"time"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@@ -15,8 +16,9 @@ import (
)
var (
config = cfg.DefaultConfig()
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
config = cfg.DefaultConfig()
logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
ctxTimeout = 4 * time.Second
)
func init() {

View File

@@ -1,6 +1,7 @@
package commands
import (
"context"
"fmt"
"github.com/spf13/cobra"
@@ -36,7 +37,11 @@ func showValidator(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("can't connect to remote validator %w", err)
}
pubKey, err = pvsc.GetPubKey()
ctx, cancel := context.WithTimeout(context.TODO(), ctxTimeout)
defer cancel()
pubKey, err = pvsc.GetPubKey(ctx)
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)
}
@@ -52,7 +57,10 @@ func showValidator(cmd *cobra.Command, args []string) error {
return err
}
pubKey, err = pv.GetPubKey()
ctx, cancel := context.WithTimeout(context.TODO(), ctxTimeout)
defer cancel()
pubKey, err = pv.GetPubKey(ctx)
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)
}

View File

@@ -1,6 +1,7 @@
package commands
import (
"context"
"fmt"
"net"
"os"
@@ -149,7 +150,10 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
return err
}
pubKey, err := pv.GetPubKey()
ctx, cancel := context.WithTimeout(context.TODO(), ctxTimeout)
defer cancel()
pubKey, err := pv.GetPubKey(ctx)
if err != nil {
return fmt.Errorf("can't get pubkey: %w", err)
}