From 10ee4c28507d11c74495a1dc0d12b30062f13b86 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 Jul 2024 00:05:04 +0200 Subject: [PATCH 1/4] build(deps): bump aws-actions/configure-aws-credentials from 2 to 4 (#2920) Bumps [aws-actions/configure-aws-credentials](https://github.com/aws-actions/configure-aws-credentials) from 2 to 4. - [Release notes](https://github.com/aws-actions/configure-aws-credentials/releases) - [Changelog](https://github.com/aws-actions/configure-aws-credentials/blob/main/CHANGELOG.md) - [Commits](https://github.com/aws-actions/configure-aws-credentials/compare/v2...v4) --- updated-dependencies: - dependency-name: aws-actions/configure-aws-credentials dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/benchmark-machine.yml | 2 +- .github/workflows/benchmark-runtime-weights.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/benchmark-machine.yml b/.github/workflows/benchmark-machine.yml index 9ec848368d..ca24dec586 100644 --- a/.github/workflows/benchmark-machine.yml +++ b/.github/workflows/benchmark-machine.yml @@ -24,7 +24,7 @@ jobs: fetch-depth: 0 - name: Set up AWS CLI - uses: aws-actions/configure-aws-credentials@v2 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} diff --git a/.github/workflows/benchmark-runtime-weights.yml b/.github/workflows/benchmark-runtime-weights.yml index a9d6d85f0c..99d41bbe7c 100644 --- a/.github/workflows/benchmark-runtime-weights.yml +++ b/.github/workflows/benchmark-runtime-weights.yml @@ -112,7 +112,7 @@ jobs: docker pull litentry/litentry-parachain:runtime-benchmarks - name: Set up AWS CLI - uses: aws-actions/configure-aws-credentials@v2 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} From da4792b41378b88b1257512e703b0cdfc78c0187 Mon Sep 17 00:00:00 2001 From: 0xverin <104152026+0xverin@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:14:49 +0800 Subject: [PATCH 2/4] quick-fix: assertion contracts tests (#2924) * add secrets * add sleep * add secret * fmt * remove console * adding contracts to file-filter --- .github/file-filter.yml | 1 + .../integration-tests/assertion_contracts.test.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/file-filter.yml b/.github/file-filter.yml index 248d169978..4d28248b4e 100644 --- a/.github/file-filter.yml +++ b/.github/file-filter.yml @@ -37,6 +37,7 @@ tee_test: &tee_test - 'tee-worker/cli/*.sh' - 'docker/**' - 'tee-worker/docker/*.yml' + - 'tee-worker/litentry/core/assertion-build/src/dynamic/contracts/**' bitacross_src: &bitacross_src - 'bitacross-worker/**/*.rs' diff --git a/tee-worker/ts-tests/integration-tests/assertion_contracts.test.ts b/tee-worker/ts-tests/integration-tests/assertion_contracts.test.ts index 2237e239ba..9d7c238413 100644 --- a/tee-worker/ts-tests/integration-tests/assertion_contracts.test.ts +++ b/tee-worker/ts-tests/integration-tests/assertion_contracts.test.ts @@ -65,7 +65,12 @@ describe('Test Vc (direct request)', function () { const assertionId = '0x0000000000000000000000000000000000000003'; const createAssertionEventsPromise = subscribeToEvents('evmAssertions', 'AssertionCreated', context.api); - const proposal = context.api.tx.evmAssertions.createAssertion(assertionId, contractBytecode, [secret]); + const proposal = context.api.tx.evmAssertions.createAssertion(assertionId, contractBytecode, [ + // At least three secrets are required here. + secret, + secret, + secret, + ]); await context.api.tx.developerCommittee.execute(proposal, proposal.encodedLength).signAndSend(alice); const event = (await createAssertionEventsPromise).map((e) => e); @@ -127,11 +132,12 @@ describe('Test Vc (direct request)', function () { const abiCoder = new ethers.utils.AbiCoder(); const encodedData = abiCoder.encode(['string'], ['bnb']); + const assertion = { dynamic: context.api.createType('DynamicParams', [ Uint8Array.from(Buffer.from('0000000000000000000000000000000000000003', 'hex')), encodedData, - false, + true, ]), }; From 761639b52638d3d71f62d42c569c97ccfbe438d0 Mon Sep 17 00:00:00 2001 From: 0xverin <104152026+0xverin@users.noreply.github.com> Date: Tue, 23 Jul 2024 21:10:28 +0800 Subject: [PATCH 3/4] p-929 Adding vcissued events listening for dr_vc test (#2925) * adding subscribeToEventsWithExtHash * uncomment * remove console --------- Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com> --- tee-worker/ts-tests/integration-tests/dr_vc.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts index 7ea4164b4f..f24ca0f724 100644 --- a/tee-worker/ts-tests/integration-tests/dr_vc.test.ts +++ b/tee-worker/ts-tests/integration-tests/dr_vc.test.ts @@ -17,6 +17,8 @@ import type { CorePrimitivesIdentity, WorkerRpcReturnValue } from 'parachain-api import { mockBatchAssertion } from './common/utils/vc-helper'; import type { LitentryValidationData, Web3Network } from 'parachain-api'; import type { Vec, Bytes } from '@polkadot/types'; +import { subscribeToEventsWithExtHash } from './common/transactions'; +import { assert } from 'chai'; describe('Test Vc (direct request)', function () { let context: IntegrationTestContext = undefined as any; @@ -171,6 +173,7 @@ describe('Test Vc (direct request)', function () { if (vcresponse.result.isOk) await assertVc(context, aliceSubstrateIdentity, vcresponse.result.asOk); }; + const eventsPromise = subscribeToEventsWithExtHash(requestIdentifier, context); // the +res+ below is the last message with "do_watch: false" property and we may not need it at all const res = await sendRequestFromTrustedCall( context, @@ -180,6 +183,9 @@ describe('Test Vc (direct request)', function () { onMessageReceived ); + const events = (await eventsPromise).map(({ event }) => event); + assert.equal(events.length, Array.isArray(assertion) ? assertion.length : 1); + // @todo: assert batch vc response }); }); From f789aad178c41436ffe0a4432d97b724d3e51c85 Mon Sep 17 00:00:00 2001 From: Francisco Silva Date: Tue, 23 Jul 2024 16:43:32 +0200 Subject: [PATCH 4/4] Improving sync parachain performance for workers (#2888) * improving sync_parentchain performance for bitacross-worker * improving sync_parentchain performance for litentry-worker * fixing parentchain_api_mock * increasing sleep time --------- Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com> --- bitacross-worker/Cargo.lock | 11 +++-- .../api-client-extensions/src/chain.rs | 14 +++++++ bitacross-worker/service/Cargo.toml | 1 + .../service/src/parentchain_handler.rs | 42 ++++++++++++++----- .../src/tests/mocks/parentchain_api_mock.rs | 7 ++++ tee-worker/Cargo.lock | 11 +++-- .../lit_test_failed_parentchain_extrinsic.sh | 4 +- .../api-client-extensions/src/chain.rs | 14 +++++++ tee-worker/service/Cargo.toml | 1 + tee-worker/service/src/parentchain_handler.rs | 42 ++++++++++++++----- .../src/tests/mocks/parentchain_api_mock.rs | 7 ++++ 11 files changed, 120 insertions(+), 34 deletions(-) diff --git a/bitacross-worker/Cargo.lock b/bitacross-worker/Cargo.lock index a6f8424a51..7820d81aff 100644 --- a/bitacross-worker/Cargo.lock +++ b/bitacross-worker/Cargo.lock @@ -612,6 +612,7 @@ dependencies = [ "parking_lot 0.12.1", "parse_duration", "prometheus", + "rayon", "regex 1.9.5", "scale-info", "serde 1.0.193", @@ -5755,9 +5756,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.7.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -5765,14 +5766,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] diff --git a/bitacross-worker/core-primitives/node-api/api-client-extensions/src/chain.rs b/bitacross-worker/core-primitives/node-api/api-client-extensions/src/chain.rs index 89321b0034..0333c41f66 100644 --- a/bitacross-worker/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/bitacross-worker/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -49,6 +49,10 @@ pub trait ChainApi { from: Self::BlockNumber, to: Self::BlockNumber, ) -> ApiResult>>; + fn get_block_by_number( + &self, + block: Self::BlockNumber, + ) -> ApiResult>>; fn is_grandpa_available(&self) -> ApiResult; fn grandpa_authorities(&self, hash: Option) -> ApiResult; fn grandpa_authorities_proof(&self, hash: Option) -> ApiResult; @@ -101,6 +105,16 @@ where Ok(blocks) } + fn get_block_by_number( + &self, + block_number: Self::BlockNumber, + ) -> ApiResult>> { + match self.get_signed_block_by_num(Some(block_number))? { + Some(block) => Ok(Some(block.into())), + None => Ok(None), + } + } + fn is_grandpa_available(&self) -> ApiResult { let genesis_hash = Some(self.get_genesis_hash().expect("Failed to get genesis hash")); Ok(self diff --git a/bitacross-worker/service/Cargo.toml b/bitacross-worker/service/Cargo.toml index 68049051a9..eaa51566fe 100644 --- a/bitacross-worker/service/Cargo.toml +++ b/bitacross-worker/service/Cargo.toml @@ -20,6 +20,7 @@ log = "0.4" parking_lot = "0.12.1" parse_duration = "2.1.1" prometheus = { version = "0.13.0", features = ["process"], default-features = false } # Enabling std lead to protobuf dependency conflicts with substrate, and we don't need it. +rayon = "1.10.0" regex = "1.9.5" scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } serde = "1.0" diff --git a/bitacross-worker/service/src/parentchain_handler.rs b/bitacross-worker/service/src/parentchain_handler.rs index ca1557cb33..a87f927f10 100644 --- a/bitacross-worker/service/src/parentchain_handler.rs +++ b/bitacross-worker/service/src/parentchain_handler.rs @@ -31,6 +31,7 @@ use itp_storage::StorageProof; use itp_time_utils::duration_now; use itp_types::ShardIdentifier; use log::*; +use rayon::prelude::*; use sp_consensus_grandpa::VersionedAuthorityList; use sp_runtime::traits::Header as HeaderTrait; use std::{cmp::min, sync::Arc, time::Duration}; @@ -204,10 +205,27 @@ where } loop { - let block_chunk_to_sync = self.parentchain_api.get_blocks( - start_block, - min(start_block + BLOCK_SYNC_BATCH_SIZE, curr_block_number), - )?; + let chunk_range = + start_block..min(start_block + BLOCK_SYNC_BATCH_SIZE, curr_block_number); + + let start_fetch_time = duration_now(); + + let block_chunk_to_sync = chunk_range + .into_par_iter() + .filter_map(|block_number| { + self.parentchain_api + .get_block_by_number(block_number) + .expect("failed to get block") + }) + .collect::>(); + + debug!( + "[{:?}] Fetched {} blocks in {}", + id, + block_chunk_to_sync.len(), + format_duration(duration_now().saturating_sub(start_fetch_time)) + ); + if block_chunk_to_sync.len() == BLOCK_SYNC_BATCH_SIZE as usize { let now = duration_now(); let total_blocks = curr_block_number.saturating_sub(last_synced_header_number); @@ -247,7 +265,7 @@ where vec![] } else { let evs = block_chunk_to_sync - .iter() + .par_iter() .map(|block| { self.parentchain_api.get_events_for_block(Some(block.block.header.hash())) }) @@ -260,13 +278,15 @@ where vec![] } else { block_chunk_to_sync - .iter() + .par_iter() .map(|block| { self.parentchain_api.get_events_value_proof(Some(block.block.header.hash())) }) .collect::, _>>()? }; + let sync_start_time = duration_now(); + self.enclave_api.sync_parentchain( block_chunk_to_sync.as_slice(), events_chunk_to_sync.as_slice(), @@ -275,14 +295,16 @@ where immediate_import, )?; + info!( + "[{:?}] Synced parentchain batch in {}", + id, + format_duration(duration_now().saturating_sub(sync_start_time)) + ); + let api_client_until_synced_header = block_chunk_to_sync .last() .map(|b| b.block.header.clone()) .ok_or(Error::EmptyChunk)?; - debug!( - "[{:?}] Synced {} out of {} finalized parentchain blocks", - id, api_client_until_synced_header.number, curr_block_number, - ); // #TODO: #1451: fix api/client types until_synced_header = diff --git a/bitacross-worker/service/src/tests/mocks/parentchain_api_mock.rs b/bitacross-worker/service/src/tests/mocks/parentchain_api_mock.rs index cfd1e891ba..b383c2412c 100644 --- a/bitacross-worker/service/src/tests/mocks/parentchain_api_mock.rs +++ b/bitacross-worker/service/src/tests/mocks/parentchain_api_mock.rs @@ -101,4 +101,11 @@ impl ChainApi for ParentchainApiMock { fn get_events_for_block(&self, _block_hash: Option) -> ApiResult> { Ok(Default::default()) } + + fn get_block_by_number( + &self, + block: Self::BlockNumber, + ) -> ApiResult>> { + Ok(self.parentchain.get(block as usize).cloned()) + } } diff --git a/tee-worker/Cargo.lock b/tee-worker/Cargo.lock index 05c62a3cd4..3670bfc070 100644 --- a/tee-worker/Cargo.lock +++ b/tee-worker/Cargo.lock @@ -5156,6 +5156,7 @@ dependencies = [ "parse_duration", "primitive-types", "prometheus", + "rayon", "regex 1.9.5", "scale-info", "serde 1.0.193", @@ -6838,9 +6839,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.7.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" dependencies = [ "either", "rayon-core", @@ -6848,14 +6849,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus 1.16.0", ] [[package]] diff --git a/tee-worker/cli/lit_test_failed_parentchain_extrinsic.sh b/tee-worker/cli/lit_test_failed_parentchain_extrinsic.sh index b6ce22ee31..e55f73afd6 100755 --- a/tee-worker/cli/lit_test_failed_parentchain_extrinsic.sh +++ b/tee-worker/cli/lit_test_failed_parentchain_extrinsic.sh @@ -46,7 +46,7 @@ echo "New Account created: ${FIRST_NEW_ACCOUNT}" echo "Linking identity to Bob" OUTPUT=$(${CLIENT} link-identity //Bob did:litentry:substrate:${FIRST_NEW_ACCOUNT} litentry) || { echo "Link identity command failed"; exit 1; } echo "Finished Linking identity to Bob" -sleep 30 +sleep 60 echo "Capturing IDGraph Hash of Bob" INITIAL_ID_GRAPH_HASH=$(${CLIENT} id-graph-hash did:litentry:substrate:0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48) || { echo "Failed to get ID Graph hash"; exit 1; } @@ -58,7 +58,7 @@ echo "New Account created: ${SECOND_NEW_ACCOUNT}" echo "Linking new identity to Bob with Eve as delegate signer" OUTPUT=$(${CLIENT} link-identity //Bob "did:litentry:substrate:${SECOND_NEW_ACCOUNT}" litentry -d //Eve) || { echo "Link identity command failed"; exit 1; } echo "Finished Linking identity to Bob" -sleep 30 +sleep 60 echo "Capturing IDGraph Hash of Bob" FINAL_ID_GRAPH_HASH=$(${CLIENT} id-graph-hash did:litentry:substrate:0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48) || { echo "Failed to get ID Graph hash"; exit 1; } diff --git a/tee-worker/core-primitives/node-api/api-client-extensions/src/chain.rs b/tee-worker/core-primitives/node-api/api-client-extensions/src/chain.rs index 89321b0034..0333c41f66 100644 --- a/tee-worker/core-primitives/node-api/api-client-extensions/src/chain.rs +++ b/tee-worker/core-primitives/node-api/api-client-extensions/src/chain.rs @@ -49,6 +49,10 @@ pub trait ChainApi { from: Self::BlockNumber, to: Self::BlockNumber, ) -> ApiResult>>; + fn get_block_by_number( + &self, + block: Self::BlockNumber, + ) -> ApiResult>>; fn is_grandpa_available(&self) -> ApiResult; fn grandpa_authorities(&self, hash: Option) -> ApiResult; fn grandpa_authorities_proof(&self, hash: Option) -> ApiResult; @@ -101,6 +105,16 @@ where Ok(blocks) } + fn get_block_by_number( + &self, + block_number: Self::BlockNumber, + ) -> ApiResult>> { + match self.get_signed_block_by_num(Some(block_number))? { + Some(block) => Ok(Some(block.into())), + None => Ok(None), + } + } + fn is_grandpa_available(&self) -> ApiResult { let genesis_hash = Some(self.get_genesis_hash().expect("Failed to get genesis hash")); Ok(self diff --git a/tee-worker/service/Cargo.toml b/tee-worker/service/Cargo.toml index c875c05259..ab861c5243 100644 --- a/tee-worker/service/Cargo.toml +++ b/tee-worker/service/Cargo.toml @@ -20,6 +20,7 @@ log = "0.4" parking_lot = "0.12.1" parse_duration = "2.1.1" prometheus = { version = "0.13.0", features = ["process"], default-features = false } # Enabling std lead to protobuf dependency conflicts with substrate, and we don't need it. +rayon = "1.10.0" regex = "1.9.5" scale-info = { version = "2.10.0", default-features = false, features = ["derive"] } serde = "1.0" diff --git a/tee-worker/service/src/parentchain_handler.rs b/tee-worker/service/src/parentchain_handler.rs index d4f59fd3bb..6aa9f7069a 100644 --- a/tee-worker/service/src/parentchain_handler.rs +++ b/tee-worker/service/src/parentchain_handler.rs @@ -31,6 +31,7 @@ use itp_storage::StorageProof; use itp_time_utils::duration_now; use itp_types::ShardIdentifier; use log::*; +use rayon::prelude::*; use sp_consensus_grandpa::VersionedAuthorityList; use sp_runtime::traits::Header as HeaderTrait; use std::{cmp::min, sync::Arc, time::Duration}; @@ -204,10 +205,27 @@ where } loop { - let block_chunk_to_sync = self.parentchain_api.get_blocks( - start_block, - min(start_block + BLOCK_SYNC_BATCH_SIZE, curr_block_number), - )?; + let chunk_range = + start_block..min(start_block + BLOCK_SYNC_BATCH_SIZE, curr_block_number); + + let start_fetch_time = duration_now(); + + let block_chunk_to_sync = chunk_range + .into_par_iter() + .filter_map(|block_number| { + self.parentchain_api + .get_block_by_number(block_number) + .expect("failed to get block") + }) + .collect::>(); + + debug!( + "[{:?}] Fetched {} blocks in {}", + id, + block_chunk_to_sync.len(), + format_duration(duration_now().saturating_sub(start_fetch_time)) + ); + if block_chunk_to_sync.len() == BLOCK_SYNC_BATCH_SIZE as usize { let now = duration_now(); let total_blocks = curr_block_number.saturating_sub(last_synced_header_number); @@ -247,7 +265,7 @@ where vec![] } else { let evs = block_chunk_to_sync - .iter() + .par_iter() .map(|block| { self.parentchain_api.get_events_for_block(Some(block.block.header.hash())) }) @@ -260,13 +278,15 @@ where vec![] } else { block_chunk_to_sync - .iter() + .par_iter() .map(|block| { self.parentchain_api.get_events_value_proof(Some(block.block.header.hash())) }) .collect::, _>>()? }; + let sync_start_time = duration_now(); + self.enclave_api.sync_parentchain( block_chunk_to_sync.as_slice(), events_chunk_to_sync.as_slice(), @@ -275,14 +295,16 @@ where immediate_import, )?; + info!( + "[{:?}] Synced parentchain batch in {}", + id, + format_duration(duration_now().saturating_sub(sync_start_time)) + ); + let api_client_until_synced_header = block_chunk_to_sync .last() .map(|b| b.block.header.clone()) .ok_or(Error::EmptyChunk)?; - debug!( - "[{:?}] Synced {} out of {} finalized parentchain blocks", - id, api_client_until_synced_header.number, curr_block_number, - ); // #TODO: #1451: fix api/client types until_synced_header = diff --git a/tee-worker/service/src/tests/mocks/parentchain_api_mock.rs b/tee-worker/service/src/tests/mocks/parentchain_api_mock.rs index cfd1e891ba..b383c2412c 100644 --- a/tee-worker/service/src/tests/mocks/parentchain_api_mock.rs +++ b/tee-worker/service/src/tests/mocks/parentchain_api_mock.rs @@ -101,4 +101,11 @@ impl ChainApi for ParentchainApiMock { fn get_events_for_block(&self, _block_hash: Option) -> ApiResult> { Ok(Default::default()) } + + fn get_block_by_number( + &self, + block: Self::BlockNumber, + ) -> ApiResult>> { + Ok(self.parentchain.get(block as usize).cloned()) + } }