Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Sim2h Integration #1744

Merged
merged 55 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0f145c6
sim2h-worker wip
zippy Oct 5, 2019
a73fe98
Merge branch '2019-10-03-update-lib3h' into sim2h
lucksus Oct 6, 2019
497d454
Add GhostWebsocketTransport with initialization code to Sim2hWorker
lucksus Oct 6, 2019
b3e2638
Hook-up all client messages to send wire messages over transport
lucksus Oct 7, 2019
5f78c27
Handle messages coming from sim2h server
lucksus Oct 7, 2019
67f3c1e
Use WireMessage's new conversion function and prevent cloning
lucksus Oct 7, 2019
aad0a39
Fix initialization for Sim2hWorker
lucksus Oct 7, 2019
8fe33ad
Less redundant logs
lucksus Oct 7, 2019
9fbb332
Wiring up messages sim2h -> core with core's handler
lucksus Oct 7, 2019
a27b59f
Add sim2h app-spec config and command
lucksus Oct 7, 2019
b6c4285
Merge branch 'develop' into sim2h
lucksus Oct 7, 2019
e583ac6
Don't use protocol message in the wrong direction
lucksus Oct 8, 2019
ec1a0f8
Wire up leave space
lucksus Oct 8, 2019
2928e85
Merge branch 'develop' into sim2h
zippy Oct 8, 2019
08b8e0f
update cargo lock
zippy Oct 8, 2019
952c02c
Add hc-sim2h-server nix shell command
lucksus Oct 8, 2019
320f92b
Cargo.lock
lucksus Oct 8, 2019
9c07d00
Switch app-spec over to sim2h
lucksus Oct 8, 2019
8bb0923
Merge branch 'develop' into sim2h
lucksus Oct 8, 2019
53998d7
Cargo.lock
lucksus Oct 8, 2019
0e37559
Apply suggestions from code review
zippy Oct 9, 2019
4704ec6
re-enable sim1h app-spec too
zippy Oct 9, 2019
f3d6ad1
Use wss protocol in sim2h config
lucksus Oct 9, 2019
f472784
Clarifying comments
lucksus Oct 9, 2019
886150d
Merge branch 'develop' into sim2h
lucksus Oct 9, 2019
a9f4d31
Switch lib3h dep over to transport-disconnect branch
lucksus Oct 9, 2019
e5e4e26
Switch sim1h dep to develop
lucksus Oct 9, 2019
4cade7a
Cargo.lock
lucksus Oct 9, 2019
54709a4
Resend JoinSpace if we get Limbo error from sim2h
lucksus Oct 9, 2019
8c884b7
Merge branch 'sim2h' of github.com:holochain/holochain-rust into sim2h
lucksus Oct 9, 2019
5350d3e
Transform publish messages to store locally
lucksus Oct 9, 2019
778f91e
updated to use sim2h handshaking
zippy Oct 9, 2019
c374752
Merge branch 'develop' into sim2h
lucksus Oct 9, 2019
1ef69d7
add zombie_actor to deptool
zippy Oct 10, 2019
27f6ba6
remove signature challenge sim2h
zippy Oct 10, 2019
04a0d13
Let hc-sim2h-server proxy arguments to binary
lucksus Oct 10, 2019
23a5119
Set cluster-test to use sim2h
lucksus Oct 10, 2019
86977eb
Configure websocket to be secure with entropy certificate
lucksus Oct 10, 2019
293dc3b
Don't let transport errors kill the network thread, just log error.
lucksus Oct 10, 2019
dffe1f1
Send Ping on error to reestablish connection
lucksus Oct 10, 2019
4afb893
Move ConductorApi from into its own crate
lucksus Oct 11, 2019
d4ed54e
Have Sim2Worker send SignedWireMessages
lucksus Oct 11, 2019
a8e8863
rustfmt
lucksus Oct 11, 2019
f916fe8
Merge branch 'develop' into sim2h
lucksus Oct 11, 2019
c5ada9b
Remove empty test
lucksus Oct 11, 2019
f9340a1
changelog
lucksus Oct 11, 2019
c9874ac
Set sim2h dependency to master
lucksus Oct 11, 2019
c168653
Merge branch 'sim1h' of github.com:holochain/holochain-rust into sim2h
lucksus Oct 11, 2019
36fb968
Fix P2pNetwork test
lucksus Oct 11, 2019
84994bf
Implement new events for websocket actor
lucksus Oct 11, 2019
b39f5a7
Cargo.lock
lucksus Oct 11, 2019
5d94485
Log error when sending ping
lucksus Oct 11, 2019
9b9b7a2
Make sure we only bind to IPv4 interfaces
lucksus Oct 11, 2019
c476432
Merge branch 'sim2h' of github.com:holochain/holochain-rust into sim2h
lucksus Oct 11, 2019
4293b86
Remove unused tick counter
lucksus Oct 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ jobs:
name: app spec tests
command: nix-shell --run hc-app-spec-test-sim1h

app-spec-tests-sim2h:
docker:
- image: holochain/holochain-rust:latest
resource_class: xlarge
steps:
- checkout
- run:
name: sim2h server
command: nix-shell --run hc-sim2h-server
background: true
- run:
name: app spec tests
command: nix-shell --run hc-app-spec-test-sim2h
# app-spec-tests-n3h:
# docker:
# - image: holochain/holochain-rust:latest
Expand Down Expand Up @@ -128,8 +141,8 @@ jobs:
steps:
- checkout
- run:
name: DynamoDB
command: nix-shell --run "dynamodb-memory -port 8002"
name: sim2h server
command: nix-shell --run "hc-sim2h-server -p 9001"
background: true
- run:
name: app spec cluster tests
Expand Down Expand Up @@ -226,6 +239,7 @@ workflows:
- build
- fmt
- app-spec-tests-sim1h
- app-spec-tests-sim2h
Connoropolous marked this conversation as resolved.
Show resolved Hide resolved
# - app-spec-tests-memory
# - app-spec-tests-websocket
# @todo reimplement proc tests properly
Expand Down
25 changes: 24 additions & 1 deletion CHANGELOG-UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,30 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
{{ version-heading }}

### Added

* Adds a network back-end: `sim2h` and all corresponding integration. [#1744](https://github.com/holochain/holochain-rust/pull/1744)

[Sim2h](https://github.com/holochain/sim2h) is the next iteration of sim1h.
In contrast to sim1h, it does not use a centralized database but a
centralized in-memory network that connects Holochain instances
like a switch-board.

It is much faster than sim1h and will be able to implement Holochain
membranes based on the agent IDs and the `validate_agent` callback.

It can be used by configuring conductors like so:
```toml
[network]
type = "sim2h"
sim2h_url = "wss://localhost:9000"
```
with `sim2h_url` pointing to a running `sim2h_server` instance.

This also adds nix-shell commands:
- `hc-sim2h-server` which starts the server part with debug logs on
port 9000 (can be changed with `-p`)
- `hc-app-spec-test-sim2h` which runs the integration tests with
networking configured to sim2h (expects to find a running
sim2h_server on localhost:9000)
### Changed

### Deprecated
Expand Down
266 changes: 204 additions & 62 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ members = [
"common",
"conductor",
"conductor_api",
"conductor_api_api",
"conductor_wasm",
"core_api_c_binding",
"core",
Expand Down
19 changes: 18 additions & 1 deletion app_spec/test/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,24 @@ let
hc-conductor-install
(cd app_spec && APP_SPEC_NETWORK_TYPE="sim1h" ./build_and_test.sh);
'';

name-sim2h = "hc-app-spec-test-sim2h";

script-sim2h = pkgs.writeShellScriptBin name-sim2h ''
set -euo pipefail
hc-cli-install
hc-conductor-install
(cd app_spec && APP_SPEC_NETWORK_TYPE="sim2h" ./build_and_test.sh);
'';

name-sim2h-server = "hc-sim2h-server";

script-sim2h-server = pkgs.writeShellScriptBin name-sim2h-server ''
set -euo pipefail
cargo install sim2h_server -f --git https://github.com/holochain/sim2h
RUST_LOG=debug sim2h_server "$@"
'';
in
{
buildInputs = [ script-n3h script-memory script-sim1h ];
buildInputs = [ script-n3h script-memory script-sim1h script-sim2h script-sim2h-server ];
}
15 changes: 15 additions & 0 deletions app_spec/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ if (process.env.APP_SPEC_NETWORK_TYPE === "sim1h")
);
}

if (process.env.APP_SPEC_NETWORK_TYPE === "sim2h")
{
transport_config = {
type: 'sim2h',
sim2h_url: "wss://localhost:9000",
}

// omit singleConductor
middleware = combine(
// dumbWaiter(1000),
callSyncMiddleware,
tapeExecutor(require('tape')),
);
}

const orchestrator = new Orchestrator({
middleware,
waiter: {
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ holochain_core = { path = "../core" }
holochain_common = { path = "../common" }
holochain_conductor_api = { path = "../conductor_api" }
holochain_dpki = { path = "../dpki" }
lib3h_sodium = { version = "=0.0.13" }
lib3h_sodium = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
holochain_json_api = "=0.0.17"
holochain_persistence_api = "=0.0.8"
holochain_persistence_file = "=0.0.8"
Expand Down
2 changes: 1 addition & 1 deletion conductor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Holochain Core Dev Team <devcore@holochain.org>"]
[dependencies]
holochain_core_types = { path = "../core_types" }
holochain_conductor_api = { path = "../conductor_api" }
lib3h_sodium = { version = "=0.0.13" }
lib3h_sodium = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
holochain_common = { path = "../common" }
structopt = "=0.2.15"
tiny_http = "=0.6.2"
Expand Down
4 changes: 2 additions & 2 deletions conductor_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ holochain_persistence_file = "=0.0.8"
holochain_persistence_pickle = "=0.0.8"
holochain_dpki = { path = "../dpki" }
holochain_net = { path = "../net" }
lib3h = { version = "=0.0.13" }
lib3h_sodium = { version = "=0.0.13" }
lib3h = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
lib3h_sodium = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
holochain_common = { path = "../common" }
chrono = "=0.4.6"
serde = "=1.0.89"
Expand Down
16 changes: 13 additions & 3 deletions conductor_api/src/conductor/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ impl Conductor {
}
NetworkConfig::Memory(_) => unimplemented!(),
NetworkConfig::Sim1h(_) => unimplemented!(),
NetworkConfig::Sim2h(_) => unimplemented!(),
NetworkConfig::Lib3h(_) => Err(HolochainError::ErrorGeneric(
"Lib3h Network not implemented".to_string(),
)),
Expand Down Expand Up @@ -636,9 +637,13 @@ impl Conductor {
);
// create an empty network with this config just so the n3h process doesn't
// kill itself in the case that all instances are closed down (as happens in app-spec)
let network =
P2pNetwork::new(NetHandler::new(Box::new(|_r| Ok(()))), config.clone())
.expect("unable to create conductor keepalive P2pNetwork");
let network = P2pNetwork::new(
NetHandler::new(Box::new(|_r| Ok(()))),
config.clone(),
None,
None,
)
.expect("unable to create conductor keepalive P2pNetwork");
self.n3h_keepalive_network = Some(network);
config
}
Expand All @@ -657,6 +662,11 @@ impl Conductor {
backend_config: BackendConfig::Sim1h(config),
maybe_end_user_config: None,
},
NetworkConfig::Sim2h(config) => P2pConfig {
backend_kind: P2pBackendKind::SIM2H,
backend_config: BackendConfig::Sim2h(config),
maybe_end_user_config: None,
},
}
}

Expand Down
3 changes: 2 additions & 1 deletion conductor_api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use holochain_json_api::json::JsonString;
use holochain_persistence_api::cas::content::AddressableContent;
use lib3h::engine::EngineConfig;

use holochain_net::sim1h_worker::Sim1hConfig;
use holochain_net::{sim1h_worker::Sim1hConfig, sim2h_worker::Sim2hConfig};
use petgraph::{algo::toposort, graph::DiGraph, prelude::NodeIndex};
use serde::Deserialize;
use std::{
Expand Down Expand Up @@ -832,6 +832,7 @@ pub enum NetworkConfig {
Lib3h(EngineConfig),
Memory(EngineConfig),
Sim1h(Sim1hConfig),
Sim2h(Sim2hConfig),
}

#[derive(Deserialize, Serialize, PartialEq, Debug, Clone)]
Expand Down
14 changes: 14 additions & 0 deletions conductor_api_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AshantiMutinta, take note of this new crate. It only includes this ConductorApi struct which is a proxy for the conductor api that does not depend on anything in the conductor_api crate - which is good because we can't depend on that in the net crate without creating cyclic dependencies. ConductorApi was in core before we can't depend on that either.

With the repository clean-up that we discussed yesterday, I would suggest with rename this crate to conductor_api since the current conductor_api will be conductor_lib, right?

name = "holochain_conductor_api_api"
version = "0.0.32-alpha2"
authors = ["Holochain Core Dev Team <devcore@holochain.org>"]
edition = "2018"

[dependencies]
holochain_core_types = { path = "../core_types" }
holochain_wasm_utils = { path = "../wasm_utils" }
jsonrpc-core = { git = "https://github.com/holochain/jsonrpc", branch = "broadcaster-getter" }
jsonrpc-lite = "=0.5.0"
serde = { version = "=1.0.89", features = ["rc"] }
serde_json = { version = "=1.0.39", features = ["preserve_order"] }
snowflake = "=1.3.0"
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use holochain_core_types::{error::HolochainError, sync::HcRwLock as RwLock};
use holochain_wasm_utils::api_serialization::crypto::CryptoMethod;
use jsonrpc_core::IoHandler;
use jsonrpc_lite::JsonRpc;
use snowflake::ProcessUniqueId;
use std::{fmt, sync::Arc};

use holochain_wasm_utils::api_serialization::crypto::CryptoMethod;

#[derive(Clone)]
pub struct ConductorApi(Arc<RwLock<IoHandler>>);

Expand Down
3 changes: 3 additions & 0 deletions conductor_api_api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod conductor_api;
pub use conductor_api::ConductorApi;
pub use holochain_wasm_utils::api_serialization::crypto::CryptoMethod;
5 changes: 3 additions & 2 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ toml = "=0.5.0"
holochain_net = { path = "../net" }
holochain_wasm_utils = { path = "../wasm_utils"}
holochain_common = { path = "../common" }
lib3h_protocol = { version = "=0.0.13" }
lib3h_sodium = { version = "=0.0.13" }
holochain_conductor_api_api = { path = "../conductor_api_api" }
lib3h_protocol = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
lib3h_sodium = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
holochain_json_derive = "=0.0.17"
holochain_json_api = "=0.0.17"
holochain_persistence_api = "=0.0.8"
Expand Down
9 changes: 2 additions & 7 deletions core/src/agent/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,8 @@ pub fn create_entry_with_header_for_header(
chain_header: ChainHeader,
) -> Result<EntryWithHeader, HolochainError> {
let entry = Entry::ChainHeader(chain_header);
let header = create_new_chain_header(
&entry,
&root_state.agent(),
&root_state,
&None,
&Vec::new(),
)?;
let header =
create_new_chain_header(&entry, &root_state.agent(), &root_state, &None, &Vec::new())?;
Ok(EntryWithHeader { entry, header })
}

Expand Down
8 changes: 2 additions & 6 deletions core/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{
action::{Action, ActionWrapper},
conductor_api::ConductorApi,
instance::Observer,
network::state::NetworkState,
nucleus::actions::get_entry::get_entry_from_cas,
Expand All @@ -12,6 +11,7 @@ use futures::{task::Poll, Future};

use crate::state::StateWrapper;
use futures::task::noop_waker_ref;
use holochain_conductor_api_api::ConductorApi;
use holochain_core_types::{
agent::AgentId,
dna::{wasm::DnaWasm, Dna},
Expand All @@ -27,7 +27,6 @@ use holochain_core_types::{
HcRwLockReadGuard as RwLockReadGuard,
},
};

use holochain_net::{p2p_config::P2pConfig, p2p_network::P2pNetwork};
use holochain_persistence_api::{
cas::{
Expand Down Expand Up @@ -199,10 +198,7 @@ impl Context {
/// is occupied already.
/// Also returns None if the context was not initialized with a state.
pub fn try_state(&self) -> Option<RwLockReadGuard<StateWrapper>> {
self.state
.as_ref()
.map(|s| s.try_read())
.unwrap_or(None)
self.state.as_ref().map(|s| s.try_read()).unwrap_or(None)
}

pub fn network(&self) -> P2pNetworkWrapper {
Expand Down
3 changes: 0 additions & 3 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,3 @@ pub mod signal;
pub mod state;
pub mod state_dump;
pub mod workflows;

mod conductor_api;

6 changes: 4 additions & 2 deletions core/src/network/reducers/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ use crate::{
state::State,
};
use holochain_net::{connection::net_connection::NetSend, p2p_network::P2pNetwork};
use lib3h_protocol::{data_types::SpaceData, protocol_client::Lib3hClientProtocol};
use lib3h_protocol::{data_types::SpaceData, protocol_client::Lib3hClientProtocol, Address};

pub fn reduce_init(state: &mut NetworkState, _root_state: &State, action_wrapper: &ActionWrapper) {
pub fn reduce_init(state: &mut NetworkState, root_state: &State, action_wrapper: &ActionWrapper) {
let action = action_wrapper.action();
let network_settings = unwrap_to!(action => Action::InitNetwork);
let network = P2pNetwork::new(
network_settings.handler.clone(),
network_settings.p2p_config.clone(),
Some(Address::from(network_settings.agent_id.clone())),
Some(root_state.conductor_api.clone()),
)
.unwrap();

Expand Down
3 changes: 1 addition & 2 deletions core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
chain_store::ChainStore,
state::{AgentState, AgentStateSnapshot},
},
conductor_api::ConductorApi,
context::Context,
dht::dht_store::DhtStore,
network::state::NetworkState,
Expand All @@ -18,7 +17,7 @@ use holochain_core_types::{
error::{HcResult, HolochainError},
sync::{HcRwLock as RwLock},
};

use holochain_conductor_api_api::ConductorApi;
use holochain_persistence_api::{
cas::{
content::{Address, AddressableContent},
Expand Down
4 changes: 2 additions & 2 deletions core_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ hcid = "=0.0.6"
rust-base58 = "=0.0.4"
snowflake = "=1.3.0"
objekt= "=0.1.2"
lib3h_crypto_api = { version = "=0.0.13" }
holochain_persistence_api = "=0.0.8"
holochain_json_derive = "=0.0.17"
holochain_json_api = "=0.0.17"
uuid = { version = "=0.7.1", features = ["v4"] }
regex = "=1.1.2"
shrinkwraprs = "=0.2.1"
crossbeam-channel = "=0.3.8"
lib3h_protocol = { version = "=0.0.13" }
lib3h_crypto_api = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
lib3h_protocol = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
parking_lot ="=0.9.0"
log = "=0.4.8"
logging = { path = "../logging" }
Expand Down
2 changes: 1 addition & 1 deletion dpki/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
lazy_static = "=1.2.0"
base64 = "=0.10.1"
holochain_core_types = { path = "../core_types" }
lib3h_sodium = { version = "=0.0.13" }
lib3h_sodium = { git = "https://github.com/holochain/lib3h", branch = "transport-disconnect" }
holochain_persistence_api = "=0.0.8"
serde = "=1.0.89"
serde_derive = "=1.0.89"
Expand Down
4 changes: 2 additions & 2 deletions hc_cluster_test/spawn_conductors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ ${debugging ? '' : 'exclude = true'}
${debugging ? '': 'pattern = "^debug"'}

[network]
type = "sim1h"
dynamo_url = "http://localhost:8002"
type = "sim2h"
sim2h_url = "wss://localhost:9001"
`

return { config, adminPort, instancePort }
Expand Down
Loading