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

exec plugin: Introduce a State Machine #63

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

winder
Copy link
Contributor

@winder winder commented Aug 13, 2024

What

Introduce a state machine to manage execution across multiple rounds of OCR.

Why

To help manage complexity when a 3rd round of OCR is required.

@winder winder marked this pull request as ready for review August 13, 2024 17:50
@winder winder requested review from makramkd, dimkouv, 0xnogo, a team and rstout August 13, 2024 17:50
@makramkd
Copy link
Collaborator

Can we have a diagram with the states and the state transitions?

@winder
Copy link
Contributor Author

winder commented Aug 13, 2024

Can we have a diagram with the states and the state transitions?

In this PR

flowchart TD
    UNKNOWN[Initial State]
    A[Get Commit Reports] 
    B[Get Report Messages]
    C[Filter]
    UNKNOWN --> A
    A -->|no report| B
    B -->|report + restart| A
Loading

In the next PR

flowchart TD
    UNKNOWN[Initial State]
    A[Get Commit Reports] 
    B[Get Report Messages]
    C[Filter]
    UNKNOWN --> A
    A -->|no report| B
    B -->|no report| C
    C -->|report + restart| A
Loading

// TODO: go to Filter after GetMessages
return GetCommitReports

case Unknown:
Copy link
Contributor

Choose a reason for hiding this comment

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

// Unknown is the default value indicating there was no previous state.

If there was no previous state, should it start getting new messages? Are we going to start the plugin state with Unknown? If we expect to start with it, why fallthrough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically, I chose to do it this way so that an uninitialized previous outcome (i.e. the first round after startup) can transition to the "Next" state with no special handling. So you can get to the first state from Unknown or Filter (or GetMessages in this PR, since I haven't implemented Filter yet).

@makramkd
Copy link
Collaborator

@winder you can include those mermaid diagrams in a README.md file, it should render natively on GitHub IIRC.

Comment on lines 16 to 17
GetMessages
Filter
Copy link
Collaborator

Choose a reason for hiding this comment

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

First state is self explanatory but these might need some comments, especially Filter

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or maybe call it FilterValidMessages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comments 👍

@@ -7,8 +7,40 @@ import (
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
)

type PluginState int
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if it would be useful to have a MarshalJSON on this so that the outcomes that are JSON encoded are still easily understandable (due to a human-readable string rather than a number). I think similar logic applies to the commit states

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. I would personally prefer if these had a more efficient encoding rather than attempting to make them human readable.

In this case the states would be 1->2->3, so still pretty human readable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I may be unlike others when it comes to this but even just 1, 2 and 3 is already a cognitive jump because I have to continuously remind myself what each number means.

Having debugged the v2 plugins quite a bit I'd rather we optimize for debuggability to start and then come back and make encoding tighter if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Changed this type to a string.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also worth noting that we have states for commit as well, with their own integers, and states in many other systems which have their own integers, etc. Having all of this in mind I feel like the actual string encoding is just better and it doesn't really have that much overhead to outcome encoding size

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The phases could also be named "ReadDest", "ReadSource" and "ReadDestAgain"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Less descriptive I feel, I kinda like the current names better, but not sure what other folks think. @asoliman92?

@winder
Copy link
Contributor Author

winder commented Aug 14, 2024

@winder you can include those mermaid diagrams in a README.md file, it should render natively on GitHub IIRC.

@makramkd Good idea. I'll create a plugin-level README with this diagram and other information in a separate PR.

Copy link

Test Coverage

Branch Coverage
will/6-exec-state-machine 76.2%
ccip-develop 77.3%

},
{
name: "panic",
p: PluginState("ElToroLoco"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤠

@winder winder requested a review from asoliman92 August 14, 2024 14:51
@winder winder merged commit 8c54f7e into ccip-develop Aug 14, 2024
3 checks passed
@winder winder deleted the will/6-exec-state-machine branch August 14, 2024 15: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.

3 participants