Skip to content

Commit

Permalink
Update identity worker upstream codebase to 9a3b032 (#2571)
Browse files Browse the repository at this point in the history
* rename files

* fix compile error

* resolve conflict

* enclave compiles

* worker compiles

* fix clippy

* remove my-node-runtime

* update lockfiles

* fix tests

* fix account assert

* fix the enum

* fix evm

* fix module index

* ignore timestamp ext

* fix clippy

* add comments to note down follow-up issue numbers
  • Loading branch information
Kailai-Wang committed Mar 14, 2024
1 parent da6d3ed commit ca83789
Show file tree
Hide file tree
Showing 177 changed files with 7,789 additions and 12,256 deletions.
2 changes: 0 additions & 2 deletions bitacross-worker/app-libs/parentchain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ lc-scheduled-enclave = { path = "../../litentry/core/scheduled-enclave", default
litentry-hex-utils = { path = "../../../primitives/hex", default-features = false }
litentry-primitives = { path = "../../litentry/primitives", default-features = false }


[dev-dependencies]
env_logger = "0.9.0"
itp-node-api = { path = "../../core-primitives/node-api", features = ["mocks"] }
Expand All @@ -42,7 +41,6 @@ itp-test = { path = "../../core-primitives/test" }
itp-top-pool-author = { path = "../../core-primitives/top-pool-author", features = ["mocks"] }
itc-parentchain-test = { path = "../../core/parentchain/test" }


[features]
default = ["std"]
std = [
Expand Down
6 changes: 3 additions & 3 deletions bitacross-worker/app-libs/stf/src/stf_sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ita_sgx_runtime::Executive;
use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait};
use itp_sgx_externalities::SgxExternalitiesTrait;
use itp_stf_interface::{
parentchain_pallet::ParentchainPalletInterface,
parentchain_pallet::ParentchainPalletInstancesInterface,
runtime_upgrade::RuntimeUpgradeInterface,
sudo_pallet::SudoPalletInterface,
system_pallet::{SystemPalletAccountInterface, SystemPalletEventInterface},
Expand Down Expand Up @@ -254,8 +254,8 @@ where
}
}

impl<TCS, G, State, Runtime, ParentchainHeader> ParentchainPalletInterface<State, ParentchainHeader>
for Stf<TCS, G, State, Runtime>
impl<TCS, G, State, Runtime, ParentchainHeader>
ParentchainPalletInstancesInterface<State, ParentchainHeader> for Stf<TCS, G, State, Runtime>
where
State: SgxExternalitiesTrait,
Runtime: frame_system::Config<Header = ParentchainHeader> + pallet_parentchain::Config,
Expand Down
14 changes: 8 additions & 6 deletions bitacross-worker/core-primitives/stf-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait};
use itp_ocall_api::{EnclaveAttestationOCallApi, EnclaveMetricsOCallApi, EnclaveOnChainOCallApi};
use itp_sgx_externalities::{SgxExternalitiesTrait, StateHash};
use itp_stf_interface::{
parentchain_pallet::ParentchainPalletInterface, runtime_upgrade::RuntimeUpgradeInterface,
StateCallInterface, StfExecutionResult, UpdateState,
parentchain_pallet::ParentchainPalletInstancesInterface,
runtime_upgrade::RuntimeUpgradeInterface, StateCallInterface, StfExecutionResult, UpdateState,
};
use itp_stf_primitives::{
traits::TrustedCallVerification,
Expand Down Expand Up @@ -176,10 +176,11 @@ where
Stf: UpdateState<
StateHandler::StateT,
<StateHandler::StateT as SgxExternalitiesTrait>::SgxExternalitiesDiffType,
> + ParentchainPalletInterface<StateHandler::StateT, ParentchainHeader>,
> + ParentchainPalletInstancesInterface<StateHandler::StateT, ParentchainHeader>,
<StateHandler::StateT as SgxExternalitiesTrait>::SgxExternalitiesDiffType:
IntoIterator<Item = (Vec<u8>, Option<Vec<u8>>)>,
<Stf as ParentchainPalletInterface<StateHandler::StateT, ParentchainHeader>>::Error: Debug,
<Stf as ParentchainPalletInstancesInterface<StateHandler::StateT, ParentchainHeader>>::Error:
Debug,
<StateHandler::StateT as SgxExternalitiesTrait>::SgxExternalitiesDiffType:
From<BTreeMap<Vec<u8>, Option<Vec<u8>>>>,
TCS: PartialEq + Encode + Decode + Debug + Clone + Send + Sync + TrustedCallVerification,
Expand Down Expand Up @@ -238,12 +239,13 @@ impl<OCallApi, StateHandler, NodeMetadataRepository, Stf, TCS, G>
where
<StateHandler::StateT as SgxExternalitiesTrait>::SgxExternalitiesDiffType:
From<BTreeMap<Vec<u8>, Option<Vec<u8>>>> + IntoIterator<Item = (Vec<u8>, Option<Vec<u8>>)>,
<Stf as ParentchainPalletInterface<StateHandler::StateT, ParentchainHeader>>::Error: Debug,
<Stf as ParentchainPalletInstancesInterface<StateHandler::StateT, ParentchainHeader>>::Error:
Debug,
NodeMetadataRepository: AccessNodeMetadata,
OCallApi: EnclaveAttestationOCallApi + EnclaveOnChainOCallApi,
StateHandler: HandleState<HashType = H256> + QueryShardState,
StateHandler::StateT: Encode + SgxExternalitiesTrait,
Stf: ParentchainPalletInterface<StateHandler::StateT, ParentchainHeader>
Stf: ParentchainPalletInstancesInterface<StateHandler::StateT, ParentchainHeader>
+ UpdateState<
StateHandler::StateT,
<StateHandler::StateT as SgxExternalitiesTrait>::SgxExternalitiesDiffType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

/// Interface trait of the parentchain pallet.
pub trait ParentchainPalletInterface<State, ParentchainHeader> {
pub trait ParentchainPalletInstancesInterface<State, ParentchainHeader> {
type Error;

/// Updates the block number, block hash and parent hash of the parentchain block.
Expand Down
2 changes: 1 addition & 1 deletion bitacross-worker/enclave-runtime/src/test/tests_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use itp_stf_executor::{
executor_tests as stf_executor_tests, traits::StateUpdateProposer, BatchExecutionResult,
};
use itp_stf_interface::{
parentchain_pallet::ParentchainPalletInterface,
parentchain_pallet::ParentchainPalletInstancesInterface,
system_pallet::{SystemPalletAccountInterface, SystemPalletEventInterface},
StateCallInterface,
};
Expand Down
2 changes: 1 addition & 1 deletion bitacross-worker/service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod sync_state;
mod tests;
mod utils;
mod worker;
mod worker_peers_registry;
mod worker_peers_updater;

#[cfg(feature = "link-binary")]
pub mod main_impl;
Expand Down
2 changes: 1 addition & 1 deletion bitacross-worker/service/src/main_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
setup, sync_state, tests,
utils::extract_shard,
worker::Worker,
worker_peers_registry::WorkerPeersRegistry,
worker_peers_updater::WorkerPeersRegistry,
};
use base58::ToBase58;
use clap::{load_yaml, App, ArgMatches};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
worker_on_chain_ocall::WorkerOnChainOCall,
},
prometheus_metrics::ReceiveEnclaveMetrics,
worker_peers_registry::PeersRegistry,
worker_peers_updater::PeersRegistry,
};
use itp_enclave_api::{enclave_base::EnclaveBase, remote_attestation::RemoteAttestationCallBacks};
use itp_node_api::node_api_factory::CreateNodeApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

use crate::{
worker::{Url, WorkerResult},
worker_peers_registry::PeersRegistry,
worker_peers_updater::PeersRegistry,
};

pub struct WorkerPeersRegistryMock;
Expand Down
74 changes: 61 additions & 13 deletions pallets/parentchain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,90 @@ pub mod pallet {
use frame_system::pallet_prelude::*;

#[pallet::pallet]
pub struct Pallet<T>(_);
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);

/// Configuration trait.
#[pallet::config]
pub trait Config: frame_system::Config {
pub trait Config<I: 'static = ()>: frame_system::Config {
type WeightInfo: WeightInfo;
}

#[pallet::error]
pub enum Error<T, I = ()> {
ShardVaultAlreadyInitialized,
}

/// The current block number being processed. Set by `set_block`.
#[pallet::storage]
#[pallet::getter(fn block_number)]
pub(super) type Number<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
pub(super) type Number<T: Config<I>, I: 'static = ()> =
StorageValue<_, T::BlockNumber, ValueQuery>;

/// Hash of the previous block. Set by `set_block`.
#[pallet::storage]
#[pallet::getter(fn parent_hash)]
pub(super) type ParentHash<T: Config> = StorageValue<_, T::Hash, ValueQuery>;
pub(super) type ParentHash<T: Config<I>, I: 'static = ()> =
StorageValue<_, T::Hash, ValueQuery>;

/// Hash of the last block. Set by `set_block`.
#[pallet::storage]
#[pallet::getter(fn block_hash)]
pub(super) type BlockHash<T: Config> = StorageValue<_, T::Hash, ValueQuery>;
pub(super) type BlockHash<T: Config<I>, I: 'static = ()> = StorageValue<_, T::Hash, ValueQuery>;

/// The current block number being processed. Set by `init_shard_vault`.
#[pallet::storage]
#[pallet::getter(fn shard_vault)]
pub(super) type ShardVault<T: Config<I>, I: 'static = ()> =
StorageValue<_, T::AccountId, OptionQuery>;

#[pallet::storage]
#[pallet::getter(fn creation_block_hash)]
pub(super) type CreationBlockHash<T: Config<I>, I: 'static = ()> =
StorageValue<_, T::Hash, OptionQuery>;

/// The creation block number. Set by `set_creation_block`.
#[pallet::storage]
#[pallet::getter(fn creation_block_number)]
pub(super) type CreationBlockNumber<T: Config<I>, I: 'static = ()> =
StorageValue<_, T::BlockNumber, OptionQuery>;

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {}
impl<T: Config<I>, I: 'static> Hooks<T::BlockNumber> for Pallet<T, I> {}

#[pallet::call]
impl<T: Config> Pallet<T> {
impl<T: Config<I>, I: 'static> Pallet<T, I> {
#[pallet::call_index(0)]
#[pallet::weight(<T as Config>::WeightInfo::set_block())]
pub fn set_block(origin: OriginFor<T>, header: T::Header) -> DispatchResult {
#[pallet::weight({195_000})]
pub fn set_block(origin: OriginFor<T>, header: T::Header) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
<Number<T, I>>::put(header.number());
<ParentHash<T, I>>::put(header.parent_hash());
<BlockHash<T, I>>::put(header.hash());
Ok(Pays::No.into())
}

#[pallet::call_index(1)]
#[pallet::weight({195_000})]
pub fn init_shard_vault(
origin: OriginFor<T>,
account: T::AccountId,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
ensure!(Self::shard_vault().is_none(), Error::<T, I>::ShardVaultAlreadyInitialized);
<ShardVault<T, I>>::put(account.clone());
Ok(Pays::No.into())
}

#[pallet::call_index(2)]
#[pallet::weight({195_000})]
pub fn set_creation_block(
origin: OriginFor<T>,
header: T::Header,
) -> DispatchResultWithPostInfo {
ensure_root(origin)?;
<Number<T>>::put(header.number());
<ParentHash<T>>::put(header.parent_hash());
<BlockHash<T>>::put(header.hash());
Ok(())
<CreationBlockNumber<T, I>>::put(header.number());
<CreationBlockHash<T, I>>::put(header.hash());
Ok(Pays::No.into())
}
}
}
Expand Down
92 changes: 5 additions & 87 deletions scripts/generate-upstream-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ UPSTREAM_URL_PREFIX="https://github.com/integritee-network"

function usage() {
echo "Usage:"
echo "For pallets: $0 p [pallets-new-commit]"
echo "For worker : $0 w [worker-new-commit]"
echo "For worker : $0 [worker-new-commit]"
}

function add_upstream_url() {
Expand Down Expand Up @@ -53,73 +52,6 @@ function generate_worker_patch() {
echo "done"
}

# This function generates a handful of patches for the diffs between commit-A and commit-B
# of the upstream repo, where
# - commit-A: the commit recorded in tee-worker/upstream_commit
# - commit-B: the HEAD of the given commit
# The patches will be generated under pallets/
# - pallets/pallets_xxx.patch
# - pallets/primitives_xxx.patch
function generate_pallets_patch() {
local dest_dir="$ROOTDIR/pallets"
local upstream_url="$UPSTREAM_URL_PREFIX/pallets"

cd "$dest_dir"
if [ -f upstream_commit ]; then
OLD_COMMIT=$(head -1 upstream_commit)
else
echo "Can't find upstream_commit file in $dest_dir, quit"
exit 1
fi

echo "fetching upstream_pallets"
git fetch -q "upstream_pallets"

local tmp_dir
tmp_dir=$(mktemp -d)
cd "$tmp_dir"
echo "cloning $upstream_url to $tmp_dir"
git clone -q "$upstream_url"
cd pallets && git checkout "$1"
echo "generating patch ..."

# pallets
local pallets=("parentchain" "sidechain" "teeracle" "teerex" "test-utils")
for p in "${pallets[@]}"; do
echo "generating $p.patch"
git diff --binary "$OLD_COMMIT" HEAD -- "$p" > "$dest_dir/pallets_$p.patch"
done

# primitives
local primitives=("sidechain" "teeracle" "teerex" "common")
for p in "${primitives[@]}"; do
echo "generating primitives_$p.patch"
git diff --binary "$OLD_COMMIT" HEAD -- primitives/"$p" > "$dest_dir/primitives_$p.patch"
done

git rev-parse --short HEAD > "$dest_dir/upstream_commit"
rm -rf "$tmp_dir"
echo "done"
}

function apply_pallets_tips() {
echo "======================================================================="
echo "upstream_commit(s) are updated."
echo "upstream.patch(s) are generated."
echo "To apply it, RUN FROM $ROOTDIR:"
echo " # Pallet patches:"
echo " git apply --allow-empty -p1 -3 --directory=pallets $ROOTDIR/pallets/pallets_xxx.patch"
echo " # Primitive patches:"
echo " git apply --allow-empty -p1 -3 $ROOTDIR/pallets/primitives_xxx.patch"

echo ""
echo "after that, please:"
echo "- pay special attention: "
echo " * ALL changes/conflicts from pallets_xxx.patch should ONLY apply into:"
echo " - pallets/(parentchain, sidechain, teeracle, teerex, test-utils)"
echo " - primitives/(common, sidechain, teeracle, teerex)"
}

function apply_worker_tips() {
echo "======================================================================="
echo "upstream_commit(s) are updated."
Expand All @@ -138,22 +70,8 @@ function apply_worker_tips() {
echo "- apply any changes of workflows/build_and_test.yml to $ROOTDIR/.github/workflows/ci.yml"
}

NEW_COMMIT=${2:-master}

case "$1" in
p)
add_upstream_url "pallets"
generate_pallets_patch "$NEW_COMMIT"
apply_pallets_tips
;;
w)
add_upstream_url "worker"
generate_worker_patch "$NEW_COMMIT"
apply_worker_tips
;;
*)
usage; exit 1 ;;
esac


NEW_COMMIT=${1:-master}

add_upstream_url "worker"
generate_worker_patch "$NEW_COMMIT"
apply_worker_tips

0 comments on commit ca83789

Please sign in to comment.