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

[BCI-1435] Improve EVM Client Readability #9662

Merged
merged 12 commits into from
Jun 21, 2023
5 changes: 2 additions & 3 deletions common/headtracker/head_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"

htrktypes "github.com/smartcontractkit/chainlink/v2/common/headtracker/types"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/utils"
Expand All @@ -30,7 +29,7 @@ var (
type HeadListener[
HTH htrktypes.Head[BLOCK_HASH, ID],
S types.Subscription,
ID txmgrtypes.ID,
ID types.ID,
BLOCK_HASH types.Hashable,
] struct {
config htrktypes.Config
Expand All @@ -46,7 +45,7 @@ type HeadListener[
func NewHeadListener[
HTH htrktypes.Head[BLOCK_HASH, ID],
S types.Subscription,
ID txmgrtypes.ID,
ID types.ID,
BLOCK_HASH types.Hashable,
CLIENT htrktypes.Client[HTH, S, ID, BLOCK_HASH],
](
Expand Down
29 changes: 14 additions & 15 deletions common/headtracker/head_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
"golang.org/x/exp/maps"

htrktypes "github.com/smartcontractkit/chainlink/v2/common/headtracker/types"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
commontypes "github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/config"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/utils"
Expand All @@ -37,13 +36,13 @@ const HeadsBufferSize = 10

type HeadTracker[
HTH htrktypes.Head[BLOCK_HASH, ID],
S commontypes.Subscription,
ID txmgrtypes.ID,
BLOCK_HASH commontypes.Hashable,
S types.Subscription,
ID types.ID,
BLOCK_HASH types.Hashable,
] struct {
log logger.Logger
headBroadcaster commontypes.HeadBroadcaster[HTH, BLOCK_HASH]
headSaver commontypes.HeadSaver[HTH, BLOCK_HASH]
headBroadcaster types.HeadBroadcaster[HTH, BLOCK_HASH]
headSaver types.HeadSaver[HTH, BLOCK_HASH]
mailMon *utils.MailboxMonitor
client htrktypes.Client[HTH, S, ID, BLOCK_HASH]
chainID ID
Expand All @@ -52,7 +51,7 @@ type HeadTracker[

backfillMB *utils.Mailbox[HTH]
broadcastMB *utils.Mailbox[HTH]
headListener commontypes.HeadListener[HTH, BLOCK_HASH]
headListener types.HeadListener[HTH, BLOCK_HASH]
chStop utils.StopChan
wgDone sync.WaitGroup
utils.StartStopOnce
Expand All @@ -62,19 +61,19 @@ type HeadTracker[
// NewHeadTracker instantiates a new HeadTracker using HeadSaver to persist new block numbers.
func NewHeadTracker[
HTH htrktypes.Head[BLOCK_HASH, ID],
S commontypes.Subscription,
ID txmgrtypes.ID,
BLOCK_HASH commontypes.Hashable,
S types.Subscription,
ID types.ID,
BLOCK_HASH types.Hashable,
](
lggr logger.Logger,
client htrktypes.Client[HTH, S, ID, BLOCK_HASH],
config htrktypes.Config,
htConfig htrktypes.HeadTrackerConfig,
headBroadcaster commontypes.HeadBroadcaster[HTH, BLOCK_HASH],
headSaver commontypes.HeadSaver[HTH, BLOCK_HASH],
headBroadcaster types.HeadBroadcaster[HTH, BLOCK_HASH],
headSaver types.HeadSaver[HTH, BLOCK_HASH],
mailMon *utils.MailboxMonitor,
getNilHead func() HTH,
) commontypes.HeadTracker[HTH, BLOCK_HASH] {
) types.HeadTracker[HTH, BLOCK_HASH] {
chStop := make(chan struct{})
lggr = lggr.Named("HeadTracker")
return &HeadTracker[HTH, S, ID, BLOCK_HASH]{
Expand Down Expand Up @@ -305,7 +304,7 @@ func (ht *HeadTracker[HTH, S, ID, BLOCK_HASH]) backfillLoop() {
}

// backfill fetches all missing heads up until the base height
func (ht *HeadTracker[HTH, S, ID, BLOCK_HASH]) backfill(ctx context.Context, head commontypes.Head[BLOCK_HASH], baseHeight int64) (err error) {
func (ht *HeadTracker[HTH, S, ID, BLOCK_HASH]) backfill(ctx context.Context, head types.Head[BLOCK_HASH], baseHeight int64) (err error) {
headBlockNumber := head.BlockNumber()
if headBlockNumber <= baseHeight {
return nil
Expand Down
5 changes: 2 additions & 3 deletions common/headtracker/types/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"context"
"math/big"

txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
commontypes "github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
)

type Client[H commontypes.Head[BLOCK_HASH], S commontypes.Subscription, ID txmgrtypes.ID, BLOCK_HASH commontypes.Hashable] interface {
type Client[H types.Head[BLOCK_HASH], S types.Subscription, ID types.ID, BLOCK_HASH types.Hashable] interface {
HeadByNumber(ctx context.Context, number *big.Int) (head H, err error)
// ConfiguredChainID returns the chain ID that the node is configured to connect to
ConfiguredChainID() (id ID)
Expand Down
3 changes: 1 addition & 2 deletions common/headtracker/types/head.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package types

import (
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
)

//go:generate mockery --quiet --name Head --output ./mocks/ --case=underscore
type Head[BLOCK_HASH types.Hashable, CHAIN_ID txmgrtypes.ID] interface {
type Head[BLOCK_HASH types.Hashable, CHAIN_ID types.ID] interface {
types.Head[BLOCK_HASH]
// ChainID returns the chain ID that the head is for
ChainID() CHAIN_ID
Expand Down
5 changes: 2 additions & 3 deletions common/headtracker/types/mocks/head.go

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

18 changes: 9 additions & 9 deletions common/txmgr/broadcaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ type ProcessUnstartedTxs[ADDR types.Hashable] func(ctx context.Context, fromAddr

// TransmitCheckerFactory creates a transmit checker based on a spec.
type TransmitCheckerFactory[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID types.ID,
ADDR types.Hashable,
TX_HASH, BLOCK_HASH types.Hashable,
SEQ txmgrtypes.Sequence,
SEQ types.Sequence,
FEE feetypes.Fee,
] interface {
// BuildChecker builds a new TransmitChecker based on the given spec.
Expand All @@ -69,10 +69,10 @@ type TransmitCheckerFactory[

// TransmitChecker determines whether a transaction should be submitted on-chain.
type TransmitChecker[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID types.ID,
ADDR types.Hashable,
TX_HASH, BLOCK_HASH types.Hashable,
SEQ txmgrtypes.Sequence,
SEQ types.Sequence,
FEE feetypes.Fee,
] interface {

Expand All @@ -97,12 +97,12 @@ type TransmitChecker[
// - transition of eth_txes out of unstarted into either fatal_error or unconfirmed
// - existence of a saved eth_tx_attempt
type Broadcaster[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID types.ID,
HEAD types.Head[BLOCK_HASH],
ADDR types.Hashable,
TX_HASH types.Hashable,
BLOCK_HASH types.Hashable,
SEQ txmgrtypes.Sequence,
SEQ types.Sequence,
FEE feetypes.Fee,
] struct {
logger logger.Logger
Expand Down Expand Up @@ -146,12 +146,12 @@ type Broadcaster[
}

func NewBroadcaster[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID types.ID,
HEAD types.Head[BLOCK_HASH],
ADDR types.Hashable,
TX_HASH types.Hashable,
BLOCK_HASH types.Hashable,
SEQ txmgrtypes.Sequence,
SEQ types.Sequence,
FEE feetypes.Fee,
](
txStore txmgrtypes.TransactionStore[ADDR, CHAIN_ID, TX_HASH, BLOCK_HASH, SEQ, FEE],
Expand Down Expand Up @@ -767,7 +767,7 @@ func (eb *Broadcaster[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE]) incr
return eb.ks.IncrementNextSequence(address, eb.chainID, currentSequence, qopts...)
}

func observeTimeUntilBroadcast[CHAIN_ID txmgrtypes.ID](chainID CHAIN_ID, createdAt, broadcastAt time.Time) {
func observeTimeUntilBroadcast[CHAIN_ID types.ID](chainID CHAIN_ID, createdAt, broadcastAt time.Time) {
duration := float64(broadcastAt.Sub(createdAt))
promTimeUntilBroadcast.WithLabelValues(chainID.String()).Observe(duration)
}
16 changes: 8 additions & 8 deletions common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ var (
// Step 3: See if any transactions have exceeded the gas bumping block threshold and, if so, bump them
// Step 4: Check confirmed transactions to make sure they are still in the longest chain (reorg protection)
type Confirmer[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID commontypes.ID,
HEAD commontypes.Head[BLOCK_HASH],
ADDR commontypes.Hashable,
TX_HASH commontypes.Hashable,
BLOCK_HASH commontypes.Hashable,
R txmgrtypes.ChainReceipt[TX_HASH, BLOCK_HASH],
SEQ txmgrtypes.Sequence,
SEQ commontypes.Sequence,
FEE feetypes.Fee,
] struct {
utils.StartStopOnce
Expand Down Expand Up @@ -140,13 +140,13 @@ type Confirmer[
}

func NewConfirmer[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID commontypes.ID,
HEAD commontypes.Head[BLOCK_HASH],
ADDR commontypes.Hashable,
TX_HASH commontypes.Hashable,
BLOCK_HASH commontypes.Hashable,
R txmgrtypes.ChainReceipt[TX_HASH, BLOCK_HASH],
SEQ txmgrtypes.Sequence,
SEQ commontypes.Sequence,
FEE feetypes.Fee,
](
txStore txmgrtypes.TxStore[ADDR, CHAIN_ID, TX_HASH, BLOCK_HASH, R, SEQ, FEE],
Expand Down Expand Up @@ -953,10 +953,10 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Ens
}

func hasReceiptInLongestChain[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID commontypes.ID,
ADDR commontypes.Hashable,
TX_HASH, BLOCK_HASH commontypes.Hashable,
SEQ txmgrtypes.Sequence,
SEQ commontypes.Sequence,
FEE feetypes.Fee,
](etx txmgrtypes.Tx[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], head commontypes.Head[BLOCK_HASH]) bool {
for {
Expand Down Expand Up @@ -1109,11 +1109,11 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) Res
// observeUntilTxConfirmed observes the promBlocksUntilTxConfirmed metric for each confirmed
// transaction.
func observeUntilTxConfirmed[
CHAIN_ID txmgrtypes.ID,
CHAIN_ID commontypes.ID,
ADDR commontypes.Hashable,
TX_HASH, BLOCK_HASH commontypes.Hashable,
R txmgrtypes.ChainReceipt[TX_HASH, BLOCK_HASH],
SEQ txmgrtypes.Sequence,
SEQ commontypes.Sequence,
FEE feetypes.Fee,
](chainID CHAIN_ID, attempts []txmgrtypes.TxAttempt[CHAIN_ID, ADDR, TX_HASH, BLOCK_HASH, SEQ, FEE], receipts []R) {
for _, attempt := range attempts {
Expand Down
33 changes: 16 additions & 17 deletions common/txmgr/mocks/tx_manager.go

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

5 changes: 3 additions & 2 deletions common/txmgr/reaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
"time"

txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/common/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

// Reaper handles periodic database cleanup for Txm
type Reaper[CHAIN_ID txmgrtypes.ID] struct {
type Reaper[CHAIN_ID types.ID] struct {
store txmgrtypes.TxHistoryReaper[CHAIN_ID]
config txmgrtypes.ReaperChainConfig
txConfig txmgrtypes.ReaperTransactionsConfig
Expand All @@ -24,7 +25,7 @@ type Reaper[CHAIN_ID txmgrtypes.ID] struct {
}

// NewReaper instantiates a new reaper object
func NewReaper[CHAIN_ID txmgrtypes.ID](lggr logger.Logger, store txmgrtypes.TxHistoryReaper[CHAIN_ID], config txmgrtypes.ReaperChainConfig, txConfig txmgrtypes.ReaperTransactionsConfig, chainID CHAIN_ID) *Reaper[CHAIN_ID] {
func NewReaper[CHAIN_ID types.ID](lggr logger.Logger, store txmgrtypes.TxHistoryReaper[CHAIN_ID], config txmgrtypes.ReaperChainConfig, txConfig txmgrtypes.ReaperTransactionsConfig, chainID CHAIN_ID) *Reaper[CHAIN_ID] {
r := &Reaper[CHAIN_ID]{
store,
config,
Expand Down
Loading