Skip to content

Commit f6331a9

Browse files
authored
Establish a mutex-like claim on the hold cluster before MRW scanning (#79)
* If best MRW scan rec has weight zero, abort + scan wider next time * Switch to a hold-cluster claim + release strategy instead * Extend the claimed-roots list rather than resetting it
1 parent 56026c7 commit f6331a9

5 files changed

Lines changed: 216 additions & 93 deletions

File tree

src/logger.lisp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,49 @@
144144
(getf entry ':hold-cluster)
145145
(getf entry ':cluster-min-id)))
146146

147+
(defmethod print-log-entry (entry
148+
(source supervisor)
149+
(entry-type (eql ':multireweight-broadcast-scan-result))
150+
&optional (stream *standard-output*))
151+
(format stream "~5f: [~a] ~a (~a)'s MRW cluster scan returned pong (~a ~a ~{~a~^ ~} target-root ~a) for hold-cluster (~{~a~^ ~})~%"
152+
(getf entry ':time)
153+
(getf entry ':source)
154+
(getf entry ':source-root)
155+
(getf entry ':source-id)
156+
(getf entry ':recommendation)
157+
(getf entry ':weight)
158+
(getf entry ':edges)
159+
(getf entry ':target-root)
160+
(getf entry ':hold-cluster)))
161+
147162
(defmethod print-log-entry (entry
148163
(source supervisor)
149164
(entry-type (eql ':aborting-multireweight-negative-pong))
150165
&optional (stream *standard-output*))
151-
(format stream "~5f: [~a] aborting ~a (~a)'s MRW bc the cluster scan returned a negative-weight pong ~a for hold-cluster (~{~a~^ ~})~%"
166+
(format stream "~5f: [~a] aborting ~a (~a)'s MRW bc the cluster scan returned a negative-weight pong (~a ~a ~{~a~^ ~} target-root ~a) for hold-cluster (~{~a~^ ~})~%"
167+
(getf entry ':time)
168+
(getf entry ':source)
169+
(getf entry ':source-root)
170+
(getf entry ':source-id)
171+
(getf entry ':recommendation)
172+
(getf entry ':weight)
173+
(getf entry ':edges)
174+
(getf entry ':target-root)
175+
(getf entry ':hold-cluster)))
176+
177+
(defmethod print-log-entry (entry
178+
(source supervisor)
179+
(entry-type (eql ':aborting-multireweight-zero-pong))
180+
&optional (stream *standard-output*))
181+
(format stream "~5f: [~a] aborting ~a (~a)'s MRW bc the cluster scan returned a zero-weight pong (~a ~a ~{~a~^ ~} target-root ~a) for hold-cluster (~{~a~^ ~})~%"
152182
(getf entry ':time)
153183
(getf entry ':source)
154184
(getf entry ':source-root)
155185
(getf entry ':source-id)
156-
(getf entry ':internal-pong)
186+
(getf entry ':recommendation)
187+
(getf entry ':weight)
188+
(getf entry ':edges)
189+
(getf entry ':target-root)
157190
(getf entry ':hold-cluster)))
158191

159192
;;;

src/node.lisp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@
122122
:initform nil
123123
:initarg :held-by-roots
124124
:type list
125-
:documentation "LIST of `BLOSSOM-NODE' roots who are causing us to `HOLD'."))
125+
:documentation "LIST of `BLOSSOM-NODE' roots who are causing us to `HOLD'.")
126+
(claimed?
127+
:accessor blossom-node-claimed?
128+
:initform nil
129+
:initarg :claimed?
130+
:type boolean
131+
:documentation "If T, this blossom is claimed as part of a hold-cluster."))
126132
(:documentation "Embodies a blossom in the blossom algorithm."))
127133

128134
;;;
@@ -266,8 +272,13 @@ evalutes to
266272
(values nil :type list))
267273

268274
(defstruct (message-id-query (:include message))
269-
"Replies with the minimum ID at this macrovertex."
270-
)
275+
"Replies with the minimum ID at this macrovertex.")
276+
277+
(defstruct (message-claim-root (:include message))
278+
"Attempts to claim a root; if successful, returns a release channel.")
279+
280+
(defstruct (message-release-root (:include message))
281+
"Releases a claimed root.")
271282

272283
;;;
273284
;;; message handlers for BLOSSOM-NODE
@@ -384,6 +395,25 @@ evalutes to
384395
:address (process-public-address node)))
385396
(setf (blossom-node-wilting node) t))
386397

398+
(define-rpc-handler handle-message-claim-root
399+
((node blossom-node) (message message-claim-root))
400+
"If node is already claimed, return NIL. Otherwise, set claimed? to T and return our public address."
401+
(with-slots (claimed?) node
402+
(cond
403+
(claimed?
404+
nil)
405+
(t
406+
(setf claimed? t)
407+
(process-public-address node)))))
408+
409+
(define-rpc-handler handle-message-release-root
410+
((node blossom-node) (message message-release-root))
411+
"Set claimed? to NIL."
412+
(with-slots (claimed?) node
413+
(assert claimed? () "Trying to release an unclaimed root!")
414+
(setf claimed? nil)
415+
t))
416+
387417
;;;
388418
;;; blossom message dispatch table
389419
;;;
@@ -441,7 +471,9 @@ evalutes to
441471

442472
(message-sprout 'handle-message-sprout-on-blossom)
443473

444-
(message-id-query 'handle-message-id-query))
474+
(message-id-query 'handle-message-id-query)
475+
(message-claim-root 'handle-message-claim-root)
476+
(message-release-root 'handle-message-release-root))
445477

446478
;;;
447479
;;; basic command definitions for BLOSSOM-NODE

0 commit comments

Comments
 (0)