Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove remaining small core packages from evm #12381

Merged
merged 8 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package toml

import (
"errors"
"fmt"
"net/url"
"slices"
Expand All @@ -17,13 +18,14 @@ import (
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink/v2/common/config"
"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"
)

var ErrNotFound = errors.New("not found")

type HasEVMConfigs interface {
EVMConfigs() EVMConfigs
}
Expand Down Expand Up @@ -145,7 +147,7 @@ func (cs EVMConfigs) Node(name string) (types.Node, error) {
}
}
}
return types.Node{}, fmt.Errorf("node %s: %w", name, chains.ErrNotFound)
return types.Node{}, fmt.Errorf("node %s: %w", name, ErrNotFound)
}

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

func legacyNode(n *Node, chainID *big.Big) (v2 types.Node) {
Expand Down Expand Up @@ -205,7 +207,7 @@ func (cs EVMConfigs) Nodes(chainID string) (ns []types.Node, err error) {
}
nodes := cs.nodes(chainID)
if nodes == nil {
err = fmt.Errorf("no nodes: chain %q: %w", chainID, chains.ErrNotFound)
err = fmt.Errorf("no nodes: chain %q: %w", chainID, ErrNotFound)
return
}
for _, n := range nodes {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/gas/rollups/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (

"github.com/ethereum/go-ethereum/core/types"

"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/services"
)

// L1Oracle provides interface for fetching L1-specific fee components if the chain is an L2.
// For example, on Optimistic Rollups, this oracle can return rollup-specific l1BaseFee
//
//go:generate mockery --quiet --name L1Oracle --output ./mocks/ --case=underscore
type L1Oracle interface {
services.ServiceCtx
services.Service

GasPrice(ctx context.Context) (*assets.Wei, error)
GetGasCost(ctx context.Context, tx *types.Transaction, blockNum *big.Int) (*assets.Wei, error)
Expand Down
23 changes: 13 additions & 10 deletions core/chains/evm/log/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package log

import (
"context"
"database/sql"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems cleaner to me than implementing in common 🤷

"fmt"
"math/big"
"sync"
Expand All @@ -22,7 +23,6 @@ import (
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
evmutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated"
"github.com/smartcontractkit/chainlink/v2/core/null"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
)

Expand Down Expand Up @@ -69,7 +69,7 @@ type (

BroadcasterInTest interface {
Broadcaster
BackfillBlockNumber() null.Int64
BackfillBlockNumber() sql.NullInt64
TrackedAddressesCount() uint32
// Pause pauses the eventLoop until Resume is called.
Pause()
Expand Down Expand Up @@ -98,7 +98,7 @@ type (
evmChainID big.Int

// a block number to start backfill from
backfillBlockNumber null.Int64
backfillBlockNumber sql.NullInt64

ethSubscriber *ethSubscriber
registrations *registrations
Expand Down Expand Up @@ -327,7 +327,7 @@ func (b *broadcaster) startResubscribeLoop() {
if from < 0 {
from = 0
}
b.backfillBlockNumber = null.NewInt64(from, true)
b.backfillBlockNumber = sql.NullInt64{Int64: from, Valid: true}
}

// Remove leftover unconsumed logs, maybe update pending broadcasts, and backfill sooner if necessary.
Expand All @@ -337,7 +337,8 @@ func (b *broadcaster) startResubscribeLoop() {
// No need to worry about r.highestNumConfirmations here because it's
// already at minimum this deep due to the latest seen head check above
if !b.backfillBlockNumber.Valid || *backfillStart < b.backfillBlockNumber.Int64 {
b.backfillBlockNumber.SetValid(*backfillStart)
b.backfillBlockNumber.Int64 = *backfillStart
b.backfillBlockNumber.Valid = true
}
}

Expand Down Expand Up @@ -490,7 +491,8 @@ func (b *broadcaster) onReplayRequest(replayReq replayRequest) {
// NOTE: This ignores r.highestNumConfirmations, but it is
// generally assumed that this will only be performed rarely and
// manually by someone who knows what he is doing
b.backfillBlockNumber.SetValid(replayReq.fromBlock)
b.backfillBlockNumber.Int64 = replayReq.fromBlock
b.backfillBlockNumber.Valid = true
if replayReq.forceBroadcast {
ctx, cancel := b.chStop.NewCtx()
defer cancel()
Expand All @@ -515,7 +517,8 @@ func (b *broadcaster) invalidatePool() int64 {
b.logPool = newLogPool(b.logger)
// Note: even if we crash right now, PendingMinBlock is preserved in the database and we will backfill the same.
blockNum := int64(min.(Uint64))
b.backfillBlockNumber.SetValid(blockNum)
b.backfillBlockNumber.Int64 = blockNum
b.backfillBlockNumber.Valid = true
return blockNum
}
return -1
Expand Down Expand Up @@ -717,7 +720,7 @@ func (b *broadcaster) TrackedAddressesCount() uint32 {
}

// test only
func (b *broadcaster) BackfillBlockNumber() null.Int64 {
func (b *broadcaster) BackfillBlockNumber() sql.NullInt64 {
return b.backfillBlockNumber
}

Expand Down Expand Up @@ -766,8 +769,8 @@ func (n *NullBroadcaster) Register(listener Listener, opts ListenerOpts) (unsubs
// ReplayFromBlock implements the Broadcaster interface.
func (n *NullBroadcaster) ReplayFromBlock(number int64, forceBroadcast bool) {}

func (n *NullBroadcaster) BackfillBlockNumber() null.Int64 {
return null.NewInt64(0, false)
func (n *NullBroadcaster) BackfillBlockNumber() sql.NullInt64 {
return sql.NullInt64{Int64: 0, Valid: false}
}
func (n *NullBroadcaster) TrackedAddressesCount() uint32 {
return 0
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/log/eth_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package log

import (
"context"
"database/sql"
"fmt"
"math/big"
"time"
Expand All @@ -15,7 +16,6 @@ import (

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

type (
Expand All @@ -39,7 +39,7 @@ func newEthSubscriber(ethClient evmclient.Client, config Config, lggr logger.Log
// backfillLogs - fetches earlier logs either from a relatively recent block (latest minus BlockBackfillDepth) or from the given fromBlockOverride
// note that the whole operation has no timeout - it relies on BlockBackfillSkip (set outside) to optionally prevent very deep, long backfills
// Max runtime is: (10 sec + 1 min * numBlocks/batchSize) * 3 retries
func (sub *ethSubscriber) backfillLogs(fromBlockOverride null.Int64, addresses []common.Address, topics []common.Hash) (chBackfilledLogs chan types.Log, abort bool) {
func (sub *ethSubscriber) backfillLogs(fromBlockOverride sql.NullInt64, addresses []common.Address, topics []common.Hash) (chBackfilledLogs chan types.Log, abort bool) {
sub.logger.Infow("backfilling logs", "from", fromBlockOverride, "addresses", addresses)
if len(addresses) == 0 {
sub.logger.Debug("LogBroadcaster: No addresses to backfill for, returning")
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/types/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types

import (
"bytes"
"database/sql"
"database/sql/driver"
"encoding/json"
"fmt"
Expand All @@ -24,15 +25,14 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types/internal/blocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/null"
)

// Head represents a BlockNumber, BlockHash.
type Head struct {
ID uint64
Hash common.Hash
Number int64
L1BlockNumber null.Int64
L1BlockNumber sql.NullInt64
ParentHash common.Hash
Parent *Head
EVMChainID *ubig.Big
Expand Down Expand Up @@ -285,7 +285,7 @@ func (h *Head) UnmarshalJSON(bs []byte) error {
h.Timestamp = time.Unix(int64(jsonHead.Timestamp), 0).UTC()
h.BaseFeePerGas = assets.NewWei((*big.Int)(jsonHead.BaseFeePerGas))
if jsonHead.L1BlockNumber != nil {
h.L1BlockNumber = null.Int64From((*big.Int)(jsonHead.L1BlockNumber).Int64())
h.L1BlockNumber = sql.NullInt64{Int64: (*big.Int)(jsonHead.L1BlockNumber).Int64(), Valid: true}
}
h.ReceiptsRoot = jsonHead.ReceiptsRoot
h.TransactionsRoot = jsonHead.TransactionsRoot
Expand Down
5 changes: 3 additions & 2 deletions core/chains/evm/types/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package types_test

import (
"bytes"
"database/sql"
"encoding/json"
"fmt"
"math"
Expand All @@ -17,6 +18,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/hex"

"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand All @@ -25,7 +27,6 @@ import (
"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/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/null"
)

func TestHead_NewHead(t *testing.T) {
Expand Down Expand Up @@ -329,7 +330,7 @@ func TestHead_UnmarshalJSON(t *testing.T) {
Number: 0x15156,
ParentHash: common.HexToHash("0x923ad1e27c1d43cb2d2fb09e26d2502ca4b4914a2e0599161d279c6c06117d34"),
Timestamp: time.Unix(0x60d0952d, 0).UTC(),
L1BlockNumber: null.Int64From(0x8652f9),
L1BlockNumber: sql.NullInt64{Int64: 0x8652f9, Valid: true},
ReceiptsRoot: common.HexToHash("0x2c292672b8fc9d223647a2569e19721f0757c96a1421753a93e141f8e56cf504"),
TransactionsRoot: common.HexToHash("0x71448077f5ce420a8e24db62d4d58e8d8e6ad2c7e76318868e089d41f7e0faf3"),
StateRoot: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Expand Down
4 changes: 2 additions & 2 deletions core/services/ocrcommon/arbitrum_block_translator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ocrcommon_test

import (
"database/sql"
"math/big"
mrand "math/rand"
"testing"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/null"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -239,7 +239,7 @@ func generateDeterministicL2Blocks() (heads []evmtypes.Head) {
for i := 0; i <= l2max; i++ {
head := evmtypes.Head{
Number: int64(i),
L1BlockNumber: null.Int64From(l1BlockNumber),
L1BlockNumber: sql.NullInt64{Int64: l1BlockNumber, Valid: true},
Hash: utils.NewHash(),
ParentHash: parentHash,
}
Expand Down
Loading