Skip to content

Commit

Permalink
[ci]: Add genesis check and update documentation.
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Petrosyan <a-p-petrosyan@yandex.ru>
  • Loading branch information
appetrosyan committed May 12, 2022
1 parent 4b6aa32 commit f351d1a
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 153 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/iroha2-dev-pr-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,3 @@ jobs:
- name: Verify iroha_data_model still supports no_std
run: cargo nono check --package iroha_data_model --no-default-features
if: always()

- name: Documentation check
run: |
cargo doc --no-deps --quiet
./scripts/check_docs.sh
if: always()
9 changes: 9 additions & 0 deletions .github/workflows/iroha2-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ jobs:
working-directory: wasm
env:
RUSTC_BOOTSTRAP: 1
- name: Documentation check
run: |
cargo doc --no-deps --quiet
./scripts/check.sh docs
if: always()
- name: Check genesis
run: |
./scripts/check.sh genesis
if: always()

# Coverage is both in PR and in push pipelines so that:
# 1. PR can get coverage report from bot.
Expand Down
4 changes: 2 additions & 2 deletions configs/peer/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
}
},
"value_type": "Quantity",
"metadata": {},
"mintable": "Infinitely"
"mintable": "Infinitely",
"metadata": {}
}
}
}
Expand Down
21 changes: 12 additions & 9 deletions core/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! This module contains execution Genesis Block logic, and `GenesisBlock` definition.
//! Genesis-related logic and constructs. Contains the `GenesisBlock`,
//! `RawGenesisBlock` and the `RawGenesisBlockBuilder` structures.
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::new_without_default)]

Expand Down Expand Up @@ -50,18 +51,20 @@ pub trait GenesisNetworkTrait:
transaction_limits: &TransactionLimits,
) -> Result<Option<Self>>;

/// Waits for a minimum number of [`Peer`]s needed for consensus to be online.
/// Returns initialized network [`Topology`] with the set A consisting of online peers.
/// Waits for a minimum number of [`Peer`]s needed for consensus
/// to be online. Returns initialized network [`Topology`] with
/// the set A consisting of online peers.
async fn wait_for_peers(
&self,
this_peer_id: PeerId,
network_topology: Topology,
network: Addr<IrohaNetwork>,
) -> Result<Topology>;

// FIXME: Having `ctx` reference and `sumaregi` reference here is not ideal.
// The way it is currently designed, this function is called from sumeragi and then calls sumeragi, while being in an unrelated module.
// This needs to be restructured.
// FIXME: Having `ctx` reference and `sumaregi` reference here is
// not ideal. The way it is currently designed, this function is
// called from sumeragi and then calls sumeragi, while being in an
// unrelated module. This needs to be restructured.

/// Submits genesis transactions.
///
Expand Down Expand Up @@ -518,7 +521,7 @@ mod tests {
let domain_id: DomainId = "wonderland".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[0],
RegisterBox::new(domain_id.clone()).into()
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[1],
Expand All @@ -534,7 +537,7 @@ mod tests {
let domain_id: DomainId = "tulgey_wood".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[3],
RegisterBox::new(domain_id.clone()).into()
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[4],
Expand All @@ -545,7 +548,7 @@ mod tests {
let domain_id: DomainId = "meadow".parse().unwrap();
assert_eq!(
finished_genesis_block.transactions[0].isi[5],
RegisterBox::new(domain_id.clone()).into()
Instruction::from(RegisterBox::new(NewDomain::new(domain_id.clone())))
);
assert_eq!(
finished_genesis_block.transactions[0].isi[6],
Expand Down
24 changes: 17 additions & 7 deletions data_model/src/domain.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
//! This module contains [`Domain`](`crate::domain::Domain`) structure and related implementations and trait implementations.
//! This module contains [`Domain`](`crate::domain::Domain`) structure
//! and related implementations and trait implementations.
//!
//! Note that the Genesis domain and account have a temporary
//! privileged position, and permission validation is turned off for
//! the Genesis block.

#[cfg(not(feature = "std"))]
use alloc::{format, string::String, vec::Vec};
Expand All @@ -18,7 +23,9 @@ use crate::{
Identifiable, Name, ParseError,
};

/// Genesis domain name. Genesis domain should contain only genesis account.
/// The domain name of the genesis domain.
///
/// The genesis domain should only contain the genesis account.
pub const GENESIS_DOMAIN_NAME: &str = "genesis";

/// Genesis domain. It will contain only one `genesis` account.
Expand Down Expand Up @@ -62,8 +69,11 @@ impl From<GenesisDomain> for Domain {
/// Builder which can be submitted in a transaction to create a new [`Domain`]
#[derive(Debug, Clone, PartialEq, Eq, Decode, Encode, Deserialize, Serialize, IntoSchema)]
pub struct NewDomain {
/// The identification associated to the domain builder.
id: <Domain as Identifiable>::Id,
/// The (IPFS) link to the logo of this domain.
logo: Option<IpfsPath>,
/// metadata associated to the domain builder.
pub metadata: Metadata,
}

Expand All @@ -82,6 +92,7 @@ impl Ord for NewDomain {
}

impl NewDomain {
/// Create a [`NewDomain`], reserved for internal use.
#[must_use]
pub fn new(id: <Domain as Identifiable>::Id) -> Self {
Self {
Expand Down Expand Up @@ -251,8 +262,8 @@ impl Domain {
self.asset_definitions.get_mut(asset_definition_id)
}

/// Add asset definition into the [`Domain`] returning previous asset definition stored under
/// the same id
/// Add asset definition into the [`Domain`] returning previous
/// asset definition stored under the same id
#[inline]
pub fn add_asset_definition(
&mut self,
Expand Down Expand Up @@ -284,9 +295,8 @@ impl FromIterator<Domain> for crate::Value {
}
}

/// Represents path in IPFS. Performs some checks to ensure path validity.
///
/// Should be constructed with `from_str()` method.
/// Represents path in IPFS. Performs checks to ensure path validity.
/// Construct using [`FromStr::from_str`] method.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encode, Serialize, IntoSchema)]
pub struct IpfsPath(String);

Expand Down
2 changes: 1 addition & 1 deletion hooks/pre-commit.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
set -e
cargo run --bin iroha_docs >docs/source/references/config.md
cargo run --bin iroha_gen -- --docs >docs/source/references/config.md
git add docs/source/references/config.md
19 changes: 19 additions & 0 deletions scripts/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
set -e

TMPFILE=$(mktemp)

case $1 in
"docs")
cargo run --bin iroha_gen -- --docs >"$TMPFILE"
diff "$TMPFILE" docs/source/references/config.md || {
echo 'Please re-generate docs with git hook in ./hooks directory'
exit 1
};;
"genesis")
cargo run --bin iroha_gen -- --genesis >"$TMPFILE"
diff "$TMPFILE" configs/peer/genesis.json || {
echo 'Please re-generate the genesis with `cargo run --bin iroha_gen -- --genesis`'
exit 1
};;
esac
8 changes: 0 additions & 8 deletions scripts/check_docs.sh

This file was deleted.

Loading

0 comments on commit f351d1a

Please sign in to comment.