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 16 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
2 changes: 1 addition & 1 deletion core/packages/test/scripts/deploy-ethereum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ start_lodestar() {
--enr.ip6 "127.0.0.1" \
--eth1.providerUrls "http://127.0.0.1:8545" \
--execution.urls "http://127.0.0.1:8551" \
--dataDir "$output_dir/beacon-$timestamp" \
--dataDir "$ethereum_data_dir" \
--reset \
--terminal-total-difficulty-override 0 \
--genesisEth1Hash $genesisHash \
Expand Down
3 changes: 1 addition & 2 deletions core/packages/test/scripts/set-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ cumulus_bin="${CUMULUS_BIN:-$cumulus_dir/bin/polkadot-parachain}"
core_dir="$root_dir/core"
lodestar_version="${LODESTAR_VER:-1.8.0}"
geth_version="${GETH_VER:-v1.11.2}"
geth_dir="$root_dir/../go-ethereum/$geth_version"
contract_dir="$core_dir/packages/contracts"
relay_dir="$root_dir/relayer"
relay_bin="$relay_dir/build/snowbridge-relay"
export output_dir="${OUTPUT_DIR:-/tmp/snowbridge}"
export output_bin_dir="$output_dir/bin"
ethereum_data_dir="$output_dir/geth"
ethereum_data_dir="$output_dir/ethereum"
zombienet_data_dir="$output_dir/zombienet"
export PATH="$output_bin_dir:$PATH"

Expand Down
2 changes: 1 addition & 1 deletion core/packages/test/scripts/start-ethereum.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ start_chains()
if [ -z "${from_start_services:-}" ]; then
echo "start ethereum only!"
trap kill_all SIGINT SIGTERM EXIT
check_tool && cleanup && start_chains
check_tool && rm -rf "$ethereum_data_dir" && start_chains
wait
fi
15 changes: 11 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,23 @@ 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"
# explicit config max-old-space-size or will be oom
node --max-old-space-size=4096 ../../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 &
echo "Waiting for beacon node to sync from checkpoint"
sleep 10
echo "Ethereum started!"
}

if [ -z "${from_start_services:-}" ]; then
echo "start goerli locally!"
trap kill_all SIGINT SIGTERM EXIT
start_chains
check_tool && rm -rf "$ethereum_data_dir" && start_chains
wait
fi
2 changes: 1 addition & 1 deletion core/packages/test/scripts/start-polkadot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ start_chains()
if [ -z "${from_start_services:-}" ]; then
echo "start polkadot only!"
trap kill_all SIGINT SIGTERM EXIT
check_tool && build_relaychain && build_cumulus_from_source && start_chains
check_tool && build_relaychain && build_cumulus_from_source && rm -rf $zombienet_data_dir && 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn participant_pubkeys<T: Config>(
let current_sync_committee = <CurrentSyncCommittee<T>>::get();
let pubkeys = EthereumBeaconClient::<T>::find_pubkeys(
&sync_committee_bits,
&current_sync_committee.pubkeys.as_ref(),
(*current_sync_committee.pubkeys).as_ref(),
true,
);
Ok(pubkeys)
Expand All @@ -25,7 +25,7 @@ pub fn absent_pubkeys<T: Config>(update: &Update) -> Result<Vec<PublicKeyPrepare
let current_sync_committee = <CurrentSyncCommittee<T>>::get();
let pubkeys = EthereumBeaconClient::<T>::find_pubkeys(
&sync_committee_bits,
&current_sync_committee.pubkeys.as_ref(),
(*current_sync_committee.pubkeys).as_ref(),
false,
);
Ok(pubkeys)
Expand Down
60 changes: 16 additions & 44 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 @@ -417,7 +387,8 @@ pub mod pallet {
} else {
<NextSyncCommittee<T>>::get()
};
let absent_pubkeys = Self::find_pubkeys(&participation, &sync_committee.pubkeys, false);
let absent_pubkeys =
Self::find_pubkeys(&participation, (*sync_committee.pubkeys).as_ref(), false);
let signing_root = Self::signing_root(
&update.attested_header,
Self::validators_root(),
Expand All @@ -439,11 +410,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 +457,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 +712,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