Skip to content

Commit

Permalink
check usdc messges attestation in batch building (mock)
Browse files Browse the repository at this point in the history
  • Loading branch information
RensR committed Sep 5, 2023
1 parent 7a883b7 commit 5468713
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
32 changes: 25 additions & 7 deletions core/services/ocr2/plugins/ccip/execution_reporting_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/hasher"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/observability"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

const (
Expand Down Expand Up @@ -525,11 +526,35 @@ func (r *ExecutionReportingPlugin) buildBatch(
msgLggr.Errorw("Skipping message unable to compute aggregate value", "err", err)
continue
}

// if token limit is smaller than message value skip message
if tokensLeft, hasCapacity := hasEnoughTokens(aggregateTokenLimit, msgValue, inflightAggregateValue); !hasCapacity {
msgLggr.Warnw("token limit is smaller than message value", "aggregateTokenLimit", tokensLeft.String(), "msgValue", msgValue.String())
continue
}

// Any tokens that require offchain token data should be added here.
var tokenData [][]byte
for _, token := range msg.TokenAmounts {
switch token.Token {
case r.config.usdcService.SourceUSDCToken:
usdcMessageBody := ""
msgHash := utils.Keccak256Fixed([]byte(usdcMessageBody))
success, attestation, err := r.config.usdcService.IsAttestationComplete(string(msgHash[:]))
if err != nil {
msgLggr.Errorw("Skipping message unable to check USDC attestation", "err", err)
continue
}
if !success {
msgLggr.Warnw("Skipping message USDC attestation not ready")
continue
}
tokenData = append(tokenData, []byte(attestation))
default:
tokenData = append(tokenData, []byte{})
}
}

// Fee boosting
execGasPriceEstimateValue, err := execGasPriceEstimate()
if err != nil {
Expand Down Expand Up @@ -599,13 +624,6 @@ func (r *ExecutionReportingPlugin) buildBatch(
}
}

var tokenData [][]byte

// TODO add attestation data for USDC here
for range msg.TokenAmounts {
tokenData = append(tokenData, []byte{})
}

msgLggr.Infow("Adding msg to batch", "seqNum", msg.SequenceNumber, "nonce", msg.Nonce,
"value", msgValue, "aggregateTokenLimit", aggregateTokenLimit)
executableMessages = append(executableMessages, NewObservedMessage(msg.SequenceNumber, tokenData))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func setupExecTestHarness(t *testing.T) execTestHarness {
sourceWrappedNativeToken: th.Source.WrappedNative.Address(),
leafHasher: hasher.NewLeafHasher(th.Source.ChainSelector, th.Dest.ChainSelector, th.Source.OnRamp.Address(), hasher.NewKeccakCtx()),
destGasEstimator: destFeeEstimator,
usdcService: customtokens.NewUSDCService("", th.Source.ChainSelector),
},
onchainConfig: th.ExecOnchainConfig,
offchainConfig: offchainConfig,
Expand Down

0 comments on commit 5468713

Please sign in to comment.