Skip to content

Commit

Permalink
Move estimate provider to public package. (#417)
Browse files Browse the repository at this point in the history
  • Loading branch information
winder authored Jan 7, 2025
1 parent 76f93c4 commit 15cbda7
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 37 deletions.
4 changes: 1 addition & 3 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ packages:
interfaces:
Controller:
Stream:
github.com/smartcontractkit/chainlink-ccip/execute/internal/gas:
interfaces:
EstimateProvider:
github.com/smartcontractkit/chainlink-ccip/pkg/reader:
interfaces:
CCIPReader:
Expand All @@ -33,6 +30,7 @@ packages:
github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3:
interfaces:
ExecutePluginCodec:
EstimateProvider:
github.com/smartcontractkit/chainlink-common/pkg/types:
interfaces:
ContractWriter:
Expand Down
5 changes: 2 additions & 3 deletions execute/costlymessages/costly_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink-ccip/execute/internal/gas"
"github.com/smartcontractkit/chainlink-ccip/internal/libs/mathslib"
"github.com/smartcontractkit/chainlink-ccip/internal/plugintypes"
readerpkg "github.com/smartcontractkit/chainlink-ccip/pkg/reader"
Expand Down Expand Up @@ -43,7 +42,7 @@ func NewObserverWithDefaults(
enabled bool,
ccipReader readerpkg.CCIPReader,
relativeBoostPerWaitHour float64,
estimateProvider gas.EstimateProvider,
estimateProvider cciptypes.EstimateProvider,
) Observer {
return NewObserver(
lggr,
Expand Down Expand Up @@ -344,7 +343,7 @@ func waitBoostedFee(
type CCIPMessageExecCostUSD18Calculator struct {
lggr logger.Logger
ccipReader readerpkg.CCIPReader
estimateProvider gas.EstimateProvider
estimateProvider cciptypes.EstimateProvider
}

// MessageExecCostUSD18 returns a map from message ID to the message's estimated execution cost in USD18s.
Expand Down
2 changes: 1 addition & 1 deletion execute/costlymessages/costly_messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink-ccip/internal/plugintypes"
gasmock "github.com/smartcontractkit/chainlink-ccip/mocks/execute/internal_/gas"
readerpkg_mock "github.com/smartcontractkit/chainlink-ccip/mocks/pkg/reader"
gasmock "github.com/smartcontractkit/chainlink-ccip/mocks/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
)

Expand Down
5 changes: 2 additions & 3 deletions execute/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/types/core"

"github.com/smartcontractkit/chainlink-ccip/execute/costlymessages"
"github.com/smartcontractkit/chainlink-ccip/execute/internal/gas"
"github.com/smartcontractkit/chainlink-ccip/execute/metrics"
"github.com/smartcontractkit/chainlink-ccip/execute/tokendata"
"github.com/smartcontractkit/chainlink-ccip/internal/plugintypes"
Expand Down Expand Up @@ -98,7 +97,7 @@ type PluginFactory struct {
execCodec cciptypes.ExecutePluginCodec
msgHasher cciptypes.MessageHasher
homeChainReader reader.HomeChain
estimateProvider gas.EstimateProvider
estimateProvider cciptypes.EstimateProvider
tokenDataEncoder cciptypes.TokenDataEncoder
contractReaders map[cciptypes.ChainSelector]types.ContractReader
chainWriters map[cciptypes.ChainSelector]types.ContractWriter
Expand All @@ -112,7 +111,7 @@ func NewPluginFactory(
msgHasher cciptypes.MessageHasher,
homeChainReader reader.HomeChain,
tokenDataEncoder cciptypes.TokenDataEncoder,
estimateProvider gas.EstimateProvider,
estimateProvider cciptypes.EstimateProvider,
contractReaders map[cciptypes.ChainSelector]types.ContractReader,
chainWriters map[cciptypes.ChainSelector]types.ContractWriter,
) *PluginFactory {
Expand Down
12 changes: 0 additions & 12 deletions execute/internal/gas/gas_estimate_provider.go

This file was deleted.

5 changes: 2 additions & 3 deletions execute/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/smartcontractkit/chainlink-ccip/execute/costlymessages"
"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/execute/internal/gas"
"github.com/smartcontractkit/chainlink-ccip/execute/metrics"
"github.com/smartcontractkit/chainlink-ccip/execute/report"
"github.com/smartcontractkit/chainlink-ccip/execute/tokendata"
Expand Down Expand Up @@ -62,7 +61,7 @@ type Plugin struct {
oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID
tokenDataObserver tokendata.TokenDataObserver
costlyMessageObserver costlymessages.Observer
estimateProvider gas.EstimateProvider
estimateProvider cciptypes.EstimateProvider
lggr logger.Logger

observationOptimizer optimizers.ObservationOptimizer
Expand All @@ -81,7 +80,7 @@ func NewPlugin(
msgHasher cciptypes.MessageHasher,
homeChain reader.HomeChain,
tokenDataObserver tokendata.TokenDataObserver,
estimateProvider gas.EstimateProvider,
estimateProvider cciptypes.EstimateProvider,
lggr logger.Logger,
costlyMessageObserver costlymessages.Observer,
metricsReporter metrics.Reporter,
Expand Down
5 changes: 2 additions & 3 deletions execute/report/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/execute/internal/gas"
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
)

Expand All @@ -23,7 +22,7 @@ func NewBuilder(
logger logger.Logger,
hasher cciptypes.MessageHasher,
encoder cciptypes.ExecutePluginCodec,
estimateProvider gas.EstimateProvider,
estimateProvider cciptypes.EstimateProvider,
nonces map[cciptypes.ChainSelector]map[string]uint64,
destChainSelector cciptypes.ChainSelector,
maxReportSizeBytes uint64,
Expand Down Expand Up @@ -63,7 +62,7 @@ type execReportBuilder struct {
// Providers
encoder cciptypes.ExecutePluginCodec
hasher cciptypes.MessageHasher
estimateProvider gas.EstimateProvider
estimateProvider cciptypes.EstimateProvider
sendersNonce map[cciptypes.ChainSelector]map[string]uint64

// Config
Expand Down
7 changes: 3 additions & 4 deletions execute/report/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/merklemulti"

"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/execute/internal/gas"
"github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib"
"github.com/smartcontractkit/chainlink-ccip/internal/mocks"
gasmock "github.com/smartcontractkit/chainlink-ccip/mocks/execute/internal_/gas"
gasmock "github.com/smartcontractkit/chainlink-ccip/mocks/pkg/types/ccipocr3"
cciptypes "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
)

Expand Down Expand Up @@ -801,7 +800,7 @@ func (bc badCodec) Decode(ctx context.Context, bytes []byte) (cciptypes.ExecuteP
func Test_execReportBuilder_verifyReport(t *testing.T) {
type fields struct {
encoder cciptypes.ExecutePluginCodec
estimateProvider gas.EstimateProvider
estimateProvider cciptypes.EstimateProvider
maxReportSizeBytes uint64
maxGas uint64
accumulated validationMetadata
Expand Down Expand Up @@ -848,7 +847,7 @@ func Test_execReportBuilder_verifyReport(t *testing.T) {
fields: fields{
maxReportSizeBytes: 10000,
maxGas: 1000000,
estimateProvider: func() gas.EstimateProvider {
estimateProvider: func() cciptypes.EstimateProvider {
// values taken from evm.EstimateProvider
mockep := gasmock.NewMockEstimateProvider(t)
mockep.EXPECT().CalculateMessageMaxGas(mock.Anything).Return(uint64(119920)).Times(4)
Expand Down
5 changes: 2 additions & 3 deletions execute/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/smartcontractkit/chainlink-ccip/chainconfig"
"github.com/smartcontractkit/chainlink-ccip/execute/costlymessages"
"github.com/smartcontractkit/chainlink-ccip/execute/exectypes"
"github.com/smartcontractkit/chainlink-ccip/execute/internal/gas"
"github.com/smartcontractkit/chainlink-ccip/execute/metrics"
"github.com/smartcontractkit/chainlink-ccip/execute/report"
"github.com/smartcontractkit/chainlink-ccip/execute/tokendata"
Expand All @@ -36,8 +35,8 @@ import (
"github.com/smartcontractkit/chainlink-ccip/internal/mocks/inmem"
"github.com/smartcontractkit/chainlink-ccip/internal/plugintypes"
"github.com/smartcontractkit/chainlink-ccip/internal/reader"
gasmock "github.com/smartcontractkit/chainlink-ccip/mocks/execute/internal_/gas"
readermock "github.com/smartcontractkit/chainlink-ccip/mocks/pkg/contractreader"
gasmock "github.com/smartcontractkit/chainlink-ccip/mocks/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
"github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
readerpkg "github.com/smartcontractkit/chainlink-ccip/pkg/reader"
Expand Down Expand Up @@ -312,7 +311,7 @@ func (it *IntTest) UpdateExecutionCost(id cciptypes.Bytes32, val int64) {
func (it *IntTest) newNode(
cfg pluginconfig.ExecuteOffchainConfig,
homeChain reader.HomeChain,
ep gas.EstimateProvider,
ep cciptypes.EstimateProvider,
tokenDataObserver tokendata.TokenDataObserver,
costlyMessageObserver costlymessages.Observer,
oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/types/ccipocr3/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ type RMNCrypto interface {
type TokenDataEncoder interface {
EncodeUSDC(ctx context.Context, message Bytes, attestation Bytes) (Bytes, error)
}

// EstimateProvider is used to estimate the gas cost of a message or a merkle tree.
type EstimateProvider interface {
CalculateMerkleTreeGas(numRequests int) uint64
CalculateMessageMaxGas(msg Message) uint64
}

0 comments on commit 15cbda7

Please sign in to comment.