Skip to content

Commit 73de19a

Browse files
committed
review fixes
1 parent 4491e5a commit 73de19a

File tree

7 files changed

+29
-36
lines changed

7 files changed

+29
-36
lines changed

execute/tokendata/lbtc/attestation.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ type attestationRequest struct {
3333
}
3434

3535
type AttestationResponse struct {
36-
Attestations []MessageAttestationResponse `json:"attestations"`
36+
Attestations []Attestation `json:"attestations"`
3737
// fields in case of error
3838
Code int `json:"code,omitempty"`
3939
Message string `json:"message,omitempty"`
4040
}
4141

42-
type MessageAttestationResponse struct {
42+
type Attestation struct {
4343
MessageHash string `json:"message_hash"`
4444
Status AttestationStatus `json:"status"`
45-
Attestation string `json:"attestation,omitempty"` // Attestation represented by abi.encode(payload, proof)
45+
Data string `json:"attestation,omitempty"` // Data is represented by abi.encode(payload, proof)
4646
}
4747

4848
type LBTCAttestationClient struct {
@@ -60,7 +60,7 @@ func NewLBTCAttestationClient(
6060
config.AttestationAPI,
6161
config.AttestationAPIInterval.Duration(),
6262
config.AttestationAPITimeout.Duration(),
63-
0,
63+
0, // no LBTC API cooldown
6464
)
6565
if err != nil {
6666
return nil, fmt.Errorf("get http client: %w", err)
@@ -74,6 +74,8 @@ func NewLBTCAttestationClient(
7474
), nil
7575
}
7676

77+
// Attestations is an AttestationClient method that accepts dict of messages and returns attestations under same keys.
78+
// As values in input it accepts ExtraData bytes from incoming TokenData
7779
func (c *LBTCAttestationClient) Attestations(
7880
ctx context.Context,
7981
messages map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.Bytes,
@@ -112,23 +114,25 @@ func (c *LBTCAttestationClient) Attestations(
112114
return res, nil
113115
}
114116

115-
func (c *LBTCAttestationClient) Token() string {
116-
return LBTCToken
117+
func (c *LBTCAttestationClient) Type() string {
118+
return pluginconfig.LBTCHandlerType
117119
}
118120

121+
// fetchBatch makes an HTTP Post request to Lombard Attestation API, requesting all messageHashes at once.
122+
// This method doesn't check for input batch size.
119123
func (c *LBTCAttestationClient) fetchBatch(
120124
ctx context.Context,
121-
batch []string,
125+
messageHashes []string,
122126
) (map[string]tokendata.AttestationStatus, error) {
123-
request := attestationRequest{PayloadHashes: batch}
127+
request := attestationRequest{PayloadHashes: messageHashes}
124128
encodedRequest, err := json.Marshal(request)
125129
if err != nil {
126130
return nil, fmt.Errorf("failed to marshal attestation request: %w", err)
127131
}
128132
attestations := make(map[string]tokendata.AttestationStatus)
129133
respRaw, _, err := c.httpClient.Post(ctx, fmt.Sprintf("bridge/%s/%s", apiVersion, attestationPath), encodedRequest)
130134
if err != nil {
131-
for _, inputMessageHash := range batch {
135+
for _, inputMessageHash := range messageHashes {
132136
attestations[inputMessageHash] = tokendata.ErrorAttestationStatus(err)
133137
}
134138
// absorb api error to each token data status
@@ -140,16 +144,16 @@ func (c *LBTCAttestationClient) fetchBatch(
140144
return nil, fmt.Errorf("failed to unmarshal attestation response: %w", err)
141145
}
142146
if attestationResp.Code != 0 {
143-
for _, inputMessageHash := range batch {
147+
for _, inputMessageHash := range messageHashes {
144148
attestations[inputMessageHash] = tokendata.ErrorAttestationStatus(
145149
fmt.Errorf("attestation request failed: %s", attestationResp.Message),
146150
)
147151
}
148152
}
149153
for _, attestation := range attestationResp.Attestations {
150-
attestations[attestation.MessageHash] = attestationToTokenData(attestation)
154+
attestations[attestation.MessageHash] = attestationToAttestationStatus(attestation)
151155
}
152-
for _, inputMessageHash := range batch {
156+
for _, inputMessageHash := range messageHashes {
153157
if _, ok := attestations[inputMessageHash]; !ok {
154158
c.lggr.Warnw(
155159
"Requested messageHash is missing in the response. Considering tokendata.ErrDataMissing",
@@ -160,7 +164,7 @@ func (c *LBTCAttestationClient) fetchBatch(
160164
return attestations, nil
161165
}
162166

163-
func attestationToTokenData(attestation MessageAttestationResponse) tokendata.AttestationStatus {
167+
func attestationToAttestationStatus(attestation Attestation) tokendata.AttestationStatus {
164168
if attestation.Status == attestationStatusSubmitted || attestation.Status == attestationStatusPending {
165169
return tokendata.ErrorAttestationStatus(tokendata.ErrNotReady)
166170
}
@@ -171,7 +175,7 @@ func attestationToTokenData(attestation MessageAttestationResponse) tokendata.At
171175
if err != nil {
172176
return tokendata.ErrorAttestationStatus(fmt.Errorf("failed to decode message hash in attestation: %w", err))
173177
}
174-
attestationBytes, err := cciptypes.NewBytesFromString(attestation.Attestation)
178+
attestationBytes, err := cciptypes.NewBytesFromString(attestation.Data)
175179
if err != nil {
176180
return tokendata.ErrorAttestationStatus(fmt.Errorf("failed to decode attestation: %w", err))
177181
}

execute/tokendata/lbtc/lbtc.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import (
1414
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
1515
)
1616

17-
const (
18-
LBTCToken = "lbtc"
19-
)
20-
2117
type LBTCTokenDataObserver struct {
2218
lggr logger.Logger
2319
destChainSelector cciptypes.ChainSelector
@@ -65,7 +61,7 @@ func (o *LBTCTokenDataObserver) Observe(
6561
// 2. Request attestations
6662
attestations, err := o.client.Attestations(ctx, lbtcMessages)
6763
if err != nil {
68-
return nil, err
64+
return nil, fmt.Errorf("failed to fetch attestations: %w", err)
6965
}
7066
// 3. Map to result
7167
return o.createTokenDataObservations(observations, attestations)

execute/tokendata/observed.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ func (o *ObservedAttestationClient) Attestations(
8181
for _, attestation := range msgIDToAttestation {
8282
o.trackTimeToAttestation(start, hex.EncodeToString(attestation.ID), attestation.Error)
8383
promAttestationDurations.
84-
WithLabelValues(o.Token()).
84+
WithLabelValues(o.Type()).
8585
Observe(float64(duration))
8686
}
8787
}
8888
return attestations, err
8989
}
9090

91-
func (o *ObservedAttestationClient) Token() string {
92-
return o.delegate.Token()
91+
func (o *ObservedAttestationClient) Type() string {
92+
return o.delegate.Type()
9393
}
9494

9595
func (o *ObservedAttestationClient) trackTimeToAttestation(start time.Time, id string, err error) {
@@ -107,9 +107,9 @@ func (o *ObservedAttestationClient) trackTimeToAttestation(start time.Time, id s
107107
// and we don't need to track that
108108
if seen {
109109
duration := time.Since(messageSeenFirst.(time.Time))
110-
promTimeToAttestation.WithLabelValues(o.Token()).Observe(float64(duration))
110+
promTimeToAttestation.WithLabelValues(o.Type()).Observe(float64(duration))
111111
o.lggr.Infow("Observed time to attestation for a message",
112-
"token", o.Token(),
112+
"type", o.Type(),
113113
"hash", id,
114114
"duration", duration.String(),
115115
)

execute/tokendata/token_data.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type AttestationClient interface {
4949
msgs map[cciptypes.ChainSelector]map[reader.MessageTokenID]cciptypes.Bytes,
5050
) (map[cciptypes.ChainSelector]map[reader.MessageTokenID]AttestationStatus, error)
5151

52-
Token() string
52+
Type() string
5353
}
5454

5555
type FakeAttestationClient struct {
@@ -70,6 +70,6 @@ func (f *FakeAttestationClient) Attestations(
7070
return outcome, nil
7171
}
7272

73-
func (f *FakeAttestationClient) Token() string {
73+
func (f *FakeAttestationClient) Type() string {
7474
return ""
7575
}

execute/tokendata/usdc/attestation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func (s *USDCAttestationClient) Attestations(
116116
return outcome, nil
117117
}
118118

119-
func (s *USDCAttestationClient) Token() string {
120-
return USDCToken
119+
func (s *USDCAttestationClient) Type() string {
120+
return pluginconfig.USDCCCTPHandlerType
121121
}
122122

123123
func (s *USDCAttestationClient) fetchSingleMessage(

execute/tokendata/usdc/usdc.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ import (
1919
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
2020
)
2121

22-
const (
23-
USDCToken = "USDC"
24-
)
25-
2622
type USDCTokenDataObserver struct {
2723
lggr logger.Logger
2824
destChainSelector cciptypes.ChainSelector

pluginconfig/execute.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,7 @@ func (e *ExecuteOffchainConfig) IsUSDCEnabled() bool {
108108

109109
func (e *ExecuteOffchainConfig) IsLBTCEnabled() bool {
110110
for _, ob := range e.TokenDataObservers {
111-
if ob.WellFormed() != nil {
112-
continue
113-
}
114-
if ob.IsLBTC() {
111+
if ob.WellFormed() != nil && ob.IsLBTC() {
115112
return true
116113
}
117114
}

0 commit comments

Comments
 (0)