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 dependencies on services package in common #11321

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions common/txmgr/types/forwarder_manager.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package types

import (
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/services"
)

//go:generate mockery --quiet --name ForwarderManager --output ./mocks/ --case=underscore
type ForwarderManager[ADDR types.Hashable] interface {
services.ServiceCtx
services.Service
ForwarderFor(addr ADDR) (forwarder ADDR, err error)
// Converts payload to be forwarder-friendly
ConvertPayload(dest ADDR, origPayload []byte) ([]byte, error)
Expand Down
6 changes: 3 additions & 3 deletions common/txmgr/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/pkg/errors"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
clnull "github.com/smartcontractkit/chainlink/v2/core/null"
"github.com/smartcontractkit/chainlink/v2/core/services/pg/datatypes"
)

// TxStrategy controls how txes are queued and sent
Expand Down Expand Up @@ -210,7 +210,7 @@ type Tx[
// Marshalled TxMeta
// Used for additional context around transactions which you want to log
// at send time.
Meta *datatypes.JSON
Meta *sqlutil.JSON
Subject uuid.NullUUID
ChainID CHAIN_ID

Expand All @@ -219,7 +219,7 @@ type Tx[

// TransmitChecker defines the check that should be performed before a transaction is submitted on
// chain.
TransmitChecker *datatypes.JSON
TransmitChecker *sqlutil.JSON

// Marks tx requiring callback
SignalCallback bool
Expand Down
4 changes: 2 additions & 2 deletions common/txmgr/types/tx_attempt_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package types
import (
"context"

"github.com/smartcontractkit/chainlink-common/pkg/services"
feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services"
)

// TxAttemptBuilder takes the base unsigned transaction + optional parameters (tx type, gas parameters)
Expand All @@ -23,7 +23,7 @@ type TxAttemptBuilder[
FEE feetypes.Fee, // FEE - chain fee type
] interface {
// interfaces for running the underlying estimator
services.ServiceCtx
services.Service
types.HeadTrackable[HEAD, BLOCK_HASH]

// NewTxAttempt builds a transaction using the configured transaction type and fee estimator (new estimation)
Expand Down
3 changes: 0 additions & 3 deletions common/txmgr/types/tx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

feetypes "github.com/smartcontractkit/chainlink/v2/common/fee/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
)

// TxStore is a superset of all the needed persistence layer methods
Expand Down Expand Up @@ -118,8 +117,6 @@ type ReceiptPlus[R any] struct {
FailOnRevert bool `db:"fail_on_revert"`
}

type QueryerFunc = func(tx pg.Queryer) error

type ChainReceipt[TX_HASH, BLOCK_HASH types.Hashable] interface {
GetStatus() uint64
GetTxHash() TX_HASH
Expand Down
6 changes: 3 additions & 3 deletions common/types/head_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package types
import (
"context"

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

// HeadTracker holds and stores the block experienced by a particular node in a thread safe manner.
// Reconstitutes the last block number on reboot.
//
//go:generate mockery --quiet --name HeadTracker --output ../mocks/ --case=underscore
type HeadTracker[H Head[BLOCK_HASH], BLOCK_HASH Hashable] interface {
services.ServiceCtx
services.Service
// Backfill given a head will fill in any missing heads up to the given depth
// (used for testing)
Backfill(ctx context.Context, headWithChain H, depth uint) (err error)
Expand Down Expand Up @@ -68,7 +68,7 @@ type NewHeadHandler[H Head[BLOCK_HASH], BLOCK_HASH Hashable] func(ctx context.Co
//
//go:generate mockery --quiet --name HeadBroadcaster --output ../mocks/ --case=underscore
type HeadBroadcaster[H Head[BLOCK_HASH], BLOCK_HASH Hashable] interface {
services.ServiceCtx
services.Service
BroadcastNewLongestChain(H)
HeadBroadcasterRegistry[H, BLOCK_HASH]
}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.uber.org/zap/zapcore"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
commonclient "github.com/smartcontractkit/chainlink/v2/common/client"
txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
Expand All @@ -43,7 +44,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
ksmocks "github.com/smartcontractkit/chainlink/v2/core/services/keystore/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/pg/datatypes"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down Expand Up @@ -255,7 +255,7 @@ func TestEthBroadcaster_ProcessUnstartedEthTxs_Success(t *testing.T) {
tr := int32(99)
b, err := json.Marshal(txmgr.TxMeta{JobID: &tr})
require.NoError(t, err)
meta := datatypes.JSON(b)
meta := sqlutil.JSON(b)
earlierEthTx := txmgr.Tx{
FromAddress: fromAddress,
ToAddress: toAddress,
Expand Down
7 changes: 3 additions & 4 deletions core/chains/evm/txmgr/evm_tx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
pkgerrors "github.com/pkg/errors"
nullv4 "gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink/v2/common/txmgr"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/null"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pg/datatypes"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down Expand Up @@ -171,14 +171,14 @@ type DbEthTx struct {
// Marshalled EvmTxMeta
// Used for additional context around transactions which you want to log
// at send time.
Meta *datatypes.JSON
Meta *sqlutil.JSON
Subject uuid.NullUUID
PipelineTaskRunID uuid.NullUUID
MinConfirmations null.Uint32
EVMChainID utils.Big
// TransmitChecker defines the check that should be performed before a transaction is submitted on
// chain.
TransmitChecker *datatypes.JSON
TransmitChecker *sqlutil.JSON
InitialBroadcastAt *time.Time
// Marks tx requiring callback
SignalCallback bool
Expand Down Expand Up @@ -1451,7 +1451,6 @@ func (o *evmTxStore) UpdateTxFatalError(ctx context.Context, etx *Tx) error {
}

// Updates eth attempt from in_progress to broadcast. Also updates the eth tx to unconfirmed.
// One of the more complicated signatures. We have to accept variable pg.QOpt and QueryerFunc arguments
func (o *evmTxStore) UpdateTxAttemptInProgressToBroadcast(ctx context.Context, etx *Tx, attempt TxAttempt, NewAttemptState txmgrtypes.TxAttemptState) error {
var cancel context.CancelFunc
ctx, cancel = o.mergeContexts(ctx)
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/txmgr/transmitchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
Expand All @@ -29,7 +30,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/services/pg/datatypes"
)

func TestFactory(t *testing.T) {
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestTransmitCheckers(t *testing.T) {

b, err := json.Marshal(meta)
require.NoError(t, err)
metaJson := datatypes.JSON(b)
metaJson := sqlutil.JSON(b)

tx := txmgr.Tx{
FromAddress: common.HexToAddress("0xfe0629509E6CB8dfa7a99214ae58Ceb465d5b5A9"),
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestTransmitCheckers(t *testing.T) {

b, err := json.Marshal(meta)
require.NoError(t, err)
metaJson := datatypes.JSON(b)
metaJson := sqlutil.JSON(b)

tx := txmgr.Tx{
FromAddress: common.HexToAddress("0xfe0629509E6CB8dfa7a99214ae58Ceb465d5b5A9"),
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ require (
github.com/shirou/gopsutil/v3 v3.23.9 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e // indirect
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231121180428-d7f28e91ccc3 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231117191236-12eab01a4542 // indirect
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231117191230-aa6640f2edd1 // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231117204155-b253a2f56664 // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1464,8 +1464,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.0-alpha.0.0.20231120164534-d4cab696c459 h1:hJhuShYv9eUQxHJQdOmyEymVmApOrICrQdOY7kKQ5Io=
github.com/smartcontractkit/chainlink-automation v1.0.0-alpha.0.0.20231120164534-d4cab696c459/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e h1:Fsx5IJDD14wdCAe2lEI1xgztIvzjiE2iVHvYzg/grew=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e/go.mod h1:Hrru9i7n+WEYyW2aIt3/YGPhxLX+HEGWnhk3yVXeDF8=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231121180428-d7f28e91ccc3 h1:cyA1aW1PYrOLZAMaSmuH7U99QBTfrF59s+6uDxQgOr0=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231121180428-d7f28e91ccc3/go.mod h1:Hrru9i7n+WEYyW2aIt3/YGPhxLX+HEGWnhk3yVXeDF8=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231117191236-12eab01a4542 h1:oewYJtdRkJKUHCNDCj5C2LQe6Oq6qy975g931nfG0cc=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231117191236-12eab01a4542/go.mod h1:EpvRoycRD+kniYlz+pCpRT5e+fmPm0mSD/vmND+0oMg=
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231117191230-aa6640f2edd1 h1:D7yb4kgNGVAiD5lFYqm/LW8d5jU66TXyYvSskDiW9yg=
Expand Down
10 changes: 5 additions & 5 deletions core/services/keystore/keys/ethkey/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ethkey
import (
"time"

"github.com/smartcontractkit/chainlink/v2/core/services/pg/datatypes"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
)

// NOTE: This model refers to the OLD key and is only used for migrations
Expand All @@ -15,10 +15,10 @@ import (
type Key struct {
ID int32
Address EIP55Address
JSON datatypes.JSON `json:"-"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt *time.Time `json:"-"`
JSON sqlutil.JSON `json:"-"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
DeletedAt *time.Time `json:"-"`
// IsFunding marks the address as being used for rescuing the node and the pending transactions
// Only one key can be IsFunding=true at a time.
IsFunding bool
Expand Down
56 changes: 3 additions & 53 deletions core/services/pg/datatypes/json.go
Original file line number Diff line number Diff line change
@@ -1,59 +1,9 @@
package datatypes

import (
"database/sql/driver"
"encoding/json"
"errors"
"fmt"
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
)

// JSON defined JSON data type, need to implements driver.Valuer, sql.Scanner interface
type JSON json.RawMessage

// Value return json value, implement driver.Valuer interface
func (j JSON) Value() (driver.Value, error) {
if len(j) == 0 {
return nil, nil
}
bytes, err := json.RawMessage(j).MarshalJSON()
return string(bytes), err
}

// Scan scan value into Jsonb, implements sql.Scanner interface
func (j *JSON) Scan(value interface{}) error {
if value == nil {
*j = JSON("null")
return nil
}
var bytes []byte
switch v := value.(type) {
case []byte:
bytes = v
case string:
bytes = []byte(v)
default:
return errors.New(fmt.Sprint("Failed to unmarshal JSONB value:", value))
}

result := json.RawMessage{}
err := json.Unmarshal(bytes, &result)
*j = JSON(result)
return err
}

// MarshalJSON to output non base64 encoded []byte
func (j JSON) MarshalJSON() ([]byte, error) {
return json.RawMessage(j).MarshalJSON()
}

// UnmarshalJSON to deserialize []byte
func (j *JSON) UnmarshalJSON(b []byte) error {
result := json.RawMessage{}
err := result.UnmarshalJSON(b)
*j = JSON(result)
return err
}

func (j JSON) String() string {
return string(j)
}
// Deprecated: Use sqlutil.JSON instead
type JSON = sqlutil.JSON
Loading
Loading