package tezos-protocol-alpha
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=43723d096307603703a1a89ed1b2eb202b365f5e7824b96b0cbf813b343a6cf7
sha512=b2a637f2e965000d3d49ad85277ca24d6cb07a1a7cf2bc69d296d8b03ad78c3eaa8e21e94b9162e62c2e11649cd03bc845b2a3dafe623b91065df69d47dc8e4f
doc/tezos-protocol-alpha.raw/Tezos_raw_protocol_alpha/Sc_rollup_refutation_storage/index.html
Module Tezos_raw_protocol_alpha.Sc_rollup_refutation_storage
Source
val get_ongoing_games_for_staker :
Raw_context.t ->
Sc_rollup_repr.t ->
Sc_rollup_repr.Staker.t ->
((Sc_rollup_game_repr.t * Sc_rollup_game_repr.Index.t) list * Raw_context.t)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.t
get_ongoing_games_for_staker ctxt rollup staker
returns games
, the list of refutation games currently played by staker
in the rollup
.
type conflict = {
other : Sc_rollup_repr.Staker.t;
their_commitment : Sc_rollup_commitment_repr.t;
our_commitment : Sc_rollup_commitment_repr.t;
parent_commitment : Sc_rollup_commitment_repr.Hash.t;
}
A conflict between a staker and an other
staker. The conflict is about the commitment that follows the parent_commitment
: their_commitment
and our_commitment
are distinct, hence in conflict.
val conflicting_stakers_uncarbonated :
Raw_context.t ->
Sc_rollup_repr.t ->
Sc_rollup_repr.Staker.t ->
conflict list Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.t
conflicting_stakers_uncarbonated rollup staker
returns the list of conflicts with staker
in rollup
.
Notice that this operation can be expensive as it is proportional to the number of stakers multiplied by the number of commitments in the staked branches. Fortunately, this operation is only useful as an RPC for the rollup node to look for a new conflict to solve.
val start_game :
Raw_context.t ->
Sc_rollup_repr.t ->
player:
(Tezos_protocol_environment_alpha.Signature.public_key_hash
* Sc_rollup_commitment_repr.Hash.t) ->
opponent:
(Tezos_protocol_environment_alpha.Signature.public_key_hash
* Sc_rollup_commitment_repr.Hash.t) ->
Raw_context.t Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.t
start_game ctxt rollup ~player:(player, player_commitment_hash) ~opponent:(opponent, opponent_commitment_hash)
initiates a refutation game between player
and opponent
in the given rollup
as they are in conflict with commitment
and opponent_commitment
. Where commitment
is the commitment in the storage with hash player_commitment_hash
(resp. opponent_commitment
with opponent_commitment_hash
).
val game_move :
Raw_context.t ->
Sc_rollup_repr.t ->
player:Sc_rollup_repr.Staker.t ->
opponent:Sc_rollup_repr.Staker.t ->
step:Sc_rollup_game_repr.step ->
choice:Sc_rollup_tick_repr.t ->
(Sc_rollup_game_repr.game_result option * Raw_context.t)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.t
game_move ctxt rollup player opponent refutation
handles the storage-side logic for when one of the players makes a move in the game. It checks the game already exists. Then it checks that player
is the player whose turn it is; if so, it applies refutation
using the play
function.
If the result is a new game, this is stored and the timeout is updated.
May fail with:
Sc_rollup_does_not_exist
ifrollup
does not existSc_rollup_no_game
ifis_opening_move
isfalse
but the game does not existSc_rollup_game_already_started
ifis_opening_move
istrue
but the game already existsSc_rollup_no_conflict
ifplayer
is staked on an ancestor of the commitment staked on byopponent
, or vice versaSc_rollup_not_staked
if one of theplayer
oropponent
is not actually stakedSc_rollup_staker_in_game
if one of theplayer
oropponent
is already playing a gameSc_rollup_wrong_turn
if a player is trying to move out of turn
The is_opening_move
argument is included here to make sure that an operation intended to start a refutation game is never mistaken for an operation to play the second move of the game---this may otherwise happen due to non-deterministic ordering of L1 operations. With the is_opening_move
parameter, the worst case is that the operation simply fails. Without it, the operation would be mistaken for an invalid move in the game and the staker would lose their stake!
val timeout :
Raw_context.t ->
Sc_rollup_repr.t ->
Sc_rollup_game_repr.Index.t ->
(Sc_rollup_game_repr.game_result * Raw_context.t)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.t
timeout ctxt rollup stakers
checks that the timeout has elapsed and if this function returns a game result that punishes whichever of stakers
is supposed to have played a move.
The timeout period is defined a protocol constant, see Constants_storage.sc_rollup_timeout_period_in_blocks
.
May fail with:
Sc_rollup_no_game
if the game does not in fact existSc_rollup_timeout_level_not_reached
if the player still has time in which to play
Note: this function takes the two stakers as a pair rather than separate arguments. This reflects the fact that for this function the two players are symmetric. This function will normalize the order of the players if necessary to get a valid game index, so the argument stakers
doesn't have to be in normal form.
val get_timeout :
Raw_context.t ->
Sc_rollup_repr.t ->
Sc_rollup_game_repr.Index.t ->
(Sc_rollup_game_repr.timeout * Raw_context.t)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.t
get_timeout ctxt rollup stakers
returns the current timeout values of both players.
val apply_game_result :
Raw_context.t ->
Sc_rollup_repr.t ->
Sc_rollup_game_repr.Index.t ->
Sc_rollup_game_repr.game_result ->
(Sc_rollup_game_repr.status * Raw_context.t * Receipt_repr.balance_updates)
Tezos_protocol_environment_alpha.Error_monad.tzresult
Tezos_protocol_environment_alpha.Lwt.t
apply_game_result ctxt rollup game_result
takes a game_result
produced by timeout
or game_move
and performs the necessary end-of-game cleanup: remove the game itself from the store and punish the losing player by removing their stake. In the case where the game ended in a draw, both players are slashed.
This is mostly just calling remove_staker
, so it can fail with the same errors as that. However, if it is called on an game_result
generated by game_move
or timeout
it should not fail.
Note: this function takes the two stakers as a pair rather than separate arguments. This reflects the fact that for this function the two players are symmetric. This function will normalize the order of the players if necessary to get a valid game index, so the argument stakers
doesn't have to be in normal form.