Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
fix(arbitration): use pcall on every tx in case of race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenctw committed Sep 12, 2023
1 parent 486225c commit 72fdb2a
Showing 1 changed file with 51 additions and 5 deletions.
56 changes: 51 additions & 5 deletions onchain/permissionless-arbitration/offchain/player/strategy.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@ local function _join_tournament_if_needed(player, tournament)
tournament.level,
tournament.commitment.root_hash
))
player.client:tx_join_tournament(tournament.address, last, proof, left, right)
local ok, e = pcall(player.client.tx_join_tournament,
player.client,
tournament.address,
last,
proof,
left,
right
)
if not ok then
helper.log(player.player_index, string.format(
"join tournament reverted: %s",
e
))
end
else
helper.touch_player_idle(player.player_index)
end
Expand Down Expand Up @@ -89,7 +102,8 @@ _react_match_honestly = function(player, match, commitment)
match.tournament.level,
commitment.root_hash
))
player.client:tx_seal_leaf_match(
local ok, e = pcall(player.client.tx_seal_leaf_match,
player.client,
match.tournament.address,
match.commitment_one,
match.commitment_two,
Expand All @@ -98,14 +112,21 @@ _react_match_honestly = function(player, match, commitment)
initial_hash,
proof
)
if not ok then
helper.log(player.player_index, string.format(
"seal leaf match reverted: %s",
e
))
end
else
helper.log(player.player_index, string.format(
"seal inner match in tournament %s of level %d for commitment %s",
match.tournament.address,
match.tournament.level,
commitment.root_hash
))
player.client:tx_seal_inner_match(
local ok, e = pcall(player.client.tx_seal_inner_match,
player.client,
match.tournament.address,
match.commitment_one,
match.commitment_two,
Expand All @@ -114,6 +135,12 @@ _react_match_honestly = function(player, match, commitment)
initial_hash,
proof
)
if not ok then
helper.log(player.player_index, string.format(
"seal inner match reverted: %s",
e
))
end
end
else
-- match running
Expand Down Expand Up @@ -141,7 +168,8 @@ _react_match_honestly = function(player, match, commitment)
match.tournament.level,
commitment.root_hash
))
player.client:tx_advance_match(
local ok, e = pcall(player.client.tx_advance_match,
player.client,
match.tournament.address,
match.commitment_one,
match.commitment_two,
Expand All @@ -150,6 +178,12 @@ _react_match_honestly = function(player, match, commitment)
new_left,
new_right
)
if not ok then
helper.log(player.player_index, string.format(
"advance match reverted: %s",
e
))
end
end
end

Expand Down Expand Up @@ -183,7 +217,19 @@ _react_tournament_honestly = function(player, tournament)
tournament.commitment.root_hash
))
local _, left, right = old_commitment:children(old_commitment.root_hash)
player.client:tx_win_inner_match(tournament.parent.address, tournament.address, left, right)
local ok, e = pcall(player.client.tx_win_inner_match,
player.client,
tournament.parent.address,
tournament.address,
left,
right
)
if not ok then
helper.log(player.player_index, string.format(
"win inner match reverted: %s",
e
))
end
return
end
end
Expand Down

0 comments on commit 72fdb2a

Please sign in to comment.