Skip to content

Commit

Permalink
chore(client-lua): improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenctw committed Oct 14, 2024
1 parent 384d22c commit ff62b3b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
4 changes: 1 addition & 3 deletions prt/client-lua/computation/commitment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ CommitmentBuilder.__index = CommitmentBuilder

function CommitmentBuilder:new(machine_path, snapshot_dir, root_commitment)
-- receive honest root commitment from main process
local commitments = {}
commitments[0] = {}
commitments[0][0] = root_commitment
local commitments = { [0] = { [0] = root_commitment } }

local c = {
commitments = commitments,
Expand Down
9 changes: 3 additions & 6 deletions prt/tests/compute/prt_compute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ local function write_json_file(leafs, root_tournament)
local flat = require "utils.flat"
local json = require "utils.json"
local file_path = string.format("/dispute_data/%s/inputs_and_leafs.json", root_tournament)
local file = io.open(file_path, "w")

if file then
file:write(json.encode(flat.flatten(inputs_and_leafs).flat_object))
file:close()
end
local file = assert(io.open(file_path, "w"))
file:write(json.encode(flat.flatten(inputs_and_leafs).flat_object))
assert(file:close())
end

-- Function to setup players
Expand Down
4 changes: 1 addition & 3 deletions prt/tests/compute/runners/helpers/fake_commitment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ end

function FakeCommitmentBuilder:new(machine_path, root_commitment, snapshot_dir)
-- receive honest root commitment from main process
local commitments = {}
commitments[0] = {}
commitments[0][0] = root_commitment
local commitments = { [0] = { [0] = root_commitment } }

local c = {
fake_index = false,
Expand Down
6 changes: 3 additions & 3 deletions prt/tests/compute/runners/rust_hero_runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ local function create_react_once_runner(player_id, machine_path)
assert(reader, "Failed to open process for Rust compute: " .. rust_compute_cmd)
local hero_pid = tonumber(reader:read())

local output = reader:read()
while output do
while true do
local output = reader:read()
if not output then break end
helper.log_color(player_id, output)
output = reader:read()
end

local success, _, code = reader:close()
Expand Down

0 comments on commit ff62b3b

Please sign in to comment.