@@ -64,7 +64,7 @@ register(_M1, _M2, Opts) ->
6464 #{},
6565 #{
6666 priv_wallet => hb :wallet (),
67- trusted => hb_opts :get (trusted , [] , Opts )
67+ snp_trusted => hb_opts :get (snp_trusted , #{} , Opts )
6868 }
6969 ),
7070 ? event (debug_register , {attestion , Attestion }),
@@ -703,16 +703,123 @@ dynamic_router_test() ->
703703 {ok , Script } = file :read_file (" scripts/dynamic-router.lua" ),
704704 Run = hb_util :bin (rand :uniform (1337 )),
705705 Node = hb_http_server :start_node (Opts = #{
706- trusted => [#{
707- vcpus => 1 ,
708- vcpu_type => 5 ,
709- vmm_type => 1 ,
710- guest_features => 1 ,
711- firmware => <<" b8c5d4082d5738db6b0fb0294174992738645df70c44cdecf7fad3a62244b788e7e408c582ee48a74b289f3acec78510" >>,
712- kernel => <<" 69d0cd7d13858e4fcef6bc7797aebd258730f215bc5642c4ad8e4b893cc67576" >>,
713- initrd => <<" da6dffff50373e1d393bf92cb9b552198b1930068176a046dda4e23bb725b3bb" >>,
714- append => <<" aaf13c9ed2e821ea8c82fcc7981c73a14dc2d01c855f09262d42090fa0424422" >>
715- }],
706+ snp_trusted => #{
707+ <<" 1" >> =>
708+ #{
709+ <<" vcpus" >> => 1 ,
710+ <<" vcpu_type" >> => 5 ,
711+ <<" vmm_type" >> => 1 ,
712+ <<" guest_features" >> => 1 ,
713+ <<" firmware" >> => <<" b8c5d4082d5738db6b0fb0294174992738645df70c44cdecf7fad3a62244b788e7e408c582ee48a74b289f3acec78510" >>,
714+ <<" kernel" >> => <<" 69d0cd7d13858e4fcef6bc7797aebd258730f215bc5642c4ad8e4b893cc67576" >>,
715+ <<" initrd" >> => <<" da6dffff50373e1d393bf92cb9b552198b1930068176a046dda4e23bb725b3bb" >>,
716+ <<" append" >> => <<" aaf13c9ed2e821ea8c82fcc7981c73a14dc2d01c855f09262d42090fa0424422" >>
717+ }
718+ },
719+ store => [
720+ #{
721+ <<" store-module" >> => hb_store_fs ,
722+ <<" prefix" >> => <<" cache-TEST/dynrouter-" , Run /binary >>
723+ }
724+ ],
725+ priv_wallet => ar_wallet :new (),
726+ preprocessor => #{
727+ <<" device" >> => <<" router@1.0" >>
728+ },
729+ route_provider => #{
730+ <<" path" >> =>
731+ <<" /router~n ode-process@1.0/compute/routes~m essage@1.0" >>
732+ },
733+ node_processes => #{
734+ <<" router" >> => #{
735+ <<" type" >> => <<" Process" >>,
736+ <<" device" >> => <<" process@1.0" >>,
737+ <<" execution-device" >> => <<" lua@5.3a" >>,
738+ <<" scheduler-device" >> => <<" scheduler@1.0" >>,
739+ <<" script" >> => #{
740+ <<" content-type" >> => <<" application/lua" >>,
741+ <<" module" >> => <<" dynamic-router" >>,
742+ <<" body" >> => Script
743+ },
744+ % Set script-specific factors for the test
745+ <<" pricing-weight" >> => 9 ,
746+ <<" performance-weight" >> => 1 ,
747+ <<" score-preference" >> => 4 ,
748+ <<" is-admissible" >> => #{
749+ <<" device" >> => <<" snp@1.0" >>
750+ }
751+ }
752+ }
753+ }),
754+ % mergeRight this takes our defined Opts and merges them into the
755+ % node opts configs.
756+ Store = hb_opts :get (store , no_store , Opts ),
757+ ? event (debug_dynrouter , {store , Store }),
758+ % Register workers with the dynamic router with varied prices.
759+ {ok , [Req ]} = file :consult (<<" test/admissible-report.eterm" >>),
760+ lists :foreach (fun (X ) ->
761+ case hb_http :post (
762+ Node ,
763+ #{
764+ <<" path" >> => <<" /router~n ode-process@1.0/schedule" >>,
765+ <<" method" >> => <<" POST" >>,
766+ <<" body" >> =>
767+ hb_message :commit (
768+ #{
769+ <<" path" >> => <<" register" >>,
770+ <<" route" >> =>
771+ #{
772+ <<" prefix" >> =>
773+ <<
774+ " http://149.28.249.192:10000"
775+ >>,
776+ <<" template" >> => <<" /.*~p rocess@1.0/.*" >>,
777+ <<" price" >> => X * 250
778+ },
779+ <<" body" >> => Req
780+ },
781+ Opts
782+ )
783+ },
784+ Opts
785+ ) of
786+ {ok , Res } ->
787+ ? event (debug_dynrouter , { res , Res });
788+ {failure , Res } ->
789+ ? event (debug_router_register , { failure , Res })
790+ end
791+ end , lists :seq (1 , 1 )),
792+ % Force computation of the current state. This should be done with a
793+ % background worker (ex: a `~cron@1.0/every' task).
794+ {Status , NodeRoutes } = hb_http :get (Node , <<" /router~n ode-process@1.0/now" >>, #{}),
795+ ? event (debug_dynrouter , {got_node_routes , NodeRoutes }),
796+ % Meta info is a part of the exempt routes. Make sure this returns our address
797+ {ok , _ } = hb_http :get (Node , <<" /~m eta@1.0/info/address" >>, Opts ),
798+ % ?assertEqual(hb_util:human_id(ar_wallet:to_address(hb_opts:get(priv_wallet, not_found, Opts))), Res),
799+ % {Status, _} = hb_http:get(Node, <<"/RhguwWmQJ-wWCXhRH_NtTDHRRgfCqNDZckXtJK52zKs~process@1.0/compute&slot=1">>, Opts),
800+ ? assertEqual (ok , Status ).
801+
802+ % % @doc Example of a Lua script being used as the `route_provider' for a
803+ % % HyperBEAM node. This test specifically sends an invalid attestation report
804+ % % (with mismatched firmware hash) which should be rejected by the SNP
805+ % % validation system. It tests the error handling for invalid attestations.
806+ dynamic_router_invalid_report_test () ->
807+ {ok , Script } = file :read_file (" scripts/dynamic-router.lua" ),
808+ Run = hb_util :bin (rand :uniform (1337 )),
809+ Node = hb_http_server :start_node (Opts = #{
810+ snp_trusted => #{
811+ <<" 1" >> =>
812+ #{
813+ <<" vcpus" >> => 1 ,
814+ <<" vcpu_type" >> => 5 ,
815+ <<" vmm_type" >> => 1 ,
816+ <<" guest_features" >> => 1 ,
817+ <<" firmware" >> => <<" b8c5d4082d5738db6b0fb0294174992734645df70c44cdecf7fad3a62244b788e7e408c582ee48a74b289f3acec78510" >>,
818+ <<" kernel" >> => <<" 69d0cd7d13858e4fcef6bc7797aebd258730f215bc5642c4ad8e4b893cc67576" >>,
819+ <<" initrd" >> => <<" da6dffff50373e1d393bf92cb9b552198b1930068176a046dda4e23bb725b3bb" >>,
820+ <<" append" >> => <<" aaf13c9ed2e821ea8c82fcc7981c73a14dc2d01c855f09262d42090fa0424422" >>
821+ }
822+ },
716823 store => [
717824 #{
718825 <<" store-module" >> => hb_store_fs ,
@@ -790,12 +897,17 @@ dynamic_router_test() ->
790897 % background worker (ex: a `~cron@1.0/every' task).
791898 {Status , NodeRoutes } = hb_http :get (Node , <<" /router~n ode-process@1.0/now" >>, #{}),
792899 ? event (debug_dynrouter , {got_node_routes , NodeRoutes }),
900+ Routes = hb_ao :get (<<" routes" >>, NodeRoutes , Opts ),
901+ % This should be 0, as the invalid report should have been rejected.
902+ ? event (debug_dynrouter , {routes_length , length (Routes )}),
903+ ? assertEqual (0 , length (Routes )),
793904 % Meta info is a part of the exempt routes. Make sure this returns our address
794905 {ok , _ } = hb_http :get (Node , <<" /~m eta@1.0/info/address" >>, Opts ),
795906 % ?assertEqual(hb_util:human_id(ar_wallet:to_address(hb_opts:get(priv_wallet, not_found, Opts))), Res),
796907 % {Status, _} = hb_http:get(Node, <<"/RhguwWmQJ-wWCXhRH_NtTDHRRgfCqNDZckXtJK52zKs~process@1.0/compute&slot=1">>, Opts),
797908 ? assertEqual (ok , Status ).
798909
910+
799911% % @doc Demonstrates routing tables being dynamically created and adjusted
800912% % according to the real-time performance of nodes. This test utilizes the
801913% % `dynamic-router' script to manage routes and recalculate weights based on the
0 commit comments