Skip to content

Commit

Permalink
CCIP-4403 don't request lbtc attestation if payload is returned
Browse files Browse the repository at this point in the history
  • Loading branch information
bukata-sa committed Dec 3, 2024
1 parent 836ea2c commit cdd6b9f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,20 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E
}
}

payloadHash, err := s.getLBTCPayloadHash(msg, tokenIndex)
decodedSourceTokenData, err := abihelpers.DecodeAbiStruct[sourceTokenData](msg.SourceTokenData[tokenIndex])
if err != nil {
return []byte{}, errors.Wrap(err, "failed getting the LBTC message body")
return []byte{}, err
}
destTokenData := decodedSourceTokenData.ExtraData
// We don't have better way to determine if the extraData is a payload or sha256(payload)
// Last parameter of the payload struct is 32-bytes nonce (see Lombard's Bridge._deposit(...) method),
// so we can assume that payload always exceeds 32 bytes
if len(destTokenData) != 32 {
s.lggr.Infow("SourceTokenData.extraData size is not 32. This is deposit payload, not sha256(payload). Attestation is disabled onchain",
"destTokenData", hexutil.Encode(destTokenData))
return destTokenData, nil
}
payloadHash := [32]byte(destTokenData)

msgID := hexutil.Encode(msg.MessageID[:])
payloadHashHex := hexutil.Encode(payloadHash[:])
Expand All @@ -207,12 +217,15 @@ func (s *TokenDataReader) ReadTokenData(ctx context.Context, msg cciptypes.EVM2E
if len(attestationResp.Attestations) > 1 {
s.lggr.Warnw("Multiple attestations received, expected one", "attestations", attestationResp.Attestations)
}
var attestation messageAttestationResponse
var attestation *messageAttestationResponse
for _, attestationCandidate := range attestationResp.Attestations {
if attestationCandidate.MessageHash == payloadHashHex {
attestation = attestationCandidate
attestation = &attestationCandidate

Check failure on line 223 in core/services/ocr2/plugins/ccip/tokendata/lbtc/lbtc.go

View workflow job for this annotation

GitHub Actions / lint

exporting a pointer for the loop variable attestationCandidate (exportloopref)
}
}
if attestation == nil {
return nil, fmt.Errorf("requested attestation %s not found in response", payloadHashHex)
}
s.lggr.Infow("Got response from attestation API", "messageID", msgID,
"attestationStatus", attestation.Status, "attestation", attestation)
switch attestation.Status {
Expand Down

0 comments on commit cdd6b9f

Please sign in to comment.