Skip to content

Commit

Permalink
PR comments for upstream (Snowfork#1127)
Browse files Browse the repository at this point in the history
* cleanup of mocks

* Adds Ethereum constant comments

* adds more comments

* clippy

* revert mock runtime changes

---------

Co-authored-by: claravanstaden <Cats 4 life!>
  • Loading branch information
claravanstaden authored Jan 29, 2024
1 parent 252df12 commit ec4df8e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 39 deletions.
28 changes: 20 additions & 8 deletions parachain/pallets/ethereum-client/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,64 @@
use primitives::merkle_proof::{generalized_index_length, subtree_index};
use static_assertions::const_assert;

// Generalized Indices

// get_generalized_index(BeaconState, 'block_roots')
/// Generalized Indices
/// related to Merkle proofs
/// get_generalized_index(BeaconState, 'block_roots')
pub const BLOCK_ROOTS_INDEX: usize = 37;
pub const BLOCK_ROOTS_SUBTREE_INDEX: usize = subtree_index(BLOCK_ROOTS_INDEX);
pub const BLOCK_ROOTS_DEPTH: usize = generalized_index_length(BLOCK_ROOTS_INDEX);

// get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')
/// get_generalized_index(BeaconState, 'finalized_checkpoint', 'root')
pub const FINALIZED_ROOT_INDEX: usize = 105;
pub const FINALIZED_ROOT_SUBTREE_INDEX: usize = subtree_index(FINALIZED_ROOT_INDEX);
pub const FINALIZED_ROOT_DEPTH: usize = generalized_index_length(FINALIZED_ROOT_INDEX);

// get_generalized_index(BeaconState, 'current_sync_committee')
/// get_generalized_index(BeaconState, 'current_sync_committee')
pub const CURRENT_SYNC_COMMITTEE_INDEX: usize = 54;
pub const CURRENT_SYNC_COMMITTEE_SUBTREE_INDEX: usize = subtree_index(CURRENT_SYNC_COMMITTEE_INDEX);
pub const CURRENT_SYNC_COMMITTEE_DEPTH: usize =
generalized_index_length(CURRENT_SYNC_COMMITTEE_INDEX);

// get_generalized_index(BeaconState, 'next_sync_committee')
/// get_generalized_index(BeaconState, 'next_sync_committee')
pub const NEXT_SYNC_COMMITTEE_INDEX: usize = 55;
pub const NEXT_SYNC_COMMITTEE_SUBTREE_INDEX: usize = subtree_index(NEXT_SYNC_COMMITTEE_INDEX);
pub const NEXT_SYNC_COMMITTEE_DEPTH: usize = generalized_index_length(NEXT_SYNC_COMMITTEE_INDEX);

// get_generalized_index(BeaconBlockBody, 'execution_payload')
/// get_generalized_index(BeaconBlockBody, 'execution_payload')
pub const EXECUTION_HEADER_INDEX: usize = 25;
pub const EXECUTION_HEADER_SUBTREE_INDEX: usize = subtree_index(EXECUTION_HEADER_INDEX);
pub const EXECUTION_HEADER_DEPTH: usize = generalized_index_length(EXECUTION_HEADER_INDEX);

/// Sizes related to SSZ encoding
pub const MAX_EXTRA_DATA_BYTES: usize = 32;
pub const MAX_LOGS_BLOOM_SIZE: usize = 256;
pub const MAX_FEE_RECIPIENT_SIZE: usize = 20;

/// Sanity value to constain the max size of a merkle branch proof.
pub const MAX_BRANCH_PROOF_SIZE: usize = 20;

/// DomainType('0x07000000')
/// <https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/beacon-chain.md#domain-types>
pub const DOMAIN_SYNC_COMMITTEE: [u8; 4] = [7, 0, 0, 0];

/// Validators public keys are 48 bytes.
pub const PUBKEY_SIZE: usize = 48;
/// Signatures produced by validators are 96 bytes.
pub const SIGNATURE_SIZE: usize = 96;

// Sanity check for the sync committee bits (see SYNC_COMMITTEE_BITS_SIZE).
const_assert!(SYNC_COMMITTEE_BITS_SIZE == SYNC_COMMITTEE_SIZE / 8);

/// Defined in <https://github.com/ethereum/consensus-specs/tree/f1dff5f6768608d890fc0b347e548297fc3e1f1c/presets/mainnet>
/// There are 32 slots in an epoch. An epoch is 6.4 minutes long.
pub const SLOTS_PER_EPOCH: usize = 32;
/// 256 epochs in a sync committee period. Frequency of sync committee (subset of Ethereum
/// validators) change is every ~27 hours.
pub const EPOCHS_PER_SYNC_COMMITTEE_PERIOD: usize = 256;
/// A sync committee contains 512 randomly selected validators.
pub const SYNC_COMMITTEE_SIZE: usize = 512;
/// An array of sync committee block votes, one bit representing the vote of one validator.
pub const SYNC_COMMITTEE_BITS_SIZE: usize = SYNC_COMMITTEE_SIZE / 8;
/// The size of the block root array in the beacon state, used for ancestry proofs.
pub const SLOTS_PER_HISTORICAL_ROOT: usize = 8192;
/// The index of the block_roots field in the beacon state tree.
pub const BLOCK_ROOT_AT_INDEX_DEPTH: usize = 13;
33 changes: 2 additions & 31 deletions parachain/pallets/ethereum-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]>
use crate as ethereum_beacon_client;
use crate::config;
use frame_support::parameter_types;
use frame_support::{derive_impl, parameter_types};
use hex_literal::hex;
use pallet_timestamp;
use primitives::{CompactExecutionHeader, Fork, ForkVersions};
use snowbridge_core::inbound::{Log, Proof};
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use std::{fs::File, path::PathBuf};
type Block = frame_system::mocking::MockBlock<Test>;
use sp_runtime::BuildStorage;
Expand Down Expand Up @@ -97,35 +95,8 @@ frame_support::construct_runtime!(
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub const SS58Prefix: u8 = 42;
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = frame_support::traits::Everything;
type OnSetCode = ();
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type RuntimeTask = RuntimeTask;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = ();
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = SS58Prefix;
type MaxConsumers = frame_support::traits::ConstU32<16>;
type Nonce = u64;
type Block = Block;
}

Expand Down

0 comments on commit ec4df8e

Please sign in to comment.