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

Version abstraction #151

Merged
merged 15 commits into from
Sep 28, 2023
Merged

Version abstraction #151

merged 15 commits into from
Sep 28, 2023

Conversation

connorwstein
Copy link
Collaborator

@connorwstein connorwstein commented Sep 21, 2023

Motivation

  • Permit breaking ABI changes without plugin modifications
  • Step towards non-EVM support
  • Improve clarity of plugins

Solution

  • Abstract gethwrappers/logpoller/ethclient behind XXReader's which are version specific and make use of gethwrappers/ethclient/logpoller to satisfy an interface for the plugin's needs
  • Start with just extracting OnRampReader/USDCReader from Reader as that is required for 1.2 backwards compat

@@ -29,9 +28,8 @@ const (
ExecutionStateFailure
)

// TODO: Deprecate in favour of version specific types
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Intention is all geth/log poller code will live in ccipdata under a reader so specific versions can be supported (not just latest version)


func jobSpecToCommitPluginConfig(lggr logger.Logger, jb job.Job, pr pipeline.Runner, chainSet evm.LegacyChainContainer) (*CommitPluginConfig, *BackfillArgs, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just to share code with the UnregisterFilter call in DeleteJob. Intention is to rename as Close(...) and just close each reader instead (which internally will unregister filters)

@@ -172,16 +177,6 @@ func CommitReportToEthTxMeta(report []byte) (*txmgr.TxMeta, error) {
}, nil
}

func getCommitPluginSourceLpFilters(onRamp common.Address) []logpoller.Filter {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The commit plugin's CCIPSend events are tied to a specific onramp address version - so this is now handled in the OnRampReader

return err
}
return unregisterCommitPluginFilters(ctx, sourceChain.LogPoller(), destChain.LogPoller(), commitStore, common.HexToAddress(pluginConfig.OffRamp), qopts...)
// TODO: once offramp/commit are abstracted, we can call Close on the offramp/commit readers to unregister filters.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will follow up with abstracting the rest of these

checkFinalityTags bool
lggr logger.Logger
// Source
onRampReader ccipdata.OnRampReader
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

notice how the source log poller is now completely abstracted in the commit plugin (can't quite abstract it yet in exec since source price reg is not yet abstracted)

@@ -1475,13 +1476,3 @@ func GetBalance(t *testing.T, chain bind.ContractBackend, tokenAddr common.Addre
require.NoError(t, err)
return bal
}

func GenerateCCIPSendLog(t *testing.T, message evm_2_evm_onramp.InternalEVM2EVMMessage) types.Log {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unused

@@ -18,7 +17,5 @@ var (
type Reader interface {
// ReadTokenData returns the attestation bytes if ready, and throws an error if not ready.
ReadTokenData(ctx context.Context, msg internal.EVM2EVMOnRampCCIPSendRequestedWithMeta) (tokenData []byte, err error)

// GetSourceLogPollerFilters returns the filters that should be used for the source chain log poller
GetSourceLogPollerFilters() []logpoller.Filter
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ccipdata.USDCReader is now logpoller owner

@@ -37,20 +34,6 @@ const (
attestationStatusPending attestationStatus = "pending_confirmations"
)

// usdcPayload has to match the onchain event emitted by the USDC message transmitter
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

log details pushed down to USDCReader

if err != nil {
return []byte{}, err
}

parsedMsgBody, err := decodeUSDCMessageSent(usdcMessageBody)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GetLastUSDCMessage handles parsing now

require.NoError(t, err)
// Message is the bytes itself from MessageSend(bytes message)
// i.e. ABI parsed.
message := "0x0000000000000001000000020000000000048d71000000000000000000000000eb08f243e5d3fcff26a9e38ae5520a669f4019d000000000000000000000000023a04d5935ed8bc8e3eb78db3541f0abfb001c6e0000000000000000000000006cb3ed9b441eb674b58495c8b3324b59faff5243000000000000000000000000000000005425890298aed601595a70ab815c96711a31bc65000000000000000000000000ab4f961939bfe6a93567cc57c59eed7084ce2131000000000000000000000000000000000000000000000000000000000000271000000000000000000000000035e08285cfed1ef159236728f843286c55fc0861"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

making this a true black box test just canned input/output

@connorwstein connorwstein marked this pull request as ready for review September 26, 2023 14:00
@connorwstein connorwstein requested a review from a team as a code owner September 26, 2023 14:00
leafHasher hashlib.LeafHasherInterface[[32]byte]
checkFinalityTags bool
lggr logger.Logger
// Source
Copy link
Contributor

Choose a reason for hiding this comment

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

Having the source/dest dependencies grouped by a comment like this could be improved.
Sometimes it's a bit confusing to just see plugin.onRamp plugin.offRamp, you won't know where this contract exists unless you are familiar with the whole ccip architecture or read the comment (which might also end up being incorrect) in the commitPluginConfig.

I would suggest something like this.


type CommitPluginConfig {
   source SourceChainDeps
   dest DestChainDeps
}

type SourceChainDeps struct {
   onRampReader ccipdata.OnRampReader
}

type DestChainDeps struct {
   offRampReader ccipdata.OffRampReader
}

func (plugin) Whatever() {
   plugin.sourceChain.onRampReader.GetWhatever()
   plugin.destChain.offRampReader.GetWhatever()
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

seem like a marginal improvement but would prefer to come back to it after all the versioning abstraction is done

@@ -302,9 +184,11 @@ func parseLogs[T any](logs []logpoller.Log, lggr logger.Logger, parseFunc func(l
if err == nil {
reqs = append(reqs, Event[T]{
Data: *data,
BlockMeta: BlockMeta{
Meta: Meta{
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are also moving towards supporting non-evm:

// now
type Meta struct {
	BlockTimestamp time.Time
	BlockNumber    int64
	TxHash         common.Hash
	LogIndex       uint
}

// should be something like this since logIndex is evm-specific
type Meta struct {
	BlockTimestamp time.Time
	BlockNumber    int64
	TxHash         common.Hash
        EvmMeta *EvmMeta
}

type EvmMeta struct {
	LogIndex       uint
}

// or like this...
type Meta struct {
        ChainType string
	BlockTimestamp time.Time
	BlockNumber    int64
	TxHash         common.Hash
        Meta json.RawMessage
}

// and unmarshal Meta according to the ChainType

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah still way far out though. Can address that when we get there I'd say out of scope atm

Hash [32]byte
// TODO: add more fields as we abstract exec plugin
// also this Log can eventually go away with destchain abstractions
Log types.Log // Raw event data
Copy link
Contributor

Choose a reason for hiding this comment

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

just a note: Log (types.Log) is also evm specific

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm aware 😄

GetSendRequestsBetweenSeqNums(ctx context.Context, seqNumMin, seqNumMax uint64, confs int) ([]Event[EVM2EVMMessage], error)

// Get router configured in the onRamp
Router() common.Address
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest renaming this method to RouterAddress() because without reading the method signature I would expect that onramp.Router() returns a router instance that I can use to call Router specific methods.

}
}

func latestFinalizedBlockHash(ctx context.Context, client client.Client) (common.Hash, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function could be moved under some library package (would be nice to have some unit tests also).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not worth it as we intend to remove it entirely shortly smartcontractkit/chainlink#10762

}

func (o *OnRampV1_0_0) GetSendRequestsGteSeqNum(ctx context.Context, seqNum uint64, confs int) ([]Event[EVM2EVMMessage], error) {
if !o.finalityTags {
Copy link
Contributor

Choose a reason for hiding this comment

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

That's the duplicate code I mentioned in the slack thread.
This code is identical for OnRampV1_0_0 and OnRampV1_2_0.

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to think of some way to reduce this

Copy link
Collaborator Author

@connorwstein connorwstein Sep 27, 2023

Choose a reason for hiding this comment

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

seems ok to me

case "1.2.0":
return NewOnRampV1_2_0(lggr, sourceSelector, destSelector, onRampAddress, sourceLP, source, finalityTags)
default:
return nil, errors.Errorf("expected version 1.0.0 got %v", version.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe just invalid version %v, we aren't strictly expecting a specific version.

@connorwstein connorwstein merged commit 77ce9d0 into ccip-develop Sep 28, 2023
44 checks passed
@connorwstein connorwstein deleted the feature/backwards-compat-1.2 branch September 28, 2023 13:00
asoliman92 pushed a commit that referenced this pull request Jul 31, 2024
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.

3 participants