Skip to content

Commit

Permalink
Fix panic when fetching the binary
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-cordenier committed Dec 3, 2024
1 parent 9deaaf5 commit 52f7e36
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
18 changes: 16 additions & 2 deletions core/capabilities/webapi/outgoing_connector_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/api"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/connector"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/handlers/capabilities"
Expand All @@ -19,6 +20,7 @@ import (
var _ connector.GatewayConnectorHandler = &OutgoingConnectorHandler{}

type OutgoingConnectorHandler struct {
services.StateMachine
gc connector.GatewayConnector
method string
lggr logger.Logger
Expand Down Expand Up @@ -125,11 +127,23 @@ func (c *OutgoingConnectorHandler) HandleGatewayMessage(ctx context.Context, gat
}

func (c *OutgoingConnectorHandler) Start(ctx context.Context) error {
return c.gc.AddHandler([]string{c.method}, c)
return c.StartOnce("OutgoingConnectorHandler", func() error {
return c.gc.AddHandler([]string{c.method}, c)
})
}

func (c *OutgoingConnectorHandler) Close() error {
return nil
return c.StopOnce("OutgoingConnectorHandler", func() error {
return nil
})
}

func (c *OutgoingConnectorHandler) HealthReport() map[string]error {
return map[string]error{c.Name(): nil}
}

func (c *OutgoingConnectorHandler) Name() string {
return c.lggr.Name()
}

func validMethod(method string) bool {
Expand Down
8 changes: 4 additions & 4 deletions core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
}

connector := gatewayConnectorWrapper.GetGatewayConnector()
webAPILggr := globalLogger.Named("WebAPITarget")
outgoingConnectorLggr := globalLogger.Named("WorkflowSyncer")

webAPIConfig := webapi.ServiceConfig{
RateLimiter: common2.RateLimiterConfig{
Expand All @@ -317,7 +317,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {

outgoingConnectorHandler, err := webapi.NewOutgoingConnectorHandler(connector,
webAPIConfig,
capabilities2.MethodWebAPITarget, webAPILggr)
capabilities2.MethodWorkflowSyncer, outgoingConnectorLggr)
if err != nil {
return nil, fmt.Errorf("could not create outgoing connector handler: %w", err)
}
Expand All @@ -326,7 +326,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
syncer.NewFetcherFunc(globalLogger, outgoingConnectorHandler), workflowstore.NewDBStore(opts.DS, globalLogger, clockwork.NewRealClock()), opts.CapabilitiesRegistry,
custmsg.NewLabeler(), clockwork.NewRealClock(), keys[0])

loader := syncer.NewWorkflowRegistryContractLoader(cfg.Capabilities().WorkflowRegistry().Address(), func(ctx context.Context, bytes []byte) (syncer.ContractReader, error) {
loader := syncer.NewWorkflowRegistryContractLoader(globalLogger, cfg.Capabilities().WorkflowRegistry().Address(), func(ctx context.Context, bytes []byte) (syncer.ContractReader, error) {
return relayer.NewContractReader(ctx, bytes)
}, eventHandler)

Expand All @@ -338,7 +338,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
QueryCount: 100,
}, eventHandler, loader, workflowDonNotifier)

srvcs = append(srvcs, wfSyncer)
srvcs = append(srvcs, outgoingConnectorHandler, wfSyncer)
}
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/services/gateway/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

// GatewayConnector is a component run by Nodes to connect to a set of Gateways.
type GatewayConnector interface {
job.ServiceCtx
services.Service
network.ConnectionInitiator

AddHandler(methods []string, handler GatewayConnectorHandler) error
Expand Down
4 changes: 4 additions & 0 deletions core/services/workflows/syncer/workflow_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,17 +556,20 @@ func (r workflowAsEvent) GetData() any {
}

type workflowRegistryContractLoader struct {
lggr logger.Logger
workflowRegistryAddress string
newContractReaderFn newContractReaderFn
handler evtHandler
}

func NewWorkflowRegistryContractLoader(
lggr logger.Logger,
workflowRegistryAddress string,
newContractReaderFn newContractReaderFn,
handler evtHandler,
) *workflowRegistryContractLoader {
return &workflowRegistryContractLoader{
lggr: lggr.Named("WorkflowRegistryContractLoader"),
workflowRegistryAddress: workflowRegistryAddress,
newContractReaderFn: newContractReaderFn,
handler: handler,
Expand Down Expand Up @@ -624,6 +627,7 @@ func (l *workflowRegistryContractLoader) LoadWorkflows(ctx context.Context, don
return nil, fmt.Errorf("failed to get workflow metadata for don %w", err)
}

l.lggr.Debugw("Rehydrating existing workflows", "len", len(workflows.WorkflowMetadataList))
for _, workflow := range workflows.WorkflowMetadataList {
if err = l.handler.Handle(ctx, workflowAsEvent{
Data: workflow,
Expand Down

0 comments on commit 52f7e36

Please sign in to comment.