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

Implement the new trigger and generic task node structure #35

Merged
merged 23 commits into from
Nov 20, 2024

Conversation

v9n
Copy link
Member

@v9n v9n commented Nov 11, 2024

Implement change to our task trigger/node https://docs.google.com/document/d/1DM0VJ0hUnC4FIWAbNSKAaLfQ3U7EI3GRd0DcQvUA8B8/edit?pli=1&tab=t.0#heading=h.oi6mw4tp84nj

This PR mainly handles 2 things:

  • Define the new trigger with time/block/event/manual
  • Add the new edges field to maintain relationship between nodes
  • Remove next from nodes. Edges handles it now.

Will update https://github.com/AvaProtocol/ava-sdk-js/pulls next to conform to the new protobuf and add new method.

An example task.

n example get '01JCK4XF8YRKAAM00KS96HD4JM'
Inspect Task ID:  01JCK4XF8YRKAAM00KS96HD4JM

edges:                    [
  {
    "id": "edge-123abcdef",
    "start": "transfer_erc20_1",
    "end": ""
  }
]
executions:               []
id:                       {
  "bytes": "01JCK4XF8YRKAAM00KS96HD4JM"
}
owner:                    "0xe272b72E51a5bF8cB720fc6D6DF164a4D5E321C5"
smart_wallet_address:     "0xdD85693fd14b522a819CC669D6bA388B4FCd158d"
trigger:                  {
  "trigger_type": "BlockTrigger",
  "block": {
    "interval": "5"
  },
  "trigger_condition": "block"
}
start_at:                 "1731514544"
expired_at:               "1734106514"
memo:                     "Demo Example task for 0xe272b72E51a5bF8cB720fc6D6DF164a4D5E321C5"
completed_at:             "0"
status:                   "Active"
recurring:                false
node_type:                "ETHTransferTask"
id:                       "get_oracle_price"
branch:                   {
  "elseIfs": [],
  "if": {
    "expression": "bigCmp(priceChainlink(\"0x694AA1769357215DE4FAC081bf1f309aDC325306\"),toBigInt(\"10000\") > 0",
    "next": "transfer_erc20_1"
  },
  "else": null
}
task_body:                "branch"
node_type:                "ETHTransferTask"
id:                       "transfer_erc20_1"
name:                     "Transfer Test Token"
contract_write:           {
  "contract_address": "0x2e8bdb63d09ef989a0018eeb1c47ef84e3e61f7b",
  "call_data": "0xa9059cbb000000000000000000000000e0f7d11fd714674722d325cd86062a5f1882e13a000000000000000000000000000000000000000000000000a688906bd8b00000",
  "contract_abi": ""
}
task_body:                "contract_write"

another example with fixed schedule

Inspect Task ID:  01JCJJ6RMMJTN5XYQTG347HYQZ

edges:                    [
  {
    "id": "edge-123abcdef",
    "start": "transfer_erc20_1",
    "end": ""
  }
]
executions:               []
id:                       {
  "bytes": "01JCJJ6RMMJTN5XYQTG347HYQZ"
}
owner:                    "0xe272b72E51a5bF8cB720fc6D6DF164a4D5E321C5"
smart_wallet_address:     "0xdD85693fd14b522a819CC669D6bA388B4FCd158d"
trigger:                  {
  "trigger_type": "FixedEpochTrigger",
  "at": {
    "epoches": [
      "1731498496",
      "1731502096"
    ]
  },
  "trigger_condition": "at"
}
start_at:                 "1731494926"
expired_at:               "1734086896"
memo:                     "Demo Example task for 0xe272b72E51a5bF8cB720fc6D6DF164a4D5E321C5"
completed_at:             "0"
status:                   "Active"
recurring:                false
node_type:                "ETHTransferTask"
id:                       "get_oracle_price"
branch:                   {
  "elseIfs": [],
  "if": {
    "expression": "bigCmp(priceChainlink(\"0x694AA1769357215DE4FAC081bf1f309aDC325306\"),toBigInt(\"10000\") > 0",
    "next": "transfer_erc20_1"
  },
  "else": null
}
task_body:                "branch"
node_type:                "ETHTransferTask"
id:                       "transfer_erc20_1"
name:                     "Transfer Test Token"
contract_write:           {
  "contract_address": "0x2e8bdb63d09ef989a0018eeb1c47ef84e3e61f7b",
  "call_data": "0xa9059cbb000000000000000000000000e0f7d11fd714674722d325cd86062a5f1882e13a000000000000000000000000000000000000000000000000a688906bd8b00000",
  "contract_abi": ""
}
task_body:                "contract_write"

another one with cron:

Inspect Task ID:  01JCK500SEF8NWVNCPTAWHQK82

edges:                    [
  {
    "id": "edge-123abcdef",
    "start": "transfer_erc20_1",
    "end": ""
  }
]
executions:               []
id:                       {
  "bytes": "01JCK500SEF8NWVNCPTAWHQK82"
}
owner:                    "0xe272b72E51a5bF8cB720fc6D6DF164a4D5E321C5"
smart_wallet_address:     "0xdD85693fd14b522a819CC669D6bA388B4FCd158d"
trigger:                  {
  "trigger_type": "ManualTrigger",
  "cron": {
    "cron_table": [
      "0 */5 * * *"
    ]
  },
  "trigger_condition": "cron"
}
start_at:                 "1731514628"
expired_at:               "1734106598"
memo:                     "Demo Example task for 0xe272b72E51a5bF8cB720fc6D6DF164a4D5E321C5"
completed_at:             "0"
status:                   "Active"
recurring:                false
node_type:                "ETHTransferTask"
id:                       "get_oracle_price"
branch:                   {
  "elseIfs": [],
  "if": {
    "expression": "bigCmp(priceChainlink(\"0x694AA1769357215DE4FAC081bf1f309aDC325306\"),toBigInt(\"10000\") > 0",
    "next": "transfer_erc20_1"
  },
  "else": null
}
task_body:                "branch"
node_type:                "ETHTransferTask"
id:                       "transfer_erc20_1"
name:                     "Transfer Test Token"
contract_write:           {
  "contract_address": "0x2e8bdb63d09ef989a0018eeb1c47ef84e3e61f7b",
  "call_data": "0xa9059cbb000000000000000000000000e0f7d11fd714674722d325cd86062a5f1882e13a000000000000000000000000000000000000000000000000a688906bd8b00000",
  "contract_abi": ""
}
task_body:                "contract_write"

@v9n v9n marked this pull request as draft November 11, 2024 19:47
@v9n v9n mentioned this pull request Nov 11, 2024
@v9n v9n force-pushed the new-task-data-structure branch from 05ea0ba to 8ce3e99 Compare November 11, 2024 19:54
@v9n v9n marked this pull request as ready for review November 12, 2024 18:40
@v9n v9n changed the title New task data structure Implement the trigger and generic task actions to avoid null field Nov 12, 2024
@v9n v9n changed the title Implement the trigger and generic task actions to avoid null field Implement the new trigger and generic task node structure Nov 12, 2024
@v9n v9n marked this pull request as draft November 12, 2024 18:42
@v9n v9n requested a review from chrisli30 November 13, 2024 10:06
@v9n v9n marked this pull request as ready for review November 13, 2024 10:06
@v9n v9n force-pushed the new-task-data-structure branch from 04c8478 to 460df3c Compare November 14, 2024 00:46
Copy link

socket-security bot commented Nov 14, 2024

New dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None 0 65.2 kB morninded

View full report↗︎

Copy link
Member

@chrisli30 chrisli30 left a comment

Choose a reason for hiding this comment

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

Added my comments to the current design.

}

message TaskNode {
TaskType node_type = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Match the variable name node_type with the type name TaskType. In my opinion we can simplify the names with the followings:

message TaskNode -> message Node
TaskType -> NodeType, and make it NodeType type = 1

Copy link
Member Author

Choose a reason for hiding this comment

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

Match the variable name node_type with the type name TaskType
Yes, will change to task_type

In my opinion we can simplify the names with the followings:
message TaskNode -> message Node
TaskType -> NodeType, and make it NodeType type = 1

I actually name it on purpose

  1. Node is too generic in our field. We have node in list, we have node in server. It's like calling something Item. Because of that, I want to avoid any confusion down the line, and explicitly calling it TaskNode. it's also more grep-able if we have to search code.
  2. type I want to avoid the case when we access it like this something.type just want to avoid someone accidently think this maybe the type of the object/class. And also same with searchable. .node_type

let me know if you still think in redundant, i can change.

Copy link
Member

Choose a reason for hiding this comment

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

okay, naming them compresive works. It’s just a naming convension.

Also, I was asking about TaskType node_type = 1;, that maybe we should calle it TaskType task_type = 1; for consistency?

string name = 3;

// based on node_type one and only one of these field are set
oneof task_body {
Copy link
Member

Choose a reason for hiding this comment

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

The TaskType already defines these categories, and the task_body values seem redundant, but let me get a screenshot from the Studio for furthur clarification.

Copy link
Member

Choose a reason for hiding this comment

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

This is a screenshot of the current Node types in Studio. As you can see I’m grouping them by functions.
CleanShot 2024-11-13 at 23 07 53@2x

Copy link
Member Author

Choose a reason for hiding this comment

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

The TaskType already defines these categories, and the task_body values seem redundant,

task_body is relevant to protobuf so it can decode the object becasue we're using oneof here
This is one-off https://protobuf.dev/programming-guides/proto3/#oneof

oneof take the value of field name by default so I was trying to be more user fiendly and having the extra node_type.

Let me just merge them into one so it won't have this dup.

protobuf/avs.proto Show resolved Hide resolved
model/task.go Outdated
Task: &avsproto.Task{
Id: &avsproto.UUID{
Bytes: taskID,
},
Copy link
Member

Choose a reason for hiding this comment

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

Isn’t id just a ulid string? I think we should just have id: string
instead of return a nested structure id: { bytes: '01JCKCRTZBS158BRP8E42P2DQW' }. This nested format doesn’t provide any real benefit to the user and only complicates retrieving the string representation of the ID.

Copy link
Member

Choose a reason for hiding this comment

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

Besides, I am using the ulid on the frontend, and find the upper cases are a little hard to read, should we return the id in lower case?

Comparison:
uppercases:
{ id: '01JCM1TGR85E59ZYEG5Q7WHKZ6' }

lowercases:
{ id: '01jcm1tgr85e59zyeg5q7whkz6' }

Copy link
Member Author

Choose a reason for hiding this comment

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

Isn’t id just a ulid string? I think we should just have id: string

uuid/ulid is actually a byte array. string is a way to re-present it in human readable form, aka canonical form.

I used []byte before (thus the name) but it's not easy to enter []byte in the gRPC UI thus I resorted to using string so ppl can type it out

Let me update to direct string instead.

Besides, I am using the ulid on the frontend, and find the upper cases are a little hard to read, should we return the id in lower case?

You can display uppercase/lowecase on the front-end. doesn't matter. the alphabet doesn't have lowecase. server side will convert it eventually.

Copy link
Member

@chrisli30 chrisli30 Nov 14, 2024

Choose a reason for hiding this comment

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

okay, let’s keep the upper case for the id, so we don’t care about conversion on the server side.

yeah, bytes have to be converted to string for transmission, so I think we should remove the bytes property key, to achieve { id: '01JCM1TGR85E59ZYEG5Q7WHKZ6' }


// repeatable means a task can continue to run even after the first execution.
// By default, recurring is false, task will only executed once.
bool recurring = 10;
Copy link
Member

Choose a reason for hiding this comment

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

If it’s a boolean varialbe, I suggest that we name it is_recurring, instead of recurring. At least in javascript that norm is with a prefix is.

Copy link
Member Author

Choose a reason for hiding this comment

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

will change

Copy link
Member

Choose a reason for hiding this comment

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

okay, we have made a decison about this last year. Checking out the automation hub, I think the below set up makes more sense.
CleanShot 2024-11-14 at 09 31 34@2x

maxExeCount: number
0 - good till cancel, equals to is_recurring
1, 2, 3, .... - the actual execution count

The reason being that with is_recurring: bool we couldn’t limit the number of execution needed for a reccuring job.

Slack workflow called it Frequency:
CleanShot 2024-11-14 at 09 34 54@2x

CleanShot 2024-11-14 at 09 35 09@2x

protobuf/avs.proto Show resolved Hide resolved
@v9n
Copy link
Member Author

v9n commented Nov 20, 2024

@chrisli30 Ready to review

Copy link
Member

@chrisli30 chrisli30 left a comment

Choose a reason for hiding this comment

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

Cood looks good. I like the encapsulation of Conditions in the examples/static_codegen/avs_pb.js

@v9n v9n merged commit dc02014 into main Nov 20, 2024
4 checks passed
@v9n v9n deleted the new-task-data-structure branch November 20, 2024 23:47
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.

2 participants