Skip to content

Commit

Permalink
grpc: Refactor internal socket code, update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matevz committed Apr 23, 2020
1 parent 4ea2199 commit 2be970c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 29 deletions.
File renamed without changes.
8 changes: 8 additions & 0 deletions .changelog/2687.breaking.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
`oasis-net-runner`: Use abstract socket for internal gRPC

Internal gRPC now uses abstract unix socket names instead of absolute file
paths. This was necessary because unix socket path length limit was too low
for some of our e2e test scenarios with longer name. Fox example providing
client address `-a
unix:/tmp/oasis-net-runner530668299/net-runner/network/client-0/internal.sock`
now becomes `-a unix:@dcdefd1d`.
7 changes: 3 additions & 4 deletions .changelog/2687.internal.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
- Scenario names now use corresponding namespace. e.g. `halt-restore` is now
`e2e/runtime/halt-restore`.
- Scenario parameters are now exposed and settable via CLI by reimplementing
`scenario.Parameters()` and setting it with `--<testname>.<param>=<val>`.
`scenario.Parameters()` and setting it with `--<test_name>.<param>=<val>`.
- Scenario parameters can also be generally set, for example
`--e2e.node.binary` will set `node.binary` parameter for all E2E tests and
`--e2e/runtime.node.binary` will set it for tests which inherit `runtime`.
- Multiple parameter values can be provided in form
`--<testname>.<param>=<val1>,<val2>,...`. In this case, `oasis-test-runner`
`--<test_name>.<param>=<val1>,<val2>,...`. In this case, `oasis-test-runner`
combines them with other parameters and generates unique parameter sets for
each test.
- Each scenario is run in a unique datadir per parameter set of form
`oasis-test-runnerXXXXXX/<testhash>/<run_id>`. `<testhash>` is a prefix of
hashed name of the test in order to keep datadir as short as possible.
`oasis-test-runnerXXXXXX/<test_name>/<run_id>`.
- If metrics are enabled, new labels are passed to oasis-nodes and pushed to
Prometheus for each test:
- `instance`,
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ started and at the end the following message should appear:
<!-- markdownlint-disable line-length -->
```
level=info module=oasis/net-runner caller=oasis.go:319 ts=2019-10-03T10:47:30.776566482Z msg="network started"
level=info module=net-runner caller=root.go:145 ts=2019-10-03T10:47:30.77662061Z msg="client node socket available" path=/tmp/oasis-net-runner530668299/net-runner/network/client-0/internal.sock
level=info module=net-runner caller=root.go:145 ts=2019-10-03T10:47:30.77662061Z msg="client node socket available" path=@1a2b3c4d
```
<!-- markdownlint-enable line-length -->

Expand All @@ -304,7 +304,7 @@ different terminal:
```
./target/default/debug/simple-keyvalue-client \
--runtime-id 8000000000000000000000000000000000000000000000000000000000000000 \
--node-address unix:/tmp/oasis-net-runner530668299/net-runner/network/client-0/internal.sock
--node-address unix:@dcdefd1d
```

By default, Oasis node is configured with a 30-second epoch, so you may
Expand Down
7 changes: 7 additions & 0 deletions go/common/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package grpc

import (
"context"
"crypto/sha256"
"crypto/tls"
"fmt"
"net"
Expand Down Expand Up @@ -508,6 +509,12 @@ func Dial(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
return grpc.Dial(target, dialOpts...)
}

// GetInternalSocketPath returns abstract socket address for internal gRPC based on hashed datadir.
func GetInternalSocketPath(datadir string) string {
p := sha256.Sum256([]byte(datadir))
return fmt.Sprintf("@%x", p[0:4])
}

func init() {
Flags.Bool(CfgLogDebug, false, "gRPC request/responses in debug logs (very verbose)")
_ = Flags.MarkHidden(CfgLogDebug)
Expand Down
2 changes: 1 addition & 1 deletion go/extra/stats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ signature counts.

```
$ stats/stats entity-signatures \
--address unix:<node_dir>/internal.sock \
--address unix:<abstract_socket> \
--start-block 0 \
--end-block 100 \
--top-n 100
Expand Down
2 changes: 1 addition & 1 deletion go/oasis-net-runner/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func runRoot(cmd *cobra.Command, args []string) error {
// Display information about where the client node socket is.
if len(net.Clients()) > 0 {
logger.Info("client node socket available",
"path", "unix:"+net.Clients()[0].SocketPath(),
"path", net.Clients()[0].SocketPath(),
)
}

Expand Down
10 changes: 2 additions & 8 deletions go/oasis-node/cmd/common/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
package grpc

import (
"crypto/sha256"
"crypto/tls"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
Expand All @@ -27,9 +25,6 @@ const (
CfgAddress = "address"
// CfgWait waits for the remote address to become available.
CfgWait = "wait"

defaultAddress = "unix:" + localSocketFilename
localSocketFilename = "internal.sock"
)

var (
Expand Down Expand Up @@ -69,8 +64,7 @@ func NewServerLocal(installWrapper bool) (*cmnGrpc.Server, error) {
if dataDir == "" {
return nil, errors.New("data directory must be set")
}
p := filepath.Join(dataDir, localSocketFilename)
path := fmt.Sprintf("@%x", sha256.Sum256([]byte(p)))
path := cmnGrpc.GetInternalSocketPath(dataDir)

config := &cmnGrpc.ServerConfig{
Name: "internal",
Expand Down Expand Up @@ -112,7 +106,7 @@ func init() {

ServerLocalFlags.AddFlagSet(cmnGrpc.Flags)

ClientFlags.StringP(CfgAddress, "a", defaultAddress, "remote gRPC address")
ClientFlags.StringP(CfgAddress, "a", "", "remote gRPC address")
ClientFlags.Bool(CfgWait, false, "wait for gRPC address to become available")
_ = viper.BindPFlags(ClientFlags)
}
8 changes: 4 additions & 4 deletions go/oasis-node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,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"), grpc.WithInsecure())
conn, err := cmnGrpc.Dial("unix:"+cmnGrpc.GetInternalSocketPath(node.dataDir), grpc.WithInsecure())
require.NoError(t, err, "Dial")

client := consensusAPI.NewConsensusClient(conn)
Expand Down Expand Up @@ -410,7 +410,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"), grpc.WithInsecure())
conn, err := cmnGrpc.Dial("unix:"+cmnGrpc.GetInternalSocketPath(node.dataDir), grpc.WithInsecure())
require.NoError(t, err, "Dial")
defer conn.Close()

Expand All @@ -424,7 +424,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"), grpc.WithInsecure())
conn, err := cmnGrpc.Dial("unix:"+cmnGrpc.GetInternalSocketPath(node.dataDir), grpc.WithInsecure())
require.NoError(t, err, "Dial")
defer conn.Close()

Expand Down Expand Up @@ -471,7 +471,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"), grpc.WithInsecure())
conn, err := cmnGrpc.Dial("unix:"+cmnGrpc.GetInternalSocketPath(node.dataDir), grpc.WithInsecure())
require.NoError(t, err, "Dial")
defer conn.Close()

Expand Down
11 changes: 2 additions & 9 deletions go/oasis-test-runner/oasis/oasis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package oasis

import (
"crypto"
"crypto/sha256"
"fmt"
"io"
"math"
Expand All @@ -21,6 +20,7 @@ import (
"github.com/oasislabs/oasis-core/go/common/crypto/drbg"
"github.com/oasislabs/oasis-core/go/common/crypto/signature"
fileSigner "github.com/oasislabs/oasis-core/go/common/crypto/signature/signers/file"
"github.com/oasislabs/oasis-core/go/common/grpc"
"github.com/oasislabs/oasis-core/go/common/identity"
"github.com/oasislabs/oasis-core/go/common/logging"
"github.com/oasislabs/oasis-core/go/common/node"
Expand All @@ -44,8 +44,6 @@ const (
defaultEpochtimeTendermintInterval = 30
defaultHaltEpoch = math.MaxUint64

internalSocketFile = "internal.sock"

logNodeFile = "node.log"
logConsoleFile = "console.log"
exportsDir = "exports"
Expand Down Expand Up @@ -87,7 +85,7 @@ func (n *Node) Exit() chan error {

// SocketPath returns the path to the node's gRPC socket.
func (n *Node) SocketPath() string {
return internalSocketPath(n.dir)
return grpc.GetInternalSocketPath(n.dir.String())
}

// LogPath returns the path to the node's log.
Expand Down Expand Up @@ -811,11 +809,6 @@ func nodeLogPath(dir *env.Dir) string {
return filepath.Join(dir.String(), logNodeFile)
}

func internalSocketPath(dir *env.Dir) string {
p := filepath.Join(dir.String(), internalSocketFile)
return fmt.Sprintf("@%x", sha256.Sum256([]byte(p)))
}

func nodeIdentityKeyPath(dir *env.Dir) string {
return filepath.Join(dir.String(), fileSigner.FileIdentityKey)
}
Expand Down

0 comments on commit 2be970c

Please sign in to comment.