3.7 What do the different kinds of consensus transfers mean? publish, pay, race, fork, parallelReduce?
These consensus steps are what happen "on-chain" and are executed by a so-called "smart contract".
There are many ways to perform a consensus transfer in Reach and each is used for different reasons. The variety can feel a bit bewildering for new users, but here is an intuitive guide to help you decide which you need for any given situation.
If the entire DApp is waiting for a single participant to act, such as when at a play the entire theatre waits in anticipation for the stage hands to draw the curtains, then you either need a
If the single participant is sharing information, then you need a
but if they are only paying a previously known amount, then you need a
This kind of transfer always explicitly names the party acting, as in:
If the entire DApp has a clear "next step", but multiple participants are able to provide the values used in that step, then you need a
race to determine the participant used for a
For example, in a radio call-in contest, there is one chance for a listener to call-in first and win the prize.
If a participant value is participant class, then all of its actions are
races, because the Reach identifier does not represent a specific principal, but a member of a large class.
If the DApp doesn’t have a clear next step, but multiple participants each have a different option for what the next step should be, then you need a
For example, a sale DApp might have a buy option and a bid option where the first immediately ends the computation, while the second moves it to an auction.
fork is for when many participants want to each do a different thing.
If you are in a situation where a
fork is needed, and the options are available repeatedly after small diversions, then you need a
For example, in an auction, bidders repeatedly provide new bids as they compete to be the highest bidder before a time limit is reached.
How many participants can act? One or many?
How many things can be done? One or many?
How many times can this be done? Once or many?
The above article uses the word "need" when talking about
parallelReduce, but actually you never need these, because they are just abbreviations of particular patterns of using the other features.
forkworks by having each participant
raceto provide a
Datainstance, where the single consensus step does a case analysis on the
Datato determine which code to run. Similarly,
parallelReduceis just an abbreviation of a