diff --git a/core/capabilities/testutils/backend.go b/core/capabilities/testutils/backend.go index 9ec15a56899..fac9124f9ff 100644 --- a/core/capabilities/testutils/backend.go +++ b/core/capabilities/testutils/backend.go @@ -45,7 +45,7 @@ type EVMBackendTH struct { // Test harness to create a simulated backend for testing a LOOPCapability func NewEVMBackendTH(t *testing.T) *EVMBackendTH { - lggr, _ := logger.NewLogger() + lggr := logger.TestLogger(t) ownerKey := cltest.MustGenerateRandomKey(t) contractsOwner, err := bind.NewKeyedTransactorWithChainID(ownerKey.ToEcdsaPrivKey(), testutils.SimulatedChainID) diff --git a/core/capabilities/triggers/logevent/service.go b/core/capabilities/triggers/logevent/service.go index d9e9d1e76f3..9f839c87856 100644 --- a/core/capabilities/triggers/logevent/service.go +++ b/core/capabilities/triggers/logevent/service.go @@ -41,7 +41,7 @@ type TriggerService struct { // Common capability level config across all workflows type Config struct { - ChainID uint64 `json:"chainId"` + ChainID string `json:"chainId"` Network string `json:"network"` LookbackBlocks uint64 `json:"lookbakBlocks"` PollPeriod uint32 `json:"pollPeriod"` @@ -54,7 +54,6 @@ func (config Config) Version(capabilityVersion string) string { type Params struct { Logger logger.Logger Relayer core.Relayer - RelayerSet core.RelayerSet LogEventConfig Config } @@ -63,7 +62,7 @@ var _ services.Service = &TriggerService{} // Creates a new Cron Trigger Service. // Scheduling will commence on calling .Start() -func NewLogEventTriggerService(p Params) *TriggerService { +func NewTriggerService(p Params) *TriggerService { l := logger.Named(p.Logger, "LogEventTriggerCapabilityService") logEventStore := NewCapabilitiesStore[logEventTrigger, capabilities.TriggerResponse]() @@ -74,7 +73,6 @@ func NewLogEventTriggerService(p Params) *TriggerService { relayer: p.Relayer, logEventConfig: p.LogEventConfig, stopChan: make(services.StopChan), - wg: sync.WaitGroup{}, } s.CapabilityInfo, _ = s.Info(context.Background()) s.Validator = capabilities.NewValidator[RequestConfig, Input, capabilities.TriggerResponse](capabilities.ValidatorArgs{Info: s.CapabilityInfo}) @@ -100,7 +98,8 @@ func (s *TriggerService) RegisterTrigger(ctx context.Context, req capabilities.T return nil, err } // Add log event trigger with Contract details to CapabilitiesStore - respCh, err := s.triggers.InsertIfNotExists(req.TriggerID, func() (*logEventTrigger, chan capabilities.TriggerResponse, error) { + var respCh chan capabilities.TriggerResponse + respCh, err = s.triggers.InsertIfNotExists(req.TriggerID, func() (*logEventTrigger, chan capabilities.TriggerResponse, error) { ctx, cancel := s.stopChan.NewCtx() l, ch, err := newLogEventTrigger(ctx, cancel, s.lggr, req.Metadata.WorkflowID, reqConfig, s.logEventConfig, s.relayer) s.wg.Add(1) @@ -132,10 +131,6 @@ func (s *TriggerService) UnregisterTrigger(ctx context.Context, req capabilities // Start the service. func (s *TriggerService) Start(ctx context.Context) error { - if s.relayer == nil { - return errors.New("service has shutdown, it must be built again to restart") - } - return nil } diff --git a/core/capabilities/triggers/logevent/service_test.go b/core/capabilities/triggers/logevent/service_test.go index 1879a927e63..c2e75d89483 100644 --- a/core/capabilities/triggers/logevent/service_test.go +++ b/core/capabilities/triggers/logevent/service_test.go @@ -20,7 +20,7 @@ func TestLogEventTriggerEVMHappyPath(t *testing.T) { th := testutils.NewContractReaderTH(t) logEventConfig := logevent.Config{ - ChainID: th.BackendTH.ChainID.Uint64(), + ChainID: th.BackendTH.ChainID.String(), Network: "evm", LookbackBlocks: 1000, PollPeriod: 1000, @@ -45,7 +45,7 @@ func TestLogEventTriggerEVMHappyPath(t *testing.T) { }, nil).Once() // Create Log Event Trigger Service and register trigger - logEventTriggerService := logevent.NewLogEventTriggerService(logevent.Params{ + logEventTriggerService := logevent.NewTriggerService(logevent.Params{ Logger: th.BackendTH.Lggr, Relayer: relayer, LogEventConfig: logEventConfig, diff --git a/core/capabilities/triggers/logevent/store.go b/core/capabilities/triggers/logevent/store.go index 0f8cebfab02..56e4a6f235b 100644 --- a/core/capabilities/triggers/logevent/store.go +++ b/core/capabilities/triggers/logevent/store.go @@ -51,11 +51,14 @@ func (cs *capabilitiesStore[T, Resp]) Write(capabilityID string, value *T) { } func (cs *capabilitiesStore[T, Resp]) InsertIfNotExists(capabilityID string, fn RegisterCapabilityFn[T, Resp]) (chan Resp, error) { - cs.mu.Lock() - defer cs.mu.Unlock() - if _, ok := cs.capabilities[capabilityID]; ok { + cs.mu.RLock() + _, ok := cs.capabilities[capabilityID] + cs.mu.RUnlock() + if ok { return nil, fmt.Errorf("capabilityID %v already exists", capabilityID) } + cs.mu.Lock() + defer cs.mu.Unlock() value, respCh, err := fn() if err != nil { return nil, fmt.Errorf("error registering capability: %v", err) diff --git a/core/capabilities/triggers/logevent/trigger.go b/core/capabilities/triggers/logevent/trigger.go index 41dd8fabbc0..0d81e8f2a9a 100644 --- a/core/capabilities/triggers/logevent/trigger.go +++ b/core/capabilities/triggers/logevent/trigger.go @@ -63,7 +63,7 @@ func newLogEventTrigger(ctx context.Context, contractReader, err := relayer.NewContractReader(ctx, jsonBytes) if err != nil { return nil, nil, - fmt.Errorf("error fetching contractReader for chainID %d from relayerSet: %v", logEventConfig.ChainID, err) + fmt.Errorf("error fetching contractReader for chainID %s from relayerSet: %v", logEventConfig.ChainID, err) } // Bind Contract in ContractReader diff --git a/plugins/cmd/capabilities/log-event-trigger/main.go b/plugins/cmd/capabilities/log-event-trigger/main.go index dc00ef59420..84ff8a73912 100644 --- a/plugins/cmd/capabilities/log-event-trigger/main.go +++ b/plugins/cmd/capabilities/log-event-trigger/main.go @@ -105,7 +105,7 @@ func (cs *LogEventTriggerGRPCService) Initialise( // Set relayer and trigger in LogEventTriggerGRPCService cs.config = logEventConfig - cs.trigger = logevent.NewLogEventTriggerService(logevent.Params{ + cs.trigger = logevent.NewTriggerService(logevent.Params{ Logger: cs.s.Logger, Relayer: relayer, LogEventConfig: logEventConfig,