diff --git a/execute/internal/gas/evm/gas_helpers.go b/execute/internal/gas/evm/gas_helpers.go index 6e6ee82cd..b94e27d52 100644 --- a/execute/internal/gas/evm/gas_helpers.go +++ b/execute/internal/gas/evm/gas_helpers.go @@ -2,6 +2,8 @@ package evm import ( "math" + + "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" ) const ( @@ -45,7 +47,13 @@ func bytesForMsgTokens(numTokens int) int { } // CalculateMessageMaxGas computes the maximum gas overhead for a message. -func (gp EstimateProvider) CalculateMessageMaxGas(dataLength, numTokens int) uint64 { +func (gp EstimateProvider) CalculateMessageMaxGas(msg ccipocr3.Message) uint64 { + numTokens := len(msg.TokenAmounts) + var data []byte = msg.Data + dataLength := len(data) + + // TODO: parse max gas from ExtraArgs. + messageBytes := ConstantMessagePartBytes + bytesForMsgTokens(numTokens) + dataLength diff --git a/execute/internal/gas/evm/gas_helpers_test.go b/execute/internal/gas/evm/gas_helpers_test.go index fea1e33bc..396d61513 100644 --- a/execute/internal/gas/evm/gas_helpers_test.go +++ b/execute/internal/gas/evm/gas_helpers_test.go @@ -5,6 +5,8 @@ import ( "testing" "github.com/stretchr/testify/assert" + + "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" ) func Test_calculateMessageMaxGas(t *testing.T) { @@ -41,8 +43,12 @@ func Test_calculateMessageMaxGas(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + msg := ccipocr3.Message{ + Data: make([]byte, tt.args.dataLen), + TokenAmounts: make([]ccipocr3.RampTokenAmount, tt.args.numTokens), + } ep := EstimateProvider{} - got := ep.CalculateMessageMaxGas(tt.args.dataLen, tt.args.numTokens) + got := ep.CalculateMessageMaxGas(msg) fmt.Println(got) assert.Equalf(t, tt.want, got, "calculateMessageMaxGas(%v, %v)", tt.args.dataLen, tt.args.numTokens) }) @@ -77,9 +83,14 @@ func TestCalculateMaxGas(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + msg := ccipocr3.Message{ + Data: make([]byte, tt.dataLength), + TokenAmounts: make([]ccipocr3.RampTokenAmount, tt.numberOfTokens), + } ep := EstimateProvider{} + gotTree := ep.CalculateMerkleTreeGas(tt.numRequests) - gotMsg := ep.CalculateMessageMaxGas(tt.dataLength, tt.numberOfTokens) + gotMsg := ep.CalculateMessageMaxGas(msg) fmt.Println("want", tt.want, "got", gotTree+gotMsg) assert.Equal(t, tt.want, gotTree+gotMsg) }) diff --git a/execute/internal/gas/gas_estimate_provider.go b/execute/internal/gas/gas_estimate_provider.go index a9b4bce37..fb487526f 100644 --- a/execute/internal/gas/gas_estimate_provider.go +++ b/execute/internal/gas/gas_estimate_provider.go @@ -1,6 +1,8 @@ package gas +import "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + type EstimateProvider interface { CalculateMerkleTreeGas(numRequests int) uint64 - CalculateMessageMaxGas(dataLength, numTokens int) uint64 + CalculateMessageMaxGas(msg ccipocr3.Message) uint64 } diff --git a/execute/report/report.go b/execute/report/report.go index bc6f98b01..ec0e0d667 100644 --- a/execute/report/report.go +++ b/execute/report/report.go @@ -236,11 +236,9 @@ func (b *execReportBuilder) verifyReport( } gasSum := uint64(0) for _, msg := range execReport.Messages { - var data []byte = msg.Data - gasSum += b.estimateProvider.CalculateMessageMaxGas(len(data), len(msg.TokenAmounts)) + gasSum += b.estimateProvider.CalculateMessageMaxGas(msg) } merkleTreeGas := b.estimateProvider.CalculateMerkleTreeGas(len(execReport.Messages)) - // TODO: Add in message max gas (unless it can be added to CalculateMessageMaxGas). totalGas := gasSum + merkleTreeGas maxGas := b.maxGas - b.accumulated.gas