Skip to content

Commit 7d1dfb5

Browse files
committed
feat: extend challenge registry wasm metadata
add wasm module metadata with network policy to registry entries include migration metadata for schema change tracking add wasm runtime interface dependency for registry
1 parent dc276af commit 7d1dfb5

4 files changed

Lines changed: 74 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/challenge-registry/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition.workspace = true
55
description = "Challenge registry and lifecycle management for Platform Network"
66

77
[dependencies]
8+
wasm-runtime-interface = { path = "../wasm-runtime-interface" }
89
platform-core = { path = "../core" }
910
platform-challenge-sdk = { path = "../challenge-sdk" }
1011
platform-storage = { path = "../storage" }
@@ -39,4 +40,4 @@ reqwest = { workspace = true }
3940

4041
[dev-dependencies]
4142
tempfile = { workspace = true }
42-
tokio-test = { workspace = true }
43+
tokio-test = { workspace = true }

crates/challenge-registry/src/migration.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ pub enum MigrationStatus {
2626
RolledBack,
2727
}
2828

29+
/// Migration metadata describing schema changes
30+
#[derive(Clone, Debug, Serialize, Deserialize)]
31+
pub struct MigrationMetadata {
32+
/// Registry schema version when migration starts
33+
pub registry_schema_version: u32,
34+
/// Whether WASM module metadata was introduced
35+
pub adds_wasm_module_metadata: bool,
36+
}
37+
2938
/// A single migration step
3039
#[derive(Clone, Debug, Serialize, Deserialize)]
3140
pub struct MigrationStep {
@@ -41,6 +50,9 @@ pub struct MigrationStep {
4150
pub reversible: bool,
4251
/// Estimated duration in seconds
4352
pub estimated_duration_secs: u64,
53+
/// Optional metadata describing schema changes
54+
#[serde(default)]
55+
pub metadata: Option<MigrationMetadata>,
4456
}
4557

4658
impl MigrationStep {
@@ -58,6 +70,7 @@ impl MigrationStep {
5870
to_version: to,
5971
reversible: true,
6072
estimated_duration_secs: 60,
73+
metadata: None,
6174
}
6275
}
6376

@@ -72,6 +85,12 @@ impl MigrationStep {
7285
self.estimated_duration_secs = secs;
7386
self
7487
}
88+
89+
/// Attach migration metadata
90+
pub fn with_metadata(mut self, metadata: MigrationMetadata) -> Self {
91+
self.metadata = Some(metadata);
92+
self
93+
}
7594
}
7695

7796
/// A plan for migrating a challenge between versions
@@ -253,6 +272,10 @@ impl ChallengeMigration {
253272
to_version.clone(),
254273
)
255274
.irreversible()
275+
.with_metadata(MigrationMetadata {
276+
registry_schema_version: 2,
277+
adds_wasm_module_metadata: true,
278+
})
256279
.with_duration(300),
257280
);
258281
} else if from_version.minor != to_version.minor {
@@ -266,6 +289,10 @@ impl ChallengeMigration {
266289
from_version.clone(),
267290
to_version.clone(),
268291
)
292+
.with_metadata(MigrationMetadata {
293+
registry_schema_version: 2,
294+
adds_wasm_module_metadata: true,
295+
})
269296
.with_duration(60),
270297
);
271298
} else if from_version.patch != to_version.patch {
@@ -279,6 +306,10 @@ impl ChallengeMigration {
279306
from_version,
280307
to_version,
281308
)
309+
.with_metadata(MigrationMetadata {
310+
registry_schema_version: 2,
311+
adds_wasm_module_metadata: true,
312+
})
282313
.with_duration(10),
283314
);
284315
}

crates/challenge-registry/src/registry.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,37 @@ use serde::{Deserialize, Serialize};
1111
use std::collections::HashMap;
1212
use std::sync::Arc;
1313
use tracing::{debug, info, warn};
14+
use wasm_runtime_interface::NetworkPolicy;
15+
16+
/// WASM module metadata for a challenge
17+
#[derive(Clone, Debug, Serialize, Deserialize)]
18+
pub struct WasmModuleMetadata {
19+
/// Hash of the WASM module
20+
pub module_hash: String,
21+
/// Location of the WASM module (URL or path)
22+
pub module_location: String,
23+
/// Entrypoint function name
24+
pub entrypoint: String,
25+
/// Network policy for WASM execution
26+
#[serde(default)]
27+
pub network_policy: NetworkPolicy,
28+
}
29+
30+
impl WasmModuleMetadata {
31+
pub fn new(
32+
module_hash: String,
33+
module_location: String,
34+
entrypoint: String,
35+
network_policy: NetworkPolicy,
36+
) -> Self {
37+
Self {
38+
module_hash,
39+
module_location,
40+
entrypoint,
41+
network_policy,
42+
}
43+
}
44+
}
1445

1546
/// Entry for a registered challenge
1647
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -25,6 +56,9 @@ pub struct ChallengeEntry {
2556
pub docker_image: String,
2657
/// HTTP endpoint for evaluation
2758
pub endpoint: Option<String>,
59+
/// WASM module metadata
60+
#[serde(default)]
61+
pub wasm_module: Option<WasmModuleMetadata>,
2862
/// Current lifecycle state
2963
pub lifecycle_state: LifecycleState,
3064
/// Health status
@@ -46,6 +80,7 @@ impl ChallengeEntry {
4680
version,
4781
docker_image,
4882
endpoint: None,
83+
wasm_module: None,
4984
lifecycle_state: LifecycleState::Registered,
5085
health_status: HealthStatus::Unknown,
5186
registered_at: now,
@@ -63,6 +98,11 @@ impl ChallengeEntry {
6398
self.metadata = metadata;
6499
self
65100
}
101+
102+
pub fn with_wasm_module(mut self, wasm_module: WasmModuleMetadata) -> Self {
103+
self.wasm_module = Some(wasm_module);
104+
self
105+
}
66106
}
67107

68108
/// A registered challenge with its full state

0 commit comments

Comments
 (0)