From 76ee979a2ed59141cfe32c39050ef804540c4f78 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 25 Oct 2024 11:30:00 +0200 Subject: [PATCH 1/6] Add strategy-pit files for sarafu-300 --- __tests__/fixtures/debt-300.csv | 247 +++++++++++++++++++++++++++++ __tests__/fixtures/dfs-300.csv | 1 + __tests__/fixtures/drains-300.csv | 75 +++++++++ __tests__/fixtures/flow-300.csv | 246 ++++++++++++++++++++++++++++ __tests__/fixtures/mcf-dfs-300.csv | 1 + __tests__/fixtures/mcf-out-300.csv | 3 + __tests__/fixtures/sources-300.csv | 182 +++++++++++++++++++++ 7 files changed, 755 insertions(+) create mode 100644 __tests__/fixtures/debt-300.csv create mode 100644 __tests__/fixtures/dfs-300.csv create mode 100644 __tests__/fixtures/drains-300.csv create mode 100644 __tests__/fixtures/flow-300.csv create mode 100644 __tests__/fixtures/mcf-dfs-300.csv create mode 100644 __tests__/fixtures/mcf-out-300.csv create mode 100644 __tests__/fixtures/sources-300.csv diff --git a/__tests__/fixtures/debt-300.csv b/__tests__/fixtures/debt-300.csv new file mode 100644 index 0000000..0144b45 --- /dev/null +++ b/__tests__/fixtures/debt-300.csv @@ -0,0 +1,247 @@ +1 0 321.5 +2 0 113 +2 1 18 +4 5 5 +4 2 4 +6 7 10 +8 2 5 +9 10 1 +11 5 5 +12 10 1 +12 13 350 +14 15 200 +9 13 370 +3 0 10 +18 19 330 +20 21 140 +22 23 5 +1 3 10 +5 26 0.5 +24 25 20 +27 23 10 +28 29 450 +16 17 110 +1 11 15 +3 2 12 +35 18 50 +36 18 40 +37 38 400 +39 40 4 +41 40 2 +30 4 5 +33 34 588 +31 32 400 +42 40 2 +48 49 100 +46 47 100 +43 40 2 +51 40 2 +53 40 2 +52 40 2 +1 54 2000 +48 56 100 +57 56 100 +49 56 100 +58 56 100 +59 56 100 +61 40 2 +60 40 2 +62 56 50 +63 40 2 +64 56 50 +65 56 2300 +67 40 2 +68 56 50 +69 40 152 +70 40 2 +71 40 2 +73 40 2 +1 74 50 +1 77 100 +78 40 2 +79 80 5 +81 40 2 +83 40 2 +84 76 2 +76 75 2 +85 40 2 +86 21 210 +87 88 100 +90 19 100 +91 92 480 +93 94 5 +95 96 5 +97 98 2 +99 100 5 +101 40 2 +102 103 1200 +105 106 5 +107 10 1 +108 40 2 +109 97 2 +110 10 1 +112 102 100 +114 115 50 +116 10 1 +113 10 1 +117 118 5 +119 19 400 +122 10 1 +124 125 50 +126 127 5 +128 10 1 +129 19 400 +36 130 360 +19 131 720 +35 130 350 +132 133 5 +16 125 120 +135 98 20 +137 10 1 +17 125 60 +138 139 240 +140 106 5 +141 10 1 +142 143 54 +144 10 1 +145 40 2 +146 98 50 +147 40 2 +148 10 1 +149 150 5 +152 98 10 +153 10 1 +154 155 5 +156 10 1 +158 159 1 +157 40 2 +160 98 5 +161 10 1 +162 10 1 +163 10 1 +88 164 300 +165 10 1 +95 164 390 +166 167 200 +168 167 150 +99 164 390 +169 10 1 +79 164 395 +170 159 1 +171 167 250 +172 167 175 +173 92 120 +105 164 390 +174 167 100 +175 164 1000 +176 167 350 +177 10 1 +178 10 1 +179 10 1 +180 181 50 +182 181 50 +183 184 800 +185 181 50 +186 10 1 +187 10 1 +32 188 280 +76 189 2 +51 167 250 +71 167 90 +190 191 400 +192 164 400 +193 10 1 +53 168 80 +73 168 100 +194 195 100 +196 10 1 +81 83 200 +60 167 220 +197 54 50 +198 199 400 +43 181 150 +200 98 5 +1 201 150 +61 181 300 +202 10 1 +201 54 150 +203 10 1 +44 131 400 +39 181 300 +204 29 300 +141 205 399 +40 206 2100 +40 207 1500 +175 192 100 +40 208 1000 +209 210 400 +211 205 50 +212 29 300 +214 215 10 +213 206 200 +216 206 100 +217 218 150 +219 220 160 +221 218 100 +222 218 50 +223 224 120 +225 226 148 +229 230 148 +232 233 450 +227 234 50 +235 208 200 +225 207 150 +237 206 99 +235 231 98 +238 208 299 +239 230 150 +240 226 198 +241 207 148 +158 242 399 +227 243 15 +236 218 50 +246 247 40 +248 249 600 +250 206 140 +244 208 48 +229 231 150 +244 245 100 +227 228 52 +170 242 399 +253 40 150 +254 226 150 +252 54 200 +251 247 190 +257 40 150 +257 208 148 +165 247 390 +256 29 300 +259 230 150 +260 40 150 +261 226 150 +262 207 150 +263 208 150 +263 226 148 +264 21 70 +265 40 150 +266 208 150 +266 245 150 +41 231 150 +41 226 148 +69 206 148 +63 208 298 +78 231 298 +255 247 140 +243 234 15 +179 13 399 +242 270 820 +267 268 1100 +169 13 399 +163 13 399 +178 13 399 +272 273 50 +274 270 600 +275 125 730 +258 245 150 +271 125 30 +269 175 198 diff --git a/__tests__/fixtures/dfs-300.csv b/__tests__/fixtures/dfs-300.csv new file mode 100644 index 0000000..fd0368f --- /dev/null +++ b/__tests__/fixtures/dfs-300.csv @@ -0,0 +1 @@ +1 3 2 10 diff --git a/__tests__/fixtures/drains-300.csv b/__tests__/fixtures/drains-300.csv new file mode 100644 index 0000000..5dd761c --- /dev/null +++ b/__tests__/fixtures/drains-300.csv @@ -0,0 +1,75 @@ +0 444.5 +5 9.5 +7 10 +10 28 +11 10 +13 2316 +15 200 +17 50 +19 510 +21 420 +23 15 +25 20 +26 0.5 +29 1350 +32 120 +34 588 +38 400 +47 100 +54 2400 +56 2950 +74 50 +75 2 +77 100 +80 5 +83 198 +92 600 +94 5 +96 5 +98 92 +100 5 +103 1200 +106 10 +115 50 +118 5 +125 990 +127 5 +130 710 +131 1120 +133 5 +139 240 +143 54 +150 5 +155 5 +159 2 +164 3265 +167 1785 +168 30 +181 900 +184 800 +188 280 +189 2 +191 400 +195 100 +199 400 +205 449 +206 2787 +207 1948 +208 2293 +210 400 +215 10 +218 350 +220 160 +224 120 +226 942 +228 52 +230 448 +231 696 +233 450 +234 65 +245 400 +247 760 +249 600 +268 1100 +270 1420 +273 50 diff --git a/__tests__/fixtures/flow-300.csv b/__tests__/fixtures/flow-300.csv new file mode 100644 index 0000000..58a1b41 --- /dev/null +++ b/__tests__/fixtures/flow-300.csv @@ -0,0 +1,246 @@ +1 0 321.5 +2 0 113.0 +3 0 10.0 +3 2 2.0 +4 5 5.0 +4 2 4.0 +2 1 8.0 +6 7 10.0 +8 2 5.0 +9 10 1.0 +11 5 5.0 +12 10 1.0 +12 13 350.0 +14 15 200.0 +16 17 110.0 +9 13 370.0 +18 19 330.0 +20 21 140.0 +22 23 5.0 +1 11 15.0 +24 25 20.0 +5 26 0.5 +27 23 10.0 +28 29 450.0 +30 4 5.0 +31 32 400.0 +33 34 588.0 +35 18 50.0 +36 18 40.0 +37 38 400.0 +39 40 4.0 +41 40 2.0 +42 40 2.0 +43 40 2.0 +46 47 100.0 +48 49 100.0 +51 40 2.0 +52 40 2.0 +53 40 2.0 +1 54 2000.0 +48 56 100.0 +57 56 100.0 +49 56 100.0 +58 56 100.0 +59 56 100.0 +60 40 2.0 +61 40 2.0 +62 56 50.0 +63 40 2.0 +64 56 50.0 +65 56 2300.0 +67 40 2.0 +68 56 50.0 +69 40 152.0 +70 40 2.0 +71 40 2.0 +73 40 2.0 +1 74 50.0 +1 77 100.0 +78 40 2.0 +79 80 5.0 +81 40 2.0 +83 40 2.0 +84 76 2.0 +76 75 2.0 +85 40 2.0 +86 21 210.0 +87 88 100.0 +90 19 100.0 +91 92 480.0 +93 94 5.0 +95 96 5.0 +99 100 5.0 +97 98 2.0 +101 40 2.0 +102 103 1200.0 +105 106 5.0 +107 10 1.0 +108 40 2.0 +109 97 2.0 +110 10 1.0 +112 102 100.0 +113 10 1.0 +114 115 50.0 +116 10 1.0 +117 118 5.0 +119 19 400.0 +122 10 1.0 +124 125 50.0 +126 127 5.0 +128 10 1.0 +129 19 400.0 +36 130 360.0 +19 131 720.0 +35 130 350.0 +132 133 5.0 +16 125 120.0 +135 98 20.0 +137 10 1.0 +17 125 60.0 +138 139 240.0 +140 106 5.0 +141 10 1.0 +142 143 54.0 +144 10 1.0 +146 98 50.0 +145 40 2.0 +147 40 2.0 +148 10 1.0 +149 150 5.0 +152 98 10.0 +153 10 1.0 +154 155 5.0 +156 10 1.0 +157 40 2.0 +158 159 1.0 +160 98 5.0 +161 10 1.0 +162 10 1.0 +163 10 1.0 +88 164 300.0 +165 10 1.0 +95 164 390.0 +166 167 200.0 +168 167 150.0 +99 164 390.0 +169 10 1.0 +79 164 395.0 +170 159 1.0 +171 167 250.0 +172 167 175.0 +173 92 120.0 +105 164 390.0 +174 167 100.0 +175 164 1000.0 +176 167 350.0 +177 10 1.0 +178 10 1.0 +179 10 1.0 +180 181 50.0 +182 181 50.0 +183 184 800.0 +185 181 50.0 +186 10 1.0 +187 10 1.0 +32 188 280.0 +76 189 2.0 +51 167 250.0 +190 191 400.0 +71 167 90.0 +192 164 400.0 +193 10 1.0 +53 168 80.0 +73 168 100.0 +194 195 100.0 +196 10 1.0 +81 83 200.0 +60 167 220.0 +197 54 50.0 +198 199 400.0 +43 181 150.0 +200 98 5.0 +61 181 300.0 +1 201 150.0 +202 10 1.0 +201 54 150.0 +203 10 1.0 +44 131 400.0 +39 181 300.0 +204 29 300.0 +141 205 399.0 +40 206 2100.0 +40 207 1500.0 +175 192 100.0 +40 208 1000.0 +209 210 400.0 +211 205 50.0 +212 29 300.0 +214 215 10.0 +213 206 200.0 +216 206 100.0 +217 218 150.0 +219 220 160.0 +221 218 100.0 +222 218 50.0 +223 224 120.0 +225 226 148.0 +227 228 52.0 +229 230 148.0 +225 207 150.0 +229 231 150.0 +232 233 450.0 +227 234 50.0 +235 208 200.0 +236 218 50.0 +237 206 99.0 +235 231 98.0 +238 208 299.0 +239 230 150.0 +240 226 198.0 +241 207 148.0 +158 242 399.0 +227 243 15.0 +244 245 100.0 +246 247 40.0 +248 249 600.0 +250 206 140.0 +244 208 48.0 +170 242 399.0 +251 247 190.0 +243 234 15.0 +252 54 200.0 +253 40 150.0 +254 226 150.0 +255 247 140.0 +256 29 300.0 +257 40 150.0 +257 208 148.0 +165 247 390.0 +258 245 150.0 +259 230 150.0 +260 40 150.0 +261 226 150.0 +262 207 150.0 +263 208 150.0 +263 226 148.0 +264 21 70.0 +265 40 150.0 +266 208 150.0 +266 245 150.0 +41 231 150.0 +41 226 148.0 +69 206 148.0 +63 208 298.0 +78 231 298.0 +267 268 1100.0 +269 175 198.0 +179 13 399.0 +242 270 820.0 +271 125 30.0 +169 13 399.0 +163 13 399.0 +178 13 399.0 +272 273 50.0 +274 270 600.0 +275 125 730.0 diff --git a/__tests__/fixtures/mcf-dfs-300.csv b/__tests__/fixtures/mcf-dfs-300.csv new file mode 100644 index 0000000..fd0368f --- /dev/null +++ b/__tests__/fixtures/mcf-dfs-300.csv @@ -0,0 +1 @@ +1 3 2 10 diff --git a/__tests__/fixtures/mcf-out-300.csv b/__tests__/fixtures/mcf-out-300.csv new file mode 100644 index 0000000..e61db5c --- /dev/null +++ b/__tests__/fixtures/mcf-out-300.csv @@ -0,0 +1,3 @@ +2 1 10 +1 3 10 +3 2 10 diff --git a/__tests__/fixtures/sources-300.csv b/__tests__/fixtures/sources-300.csv new file mode 100644 index 0000000..fd1b201 --- /dev/null +++ b/__tests__/fixtures/sources-300.csv @@ -0,0 +1,182 @@ +1 2628.5 +2 110 +3 12 +4 4 +6 10 +8 5 +9 371 +12 351 +14 200 +16 230 +18 240 +20 140 +22 5 +24 20 +27 10 +28 450 +30 5 +31 400 +33 588 +35 400 +37 400 +39 304 +36 400 +40 3800 +41 300 +42 2 +43 152 +44 400 +46 100 +48 200 +51 252 +52 2 +53 82 +57 100 +58 100 +59 100 +60 222 +61 302 +62 50 +63 300 +64 50 +65 2300 +67 2 +68 50 +69 300 +70 2 +71 92 +73 102 +76 2 +78 300 +79 400 +81 202 +84 2 +85 2 +86 210 +87 100 +88 200 +90 100 +91 480 +93 5 +95 395 +99 395 +101 2 +102 1100 +105 395 +107 1 +108 2 +109 2 +110 1 +112 100 +113 1 +114 50 +116 1 +117 5 +119 400 +122 1 +124 50 +126 5 +128 1 +129 400 +132 5 +135 20 +137 1 +138 240 +140 5 +141 400 +142 54 +144 1 +145 2 +146 50 +147 2 +148 1 +149 5 +152 10 +153 1 +154 5 +156 1 +157 2 +158 400 +160 5 +161 1 +162 1 +163 400 +165 391 +166 200 +169 400 +170 400 +171 250 +172 175 +173 120 +174 100 +175 902 +176 350 +177 1 +178 400 +179 400 +180 50 +182 50 +183 800 +185 50 +186 1 +187 1 +190 400 +192 300 +193 1 +194 100 +196 1 +197 50 +198 400 +200 5 +202 1 +203 1 +204 300 +209 400 +211 50 +212 300 +213 200 +214 10 +216 100 +217 150 +219 160 +221 100 +222 50 +223 120 +225 298 +227 117 +229 298 +232 450 +235 298 +236 50 +239 150 +240 198 +241 148 +242 22 +237 99 +246 40 +238 299 +244 148 +248 600 +251 190 +252 200 +250 140 +253 150 +254 150 +255 140 +256 300 +257 298 +258 150 +259 150 +260 150 +261 150 +262 150 +263 298 +264 70 +265 150 +266 300 +267 1100 +269 198 +271 30 +272 50 +274 600 +275 730 From 14043610c5a4223ea71fd3b89e97650309cf4339 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 25 Oct 2024 11:33:14 +0200 Subject: [PATCH 2/6] Failing test for issue #53 --- __tests__/SingleThread.test.ts | 10 +++++----- __tests__/fixtures/sarafu-300.solution | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/__tests__/SingleThread.test.ts b/__tests__/SingleThread.test.ts index 59a3db6..6b29944 100644 --- a/__tests__/SingleThread.test.ts +++ b/__tests__/SingleThread.test.ts @@ -1,5 +1,5 @@ -import { readFileSync, writeFileSync } from "fs"; +import { readFileSync } from "fs"; import { SingleThread } from '../src/SingleThread.js'; const SARAFU_CSV = './__tests__/fixtures/sarafu-300.csv'; @@ -13,10 +13,10 @@ describe('SingleThread', () => { }, }); const cummNumProbes = await threadRunner.runAllWorkers(); const read = readFileSync(`./__tests__/fixtures/sarafu-300.solution`).toString(); - if (solution !== read) { - // console.log(`mending test`); - writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); - } + // if (solution !== read) { + // // console.log(`mending test`); + // writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); + // } expect(solution).toEqual(read); expect(cummNumProbes).toEqual(2); diff --git a/__tests__/fixtures/sarafu-300.solution b/__tests__/fixtures/sarafu-300.solution index e69de29..fd0368f 100644 --- a/__tests__/fixtures/sarafu-300.solution +++ b/__tests__/fixtures/sarafu-300.solution @@ -0,0 +1 @@ +1 3 2 10 From f1bdded39d974828f859113f212b6fddddb50b60 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 25 Oct 2024 11:52:01 +0200 Subject: [PATCH 3/6] SingleThread tests pass if only transactions between nodes 1,2 and 3 are considered --- __tests__/SingleThread.test.ts | 3 +- __tests__/fixtures/sarafu-300.solution | 2 +- src/SingleThread.ts | 7 +++++ src/Worker.ts | 40 +++++++++++++++++++++----- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/__tests__/SingleThread.test.ts b/__tests__/SingleThread.test.ts index 6b29944..d7d2e4c 100644 --- a/__tests__/SingleThread.test.ts +++ b/__tests__/SingleThread.test.ts @@ -9,6 +9,7 @@ describe('SingleThread', () => { let solution: string = ''; const threadRunner = new SingleThread({ sarafuFile: SARAFU_CSV, numWorkers: 1, solutionCallback: async (line: string): Promise => { + console.log(line); solution += line; }, }); const cummNumProbes = await threadRunner.runAllWorkers(); @@ -18,7 +19,7 @@ describe('SingleThread', () => { // writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); // } expect(solution).toEqual(read); - expect(cummNumProbes).toEqual(2); + expect(cummNumProbes).toEqual(3); expect(await threadRunner.solutionIsComplete()).toEqual(true); }); diff --git a/__tests__/fixtures/sarafu-300.solution b/__tests__/fixtures/sarafu-300.solution index fd0368f..fd6e0ba 100644 --- a/__tests__/fixtures/sarafu-300.solution +++ b/__tests__/fixtures/sarafu-300.solution @@ -1 +1 @@ -1 3 2 10 +(2-0:0) [2 1 3 2] diff --git a/src/SingleThread.ts b/src/SingleThread.ts index b1f57ec..4707596 100644 --- a/src/SingleThread.ts +++ b/src/SingleThread.ts @@ -46,7 +46,14 @@ export class SingleThread { this.workers[i] = new Worker(workerOptions); } } + private debug(str: string): void { + if (process.env.VERBOSE) { + console.log(str); + } + } + async runAllWorkers(): Promise { + this.debug(`SingleThread runAllWorkers`); if (this.sarafuFile) { await Promise.all(this.workers.map(async (worker) => worker.readTransfersFromCsv(this.sarafuFile))); } diff --git a/src/Worker.ts b/src/Worker.ts index 8fe2421..969080c 100644 --- a/src/Worker.ts +++ b/src/Worker.ts @@ -35,6 +35,11 @@ export class Worker { this.sendMessage = options.sendMessage; this.semaphoreService = options.semaphoreService; } + private debug(str: string): void { + if (process.env.VERBOSE) { + console.log(str); + } + } public reportState(cb: (string) => void): void { Object.keys(this.ourNodes).forEach((name: string) => { this.ourNodes[name].reportState(cb); @@ -44,7 +49,7 @@ export class Worker { if (this.nodeIsOurs(to)) { // instead of delivering immediately, queue it up until runTasks is called on this worker: // this.getNode(to).receiveMessage(from, message); - // console.log('pushing onto message queue of length', this.messages.length); + // this.debug('pushing onto message queue of length', this.messages.length); this.messages.push({from, to, message }); } else { throw Error('to node is not ours'); @@ -55,13 +60,13 @@ export class Worker { return false; } const msg = this.messages.shift(); - // console.log('delivering', msg); + // this.debug('delivering', msg); await this.deliverMessageToNodeInThisWorker(msg.from, msg.to, msg.message); return true; } async deliverMessageToNodeInThisWorker(from: string, to: string, message: Message): Promise { this.messagesSent++; - // console.log(`Worker ${this.workerNo} delivering message to node ${to}`, from, to, message, this.messages.length); + // this.debug(`Worker ${this.workerNo} delivering message to node ${to}`, from, to, message, this.messages.length); return this.getNode(to).receiveMessage(from, message); } getNumProbes(): number { @@ -78,7 +83,7 @@ export class Worker { if (isNaN(nodeNo)) { throw new Error('node name is not a number ' + name); } - // console.log(`comparing`, nodeNo, this.numWorkers, nodeNo % this.numWorkers, this.workerNo); + // this.debug(`comparing`, nodeNo, this.numWorkers, nodeNo % this.numWorkers, this.workerNo); return (nodeNo % this.numWorkers === this.workerNo); } private ensureNode(name: string): void { @@ -90,7 +95,7 @@ export class Worker { name, solutionCallback: this.solutionCallback, sendMessage: (to: string, message: Message) => { - // console.log('our node', name, to, message); + // this.debug('our node', name, to, message); this.sendMessage(name, to, message); }, semaphoreService: this.semaphoreService, @@ -200,7 +205,7 @@ export class Worker { stats.multilateralAmount += this.ourNodes[name].multilateralAmount; stats.numNodes++; }); - // console.log(`Worker ${this.workerNo} return stats`, stats); + // this.debug(`Worker ${this.workerNo} return stats`, stats); return stats; } getNode(name: string): Jerboa { @@ -208,9 +213,21 @@ export class Worker { return this.ourNodes[name]; } async readTransfersFromCsv(filename: string): Promise { + this.debug(`Worker ${this.workerNo} reading transfers from ${filename}`); await readSarafuCsv(filename, (from: string, to: string, amount: number) => { if (parseInt(from) % this.numWorkers === this.workerNo) { - this.addWeight(from, to, amount); + if (parseInt(from) % this.numWorkers === this.workerNo) { + if (['1','2','3'].indexOf(from) === -1) { + this.debug(`skipping transaction from ${from}`); + return; + } + if (['1','2','3'].indexOf(to) === -1) { + this.debug(`skipping transaction to ${to}`); + return; + } + this.debug(`not skipping transaction from ${from} to ${to}`); + this.addWeight(from, to, amount); + } } }); } @@ -219,6 +236,15 @@ export class Worker { const [ from, to, amountStr ] = cells; const amount = parseFloat(amountStr); if (parseInt(from) % this.numWorkers === this.workerNo) { + if (['1','2','3'].indexOf(from) === -1) { + this.debug(`skipping transaction from ${from}`); + return; + } + if (['1','2','3'].indexOf(to) === -1) { + this.debug(`skipping transaction to ${to}`); + return; + } + this.debug(`not skipping transaction from ${from} to ${to}`); this.addWeight(from, to, amount); } }); From 05051f15d36629e594ea0fad672a5cdac00bb07c Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 25 Oct 2024 11:57:07 +0200 Subject: [PATCH 4/6] Transactions from node 0 are stopping it from finding the 1-2-3-1 triangle --- __tests__/SingleThread.test.ts | 2 +- __tests__/fixtures/sarafu-300.solution | 2 +- src/Worker.ts | 15 +-------------- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/__tests__/SingleThread.test.ts b/__tests__/SingleThread.test.ts index d7d2e4c..eb1e023 100644 --- a/__tests__/SingleThread.test.ts +++ b/__tests__/SingleThread.test.ts @@ -19,7 +19,7 @@ describe('SingleThread', () => { // writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); // } expect(solution).toEqual(read); - expect(cummNumProbes).toEqual(3); + expect(cummNumProbes).toEqual(22); expect(await threadRunner.solutionIsComplete()).toEqual(true); }); diff --git a/__tests__/fixtures/sarafu-300.solution b/__tests__/fixtures/sarafu-300.solution index fd6e0ba..7bbcabc 100644 --- a/__tests__/fixtures/sarafu-300.solution +++ b/__tests__/fixtures/sarafu-300.solution @@ -1 +1 @@ -(2-0:0) [2 1 3 2] +(2-0:3) [2 1 3 2] diff --git a/src/Worker.ts b/src/Worker.ts index 969080c..ae9bbf3 100644 --- a/src/Worker.ts +++ b/src/Worker.ts @@ -217,14 +217,10 @@ export class Worker { await readSarafuCsv(filename, (from: string, to: string, amount: number) => { if (parseInt(from) % this.numWorkers === this.workerNo) { if (parseInt(from) % this.numWorkers === this.workerNo) { - if (['1','2','3'].indexOf(from) === -1) { + if (parseInt(from) === 0) { this.debug(`skipping transaction from ${from}`); return; } - if (['1','2','3'].indexOf(to) === -1) { - this.debug(`skipping transaction to ${to}`); - return; - } this.debug(`not skipping transaction from ${from} to ${to}`); this.addWeight(from, to, amount); } @@ -236,15 +232,6 @@ export class Worker { const [ from, to, amountStr ] = cells; const amount = parseFloat(amountStr); if (parseInt(from) % this.numWorkers === this.workerNo) { - if (['1','2','3'].indexOf(from) === -1) { - this.debug(`skipping transaction from ${from}`); - return; - } - if (['1','2','3'].indexOf(to) === -1) { - this.debug(`skipping transaction to ${to}`); - return; - } - this.debug(`not skipping transaction from ${from} to ${to}`); this.addWeight(from, to, amount); } }); From 6b11df4a55f425ef713f304ebf3b36e55d7dc255 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 25 Oct 2024 12:49:42 +0200 Subject: [PATCH 5/6] whenDone for startProbe and for receiveProbe --- __tests__/SingleThread.test.ts | 12 +- __tests__/fixtures/sarafu-300.solution | 205 +++++++++++++++++++++++++ src/Jerboa.ts | 26 +++- src/Worker.ts | 6 +- 4 files changed, 237 insertions(+), 12 deletions(-) diff --git a/__tests__/SingleThread.test.ts b/__tests__/SingleThread.test.ts index eb1e023..85670f2 100644 --- a/__tests__/SingleThread.test.ts +++ b/__tests__/SingleThread.test.ts @@ -1,5 +1,5 @@ -import { readFileSync } from "fs"; +import { readFileSync, writeFileSync } from "fs"; import { SingleThread } from '../src/SingleThread.js'; const SARAFU_CSV = './__tests__/fixtures/sarafu-300.csv'; @@ -9,15 +9,15 @@ describe('SingleThread', () => { let solution: string = ''; const threadRunner = new SingleThread({ sarafuFile: SARAFU_CSV, numWorkers: 1, solutionCallback: async (line: string): Promise => { - console.log(line); + // console.log(line); solution += line; }, }); const cummNumProbes = await threadRunner.runAllWorkers(); const read = readFileSync(`./__tests__/fixtures/sarafu-300.solution`).toString(); - // if (solution !== read) { - // // console.log(`mending test`); - // writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); - // } + if (solution !== read) { + // console.log(`mending test`); + writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); + } expect(solution).toEqual(read); expect(cummNumProbes).toEqual(22); diff --git a/__tests__/fixtures/sarafu-300.solution b/__tests__/fixtures/sarafu-300.solution index 7bbcabc..15aebf2 100644 --- a/__tests__/fixtures/sarafu-300.solution +++ b/__tests__/fixtures/sarafu-300.solution @@ -1 +1,206 @@ +Node 0 adjustSent for 1 to 0+0.5 while processing addWeight +SEND 0 1 {"command":"transfer","amount":0.5} +transfer 0 -> 1 +Node 1 adjustSent for 0 to 0+100 while processing addWeight +SEND 1 0 {"command":"transfer","amount":100} +transfer 1 -> 0 +Node 1 adjustSent for 0 to 100+200 while processing addWeight +SEND 1 0 {"command":"transfer","amount":200} +transfer 1 -> 0 +Node 2 adjustSent for 0 to 0+100 while processing addWeight +SEND 2 0 {"command":"transfer","amount":100} +transfer 2 -> 0 +Node 1 adjustSent for 2 to 0+2 while processing addWeight +SEND 1 2 {"command":"transfer","amount":2} +transfer 1 -> 2 +Node 1 adjustSent for 0 to 300+2 while processing addWeight +SEND 1 0 {"command":"transfer","amount":2} +transfer 1 -> 0 +Node 2 adjustSent for 0 to 100+23 while processing addWeight +SEND 2 0 {"command":"transfer","amount":23} +transfer 2 -> 0 +Node 3 adjustSent for 2 to 0+12 while processing addWeight +SEND 3 2 {"command":"transfer","amount":12} +transfer 3 -> 2 +Node 1 adjustSent for 3 to 0+10 while processing addWeight +SEND 1 3 {"command":"transfer","amount":10} +transfer 1 -> 3 +Node 3 adjustSent for 0 to 0+10 while processing addWeight +SEND 3 0 {"command":"transfer","amount":10} +transfer 3 -> 0 +Node 1 adjustSent for 0 to 302+20 while processing addWeight +SEND 1 0 {"command":"transfer","amount":20} +transfer 1 -> 0 +Node 0 adjustSent for 2 to 0+10 while processing addWeight +SEND 0 2 {"command":"transfer","amount":10} +transfer 0 -> 2 +Node 2 adjustSent for 1 to 0+10 while processing addWeight +SEND 2 1 {"command":"transfer","amount":10} +transfer 2 -> 1 +Node 2 adjustSent for 1 to 10+10 while processing addWeight +SEND 2 1 {"command":"transfer","amount":10} +transfer 2 -> 1 +RCV[0->1]transfer 0.5 +RCV[1->0]transfer 100 +transfer receiver starts probe +SEMAPHORE REQ 0 +SEMAPHORE GO 0-0 +0 starts probe 0-0 +0 is setting whenDone for 0-0 +Node 0 starting probe 0-0:0 [0] +0 has checked the suitability of possible next hop 2 for probe 0-0 -> true +SEND 0 2 {"command":"probe","probeId":"0-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} +RCV[1->0]transfer 200 +transfer receiver starts probe +SEMAPHORE REQ 0 +RCV[2->0]transfer 100 +RCV[1->2]transfer 2 +RCV[1->0]transfer 2 +RCV[2->0]transfer 23 +RCV[3->2]transfer 12 +transfer receiver starts probe +SEMAPHORE REQ 2 +RCV[1->3]transfer 10 +transfer receiver starts probe +SEMAPHORE REQ 3 +RCV[3->0]transfer 10 +RCV[1->0]transfer 20 +RCV[0->2]transfer 10 +transfer receiver starts probe +SEMAPHORE REQ 2 +RCV[2->1]transfer 10 +transfer receiver starts probe +SEMAPHORE REQ 1 +RCV[2->1]transfer 10 +transfer receiver starts probe +SEMAPHORE REQ 1 +RCV[0->2]probe 0-0:0 +2 recording probe traffic in from receiveProbe "0-0" [0 2] +Node 2 considering probe 0-0:0 [0 2] +2 nacks counter-balance probe 0-0:0 from 0 +SEND 2 0 {"command":"nack","probeId":"0-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} +RCV[2->0]nack 0-0:0 / +(0-0:0) / 0 2 +0 is done with current probe 0-0 due to nack-and-finished +0 is calling whenDone for 0-0 +0 is deleting whenDone for 0-0 +SEMAPHORE DONE 0-0 +SEMAPHORE GO 0-1 +0 starts probe 0-1 +0 is setting whenDone for 0-1 +Node 0 starting probe 0-1:0 [0] +0 is done with current probe 0-1 due to non-starter +0 is calling whenDone for 0-1 +0 is deleting whenDone for 0-1 +SEMAPHORE DONE 0-1 +SEMAPHORE GO 2-0 +2 starts probe 2-0 +2 is setting whenDone for 2-0 +Node 2 starting probe 2-0:0 [2] +2 has checked the suitability of possible next hop 0 for probe 2-0 -> true +2 has checked the suitability of possible next hop 1 for probe 2-0 -> true +SEND 2 0 {"command":"probe","probeId":"2-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} +RCV[2->0]probe 2-0:0 +0 recording probe traffic in from receiveProbe "2-0" [2 0] +Node 0 considering probe 2-0:0 [2 0] +no outgoing links, so sending nack 0->2 2-0:0 [] [] +0 is done with current probe 2-0 due to leaf +0 is calling whenDone for 2-0 +0 is done with incoming 2-0 +0 is deleting whenDone for 2-0 +SEND 0 2 {"command":"nack","probeId":"2-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} +RCV[0->2]nack 2-0:0 / +2 has checked the suitability of possible next hop 0 for probe 2-0 (balance: 113000000 -> false +2 has checked the suitability of possible next hop 1 for probe 2-0 (balance: 18000000 -> true +(2-0:0) 2 / 0 +2 received nack from 0 for its own probe (2-0:0) and switches to next incarnation (2-0:1) +Node 2 starting probe 2-0:1 [2] +2 has checked the suitability of possible next hop 0 for probe 2-0 -> false +2 has checked the suitability of possible next hop 1 for probe 2-0 -> true +SEND 2 1 {"command":"probe","probeId":"2-0","incarnation":1,"debugInfo":{"path":[]}} +RCV[2->1]probe 2-0:1 +1 recording probe traffic in from receiveProbe "2-0" [2 1] +Node 1 considering probe 2-0:1 [2 1] +1 has checked the suitability of possible next hop 0 for probe 2-0 -> true +1 has checked the suitability of possible next hop 3 for probe 2-0 -> true +SEND 1 0 {"command":"probe","probeId":"2-0","incarnation":1,"debugInfo":{"path":["2"]}} +RCV[1->0]probe 2-0:1 2 +0 recording probe traffic in from receiveProbe "2-0" [2 1 0] +Node 0 considering probe 2-0:1 [2 1 0] +no outgoing links, so sending nack 0->1 2-0:1 [2] [] +0 is done with current probe 2-0 due to leaf +0 is calling whenDone for 2-0 +0 is done with incoming 2-0 +0 is deleting whenDone for 2-0 +SEND 0 1 {"command":"nack","probeId":"2-0","incarnation":1,"debugInfo":{"path":["2"],"backtracked":[]}} +RCV[0->1]nack 2-0:1 2 / +1 reconsiders probe 2-0 from 2 after receiving nack from 0 +1 has checked the suitability of possible next hop 0 for probe 2-0 -> false +1 has checked the suitability of possible next hop 3 for probe 2-0 -> true +(2-0:1) 2 1 / 0 +SEND 1 3 {"command":"probe","probeId":"2-0","incarnation":2,"debugInfo":{"path":["2"]}} +RCV[1->3]probe 2-0:2 2 +3 recording probe traffic in from receiveProbe "2-0" [2 1 3] +Node 3 considering probe 2-0:2 [2 1 3] +3 has checked the suitability of possible next hop 0 for probe 2-0 -> true +3 has checked the suitability of possible next hop 2 for probe 2-0 -> true +SEND 3 0 {"command":"probe","probeId":"2-0","incarnation":2,"debugInfo":{"path":["2","1"]}} +RCV[3->0]probe 2-0:2 2 1 +0 recording probe traffic in from receiveProbe "2-0" [2 1 3 0] +Node 0 considering probe 2-0:2 [2 1 3 0] +no outgoing links, so sending nack 0->3 2-0:2 [2 1] [] +0 is done with current probe 2-0 due to leaf +0 is calling whenDone for 2-0 +0 is done with incoming 2-0 +0 is deleting whenDone for 2-0 +SEND 0 3 {"command":"nack","probeId":"2-0","incarnation":2,"debugInfo":{"path":["2","1"],"backtracked":[]}} +RCV[0->3]nack 2-0:2 2 1 / +3 reconsiders probe 2-0 from 1 after receiving nack from 0 +3 has checked the suitability of possible next hop 0 for probe 2-0 -> false +3 has checked the suitability of possible next hop 2 for probe 2-0 -> true +(2-0:2) 2 1 3 / 0 +SEND 3 2 {"command":"probe","probeId":"2-0","incarnation":3,"debugInfo":{"path":["2","1"]}} +RCV[3->2]probe 2-0:3 2 1 +2 recording probe traffic in from receiveProbe "2-0" [2 1 3 2] +Node 2 considering probe 2-0:3 [2 1 3 2] +Initiator 2 sets scout amount for (2-0:3-) to incoming balance 12 +SEND 2 3 {"command":"scout","probeId":"2-0","maxIncarnation":3,"amount":12,"debugInfo":{"loop":["2","1","3","2"]}} (2-0:3) [2 1 3 2] +SEMAPHORE REQ 2 +RCV[2->3]scout 2-0:3- 12 2 1 3 2 +3 is OK with scout amount for (2-0:3-) based on out balance to 2 because 12 <= 12 +3 is OK with scout amount for (2-0:3-) based on in balance from 1 because 12 <= 12 +SEND 3 1 {"command":"scout","probeId":"2-0","maxIncarnation":3,"amount":12,"debugInfo":{"loop":["2","1","3","2"]}} +RCV[3->1]scout 2-0:3- 12 2 1 3 2 +1 adjust the scout amount for (2-0:3-) based on out balance to 3 from 12 to 10 +1 is OK with scout amount for (2-0:3-) based on in balance from 2 because 10 <= 10 +SEND 1 2 {"command":"scout","probeId":"2-0","maxIncarnation":3,"amount":10,"debugInfo":{"loop":["2","1","3","2"]}} +RCV[1->2]scout 2-0:3- 10 2 1 3 2 +Initiator 2 is still OK with scout amount for (2-0:3-) based on out balance to 1 because 10 <= 18 +SEND 2 3 {"command":"propose","probeId":"2-0","maxIncarnation":3,"amount":10,"hash":"o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk=","debugInfo":{"loop":["2","1","3","2"]}} +RCV[2->3]propose 2-0:3- 10 o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk= 2 1 3 2 +SEND 3 1 {"command":"propose","probeId":"2-0","maxIncarnation":3,"amount":10,"hash":"o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk=","debugInfo":{"loop":["2","1","3","2"]}} +RCV[3->1]propose 2-0:3- 10 o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk= 2 1 3 2 +SEND 1 2 {"command":"propose","probeId":"2-0","maxIncarnation":3,"amount":10,"hash":"o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk=","debugInfo":{"loop":["2","1","3","2"]}} +RCV[1->2]propose 2-0:3- 10 o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk= 2 1 3 2 +SEND 2 1 {"command":"commit","probeId":"2-0","amount":10,"preimage":"541f608a3ce3f487","debugInfo":{"loop":["2","1","3","2"]}} +RCV[2->1]commit 2-0:~- 10 541f608a3ce3f487 2 1 3 2 +Node 1 adjustSent for 2 to -18+10 while processing commit +SEND 1 3 {"command":"commit","probeId":"2-0","amount":10,"preimage":"541f608a3ce3f487","debugInfo":{"loop":["2","1","3","2"]}} +1 is done with current probe 2-0 due to commit +1 is calling whenDone for 2-0 +1 is done with incoming 2-0 +1 is deleting whenDone for 2-0 +RCV[1->3]commit 2-0:~- 10 541f608a3ce3f487 2 1 3 2 +Node 3 adjustSent for 1 to -10+10 while processing commit +SEND 3 2 {"command":"commit","probeId":"2-0","amount":10,"preimage":"541f608a3ce3f487","debugInfo":{"loop":["2","1","3","2"]}} +3 is done with current probe 2-0 due to commit +3 is calling whenDone for 2-0 +3 is done with incoming 2-0 +3 is deleting whenDone for 2-0 +RCV[3->2]commit 2-0:~- 10 541f608a3ce3f487 2 1 3 2 +Node 2 adjustSent for 3 to -12+10 while processing commit +2 is done with current probe 2-0 due to commit +2 is calling whenDone for 2-0 +2 is done with incoming 2-0 +2 is deleting whenDone for 2-0 diff --git a/src/Jerboa.ts b/src/Jerboa.ts index c3c9a7d..784a107 100644 --- a/src/Jerboa.ts +++ b/src/Jerboa.ts @@ -104,7 +104,9 @@ export class Jerboa { private sendMessageCb: (to: string, message: Message) => void; private loopsTried: string[] = []; private solutionCallback: (line: string) => void; - private whenDone: (value: unknown) => void; + private whenDone: { + [probeId: string]: (value: unknown) => void + } = {}; // private maybeRunProbeTimer; constructor(options: JerboaOptions) { this.name = options.name; @@ -350,9 +352,13 @@ export class Jerboa { this.currentProbeIds.splice(index, 1); // 2nd parameter means remove one item only } // this.resumeProbeQueue(); - if (this.whenDone) { - this.whenDone(undefined); - delete this.whenDone; + if (this.whenDone[probeId]) { + this.debug(`${this.name} is calling whenDone for ${probeId}`); + this.whenDone[probeId](undefined); + this.debug(`${this.name} is deleting whenDone for ${probeId}`); + delete this.whenDone[probeId]; + } else { + this.debug(`${this.name} has no whenDone callback found for probeId ${probeId}`); } } initiatePropose(to: string, probeId: string, incarnation: number, amount: number, debugInfo: { loop: string[] }): void { @@ -454,6 +460,9 @@ export class Jerboa { const { probeId, incarnation, debugInfo } = msg; this.debug(`${this.name} recording probe traffic in from receiveProbe "${probeId}" [${debugInfo.path.concat([sender, this.name]).join(' ')}]`); this.recordProbeTraffic(sender, 'in', probeId, incarnation); + this.whenDone[msg.probeId] = () => { + this.debug(`${this.name} is done with incoming ${msg.probeId}`); + } this.runProbe({ sender, probeId: msg.probeId, incarnation: msg.incarnation, debugInfo: msg.debugInfo }); } changeToLooper(sender: string, probeId: string, incarnation: number): void { @@ -571,11 +580,18 @@ export class Jerboa { this.debug(`transfer ${this.name} -> ${to}`); } startProbe(): void { + this.debug(`SEMAPHORE REQ ${this.name}`); this.semaphoreService.joinQueue(async () => { const probeId = `${this.name}-${this.probeMinter++}`; + this.debug(`SEMAPHORE GO ${probeId}`); this.debug(`${this.name} starts probe ${probeId}`); + const promise = new Promise(resolve => { + this.debug(`${this.name} is setting whenDone for ${probeId}`); + this.whenDone[probeId] = resolve; + }); this.runProbe({ sender: null, probeId, incarnation: 0, debugInfo: { path: [], backtracked: [] } }); - await new Promise(resolve => this.whenDone = resolve); + await promise; + this.debug(`SEMAPHORE DONE ${probeId}`); }); } runProbe(probeInfo: ProbeInfo): void { diff --git a/src/Worker.ts b/src/Worker.ts index ae9bbf3..a825eed 100644 --- a/src/Worker.ts +++ b/src/Worker.ts @@ -217,10 +217,14 @@ export class Worker { await readSarafuCsv(filename, (from: string, to: string, amount: number) => { if (parseInt(from) % this.numWorkers === this.workerNo) { if (parseInt(from) % this.numWorkers === this.workerNo) { - if (parseInt(from) === 0) { + if (parseInt(from) > 3) { this.debug(`skipping transaction from ${from}`); return; } + if (parseInt(to) > 3) { + this.debug(`skipping transaction to ${to}`); + return; + } this.debug(`not skipping transaction from ${from} to ${to}`); this.addWeight(from, to, amount); } From fa7fd50a63f5eb27d7b13da1dae60a2d398bcb03 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 25 Oct 2024 12:51:37 +0200 Subject: [PATCH 6/6] Fix #53 --- __tests__/SingleThread.test.ts | 12 +- __tests__/fixtures/sarafu-300.solution | 205 ------------------------- src/Worker.ts | 8 - 3 files changed, 6 insertions(+), 219 deletions(-) diff --git a/__tests__/SingleThread.test.ts b/__tests__/SingleThread.test.ts index 85670f2..08d83c8 100644 --- a/__tests__/SingleThread.test.ts +++ b/__tests__/SingleThread.test.ts @@ -1,5 +1,5 @@ -import { readFileSync, writeFileSync } from "fs"; +import { readFileSync } from "fs"; import { SingleThread } from '../src/SingleThread.js'; const SARAFU_CSV = './__tests__/fixtures/sarafu-300.csv'; @@ -14,12 +14,12 @@ describe('SingleThread', () => { }, }); const cummNumProbes = await threadRunner.runAllWorkers(); const read = readFileSync(`./__tests__/fixtures/sarafu-300.solution`).toString(); - if (solution !== read) { - // console.log(`mending test`); - writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); - } + // if (solution !== read) { + // // console.log(`mending test`); + // writeFileSync(`./__tests__/fixtures/sarafu-300.solution`, solution); + // } expect(solution).toEqual(read); - expect(cummNumProbes).toEqual(22); + expect(cummNumProbes).toEqual(3); expect(await threadRunner.solutionIsComplete()).toEqual(true); }); diff --git a/__tests__/fixtures/sarafu-300.solution b/__tests__/fixtures/sarafu-300.solution index 15aebf2..7bbcabc 100644 --- a/__tests__/fixtures/sarafu-300.solution +++ b/__tests__/fixtures/sarafu-300.solution @@ -1,206 +1 @@ -Node 0 adjustSent for 1 to 0+0.5 while processing addWeight -SEND 0 1 {"command":"transfer","amount":0.5} -transfer 0 -> 1 -Node 1 adjustSent for 0 to 0+100 while processing addWeight -SEND 1 0 {"command":"transfer","amount":100} -transfer 1 -> 0 -Node 1 adjustSent for 0 to 100+200 while processing addWeight -SEND 1 0 {"command":"transfer","amount":200} -transfer 1 -> 0 -Node 2 adjustSent for 0 to 0+100 while processing addWeight -SEND 2 0 {"command":"transfer","amount":100} -transfer 2 -> 0 -Node 1 adjustSent for 2 to 0+2 while processing addWeight -SEND 1 2 {"command":"transfer","amount":2} -transfer 1 -> 2 -Node 1 adjustSent for 0 to 300+2 while processing addWeight -SEND 1 0 {"command":"transfer","amount":2} -transfer 1 -> 0 -Node 2 adjustSent for 0 to 100+23 while processing addWeight -SEND 2 0 {"command":"transfer","amount":23} -transfer 2 -> 0 -Node 3 adjustSent for 2 to 0+12 while processing addWeight -SEND 3 2 {"command":"transfer","amount":12} -transfer 3 -> 2 -Node 1 adjustSent for 3 to 0+10 while processing addWeight -SEND 1 3 {"command":"transfer","amount":10} -transfer 1 -> 3 -Node 3 adjustSent for 0 to 0+10 while processing addWeight -SEND 3 0 {"command":"transfer","amount":10} -transfer 3 -> 0 -Node 1 adjustSent for 0 to 302+20 while processing addWeight -SEND 1 0 {"command":"transfer","amount":20} -transfer 1 -> 0 -Node 0 adjustSent for 2 to 0+10 while processing addWeight -SEND 0 2 {"command":"transfer","amount":10} -transfer 0 -> 2 -Node 2 adjustSent for 1 to 0+10 while processing addWeight -SEND 2 1 {"command":"transfer","amount":10} -transfer 2 -> 1 -Node 2 adjustSent for 1 to 10+10 while processing addWeight -SEND 2 1 {"command":"transfer","amount":10} -transfer 2 -> 1 -RCV[0->1]transfer 0.5 -RCV[1->0]transfer 100 -transfer receiver starts probe -SEMAPHORE REQ 0 -SEMAPHORE GO 0-0 -0 starts probe 0-0 -0 is setting whenDone for 0-0 -Node 0 starting probe 0-0:0 [0] -0 has checked the suitability of possible next hop 2 for probe 0-0 -> true -SEND 0 2 {"command":"probe","probeId":"0-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} -RCV[1->0]transfer 200 -transfer receiver starts probe -SEMAPHORE REQ 0 -RCV[2->0]transfer 100 -RCV[1->2]transfer 2 -RCV[1->0]transfer 2 -RCV[2->0]transfer 23 -RCV[3->2]transfer 12 -transfer receiver starts probe -SEMAPHORE REQ 2 -RCV[1->3]transfer 10 -transfer receiver starts probe -SEMAPHORE REQ 3 -RCV[3->0]transfer 10 -RCV[1->0]transfer 20 -RCV[0->2]transfer 10 -transfer receiver starts probe -SEMAPHORE REQ 2 -RCV[2->1]transfer 10 -transfer receiver starts probe -SEMAPHORE REQ 1 -RCV[2->1]transfer 10 -transfer receiver starts probe -SEMAPHORE REQ 1 -RCV[0->2]probe 0-0:0 -2 recording probe traffic in from receiveProbe "0-0" [0 2] -Node 2 considering probe 0-0:0 [0 2] -2 nacks counter-balance probe 0-0:0 from 0 -SEND 2 0 {"command":"nack","probeId":"0-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} -RCV[2->0]nack 0-0:0 / -(0-0:0) / 0 2 -0 is done with current probe 0-0 due to nack-and-finished -0 is calling whenDone for 0-0 -0 is deleting whenDone for 0-0 -SEMAPHORE DONE 0-0 -SEMAPHORE GO 0-1 -0 starts probe 0-1 -0 is setting whenDone for 0-1 -Node 0 starting probe 0-1:0 [0] -0 is done with current probe 0-1 due to non-starter -0 is calling whenDone for 0-1 -0 is deleting whenDone for 0-1 -SEMAPHORE DONE 0-1 -SEMAPHORE GO 2-0 -2 starts probe 2-0 -2 is setting whenDone for 2-0 -Node 2 starting probe 2-0:0 [2] -2 has checked the suitability of possible next hop 0 for probe 2-0 -> true -2 has checked the suitability of possible next hop 1 for probe 2-0 -> true -SEND 2 0 {"command":"probe","probeId":"2-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} -RCV[2->0]probe 2-0:0 -0 recording probe traffic in from receiveProbe "2-0" [2 0] -Node 0 considering probe 2-0:0 [2 0] -no outgoing links, so sending nack 0->2 2-0:0 [] [] -0 is done with current probe 2-0 due to leaf -0 is calling whenDone for 2-0 -0 is done with incoming 2-0 -0 is deleting whenDone for 2-0 -SEND 0 2 {"command":"nack","probeId":"2-0","incarnation":0,"debugInfo":{"path":[],"backtracked":[]}} -RCV[0->2]nack 2-0:0 / -2 has checked the suitability of possible next hop 0 for probe 2-0 (balance: 113000000 -> false -2 has checked the suitability of possible next hop 1 for probe 2-0 (balance: 18000000 -> true -(2-0:0) 2 / 0 -2 received nack from 0 for its own probe (2-0:0) and switches to next incarnation (2-0:1) -Node 2 starting probe 2-0:1 [2] -2 has checked the suitability of possible next hop 0 for probe 2-0 -> false -2 has checked the suitability of possible next hop 1 for probe 2-0 -> true -SEND 2 1 {"command":"probe","probeId":"2-0","incarnation":1,"debugInfo":{"path":[]}} -RCV[2->1]probe 2-0:1 -1 recording probe traffic in from receiveProbe "2-0" [2 1] -Node 1 considering probe 2-0:1 [2 1] -1 has checked the suitability of possible next hop 0 for probe 2-0 -> true -1 has checked the suitability of possible next hop 3 for probe 2-0 -> true -SEND 1 0 {"command":"probe","probeId":"2-0","incarnation":1,"debugInfo":{"path":["2"]}} -RCV[1->0]probe 2-0:1 2 -0 recording probe traffic in from receiveProbe "2-0" [2 1 0] -Node 0 considering probe 2-0:1 [2 1 0] -no outgoing links, so sending nack 0->1 2-0:1 [2] [] -0 is done with current probe 2-0 due to leaf -0 is calling whenDone for 2-0 -0 is done with incoming 2-0 -0 is deleting whenDone for 2-0 -SEND 0 1 {"command":"nack","probeId":"2-0","incarnation":1,"debugInfo":{"path":["2"],"backtracked":[]}} -RCV[0->1]nack 2-0:1 2 / -1 reconsiders probe 2-0 from 2 after receiving nack from 0 -1 has checked the suitability of possible next hop 0 for probe 2-0 -> false -1 has checked the suitability of possible next hop 3 for probe 2-0 -> true -(2-0:1) 2 1 / 0 -SEND 1 3 {"command":"probe","probeId":"2-0","incarnation":2,"debugInfo":{"path":["2"]}} -RCV[1->3]probe 2-0:2 2 -3 recording probe traffic in from receiveProbe "2-0" [2 1 3] -Node 3 considering probe 2-0:2 [2 1 3] -3 has checked the suitability of possible next hop 0 for probe 2-0 -> true -3 has checked the suitability of possible next hop 2 for probe 2-0 -> true -SEND 3 0 {"command":"probe","probeId":"2-0","incarnation":2,"debugInfo":{"path":["2","1"]}} -RCV[3->0]probe 2-0:2 2 1 -0 recording probe traffic in from receiveProbe "2-0" [2 1 3 0] -Node 0 considering probe 2-0:2 [2 1 3 0] -no outgoing links, so sending nack 0->3 2-0:2 [2 1] [] -0 is done with current probe 2-0 due to leaf -0 is calling whenDone for 2-0 -0 is done with incoming 2-0 -0 is deleting whenDone for 2-0 -SEND 0 3 {"command":"nack","probeId":"2-0","incarnation":2,"debugInfo":{"path":["2","1"],"backtracked":[]}} -RCV[0->3]nack 2-0:2 2 1 / -3 reconsiders probe 2-0 from 1 after receiving nack from 0 -3 has checked the suitability of possible next hop 0 for probe 2-0 -> false -3 has checked the suitability of possible next hop 2 for probe 2-0 -> true -(2-0:2) 2 1 3 / 0 -SEND 3 2 {"command":"probe","probeId":"2-0","incarnation":3,"debugInfo":{"path":["2","1"]}} -RCV[3->2]probe 2-0:3 2 1 -2 recording probe traffic in from receiveProbe "2-0" [2 1 3 2] -Node 2 considering probe 2-0:3 [2 1 3 2] -Initiator 2 sets scout amount for (2-0:3-) to incoming balance 12 -SEND 2 3 {"command":"scout","probeId":"2-0","maxIncarnation":3,"amount":12,"debugInfo":{"loop":["2","1","3","2"]}} (2-0:3) [2 1 3 2] -SEMAPHORE REQ 2 -RCV[2->3]scout 2-0:3- 12 2 1 3 2 -3 is OK with scout amount for (2-0:3-) based on out balance to 2 because 12 <= 12 -3 is OK with scout amount for (2-0:3-) based on in balance from 1 because 12 <= 12 -SEND 3 1 {"command":"scout","probeId":"2-0","maxIncarnation":3,"amount":12,"debugInfo":{"loop":["2","1","3","2"]}} -RCV[3->1]scout 2-0:3- 12 2 1 3 2 -1 adjust the scout amount for (2-0:3-) based on out balance to 3 from 12 to 10 -1 is OK with scout amount for (2-0:3-) based on in balance from 2 because 10 <= 10 -SEND 1 2 {"command":"scout","probeId":"2-0","maxIncarnation":3,"amount":10,"debugInfo":{"loop":["2","1","3","2"]}} -RCV[1->2]scout 2-0:3- 10 2 1 3 2 -Initiator 2 is still OK with scout amount for (2-0:3-) based on out balance to 1 because 10 <= 18 -SEND 2 3 {"command":"propose","probeId":"2-0","maxIncarnation":3,"amount":10,"hash":"o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk=","debugInfo":{"loop":["2","1","3","2"]}} -RCV[2->3]propose 2-0:3- 10 o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk= 2 1 3 2 -SEND 3 1 {"command":"propose","probeId":"2-0","maxIncarnation":3,"amount":10,"hash":"o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk=","debugInfo":{"loop":["2","1","3","2"]}} -RCV[3->1]propose 2-0:3- 10 o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk= 2 1 3 2 -SEND 1 2 {"command":"propose","probeId":"2-0","maxIncarnation":3,"amount":10,"hash":"o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk=","debugInfo":{"loop":["2","1","3","2"]}} -RCV[1->2]propose 2-0:3- 10 o1WCBiqFNmHy6vfL+N8wFzfATUl7QUuU+XG8KIagDEk= 2 1 3 2 -SEND 2 1 {"command":"commit","probeId":"2-0","amount":10,"preimage":"541f608a3ce3f487","debugInfo":{"loop":["2","1","3","2"]}} -RCV[2->1]commit 2-0:~- 10 541f608a3ce3f487 2 1 3 2 -Node 1 adjustSent for 2 to -18+10 while processing commit -SEND 1 3 {"command":"commit","probeId":"2-0","amount":10,"preimage":"541f608a3ce3f487","debugInfo":{"loop":["2","1","3","2"]}} -1 is done with current probe 2-0 due to commit -1 is calling whenDone for 2-0 -1 is done with incoming 2-0 -1 is deleting whenDone for 2-0 -RCV[1->3]commit 2-0:~- 10 541f608a3ce3f487 2 1 3 2 -Node 3 adjustSent for 1 to -10+10 while processing commit -SEND 3 2 {"command":"commit","probeId":"2-0","amount":10,"preimage":"541f608a3ce3f487","debugInfo":{"loop":["2","1","3","2"]}} -3 is done with current probe 2-0 due to commit -3 is calling whenDone for 2-0 -3 is done with incoming 2-0 -3 is deleting whenDone for 2-0 -RCV[3->2]commit 2-0:~- 10 541f608a3ce3f487 2 1 3 2 -Node 2 adjustSent for 3 to -12+10 while processing commit -2 is done with current probe 2-0 due to commit -2 is calling whenDone for 2-0 -2 is done with incoming 2-0 -2 is deleting whenDone for 2-0 diff --git a/src/Worker.ts b/src/Worker.ts index a825eed..92ca597 100644 --- a/src/Worker.ts +++ b/src/Worker.ts @@ -217,14 +217,6 @@ export class Worker { await readSarafuCsv(filename, (from: string, to: string, amount: number) => { if (parseInt(from) % this.numWorkers === this.workerNo) { if (parseInt(from) % this.numWorkers === this.workerNo) { - if (parseInt(from) > 3) { - this.debug(`skipping transaction from ${from}`); - return; - } - if (parseInt(to) > 3) { - this.debug(`skipping transaction to ${to}`); - return; - } this.debug(`not skipping transaction from ${from} to ${to}`); this.addWeight(from, to, amount); }