-
Notifications
You must be signed in to change notification settings - Fork 42
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
Specify time or event for note consumption in network transaction #582
Comments
I think, more broadly, we need to define a mechanism (or maybe a few) of how the node should decide when to include some note into a transaction. At the high-level, we have the following "triggers":
The first 2 types of triggers can probably be encoded in the note metadata. The mechanism for the 3rd trigger still needs to be defined (e.g., a user may ping a node to indicate that the note is ready for execution - but this may lead to griefing attacks, and so this action should not be "free" for the user). |
Should we consider encoding such conditions in the note script itself rather than letting node to decide. Like |
The conditions would be encoded in the script. I think the main challenge is how the node can learn about these conditions without analyzing or executing the script. To give a concrete example: Let's say there is a note that can be consumed 1000 blocks from now. That is, if the node tries to execute the note's now, the execution will fail, but if the same note's script is executed after 1000 blocks, it will all work fine. Without knowing this condition the node has two options:
I feel like we'll need to do something like the option 2 above further down the road, but for now, I'm trying to figure out how we can minimize the number of cases where such sophisticated analysis would be needed. So, if we can tell the node (via note metadata) that the note's script is supposed to be executed in 1000 blocks, it would wait 1000 blocks and only then try to execute the script. |
The second option looks promising, but we should be prepared to deal with the false negatives (note can be executed, but analysis says it's not). |
I'm thinking we could add another field to the pub enum NoteExecutionHint {
/// Note execution hit is not specified.
None,
/// The note can be executed at any time.
Always,
/// The note can be executed after the specified block height.
AfterBlock { block_num: u32 },
/// The note can be executed in the specified slot within the specified epoch.
///
/// The slot is defined as follows:
/// - First we define the length of the epoch in powers of 2. For example, epoch_len = 10 is an epoch
/// of 1024 blocks.
/// - Then we define the length of a slot within the epoch also using powers of 2. For example,
/// slot_len = 7 is a slot of 128 blocks.
/// - Lastly, the offset specifies the index of the slot within the epoch - i.e., 0 is the first slot,
/// 1 is the second slot etc.
///
/// Putting this all together { epoch_len: 10, slot_len: 7, slot_offset: 1 } means that the note can
/// be executed in any second 128 block slot of a 1024 block epoch. These would be blocks 128..256,
/// 1152..1280, 2176..2304 etc.
OnBlockSlot { epoch_len: u8, slot_len: u8, slot_offset: u8 }
} The reasons why we may want to start with these set of variants:
In terms of encoding, we could use 36 bits to encode the enum as follows:
We can also reduce the overall size to just 32 bits by giving up some precision on block height for the |
Adding a new field to |
We can fit multiple logical elements into a single field element. For example, One thing to keep in mind though, we will need to increase the size of account ID and so the |
Yeah, for some reason I was thinking that |
Created #816 with the remaining changes to implement this. |
Feature description
As a user, I want to be able to specify certain conditions under which my note should be consumed. This is important for network transactions in which the operator picks notes for consumption and executes transactions.
For example, I want to specify that my note should be consumed at block height
1111
or only in odd blocks.One way to communicate the intent for future consumption is using note metadata. A dedicated
tag
forfuture network execution
could be created, and the user could define the rest via theaux_data
field. There might be other more sophisticated ways.However, the implementation also depends on the Node's mempool design. We should wait until #350 is finalized.
Why is this feature needed?
We need this feature as a building block for network transactions.
The text was updated successfully, but these errors were encountered: