Skip to content

Commit

Permalink
Implement feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
george-dorin committed Jan 21, 2025
1 parent 140aa03 commit 4ac2a31
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions core/services/relay/evm/dual_contract_transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,32 +178,14 @@ func (oc *dualContractTransmitter) FromAccount(ctx context.Context) (ocrtypes.Ac
}

func (oc *dualContractTransmitter) lockTransmitters(ctx context.Context) error {
primaryAddress := oc.transmitter.FromAddress(ctx)
rmPrimary, err := oc.ks.GetResourceMutex(ctx, primaryAddress)
if err != nil {
return err
}

secondaryAddress, err := oc.transmitter.SecondaryFromAddress(ctx)
err := oc.lockPrimary(ctx)
if err != nil {
return err
}

rmSecondary, err := oc.ks.GetResourceMutex(ctx, secondaryAddress)
err = oc.lockSecondary(ctx)
if err != nil {
return err
return multierr.Append(err, oc.unlockPrimary(ctx))
}

if err = rmPrimary.TryLock(keystore.TXMv1); err != nil {
return err
}
oc.lggr.Debugf("Key %s has been locked for TXMv1", primaryAddress.String())

err = rmSecondary.TryLock(keystore.TXMv2)
if err != nil {
return multierr.Append(err, rmPrimary.Unlock(keystore.TXMv1))
}
oc.lggr.Debugf("Key %s has been locked for TXMv2", secondaryAddress.String())
return nil
}

Expand Down Expand Up @@ -241,6 +223,36 @@ func (oc *dualContractTransmitter) unlockSecondary(ctx context.Context) error {
return nil
}

func (oc *dualContractTransmitter) lockPrimary(ctx context.Context) error {
primaryAddress := oc.transmitter.FromAddress(ctx)
rmPrimary, err := oc.ks.GetResourceMutex(ctx, primaryAddress)
if err != nil {
return err
}
err = rmPrimary.TryLock(keystore.TXMv1)
if err != nil {
return err
}
oc.lggr.Debugf("Key %s has been locked for TXMv1", primaryAddress.String())
return nil
}
func (oc *dualContractTransmitter) lockSecondary(ctx context.Context) error {
secondaryAddress, err := oc.transmitter.SecondaryFromAddress(ctx)
if err != nil {
return err
}
rmSecondary, err := oc.ks.GetResourceMutex(ctx, secondaryAddress)
if err != nil {
return err
}
err = rmSecondary.TryLock(keystore.TXMv2)
if err != nil {
return err
}
oc.lggr.Debugf("Key %s has been locked for TXMv2", secondaryAddress.String())
return nil
}

func (oc *dualContractTransmitter) Start(ctx context.Context) error {
return oc.lockTransmitters(ctx)
}
Expand Down

0 comments on commit 4ac2a31

Please sign in to comment.