hyperledger / iroha-javascript

JavaScript library for Iroha, a Distributed Ledger Technology (blockchain) platform.
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
94 stars 64 forks source link

[feature]: functional approach to compile data-model artifacts #136

Closed 0x009922 closed 1 year ago

0x009922 commented 1 year ago

Old approach

Iroha JavaScript uses the original Iroha repository for a set of reasons:

Previously, iroha_data_model was referenced in packages/data-model-rust-samples/Cargo.toml as:

iroha_data_model = { git = "<git repo>", rev = "<rev>" }

kagami and iroha binaries were built via cargo build:

cargo build --git "<git repo>" --rev "<rev>" --package kagami

This pipeline was encapsulated into @iroha2/dev-iroha-bins package and was semi-automatic - compiled artifacts were produced and committed manually as described at "Manually update reference iroha version" guide.

New approach

Automatic updates of the reference iroha in a single place

@iroha2/iroha-source dev packages comes in instead of @iroha2/dev-iroha-bins. In order to change reference Iroha version, it is only needed to update packages/iroha-source/config.json, and everything else will be re-compiled on the fly.

The configuration schema is pretty straightforward:

{
  "origin": "https://github.com/hyperledger/iroha.git",
  "rev": "52dc18cd81bdc1d1906ffeecb666dd9b2eb27955"
}

These parameters are used to git clone the repo. Thus, origin field might be even a file-system path, and rev - a branch/tag name.

Then, each time when some actor needs to use iroha or kagami binary, the following steps are performed:

import { resolveBinary } from '@iroha2/iroha-source'

const irohaPath = (await resolveBinary('iroha')).path
// 1. If the repo is not cloned, clone it. If the cloned repo is not the same as specified
//    in `config.json`, update it.
// 2. If there is no `target/release/iroha`, run `cargo build --release --package iroha`
// 3. Return path to the `target/release/iroha` binary

Also, data-model-rust-samples crate now references iroha_data_model via path option in Cargo.toml, which:

Exclude data-model artifacts from Git tracking

Those artifacts aren't tracked by Git anymore:

Their generation now works fast, and it is run at following steps:

Refactored monorepo tasks

I made some changes in the root Jakefile and package.json. Notable ones:


In conclusion, the overall approach is easier to use, maintain and is more robust, because now it is harder to "forget" update data-model schema - it updates automatically before each step that needs it, and it runs fast in dev environment.

However, CI/CD might run longer now, because it will compile 3 Rust crates, but this process is optimized thanks to incremental compilation.