Skip to content

Commit 67ba214

Browse files
committed
ts: track coordinator versions
1 parent 049147c commit 67ba214

File tree

8 files changed

+36
-22
lines changed

8 files changed

+36
-22
lines changed

architectures/decentralized/solana-authorizer/programs/solana-authorizer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod state;
44
use anchor_lang::prelude::*;
55
use logic::*;
66

7-
declare_id!("PsyAUmhpmiUouWsnJdNGFSX8vZ6rWjXjgDPHsgqPGyw");
7+
declare_id!("9Fama3hhPJWnW2my835ptNR8kQmDH4EdK1hYZ7sGqtbS");
88

99
pub fn find_authorization(
1010
grantor: &Pubkey,
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
[
2-
133, 168, 22, 30, 172, 129, 250, 222, 16, 179, 41, 22, 161, 2, 171, 87, 19,
3-
134, 196, 81, 67, 2, 234, 210, 48, 19, 234, 27, 192, 50, 161, 118, 5, 220,
4-
104, 106, 206, 33, 252, 167, 179, 12, 115, 187, 217, 59, 144, 210, 71, 193,
5-
163, 175, 67, 155, 20, 145, 152, 109, 251, 190, 151, 5, 10, 82
6-
]
1+
[235, 60, 229, 84, 186, 162, 20, 27, 214, 150, 28, 48, 91, 197, 33, 223, 121, 140, 79, 184, 91, 93, 221, 176, 247, 8, 82, 169, 31, 209, 249, 52, 122, 153, 207, 16, 27, 219, 117, 113, 251, 151, 62, 246, 116, 148, 194, 167, 145, 74, 57, 223, 242, 70, 130, 234, 165, 194, 152, 63, 144, 81, 223, 41]

architectures/decentralized/solana-coordinator/programs/solana-coordinator/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use ts_rs::TS;
2929

3030
pub use crate::instance_state::RunMetadata;
3131

32-
declare_id!("HR8RN2TP9E9zsi2kjhvPbirJWA1R6L6ruf4xNNGpjU5Y");
32+
declare_id!("85sDrgwxZSKTuXh28rjUUdkBdKQoYSsw67j8hauiq4Xm");
3333

3434
pub const SOLANA_MAX_NUM_PENDING_CLIENTS: usize = SOLANA_MAX_NUM_CLIENTS;
3535

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[252,0,151,112,226,72,111,48,53,164,217,219,148,181,182,221,30,194,108,107,85,66,193,59,48,103,234,83,198,43,22,202,243,233,81,242,169,6,28,67,34,77,89,164,7,220,33,110,247,29,109,237,215,212,247,134,160,42,48,195,27,19,101,115]
1+
[233, 47, 9, 253, 202, 44, 16, 222, 93, 154, 129, 220, 63, 149, 238, 14, 0, 218, 213, 151, 2, 186, 142, 156, 247, 225, 114, 184, 167, 124, 40, 126, 105, 64, 234, 227, 247, 154, 186, 102, 186, 152, 166, 71, 114, 203, 94, 106, 98, 190, 21, 203, 104, 88, 156, 192, 121, 146, 24, 141, 90, 163, 175, 52]

website/backend/src/coordinator.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
export type UniqueRunKey = `${string}-${string}` & { __uniqueRunKey: true }
1+
export type UniqueRunKey = `${string}-${string}-${string}` & { __uniqueRunKey: true }
22

3-
export function runKey(runId: string, index: number): UniqueRunKey {
4-
return `${runId}-${index}` as UniqueRunKey
3+
export function runKey(programId: string, runId: string, index: number): UniqueRunKey {
4+
return `${programId}-${runId}-${index}` as UniqueRunKey
55
}
66

77
export function getRunFromKey(
88
runKey: UniqueRunKey
9-
): [runId: string, index: number] {
10-
const [runId, index] = splitAtLastInstance(runKey, '-')
11-
return [runId, Number.parseInt(index, 10)]
9+
): [programId: string, runId: string, index: number] {
10+
const parts = runKey.split('-')
11+
if (parts.length < 3) {
12+
// Backward compatibility: assume old format runId-index without programId
13+
const [runId, index] = splitAtLastInstance(runKey, '-')
14+
return ['', runId, Number.parseInt(index, 10)]
15+
}
16+
17+
// New format: programId-runId-index
18+
// Handle case where runId might contain dashes by joining middle parts
19+
const programId = parts[0]
20+
const index = parts[parts.length - 1]
21+
const runId = parts.slice(1, -1).join('-')
22+
23+
return [programId, runId, Number.parseInt(index, 10)]
1224
}
1325

1426
function splitAtLastInstance(text: string, splitAt: string): [string, string] {

website/backend/src/dataStore.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RunSummary, RunData, ContributionInfo, ChainTimestamp } from 'shared'
33
import { PsycheMiningPoolAccount, WitnessMetadata } from './idlTypes.js'
44
import EventEmitter from 'node:events'
55
import { UniqueRunKey } from './coordinator.js'
6+
import { PublicKey } from '@solana/web3.js'
67

78
export interface IndexedSignature {
89
signature: string
@@ -22,6 +23,8 @@ export interface ChainDataStore {
2223

2324
export interface CoordinatorDataStore extends ChainDataStore {
2425
eventEmitter: EventEmitter<{ update: [UniqueRunKey] }>
26+
27+
readonly programId: PublicKey
2528

2629
createRun(
2730
pubkey: string,

website/backend/src/dataStores/flatFileCoordinator.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class FlatFileCoordinatorDataStore implements CoordinatorDataStore {
192192
})
193193

194194
this.#runsMutatedSinceLastSync.add(
195-
runKey(runId, runsAtThisAddress.length - 1)
195+
runKey(this.#programId.toString(), runId, runsAtThisAddress.length - 1)
196196
)
197197
}
198198

@@ -263,7 +263,7 @@ export class FlatFileCoordinatorDataStore implements CoordinatorDataStore {
263263
})
264264
}
265265

266-
this.#runsMutatedSinceLastSync.add(runKey(lastRun.runId, index))
266+
this.#runsMutatedSinceLastSync.add(runKey(this.#programId.toString(), lastRun.runId, index))
267267
}
268268

269269
setRunPaused(pubkey: string, paused: boolean, timestamp: ChainTimestamp) {
@@ -278,7 +278,7 @@ export class FlatFileCoordinatorDataStore implements CoordinatorDataStore {
278278
lastRun.lastUpdated = timestamp
279279
lastRun.pauseTimestamps.push([newPauseState, timestamp])
280280

281-
this.#runsMutatedSinceLastSync.add(runKey(lastRun.runId, index))
281+
this.#runsMutatedSinceLastSync.add(runKey(this.#programId.toString(), lastRun.runId, index))
282282
}
283283

284284
witnessRun(
@@ -427,8 +427,12 @@ export class FlatFileCoordinatorDataStore implements CoordinatorDataStore {
427427
)
428428
}
429429

430+
get programId(): PublicKey {
431+
return this.#programId
432+
}
433+
430434
getRunDataById(runId: string, index: number): RunData | null {
431-
const cachedRun = this.#runCache.get(runKey(runId, index))
435+
const cachedRun = this.#runCache.get(runKey(this.#programId.toString(), runId, index))
432436
if (cachedRun) {
433437
return cachedRun
434438
}
@@ -580,7 +584,7 @@ export class FlatFileCoordinatorDataStore implements CoordinatorDataStore {
580584
history,
581585
},
582586
}
583-
this.#runCache.set(runKey(runId, index), runData)
587+
this.#runCache.set(runKey(this.#programId.toString(), runId, index), runData)
584588
return runData
585589
}
586590
}

website/backend/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async function main() {
8686
coordinator.dataStore.eventEmitter.addListener('update', (key) => {
8787
const listeners = liveRunListeners.get(key)
8888
if (listeners) {
89-
const [runId, index] = getRunFromKey(key)
89+
const [programId, runId, index] = getRunFromKey(key)
9090
const runData = coordinator.dataStore.getRunDataById(runId, index)
9191
if (!runData) {
9292
console.warn(
@@ -262,7 +262,7 @@ async function main() {
262262
return
263263
}
264264

265-
const key = runKey(matchingRun.info.id, matchingRun.info.index)
265+
const key = runKey(coordinator.dataStore.programId.toString(), matchingRun.info.id, matchingRun.info.index)
266266
let listeners = liveRunListeners.get(key)
267267
if (!listeners) {
268268
listeners = new Set()

0 commit comments

Comments
 (0)