@@ -203,11 +203,25 @@ end
203203-- Register a new host to a route.
204204function register (state , assignment , opts )
205205 state = ensure_defaults (state )
206+ ao .event ({" register" , { state = state , assignment = assignment , opts = opts }})
206207 local req = assignment .body
208+
209+ -- If the message is signed by an explicitly trusted peer, we can skip the
210+ -- is-admissible check.
211+ if state [" trusted-peer" ] then
212+ local committers = ao .get (" committers" , req )
213+ for _ , committer in ipairs (committers ) do
214+ if committer == state [" trusted-peer" ] then
215+ state = add_node (state , req )
216+ return recalculate (state , assignment , opts )
217+ end
218+ end
219+ end
220+
207221 req .path = state [" is-admissible" ].path or " is-admissible"
208222 local status , is_admissible = ao .resolve (state [" is-admissible" ], req )
209223
210- ao .event (" is-admissible result:" , { status , is_admissible })
224+ ao .event ({ " is-admissible result:" , { status , is_admissible } })
211225 if status == " ok" and is_admissible == " true" then
212226 state = add_node (state , req )
213227 return recalculate (state , assignment , opts )
@@ -270,11 +284,11 @@ function duration(state, assignment, opts)
270284end
271285
272286function compute (state , assignment , opts )
273- if assignment .body .path == " register" then
287+ if assignment .body .action == " register" then
274288 return register (state , assignment , opts )
275- elseif assignment .body .path == " recalculate" then
289+ elseif assignment .body .action == " recalculate" then
276290 return recalculate (state , assignment , opts )
277- elseif assignment .body .path == " performance" then
291+ elseif assignment .body .action == " performance" then
278292 return duration (state , assignment , opts )
279293 else
280294 -- If we have been called without a relevant path, simply ensure that
@@ -377,7 +391,7 @@ function performance_test()
377391 -- Record the starting scores for the nodes
378392 local t0_node1_score = state .routes [1 ].nodes [1 ].weight
379393 local t0_node2_score = state .routes [1 ].nodes [1 ].weight
380-
394+
381395 if t0_node1_score ~= t0_node2_score then
382396 error (" Initial node scores should be equal. Received: "
383397 .. tostring (t0_node1_score ) .. " and " .. tostring (t0_node2_score ))
@@ -403,7 +417,7 @@ function performance_test()
403417 state = state
404418 }}
405419 )
406-
420+
407421 -- now trigger a recalc
408422 _ , state = recalculate (state , { body = { path = " recalculate" } }, {})
409423
@@ -429,6 +443,6 @@ function performance_test()
429443 if t1_node2_score >= t0_node2_score then
430444 error (" Node 2 score should have decreased!" )
431445 end
432-
446+
433447 return " ok"
434448end
0 commit comments