Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase test coverage & Fix for goerli setup #853

Merged
merged 26 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/ethereum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ jobs:
node-version: v18.16.0
cache: "pnpm"
cache-dependency-path: core/pnpm-lock.yaml
- name: Install dependencies
working-directory: core
run: pnpm install --frozen-lockfile
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Build
working-directory: core/packages/contracts
run: pnpm build
- name: Install dependencies and Build all
working-directory: core
run: pnpm install --frozen-lockfile && pnpm build
- name: Test
working-directory: core/packages/contracts
run: forge test
Expand Down
7 changes: 5 additions & 2 deletions core/init.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env sh
#!/usr/bin/env bash

echo "Update submodules"
(cd .. && (git submodule update --init --recursive||true))

echo "Install husky hook"
(cd .. && ./core/node_modules/.bin/husky install)

echo "Installing sszgen"
go install github.com/ferranbt/fastssz/sszgen@latest

echo "Initialize foundry libraries"
(cd packages/contracts && (forge install||true))
(cd packages/contracts && forge install)

2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"scripts": {
"preinstall": "npx only-allow pnpm",
"postinstall": "./init.sh",
"postinstall": "/bin/bash ./init.sh",
yrong marked this conversation as resolved.
Show resolved Hide resolved
"build": "turbo run build --filter '!./packages/contracts/lib/*'",
"test": "turbo run test --filter '!./packages/contracts/lib/*'",
"lint": "turbo run lint --filter '!./packages/contracts/lib/*'",
Expand Down
2 changes: 0 additions & 2 deletions core/packages/test/scripts/configure-beacon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ config_beacon_checkpoint()
check_point_call=$($relay_bin generate-beacon-checkpoint --spec $active_spec --url $beacon_endpoint_http)
popd
send_governance_transact_from_relaychain $bridgehub_para_id "$check_point_call" 180000000000 900000
# waiting for xcm to be executed on parachain
sleep 12
}

wait_beacon_chain_ready()
Expand Down
13 changes: 9 additions & 4 deletions core/packages/test/scripts/start-goerli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ set -eu

source scripts/set-env.sh


start_chains()
{
npx lodestar beacon --dataDir="./ethereum-goerli" --network="goerli" --rest.namespace="*" --jwt-secret="./config/jwtsecret" --checkpointSyncUrl="https://sync-goerli.beaconcha.in" 2>&1 &
geth --goerli --override.shanghai=0 --datadir="./ethereum-goerli" --authrpc.addr="127.0.0.1" --http.addr="0.0.0.0" --http.corsdomain '*' --http --http.api eth,net,engine,admin --authrpc.jwtsecret config/jwtsecret 2>&1 &
echo "Starting execution node"
geth --goerli --override.shanghai=0 --datadir="$ethereum_data_dir" --authrpc.addr="127.0.0.1" --http.addr="0.0.0.0" --http.corsdomain '*' --http --http.api eth,net,engine,admin --authrpc.jwtsecret config/jwtsecret > "$output_dir/geth.log" 2>&1 &
echo "Waiting for geth API to be ready"
sleep 3
echo "Starting beacon node"
# npx lodestar beacon --dataDir="$ethereum_data_dir" --network="goerli" --rest.namespace="*" --jwt-secret="./config/jwtsecret" --checkpointSyncUrl="https://sync-goerli.beaconcha.in" > "$output_dir/lodestar.log" 2>&1 &
node --max-old-space-size=4096 ./node_modules/.bin/../../../../node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@chainsafe/lodestar/lib/index.js beacon --dataDir="$ethereum_data_dir" --network=goerli --rest.namespace=* --jwt-secret=./config/jwtsecret --checkpointSyncUrl=https://sync-goerli.beaconcha.in > "$output_dir/lodestar.log" 2>&1 &

}

if [ -z "${from_start_services:-}" ]; then
echo "start goerli locally!"
trap kill_all SIGINT SIGTERM EXIT
start_chains
check_tool && cleanup && start_chains
wait
fi
2 changes: 1 addition & 1 deletion core/packages/test/scripts/start-relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ build_relayer()
if [ -z "${from_start_services:-}" ]; then
echo "start relayers only!"
trap kill_all SIGINT SIGTERM EXIT
check_tool && build_relayer && start_relayer
check_tool && build_relayer && config_relayer && start_relayer
wait
fi
57 changes: 14 additions & 43 deletions parachain/pallets/ethereum-beacon-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,47 +89,25 @@ pub mod pallet {
#[pallet::error]
#[cfg_attr(test, derive(PartialEq))]
pub enum Error<T> {
AncientHeader,
SkippedSyncCommitteePeriod,
SyncCommitteeMissing,
NotRelevant,
Unknown,
NotBootstrapped,
SyncCommitteeParticipantsNotSupermajority,
InvalidHeaderMerkleProof,
InvalidSyncCommitteeMerkleProof,
InvalidExecutionHeaderProof,
InvalidAncestryMerkleProof,
InvalidBlockRootsRootMerkleProof,
InvalidHash,
InvalidSyncCommitteeBits,
SignatureVerificationFailed,
NoBranchExpected,
HeaderNotFinalized,
MissingHeader,
MissingFinalityHeader,
InvalidProof,
InvalidBlockRootAtSlot,
DecodeFailed,
BlockBodyHashTreeRootFailed,
BlockRootsHashTreeRootFailed,
HeaderHashTreeRootFailed,
SyncCommitteeHashTreeRootFailed,
SigningRootHashTreeRootFailed,
ForkDataHashTreeRootFailed,
ExecutionHeaderNotLatest,
UnexpectedHeaderSlotPosition,
ExpectedFinalizedHeaderNotStored,
BridgeBlocked,
InvalidSyncCommitteeUpdateWithGap,
InvalidSyncCommitteeUpdateWithDuplication,
InvalidSignatureSlot,
InvalidAttestedHeaderSlot,
DuplicateFinalizedHeaderUpdate,
InvalidFinalizedPeriodUpdate,
ExecutionHeaderAlreadyImported,
FinalizedBeaconHeaderSlotsExceeded,
ExecutionHeaderMappingFailed,
yrong marked this conversation as resolved.
Show resolved Hide resolved
BLSPreparePublicKeysFailed,
BLSVerificationFailed(BlsError),
InvalidUpdateSlot,
Expand Down Expand Up @@ -295,12 +273,8 @@ pub mod pallet {
// that happens just return error so to pause processing FinalizedHeader until
// ExecutionHeader catch up
fn cross_check_execution_state() -> DispatchResult {
let latest_finalized_state: CompactBeaconState =
match Self::finalized_beacon_state(Self::latest_finalized_block_root()) {
Some(finalized_beacon_state) => finalized_beacon_state,
None => return Err(Error::<T>::NotBootstrapped.into()),
};
let latest_execution_state: ExecutionHeaderState = Self::latest_execution_state();
let latest_finalized_state = Self::latest_finalized_state()?;
let latest_execution_state = Self::latest_execution_state();
let max_latency = config::EPOCHS_PER_SYNC_COMMITTEE_PERIOD * config::SLOTS_PER_EPOCH;
ensure!(
latest_execution_state.beacon_slot == 0 ||
Expand All @@ -326,11 +300,7 @@ pub mod pallet {
);

// Retrieve latest finalized state
let latest_finalized_state: CompactBeaconState =
match Self::finalized_beacon_state(Self::latest_finalized_block_root()) {
Some(finalized_beacon_state) => finalized_beacon_state,
None => return Err(Error::<T>::NotBootstrapped.into()),
};
let latest_finalized_state = Self::latest_finalized_state()?;

let store_period = compute_period(latest_finalized_state.slot);
let signature_period = compute_period(update.signature_slot);
Expand Down Expand Up @@ -439,11 +409,7 @@ pub mod pallet {

// reference and strict follows https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#apply_light_client_update
fn apply_update(update: &Update) -> DispatchResult {
let latest_finalized_state: CompactBeaconState =
match Self::finalized_beacon_state(Self::latest_finalized_block_root()) {
Some(finalized_beacon_state) => finalized_beacon_state,
None => return Err(Error::<T>::NotBootstrapped.into()),
};
let latest_finalized_state = Self::latest_finalized_state()?;
if let Some(next_sync_committee_update) = &update.next_sync_committee_update {
let store_period = compute_period(latest_finalized_state.slot);
let update_finalized_period = compute_period(update.finalized_header.slot);
Expand Down Expand Up @@ -490,11 +456,7 @@ pub mod pallet {
pub(crate) fn process_execution_header_update(
update: &ExecutionHeaderUpdate,
) -> DispatchResult {
let latest_finalized_state: CompactBeaconState =
match Self::finalized_beacon_state(Self::latest_finalized_block_root()) {
Some(finalized_beacon_state) => finalized_beacon_state,
None => return Err(Error::<T>::NotBootstrapped.into()),
};
let latest_finalized_state = Self::latest_finalized_state()?;
ensure!(
update.header.slot <= latest_finalized_state.slot,
Error::<T>::HeaderNotFinalized
Expand Down Expand Up @@ -749,5 +711,14 @@ pub mod pallet {
let signing_root = Self::compute_signing_root(header, domain)?;
Ok(signing_root)
}

pub fn latest_finalized_state() -> Result<CompactBeaconState, DispatchError> {
let latest_finalized_state =
match FinalizedBeaconState::<T>::get(LatestFinalizedBlockRoot::<T>::get()) {
Some(finalized_beacon_state) => finalized_beacon_state,
None => return Err(Error::<T>::NotBootstrapped.into()),
};
Ok(latest_finalized_state)
yrong marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
10 changes: 10 additions & 0 deletions parachain/pallets/ethereum-beacon-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,20 @@ pub mod minimal {
load_fixture("sync-committee-update.minimal.json").unwrap()
}

pub fn load_next_sync_committee_update_fixture(
) -> primitives::Update<{ config::SYNC_COMMITTEE_SIZE }, { config::SYNC_COMMITTEE_BITS_SIZE }> {
load_fixture("next-sync-committee-update.minimal.json").unwrap()
}

pub fn load_finalized_header_update_fixture(
) -> primitives::Update<{ config::SYNC_COMMITTEE_SIZE }, { config::SYNC_COMMITTEE_BITS_SIZE }> {
load_fixture("finalized-header-update.minimal.json").unwrap()
}

pub fn load_next_finalized_header_update_fixture(
) -> primitives::Update<{ config::SYNC_COMMITTEE_SIZE }, { config::SYNC_COMMITTEE_BITS_SIZE }> {
load_fixture("next-finalized-header-update.minimal.json").unwrap()
}
}

#[cfg(feature = "beacon-spec-mainnet")]
Expand Down
Loading