Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/dev_delegated_compute.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ normalize(Base, _Req, Opts) ->
error -> {ok, Base};
{ok, Snapshot} ->
Unset = hb_ao:set(Base, #{ <<"snapshot">> => unset }, Opts),
case hb_maps:get(<<"type">>, Snapshot, Opts) == <<"Checkpoint">> of
case hb_maps:get(<<"type">>, Snapshot, not_found, Opts) == <<"Checkpoint">> of
false -> Unset;
true ->
load_state(Snapshot, Opts),
Expand All @@ -31,7 +31,11 @@ normalize(Base, _Req, Opts) ->
%% @doc Attempt to load a snapshot into the delegated compute server.
load_state(Snapshot, Opts) ->
?event(debug_load_snapshot, {loading_snapshot, {snapshot, Snapshot}}),
Body = hb_maps:get(<<"data">>, Snapshot, Opts),
Body = hb_maps:get(<<"data">>, Snapshot, not_found, Opts),
case Body of
not_found -> throw({error, missing_checkpoint_data});
_ -> ok
end,
Headers = hb_maps:without([<<"data">>], Snapshot, Opts),
Res = do_relay(
<<"POST">>,
Expand Down
10 changes: 9 additions & 1 deletion src/dev_genesis_wasm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ do_import(Proc, CheckpointMessage, Opts) ->
CheckpointSigners
) orelse untrusted,
true ?= hb_message:verify(CheckpointMessage, all, Opts) orelse unverified,
CheckpointTargetProcID = hb_maps:get(<<"process">>, CheckpointMessage, Opts),
CheckpointData = hb_maps:get(<<"data">>, CheckpointMessage, not_found, Opts),
true ?= CheckpointData =/= not_found orelse missing_checkpoint_data,
CheckpointTargetProcID = hb_maps:get(<<"process">>, CheckpointMessage, not_found, Opts),
ProcID = dev_process_lib:process_id(Proc, #{}, Opts),
true ?= CheckpointTargetProcID == ProcID orelse process_mismatch,
% Normalize the checkpoint message into a process state message with
Expand Down Expand Up @@ -481,6 +483,12 @@ do_import(Proc, CheckpointMessage, Opts) ->
<<"body">> =>
<<"Checkpoint message is not signed by a trusted snapshot "
"authority.">>
}};
missing_checkpoint_data ->
{error, #{
<<"status">> => 400,
<<"body">> =>
<<"Checkpoint message is missing data.">>
}}
end.

Expand Down
12 changes: 11 additions & 1 deletion src/dev_process.erl
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,17 @@ ensure_loaded(Base, Req, Opts) ->
MaybeLoadedSnapshotMsg,
Opts
),
Process = hb_maps:get(<<"process">>, LoadedSnapshotMsg, Opts),
Process =
case hb_maps:get(
<<"process">>,
LoadedSnapshotMsg,
not_found,
Opts
) of
P when is_map(P) -> P;
not_found -> throw({error, missing_snapshot_process});
_ -> throw({error, invalid_snapshot_process})
end,
#{ <<"commitments">> := HmacCommits} =
hb_message:with_commitments(
#{ <<"type">> => <<"hmac-sha256">>},
Expand Down