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

[BACKPORT/23.0.x] 5427 #5429

Merged
merged 1 commit into from
Nov 7, 2023
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
7 changes: 7 additions & 0 deletions .changelog/5427.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
config: add option to override internal unix socket path

Previously the UNIX socket path could only be overriden via a debug option
which also required the general "don't blame Oasis" to be set. Since this
option can be generally useful in production environments it is now supported
in the config file. The socket path can be set under
`common.internal_socket_path`, and is not considered a debug option anymore.
11 changes: 11 additions & 0 deletions go/oasis-node/cmd/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const (
// RequiredRlimit is the minimum required RLIMIT_NOFILE as too low of a
// limit can cause problems with BadgerDB.
RequiredRlimit = 50_000

// InternalSocketName is the default name of the internal gRPC socket.
InternalSocketName = "internal.sock"
)

var (
Expand All @@ -57,6 +60,14 @@ func DataDir() string {
return config.GlobalConfig.Common.DataDir
}

// InternalSocketPath returns the path to the node's internal unix socket.
func InternalSocketPath() string {
if config.GlobalConfig.Common.InternalSocketPath != "" {
return config.GlobalConfig.Common.InternalSocketPath
}
return filepath.Join(DataDir(), InternalSocketName)
}

// IsNodeCmd returns true iff the current command is the ekiden node.
func IsNodeCmd() bool {
return isNodeCmd
Expand Down
2 changes: 2 additions & 0 deletions go/oasis-node/cmd/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package config
type Config struct {
// Node's data directory.
DataDir string `yaml:"data_dir"`
// Path to the node's internal unix socket.
InternalSocketPath string `yaml:"internal_socket_path,omitempty"`
// Logging configuration options.
Log LogConfig `yaml:"log,omitempty"`
// Debug configuration options (do not use).
Expand Down
18 changes: 2 additions & 16 deletions go/oasis-node/cmd/common/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/spf13/cobra"
Expand All @@ -20,7 +19,6 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/identity"
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
)

const (
Expand All @@ -30,13 +28,8 @@ const (
CfgAddress = "address"
// CfgWait waits for the remote address to become available.
CfgWait = "wait"
// CfgDebugGrpcInternalSocketPath sets custom internal socket path.
CfgDebugGrpcInternalSocketPath = "debug.grpc.internal.socket_path"

// LocalSocketFilename is the filename of the unix socket in node datadir.
LocalSocketFilename = "internal.sock"

defaultAddress = "unix:" + LocalSocketFilename
defaultAddress = "unix:" + common.InternalSocketName
)

var (
Expand Down Expand Up @@ -75,15 +68,10 @@ func NewServerLocal(installWrapper bool) (*cmnGrpc.Server, error) {
if dataDir == "" {
return nil, errors.New("data directory must be set")
}
path := filepath.Join(dataDir, LocalSocketFilename)
if viper.IsSet(CfgDebugGrpcInternalSocketPath) && flags.DebugDontBlameOasis() {
logger.Info("overriding internal socket path", "path", viper.GetString(CfgDebugGrpcInternalSocketPath))
path = viper.GetString(CfgDebugGrpcInternalSocketPath)
}

config := &cmnGrpc.ServerConfig{
Name: "internal",
Path: path,
Path: common.InternalSocketPath(),
InstallWrapper: installWrapper,
}

Expand Down Expand Up @@ -125,8 +113,6 @@ func init() {
_ = viper.BindPFlags(ServerTCPFlags)
ServerTCPFlags.AddFlagSet(cmnGrpc.Flags)

ServerLocalFlags.String(CfgDebugGrpcInternalSocketPath, "", "use custom internal unix socket path")
_ = ServerLocalFlags.MarkHidden(CfgDebugGrpcInternalSocketPath)
_ = viper.BindPFlags(ServerLocalFlags)
ServerLocalFlags.AddFlagSet(cmnGrpc.Flags)

Expand Down
5 changes: 5 additions & 0 deletions go/oasis-node/cmd/config/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ func doMigrateConfig(cmd *cobra.Command, args []string) {
mDebug["allow_root"] = allow_root
delete(m(debug), "allow_root")
}

if socketPath, ok := m(m(m(debug)["grpc"])["internal"])["socket_path"]; ok {
m(newCfg["common"])["internal_socket_path"] = socketPath
delete(m(debug), "grpc")
}
}

pprof, ok := oldCfg["pprof"]
Expand Down
60 changes: 60 additions & 0 deletions go/oasis-node/cmd/config/migrate/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,45 @@ consensus:
- "[email protected]:26656"
`

// Simple config with internal socket override.
const testInternalSocketOverrideConfigRaw = `
debug:
dont_blame_oasis: true
grpc:
internal:
socket_path: /node/custom-internal.sock

datadir: /node/data

log:
level:
default: debug
tendermint: debug
tendermint/context: error
format: JSON

genesis:
file: /node/etc/genesis.json

consensus:
tendermint:
p2p:
seed:
- "[email protected]:26656"

runtime:
mode: client
paths:
- /node/runtime/cipher-paratime-2.6.2.orc
- /node/runtime/emerald-paratime-10.0.0.orc
- /node/runtime/sapphire-paratime-0.4.0.orc

worker:
storage:
checkpointer:
enabled: true
`

func prepareTest(require *require.Assertions, configIn string) config.Config {
// Prepare temporary directory and populate it with the test config file.
tempDir, err := os.MkdirTemp("", "oasis-node-config_migrate_test_")
Expand Down Expand Up @@ -778,3 +817,24 @@ func TestConfigMigrationDocsSentry(t *testing.T) {
require.Equal(newConfig.P2P.Seeds[1], "H6u9MtuoWRKn5DKSgarj/[email protected]:9200")
require.Equal(newConfig.Consensus.SentryUpstreamAddresses[0], "[email protected]:26656")
}

func TestConfigMigrationSocketOverride(t *testing.T) {
require := require.New(t)
newConfig := prepareTest(require, testInternalSocketOverrideConfigRaw)

// Now check if the config struct fields actually match the original state.
require.Equal(newConfig.Mode, config.ModeClient)
require.Equal(newConfig.Common.DataDir, "/node/data")
require.Equal(newConfig.Common.Log.Format, "JSON")
require.Equal(newConfig.Common.Log.Level["default"], "debug")
require.Equal(newConfig.Common.Log.Level["cometbft"], "debug")
require.Equal(newConfig.Common.Log.Level["cometbft/context"], "error")
require.Equal(newConfig.Genesis.File, "/node/etc/genesis.json")
require.Equal(newConfig.P2P.Seeds[0], "H6u9MtuoWRKn5DKSgarj/[email protected]:26656")
require.Equal(newConfig.P2P.Seeds[1], "H6u9MtuoWRKn5DKSgarj/[email protected]:9200")
require.Equal(newConfig.Runtime.Paths[0], "/node/runtime/cipher-paratime-2.6.2.orc")
require.Equal(newConfig.Runtime.Paths[1], "/node/runtime/emerald-paratime-10.0.0.orc")
require.Equal(newConfig.Runtime.Paths[2], "/node/runtime/sapphire-paratime-0.4.0.orc")
require.Equal(newConfig.Storage.Checkpointer.Enabled, true)
require.Equal(newConfig.Common.InternalSocketPath, "/node/custom-internal.sock")
}
12 changes: 6 additions & 6 deletions go/oasis-node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func testConsensus(t *testing.T, node *testNode) {

func testConsensusClient(t *testing.T, node *testNode) {
// Create a client backend connected to the local node's internal socket.
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, "internal.sock"),
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, cmdCommon.InternalSocketName),
grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "Dial")

Expand Down Expand Up @@ -346,7 +346,7 @@ func testScheduler(t *testing.T, node *testNode) {

func testSchedulerClient(t *testing.T, node *testNode) {
// Create a client backend connected to the local node's internal socket.
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, "internal.sock"),
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, cmdCommon.InternalSocketName),
grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "Dial")
defer conn.Close()
Expand All @@ -361,7 +361,7 @@ func testStaking(t *testing.T, node *testNode) {

func testStakingClient(t *testing.T, node *testNode) {
// Create a client backend connected to the local node's internal socket.
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, "internal.sock"),
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, cmdCommon.InternalSocketName),
grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "Dial")
defer conn.Close()
Expand All @@ -379,7 +379,7 @@ func testRootHash(t *testing.T, node *testNode) {
// Over gRPC.
t.Run("OverGrpc", func(t *testing.T) {
// Create a client backend connected to the local node's internal socket.
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, "internal.sock"),
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, cmdCommon.InternalSocketName),
grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "Dial")
defer conn.Close()
Expand All @@ -398,7 +398,7 @@ func testGovernance(t *testing.T, node *testNode) {
// Over gRPC.
t.Run("OverGrpc", func(t *testing.T) {
// Create a client backend connected to the local node's internal socket.
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, "internal.sock"),
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, cmdCommon.InternalSocketName),
grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "Dial")
defer conn.Close()
Expand Down Expand Up @@ -435,7 +435,7 @@ func testRuntimeClient(t *testing.T, node *testNode) {
// Over gRPC.
t.Run("OverGrpc", func(t *testing.T) {
// Create a client backend connected to the local node's internal socket.
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, "internal.sock"),
conn, err := cmnGrpc.Dial("unix:"+filepath.Join(node.dataDir, cmdCommon.InternalSocketName),
grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err, "Dial")
defer conn.Close()
Expand Down
8 changes: 0 additions & 8 deletions go/oasis-test-runner/oasis/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,6 @@ func (args *argBuilder) grpcLogDebug() *argBuilder {
return args
}

func (args *argBuilder) grpcDebugGrpcInternalSocketPath(path string) *argBuilder {
args.vec = append(args.vec, Argument{
Name: grpc.CfgDebugGrpcInternalSocketPath,
Values: []string{path},
})
return args
}

func (args *argBuilder) iasDebugMock() *argBuilder {
args.vec = append(args.vec, Argument{Name: "ias.debug.mock"})
return args
Expand Down
3 changes: 1 addition & 2 deletions go/oasis-test-runner/oasis/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,7 @@ func (net *Network) startOasisNode(
if node.customGrpcSocketPath == "" {
node.customGrpcSocketPath = net.generateTempSocketPath(node.Name)
}
extraArgs = extraArgs.debugDontBlameOasis()
extraArgs = extraArgs.grpcDebugGrpcInternalSocketPath(node.customGrpcSocketPath)
cfg.Common.InternalSocketPath = node.customGrpcSocketPath
}
if node.consensusStateSync != nil {
cfg.Consensus.StateSync.Enabled = true
Expand Down
3 changes: 1 addition & 2 deletions go/oasis-test-runner/oasis/oasis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/oasisprotocol/oasis-core/go/config"
"github.com/oasisprotocol/oasis-core/go/consensus/cometbft/abci"
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/grpc"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/log"
)
Expand Down Expand Up @@ -504,7 +503,7 @@ func nodeLogPath(dir *env.Dir) string {
}

func internalSocketPath(dir *env.Dir) string {
return filepath.Join(dir.String(), grpc.LocalSocketFilename)
return filepath.Join(dir.String(), cmdCommon.InternalSocketName)
}

func nodeIdentityKeyPath(dir *env.Dir) string {
Expand Down
Loading