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

Add automation types and services #297

Merged
merged 6 commits into from
Jan 18, 2024
Merged

Add automation types and services #297

merged 6 commits into from
Jan 18, 2024

Conversation

ferglor
Copy link
Collaborator

@ferglor ferglor commented Dec 20, 2023

The bulk of this PR is a cut/paste of the v3/types package in chainlink-automation

We're also moving the MercuryCredentials type from core, into the RelayArgs

Aside from that, I've added some new functions to the AutomationProvider that will expose services needed for automation in core

Associated PRs

chainlink: smartcontractkit/chainlink#11631
chainlink-automation: smartcontractkit/chainlink-automation#299

@ferglor ferglor force-pushed the feature/AUTO-7266-services branch from 39e5668 to 3d88f4c Compare December 20, 2023 15:47
@ferglor ferglor force-pushed the feature/AUTO-7266-services branch from 3d88f4c to 933a690 Compare January 8, 2024 13:47
@ferglor ferglor marked this pull request as ready for review January 8, 2024 16:11
Comment on lines +33 to +35
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, " ", "", -1)
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\t", "", -1)
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\n", "", -1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ReplaceAll is available:

Suggested change
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, " ", "", -1)
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\t", "", -1)
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\n", "", -1)
checkResultStringTemplate = strings.ReplaceAll(checkResultStringTemplate, " ", "")
checkResultStringTemplate = strings.ReplaceAll(checkResultStringTemplate, "\t", "")
checkResultStringTemplate = strings.ReplaceAll(checkResultStringTemplate, "\n", "")

Although this seems odd. Is the point to keep it in human readable form in source?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh and there is a Replacer:

Suggested change
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, " ", "", -1)
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\t", "", -1)
checkResultStringTemplate = strings.Replace(checkResultStringTemplate, "\n", "", -1)
checkResultStringTemplate = strings.NewReplacer(" ", "", "\t", "", "").Replace(checkResultStringTemplate)

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 so the init implementation is just to collapse the more readable source string into a single line; my understanding here is that using a JSON encoder was deemed to be too expensive at the time, and using a string template was cheaper/faster. I didn't want to modify any of the code lifted out of automation in this PR; I wanted to keep everything as it was written in the automation repo to keep the impacts of these changes to a minimum

// upgrade plan before changing this
type LogTriggerExtension struct {
// LogTxHash is the transaction hash of the log event
TxHash [32]byte
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see a lot of [32]byte hash types. Is that something we will have to relax later on for other chains? like to a slice []byte?

How are these values actually used? The approach taken with accounts is to just use a string, which for EVM happens to be the encoded hex format, but then never try to parse those values - only compare them directly. It would be nice to be able to make a similar kind of simplification here.

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 TxHash is used to build a log identifier for a log event; I think we use the block hash as well and a few other fields maybe? I think we also hex encode this field for a string representation as well!

Copy link

@infiloop2 infiloop2 Jan 22, 2024

Choose a reason for hiding this comment

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

Having these as concrete [32]bytes gives us a lot of safety as these values are sent within observations and outcomes in OCR, and having a tight control on the size reduces surface area for potential security issues + gives us better control over how many upkeeps we can include in an observation/outcome.

We haven't run into chains where this has been an issue yet, but if we generalise this to byte slice then will need to do a proper review of any downstream implications.

Comment on lines 28 to 32
Name() string
Start(_ context.Context) error
Close() error
Ready() error
HealthReport() map[string]error
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use services.Service for this common set.

Suggested change
Name() string
Start(_ context.Context) error
Close() error
Ready() error
HealthReport() map[string]error
services.Service

You might want/need to upgrade anything with Start/Close to services.Service also, since that suggests they have background processes/state that could be monitored.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Otherwise there is services.StartClose:

type StartClose interface {
	Start(context.Context) error
	Close() error
}

Add service functions to BlockSubscriber and LogEventProvider

Add a makefile with a generate task

Generate mocks for automation types
type UpkeepStateStore interface {
UpkeepStateUpdater
UpkeepStateReader
Start(context.Context) error
Copy link

Choose a reason for hiding this comment

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

We can avoid Start() and Close() functions for all interfaces, as they are not really part of the interfaces (at least not the logical interface) and are only called from within the repo with the implementations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So the list of automation services in core is now a []job.ServiceCtx, and the AutomationProvider exposes the upkeep state store as this interface type, which is why this was implemented

@ferglor ferglor merged commit 4864e23 into main Jan 18, 2024
7 of 8 checks passed
@ferglor ferglor deleted the feature/AUTO-7266-services branch January 18, 2024 01:23
ettec pushed a commit that referenced this pull request Mar 28, 2024
* Move automation types into common
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.

5 participants