Autonomous Triggers system in SC #3168
Replies: 7 comments 15 replies
-
This would be a killer feature :) |
Beta Was this translation helpful? Give feedback.
-
another interesting model of async communication would be the go channels. I think it would be even more powerful (like, making a sc block until some event is received in the channel, etc). |
Beta Was this translation helpful? Give feedback.
-
I dont think we need the publisher contract to explicitly publish / be aware that other contracts are subscribing, in which case this will be much more powerful :) |
Beta Was this translation helpful? Give feedback.
-
Here is my take on it: Sub
Calling this registers a listener that will be called when The callback function takes To de-register, call: PubTo publish a message on a channel of the current address (top of call stack):
Special channelsThere are some implicit channel names:
Execution sequenceWe should move autonomous smart contract execution at the end of a slot, instead of the beginning. TODO: define the exact execution sequence TODO: how to order execution with respect to the current autonomous SCs ? should they be changed and merged into this general behavior ? TODO: how are the listeners limited/prioritized/dropped, when/how are the fees paid ? |
Beta Was this translation helpful? Give feedback.
-
Questions: |
Beta Was this translation helpful? Give feedback.
-
This is super cool! |
Beta Was this translation helpful? Give feedback.
-
First implementation : #3228 |
Beta Was this translation helpful? Give feedback.
-
Problem
Currently, in the smart contract system you can use
send_message
to send a message that we will be executed at a given slot.If you want to execute message with others trigger conditions than a slot you can't.
There is a workaround that exist which consist of sending message each slot and checking the condition each slot but cost an insane amount of gas to just check the condition even if the data we changed didn't even changed.
Solution
We can design a publish/subscribe system where you can subscribe to a channel and when an SC publish on this channel you will be triggered.
Technical design
Three methods should be added in the SC interface:
track_addr
is the address from which SC we accept the trigger to avoid having someone read the SC, find the channel and spam it. Could be potentially an option if you don't want to add this protection. To be discuss.track_channel
is an identifier to identify the channel you are subscribed tocall_addr
is the address that you want to trigger whenever you receive a triggercall_func
is the function you want to trigger whenever you receive a triggerfee
is the number of coins you can pay for gas and for block producer and message publishermax_gas
is the maximum amount of gas we allow for the executiontrack_channel
is an identifier to identify the channel you are subscribed tochannel_name
: is an identifier to identify the channel you want to send the message todata
: is an arbitrary data that will be passed to the function calledSpecial channels
There are some implicit channel names:
"_datastore" listens to all changes on the datastore of an address, and sends the list of changed datastore entry keys to the callback function as data.
"_balance" listens to changes in balance of the address, and sends the new balance as data
pub cannot be called on those channel names.
What should be the prototype of the function triggered ?
data
will be filled by thedata
passed by thepublish
methodCoins implications
This functionality should be costly but we need to figure out who will pay and how much ?
Publisher side
Publisher should pay gas for sending the trigger but it should be a constant cost (not dependent of the number of subscribers).
He will get money for the service he provide from the fees of subscribers.
Subscriber side
Each time he receive a message on the channel he need to pay for the gas and a fee for the publisher and block producer.
Notes
The subscriber pay to the publisher so that we can have services on the blockchain that can self-sustain if they are efficient enough. Otherwise the publisher just lose money each time he send and then it limit the use-cases
The subscriber can run out of money in this case the function isn't executed and the publisher don't have the fee from this subscriber.
Spamming limitation
As sending and executing on receiving cost gas and fee for block producer then it's costly to use this system and so it's limited by your money.
Future
In the future we could have a more powerful system with built-in triggers on differents triggers. For example you can directly register to a change in the storage or a balance of someone.
We could also have a query language to have multiple conditions from these built-ins.
Currents problems (updated with answers) :
Beta Was this translation helpful? Give feedback.
All reactions