Skip to content

Commit

Permalink
Removed dependencies on services package in common
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-momin committed Nov 20, 2023
1 parent c9312c6 commit d219cab
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 32 deletions.
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
5 changes: 2 additions & 3 deletions common/txmgr/types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"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 +209,7 @@ type Tx[
// Marshalled TxMeta
// Used for additional context around transactions which you want to log
// at send time.
Meta *datatypes.JSON
Meta *json.RawMessage
Subject uuid.NullUUID
ChainID CHAIN_ID

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

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

// 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
3 changes: 1 addition & 2 deletions core/chains/evm/txmgr/broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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 +254,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 := json.RawMessage(b)
earlierEthTx := txmgr.Tx{
FromAddress: fromAddress,
ToAddress: toAddress,
Expand Down
6 changes: 2 additions & 4 deletions core/chains/evm/txmgr/evm_tx_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 +170,14 @@ type DbEthTx struct {
// Marshalled EvmTxMeta
// Used for additional context around transactions which you want to log
// at send time.
Meta *datatypes.JSON
Meta *json.RawMessage
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 *json.RawMessage
InitialBroadcastAt *time.Time
// Marks tx requiring callback
SignalCallback bool
Expand Down Expand Up @@ -1449,7 +1448,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
5 changes: 2 additions & 3 deletions core/chains/evm/txmgr/transmitchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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 +191,7 @@ func TestTransmitCheckers(t *testing.T) {

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

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

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

tx := txmgr.Tx{
FromAddress: common.HexToAddress("0xfe0629509E6CB8dfa7a99214ae58Ceb465d5b5A9"),
Expand Down
10 changes: 5 additions & 5 deletions core/services/vrf/v2/integration_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/vrfkey"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pg/datatypes"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
evmrelay "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm"
"github.com/smartcontractkit/chainlink/v2/core/services/signatures/secp256k1"
Expand Down Expand Up @@ -2038,13 +2037,13 @@ func TestStartingCountsV1(t *testing.T) {
}
md1, err := json.Marshal(&m1)
require.NoError(t, err)
md1_ := datatypes.JSON(md1)
md1_ := json.RawMessage(md1)
reqID2 := utils.PadByteToHash(0x11)
m2 := txmgr.TxMeta{
RequestID: &reqID2,
}
md2, err := json.Marshal(&m2)
md2_ := datatypes.JSON(md2)
md2_ := json.RawMessage(md2)
require.NoError(t, err)
chainID := utils.NewBig(testutils.SimulatedChainID)
confirmedTxes := []txmgr.Tx{
Expand All @@ -2056,7 +2055,7 @@ func TestStartingCountsV1(t *testing.T) {
InitialBroadcastAt: &b,
CreatedAt: b,
State: txmgrcommon.TxConfirmed,
Meta: &datatypes.JSON{},
Meta: &json.RawMessage{},
EncodedPayload: []byte{},
ChainID: chainID.ToInt(),
},
Expand Down Expand Up @@ -2104,6 +2103,7 @@ func TestStartingCountsV1(t *testing.T) {
md, err2 := json.Marshal(&txmgr.TxMeta{
RequestID: &reqID3,
})
meta := json.RawMessage(md)
require.NoError(t, err2)
newNonce := evmtypes.Nonce(i + 1)
unconfirmedTxes = append(unconfirmedTxes, txmgr.Tx{
Expand All @@ -2114,7 +2114,7 @@ func TestStartingCountsV1(t *testing.T) {
State: txmgrcommon.TxUnconfirmed,
BroadcastAt: &b,
InitialBroadcastAt: &b,
Meta: (*datatypes.JSON)(&md),
Meta: &meta,
EncodedPayload: []byte{},
ChainID: chainID.ToInt(),
})
Expand Down
9 changes: 4 additions & 5 deletions core/services/vrf/v2/listener_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2plus_interface"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/pg/datatypes"
"github.com/smartcontractkit/chainlink/v2/core/services/vrf/vrfcommon"

txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr"
Expand Down Expand Up @@ -77,7 +76,7 @@ func addEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, from common.Address, s
RequestTxHash: &reqTxHash,
})
require.NoError(t, err)
meta := datatypes.JSON(b)
meta := json.RawMessage(b)
tx := &txmgr.Tx{
FromAddress: from,
ToAddress: from,
Expand All @@ -103,7 +102,7 @@ func addConfirmedEthTx(t *testing.T, txStore txmgr.TestEvmTxStore, from common.A
GlobalSubID: txMetaGlobalSubID,
})
require.NoError(t, err)
meta := datatypes.JSON(b)
meta := json.RawMessage(b)
now := time.Now()

tx := &txmgr.Tx{
Expand Down Expand Up @@ -135,7 +134,7 @@ func addEthTxNativePayment(t *testing.T, txStore txmgr.TestEvmTxStore, from comm
RequestTxHash: &reqTxHash,
})
require.NoError(t, err)
meta := datatypes.JSON(b)
meta := json.RawMessage(b)
tx := &txmgr.Tx{
FromAddress: from,
ToAddress: from,
Expand All @@ -161,7 +160,7 @@ func addConfirmedEthTxNativePayment(t *testing.T, txStore txmgr.TestEvmTxStore,
GlobalSubID: txMetaGlobalSubID,
})
require.NoError(t, err)
meta := datatypes.JSON(b)
meta := json.RawMessage(b)
now := time.Now()
tx := &txmgr.Tx{
Sequence: &nonce,
Expand Down

0 comments on commit d219cab

Please sign in to comment.