diff --git a/src/dev_delegated_compute.erl b/src/dev_delegated_compute.erl index c4416b295..ff6fc696e 100644 --- a/src/dev_delegated_compute.erl +++ b/src/dev_delegated_compute.erl @@ -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), @@ -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">>, diff --git a/src/dev_genesis_wasm.erl b/src/dev_genesis_wasm.erl index 42e3b90dc..cb7818dfc 100644 --- a/src/dev_genesis_wasm.erl +++ b/src/dev_genesis_wasm.erl @@ -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 @@ -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. diff --git a/src/dev_process.erl b/src/dev_process.erl index bec7cb058..06fb3e8b8 100644 --- a/src/dev_process.erl +++ b/src/dev_process.erl @@ -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">>},