Skip to content

Commit

Permalink
Improve ocr2FeedsTransmitter FromAddress() fallback (#13343)
Browse files Browse the repository at this point in the history
* Improve ocr2FeedsTransmitter FromAddress() fallback

* Fix forwarders test error assert
  • Loading branch information
ilija42 committed May 28, 2024
1 parent 8585cc9 commit 636c5e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
8 changes: 6 additions & 2 deletions core/chains/evm/forwarders/forwarder_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package forwarders

import (
"context"
"errors"
"slices"
"sync"
"time"
Expand Down Expand Up @@ -130,9 +131,12 @@ func (f *FwdMgr) ForwarderFor(ctx context.Context, addr common.Address) (forward
}
}
}
return common.Address{}, pkgerrors.Errorf("Cannot find forwarder for given EOA")
return common.Address{}, ErrForwarderForEOANotFound
}

// ErrForwarderForEOANotFound defines the error triggered when no valid forwarders were found for EOA
var ErrForwarderForEOANotFound = errors.New("cannot find forwarder for given EOA")

func (f *FwdMgr) ForwarderForOCR2Feeds(ctx context.Context, eoa, ocr2Aggregator common.Address) (forwarder common.Address, err error) {
fwdrs, err := f.ORM.FindForwardersByChain(ctx, big.Big(*f.evmClient.ConfiguredChainID()))
if err != nil {
Expand Down Expand Up @@ -166,7 +170,7 @@ func (f *FwdMgr) ForwarderForOCR2Feeds(ctx context.Context, eoa, ocr2Aggregator
}
}
}
return common.Address{}, pkgerrors.Errorf("Cannot find forwarder for given EOA")
return common.Address{}, ErrForwarderForEOANotFound
}

func (f *FwdMgr) ConvertPayload(dest common.Address, origPayload []byte) ([]byte, error) {
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/forwarders/forwarder_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func TestFwdMgr_AccountUnauthorizedToForward_SkipsForwarding(t *testing.T) {
err = fwdMgr.Start(testutils.Context(t))
require.NoError(t, err)
addr, err := fwdMgr.ForwarderFor(ctx, owner.From)
require.ErrorContains(t, err, "Cannot find forwarder for given EOA")
require.ErrorIs(t, err, forwarders.ErrForwarderForEOANotFound)
require.True(t, utils.IsZero(addr))
err = fwdMgr.Close()
require.NoError(t, err)
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestFwdMgr_InvalidForwarderForOCR2FeedsStates(t *testing.T) {
require.NoError(t, fwdMgr.Start(testutils.Context(t)))
// cannot find forwarder because it isn't authorized nor added as a transmitter
addr, err := fwdMgr.ForwarderForOCR2Feeds(ctx, owner.From, ocr2Address)
require.ErrorContains(t, err, "Cannot find forwarder for given EOA")
require.ErrorIs(t, err, forwarders.ErrForwarderForEOANotFound)
require.True(t, utils.IsZero(addr))

_, err = forwarder.SetAuthorizedSenders(owner, []common.Address{owner.From})
Expand All @@ -229,7 +229,7 @@ func TestFwdMgr_InvalidForwarderForOCR2FeedsStates(t *testing.T) {

// cannot find forwarder because it isn't added as a transmitter
addr, err = fwdMgr.ForwarderForOCR2Feeds(ctx, owner.From, ocr2Address)
require.ErrorContains(t, err, "Cannot find forwarder for given EOA")
require.ErrorIs(t, err, forwarders.ErrForwarderForEOANotFound)
require.True(t, utils.IsZero(addr))

onchainConfig, err := testhelpers.GenerateDefaultOCR2OnchainConfig(big.NewInt(0), big.NewInt(10))
Expand Down
8 changes: 6 additions & 2 deletions core/services/ocrcommon/transmitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/forwarders"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
)

Expand Down Expand Up @@ -175,8 +176,11 @@ func (t *ocr2FeedsTransmitter) FromAddress() common.Address {
return t.effectiveTransmitterAddress
}

forwarderAddress, err := t.forwarderAddress(context.Background(), roundRobinFromAddress, t.ocr2Aggregator)
if err != nil || forwarderAddress == (common.Address{}) {
forwarderAddress, err := t.GetForwarderForEOAOCR2Feeds(context.Background(), roundRobinFromAddress, t.ocr2Aggregator)
if errors.Is(err, forwarders.ErrForwarderForEOANotFound) {
// if there are no valid forwarders try to fallback to eoa
return roundRobinFromAddress
} else if err != nil {
return t.effectiveTransmitterAddress
}

Expand Down

0 comments on commit 636c5e1

Please sign in to comment.