Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 6d14080

Browse files
committed
Reapply "CCIP-4403 LBTC attestation cherry-pick (#1564)" (#1566)
This reverts commit 4ad51f8.
1 parent 4ad51f8 commit 6d14080

File tree

8 files changed

+885
-66
lines changed

8 files changed

+885
-66
lines changed

core/services/ocr2/delegate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ func (d *Delegate) ccipExecGetDstProvider(ctx context.Context, jb job.Job, plugi
18941894

18951895
// PROVIDER BASED ARG CONSTRUCTION
18961896
// Write PluginConfig bytes to send source/dest relayer provider + info outside of top level rargs/pargs over the wire
1897-
dstConfigBytes, err := newExecPluginConfig(false, pluginJobSpecConfig.SourceStartBlock, pluginJobSpecConfig.DestStartBlock, pluginJobSpecConfig.USDCConfig, string(jb.ID)).Encode()
1897+
dstConfigBytes, err := newExecPluginConfig(false, pluginJobSpecConfig.SourceStartBlock, pluginJobSpecConfig.DestStartBlock, pluginJobSpecConfig.USDCConfig, pluginJobSpecConfig.LBTCConfig, string(jb.ID)).Encode()
18981898
if err != nil {
18991899
return nil, err
19001900
}
@@ -1927,7 +1927,7 @@ func (d *Delegate) ccipExecGetDstProvider(ctx context.Context, jb job.Job, plugi
19271927

19281928
func (d *Delegate) ccipExecGetSrcProvider(ctx context.Context, jb job.Job, pluginJobSpecConfig ccipconfig.ExecPluginJobSpecConfig, transmitterID string, dstProvider types.CCIPExecProvider) (srcProvider types.CCIPExecProvider, srcChainID uint64, err error) {
19291929
spec := jb.OCR2OracleSpec
1930-
srcConfigBytes, err := newExecPluginConfig(true, pluginJobSpecConfig.SourceStartBlock, pluginJobSpecConfig.DestStartBlock, pluginJobSpecConfig.USDCConfig, string(jb.ID)).Encode()
1930+
srcConfigBytes, err := newExecPluginConfig(true, pluginJobSpecConfig.SourceStartBlock, pluginJobSpecConfig.DestStartBlock, pluginJobSpecConfig.USDCConfig, pluginJobSpecConfig.LBTCConfig, string(jb.ID)).Encode()
19311931
if err != nil {
19321932
return nil, 0, err
19331933
}
@@ -1976,12 +1976,13 @@ func (d *Delegate) ccipExecGetSrcProvider(ctx context.Context, jb job.Job, plugi
19761976
return
19771977
}
19781978

1979-
func newExecPluginConfig(isSourceProvider bool, srcStartBlock uint64, dstStartBlock uint64, usdcConfig ccipconfig.USDCConfig, jobID string) config.ExecPluginConfig {
1979+
func newExecPluginConfig(isSourceProvider bool, srcStartBlock uint64, dstStartBlock uint64, usdcConfig ccipconfig.USDCConfig, lbtcConfig ccipconfig.LBTCConfig, jobID string) config.ExecPluginConfig {
19801980
return config.ExecPluginConfig{
19811981
IsSourceProvider: isSourceProvider,
19821982
SourceStartBlock: srcStartBlock,
19831983
DestStartBlock: dstStartBlock,
19841984
USDCConfig: usdcConfig,
1985+
LBTCConfig: lbtcConfig,
19851986
JobID: jobID,
19861987
}
19871988
}

core/services/ocr2/plugins/ccip/ccipexec/initializers.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ func NewExecServices(ctx context.Context, lggr logger.Logger, jb job.Job, srcPro
121121
}
122122
tokenDataProviders[cciptypes.Address(pluginConfig.USDCConfig.SourceTokenAddress.String())] = usdcReader
123123
}
124+
// init lbtc token data provider
125+
if pluginConfig.LBTCConfig.AttestationAPI != "" {
126+
lggr.Infof("LBTC token data provider enabled")
127+
err2 := pluginConfig.LBTCConfig.ValidateLBTCConfig()
128+
if err2 != nil {
129+
return nil, err2
130+
}
131+
132+
lbtcReader, err2 := srcProvider.NewTokenDataReader(ctx, ccip.EvmAddrToGeneric(pluginConfig.LBTCConfig.SourceTokenAddress))
133+
if err2 != nil {
134+
return nil, fmt.Errorf("new lbtc reader: %w", err2)
135+
}
136+
tokenDataProviders[cciptypes.Address(pluginConfig.LBTCConfig.SourceTokenAddress.String())] = lbtcReader
137+
}
124138

125139
// Prom wrappers
126140
onRampReader = observability.NewObservedOnRampReader(onRampReader, srcChainID, ccip.ExecPluginLabel)

core/services/ocr2/plugins/ccip/config/config.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (c *DynamicPriceGetterConfig) Validate() error {
108108
type ExecPluginJobSpecConfig struct {
109109
SourceStartBlock, DestStartBlock uint64 // Only for first time job add.
110110
USDCConfig USDCConfig
111+
LBTCConfig LBTCConfig
111112
}
112113

113114
type USDCConfig struct {
@@ -119,10 +120,19 @@ type USDCConfig struct {
119120
AttestationAPIIntervalMilliseconds int
120121
}
121122

123+
type LBTCConfig struct {
124+
SourceTokenAddress common.Address
125+
AttestationAPI string
126+
AttestationAPITimeoutSeconds uint
127+
// AttestationAPIIntervalMilliseconds can be set to -1 to disable or 0 to use a default interval.
128+
AttestationAPIIntervalMilliseconds int
129+
}
130+
122131
type ExecPluginConfig struct {
123132
SourceStartBlock, DestStartBlock uint64 // Only for first time job add.
124133
IsSourceProvider bool
125134
USDCConfig USDCConfig
135+
LBTCConfig LBTCConfig
126136
JobID string
127137
}
128138

@@ -136,17 +146,30 @@ func (e ExecPluginConfig) Encode() ([]byte, error) {
136146

137147
func (uc *USDCConfig) ValidateUSDCConfig() error {
138148
if uc.AttestationAPI == "" {
139-
return errors.New("AttestationAPI is required")
149+
return errors.New("USDCConfig: AttestationAPI is required")
140150
}
141151
if uc.AttestationAPIIntervalMilliseconds < -1 {
142-
return errors.New("AttestationAPIIntervalMilliseconds must be -1 to disable, 0 for default or greater to define the exact interval")
152+
return errors.New("USDCConfig: AttestationAPIIntervalMilliseconds must be -1 to disable, 0 for default or greater to define the exact interval")
143153
}
144154
if uc.SourceTokenAddress == utils.ZeroAddress {
145-
return errors.New("SourceTokenAddress is required")
155+
return errors.New("USDCConfig: SourceTokenAddress is required")
146156
}
147157
if uc.SourceMessageTransmitterAddress == utils.ZeroAddress {
148-
return errors.New("SourceMessageTransmitterAddress is required")
158+
return errors.New("USDCConfig: SourceMessageTransmitterAddress is required")
149159
}
150160

151161
return nil
152162
}
163+
164+
func (lc *LBTCConfig) ValidateLBTCConfig() error {
165+
if lc.AttestationAPI == "" {
166+
return errors.New("LBTCConfig: AttestationAPI is required")
167+
}
168+
if lc.AttestationAPIIntervalMilliseconds < -1 {
169+
return errors.New("LBTCConfig: AttestationAPIIntervalMilliseconds must be -1 to disable, 0 for default or greater to define the exact interval")
170+
}
171+
if lc.SourceTokenAddress == utils.ZeroAddress {
172+
return errors.New("LBTCConfig: SourceTokenAddress is required")
173+
}
174+
return nil
175+
}

core/services/ocr2/plugins/ccip/tokendata/http/http_client.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ import (
1212
)
1313

1414
type IHttpClient interface {
15-
// Get issue a GET request to the given url and return the response body and status code.
15+
// Get issues a GET request to the given url and returns the response body and status code.
1616
Get(ctx context.Context, url string, timeout time.Duration) ([]byte, int, http.Header, error)
17+
18+
// Post issues a POST request to the given url with the given request data and returns the response body and status code.
19+
Post(ctx context.Context, url string, requestData io.Reader, timeout time.Duration) ([]byte, int, http.Header, error)
1720
}
1821

1922
type HttpClient struct {
2023
}
2124

22-
func (s *HttpClient) Get(ctx context.Context, url string, timeout time.Duration) ([]byte, int, http.Header, error) {
25+
func doRequest(ctx context.Context, url string, requestType string, requestBody io.Reader, timeout time.Duration) ([]byte, int, http.Header, error) {
2326
// Use a timeout to guard against attestation API hanging, causing observation timeout and failing to make any progress.
2427
timeoutCtx, cancel := context.WithTimeoutCause(ctx, timeout, tokendata.ErrTimeout)
2528
defer cancel()
26-
req, err := http.NewRequestWithContext(timeoutCtx, http.MethodGet, url, nil)
29+
req, err := http.NewRequestWithContext(timeoutCtx, requestType, url, requestBody)
2730
if err != nil {
2831
return nil, http.StatusBadRequest, nil, err
2932
}
@@ -46,3 +49,11 @@ func (s *HttpClient) Get(ctx context.Context, url string, timeout time.Duration)
4649
body, err := io.ReadAll(res.Body)
4750
return body, res.StatusCode, res.Header, err
4851
}
52+
53+
func (s *HttpClient) Get(ctx context.Context, url string, timeout time.Duration) ([]byte, int, http.Header, error) {
54+
return doRequest(ctx, url, http.MethodGet, nil, timeout)
55+
}
56+
57+
func (s *HttpClient) Post(ctx context.Context, url string, requestBody io.Reader, timeout time.Duration) ([]byte, int, http.Header, error) {
58+
return doRequest(ctx, url, http.MethodPost, requestBody, timeout)
59+
}

0 commit comments

Comments
 (0)