MIMD 0011 Ephemeral Crank #479
Dodecahedr0x
started this conversation in
MIMD
Replies: 1 comment 1 reply
-
@Dodecahedr0x I have been thinking about the requirements from the consumer developer perspective and I need few things:
Extra considerations: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Ephemeral Crank
Abstract
Developers need to implement custom cranking solutions for executing transactions periodically or conditionally. This requires external infrastructure and increases complexity for developers building on MagicBlock.
This proposal introduces a task scheduling system that enables developers to schedule arbitrary transactions for execution by the validator at specific intervals or when certain conditions are met. The target properties of this system are:
The proposed solution introduces a set of instructions in the MagicBlock program that write tasks to a dedicated task context account. A dedicated task scheduling service then takes tasks from the context and maintains them in a local database.
Proposed Design
Sequence overview
Below are the sequence diagrams of the different interactions between system components.
Task scheduler initialization
Upon initialization, the scheduler retrieves the task context from the bank and creates any tasks it does not already have in its database. It also retrieves an account subscription for the task context from the
geyser_rpc_service
to detect any changes in the context, indicating that an instruction has created or cancelled a task.Scheduling tasks
Scheduling tasks can only occur through a program using CPI. This stores the definition of the task in the task context.
Cancel task
Similarly, the task authority defined during scheduling can call the Magic program to cancel the task. It removes it from the context so that the scheduler can detect it.
Updating scheduler DB
When the scheduler is notified that the task context has changed, it fetches the context account, reads the tasks, and updates its local DB accordingly: removes cancelled tasks and adds scheduled ones.
Executing scheduled tasks
The scheduler has its own tick period, during which it checks if any tasks in the database should now be executed. If so, it runs the tasks' instructions and updates the corresponding rows in the DB.
Data Structure
Solana Accounts
Data stored in accounts is written only once, to avoid serialization too frequently, which is expensive given the size of the account. The on-chain account is used to register requests that the task scheduling service will process. These requests provide the initial state of the task.
Scheduler Database
Tasks in the database are updated on every execution.
Configuration
The task scheduler can
pub struct TaskSchedulerConfig {
/// Path the SQLite db file
pub db_path: String,
/// Whether to reset the local scheduler database
pub reset_db: bool,
/// How frequently we check for executable tasks
pub millis_per_tick: u64,
}
Future evolutions
Scheduling costs
The proposal currently does not price the execution of tasks. This can lead to potential abuses.
In subsequent iterations of this proposal, users will need to provision a budget related to the compute unit used by their tasks.
Conditional executions
In the current proposal, the same transactions are executed periodically. This does not allow for more complex use cases, such as limit orders that execute once an account reaches a specific value, or game collision detection that writes to an account only if it matches certain conditions.
Considered Alternatives
Extending MagicContext
Using the existing MagicContext account to store tasks alongside scheduled commits. This approach was rejected because:
External Crank Services
Relying on external crank services (like Clockwork or TukTuk) to handle scheduled execution. This approach was rejected because:
Geyser Plugin Approach
Using a Geyser plugin to monitor on-chain state and trigger transactions. This approach was rejected because:
Beta Was this translation helpful? Give feedback.
All reactions