Rust-Holochain rust: Holochain — Scalable P2P alternative to blockchain for all those distributed apps you always wanted to build

Holochain-rust

holochain logo

Project Chat

Twitter Follow

Travis: Build Status Circle CI: CircleCI Codecov: Codecov License: License: GPL v3

This is the home of the Holochain Rust libraries.

This code is loosely based on the Golang prototype.

Code Status: Rust version is alpha. Not for production use. The code is guaranteed NOT secure. We will aggressively restructure code APIs and data chains until Beta.

Releases happen weekly.

Holochain Links: FAQ Developer Docs White Paper

Overview

Holochain-Rust Architectural Overview

Application Developer

Setup a development environment with the latest release to build Holochain applications:

https://developer.holochain.org/start.html

Core Developer

Setup a core development environment to work on Holochain itself:

Core Developer Setup

Documentation

API Reference

Auto generated documentation for all of the code written in Rust is published online, with different versions to match the releases here: https://developer.holochain.org/docs/api.

The Holochain Guidebook

There is a guide for understanding and developing with Holochain. It is published online, with different versions to match the releases here: https://developer.holochain.org/guide.

See instructions for how to contribute to the book at doc/holochain_101/src/how_to_contribute.md.

Contribute

Holochain is an open source project. We welcome all sorts of participation and are actively working on increasing surface area to accept it. Please see our contributing guidelines for our general practices and protocols on participating in the community, as well as specific expectations around things like code formatting, testing practices, continuous integration, etc.

Some helpful links:

License

License: GPL v3

Copyright (C) 2017 - 2019, Holochain Foundation

This program is free software: you can redistribute it and/or modify it under the terms of the license p rovided in the LICENSE file (GPLv3). This program is distributed in the hope that it will be useful, bu t WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Note: We are considering other 'looser' licensing options (like MIT license) but at this stage are using GPL while we're getting the matter sorted out. See this article for some of our thinking on licensing for distributed application frameworks.

Comments

  • Fix for Async Zome Calls
    Fix for Async Zome Calls

    May 28, 2020

    PR summary

    Redo PR# 2179

    testing/benchmarking notes

    ( if any manual testing or benchmarking was/should be done, add notes and/or screenshots here )

    followups

    ( any new tickets/concerns that were discovered or created during this work but aren't in scope for review here )

    changelog

    • [ ] if this is a code change that effects some consumer (e.g. zome developers) of holochain core, then it has been added to our between-release changelog with the format
    - summary of change [PR#1234](https://github.com/holochain/holochain-rust/pull/1234)
    

    documentation

    Reply
  • Update tarpaulin attributes
    Update tarpaulin attributes

    Jun 27, 2020

    PR summary

    So in 0.13.4 (yanked) tarpaulin actually started passing --cfg=tarpaulin so users could do #[cfg_attr(tarpaulin, ignore)] to ignore certain tests in coverage and also conditionally include/exclude code in coverage. This had the unintended result of breaking the recommended skip attr.

    Because of that 0.13.4 was yanked and later on a 0.14.0 version released which still did --cfg=tarpaulin but also --cfg=tarpaulin_include so that code could now be skipped but still included if you did #[cfg(not(tarpaulin_include))]. There's also an unstable #[tarpaulin::skip] tool attribute for those using nightly.

    This PR changes time to use the new attributes as a user of time and tarpaulin found this broke their coverage CI.

    Link to relevant tarpaulin issue: xd009642/tarpaulin#487

    testing/benchmarking notes

    I struggled to get holochain building and running coverage on it. Still working on that but it shouldn't functionally impact any code just driving the tarpaulin source analysis and exclusion functionality.

    Reply
  • Do Not Merge (will be merged with #2203):  re-enable tls
    Do Not Merge (will be merged with #2203): re-enable tls

    Jul 30, 2020

    • reenable TLS security on sim2h websocket connections
    • switch to using elliptic curve for TLS certificate
    Reply
  • Holo
    Holo

    Oct 8, 2020

                                                                                                                                                                                                           
    Reply
  • Formatting fixup
    Formatting fixup

    Mar 30, 2021

    PR summary

    Just updated FAQ for basic fixup

    Reply
  • staking
    staking

    May 5, 2021

    algorithm that has a staking function

    Reply
  • Failing to compile futures-util-preview v0.3.0-alpha.11 (tag =
    Failing to compile futures-util-preview v0.3.0-alpha.11 (tag = "v0.0.3" in Cargo.toml)

    Jan 16, 2019

    OS: Windows mingw64.

    I've cargo cleaned and cargo updated, still doesn't work. Nightly toolchain is up to date. Tried both tag = "v0.0.3" and branch = "develop"

    Cargo.toml

    [package]
    name = "articles"
    version = "0.1.0"
    authors = ["marcusnewton1 <[email protected]>"]
    edition = "2018"
    
    [dependencies]
    serde = "1.0"
    serde_json = "1.0"
    serde_derive = "1.0"
    hdk = { git = "https://github.com/holochain/holochain-rust" , tag = "v0.0.3" }
    holochain_wasm_utils = { git = "https://github.com/holochain/holochain-rust" , tag = "v0.0.3" }
    holochain_core_types_derive = { git = "https://github.com/holochain/holochain-rust" , tag = "v0.0.3" }
    
    [lib]
    path = "src/lib.rs"
    crate-type = ["cdylib"]
    

    Console output

       Compiling futures-util-preview v0.3.0-alpha.11 (https://github.com/holochain/futures-rs?branch=pinned-to-alpha-11#dd9acd0b)
    error[E0308]: mismatched types
       --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\future\maybe_done.rs:110:18
        |
    110 |         Pin::set(self, MaybeDone::Done(res));
        |                  ^^^^
        |                  |
        |                  expected mutable reference, found struct `std::pin::Pin`
        |                  help: consider mutably borrowing here: `&mut self`
        |
        = note: expected type `&mut std::pin::Pin<_>`
                   found type `std::pin::Pin<&mut future::maybe_done::MaybeDone<Fut>>`
    
    error[E0308]: mismatched types
      --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\future\fuse.rs:53:18
       |
    53 |         Pin::set(self.as_mut().future(), None);
       |                  ^^^^^^^^^^^^^^^^^^^^^^
       |                  |
       |                  expected mutable reference, found struct `std::pin::Pin`
       |                  help: consider mutably borrowing here: `&mut self.as_mut().future()`
       |
       = note: expected type `&mut std::pin::Pin<_>`
                  found type `std::pin::Pin<&mut std::option::Option<Fut>>`
    
    error[E0308]: mismatched types
      --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\future\into_stream.rs:39:18
       |
    39 |         Pin::set(self.as_mut().future(), None);
       |                  ^^^^^^^^^^^^^^^^^^^^^^
       |                  |
       |                  expected mutable reference, found struct `std::pin::Pin`
       |                  help: consider mutably borrowing here: `&mut self.as_mut().future()`
       |
       = note: expected type `&mut std::pin::Pin<_>`
                  found type `std::pin::Pin<&mut std::option::Option<Fut>>`
    
    error[E0308]: mismatched types
      --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\try_future\flatten_sink.rs:62:18
       |
    62 |         Pin::set(self.as_mut(), FlattenSink(Ready(resolved_stream)));
       |                  ^^^^^^^^^^^^^
       |                  |
       |                  expected mutable reference, found struct `std::pin::Pin`
       |                  help: consider mutably borrowing here: `&mut self.as_mut()`
       |
       = note: expected type `&mut std::pin::Pin<_>`
                  found type `std::pin::Pin<&mut try_future::flatten_sink::FlattenSink<Fut, Si>>`
    
    error[E0308]: mismatched types
       --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\try_future\flatten_sink.rs:102:22
        |
    102 |             Pin::set(self, FlattenSink(Closed));
        |                      ^^^^
        |                      |
        |                      expected mutable reference, found struct `std::pin::Pin`
        |                      help: consider mutably borrowing here: `&mut self`
        |
        = note: expected type `&mut std::pin::Pin<_>`
                   found type `std::pin::Pin<&mut try_future::flatten_sink::FlattenSink<Fut, Si>>`
    
    error[E0308]: mismatched types
      --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\stream\unfold.rs:99:22
       |
    99 |             Pin::set(self.as_mut().fut(), Some(fut));
       |                      ^^^^^^^^^^^^^^^^^^^
       |                      |
       |                      expected mutable reference, found struct `std::pin::Pin`
       |                      help: consider mutably borrowing here: `&mut self.as_mut().fut()`
       |
       = note: expected type `&mut std::pin::Pin<_>`
                  found type `std::pin::Pin<&mut std::option::Option<Fut>>`
    
    error[E0308]: mismatched types
      --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\try_stream\try_for_each.rs:52:22
       |
    52 |             Pin::set(self.as_mut().future(), None);
       |                      ^^^^^^^^^^^^^^^^^^^^^^
       |                      |
       |                      expected mutable reference, found struct `std::pin::Pin`
       |                      help: consider mutably borrowing here: `&mut self.as_mut().future()`
       |
       = note: expected type `&mut std::pin::Pin<_>`
                  found type `std::pin::Pin<&mut std::option::Option<Fut>>`
    
    error[E0308]: mismatched types
      --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\try_stream\try_for_each.rs:57:30
       |
    57 |                     Pin::set(self.as_mut().future(), Some(future));
       |                              ^^^^^^^^^^^^^^^^^^^^^^
       |                              |
       |                              expected mutable reference, found struct `std::pin::Pin`
       |                              help: consider mutably borrowing here: `&mut self.as_mut().future()`
       |
       = note: expected type `&mut std::pin::Pin<_>`
                  found type `std::pin::Pin<&mut std::option::Option<Fut>>`
    
    error[E0308]: mismatched types
       --> C:\Users\Marcus\.cargo\git\checkouts\futures-rs-d2a1cd193ada173b\dd9acd0\futures-util\src\sink\with_flat_map.rs:105:18
        |
    105 |         Pin::set(stream, None);
        |                  ^^^^^^
        |                  |
        |                  expected mutable reference, found struct `std::pin::Pin`
        |                  help: consider mutably borrowing here: `&mut stream`
        |
        = note: expected type `&mut std::pin::Pin<_>`
                   found type `std::pin::Pin<&mut std::option::Option<St>>`
    
    error: aborting due to 9 previous errors
    
    For more information about this error, try `rustc --explain E0308`.
    error: Could not compile `futures-util-preview`.
    
    Reply
  • UnresolvedDependencies error should not actually be an 'err'
    UnresolvedDependencies error should not actually be an 'err'

    May 30, 2019

    while running the nix-shell --run hc-app-spec-cluster-test bumped up to 8 nodes, we start seeing some erroneous behaviours.

    It seems to be affecting both workflow/hold_entry and workflow/hold_link.

    Some nodes successfully Hold the entry or link, while others don't, the ones that don't show:

    [C2] 2019-05-29 20:14:10 ThreadId(1):test-1: err/workflow/hold_entry: QmUFxhsmL1krv59jL9rRQBKj8Jn311Tpz95KjR7zKEariU is NOT valid! UnresolvedDependencies([HashString("HcSCitO5WWuzmbyf7sfBZp7Oq5Y58Wkq7wvMA4gP4r364ideWxQkpHjko4ndrni"), HashString("QmWY98zemN4Mi9A9SgmC8vQufaQUf5a13Xe81PfWDvvnn9")])
    
    ...
    
    [C3] 2019-05-29 20:14:10 ThreadId(1):test-1: err/workflow/hold_entry: QmUFxhsmL1krv59jL9rRQBKj8Jn311Tpz95KjR7zKEariU is NOT valid! UnresolvedDependencies([HashString("HcSCitO5WWuzmbyf7sfBZp7Oq5Y58Wkq7wvMA4gP4r364ideWxQkpHjko4ndrni"), HashString("QmWY98zemN4Mi9A9SgmC8vQufaQUf5a13Xe81PfWDvvnn9")])
    
    ...
    
    [C4] 2019-05-29 20:14:10 ThreadId(1):test-1: debug/workflow/hold_link: invalid! UnresolvedDependencies([HashString("HcSCitO5WWuzmbyf7sfBZp7Oq5Y58Wkq7wvMA4gP4r364ideWxQkpHjko4ndrni"), HashString("QmWY98zemN4Mi9A9SgmC8vQufaQUf5a13Xe81PfWDvvnn9")])
    2019-05-29 20:14:10 ThreadId(1):test-1: err/workflow/hold_entry: QmUFxhsmL1krv59jL9rRQBKj8Jn311Tpz95KjR7zKEariU is NOT valid! UnresolvedDependencies([HashString("HcSCitO5WWuzmbyf7sfBZp7Oq5Y58Wkq7wvMA4gP4r364ideWxQkpHjko4ndrni"), HashString("QmWY98zemN4Mi9A9SgmC8vQufaQUf5a13Xe81PfWDvvnn9")])
    
    ...
    
    [C7] 2019-05-29 20:14:10 ThreadId(1):test-1: err/workflow/hold_entry: QmUFxhsmL1krv59jL9rRQBKj8Jn311Tpz95KjR7zKEariU is NOT valid! UnresolvedDependencies([HashString("HcSCitO5WWuzmbyf7sfBZp7Oq5Y58Wkq7wvMA4gP4r364ideWxQkpHjko4ndrni"), HashString("QmWY98zemN4Mi9A9SgmC8vQufaQUf5a13Xe81PfWDvvnn9")])
    

    My test shows that we should see 16 successful Hold actions, but we only see 12, corresponding to these 4 which failed

    Reproduce

    Change the following line in /holonix/app-spec-cluster/src/test.nix:

    ( EMULATION_HOLOCHAIN_BIN_PATH=./.cargo/bin/holochain node ./app_spec/cluster_test/index.js 2 )
    

    to

    ( EMULATION_HOLOCHAIN_BIN_PATH=./.cargo/bin/holochain node ./app_spec/cluster_test/index.js 8 true )
    

    also change the timeout of 5 seconds in /app_spec/cluster_test/index.js from 5000 to 20000 to give it more time to complete and show you the results.

    Then run nix-shell --run hc-app-spec-cluster-test

    bug 
    Reply
  • Check currently installed version of Rust, offer to un/re-install (OLD: See #782)
    Check currently installed version of Rust, offer to un/re-install (OLD: See #782)

    Nov 28, 2018

    o Properly export PATH (in case this is the first installation of Rust) o Use target-specific variables to select TOOLS/CORE_RUST_VERSION

    If the wrong version of Rust is installed, we can check and offer to replace it with one compatible with holochain-rust.

    Reply
  • Keypair Derivation (HC-dpki lib)
    Keypair Derivation (HC-dpki lib)

    Jan 15, 2019

    Holochain crypto is based on NACL / libsodium.

    Keypair is a bit of a misnomer. It is more of a pair of keypairs. A holochain "keypair" is made up of both a signing keypair and a key exchange keypair for use in encryption. Both pairs are derived from a common seed.

    • signature keypair - crypto_sign_seed_keypair Ed25519
    • encryption keypair - crypto_kx_seed_keypair BLAKE2B-512
    Reply
  • [upstream issue] Warnings with nix on Manjaro Archlinux `warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring`
    [upstream issue] Warnings with nix on Manjaro Archlinux `warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring`

    Oct 22, 2019

    These warnings are misleading as suggested here on the Discourse forum and can be ignored.

    warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
    warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
    

    They are the warnings that appear after uninstalling and reinstalling and entering the nix-shell (including by running nh):

    $ sudo rm -rf /nix /etc/nix /root/.nix-* /home/*/.nix-*
    zsh: no matches found: /root/.nix-*
    
     23:32:53  ✘  [email protected]  ~/hcr  ⬡ v8.16.0  ? 1.33.0-nightly   946-feature-chain-pair ✔ ⬆ 
    $ sudo rm -rf /nix /etc/nix /home/*/.nix-*             
    [sudo] password for jr: 
    
    $ alias cn
    cn='curl https://nixos.org/nix/install | sh'
    
     23:33:11  [email protected]  ~/hcr  ⬡ v8.16.0  ? 1.33.0-nightly   946-feature-chain-pair ✔ ⬆  6s 
    $ cn
    
    $ . /home/jr/.nix-profile/etc/profile.d/nix.sh
    
    $ alias nh
    nh='nix-shell https://holochain.love'
    
    $ nh
    warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
    warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels/nixpkgs' does not exist, ignoring
    
    [nix-shell:~/hcr]$ 
    

    So it seems unnecessary with trying to fix the warnings by doing things like those listed in https://forum.holochain.org/t/ubuntu-and-debian-troubleshooting-brain-dump/1007. If they cause CI issues down the track that would be problematic, but that could be handled if the issue arises.

    Outdated:

    Tasks:

    • [ ] resolve being able run curl https://nixos.org/nix/install | sh on (Manjaro) Archlinux rather than installing nix from NixOS/nix#3154.
    • [x] update docs from curl https://nixos.org/nix/instal to curl https://nixos.org/nix/install | sh.

    To install nix, recently and just today I tried using curl https://nixos.org/nix/install from https://developer.holochain.org/docs/install/, however, that just outputted the script. So I then tried piping with zsh and sh: curl https://nixos.org/nix/install | zsh. I was then able to run nix-shell, however I found that on logging out and in I was no longer able to run it—the command wasn't found. So I ran yay -a nix 2>&1 | tee nix-install-yay.txt. The command appears to be stuck in a loop, with cycling between different errors: nix-install-yay.txt

    Reply
  • [WIP] - New macro HDK
    [WIP] - New macro HDK

    Feb 1, 2019

    HDK Improvements

    Rust edition 2018 allows for defining procedural macros. These allow for arbitrary transformations to be made to modules, functions and structs/enums at compile time. These were not available at the time the current HDK was created.

    This is used by popular rust crates (notable Serde and Rocket.rs) to allow simple DSLs. For example in Rocket.rs it is used to define which functions act as callbacks to HTTP reqests:

    #[get("/")] // example of an attribute-like macro
    fn hello() -> &'static str {
        "Hello, world!"
    }
    

    The flexibility of proc macros means there almost unlimited ways to define a DSL that makes zome development in rust as productive as possible with minimum boiler-plate. This PR serves as a place to discuss both what the HDK should look like from a developer perspective but also what is easy/possible to implement.

    Initial Proposal

    #![hdk::zome] // this attribute-like macro operates on the whole module. This is equivalent to define_zome! in the old HDK
    
    #[hdk:entry] // instructs the top level macro that a entry should be created that maps to this struct
    struct Post {
        content: String,
    }
    
    #[hdk:entry(validation = "validate_blog", validation_package = ChainFull)]
    // provides custom validation callback and also an idea of how links could be defined
    struct Blog {
        owner: Agent,
        #[hdk::links("posts")]
        posts: vec<Post>,
    }
    
    fn validate_blog(entry: BlogEntry, validation_data: ValidationData) -> ZomeApiResult<()> {
    
    }
    
    /////////////////////////////////////////////////////////////////
    
    #[hdk::genesis] // genesis callback
    fn genesis() -> bool {
    	true
    }
    
    #[hdk::receive] // receive callback
    fn receive() -> ZomeApiResult<()> {
    }
    
    // a zome api function that belongs to these two traits 
    // (this maybe needs some discussion)
    #[hdk::zome_function(traits = ["zome", "bridge"])]
    fn get_posts() -> ZomeApiResult<String> {
    }
    
    #[hdk::zome_function(traits = ["plumbus"])]
    fn delete_all_posts_idc() -> ZomeApiResult<> {
    }
    

    Considerations:

    • It should still be possible to split entries/callbacks between multiple files
    • All of the customization of define_zome! must be supported
    • The GraphQL schema generation should be an extension that works on top of what is defined here
    WIP bikeshed? 
    Reply