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

Introduce a chain agnostic Head interface in the core Transaction Manager #8674

Merged
merged 66 commits into from
Mar 17, 2023

Conversation

prashantkumar1982
Copy link
Contributor

@prashantkumar1982 prashantkumar1982 commented Mar 10, 2023

The core Txm shouldn't be importing evmtypes.Head.
Instead it will use a generic Head interface that all chains can provide.

Ticket: smartcontract-it.atlassian.net/browse/BCI-854

PS: This PR was opened after initially trying the following one, which due to use of generics, was far more complicated: #8597

core/chains/evm/evm_txm.go Outdated Show resolved Hide resolved
type evmTxm struct {
httypes.HeadTrackable
GenericTxManager
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where are the comments on lines 18 thru 21?

Comment on lines 26 to 28
func (e evmTxm) OnNewLongestChain(ctx context.Context, head *evmtypes.Head) {
e.TxManager.OnNewLongestChain(ctx, head)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure why this is necessary but I believe you that it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here. I don't know why it doesn't work without this, but if I remove this function, I see these errors:

FAIL github.com/smartcontractkit/chainlink/core/chains/evm [build failed]

github.com/smartcontractkit/chainlink/core/chains/evm [github.com/smartcontractkit/chainlink/core/chains/evm/client.test]

./evm_txm.go:16:31: cannot use &evmTxm{} (value of type *evmTxm) as "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable value in variable declaration: *evmTxm does not implement "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable (missing method OnNewLongestChain)
./chain.go:120:28: cannot use txm (variable of type *evmTxm) as "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable value in argument to headBroadcaster.Subscribe: *evmTxm does not implement "github.com/smartcontractkit/chainlink/core/chains/evm/headtracker/types".HeadTrackable (missing method OnNewLongestChain)

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, weird. Could it have been a pointer issue? I'm surprised to see the receiver here is not a pointer.

Copy link
Contributor Author

@prashantkumar1982 prashantkumar1982 Mar 17, 2023

Choose a reason for hiding this comment

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

I didn't understand your question.

evmTxm implements both interfaces:

  • httypes.HeadTrackable. (requires OnLongestChain(..., *evmtypes.Head))
  • txmgr.TxManager (requires OnLongestChain(..., txmgrtypes.Head))

I earlier assumed that in evmTxm, just letting the OnLongestChain method inheriting from TxManager would work, but it doesn't. I have to create above function to pass-through.

Copy link
Collaborator

Choose a reason for hiding this comment

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

From my understanding of go, this shouldn't be necessary. Can we figure out why it's here?

Copy link
Contributor

Choose a reason for hiding this comment

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

This method is not necessary. This is because the type assertion is generic instead of specifying [*evmtypes.Head].

Copy link
Contributor

Choose a reason for hiding this comment

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

Er, the concrete type with the same name is not connected to the generic one. This should be removable if they are derived from one another.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, this whole type is not necessary: #8744

core/chains/evm/gas/block_history_estimator.go Outdated Show resolved Hide resolved
@@ -159,7 +159,7 @@ func (ht *headTracker) Backfill(ctx context.Context, headWithChain *evmtypes.Hea
baseHeight = 0
}

return ht.backfill(ctx, headWithChain.EarliestInChain(), baseHeight)
return ht.backfill(ctx, headWithChain.EarliestInChain().(*evmtypes.Head), baseHeight)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we going to end up with typecasts everywhere like this now that head is more generic? That seems like a step backwards

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was due to the fact that EarliestInChain() was already used by evm native code, and also needed for generic Txmgr, so i merged them to a single interface method, that returns interface Head, instead of native head.

Changed it now.
The interface method is different from native method, so avoids having to use different types.

aalu1418
aalu1418 previously approved these changes Mar 17, 2023

// evmTxm is an evm wrapper over the generic TxManager interface
type evmTxm struct {
httypes.HeadTrackable
Copy link
Contributor

Choose a reason for hiding this comment

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

is this redundant? TxManager already requires txmgrtypes.HeadTrackable[*evmtypes.Head]

Copy link
Contributor

@jmank88 jmank88 Mar 17, 2023

Choose a reason for hiding this comment

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

Yes, the whole evmTxm type is actually not neccesssary: #8744

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot Jordan!

jmank88
jmank88 previously approved these changes Mar 17, 2023
jmank88
jmank88 previously approved these changes Mar 17, 2023
@cl-sonarqube-production
Copy link

SonarQube Quality Gate

Quality Gate failed

Failed condition 60.0% 60.0% Coverage on New Code (is less than 90%)

See analysis details on SonarQube

@prashantkumar1982 prashantkumar1982 merged commit 22d682f into develop Mar 17, 2023
@prashantkumar1982 prashantkumar1982 deleted the head_generic branch March 17, 2023 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants