Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
feat: support secure grpc connections (#576)
Browse files Browse the repository at this point in the history
* feat: support secure grpc connections

* fix: add the insecure flag to e2e orchestrator script
  • Loading branch information
rach-id authored Nov 6, 2023
1 parent cae6432 commit ecd65d7
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 37 deletions.
5 changes: 5 additions & 0 deletions cmd/blobstream/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
FlagBootstrappers = "p2p.bootstrappers"
FlagP2PListenAddress = "p2p.listen-addr"
FlagP2PNickname = "p2p.nickname"
FlagGRPCInsecure = "grpc.insecure"
)

func AddP2PNicknameFlag(cmd *cobra.Command) {
Expand All @@ -59,3 +60,7 @@ func AddP2PListenAddressFlag(cmd *cobra.Command) {
func AddBootstrappersFlag(cmd *cobra.Command) {
cmd.Flags().String(FlagBootstrappers, "", "Comma-separated multiaddresses of p2p peers to connect to")
}

func AddGRPCInsecureFlag(cmd *cobra.Command) {
cmd.Flags().Bool(FlagGRPCInsecure, false, "allow gRPC over insecure channels, if not TLS the server must use TLS")
}
4 changes: 2 additions & 2 deletions cmd/blobstream/common/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

// NewTmAndAppQuerier helper function that creates a new TmQuerier and AppQuerier and registers their stop functions in the
// stopFuncs slice.
func NewTmAndAppQuerier(logger tmlog.Logger, tendermintRPC string, celesGRPC string) (*rpc.TmQuerier, *rpc.AppQuerier, []func() error, error) {
func NewTmAndAppQuerier(logger tmlog.Logger, tendermintRPC string, celesGRPC string, grpcInsecure bool) (*rpc.TmQuerier, *rpc.AppQuerier, []func() error, error) {
// load app encoding configuration
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)

Expand All @@ -45,7 +45,7 @@ func NewTmAndAppQuerier(logger tmlog.Logger, tendermintRPC string, celesGRPC str

// creating the application querier
appQuerier := rpc.NewAppQuerier(logger, celesGRPC, encCfg)
err = appQuerier.Start()
err = appQuerier.Start(grpcInsecure)
if err != nil {
return nil, nil, stopFuncs, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/blobstream/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func Command() *cobra.Command {
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)

querier := rpc.NewAppQuerier(logger, config.coreGRPC, encCfg)
err = querier.Start()
err = querier.Start(config.grpcInsecure)
if err != nil {
return err
}
Expand Down
8 changes: 7 additions & 1 deletion cmd/blobstream/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func addDeployFlags(cmd *cobra.Command) *cobra.Command {
}
cmd.Flags().String(base.FlagHome, homeDir, "The Blobstream deployer home directory")
cmd.Flags().String(base.FlagEVMPassphrase, "", "the evm account passphrase (if not specified as a flag, it will be asked interactively)")

base.AddGRPCInsecureFlag(cmd)
return cmd
}

Expand All @@ -53,6 +53,7 @@ type deployConfig struct {
evmAccAddress string
startingNonce string
evmGasLimit uint64
grpcInsecure bool
}

func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
Expand Down Expand Up @@ -102,6 +103,10 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
if err != nil {
return deployConfig{}, err
}
grpcInsecure, err := cmd.Flags().GetBool(base.FlagGRPCInsecure)
if err != nil {
return deployConfig{}, err
}

return deployConfig{
evmAccAddress: evmAccAddr,
Expand All @@ -114,5 +119,6 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
Home: homeDir,
EVMPassphrase: passphrase,
},
grpcInsecure: grpcInsecure,
}, nil
}
2 changes: 1 addition & 1 deletion cmd/blobstream/orchestrator/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Start() *cobra.Command {

stopFuncs := make([]func() error, 0)

tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC, config.grpcInsecure)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions cmd/blobstream/orchestrator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func addOrchestratorFlags(cmd *cobra.Command) *cobra.Command {
base.AddP2PNicknameFlag(cmd)
base.AddP2PListenAddressFlag(cmd)
base.AddBootstrappersFlag(cmd)
base.AddGRPCInsecureFlag(cmd)
return cmd
}

Expand All @@ -46,6 +47,7 @@ type StartConfig struct {
evmAccAddress string
bootstrappers, p2pListenAddr string
p2pNickname string
grpcInsecure bool
}

func parseOrchestratorFlags(cmd *cobra.Command) (StartConfig, error) {
Expand Down Expand Up @@ -99,6 +101,10 @@ func parseOrchestratorFlags(cmd *cobra.Command) (StartConfig, error) {
if err != nil {
return StartConfig{}, err
}
grpcInsecure, err := cmd.Flags().GetBool(base.FlagGRPCInsecure)
if err != nil {
return StartConfig{}, err
}

return StartConfig{
evmAccAddress: evmAccAddr,
Expand All @@ -111,6 +117,7 @@ func parseOrchestratorFlags(cmd *cobra.Command) (StartConfig, error) {
Home: homeDir,
EVMPassphrase: passphrase,
},
grpcInsecure: grpcInsecure,
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/blobstream/query/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Signers() *cobra.Command {
}()

// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC, config.grpcInsecure)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down Expand Up @@ -358,7 +358,7 @@ func Signature() *cobra.Command {
}()

// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC, config.grpcInsecure)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down
18 changes: 13 additions & 5 deletions cmd/blobstream/query/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package query
import (
"fmt"

"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base"

"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/relayer"
"github.com/spf13/cobra"
)
Expand All @@ -19,6 +21,7 @@ func addFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().Uint(relayer.FlagCoreRPCPort, 26657, "Specify the rest rpc address")
cmd.Flags().String(FlagP2PNode, "", "P2P target node multiaddress (eg. /ip4/127.0.0.1/tcp/30000/p2p/12D3KooWBSMasWzRSRKXREhediFUwABNZwzJbkZcYz5rYr9Zdmfn)")
cmd.Flags().String(FlagOutputFile, "", "Path to an output file path if the results need to be written to a json file. Leaving it as empty will result in printing the result to stdout")
base.AddGRPCInsecureFlag(cmd)

return cmd
}
Expand All @@ -27,6 +30,7 @@ type Config struct {
coreGRPC, coreRPC string
targetNode string
outputFile string
grpcInsecure bool
}

func parseFlags(cmd *cobra.Command) (Config, error) {
Expand Down Expand Up @@ -54,11 +58,15 @@ func parseFlags(cmd *cobra.Command) (Config, error) {
if err != nil {
return Config{}, err
}

grpcInsecure, err := cmd.Flags().GetBool(base.FlagGRPCInsecure)
if err != nil {
return Config{}, err
}
return Config{
coreGRPC: fmt.Sprintf("%s:%d", coreGRPCHost, coreGRPCPort),
coreRPC: fmt.Sprintf("tcp://%s:%d", coreRPCHost, coreRPCPort),
targetNode: targetNode,
outputFile: outputFile,
coreGRPC: fmt.Sprintf("%s:%d", coreGRPCHost, coreGRPCPort),
coreRPC: fmt.Sprintf("tcp://%s:%d", coreRPCHost, coreRPCPort),
targetNode: targetNode,
outputFile: outputFile,
grpcInsecure: grpcInsecure,
}, nil
}
2 changes: 1 addition & 1 deletion cmd/blobstream/relayer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Start() *cobra.Command {

stopFuncs := make([]func() error, 0)

tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC, config.grpcInsecure)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down
7 changes: 7 additions & 0 deletions cmd/blobstream/relayer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func addRelayerStartFlags(cmd *cobra.Command) *cobra.Command {
base.AddP2PNicknameFlag(cmd)
base.AddP2PListenAddressFlag(cmd)
base.AddBootstrappersFlag(cmd)
base.AddGRPCInsecureFlag(cmd)

return cmd
}
Expand All @@ -59,6 +60,7 @@ type StartConfig struct {
evmGasLimit uint64
bootstrappers, p2pListenAddr string
p2pNickname string
grpcInsecure bool
}

func parseRelayerStartFlags(cmd *cobra.Command) (StartConfig, error) {
Expand Down Expand Up @@ -135,6 +137,10 @@ func parseRelayerStartFlags(cmd *cobra.Command) (StartConfig, error) {
if err != nil {
return StartConfig{}, err
}
grpcInsecure, err := cmd.Flags().GetBool(base.FlagGRPCInsecure)
if err != nil {
return StartConfig{}, err
}

return StartConfig{
evmAccAddress: evmAccAddr,
Expand All @@ -151,6 +157,7 @@ func parseRelayerStartFlags(cmd *cobra.Command) (StartConfig, error) {
Home: homeDir,
EVMPassphrase: passphrase,
},
grpcInsecure: grpcInsecure,
}, nil
}

Expand Down
16 changes: 8 additions & 8 deletions e2e/qgb_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (network BlobstreamNetwork) WaitForOrchestratorToStart(_ctx context.Context
p2pQuerier := p2p.NewQuerier(dht, network.Logger)

appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err := appQuerier.Start()
err := appQuerier.Start(true)
if err != nil {
return 0, 0, err
}
Expand Down Expand Up @@ -491,7 +491,7 @@ func (network BlobstreamNetwork) WaitForOrchestratorToStart(_ctx context.Context
// Thus, any nonce after the returned valset should be signed by all orchestrators.
func (network BlobstreamNetwork) GetValsetContainingVals(_ctx context.Context, number int) (*types.Valset, error) {
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err := appQuerier.Start()
err := appQuerier.Start(true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -539,7 +539,7 @@ func (network BlobstreamNetwork) GetValsetConfirm(
p2pQuerier := p2p.NewQuerier(dht, network.Logger)
// create app querier
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err := appQuerier.Start()
err := appQuerier.Start(true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -602,7 +602,7 @@ func (network BlobstreamNetwork) GetDataCommitmentConfirm(

// create app querier
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err = appQuerier.Start()
err = appQuerier.Start(true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -651,7 +651,7 @@ func (network BlobstreamNetwork) GetDataCommitmentConfirmByHeight(
) (*blobstreamtypes.DataCommitmentConfirm, error) {
// create app querier
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err := appQuerier.Start()
err := appQuerier.Start(true)
if err != nil {
return nil, err
}
Expand All @@ -672,7 +672,7 @@ func (network BlobstreamNetwork) GetDataCommitmentConfirmByHeight(
func (network BlobstreamNetwork) GetLatestAttestationNonce(_ctx context.Context) (uint64, error) {
// create app querier
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err := appQuerier.Start()
err := appQuerier.Start(true)
if err != nil {
return 0, err
}
Expand All @@ -694,7 +694,7 @@ func (network BlobstreamNetwork) WasAttestationSigned(
) (bool, error) {
// create app querier
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err := appQuerier.Start()
err := appQuerier.Start(true)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -992,7 +992,7 @@ func (network BlobstreamNetwork) PrintLogs() {
func (network BlobstreamNetwork) GetLatestValset(ctx context.Context) (*types.Valset, error) {
// create app querier
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
err := appQuerier.Start()
err := appQuerier.Start(true)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestRelayerWithMultipleValidators(t *testing.T) {
// check whether the four validators are up and running
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
HandleNetworkError(t, network, err, false)
err = appQuerier.Start()
err = appQuerier.Start(true)
HandleNetworkError(t, network, err, false)
defer appQuerier.Stop() //nolint:errcheck

Expand Down Expand Up @@ -270,7 +270,7 @@ func TestUpdatingTheDataCommitmentWindow(t *testing.T) {
// check whether the four validators are up and running
appQuerier := rpc.NewAppQuerier(network.Logger, network.CelestiaGRPC, network.EncCfg)
HandleNetworkError(t, network, err, false)
err = appQuerier.Start()
err = appQuerier.Start(true)
HandleNetworkError(t, network, err, false)
defer appQuerier.Stop() //nolint:errcheck

Expand Down
1 change: 1 addition & 0 deletions e2e/scripts/deploy_blobstream_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ echo "deploying Blobstream contract..."
--evm.account "${EVM_ACCOUNT}" \
--core.grpc.host "${CORE_GRPC_HOST}" \
--core.grpc.port "${CORE_GRPC_PORT}" \
--grpc.insecure \
--starting-nonce "${STARTING_NONCE}" \
--evm.rpc "${EVM_ENDPOINT}" \
--evm.passphrase=123 > /opt/output
Expand Down
2 changes: 2 additions & 0 deletions e2e/scripts/start_orchestrator_after_validator_created.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ then
--core.rpc.port="${CORE_RPC_PORT}" \
--core.grpc.host="${CORE_GRPC_HOST}" \
--core.grpc.port="${CORE_GRPC_PORT}" \
--grpc.insecure \
--p2p.nickname=key \
--p2p.listen-addr="${P2P_LISTEN}" \
--evm.passphrase=123
Expand All @@ -66,6 +67,7 @@ else
--core.rpc.port="${CORE_RPC_PORT}" \
--core.grpc.host="${CORE_GRPC_HOST}" \
--core.grpc.port="${CORE_GRPC_PORT}" \
--grpc.insecure \
--p2p.listen-addr="${P2P_LISTEN}" \
--p2p.bootstrappers="${P2P_BOOTSTRAPPERS}" \
--evm.passphrase=123
Expand Down
1 change: 1 addition & 0 deletions e2e/scripts/start_relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ sleep 5s
--core.rpc.port="${CORE_RPC_PORT}" \
--core.grpc.host="${CORE_GRPC_HOST}" \
--core.grpc.port="${CORE_GRPC_PORT}" \
--grpc.insecure \
--evm.chain-id="${EVM_CHAIN_ID}" \
--evm.rpc="${EVM_ENDPOINT}" \
--evm.contract-address="${BLOBSTREAM_CONTRACT}" \
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (s *OrchestratorTestSuite) TestEnqueuingAttestationNonces() {
s.Node.CelestiaNetwork.GRPCAddr,
ecfg,
)
require.NoError(s.T(), appQuerier.Start())
require.NoError(s.T(), appQuerier.Start(true))
defer appQuerier.Stop() //nolint:errcheck

latestNonce, err := appQuerier.QueryLatestAttestationNonce(ctx)
Expand Down
15 changes: 13 additions & 2 deletions rpc/app_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package rpc

import (
"context"
"crypto/tls"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"

"github.com/celestiaorg/orchestrator-relayer/types"
Expand All @@ -26,9 +28,18 @@ func NewAppQuerier(logger tmlog.Logger, blobStreamRPC string, encCft encoding.Co
return &AppQuerier{Logger: logger, blobStreamRPC: blobStreamRPC, EncCfg: encCft}
}

func (aq *AppQuerier) Start() error {
func (aq *AppQuerier) Start(grpcInsecure bool) error {
// creating a grpc connection to Celestia-app
blobStreamGRPC, err := grpc.Dial(aq.blobStreamRPC, grpc.WithTransportCredentials(insecure.NewCredentials()))
var dialOpts []grpc.DialOption

if grpcInsecure {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} else {
dialOpts = append(dialOpts, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
MinVersion: tls.VersionTLS12,
})))
}
blobStreamGRPC, err := grpc.Dial(aq.blobStreamRPC, dialOpts...)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit ecd65d7

Please sign in to comment.