Skip to content

Commit

Permalink
Remove big from core utils (#11511)
Browse files Browse the repository at this point in the history
* Change difficulty from Big to BigInt

* Fix headtracker mock head

* Remove EsnureClosed

* Fix mock heads

* Migrate to common Mailbox

* Fix Tracker close on txm

* Change to EnsureHexPrefix

* Change names to mailbox

* Remove core/null dependency from common

* Remove core mailbox

* Fix dependencies

* Tidy

* Fix dependencies

* Change path to internal utils

* Minor fixes

* Implement skeleton interfaces, structs, & methods for ChainReader EVM POC

- Read ChainReader config in from RelayConfig
- Add some initialization and validation relay skeletons

- Use medianProviderWrapper instead of passing medianContract separately

This avoids us having to modify the signature of NewMedianFactory, which
would require further modifications to all non-evm repos and chainlink-relay

- Add chain_reader_test.go with some basic relay tests

Co-authored-by: Jordan Krage <jmank88@gmail.com>

- Add chain reader config validation
- Add chain reader config validation tests
- Add config for chain reader median contract to cr validation testcases
- Add unimplemented Encode(), Decode(), GetMaxEncodingSize(), GetMaxDecodingSize()
- Add ChainReader() method to mock provider for plugin test
- Rename relaymercury.ChainReader to MercuryChainReader, resolve name collisions
- Add tests for errors during ChainReader construction
- Propagate InvalidConfig & any other errors back to client

We should ignore Unimplemented until node ops have been given ample time to migrate to the new job spec
(including a section for ChainReader config) so that we can remove the old product-specific
MedianContract component from MedianProvider. All other errors we can immediately start passing back
to the client, letting the core node decide how to handle them (eg. displaying an "invalid job spec"
message to the UI if the RelayConfig was invalid or the ContractID missing)

* Update relay versions

* Big migration

* Simplify chain reader config validation

* Rename MinKey function

* Remove big from utils

* Fix dependencies

* Minor fixes

* Fix merge conflicts

* Minor fixes

---------

Co-authored-by: Domino Valdano <2644901+reductionista@users.noreply.github.com>
Co-authored-by: ilija <pavlovicilija42@gmail.com>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 35ad7d1 commit a8d096c
Show file tree
Hide file tree
Showing 148 changed files with 636 additions and 550 deletions.
6 changes: 3 additions & 3 deletions core/chains/evm/assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/utils/bytes"
"github.com/smartcontractkit/chainlink/v2/core/utils"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"

"github.com/shopspring/decimal"
)
Expand Down Expand Up @@ -108,10 +108,10 @@ func (e *Eth) ToInt() *big.Int {

// Scan reads the database value and returns an instance.
func (e *Eth) Scan(value interface{}) error {
return (*utils.Big)(e).Scan(value)
return (*ubig.Big)(e).Scan(value)
}

// Value returns the Eth value for serialization to database.
func (e Eth) Value() (driver.Value, error) {
return (utils.Big)(e).Value()
return (ubig.Big)(e).Value()
}
10 changes: 5 additions & 5 deletions core/chains/evm/assets/wei.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"golang.org/x/exp/constraints"

bigmath "github.com/smartcontractkit/chainlink-common/pkg/utils/big_math"
"github.com/smartcontractkit/chainlink/v2/core/utils"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)

const (
Expand Down Expand Up @@ -58,10 +58,10 @@ func suffixExp(suf string) int32 {
}
}

// Wei extends utils.Big to implement encoding.TextMarshaler and
// Wei extends ubig.Big to implement encoding.TextMarshaler and
// encoding.TextUnmarshaler with support for unit suffixes, as well as
// additional functions
type Wei utils.Big
type Wei ubig.Big

func MaxWei(w, x *Wei) *Wei {
return NewWei(bigmath.Max(w.ToInt(), x.ToInt()))
Expand Down Expand Up @@ -271,10 +271,10 @@ func (w *Wei) AddPercentage(percentage uint16) *Wei {

// Scan reads the database value and returns an instance.
func (w *Wei) Scan(value interface{}) error {
return (*utils.Big)(w).Scan(value)
return (*ubig.Big)(w).Scan(value)
}

// Value returns this instance serialized for database storage.
func (w Wei) Value() (driver.Value, error) {
return (utils.Big)(w).Value()
return (ubig.Big)(w).Value()
}
4 changes: 2 additions & 2 deletions core/chains/evm/client/chain_id_sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/ethereum/go-ethereum"

evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/utils"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)

var _ ethereum.Subscription = &chainIDSubForwarder{}
Expand Down Expand Up @@ -64,7 +64,7 @@ func (c *chainIDSubForwarder) forwardLoop() {
return

case h := <-c.srcCh:
h.EVMChainID = utils.NewBig(c.chainID)
h.EVMChainID = ubig.New(c.chainID)
select {
case c.destCh <- h:
case <-c.unSub:
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/client/chain_id_sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"

evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/utils"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)

type mockSubscription struct {
Expand Down Expand Up @@ -111,7 +111,7 @@ func TestChainIDSubForwarder(t *testing.T) {
forwarder.srcCh <- head
receivedHead := <-ch
assert.Equal(t, head, receivedHead)
assert.Equal(t, utils.NewBig(chainID), receivedHead.EVMChainID)
assert.Equal(t, ubig.New(chainID), receivedHead.EVMChainID)

expectedErr := errors.New("error")
sub.Errors <- expectedErr
Expand Down
5 changes: 3 additions & 2 deletions core/chains/evm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/common/config"
htrktypes "github.com/smartcontractkit/chainlink/v2/common/headtracker/types"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/utils"

"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -286,7 +287,7 @@ func (client *client) HeadByNumber(ctx context.Context, number *big.Int) (head *
err = ethereum.NotFound
return
}
head.EVMChainID = utils.NewBig(client.ConfiguredChainID())
head.EVMChainID = ubig.New(client.ConfiguredChainID())
return
}

Expand All @@ -299,7 +300,7 @@ func (client *client) HeadByHash(ctx context.Context, hash common.Hash) (head *e
err = ethereum.NotFound
return
}
head.EVMChainID = utils.NewBig(client.ConfiguredChainID())
head.EVMChainID = ubig.New(client.ConfiguredChainID())
return
}

Expand Down
5 changes: 3 additions & 2 deletions core/chains/evm/client/node_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
cutils "github.com/smartcontractkit/chainlink-common/pkg/utils"
bigmath "github.com/smartcontractkit/chainlink-common/pkg/utils/big_math"

evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/utils"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
)

var (
Expand Down Expand Up @@ -50,7 +51,7 @@ func zombieNodeCheckInterval(noNewHeadsThreshold time.Duration) time.Duration {
if interval <= 0 || interval > queryTimeout {
interval = queryTimeout
}
return utils.WithJitter(interval)
return cutils.WithJitter(interval)
}

func (n *node) setLatestReceived(blockNumber int64, totalDifficulty *big.Int) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (

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

"github.com/smartcontractkit/chainlink/v2/common/config"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

var (
Expand Down
5 changes: 3 additions & 2 deletions core/chains/evm/client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
commontypes "github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down Expand Up @@ -491,7 +492,7 @@ func (r *rpcClient) BlockByNumber(ctx context.Context, number *big.Int) (head *e
err = ethereum.NotFound
return
}
head.EVMChainID = utils.NewBig(r.chainID)
head.EVMChainID = ubig.New(r.chainID)
return
}

Expand All @@ -504,7 +505,7 @@ func (r *rpcClient) BlockByHash(ctx context.Context, hash common.Hash) (head *ev
err = ethereum.NotFound
return
}
head.EVMChainID = utils.NewBig(r.chainID)
head.EVMChainID = ubig.New(r.chainID)
return
}

Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/send_only_node_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"time"

"github.com/smartcontractkit/chainlink/v2/core/utils"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
)

// verifyLoop may only be triggered once, on Start, if initial chain ID check
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/client/simulated_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/utils"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)

func init() {
Expand Down Expand Up @@ -197,7 +197,7 @@ func (c *SimulatedBackendClient) HeadByNumber(ctx context.Context, n *big.Int) (
return nil, ethereum.NotFound
}
return &evmtypes.Head{
EVMChainID: utils.NewBigI(c.chainId.Int64()),
EVMChainID: ubig.NewI(c.chainId.Int64()),
Hash: header.Hash(),
Number: header.Number.Int64(),
ParentHash: header.ParentHash,
Expand All @@ -214,7 +214,7 @@ func (c *SimulatedBackendClient) HeadByHash(ctx context.Context, h common.Hash)
return nil, ethereum.NotFound
}
return &evmtypes.Head{
EVMChainID: utils.NewBigI(c.chainId.Int64()),
EVMChainID: ubig.NewI(c.chainId.Int64()),
Hash: header.Hash(),
Number: header.Number.Int64(),
ParentHash: header.ParentHash,
Expand Down Expand Up @@ -302,7 +302,7 @@ func (c *SimulatedBackendClient) SubscribeNewHead(
case h := <-ch:
var head *evmtypes.Head
if h != nil {
head = &evmtypes.Head{Difficulty: h.Difficulty, Timestamp: time.Unix(int64(h.Time), 0), Number: h.Number.Int64(), Hash: h.Hash(), ParentHash: h.ParentHash, Parent: lastHead, EVMChainID: utils.NewBig(c.chainId)}
head = &evmtypes.Head{Difficulty: h.Difficulty, Timestamp: time.Unix(int64(h.Time), 0), Number: h.Number.Int64(), Hash: h.Hash(), ParentHash: h.ParentHash, Parent: lastHead, EVMChainID: ubig.New(c.chainId)}
lastHead = head
}
select {
Expand Down
16 changes: 8 additions & 8 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ import (
commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

func TestChainScopedConfig(t *testing.T) {
t.Parallel()
gcfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
id := utils.NewBig(big.NewInt(rand.Int63()))
id := ubig.New(big.NewInt(rand.Int63()))
c.EVM[0] = &toml.EVMConfig{
ChainID: id,
Chain: toml.Defaults(id, &toml.Chain{
Expand All @@ -38,7 +38,7 @@ func TestChainScopedConfig(t *testing.T) {
cfg := evmtest.NewChainScopedConfig(t, gcfg)

overrides := func(c *chainlink.Config, s *chainlink.Secrets) {
id := utils.NewBig(big.NewInt(rand.Int63()))
id := ubig.New(big.NewInt(rand.Int63()))
c.EVM[0] = &toml.EVMConfig{
ChainID: id,
Chain: toml.Defaults(id, &toml.Chain{
Expand All @@ -65,7 +65,7 @@ func TestChainScopedConfig(t *testing.T) {
t.Run("uses customer configured value when set", func(t *testing.T) {
var override uint32 = 10
gasBumpOverrides := func(c *chainlink.Config, s *chainlink.Secrets) {
id := utils.NewBig(big.NewInt(rand.Int63()))
id := ubig.New(big.NewInt(rand.Int63()))
c.EVM[0] = &toml.EVMConfig{
ChainID: id,
Chain: toml.Defaults(id, &toml.Chain{
Expand Down Expand Up @@ -292,7 +292,7 @@ func TestChainScopedConfig_GasEstimator(t *testing.T) {
func TestChainScopedConfig_BSCDefaults(t *testing.T) {
chainID := big.NewInt(56)
gcfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, secrets *chainlink.Secrets) {
id := utils.NewBig(chainID)
id := ubig.New(chainID)
cfg := toml.Defaults(id)
c.EVM[0] = &toml.EVMConfig{
ChainID: id,
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestChainScopedConfig_Profiles(t *testing.T) {
t.Parallel()

gcfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, secrets *chainlink.Secrets) {
id := utils.NewBigI(tt.chainID)
id := ubig.NewI(tt.chainID)
cfg := toml.Defaults(id)
c.EVM[0] = &toml.EVMConfig{
ChainID: id,
Expand Down Expand Up @@ -379,7 +379,7 @@ func TestChainScopedConfig_HeadTracker(t *testing.T) {
func Test_chainScopedConfig_Validate(t *testing.T) {
configWithChains := func(t *testing.T, id int64, chains ...*toml.Chain) config.AppConfig {
return configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
chainID := utils.NewBigI(id)
chainID := ubig.NewI(id)
c.EVM[0] = &toml.EVMConfig{ChainID: chainID, Enabled: ptr(true), Chain: toml.Defaults(chainID, chains...),
Nodes: toml.EVMNodes{{
Name: ptr("fake"),
Expand Down Expand Up @@ -462,7 +462,7 @@ func Test_chainScopedConfig_Validate(t *testing.T) {

func TestNodePoolConfig(t *testing.T) {
gcfg := configtest.NewGeneralConfig(t, func(c *chainlink.Config, s *chainlink.Secrets) {
id := utils.NewBig(big.NewInt(rand.Int63()))
id := ubig.New(big.NewInt(rand.Int63()))
c.EVM[0] = &toml.EVMConfig{
ChainID: id,
Chain: toml.Defaults(id, &toml.Chain{}),
Expand Down
8 changes: 4 additions & 4 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"
configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config"
)

Expand Down Expand Up @@ -161,7 +161,7 @@ func (cs EVMConfigs) NodeStatus(name string) (commontypes.NodeStatus, error) {
return commontypes.NodeStatus{}, fmt.Errorf("node %s: %w", name, chains.ErrNotFound)
}

func legacyNode(n *Node, chainID *utils.Big) (v2 types.Node) {
func legacyNode(n *Node, chainID *big.Big) (v2 types.Node) {
v2.Name = *n.Name
v2.EVMChainID = *chainID
if n.HTTPURL != nil {
Expand Down Expand Up @@ -215,7 +215,7 @@ func (cs EVMConfigs) Nodes(chainID relay.ChainID) (ns []types.Node, err error) {
continue
}

ns = append(ns, legacyNode(n, utils.NewBigI(evmID)))
ns = append(ns, legacyNode(n, big.NewI(evmID)))
}
return
}
Expand Down Expand Up @@ -268,7 +268,7 @@ func (ns *EVMNodes) SetFrom(fs *EVMNodes) {
}

type EVMConfig struct {
ChainID *utils.Big
ChainID *big.Big
Enabled *bool
Chain
Nodes EVMNodes
Expand Down
Loading

0 comments on commit a8d096c

Please sign in to comment.