Skip to content

Commit

Permalink
Move config structs
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Jul 8, 2024
1 parent 23bfb8a commit 3d59b02
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 91 deletions.
32 changes: 32 additions & 0 deletions pkg/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,35 @@ outerLoop:

return &values.List{Underlying: vs}, nil
}

const (
DefaultRegistrationRefreshMs = 30_000
DefaultRegistrationExpiryMs = 120_000
DefaultMessageExpiryMs = 120_000
)

type RemoteTriggerConfig struct {
RegistrationRefreshMs uint32
RegistrationExpiryMs uint32
MinResponsesToAggregate uint32
MessageExpiryMs uint32
}

// NOTE: consider splitting this config into values stored in Registry (KS-118)
// and values defined locally by Capability owners.
func (c *RemoteTriggerConfig) ApplyDefaults() {
if c.RegistrationRefreshMs == 0 {
c.RegistrationRefreshMs = DefaultRegistrationRefreshMs
}
if c.RegistrationExpiryMs == 0 {
c.RegistrationExpiryMs = DefaultRegistrationExpiryMs
}
if c.MessageExpiryMs == 0 {
c.MessageExpiryMs = DefaultMessageExpiryMs
}
}

type CapabilityConfiguration struct {
ExecuteConfig *values.Map
RemoteTriggerConfig RemoteTriggerConfig
}
2 changes: 1 addition & 1 deletion pkg/capabilities/pb/registry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/net"
"github.com/smartcontractkit/chainlink-common/pkg/loop/internal/pb"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink-common/pkg/values"

p2ptypes "github.com/smartcontractkit/libocr/ragep2p/types"
)
Expand Down Expand Up @@ -76,6 +77,33 @@ func (cr *capabilitiesRegistryClient) GetLocalNode(ctx context.Context) (capabil
}, nil
}

func (cr *capabilitiesRegistryClient) ConfigForCapability(ctx context.Context, capabilityID string, donID uint32) (capabilities.CapabilityConfiguration, error) {
res, err := cr.grpc.ConfigForCapability(ctx, &pb.ConfigForCapabilityRequest{
CapabilityID: capabilityID,
DonID: donID,
})
if err != nil {
return capabilities.CapabilityConfiguration{}, err
}

mc := values.FromMapValueProto(res.CapabilityConfig.ExecuteConfig)

var rtc capabilities.RemoteTriggerConfig
rtc.ApplyDefaults()

if prtc := res.CapabilityConfig.GetRemoteTriggerConfig(); prtc != nil {
rtc.RegistrationRefreshMs = prtc.RegistrationRefreshMs
rtc.RegistrationExpiryMs = prtc.RegistrationExpiryMs
rtc.MinResponsesToAggregate = prtc.MinResponsesToAggregate
rtc.MessageExpiryMs = prtc.MessageExpiryMs
}

return capabilities.CapabilityConfiguration{
ExecuteConfig: mc,
RemoteTriggerConfig: rtc,
}, nil
}

func (cr *capabilitiesRegistryClient) Get(ctx context.Context, ID string) (capabilities.BaseCapability, error) {
req := &pb.GetRequest{
Id: ID,
Expand Down Expand Up @@ -257,6 +285,31 @@ func (c *capabilitiesRegistryServer) Get(ctx context.Context, request *pb.GetReq
}, nil
}

func (c *capabilitiesRegistryServer) ConfigForCapability(ctx context.Context, req *pb.ConfigForCapabilityRequest) (*pb.ConfigForCapabilityReply, error) {
cc, err := c.impl.ConfigForCapability(ctx, req.CapabilityID, req.DonID)
if err != nil {
return nil, err
}

ecm := values.Proto(cc.ExecuteConfig).GetMapValue()

ccp := &capabilitiespb.CapabilityConfig{
ExecuteConfig: ecm,
RemoteConfig: &capabilitiespb.CapabilityConfig_RemoteTriggerConfig{
RemoteTriggerConfig: &capabilitiespb.RemoteTriggerConfig{
RegistrationRefreshMs: cc.RemoteTriggerConfig.RegistrationRefreshMs,
RegistrationExpiryMs: cc.RemoteTriggerConfig.RegistrationExpiryMs,
MinResponsesToAggregate: cc.RemoteTriggerConfig.MinResponsesToAggregate,
MessageExpiryMs: cc.RemoteTriggerConfig.MessageExpiryMs,
},
},
}

return &pb.ConfigForCapabilityReply{
CapabilityConfig: ccp,
}, nil
}

func (c *capabilitiesRegistryServer) GetLocalNode(ctx context.Context, _ *emptypb.Empty) (*pb.GetLocalNodeReply, error) {
node, err := c.impl.GetLocalNode(ctx)
if err != nil {
Expand Down
315 changes: 234 additions & 81 deletions pkg/loop/internal/pb/capabilities_registry.pb.go

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions pkg/loop/internal/pb/capabilities_registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ option go_package = "github.com/smartcontractkit/chainlink-common/pkg/loop/inter
package loop;

import "google/protobuf/empty.proto";
import "capabilities/pb/registry.proto";

service CapabilitiesRegistry {
rpc GetLocalNode (google.protobuf.Empty) returns (GetLocalNodeReply) {}
rpc ConfigForCapability (ConfigForCapabilityRequest) returns (ConfigForCapabilityReply) {}
rpc Get (GetRequest) returns (GetReply) {}
rpc GetTrigger (GetTriggerRequest) returns (GetTriggerReply) {}
rpc GetAction (GetActionRequest) returns (GetActionReply) {}
Expand Down Expand Up @@ -101,3 +103,12 @@ message AddRequest {
uint32 capabilityID = 1;
ExecuteAPIType type = 2;
}

message ConfigForCapabilityRequest {
string capabilityID = 1;
uint32 donID = 2;
}

message ConfigForCapabilityReply {
loop.CapabilityConfig capability_config = 1;
}
53 changes: 45 additions & 8 deletions pkg/loop/internal/pb/capabilities_registry_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/loop/internal/pb/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative codec.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative keyvalue_store.proto
//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative validate_config.proto
//go:generate protoc --go_out=../../../ --go_opt=paths=source_relative --go-grpc_out=../../../ --go-grpc_opt=paths=source_relative --proto_path=../../../ capabilities/pb/capabilities.proto values/pb/values.proto loop/internal/pb/capabilities_registry.proto
//go:generate protoc --go_out=../../../ --go_opt=paths=source_relative --go-grpc_out=../../../ --go-grpc_opt=paths=source_relative --proto_path=../../../ capabilities/pb/capabilities.proto capabilities/pb/registry.proto values/pb/values.proto loop/internal/pb/capabilities_registry.proto
package pb
2 changes: 2 additions & 0 deletions pkg/types/core/capabilities_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
//go:generate mockery --quiet --name CapabilitiesRegistry --output ./mocks/ --case=underscore
type CapabilitiesRegistry interface {
GetLocalNode(ctx context.Context) (capabilities.Node, error)
ConfigForCapability(ctx context.Context, capabilityID string, donID uint32) (capabilities.CapabilityConfiguration, error)

Get(ctx context.Context, ID string) (capabilities.BaseCapability, error)
GetTrigger(ctx context.Context, ID string) (capabilities.TriggerCapability, error)
GetAction(ctx context.Context, ID string) (capabilities.ActionCapability, error)
Expand Down
28 changes: 28 additions & 0 deletions pkg/types/core/mocks/capabilities_registry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3d59b02

Please sign in to comment.