Skip to content

Commit

Permalink
Rename xdai ChainType config to gnosis (#12093)
Browse files Browse the repository at this point in the history
* feat: rename xdai ChainType config to gnosis due to the chain rebranding (SHIP-1067)

* chore: demote pyroscope-go

* chore: rename more occurrences of xdai

* refactor: retain old value for compatibility reasons, but deprecate and add warning if still used.

* fix: golangci-lint

* refactor: move deprecation warning to deprecationWarnings()

* refactor: sort chainTypes alphabetically and add exhaustive switch stmts

* bump deprecating version for xdai chaintype to v2.13.0

* remove changelog entry and add changeset

* fix config test
  • Loading branch information
friedemannf authored and ogtownsend committed Mar 13, 2024
1 parent 1b6f91f commit a8cdd7a
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 103 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-cats-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

The `xdai` `ChainType` has been renamed to `gnosis` to match the chain's new name. The old value is still supported but has been deprecated and will be removed in v2.13.0.
26 changes: 16 additions & 10 deletions common/config/chaintype.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,33 @@ type ChainType string
// nolint
const (
ChainArbitrum ChainType = "arbitrum"
ChainCelo ChainType = "celo"
ChainGnosis ChainType = "gnosis"
ChainKroma ChainType = "kroma"
ChainMetis ChainType = "metis"
ChainOptimismBedrock ChainType = "optimismBedrock"
ChainXDai ChainType = "xdai"
ChainCelo ChainType = "celo"
ChainScroll ChainType = "scroll"
ChainWeMix ChainType = "wemix"
ChainKroma ChainType = "kroma"
ChainXDai ChainType = "xdai" // Deprecated: use ChainGnosis instead
ChainZkSync ChainType = "zksync"
ChainScroll ChainType = "scroll"
)

var ErrInvalidChainType = fmt.Errorf("must be one of %s or omitted", strings.Join([]string{
string(ChainArbitrum), string(ChainMetis), string(ChainXDai), string(ChainOptimismBedrock), string(ChainCelo),
string(ChainKroma), string(ChainWeMix), string(ChainZkSync), string(ChainScroll)}, ", "))
string(ChainArbitrum),
string(ChainCelo),
string(ChainGnosis),
string(ChainKroma),
string(ChainMetis),
string(ChainOptimismBedrock),
string(ChainScroll),
string(ChainWeMix),
string(ChainZkSync),
}, ", "))

// IsValid returns true if the ChainType value is known or empty.
func (c ChainType) IsValid() bool {
switch c {
case "", ChainArbitrum, ChainMetis, ChainOptimismBedrock, ChainXDai, ChainCelo, ChainKroma, ChainWeMix, ChainZkSync, ChainScroll:
case "", ChainArbitrum, ChainCelo, ChainGnosis, ChainKroma, ChainMetis, ChainOptimismBedrock, ChainScroll, ChainWeMix, ChainXDai, ChainZkSync:
return true
}
return false
Expand All @@ -41,9 +50,6 @@ func (c ChainType) IsL2() bool {
switch c {
case ChainArbitrum, ChainMetis:
return true

case ChainXDai:
fallthrough
default:
return false
}
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func TestChainScopedConfig_Profiles(t *testing.T) {
{"harmonyMainnet", 1666600000, 500000, "0.00001"},
{"harmonyTestnet", 1666700000, 500000, "0.00001"},

{"xDai", 100, 500000, "0.00001"},
{"gnosisMainnet", 100, 500000, "0.00001"},
}
for _, test := range tests {
tt := test
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/config/toml/defaults/Gnosis_Chiado.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ChainID = '10200'
# Gnoisis Finality is approx 8 minutes @ 12 blocks per minute, so 96 blocks
FinalityDepth = 100
ChainType = 'xdai'
ChainType = 'gnosis'
LogPollInterval = '5s'

[GasEstimator]
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/config/toml/defaults/Gnosis_Mainnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# With xDai's current maximum of 19 validators then 40 blocks is the maximum possible re-org)
# The mainnet default of 50 blocks is ok here
ChainID = '100'
ChainType = 'xdai'
ChainType = 'gnosis'
LinkContractAddress = '0xE2e73A1c69ecF83F464EFCE6A5be353a37cA09b2'
LogPollInterval = '5s'

Expand Down
34 changes: 20 additions & 14 deletions core/chains/evm/gas/block_history_estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,12 +886,12 @@ func TestBlockHistoryEstimator_Recalculate_NoEIP1559(t *testing.T) {
require.Equal(t, assets.NewWeiI(70), price)
})

t.Run("takes into account zero priced transactions if chain is not xDai", func(t *testing.T) {
t.Run("takes into account zero priced transactions if chain is not Gnosis", func(t *testing.T) {
// Because everyone loves free gas!
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
cfg := gas.NewMockConfig()
bhCfg := newBlockHistoryConfig()

bhCfg := newBlockHistoryConfig()
bhCfg.TransactionPercentileF = uint16(50)

geCfg := &gas.MockGasEstimatorConfig{}
Expand All @@ -908,7 +908,7 @@ func TestBlockHistoryEstimator_Recalculate_NoEIP1559(t *testing.T) {
Number: 0,
Hash: b1Hash,
ParentHash: common.Hash{},
Transactions: cltest.LegacyTransactionsFromGasPrices(0, 0, 0, 0, 100),
Transactions: cltest.LegacyTransactionsFromGasPrices(0, 0, 25, 50, 100),
},
}

Expand All @@ -917,24 +917,22 @@ func TestBlockHistoryEstimator_Recalculate_NoEIP1559(t *testing.T) {
bhe.Recalculate(cltest.Head(0))

price := gas.GetGasPrice(bhe)
require.Equal(t, assets.NewWeiI(0), price)
require.Equal(t, assets.NewWeiI(25), price)
})

t.Run("ignores zero priced transactions on xDai", func(t *testing.T) {
chainID := big.NewInt(100)

t.Run("ignores zero priced transactions only on Gnosis", func(t *testing.T) {
ethClient := evmtest.NewEthClientMock(t)
cfg := gas.NewMockConfig()
bhCfg := newBlockHistoryConfig()

bhCfg := newBlockHistoryConfig()
bhCfg.TransactionPercentileF = uint16(50)

geCfg := &gas.MockGasEstimatorConfig{}
geCfg.EIP1559DynamicFeesF = false
geCfg.PriceMaxF = maxGasPrice
geCfg.PriceMinF = assets.NewWeiI(100)
geCfg.PriceMinF = assets.NewWeiI(11) // Has to be set as Gnosis will only ignore transactions below this price

ibhe := newBlockHistoryEstimatorWithChainID(t, ethClient, cfg, geCfg, bhCfg, *chainID)
ibhe := newBlockHistoryEstimator(t, ethClient, cfg, geCfg, bhCfg)
bhe := gas.BlockHistoryEstimatorFromInterface(ibhe)

b1Hash := utils.NewHash()
Expand All @@ -944,16 +942,24 @@ func TestBlockHistoryEstimator_Recalculate_NoEIP1559(t *testing.T) {
Number: 0,
Hash: b1Hash,
ParentHash: common.Hash{},
Transactions: cltest.LegacyTransactionsFromGasPrices(0, 0, 0, 0, 100),
Transactions: cltest.LegacyTransactionsFromGasPrices(0, 0, 0, 0, 80),
},
}

gas.SetRollingBlockHistory(bhe, blocks)

// chainType is not set - GasEstimator should not ignore zero priced transactions and instead default to PriceMin==11
bhe.Recalculate(cltest.Head(0))
require.Equal(t, assets.NewWeiI(11), gas.GetGasPrice(bhe))

price := gas.GetGasPrice(bhe)
require.Equal(t, assets.NewWeiI(100), price)
// Set chainType to Gnosis - GasEstimator should now ignore zero priced transactions
cfg.ChainTypeF = string(config.ChainGnosis)
bhe.Recalculate(cltest.Head(0))
require.Equal(t, assets.NewWeiI(80), gas.GetGasPrice(bhe))

// Same for xDai (deprecated)
cfg.ChainTypeF = string(config.ChainXDai)
bhe.Recalculate(cltest.Head(0))
require.Equal(t, assets.NewWeiI(80), gas.GetGasPrice(bhe))
})

t.Run("handles unreasonably large gas prices (larger than a 64 bit int can hold)", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/gas/chain_specific.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
// chainSpecificIsUsable allows for additional logic specific to a particular
// Config that determines whether a transaction should be used for gas estimation
func chainSpecificIsUsable(tx evmtypes.Transaction, baseFee *assets.Wei, chainType config.ChainType, minGasPriceWei *assets.Wei) bool {
if chainType == config.ChainXDai {
if chainType == config.ChainGnosis || chainType == config.ChainXDai {
// GasPrice 0 on most chains is great since it indicates cheap/free transactions.
// However, xDai reserves a special type of "bridge" transaction with 0 gas
// However, Gnosis reserves a special type of "bridge" transaction with 0 gas
// price that is always processed at top priority. Ordinary transactions
// must be priced at least 1GWei, so we have to discard anything priced
// below that (unless the contract is whitelisted).
Expand Down
12 changes: 7 additions & 5 deletions core/config/docs/chains-evm.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ BlockBackfillDepth = 10 # Default
# BlockBackfillSkip enables skipping of very long backfills.
BlockBackfillSkip = false # Default
# ChainType is automatically detected from chain ID. Set this to force a certain chain type regardless of chain ID.
# Available types: arbitrum, metis, optimismBedrock, xdai, celo, kroma, wemix, zksync, scroll
# Available types: `arbitrum`, `celo`, `gnosis`, `kroma`, `metis`, `optimismBedrock`, `scroll`, `wemix`, `zksync`
#
# `xdai` has been deprecated and will be removed in v2.13.0, use `gnosis` instead.
ChainType = 'arbitrum' # Example
# FinalityDepth is the number of blocks after which an ethereum transaction is considered "final". Note that the default is automatically set based on chain ID so it should not be necessary to change this under normal operation.
# FinalityDepth is the number of blocks after which an ethereum transaction is considered "final". Note that the default is automatically set based on chain ID, so it should not be necessary to change this under normal operation.
# BlocksConsideredFinal determines how deeply we look back to ensure that transactions are confirmed onto the longest chain
# There is not a large performance penalty to setting this relatively high (on the order of hundreds)
# It is practically limited by the number of heads we store in the database and should be less than this with a comfortable margin.
# If a transaction is mined in a block more than this many blocks ago, and is reorged out, we will NOT retransmit this transaction and undefined behaviour can occur including gaps in the nonce sequence that require manual intervention to fix.
# Therefore this number represents a number of blocks we consider large enough that no re-org this deep will ever feasibly happen.
# Therefore, this number represents a number of blocks we consider large enough that no re-org this deep will ever feasibly happen.
#
# Special cases:
# `FinalityDepth`=0 would imply that transactions can be final even before they were mined into a block. This is not supported.
Expand Down Expand Up @@ -229,7 +231,7 @@ FeeCapDefault = '100 gwei' # Default
TipCapDefault = '1 wei' # Default
# TipCapMinimum is the minimum gas tip to use when submitting transactions to the blockchain.
#
# Only applies to EIP-1559 transactions)
# (Only applies to EIP-1559 transactions)
TipCapMin = '1 wei' # Default

[EVM.GasEstimator.LimitJobType]
Expand Down Expand Up @@ -267,7 +269,7 @@ CheckInclusionPercentile = 90 # Default
# **ADVANCED**
# EIP1559FeeCapBufferBlocks controls the buffer blocks to add to the current base fee when sending a transaction. By default, the gas bumping threshold + 1 block is used.
#
# Only applies to EIP-1559 transactions)
# (Only applies to EIP-1559 transactions)
EIP1559FeeCapBufferBlocks = 13 # Example
# TransactionPercentile specifies gas price to choose. E.g. if the block history contains four transactions with gas prices `[100, 200, 300, 400]` then picking 25 for this number will give a value of 200. If the calculated gas price is higher than `GasPriceDefault` then the higher price will be used as the base price for new transactions.
#
Expand Down
12 changes: 11 additions & 1 deletion core/services/chainlink/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/smartcontractkit/chainlink-solana/pkg/solana"
stkcfg "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/config"

commoncfg "github.com/smartcontractkit/chainlink/v2/common/config"
evmcfg "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/config/docs"
"github.com/smartcontractkit/chainlink/v2/core/config/env"
Expand Down Expand Up @@ -76,7 +77,16 @@ func (c *Config) valueWarnings() (err error) {
// deprecationWarnings returns an error if the Config contains deprecated fields.
// This is typically used before defaults have been applied, with input from the user.
func (c *Config) deprecationWarnings() (err error) {
// none
// ChainType xdai is deprecated and has been renamed to gnosis
for _, evm := range c.EVM {
if evm.ChainType != nil && *evm.ChainType == string(commoncfg.ChainXDai) {
err = multierr.Append(err, config.ErrInvalid{
Name: "EVM.ChainType",
Value: *evm.ChainType,
Msg: "deprecated and will be removed in v2.13.0, use 'gnosis' instead",
})
}
}
return
}

Expand Down
Loading

0 comments on commit a8cdd7a

Please sign in to comment.