Skip to content

Commit

Permalink
feat!: implement per-worker aliasing [NET-352] (#1449)
Browse files Browse the repository at this point in the history
* feat!: implement per-worker aliasing

* fix tests

* pr fixes

* Update crates/particle-node-tests/tests/spells.rs

* Update sorcerer/src/script_executor.rs

* clippy fixes

* fix fmt
  • Loading branch information
justprosh committed Feb 10, 2023
1 parent f4ef8b5 commit 097d47d
Show file tree
Hide file tree
Showing 14 changed files with 558 additions and 133 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ opt-level = 1

# Enable high optimizations for dependencies, but not for our code:
[profile.dev.package."*"]
inherits = "release"
opt-level = 3
codegen-units = 256

[profile.dev.package.clap]
debug-assertions = false

[profile.release]
strip = true
lto = true
lto = false
codegen-units = 1 # Reduce number of codegen units to increase optimizations
12 changes: 6 additions & 6 deletions aquamarine/src/plumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<RT: AquaRuntime, F: ParticleFunctionStatic> Plumber<RT, F> {
.actors
.entry((particle.id.clone(), scope_peer_id))
.or_insert_with(|| {
let params = ParticleParams::clone_from(&particle);
let params = ParticleParams::clone_from(&particle, scope_peer_id);
let functions = Functions::new(params, builtins.clone());
Actor::new(&particle, functions, scope_peer_id)
});
Expand Down Expand Up @@ -139,11 +139,11 @@ impl<RT: AquaRuntime, F: ParticleFunctionStatic> Plumber<RT, F> {
for actor in self.actors.values_mut() {
if let Poll::Ready(result) = actor.poll_completed(cx) {
interpretation_stats.push(result.stats);
let (local_peers, remote_peers): (Vec<_>, Vec<_>) = result
.effects
.next_peers
.into_iter()
.partition(|p| key_manager.is_scope_peer_id(*p));
let (local_peers, remote_peers): (Vec<_>, Vec<_>) =
result.effects.next_peers.into_iter().partition(|p| {
key_manager.is_scope_peer_id(*p)
|| p.eq(&self.key_manager.get_host_peer_id())
});

if !remote_peers.is_empty() {
remote_effects.push(RoutingEffects {
Expand Down
28 changes: 28 additions & 0 deletions crates/libp2p/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ pub mod peerid_serializer {
}
}

pub mod peerid_serializer_opt {
use libp2p::PeerId;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::str::FromStr;

pub fn serialize<S>(value: &Option<PeerId>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
value.map(|p| p.to_base58()).serialize(serializer)
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<PeerId>, D::Error>
where
D: Deserializer<'de>,
{
let opt: Option<String> = Option::deserialize(deserializer)?;
match opt {
None => Ok(None),
Some(str) => PeerId::from_str(&str)
.map_err(|e| {
serde::de::Error::custom(format!("peer id deserialization failed for {e:?}"))
})
.map(Some),
}
}
}

#[cfg(test)]
mod tests {
use crate::RandomPeerId;
Expand Down
Loading

0 comments on commit 097d47d

Please sign in to comment.