Skip to content

Commit

Permalink
Remove go-plugin dependency (ava-labs#2563)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen <[email protected]>
  • Loading branch information
hexfusion and StephenButtolph authored Feb 19, 2023
1 parent 73b8717 commit a33c8c2
Show file tree
Hide file tree
Showing 56 changed files with 1,645 additions and 1,682 deletions.
20 changes: 8 additions & 12 deletions api/keystore/gkeystore/keystore_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package gkeystore
import (
"context"

"google.golang.org/grpc"

"github.com/ava-labs/avalanchego/api/keystore"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/rpcdb"
Expand Down Expand Up @@ -43,21 +41,19 @@ func (s *Server) GetDatabase(

closer := dbCloser{Database: db}

// start the db server
serverListener, err := grpcutils.NewListener()
if err != nil {
return nil, err
}
serverAddr := serverListener.Addr().String()

go grpcutils.Serve(serverListener, func(opts []grpc.ServerOption) *grpc.Server {
server := grpcutils.NewDefaultServer(opts)
closer.closer.Add(server)
db := rpcdb.NewServer(&closer)
rpcdbpb.RegisterDatabaseServer(server, db)
return server
})
return &keystorepb.GetDatabaseResponse{ServerAddr: serverAddr}, nil
server := grpcutils.NewServer()
closer.closer.Add(server)
rpcdbpb.RegisterDatabaseServer(server, rpcdb.NewServer(&closer))

// start the db server
go grpcutils.Serve(serverListener, server)

return &keystorepb.GetDatabaseResponse{ServerAddr: serverListener.Addr().String()}, nil
}

type dbCloser struct {
Expand Down
56 changes: 0 additions & 56 deletions app/plugin/plugin.go

This file was deleted.

41 changes: 0 additions & 41 deletions app/plugin/plugin_client.go

This file was deleted.

41 changes: 0 additions & 41 deletions app/plugin/plugin_server.go

This file was deleted.

49 changes: 0 additions & 49 deletions app/plugin/process.go

This file was deleted.

3 changes: 0 additions & 3 deletions app/runner/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ package runner
type Config struct {
// If true, displays version and exits during startup
DisplayVersionAndExit bool

// If true, run AvalancheGo as a plugin
PluginMode bool
}
24 changes: 1 addition & 23 deletions app/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,16 @@ import (
"fmt"
"os"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"

"golang.org/x/term"

"github.com/ava-labs/avalanchego/app"
"github.com/ava-labs/avalanchego/app/process"
"github.com/ava-labs/avalanchego/node"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils"

appplugin "github.com/ava-labs/avalanchego/app/plugin"
)

// Run an AvalancheGo node.
// If specified in the config, serves a hashicorp plugin that can be consumed by
// the daemon (see avalanchego/main).
func Run(config Config, nodeConfig node.Config) {
func Run(nodeConfig node.Config) {
nodeApp := process.NewApp(nodeConfig) // Create node wrapper
if config.PluginMode { // Serve as a plugin
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: appplugin.Handshake,
Plugins: map[string]plugin.Plugin{
appplugin.Name: appplugin.New(nodeApp),
},
GRPCServer: grpcutils.NewDefaultServer, // A non-nil value here enables gRPC serving for this plugin
Logger: hclog.New(&hclog.LoggerOptions{
Level: hclog.Error,
}),
})
return
}

if term.IsTerminal(int(os.Stdout.Fd())) {
fmt.Println(process.Header)
}
Expand Down
36 changes: 9 additions & 27 deletions chains/atomic/gsharedmemory/shared_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,21 @@
package gsharedmemory

import (
"context"
"io"
"net"
"testing"

"github.com/stretchr/testify/require"

"google.golang.org/grpc"
"google.golang.org/grpc/test/bufconn"

"github.com/ava-labs/avalanchego/chains/atomic"
"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/memdb"
"github.com/ava-labs/avalanchego/database/prefixdb"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/rpcchainvm/grpcutils"

sharedmemorypb "github.com/ava-labs/avalanchego/proto/pb/sharedmemory"
)

const (
bufSize = units.MiB
)

func TestInterface(t *testing.T) {
require := require.New(t)

Expand Down Expand Up @@ -56,27 +46,19 @@ func TestInterface(t *testing.T) {
}

func wrapSharedMemory(t *testing.T, sm atomic.SharedMemory, db database.Database) (atomic.SharedMemory, io.Closer) {
listener := bufconn.Listen(bufSize)
serverCloser := grpcutils.ServerCloser{}

serverFunc := func(opts []grpc.ServerOption) *grpc.Server {
server := grpcutils.NewDefaultServer(opts)
sharedmemorypb.RegisterSharedMemoryServer(server, NewServer(sm, db))
serverCloser.Add(server)
return server
listener, err := grpcutils.NewListener()
if err != nil {
t.Fatalf("Failed to create listener: %s", err)
}
serverCloser := grpcutils.ServerCloser{}

go grpcutils.Serve(listener, serverFunc)
server := grpcutils.NewServer()
sharedmemorypb.RegisterSharedMemoryServer(server, NewServer(sm, db))
serverCloser.Add(server)

dialer := grpc.WithContextDialer(
func(context.Context, string) (net.Conn, error) {
return listener.Dial()
},
)
go grpcutils.Serve(listener, server)

dopts := grpcutils.DefaultDialOptions
dopts = append(dopts, dialer)
conn, err := grpcutils.Dial("", dopts...)
conn, err := grpcutils.Dial(listener.Addr().String())
if err != nil {
t.Fatalf("Failed to dial: %s", err)
}
Expand Down
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ var (
func GetRunnerConfig(v *viper.Viper) runner.Config {
return runner.Config{
DisplayVersionAndExit: v.GetBool(VersionKey),
PluginMode: v.GetBool(PluginModeKey),
}
}

Expand Down
3 changes: 0 additions & 3 deletions config/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ var (
func addProcessFlags(fs *flag.FlagSet) {
// If true, print the version and quit.
fs.Bool(VersionKey, false, "If true, print version and quit")

// Plugin
fs.Bool(PluginModeKey, false, "Whether the app should run as a plugin")
}

func addNodeFlags(fs *flag.FlagSet) {
Expand Down
1 change: 0 additions & 1 deletion config/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ const (
RetryBootstrapKey = "bootstrap-retry-enabled"
RetryBootstrapWarnFrequencyKey = "bootstrap-retry-warn-frequency"
PluginDirKey = "plugin-dir"
PluginModeKey = "plugin-mode-enabled"
BootstrapBeaconConnectionTimeoutKey = "bootstrap-beacon-connection-timeout"
BootstrapMaxTimeGetAncestorsKey = "bootstrap-max-time-get-ancestors"
BootstrapAncestorsMaxContainersSentKey = "bootstrap-ancestors-max-containers-sent"
Expand Down
Loading

0 comments on commit a33c8c2

Please sign in to comment.