Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kidambisrinivas committed Sep 30, 2024
1 parent 2786cef commit 31954ea
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion core/capabilities/testutils/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions core/capabilities/triggers/logevent/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
}

Expand All @@ -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]()
Expand All @@ -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})
Expand All @@ -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)

Check failure on line 104 in core/capabilities/triggers/logevent/service.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 96 (govet)
s.wg.Add(1)
Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions core/capabilities/triggers/logevent/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 6 additions & 3 deletions core/capabilities/triggers/logevent/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion core/capabilities/triggers/logevent/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugins/cmd/capabilities/log-event-trigger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 31954ea

Please sign in to comment.