diff --git a/core/services/relay/evm/dual_contract_transmitter.go b/core/services/relay/evm/dual_contract_transmitter.go index ce4238a14cb..981c6120cdd 100644 --- a/core/services/relay/evm/dual_contract_transmitter.go +++ b/core/services/relay/evm/dual_contract_transmitter.go @@ -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 } @@ -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) }