Skip to content

Commit

Permalink
Merge pull request #74 from mangata-finance/feature/github_actions_fe…
Browse files Browse the repository at this point in the history
…atures

create intermediate image before building the node and execute pre ch…
  • Loading branch information
mateuszaaa authored Jun 23, 2021
2 parents 8cca1ac + 4eaa493 commit d28fc0a
Show file tree
Hide file tree
Showing 10 changed files with 1,363 additions and 1,206 deletions.
82 changes: 79 additions & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,84 @@ on:

jobs:

build:
rustfmt-check:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
-
name: Build Docker Image
uses: docker/build-push-action@v2
with:
file: "devops/dockerfiles/node-and-runtime/Dockerfile"
load: true
tags: mangatasolutions/mangata-node-fmt-check:${{ github.sha }}
target: env_builder
-
name: Check formatting
run: |
docker run --entrypoint /root/.cargo/bin/cargo mangatasolutions/mangata-node-fmt-check:${{ github.sha }} fmt -- --check
clippy:
name: Clippy check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install latest nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2020-10-01
target: wasm32-unknown-unknown
override: true
components: clippy

- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: clippy
args: -p pallet-xyk -p sc-block-builder -p sc-basic-authorship -p extrinsic-shuffler -p pallet-random-seed -p random-seed-runtime-api -p xyk-runtime-api -p mangata-primitives -p extrinsic-info-runtime-api

unit-test:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Build Docker Image
uses: docker/build-push-action@v2
with:
file: "devops/dockerfiles/node-and-runtime/Dockerfile"
load: true
tags: mangatasolutions/mangata-node-ut:${{ github.sha }}
target: env_builder
-
name: Run Tests
run: |
pwd
ls -la
docker run mangatasolutions/mangata-node-ut:${{ github.sha }} /bin/bash -c \
'cargo test -p pallet-xyk --no-run'
docker run mangatasolutions/mangata-node-ut:${{ github.sha }} /bin/bash -c \
'cargo test -- -Z unstable-options --format json --report-time |cargo2junit' | tee ut-results.xml
# remove empty tests suites
sed -i '/<testsuite.*\/>$/d' ut-results.xml
sed -i 's/<testsuites>/<testsuites time="0">/g' ut-results.xml
cat ut-results.xml
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Unit Tests
path: ut-results.xml
reporter: jest-junit


build:
runs-on: ubuntu-latest
steps:
-
Expand Down Expand Up @@ -48,7 +124,7 @@ jobs:
name: ${{ github.run_id }}
path: /tmp/${{ github.run_id }}.tar

test:
e2e-test:
needs: build
runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'skip-e2e-tests')"
Expand Down Expand Up @@ -115,7 +191,7 @@ jobs:
reporter: jest-junit # Format of test results

publish:
needs: test
needs: [rustfmt-check, unit-test, e2e-test, clippy]
runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'skip-publish') && ${{ github.event_name == 'push'}}"
#if: # its a push to develop.
Expand Down
58 changes: 30 additions & 28 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,16 @@ where
mod tests {
use super::*;

use pallet_random_seed::RandomSeedInherentDataProvider;
use parking_lot::Mutex;
use sc_client_api::Backend;
use sc_transaction_pool::BasicPool;
use sp_api::Core;
use sp_blockchain::HeaderBackend;
use sp_consensus::{BlockOrigin, Proposer};
use sp_inherents::{InherentData, ProvideInherentData};
use sp_runtime::traits::NumberFor;
use sp_transaction_pool::{ChainEvent, MaintainedTransactionPool, TransactionSource};
use sp_inherents::{InherentData, ProvideInherentData};
use pallet_random_seed::RandomSeedInherentDataProvider;

use substrate_test_runtime_client::{
prelude::*,
Expand All @@ -372,7 +372,7 @@ mod tests {
const SOURCE: TransactionSource = TransactionSource::External;

/// inject shuffling seed that is mandatory in mangata
fn create_inherents() -> InherentData{
fn create_inherents() -> InherentData {
let mut data: InherentData = Default::default();
RandomSeedInherentDataProvider(Default::default())
.provide_inherent_data(&mut data)
Expand Down Expand Up @@ -557,9 +557,9 @@ mod tests {
#[test]
// TODO this tests fails due two reasons. It verifies extrinsics order compairing extrinsic
// root hash block-builder/src/lib.rs:272 and due to fact that extrinsic validation mechanism
// has been disabled BlockBuilder::push. Once shuffling will be done at runtime and validation
// has been disabled BlockBuilder::push. Once shuffling will be done at runtime and validation
// will be reverted it can be enalbed again
#[ignore]
#[ignore]
fn should_not_remove_invalid_transactions_when_skipping() {
// given
let mut client = Arc::new(substrate_test_runtime_client::new());
Expand Down Expand Up @@ -592,31 +592,33 @@ mod tests {
.unwrap();

let mut proposer_factory = ProposerFactory::new(client.clone(), txpool.clone(), None);
let mut propose_block =
|client: &TestClient, number, _expected_block_extrinsics, expected_pool_transactions| {
let proposer = proposer_factory.init_with_now(
&client.header(&BlockId::number(number)).unwrap().unwrap(),
Box::new(move || time::Instant::now()),
);

// when
let deadline = time::Duration::from_secs(9);
let block = futures::executor::block_on(proposer.propose(
create_inherents(),
Default::default(),
deadline,
RecordProof::No,
))
.map(|r| r.block)
.unwrap();
let mut propose_block = |client: &TestClient,
number,
_expected_block_extrinsics,
expected_pool_transactions| {
let proposer = proposer_factory.init_with_now(
&client.header(&BlockId::number(number)).unwrap().unwrap(),
Box::new(move || time::Instant::now()),
);

// when
let deadline = time::Duration::from_secs(9);
let block = futures::executor::block_on(proposer.propose(
create_inherents(),
Default::default(),
deadline,
RecordProof::No,
))
.map(|r| r.block)
.unwrap();

// then
// block should have some extrinsics although we have some more in the pool.
//assert_eq!(block.extrinsics().len(), expected_block_extrinsics);
assert_eq!(txpool.ready().count(), expected_pool_transactions);
// then
// block should have some extrinsics although we have some more in the pool.
//assert_eq!(block.extrinsics().len(), expected_block_extrinsics);
assert_eq!(txpool.ready().count(), expected_pool_transactions);

block
};
block
};

futures::executor::block_on(
txpool.maintain(chain_event(
Expand Down
5 changes: 2 additions & 3 deletions client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,8 @@ where
inherent_data: sp_inherents::InherentData,
) -> Result<(SeedType, Vec<Block::Extrinsic>), ApiErrorFor<A, Block>> {
let block_id = self.block_id.clone();
let seed = pallet_random_seed::extract_inherent_data(&inherent_data).map_err(|_|{
String::from("cannot random seed from inherents data")
})?;
let seed = pallet_random_seed::extract_inherent_data(&inherent_data)
.map_err(|_| String::from("cannot random seed from inherents data"))?;
self.api
.execute_in_transaction(move |api| {
// `create_inherents` should not change any state, to ensure this we always rollback
Expand Down
49 changes: 22 additions & 27 deletions client/shuffler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![cfg_attr(not(feature = "std"), no_std)]
use extrinsic_info_runtime_api::runtime_api::ExtrinsicInfoRuntimeApi;
use pallet_random_seed::SeedType;
use random_seed_runtime_api::RandomSeedApi;
use sp_api::{ApiExt, ApiRef, Encode, HashT, ProvideRuntimeApi, TransactionOutcome};
use sp_block_builder::BlockBuilder as BlockBuilderRuntimeApi;
use sp_core::crypto::Ss58Codec;
use sp_runtime::generic::BlockId;
use sp_runtime::traits::{BlakeTwo256, Block as BlockT};
Expand All @@ -10,8 +12,6 @@ use sp_std::collections::btree_map::BTreeMap;
use sp_std::collections::vec_deque::VecDeque;
use sp_std::convert::TryInto;
use sp_std::vec::Vec;
use sp_block_builder::BlockBuilder as BlockBuilderRuntimeApi;
use random_seed_runtime_api::RandomSeedApi;

pub struct Xoshiro256PlusPlus {
s: [u64; 4],
Expand Down Expand Up @@ -46,7 +46,7 @@ impl Xoshiro256PlusPlus {

self.s[3] = rotl(self.s[3], 45);

return (self.s[0].wrapping_add(self.s[3])) as u32;
(self.s[0].wrapping_add(self.s[3])) as u32
}
}

Expand Down Expand Up @@ -112,7 +112,10 @@ where
let mut grouped_extrinsics: BTreeMap<Option<AccountId32>, VecDeque<_>> = extrinsics
.into_iter()
.fold(BTreeMap::new(), |mut groups, (who, tx)| {
groups.entry(who).or_insert(VecDeque::new()).push_back(tx);
groups
.entry(who)
.or_insert_with(VecDeque::new)
.push_back(tx);
groups
});

Expand Down Expand Up @@ -145,10 +148,10 @@ where

#[derive(derive_more::Display, Debug)]
pub enum Error {
#[display(fmt = "Cannot apply inherents")]
InherentApplyError,
#[display(fmt = "Cannot read seed from the runtime api ")]
SeedFetchingError,
#[display(fmt = "Cannot apply inherents")]
InherentApplyError,
#[display(fmt = "Cannot read seed from the runtime api ")]
SeedFetchingError,
}

pub fn fetch_seed<'a, Block, Api>(
Expand All @@ -160,11 +163,9 @@ where
Api: ProvideRuntimeApi<Block> + 'a,
Api::Api: BlockBuilderRuntimeApi<Block> + RandomSeedApi<Block>,
{
api.get_seed(block_id)
.map_err(|_|Error::SeedFetchingError)
api.get_seed(block_id).map_err(|_| Error::SeedFetchingError)
}


/// shuffles extrinsics assuring that extrinsics signed by single account will be still evaluated
/// in proper order
pub fn apply_inherents_and_fetch_seed<'a, Block, Api>(
Expand All @@ -177,23 +178,17 @@ where
Api: ProvideRuntimeApi<Block> + 'a,
Api::Api: BlockBuilderRuntimeApi<Block> + RandomSeedApi<Block>,
{
api.execute_in_transaction(|api|
api.execute_in_transaction(|api| {
sp_api::TransactionOutcome::Rollback(
extrinsics.into_iter().take(2).map(|xt|
{
match api.apply_extrinsic(
block_id,
xt,
) {
Ok(Ok(Ok(_))) => Ok(()),
_ => Err(Error::InherentApplyError)
}
extrinsics
.into_iter()
.take(2)
.map(|xt| match api.apply_extrinsic(block_id, xt) {
Ok(Ok(Ok(_))) => Ok(()),
_ => Err(Error::InherentApplyError),
})
.collect::<Result<Vec<_>, _>>()
.and_then(|_|
api.get_seed(block_id)
.map_err(|_|Error::SeedFetchingError)
)
)
)
.and_then(|_| api.get_seed(block_id).map_err(|_| Error::SeedFetchingError)),
)
})
}
Loading

0 comments on commit d28fc0a

Please sign in to comment.