-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial draft * Add median provider checks * Move provider-server to relay * Bump chainlink-relay version * Add tests * Add comment explaining why the code lives inside the newServicesGenericPlugin method * Fix formatting * Fix lint
- Loading branch information
1 parent
94625ef
commit 0ba7e9a
Showing
4 changed files
with
141 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package relay | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"go.uber.org/multierr" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
"github.com/smartcontractkit/chainlink-relay/pkg/loop" | ||
"github.com/smartcontractkit/chainlink-relay/pkg/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
type ProviderServer struct { | ||
s *grpc.Server | ||
lis net.Listener | ||
lggr logger.Logger | ||
conns []*grpc.ClientConn | ||
} | ||
|
||
func (p *ProviderServer) Start(ctx context.Context) error { | ||
p.serve() | ||
return nil | ||
} | ||
|
||
func (p *ProviderServer) Close() error { | ||
var err error | ||
for _, c := range p.conns { | ||
err = multierr.Combine(err, c.Close()) | ||
} | ||
p.s.Stop() | ||
return err | ||
} | ||
|
||
func (p *ProviderServer) GetConn() (*grpc.ClientConn, error) { | ||
cc, err := grpc.Dial(p.lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
p.conns = append(p.conns, cc) | ||
return cc, err | ||
} | ||
|
||
// NewProviderServer creates a GRPC server that will wrap a provider, this is a workaround to test the Node API PoC until the EVM relayer is loopifyed | ||
func NewProviderServer(p types.PluginProvider, pType types.OCR2PluginType, lggr logger.Logger) (*ProviderServer, error) { | ||
lis, err := net.Listen("tcp", "127.0.0.1:0") | ||
if err != nil { | ||
return nil, err | ||
} | ||
ps := ProviderServer{ | ||
s: grpc.NewServer(), | ||
lis: lis, | ||
lggr: lggr.Named("EVM.ProviderServer"), | ||
} | ||
err = loop.RegisterStandAloneProvider(ps.s, p, pType) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &ps, nil | ||
} | ||
|
||
func (p *ProviderServer) serve() { | ||
go func() { | ||
if err := p.s.Serve(p.lis); err != nil { | ||
p.lggr.Errorf("Failed to serve EVM provider server: %v", err) | ||
} | ||
}() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package relay | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink-relay/pkg/types" | ||
"github.com/smartcontractkit/chainlink/v2/core/logger" | ||
) | ||
|
||
func TestProviderServer(t *testing.T) { | ||
r := &mockRelayer{} | ||
sa := NewServerAdapter(r, mockRelayerExt{}) | ||
mp, _ := sa.NewPluginProvider(context.Background(), types.RelayArgs{ProviderType: string(types.Median)}, types.PluginArgs{}) | ||
|
||
lggr := logger.TestLogger(t) | ||
_, err := NewProviderServer(mp, "unsupported-type", lggr) | ||
require.Error(t, err) | ||
|
||
ps, err := NewProviderServer(staticMedianProvider{}, types.Median, lggr) | ||
require.NoError(t, err) | ||
|
||
_, err = ps.GetConn() | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters