linera-protocol
linera-protocol copied to clipboard
Update the crowdfunding example to allow any user to cancel (when permitted)
Per README file:
Currently, only the owner of the campaign can create blocks that contain the `Cancel`
operation. In the future, campaign chains will not be single-owner chains and should
instead allow contributors (users with a pledge) to cancel the campaign if
appropriate (even without the owner's cooperation).
So the campaign chain would be configured with open_multi_leader_rounds: true, and the crowd-funding application as mandatory. That means that, in multi-leader rounds, the system accepts proposals from anyone, not only chain owners, but that it won't accept proposals that don't contain an operation or message belonging to the mandatory application. This configuration currently has to be done on the CLI. (When https://github.com/linera-io/linera-protocol/issues/2371 is done, it can be done by the app itself.)
The crowd-funding application would then be changed so that it panics (→ fails the block) if the authenticated signer isn't the campaign creator and the campaign hasn't timed out yet according to the block's timestamp. (Maybe it should also be possible to cancel your own pledge before the timeout. The application could allow that, too.)
If the campaign has timed out, the app would only panic if there is no pledge by the authenticated signer. I.e. anyone who has pledged money can now propose a block. The app would now automatically either finish and close the campaign, or, if it is not fully funded, cancel it and refund all the pledges.
Defense against faulty participants
One caveat is that multi-leader rounds can be skipped, and a malicious participant (or the campaign creator) could make multiple conflicting proposals in the highest multi-leader round to prevent others from closing the campaign.
As a defense against that, the app could internally implement a round-robin with time slots assigned to the different participants, or proof of work. The assert_before and validation_round oracles provide apps with the tools to do that, i.e. define precisely who is allowed to make a proposal, in which round, and at what time.