Skip to content

Commit

Permalink
feat: Migrate Registry to spell (#1629)
Browse files Browse the repository at this point in the history
  • Loading branch information
gurinderu authored Jun 20, 2023
1 parent f272c02 commit 978ea2c
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 29 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions crates/server-config/src/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,28 @@ pub fn default_decider_spell_period_sec() -> u32 {
120
}

// 60 minutes
// This is an interval setting for a spell in general.
// should be the smallest common denominator of other intervals.
pub fn default_registry_spell_period_sec() -> u32 {
3600
}

// 24 hours
pub fn default_registry_expired_spell_period_sec() -> u32 {
86400
}

// 12 hours
pub fn default_registry_renew_spell_period_sec() -> u32 {
43200
}

// 60 minutes
pub fn default_registry_replicate_spell_period_sec() -> u32 {
3600
}

pub fn default_deal_network_api_endpoint() -> String {
"https://testnet.aurora.dev".to_string()
}
Expand Down
26 changes: 26 additions & 0 deletions crates/server-config/src/system_services_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct SystemServicesConfig {
pub aqua_ipfs: AquaIpfsConfig,
#[serde(default)]
pub decider: DeciderConfig,
#[serde(default)]
pub registry: RegistryConfig,
}

impl Default for SystemServicesConfig {
Expand All @@ -65,6 +67,7 @@ impl Default for SystemServicesConfig {
enable: default_system_services(),
aqua_ipfs: Default::default(),
decider: Default::default(),
registry: Default::default(),
}
}
}
Expand Down Expand Up @@ -114,3 +117,26 @@ impl Default for DeciderConfig {
}
}
}

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct RegistryConfig {
#[serde(default = "default_registry_spell_period_sec")]
pub registry_period_sec: u32,
#[serde(default = "default_registry_expired_spell_period_sec")]
pub expired_period_sec: u32,
#[serde(default = "default_registry_renew_spell_period_sec")]
pub renew_period_sec: u32,
#[serde(default = "default_registry_replicate_spell_period_sec")]
pub replicate_period_sec: u32,
}

impl Default for RegistryConfig {
fn default() -> Self {
Self {
registry_period_sec: default_registry_spell_period_sec(),
expired_period_sec: default_registry_expired_spell_period_sec(),
renew_period_sec: default_registry_renew_spell_period_sec(),
replicate_period_sec: default_registry_replicate_spell_period_sec(),
}
}
}
2 changes: 1 addition & 1 deletion crates/system-services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
aqua-ipfs-distro = "=0.5.14"
decider-distro = "=0.4.15"
registry-distro = "=0.8.5"
registry-distro = "=0.8.7"
trust-graph-distro = "=0.4.5"

maplit = { workspace = true }
Expand Down
52 changes: 26 additions & 26 deletions crates/system-services/src/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use particle_execution::FunctionOutcome;
use particle_modules::{AddBlueprint, ModuleRepository};
use particle_services::{ParticleAppServices, ServiceError, ServiceType};
use serde_json::{json, Value as JValue};
use server_config::system_services_config::RegistryConfig;
use server_config::system_services_config::ServiceKey::*;
use server_config::{system_services_config::ServiceKey, DeciderConfig, SystemServicesConfig};
use sorcerer::{get_spell_info, install_spell, remove_spell};
Expand Down Expand Up @@ -149,12 +150,10 @@ impl Deployer {
}

async fn deploy_registry(&self) -> eyre::Result<()> {
let (registry_distro, registry_spell_distros) = Self::get_registry_distro();
let _deployed = self.deploy_service_common(registry_distro)?;

for spell_distro in registry_spell_distros {
self.deploy_system_spell(spell_distro).await?;
}
let (registry_distro, registry_spell_distro) =
Self::get_registry_distro(self.config.registry.clone());
self.deploy_service_common(registry_distro)?;
self.deploy_system_spell(registry_spell_distro).await?;
Ok(())
}

Expand Down Expand Up @@ -198,29 +197,30 @@ impl Deployer {
}
}

fn get_registry_distro() -> (ServiceDistro, Vec<SpellDistro>) {
use registry_distro::*;

fn get_registry_distro(config: RegistryConfig) -> (ServiceDistro, SpellDistro) {
let distro = ServiceDistro {
modules: modules(),
config: CONFIG,
modules: registry_distro::modules(),
config: registry_distro::CONFIG,
name: Registry.to_string(),
};
let spells_distro = scripts()
.into_iter()
.map(|script| {
let mut trigger_config = TriggerConfig::default();
trigger_config.clock.start_sec = 1;
trigger_config.clock.period_sec = script.period_sec;
SpellDistro {
name: script.name.to_string(),
air: script.air,
kv: HashMap::new(),
trigger_config,
}
})
.collect::<_>();
(distro, spells_distro)

let registry_config = registry_distro::RegistryConfig {
expired_interval: config.expired_period_sec,
renew_interval: config.renew_period_sec,
replicate_interval: config.replicate_period_sec,
};
let spell_distro = registry_distro::registry_spell(registry_config);
let mut trigger_config = TriggerConfig::default();
trigger_config.clock.start_sec = 1;
trigger_config.clock.period_sec = config.registry_period_sec;
let spell_distro = SpellDistro {
name: "registry-spell".to_string(),
air: spell_distro.air,
kv: spell_distro.init_data,
trigger_config,
};

(distro, spell_distro)
}

fn get_ipfs_service_distro() -> ServiceDistro {
Expand Down

0 comments on commit 978ea2c

Please sign in to comment.