Skip to content

Commit

Permalink
Merge branch 'release/2.12.1' into fix_mercury_db_multicast_performan…
Browse files Browse the repository at this point in the history
…ce_issue
  • Loading branch information
akuzni2 authored Jun 5, 2024
2 parents 4618906 + 963c513 commit 1d66b26
Show file tree
Hide file tree
Showing 40 changed files with 833 additions and 291 deletions.
82 changes: 17 additions & 65 deletions CHANGELOG.md

Large diffs are not rendered by default.

117 changes: 93 additions & 24 deletions common/config/chaintype.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import (
"strings"
)

// ChainType denotes the chain or network to work with
type ChainType string

// nolint
const (
ChainArbitrum ChainType = "arbitrum"
ChainCelo ChainType = "celo"
Expand All @@ -18,11 +16,103 @@ const (
ChainOptimismBedrock ChainType = "optimismBedrock"
ChainScroll ChainType = "scroll"
ChainWeMix ChainType = "wemix"
ChainXDai ChainType = "xdai" // Deprecated: use ChainGnosis instead
ChainXLayer ChainType = "xlayer"
ChainZkSync ChainType = "zksync"
)

// IsL2 returns true if this chain is a Layer 2 chain. Notably:
// - the block numbers used for log searching are different from calling block.number
// - gas bumping is not supported, since there is no tx mempool
func (c ChainType) IsL2() bool {
switch c {
case ChainArbitrum, ChainMetis:
return true
default:
return false
}
}

func (c ChainType) IsValid() bool {
switch c {
case "", ChainArbitrum, ChainCelo, ChainGnosis, ChainKroma, ChainMetis, ChainOptimismBedrock, ChainScroll, ChainWeMix, ChainXLayer, ChainZkSync:
return true
}
return false
}

func ChainTypeFromSlug(slug string) ChainType {
switch slug {
case "arbitrum":
return ChainArbitrum
case "celo":
return ChainCelo
case "gnosis", "xdai":
return ChainGnosis
case "kroma":
return ChainKroma
case "metis":
return ChainMetis
case "optimismBedrock":
return ChainOptimismBedrock
case "scroll":
return ChainScroll
case "wemix":
return ChainWeMix
case "xlayer":
return ChainXLayer
case "zksync":
return ChainZkSync
default:
return ChainType(slug)
}
}

type ChainTypeConfig struct {
value ChainType
slug string
}

func NewChainTypeConfig(slug string) *ChainTypeConfig {
return &ChainTypeConfig{
value: ChainTypeFromSlug(slug),
slug: slug,
}
}

func (c *ChainTypeConfig) MarshalText() ([]byte, error) {
if c == nil {
return nil, nil
}
return []byte(c.slug), nil
}

func (c *ChainTypeConfig) UnmarshalText(b []byte) error {
c.slug = string(b)
c.value = ChainTypeFromSlug(c.slug)
return nil
}

func (c *ChainTypeConfig) Slug() string {
if c == nil {
return ""
}
return c.slug
}

func (c *ChainTypeConfig) ChainType() ChainType {
if c == nil {
return ""
}
return c.value
}

func (c *ChainTypeConfig) String() string {
if c == nil {
return ""
}
return string(c.value)
}

var ErrInvalidChainType = fmt.Errorf("must be one of %s or omitted", strings.Join([]string{
string(ChainArbitrum),
string(ChainCelo),
Expand All @@ -35,24 +125,3 @@ var ErrInvalidChainType = fmt.Errorf("must be one of %s or omitted", strings.Joi
string(ChainXLayer),
string(ChainZkSync),
}, ", "))

// IsValid returns true if the ChainType value is known or empty.
func (c ChainType) IsValid() bool {
switch c {
case "", ChainArbitrum, ChainCelo, ChainGnosis, ChainKroma, ChainMetis, ChainOptimismBedrock, ChainScroll, ChainWeMix, ChainXDai, ChainXLayer, ChainZkSync:
return true
}
return false
}

// IsL2 returns true if this chain is a Layer 2 chain. Notably:
// - the block numbers used for log searching are different from calling block.number
// - gas bumping is not supported, since there is no tx mempool
func (c ChainType) IsL2() bool {
switch c {
case ChainArbitrum, ChainMetis:
return true
default:
return false
}
}
46 changes: 37 additions & 9 deletions common/txmgr/mocks/tx_manager.go

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

22 changes: 18 additions & 4 deletions common/txmgr/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ type TxManager[
services.Service
Trigger(addr ADDR)
CreateTransaction(ctx context.Context, txRequest txmgrtypes.TxRequest[ADDR, TX_HASH]) (etx txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], err error)
GetForwarderForEOA(eoa ADDR) (forwarder ADDR, err error)
GetForwarderForEOA(ctx context.Context, eoa ADDR) (forwarder ADDR, err error)
GetForwarderForEOAOCR2Feeds(ctx context.Context, eoa, ocr2AggregatorID ADDR) (forwarder ADDR, err error)
RegisterResumeCallback(fn ResumeCallback)
SendNativeToken(ctx context.Context, chainID CHAIN_ID, from, to ADDR, value big.Int, gasLimit uint64) (etx txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], err error)
Reset(addr ADDR, abandon bool) error
Expand Down Expand Up @@ -545,11 +546,20 @@ func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) CreateTran
}

// Calls forwarderMgr to get a proper forwarder for a given EOA.
func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) GetForwarderForEOA(eoa ADDR) (forwarder ADDR, err error) {
func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) GetForwarderForEOA(ctx context.Context, eoa ADDR) (forwarder ADDR, err error) {
if !b.txConfig.ForwardersEnabled() {
return forwarder, fmt.Errorf("forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
}
forwarder, err = b.fwdMgr.ForwarderFor(eoa)
forwarder, err = b.fwdMgr.ForwarderFor(ctx, eoa)
return
}

// GetForwarderForEOAOCR2Feeds calls forwarderMgr to get a proper forwarder for a given EOA and checks if its set as a transmitter on the OCR2Aggregator contract.
func (b *Txm[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) GetForwarderForEOAOCR2Feeds(ctx context.Context, eoa, ocr2Aggregator ADDR) (forwarder ADDR, err error) {
if !b.txConfig.ForwardersEnabled() {
return forwarder, fmt.Errorf("forwarding is not enabled, to enable set Transactions.ForwardersEnabled =true")
}
forwarder, err = b.fwdMgr.ForwarderForOCR2Feeds(ctx, eoa, ocr2Aggregator)
return
}

Expand Down Expand Up @@ -646,9 +656,13 @@ func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) Tri
func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) CreateTransaction(ctx context.Context, txRequest txmgrtypes.TxRequest[ADDR, TX_HASH]) (etx txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], err error) {
return etx, errors.New(n.ErrMsg)
}
func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetForwarderForEOA(addr ADDR) (fwdr ADDR, err error) {
func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetForwarderForEOA(ctx context.Context, addr ADDR) (fwdr ADDR, err error) {
return fwdr, err
}
func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) GetForwarderForEOAOCR2Feeds(ctx context.Context, _, _ ADDR) (fwdr ADDR, err error) {
return fwdr, err
}

func (n *NullTxManager[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) Reset(addr ADDR, abandon bool) error {
return nil
}
Expand Down
6 changes: 5 additions & 1 deletion common/txmgr/types/forwarder_manager.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package types

import (
"context"

"github.com/smartcontractkit/chainlink-common/pkg/services"

"github.com/smartcontractkit/chainlink/v2/common/types"
)

//go:generate mockery --quiet --name ForwarderManager --output ./mocks/ --case=underscore
type ForwarderManager[ADDR types.Hashable] interface {
services.Service
ForwarderFor(addr ADDR) (forwarder ADDR, err error)
ForwarderFor(ctx context.Context, addr ADDR) (forwarder ADDR, err error)
ForwarderForOCR2Feeds(ctx context.Context, eoa, ocr2Aggregator ADDR) (forwarder ADDR, err error)
// Converts payload to be forwarder-friendly
ConvertPayload(dest ADDR, origPayload []byte) ([]byte, error)
}
46 changes: 37 additions & 9 deletions common/txmgr/types/mocks/forwarder_manager.go

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

3 changes: 2 additions & 1 deletion core/chains/evm/client/config_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go.uber.org/multierr"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/common/config"

commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
evmconfig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/config"
Expand Down Expand Up @@ -55,7 +56,7 @@ func NewClientConfigs(
chainConfig := &evmconfig.EVMConfig{
C: &toml.EVMConfig{
Chain: toml.Chain{
ChainType: &chainType,
ChainType: config.NewChainTypeConfig(chainType),
FinalityDepth: finalityDepth,
FinalityTagEnabled: finalityTagEnabled,
NoNewHeadsThreshold: commonconfig.MustNewDuration(noNewHeadsThreshold),
Expand Down
2 changes: 0 additions & 2 deletions core/chains/evm/client/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func TestPool_Dial(t *testing.T) {
if err == nil {
t.Cleanup(func() { assert.NoError(t, p.Close()) })
}
assert.True(t, p.ChainType().IsValid())
assert.False(t, p.ChainType().IsL2())
if test.errStr != "" {
require.Error(t, err)
Expand Down Expand Up @@ -333,7 +332,6 @@ func TestUnit_Pool_BatchCallContextAll(t *testing.T) {

p := evmclient.NewPool(logger.Test(t), defaultConfig.NodeSelectionMode(), defaultConfig.LeaseDuration(), time.Second*0, nodes, sendonlys, &cltest.FixtureChainID, "")

assert.True(t, p.ChainType().IsValid())
assert.False(t, p.ChainType().IsL2())
require.NoError(t, p.BatchCallContextAll(ctx, b))
}
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/config/chain_scoped.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (e *EVMConfig) ChainType() commonconfig.ChainType {
if e.C.ChainType == nil {
return ""
}
return commonconfig.ChainType(*e.C.ChainType)
return e.C.ChainType.ChainType()
}

func (e *EVMConfig) ChainID() *big.Int {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func Test_chainScopedConfig_Validate(t *testing.T) {
t.Run("arbitrum-estimator", func(t *testing.T) {
t.Run("custom", func(t *testing.T) {
cfg := configWithChains(t, 0, &toml.Chain{
ChainType: ptr(string(commonconfig.ChainArbitrum)),
ChainType: commonconfig.NewChainTypeConfig(string(commonconfig.ChainArbitrum)),
GasEstimator: toml.GasEstimator{
Mode: ptr("BlockHistory"),
},
Expand Down Expand Up @@ -437,7 +437,7 @@ func Test_chainScopedConfig_Validate(t *testing.T) {
t.Run("optimism-estimator", func(t *testing.T) {
t.Run("custom", func(t *testing.T) {
cfg := configWithChains(t, 0, &toml.Chain{
ChainType: ptr(string(commonconfig.ChainOptimismBedrock)),
ChainType: commonconfig.NewChainTypeConfig(string(commonconfig.ChainOptimismBedrock)),
GasEstimator: toml.GasEstimator{
Mode: ptr("BlockHistory"),
},
Expand Down
Loading

0 comments on commit 1d66b26

Please sign in to comment.