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

CCIP Contract Reader usage improvements #256

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions internal/reader/home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ func (r *homeChainPoller) GetOCRConfigs(
allConfigs ActiveAndCandidate
)

// TODO should addresses in OCR3Config be strings instead of bytes?
err := r.homeChainReader.GetLatestValue(
ctx,
r.ccipConfigBoundContract.ReadIdentifier(consts.MethodNameGetOCRConfig),
Expand Down
15 changes: 15 additions & 0 deletions pkg/reader/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (r *ccipChainReader) CommitReportsGTETimestamp(
}
// ---------------------------------------------------

// TODO should any addresses in CommitReportAcceptedEvent be string? OnRampAddress, SourceToken?
ev := CommitReportAcceptedEvent{}

iter, err := r.contractReaders[dest].ExtendedQueryKey(
Expand Down Expand Up @@ -150,6 +151,7 @@ func (r *ccipChainReader) CommitReportsGTETimestamp(
return nil, fmt.Errorf("unexpected type %T while expecting a commit report", item)
}

// TODO do this through QueryKey
valid := item.Timestamp >= uint64(ts.Unix())
if !valid {
r.lggr.Debugw("commit report too old, skipping", "report", ev, "item", item,
Expand Down Expand Up @@ -263,6 +265,7 @@ func (r *ccipChainReader) ExecutedMessageRanges(
return nil, fmt.Errorf("failed to cast %T to executionStateChangedEvent", item.Data)
}

// TODO reminder
// todo: filter via the query
valid := stateChange.SourceChainSelector == source &&
stateChange.SequenceNumber >= seqNumRange.Start() &&
Expand Down Expand Up @@ -291,6 +294,7 @@ func (r *ccipChainReader) MsgsBetweenSeqNums(
return nil, fmt.Errorf("get onRamp address: %w", err)
}

// TODO should any addresses in here be handled as strings instead?
type SendRequestedEvent struct {
DestChainSelector cciptypes.ChainSelector
Message cciptypes.Message
Expand Down Expand Up @@ -329,6 +333,7 @@ func (r *ccipChainReader) MsgsBetweenSeqNums(
return nil, fmt.Errorf("failed to cast %v to Message", item.Data)
}

// TODO reminder
// todo: filter via the query
valid := msg.Message.Header.SourceChainSelector == sourceChainSelector &&
msg.Message.Header.DestChainSelector == r.destChain &&
Expand Down Expand Up @@ -423,6 +428,7 @@ func (r *ccipChainReader) Nonces(
return fmt.Errorf("failed to convert address %s to bytes: %w", address, err)
}

// TODO should sender be a string?
var resp uint64
err = r.contractReaders[destChainSelector].ExtendedGetLatestValue(
ctx,
Expand Down Expand Up @@ -482,6 +488,7 @@ func (r *ccipChainReader) GetWrappedNativeTokenPriceUSD(
continue
}

// TODO should nativeTokenAddress be a string?
//TODO: Use batching in the future
var nativeTokenAddress cciptypes.Bytes
err := reader.ExtendedGetLatestValue(
Expand All @@ -502,6 +509,7 @@ func (r *ccipChainReader) GetWrappedNativeTokenPriceUSD(
continue
}

// TODO should nativeTokenAddress be a string instead?
var update *plugintypes.TimestampedUnixBig
err = reader.ExtendedGetLatestValue(
ctx,
Expand Down Expand Up @@ -660,6 +668,7 @@ func (r *ccipChainReader) discoverOffRampContracts(

// NonceManager and RMNRemote are in the offramp static config.
{
// TODO should any fields in offRampStaticChainConfig be strings?
var staticConfig offRampStaticChainConfig
err := r.getDestinationData(
ctx,
Expand All @@ -678,6 +687,7 @@ func (r *ccipChainReader) discoverOffRampContracts(

// FeeQuoter from the offRamp dynamic config.
{
// TODO should any fields in offRampDynamicChainConfig be strings?
var dynamicConfig offRampDynamicChainConfig
err := r.getDestinationData(
ctx,
Expand Down Expand Up @@ -778,6 +788,7 @@ func (r *ccipChainReader) Sync(ctx context.Context, contracts ContractAddresses)
return errors.Join(errs...)
}

// TODO can this be removed if contract Reader always handles addresses as strings?
func (r *ccipChainReader) GetContractAddress(contractName string, chain cciptypes.ChainSelector) ([]byte, error) {
extendedReader, ok := r.contractReaders[chain]
if !ok {
Expand Down Expand Up @@ -841,6 +852,7 @@ type feeQuoterStaticConfig struct {

// getDestFeeQuoterStaticConfig returns the destination chain's Fee Quoter's StaticConfig
func (r *ccipChainReader) getDestFeeQuoterStaticConfig(ctx context.Context) (feeQuoterStaticConfig, error) {
// TODO should any fields in feeQuoterStaticConfig be a string instead, LinkToken?
var staticConfig feeQuoterStaticConfig
err := r.getDestinationData(
ctx,
Expand Down Expand Up @@ -869,6 +881,7 @@ func (r *ccipChainReader) getFeeQuoterTokenPriceUSD(ctx context.Context, tokenAd
return cciptypes.BigInt{}, fmt.Errorf("contract reader not found for chain %d", r.destChain)
}

// TODO should tokenAddr be a string?
var timestampedPrice plugintypes.TimestampedUnixBig
err := reader.ExtendedGetLatestValue(
ctx,
Expand Down Expand Up @@ -1124,6 +1137,7 @@ func (r *ccipChainReader) getOnRampDynamicConfigs(
chainSel := chainSel
eg.Go(func() error {
// read onramp dynamic config
// TODO should any fields in getOnRampDynamicConfigResponse be strings? FeeQuoter>
resp := getOnRampDynamicConfigResponse{}
err := r.contractReaders[chainSel].ExtendedGetLatestValue(
ctx,
Expand Down Expand Up @@ -1183,6 +1197,7 @@ func (r *ccipChainReader) getOnRampDestChainConfig(
// 2. Chain X Router
chainSel := chainSel
eg.Go(func() error {
// TOdo should any fields in onRampDestChainConfig be strings? is Router an address?
resp := onRampDestChainConfig{}
err := r.contractReaders[chainSel].ExtendedGetLatestValue(
ctx,
Expand Down
2 changes: 2 additions & 0 deletions pkg/reader/price_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (pr *priceReader) GetFeeQuoterTokenUpdates(
pr.lggr.Warnw("contract reader not found", "chain", chain)
return nil, nil
}

// TODO should these tokens be strings instead of bytes?
// MethodNameFeeQuoterGetTokenPrices returns an empty update with
// a timestamp and price of 0 if the token is not found
if err :=
Expand Down
Loading