Skip to content

Commit

Permalink
Charge l1 data availability fee (#86)
Browse files Browse the repository at this point in the history
* add uint224 price split and call data config fields

* add calldata calculation

* address early comments

* add more comments to explain config values

* completing onramp

* fill in transfer fee tests

* add tests for getMessageCalldataCostUSD

* onchain tests complete

* complete onchain portion

* update offchain tests

* update snapshot

* fix loadgen test MaxDataSize

* better variable names

* update changelog

* address comments

* address comments

* re-generate snapshot

* update loadgen

* reset submodule

* update snapshot
  • Loading branch information
matYang authored Sep 11, 2023
1 parent 4a26c30 commit c0aa6e0
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 31 deletions.
2 changes: 1 addition & 1 deletion core/services/ocr2/plugins/ccip/execution_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestGetExecutionPluginFilterNames(t *testing.T) {
}, nil)

mockOnRamp := mock_contracts.NewEVM2EVMOnRampInterface(t)
mockOnRamp.On("TypeAndVersion", mock.Anything).Return(fmt.Sprintf("%s %s", ccipconfig.EVM2EVMOnRamp, "1.1.0"), nil)
mockOnRamp.On("TypeAndVersion", mock.Anything).Return(fmt.Sprintf("%s %s", ccipconfig.EVM2EVMOnRamp, "1.2.0"), nil)
mockOnRamp.On("GetDynamicConfig", mock.Anything).Return(
evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{
PriceRegistry: srcPriceRegAddr,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,15 @@ func Test_getTokensPrices(t *testing.T) {
name string
feeTokens []common.Address
tokens []common.Address
retPrices []price_registry.InternalTimestampedUint192Value
retPrices []price_registry.InternalTimestampedPackedUint224
expPrices map[common.Address]*big.Int
expErr bool
}{
{
name: "base",
feeTokens: []common.Address{tk1, tk2},
tokens: []common.Address{tk3},
retPrices: []price_registry.InternalTimestampedUint192Value{
retPrices: []price_registry.InternalTimestampedPackedUint224{
{Value: big.NewInt(10)},
{Value: big.NewInt(20)},
{Value: big.NewInt(30)},
Expand All @@ -907,7 +907,7 @@ func Test_getTokensPrices(t *testing.T) {
name: "token is both fee token and normal token",
feeTokens: []common.Address{tk1, tk2},
tokens: []common.Address{tk3, tk1},
retPrices: []price_registry.InternalTimestampedUint192Value{
retPrices: []price_registry.InternalTimestampedPackedUint224{
{Value: big.NewInt(10)},
{Value: big.NewInt(20)},
{Value: big.NewInt(30)},
Expand All @@ -924,7 +924,7 @@ func Test_getTokensPrices(t *testing.T) {
name: "token is both fee token and normal token and price registry gave different price",
feeTokens: []common.Address{tk1, tk2},
tokens: []common.Address{tk3, tk1},
retPrices: []price_registry.InternalTimestampedUint192Value{
retPrices: []price_registry.InternalTimestampedPackedUint224{
{Value: big.NewInt(10)},
{Value: big.NewInt(20)},
{Value: big.NewInt(30)},
Expand All @@ -936,7 +936,7 @@ func Test_getTokensPrices(t *testing.T) {
name: "zero price should lead to an error",
feeTokens: []common.Address{tk1, tk2},
tokens: []common.Address{tk3},
retPrices: []price_registry.InternalTimestampedUint192Value{
retPrices: []price_registry.InternalTimestampedPackedUint224{
{Value: big.NewInt(10)},
{Value: big.NewInt(0)},
{Value: big.NewInt(30)},
Expand All @@ -947,7 +947,7 @@ func Test_getTokensPrices(t *testing.T) {
name: "contract returns less prices than requested",
feeTokens: []common.Address{tk1, tk2},
tokens: []common.Address{tk3},
retPrices: []price_registry.InternalTimestampedUint192Value{
retPrices: []price_registry.InternalTimestampedPackedUint224{
{Value: big.NewInt(10)},
{Value: big.NewInt(20)},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (o *ObservedPriceRegistry) GetFeeTokens(opts *bind.CallOpts) ([]common.Addr
})
}

func (o *ObservedPriceRegistry) GetTokenPrices(opts *bind.CallOpts, tokens []common.Address) ([]price_registry.InternalTimestampedUint192Value, error) {
return withObservedContract(o.metric, "GetTokenPrices", func() ([]price_registry.InternalTimestampedUint192Value, error) {
func (o *ObservedPriceRegistry) GetTokenPrices(opts *bind.CallOpts, tokens []common.Address) ([]price_registry.InternalTimestampedPackedUint224, error) {
return withObservedContract(o.metric, "GetTokenPrices", func() ([]price_registry.InternalTimestampedPackedUint224, error) {
return o.PriceRegistryInterface.GetTokenPrices(opts, tokens)
})
}
Expand Down
23 changes: 21 additions & 2 deletions core/services/ocr2/plugins/ccip/plugins_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp_1_0_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/evm_2_evm_onramp_1_1_0"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/ccipevents"
ccipconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ccip/config"
Expand Down Expand Up @@ -75,9 +76,27 @@ func LoadOnRampDynamicConfig(onRamp evm_2_evm_onramp.EVM2EVMOnRampInterface, cli
MaxTokensLength: legacyDynamicConfig.MaxTokensLength,
PriceRegistry: legacyDynamicConfig.PriceRegistry,
MaxDataSize: legacyDynamicConfig.MaxDataSize,
MaxGasLimit: legacyDynamicConfig.MaxGasLimit,
MaxGasLimit: uint32(legacyDynamicConfig.MaxGasLimit),
}, nil
case "1.1.0", "1.2.0":
case "1.1.0":
legacyOnramp, err := evm_2_evm_onramp_1_1_0.NewEVM2EVMOnRamp(onRamp.Address(), client)
if err != nil {
return evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{}, err
}
legacyDynamicConfig, err := legacyOnramp.GetDynamicConfig(opts)
if err != nil {
return evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{}, err
}
return evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{
Router: legacyDynamicConfig.Router,
MaxTokensLength: legacyDynamicConfig.MaxTokensLength,
DestGasOverhead: legacyDynamicConfig.DestGasOverhead,
DestGasPerPayloadByte: legacyDynamicConfig.DestGasPerPayloadByte,
PriceRegistry: legacyDynamicConfig.PriceRegistry,
MaxDataSize: legacyDynamicConfig.MaxDataSize,
MaxGasLimit: uint32(legacyDynamicConfig.MaxGasLimit),
}, nil
case "1.2.0":
return onRamp.GetDynamicConfig(opts)
default:
return evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{}, errors.Errorf("Invalid onramp version: %s", version)
Expand Down
48 changes: 28 additions & 20 deletions core/services/ocr2/plugins/ccip/testhelpers/ccip_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,16 @@ func (c *CCIPContracts) DeployNewOnRamp(t *testing.T) {
ArmProxy: c.Source.ARM.Address(), // ARM
},
evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{
Router: c.Source.Router.Address(),
MaxTokensLength: 5,
DestGasOverhead: 350_000,
DestGasPerPayloadByte: 16,
PriceRegistry: c.Source.PriceRegistry.Address(),
MaxDataSize: 1e5,
MaxGasLimit: 4_000_000,
Router: c.Source.Router.Address(),
MaxTokensLength: 5,
DestGasOverhead: 350_000,
DestGasPerPayloadByte: 16,
DestDataAvailabilityOverheadGas: 33_596,
DestGasPerDataAvailabilityByte: 16,
DestDataAvailabilityMultiplier: 6840, // 0.684
PriceRegistry: c.Source.PriceRegistry.Address(),
MaxDataSize: 1e5,
MaxGasLimit: 4_000_000,
},
[]evm_2_evm_onramp.InternalPoolUpdate{
{
Expand Down Expand Up @@ -265,9 +268,10 @@ func (c *CCIPContracts) DeployNewOnRamp(t *testing.T) {
},
[]evm_2_evm_onramp.EVM2EVMOnRampTokenTransferFeeConfigArgs{
{
Token: c.Source.LinkToken.Address(),
Ratio: 5_0, // 5 bps
DestGasOverhead: 34_000,
Token: c.Source.LinkToken.Address(),
Ratio: 5_0, // 5 bps
DestGasOverhead: 34_000,
DestBytesOverhead: 0,
},
},
[]evm_2_evm_onramp.EVM2EVMOnRampNopAndWeight{},
Expand Down Expand Up @@ -891,13 +895,16 @@ func SetupCCIPContracts(t *testing.T, sourceChainID, sourceChainSelector, destCh
ArmProxy: armProxySourceAddress, // ARM
},
evm_2_evm_onramp.EVM2EVMOnRampDynamicConfig{
Router: sourceRouterAddress,
MaxTokensLength: 5,
DestGasOverhead: 350_000,
DestGasPerPayloadByte: 16,
PriceRegistry: sourcePricesAddress,
MaxDataSize: 1e5,
MaxGasLimit: 4_000_000,
Router: sourceRouterAddress,
MaxTokensLength: 5,
DestGasOverhead: 350_000,
DestGasPerPayloadByte: 16,
DestDataAvailabilityOverheadGas: 33_596,
DestGasPerDataAvailabilityByte: 16,
DestDataAvailabilityMultiplier: 6840, // 0.684
PriceRegistry: sourcePricesAddress,
MaxDataSize: 1e5,
MaxGasLimit: 4_000_000,
},
[]evm_2_evm_onramp.InternalPoolUpdate{
{
Expand Down Expand Up @@ -936,9 +943,10 @@ func SetupCCIPContracts(t *testing.T, sourceChainID, sourceChainSelector, destCh
},
[]evm_2_evm_onramp.EVM2EVMOnRampTokenTransferFeeConfigArgs{
{
Token: sourceLinkTokenAddress,
Ratio: 5_0, // 5 bps
DestGasOverhead: 34_000,
Token: sourceLinkTokenAddress,
Ratio: 5_0, // 5 bps
DestGasOverhead: 34_000,
DestBytesOverhead: 0,
},
},
[]evm_2_evm_onramp.EVM2EVMOnRampNopAndWeight{},
Expand Down

0 comments on commit c0aa6e0

Please sign in to comment.