Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't observe destChain fee #392

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion commit/chainfee/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ func (p *processor) Observation(
return Observation{}, err
}

supportedChains.Remove(p.destChain)
if supportedChains.Cardinality() == 0 {
p.lggr.Info("no supported chains, nothing to observe")
p.lggr.Info("no supported chains other than dest chain to observe")
return Observation{}, nil
}

Expand Down
50 changes: 39 additions & 11 deletions commit/chainfee/observation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package chainfee
import (
"math/big"
"math/rand"
"sort"
"testing"
"time"

"golang.org/x/exp/maps"

mapset "github.com/deckarep/golang-set/v2"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/types"
Expand All @@ -32,11 +35,15 @@ func Test_processor_Observation(t *testing.T) {
fChain map[ccipocr3.ChainSelector]int
expectedChainFeePriceUpdates map[ccipocr3.ChainSelector]Update

expErr bool
dstChain ccipocr3.ChainSelector

expErr bool
emptyObs bool
}{
{
name: "two chains",
supportedChains: []ccipocr3.ChainSelector{1},
name: "two chains excluding dest",
supportedChains: []ccipocr3.ChainSelector{1, 2, 3},
dstChain: 3,
chainFeeComponents: map[ccipocr3.ChainSelector]types.ChainFeeComponents{
1: {
ExecutionFee: big.NewInt(10),
Expand Down Expand Up @@ -86,9 +93,16 @@ func Test_processor_Observation(t *testing.T) {
fChain: map[ccipocr3.ChainSelector]int{
1: 1,
2: 2,
3: 1,
},
expErr: false,
},
{
name: "only dest chain",
supportedChains: []ccipocr3.ChainSelector{1},
dstChain: 1,
emptyObs: true,
},
}

for _, tc := range testCases {
Expand All @@ -103,25 +117,32 @@ func Test_processor_Observation(t *testing.T) {
p := &processor{
lggr: lggr,
chainSupport: cs,
destChain: tc.dstChain,
ccipReader: ccipReader,
oracleID: oracleID,
homeChain: homeChain,
metricsReporter: NoopMetrics{},
}

supportedSet := mapset.NewSet(tc.supportedChains...)
cs.EXPECT().DestChain().Return(tc.dstChain).Maybe()
cs.EXPECT().SupportedChains(oracleID).
Return(mapset.NewSet(tc.supportedChains...), nil)
Return(supportedSet, nil).Maybe()

supportedSet.Remove(tc.dstChain)
slicesWithoutDst := supportedSet.ToSlice()
sort.Slice(slicesWithoutDst, func(i, j int) bool { return slicesWithoutDst[i] < slicesWithoutDst[j] })

ccipReader.EXPECT().GetChainsFeeComponents(ctx, tc.supportedChains).
Return(tc.chainFeeComponents)
ccipReader.EXPECT().GetChainsFeeComponents(ctx, slicesWithoutDst).
Return(tc.chainFeeComponents).Maybe()

ccipReader.EXPECT().GetWrappedNativeTokenPriceUSD(ctx, tc.supportedChains).
Return(tc.nativeTokenPrices)
ccipReader.EXPECT().GetWrappedNativeTokenPriceUSD(ctx, slicesWithoutDst).
Return(tc.nativeTokenPrices).Maybe()

ccipReader.EXPECT().GetChainFeePriceUpdate(ctx, tc.supportedChains).
Return(tc.existingChainFeePriceUpdates)
ccipReader.EXPECT().GetChainFeePriceUpdate(ctx, slicesWithoutDst).
Return(tc.existingChainFeePriceUpdates).Maybe()

homeChain.EXPECT().GetFChain().Return(tc.fChain, nil)
homeChain.EXPECT().GetFChain().Return(tc.fChain, nil).Maybe()

tStart := time.Now()
obs, err := p.Observation(ctx, Outcome{}, Query{})
Expand All @@ -130,13 +151,20 @@ func Test_processor_Observation(t *testing.T) {
require.Error(t, err)
return
}
if tc.emptyObs {
require.Empty(t, obs)
return
}

require.NoError(t, err)
require.GreaterOrEqual(t, obs.TimestampNow.UnixNano(), tStart.UnixNano())
require.LessOrEqual(t, obs.TimestampNow.UnixNano(), tEnd.UnixNano())
require.Equal(t, tc.chainFeeComponents, obs.FeeComponents)
require.Equal(t, maps.Keys(tc.chainFeeComponents), slicesWithoutDst)
require.Equal(t, tc.nativeTokenPrices, obs.NativeTokenPrices)
require.Equal(t, maps.Keys(tc.nativeTokenPrices), slicesWithoutDst)
require.Equal(t, tc.expectedChainFeePriceUpdates, obs.ChainFeeUpdates)
require.Equal(t, maps.Keys(tc.expectedChainFeePriceUpdates), slicesWithoutDst)
require.Equal(t, tc.fChain, obs.FChain)
})
}
Expand Down
Loading