-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CCIP-2590] Transfer Data Availability costs to the DAGasEstimator (#…
…1161) ## Motivation We use DAGasPriceEstimator to roughly estimate execution cost of a message in the Exec plugin. During this execution cost estimation, we need to account for the data availability component: ``` type DAGasPriceEstimator struct { daOverheadGas int64 gasPerDAByte int64 daMultiplier int64 } ``` however, these fields are not used atm, they remain 0 during cost estimation. The challenge is they live in OnRamp.sol DynamicConfig, ``` struct DynamicConfig { uint32 destDataAvailabilityOverheadGas; // Extra data availability gas charged on top of the message, e.g. for OCR uint16 destGasPerDataAvailabilityByte; // Amount of gas to charge per byte of message data that needs availability uint16 destDataAvailabilityMultiplierBps; // Multiplier for data availability gas, multiples of bps, or 0.0001 } ``` We need to read them via the OnRamp reader and pass that into the DAGasPriceEstimator one way or another. ## Solution New service implemented to transfer onRamp config to offRamp/commit plugins. It provides weak dependency between plugins and provides actual data on demand.
- Loading branch information
1 parent
87b7119
commit cfbe326
Showing
35 changed files
with
652 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package estimatorconfig | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/types/ccip" | ||
) | ||
|
||
// FeeEstimatorConfigProvider implements abstract storage for the DataAvailability settings in onRamp dynamic Config. | ||
// It's implemented to transfer DA config from different entities offRamp, onRamp, commitStore without injecting the | ||
// strong dependency between modules. ConfigProvider fetch ccip.OnRampReader object reads and returns only relevant | ||
// fields for the daGasEstimator from the encapsulated onRampReader. | ||
type FeeEstimatorConfigProvider interface { | ||
SetOnRampReader(reader ccip.OnRampReader) | ||
GetDataAvailabilityConfig(ctx context.Context) (destDataAvailabilityOverheadGas, destGasPerDataAvailabilityByte, destDataAvailabilityMultiplierBps int64, err error) | ||
} | ||
|
||
type FeeEstimatorConfigService struct { | ||
onRampReader ccip.OnRampReader | ||
} | ||
|
||
func NewFeeEstimatorConfigService() *FeeEstimatorConfigService { | ||
return &FeeEstimatorConfigService{} | ||
} | ||
|
||
// SetOnRampReader Sets the onRamp reader instance. | ||
// must be called once for each instance. | ||
func (c *FeeEstimatorConfigService) SetOnRampReader(reader ccip.OnRampReader) { | ||
c.onRampReader = reader | ||
} | ||
|
||
// GetDataAvailabilityConfig Returns dynamic config data availability parameters. | ||
// GetDynamicConfig should be cached in the onRamp reader to avoid unnecessary on-chain calls | ||
func (c *FeeEstimatorConfigService) GetDataAvailabilityConfig(ctx context.Context) (destDataAvailabilityOverheadGas, destGasPerDataAvailabilityByte, destDataAvailabilityMultiplierBps int64, err error) { | ||
if c.onRampReader == nil { | ||
return 0, 0, 0, errors.New("no OnRampReader has been configured") | ||
} | ||
|
||
cfg, err := c.onRampReader.GetDynamicConfig(ctx) | ||
if err != nil { | ||
return 0, 0, 0, err | ||
} | ||
|
||
return int64(cfg.DestDataAvailabilityOverheadGas), | ||
int64(cfg.DestGasPerDataAvailabilityByte), | ||
int64(cfg.DestDataAvailabilityMultiplierBps), | ||
err | ||
} |
45 changes: 45 additions & 0 deletions
45
core/services/ocr2/plugins/ccip/estimatorconfig/config_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package estimatorconfig_test | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/types/ccip" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/estimatorconfig" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/internal/ccipdata/mocks" | ||
) | ||
|
||
func TestFeeEstimatorConfigService(t *testing.T) { | ||
svc := estimatorconfig.NewFeeEstimatorConfigService() | ||
ctx := context.Background() | ||
|
||
var expectedDestDataAvailabilityOverheadGas int64 = 1 | ||
var expectedDestGasPerDataAvailabilityByte int64 = 2 | ||
var expectedDestDataAvailabilityMultiplierBps int64 = 3 | ||
|
||
onRampReader := mocks.NewOnRampReader(t) | ||
_, _, _, err := svc.GetDataAvailabilityConfig(ctx) | ||
require.Error(t, err) | ||
svc.SetOnRampReader(onRampReader) | ||
|
||
onRampReader.On("GetDynamicConfig", ctx). | ||
Return(ccip.OnRampDynamicConfig{ | ||
DestDataAvailabilityOverheadGas: uint32(expectedDestDataAvailabilityOverheadGas), | ||
DestGasPerDataAvailabilityByte: uint16(expectedDestGasPerDataAvailabilityByte), | ||
DestDataAvailabilityMultiplierBps: uint16(expectedDestDataAvailabilityMultiplierBps), | ||
}, nil).Once() | ||
|
||
destDataAvailabilityOverheadGas, destGasPerDataAvailabilityByte, destDataAvailabilityMultiplierBps, err := svc.GetDataAvailabilityConfig(ctx) | ||
require.NoError(t, err) | ||
require.Equal(t, expectedDestDataAvailabilityOverheadGas, destDataAvailabilityOverheadGas) | ||
require.Equal(t, expectedDestGasPerDataAvailabilityByte, destGasPerDataAvailabilityByte) | ||
require.Equal(t, expectedDestDataAvailabilityMultiplierBps, destDataAvailabilityMultiplierBps) | ||
|
||
onRampReader.On("GetDynamicConfig", ctx). | ||
Return(ccip.OnRampDynamicConfig{}, errors.New("test")).Once() | ||
_, _, _, err = svc.GetDataAvailabilityConfig(ctx) | ||
require.Error(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.