From eee2b6a339bb72d0de90c4cd4b37320e7ca3597c Mon Sep 17 00:00:00 2001 From: Oliver Townsend Date: Fri, 6 Jun 2025 14:13:17 -0700 Subject: [PATCH 1/2] [CAL][6] - move SourceChainConfig to types package --- pkg/reader/ccip.go | 24 ++++----------- pkg/reader/ccip_interface.go | 4 +-- pkg/reader/ccip_test.go | 2 +- pkg/reader/config_poller.go | 10 +++---- pkg/reader/config_poller_test.go | 50 ++++++++++++++++---------------- 5 files changed, 39 insertions(+), 51 deletions(-) diff --git a/pkg/reader/ccip.go b/pkg/reader/ccip.go index c8b90ddce..fc3587f86 100644 --- a/pkg/reader/ccip.go +++ b/pkg/reader/ccip.go @@ -1369,18 +1369,6 @@ func (r *ccipChainReader) getFeeQuoterTokenPriceUSD(ctx context.Context, tokenAd return cciptypes.NewBigInt(price), nil } -// sourceChainConfig is used to parse the response from the offRamp contract's getSourceChainConfig method. -// See: https://github.com/smartcontractkit/ccip/blob/a3f61f7458e4499c2c62eb38581c60b4942b1160/contracts/src/v0.8/ccip/offRamp/OffRamp.sol#L94 -// -//nolint:lll // It's a URL. -type SourceChainConfig struct { - Router []byte // local router - IsEnabled bool - IsRMNVerificationDisabled bool - MinSeqNr uint64 - OnRamp cciptypes.UnknownAddress -} - // GetOffRampSourceChainsConfig returns the static source chain configs for all the provided source chains. // This method returns configurations without the MinSeqNr field, which should be fetched separately when needed. func (r *ccipChainReader) GetOffRampSourceChainsConfig(ctx context.Context, chains []cciptypes.ChainSelector, @@ -1436,7 +1424,7 @@ func (r *ccipChainReader) fetchFreshSourceChainConfigs( ctx context.Context, destChain cciptypes.ChainSelector, sourceChains []cciptypes.ChainSelector, -) (map[cciptypes.ChainSelector]SourceChainConfig, error) { +) (map[cciptypes.ChainSelector]cciptypes.SourceChainConfig, error) { lggr := logutil.WithContextValues(ctx, r.lggr) reader, exists := r.contractReaders[destChain] @@ -1447,7 +1435,7 @@ func (r *ccipChainReader) fetchFreshSourceChainConfigs( // Filter out destination chain filteredSourceChains := filterOutChainSelector(sourceChains, destChain) if len(filteredSourceChains) == 0 { - return make(map[cciptypes.ChainSelector]SourceChainConfig), nil + return make(map[cciptypes.ChainSelector]cciptypes.SourceChainConfig), nil } // Prepare batch requests for the sourceChains to fetch the latest Unfinalized config values. @@ -1461,7 +1449,7 @@ func (r *ccipChainReader) fetchFreshSourceChainConfigs( Params: map[string]any{ "sourceChainSelector": chain, }, - ReturnVal: new(SourceChainConfig), + ReturnVal: new(cciptypes.SourceChainConfig), }) } @@ -1483,7 +1471,7 @@ func (r *ccipChainReader) fetchFreshSourceChainConfigs( } // Process results - configs := make(map[cciptypes.ChainSelector]SourceChainConfig) + configs := make(map[cciptypes.ChainSelector]cciptypes.SourceChainConfig) for _, readResult := range results { if len(readResult) != len(validSourceChains) { @@ -1500,7 +1488,7 @@ func (r *ccipChainReader) fetchFreshSourceChainConfigs( return nil, fmt.Errorf("GetSourceChainConfig for chainSelector=%d failed: %w", chain, err) } - cfg, ok := v.(*SourceChainConfig) + cfg, ok := v.(*cciptypes.SourceChainConfig) if !ok { lggr.Errorw("Invalid result type from GetSourceChainConfig", "chain", chain, @@ -2128,7 +2116,7 @@ type ccipReaderInternal interface { // fetchFreshSourceChainConfigs fetches source chain configurations from the specified destination chain fetchFreshSourceChainConfigs( ctx context.Context, destChain cciptypes.ChainSelector, - sourceChains []cciptypes.ChainSelector) (map[cciptypes.ChainSelector]SourceChainConfig, error) + sourceChains []cciptypes.ChainSelector) (map[cciptypes.ChainSelector]cciptypes.SourceChainConfig, error) } // getDestChain returns the destination chain selector diff --git a/pkg/reader/ccip_interface.go b/pkg/reader/ccip_interface.go index d25bbf775..aefa204a3 100644 --- a/pkg/reader/ccip_interface.go +++ b/pkg/reader/ccip_interface.go @@ -87,8 +87,8 @@ type StaticSourceChainConfig struct { // ToSourceChainConfig converts a CachedSourceChainConfig to a full SourceChainConfig // by adding the provided sequence number. -func (s StaticSourceChainConfig) ToSourceChainConfig(minSeqNr uint64) SourceChainConfig { - return SourceChainConfig{ +func (s StaticSourceChainConfig) ToSourceChainConfig(minSeqNr uint64) cciptypes.SourceChainConfig { + return cciptypes.SourceChainConfig{ Router: s.Router, IsEnabled: s.IsEnabled, IsRMNVerificationDisabled: s.IsRMNVerificationDisabled, diff --git a/pkg/reader/ccip_test.go b/pkg/reader/ccip_test.go index 7c8c0a6a3..3f309fabf 100644 --- a/pkg/reader/ccip_test.go +++ b/pkg/reader/ccip_test.go @@ -330,7 +330,7 @@ func TestCCIPChainReader_getSourceChainsConfig(t *testing.T) { } params := readReq.Params.(map[string]any) sourceChain := params["sourceChainSelector"].(cciptypes.ChainSelector) - v := readReq.ReturnVal.(*SourceChainConfig) + v := readReq.ReturnVal.(*cciptypes.SourceChainConfig) fromString, err := cciptypes.NewBytesFromString(fmt.Sprintf( "0x%d000000000000000000000000000000000000000", sourceChain), diff --git a/pkg/reader/config_poller.go b/pkg/reader/config_poller.go index 4261f207b..4ff9df64b 100644 --- a/pkg/reader/config_poller.go +++ b/pkg/reader/config_poller.go @@ -263,8 +263,8 @@ func (c *configPoller) processSourceChainResults( batchResult types.BatchGetLatestValuesResult, standardOffRampRequestCount int, filteredSourceChains []cciptypes.ChainSelector, -) map[cciptypes.ChainSelector]SourceChainConfig { - sourceConfigs := make(map[cciptypes.ChainSelector]SourceChainConfig) +) map[cciptypes.ChainSelector]cciptypes.SourceChainConfig { + sourceConfigs := make(map[cciptypes.ChainSelector]cciptypes.SourceChainConfig) // Find the OffRamp results for contract, results := range batchResult { @@ -291,7 +291,7 @@ func (c *configPoller) processSourceChainResults( continue } - cfg, ok := v.(*SourceChainConfig) + cfg, ok := v.(*cciptypes.SourceChainConfig) if !ok { c.lggr.Errorw("Invalid result type from GetSourceChainConfig", "chain", chain, @@ -320,7 +320,7 @@ func (c *configPoller) prepareSourceChainQueries(sourceChains []cciptypes.ChainS Params: map[string]any{ "sourceChainSelector": chain, }, - ReturnVal: new(SourceChainConfig), + ReturnVal: new(cciptypes.SourceChainConfig), }) } return sourceConfigQueries @@ -760,7 +760,7 @@ func filterOutChainSelector( // StaticSourceChainConfigFromSourceChainConfig creates a StaticSourceChainConfig from a SourceChainConfig, // omitting the MinSeqNr field. -func staticSourceChainConfigFromSourceChainConfig(sc SourceChainConfig) StaticSourceChainConfig { +func staticSourceChainConfigFromSourceChainConfig(sc cciptypes.SourceChainConfig) StaticSourceChainConfig { return StaticSourceChainConfig{ Router: sc.Router, IsEnabled: sc.IsEnabled, diff --git a/pkg/reader/config_poller_test.go b/pkg/reader/config_poller_test.go index d4bfe9909..237313c4c 100644 --- a/pkg/reader/config_poller_test.go +++ b/pkg/reader/config_poller_test.go @@ -88,9 +88,9 @@ func setupBatchMockResponse(reader *reader_mocks.MockExtended) { // Source chain config part resultB := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - resultB.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + resultB.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) resultC := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - resultC.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) + resultC.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) // Combined response responses := types.BatchGetLatestValuesResult{ @@ -123,9 +123,9 @@ func setupInitialData(ctx context.Context, cache *configPoller, reader *reader_m sourceChains := []cciptypes.ChainSelector{chainB, chainC} result1 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result1.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result1.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) result2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result2.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) + result2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) response := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1107,9 +1107,9 @@ func TestConfigCache_GetOfframpSourceChainConfigs_CacheHit(t *testing.T) { // Create batch read results for source chains result1 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result1.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result1.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) result2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result2.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) + result2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) responses := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1150,9 +1150,9 @@ func TestConfigCache_GetOfframpSourceChainConfigs_Update(t *testing.T) { // Setup mock response for first fetch result1 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result1.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result1.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) result2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result2.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) + result2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) firstResponse := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1177,9 +1177,9 @@ func TestConfigCache_GetOfframpSourceChainConfigs_Update(t *testing.T) { // Setup mock response for second fetch with different data result3 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result3.SetResult(&SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) + result3.SetResult(&cciptypes.SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) result4 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result4.SetResult(&SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{10, 11, 12}}, nil) + result4.SetResult(&cciptypes.SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{10, 11, 12}}, nil) secondResponse := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1228,9 +1228,9 @@ func TestConfigCache_GetOfframpSourceChainConfigs_MixedSet(t *testing.T) { // Setup mock response for first fetch result1 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result1.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result1.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) result2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result2.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) + result2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) firstResponse := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1254,7 +1254,7 @@ func TestConfigCache_GetOfframpSourceChainConfigs_MixedSet(t *testing.T) { // Setup mock response for second fetch (only D should be fetched) result3 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result3.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) + result3.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) secondResponse := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1291,9 +1291,9 @@ func TestConfigCache_RefreshSourceChainConfigs(t *testing.T) { // Setup mock response result1 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result1.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result1.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) result2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result2.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) + result2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) response := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1316,9 +1316,9 @@ func TestConfigCache_RefreshSourceChainConfigs(t *testing.T) { // Setup mock for a second call with different data result3 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result3.SetResult(&SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) + result3.SetResult(&cciptypes.SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) result4 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result4.SetResult(&SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{10, 11, 12}}, nil) + result4.SetResult(&cciptypes.SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{10, 11, 12}}, nil) response2 := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1356,7 +1356,7 @@ func TestConfigCache_GetOfframpSourceChainConfigs_Error(t *testing.T) { // First fetch - one chain succeeds, one fails with error result1 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result1.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result1.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) result2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} result2.SetResult(nil, errors.New("read error")) @@ -1393,9 +1393,9 @@ func TestConfigCache_GlobalSourceChainRefreshTime(t *testing.T) { // Setup mock response for first fetch result1 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result1.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result1.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) result2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result2.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) + result2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{4, 5, 6}}, nil) firstResponse := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1422,7 +1422,7 @@ func TestConfigCache_GlobalSourceChainRefreshTime(t *testing.T) { // Setup mock for D fetch only resultD := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - resultD.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) + resultD.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{7, 8, 9}}, nil) secondResponse := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1452,11 +1452,11 @@ func TestConfigCache_GlobalSourceChainRefreshTime(t *testing.T) { // Setup mock for manual refresh of all chains resultB2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - resultB2.SetResult(&SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{10, 11, 12}}, nil) + resultB2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{10, 11, 12}}, nil) resultC2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - resultC2.SetResult(&SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{13, 14, 15}}, nil) + resultC2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{13, 14, 15}}, nil) resultD2 := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - resultD2.SetResult(&SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{16, 17, 18}}, nil) + resultD2.SetResult(&cciptypes.SourceChainConfig{IsEnabled: false, OnRamp: cciptypes.UnknownAddress{16, 17, 18}}, nil) thirdResponse := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { @@ -1522,7 +1522,7 @@ func TestConfigCache_RefreshSourceChainConfigs_SetsGlobalTimestamp(t *testing.T) // Setup mock response result := &types.BatchReadResult{ReadName: consts.MethodNameGetSourceChainConfig} - result.SetResult(&SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) + result.SetResult(&cciptypes.SourceChainConfig{IsEnabled: true, OnRamp: cciptypes.UnknownAddress{1, 2, 3}}, nil) response := types.BatchGetLatestValuesResult{ types.BoundContract{Name: consts.ContractNameOffRamp}: { From 9c72de4c5c71122c5c70d28d052e792169c1316f Mon Sep 17 00:00:00 2001 From: Oliver Townsend <133903322+ogtownsend@users.noreply.github.com> Date: Tue, 10 Jun 2025 11:52:08 -0700 Subject: [PATCH 2/2] [CAL][7] - implement GetExpectedNextSequenceNumber (#990) --- pkg/chainaccessor/legacy_accessor.go | 26 +++++++++++++++++++++++--- pkg/reader/ccip.go | 28 ++++++---------------------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/pkg/chainaccessor/legacy_accessor.go b/pkg/chainaccessor/legacy_accessor.go index 7485c268f..3b0db5920 100644 --- a/pkg/chainaccessor/legacy_accessor.go +++ b/pkg/chainaccessor/legacy_accessor.go @@ -219,10 +219,30 @@ func (l *LegacyAccessor) LatestMsgSeqNum( func (l *LegacyAccessor) GetExpectedNextSequenceNumber( ctx context.Context, - dest cciptypes.ChainSelector, + destChainSelector cciptypes.ChainSelector, ) (cciptypes.SeqNum, error) { - // TODO(NONEVM-1865): implement - panic("implement me") + var expectedNextSequenceNumber uint64 + err := l.contractReader.ExtendedGetLatestValue( + ctx, + consts.ContractNameOnRamp, + consts.MethodNameGetExpectedNextSequenceNumber, + primitives.Unconfirmed, + map[string]any{ + "destChainSelector": destChainSelector, + }, + &expectedNextSequenceNumber, + ) + if err != nil { + return 0, fmt.Errorf("failed to get expected next sequence number from onramp, source chain: %d, dest chain: %d: %w", + l.chainSelector, destChainSelector, err) + } + + if expectedNextSequenceNumber == 0 { + return 0, fmt.Errorf("the returned expected next sequence num is 0, source chain: %d, dest chain: %d", + l.chainSelector, destChainSelector) + } + + return cciptypes.SeqNum(expectedNextSequenceNumber), nil } func (l *LegacyAccessor) GetTokenPriceUSD( diff --git a/pkg/reader/ccip.go b/pkg/reader/ccip.go index fc3587f86..dbac3adbb 100644 --- a/pkg/reader/ccip.go +++ b/pkg/reader/ccip.go @@ -555,34 +555,18 @@ func (r *ccipChainReader) GetExpectedNextSequenceNumber( ) (cciptypes.SeqNum, error) { lggr := logutil.WithContextValues(ctx, r.lggr) - if err := validateReaderExistence(r.contractReaders, sourceChainSelector); err != nil { + if err := validateAccessorExistence(r.accessors, sourceChainSelector); err != nil { return 0, err } - - var expectedNextSequenceNumber uint64 - err := r.contractReaders[sourceChainSelector].ExtendedGetLatestValue( - ctx, - consts.ContractNameOnRamp, - consts.MethodNameGetExpectedNextSequenceNumber, - primitives.Unconfirmed, - map[string]any{ - "destChainSelector": r.destChain, - }, - &expectedNextSequenceNumber, - ) + expectedNextSeqNum, err := r.accessors[sourceChainSelector].GetExpectedNextSequenceNumber(ctx, r.destChain) if err != nil { - return 0, fmt.Errorf("failed to get expected next sequence number from onramp, source chain: %d, dest chain: %d: %w", + return 0, fmt.Errorf("failed to call accessor LatestMsgSeqNum, source chain: %d, dest chain: %d: %w", sourceChainSelector, r.destChain, err) } - if expectedNextSequenceNumber == 0 { - return 0, fmt.Errorf("the returned expected next sequence num is 0, source chain: %d, dest chain: %d", - sourceChainSelector, r.destChain) - } - - lggr.Debugw("chain reader returning expected next sequence number", - "seqNum", expectedNextSequenceNumber, "sourceChainSelector", sourceChainSelector) - return cciptypes.SeqNum(expectedNextSequenceNumber), nil + lggr.Debugw("chain accessor returning expected next sequence number", + "seqNum", expectedNextSeqNum, "sourceChainSelector", sourceChainSelector) + return expectedNextSeqNum, nil } // NextSeqNum returns the current sequence numbers for chains.