mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 10:54:24 +00:00
Migrate from ethereum-types to alloy-primitives (#6078)
* Remove use of ethers_core::RlpStream
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core
* Remove old code
* Simplify keccak call
* Remove unused package
* Merge branch 'unstable' of https://github.com/ethDreamer/lighthouse into remove_use_of_ethers_core
* Merge branch 'unstable' into remove_use_of_ethers_core
* Run clippy
* Merge branch 'remove_use_of_ethers_core' of https://github.com/dospore/lighthouse into remove_use_of_ethers_core
* Check all cargo fmt
* migrate to alloy primitives init
* fix deps
* integrate alloy-primitives
* resolve dep issues
* more changes based on dep changes
* add TODOs
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core
* Revert lock
* Add BeaconBlocksByRange v3
* continue migration
* Revert "Add BeaconBlocksByRange v3"
This reverts commit e3ce7fc5ea.
* impl hash256 extended trait
* revert some uneeded diffs
* merge conflict resolved
* fix subnet id rshift calc
* rename to FixedBytesExtended
* debugging
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives
* fix failed test
* fixing more tests
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into remove_use_of_ethers_core
* introduce a shim to convert between the two u256 types
* move alloy to wrokspace
* align alloy versions
* update
* update web3signer test certs
* refactor
* resolve failing tests
* linting
* fix graffiti string test
* fmt
* fix ef test
* resolve merge conflicts
* remove udep and revert cert
* cargo patch
* cyclic dep
* fix build error
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives
* resolve conflicts, update deps
* merge unstable
* fmt
* fix deps
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives
* resolve merge conflicts
* resolve conflicts, make necessary changes
* Remove patch
* fmt
* remove file
* merge conflicts
* sneaking in a smol change
* bump versions
* Merge remote-tracking branch 'origin/unstable' into migrate-to-alloy-primitives
* Updates for peerDAS
* Update ethereum_hashing to prevent dupe
* updated alloy-consensus, removed TODOs
* cargo update
* endianess fix
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives
* fmt
* fix merge
* fix test
* fixed_bytes crate
* minor fixes
* convert u256 to i64
* panic free mixin to_low_u64_le
* from_str_radix
* computbe_subnet api and ensuring we use big-endian
* Merge branch 'unstable' of https://github.com/sigp/lighthouse into migrate-to-alloy-primitives
* fix test
* Simplify subnet_id test
* Simplify some more tests
* Add tests to fixed_bytes crate
* Merge branch 'unstable' into migrate-to-alloy-primitives
This commit is contained in:
@@ -23,6 +23,7 @@ serde_json = { workspace = true }
|
||||
criterion = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
alloy-primitives = { workspace = true }
|
||||
bitvec = { workspace = true }
|
||||
bls = { workspace = true }
|
||||
derivative = { workspace = true }
|
||||
|
||||
@@ -19,8 +19,8 @@ use types::{
|
||||
beacon_state::{
|
||||
compute_committee_index_in_epoch, compute_committee_range_in_epoch, epoch_committee_count,
|
||||
},
|
||||
BeaconState, BeaconStateError, ChainSpec, Checkpoint, Epoch, EthSpec, Hash256, RelativeEpoch,
|
||||
Slot,
|
||||
BeaconState, BeaconStateError, ChainSpec, Checkpoint, Epoch, EthSpec, FixedBytesExtended,
|
||||
Hash256, RelativeEpoch, Slot,
|
||||
};
|
||||
|
||||
type JustifiedCheckpoint = Checkpoint;
|
||||
|
||||
@@ -715,7 +715,9 @@ mod tests {
|
||||
use std::sync::LazyLock;
|
||||
use std::time::Duration;
|
||||
use tokio::sync::mpsc;
|
||||
use types::{ChainSpec, Epoch, EthSpec, Hash256, Keypair, MinimalEthSpec, Slot};
|
||||
use types::{
|
||||
ChainSpec, Epoch, EthSpec, FixedBytesExtended, Hash256, Keypair, MinimalEthSpec, Slot,
|
||||
};
|
||||
|
||||
const VALIDATOR_COUNT: usize = 48;
|
||||
|
||||
|
||||
@@ -134,10 +134,10 @@ pub type ForkChoiceError = fork_choice::Error<crate::ForkChoiceStoreError>;
|
||||
type HashBlockTuple<E> = (Hash256, RpcBlock<E>);
|
||||
|
||||
// These keys are all zero because they get stored in different columns, see `DBColumn` type.
|
||||
pub const BEACON_CHAIN_DB_KEY: Hash256 = Hash256::zero();
|
||||
pub const OP_POOL_DB_KEY: Hash256 = Hash256::zero();
|
||||
pub const ETH1_CACHE_DB_KEY: Hash256 = Hash256::zero();
|
||||
pub const FORK_CHOICE_DB_KEY: Hash256 = Hash256::zero();
|
||||
pub const BEACON_CHAIN_DB_KEY: Hash256 = Hash256::ZERO;
|
||||
pub const OP_POOL_DB_KEY: Hash256 = Hash256::ZERO;
|
||||
pub const ETH1_CACHE_DB_KEY: Hash256 = Hash256::ZERO;
|
||||
pub const FORK_CHOICE_DB_KEY: Hash256 = Hash256::ZERO;
|
||||
|
||||
/// Defines how old a block can be before it's no longer a candidate for the early attester cache.
|
||||
const EARLY_ATTESTER_CACHE_HISTORIC_SLOTS: u64 = 4;
|
||||
@@ -528,7 +528,7 @@ impl<E: EthSpec> BeaconBlockResponseWrapper<E> {
|
||||
}
|
||||
|
||||
pub fn consensus_block_value_wei(&self) -> Uint256 {
|
||||
Uint256::from(self.consensus_block_value_gwei()) * 1_000_000_000
|
||||
Uint256::from(self.consensus_block_value_gwei()) * Uint256::from(1_000_000_000)
|
||||
}
|
||||
|
||||
pub fn is_blinded(&self) -> bool {
|
||||
@@ -3446,7 +3446,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
{
|
||||
let mut slashable_cache = self.observed_slashable.write();
|
||||
for header in blobs
|
||||
.into_iter()
|
||||
.iter()
|
||||
.filter_map(|b| b.as_ref().map(|b| b.signed_block_header.clone()))
|
||||
.unique()
|
||||
{
|
||||
@@ -5425,7 +5425,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
},
|
||||
}),
|
||||
None,
|
||||
Uint256::zero(),
|
||||
Uint256::ZERO,
|
||||
),
|
||||
BeaconState::Altair(_) => (
|
||||
BeaconBlock::Altair(BeaconBlockAltair {
|
||||
@@ -5448,7 +5448,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
||||
},
|
||||
}),
|
||||
None,
|
||||
Uint256::zero(),
|
||||
Uint256::ZERO,
|
||||
),
|
||||
BeaconState::Bellatrix(_) => {
|
||||
let block_proposal_contents =
|
||||
|
||||
@@ -17,7 +17,7 @@ use store::{Error as StoreError, HotColdDB, ItemStore};
|
||||
use superstruct::superstruct;
|
||||
use types::{
|
||||
AbstractExecPayload, BeaconBlockRef, BeaconState, BeaconStateError, Checkpoint, Epoch, EthSpec,
|
||||
Hash256, Slot,
|
||||
FixedBytesExtended, Hash256, Slot,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -64,7 +64,7 @@ impl MergeConfig {
|
||||
/// Instantiate `self` from the values in a `ChainSpec`.
|
||||
pub fn from_chainspec(spec: &ChainSpec) -> Self {
|
||||
let mut params = MergeConfig::default();
|
||||
if spec.terminal_total_difficulty != Uint256::max_value() {
|
||||
if spec.terminal_total_difficulty != Uint256::MAX {
|
||||
params.terminal_total_difficulty = Some(spec.terminal_total_difficulty);
|
||||
}
|
||||
if spec.terminal_block_hash != ExecutionBlockHash::zero() {
|
||||
|
||||
@@ -294,6 +294,7 @@ impl BlockTimesCache {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use types::FixedBytesExtended;
|
||||
|
||||
#[test]
|
||||
fn observed_time_uses_minimum() {
|
||||
|
||||
@@ -39,8 +39,8 @@ use std::time::Duration;
|
||||
use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp};
|
||||
use task_executor::{ShutdownReason, TaskExecutor};
|
||||
use types::{
|
||||
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, Checkpoint, Epoch, EthSpec, Hash256,
|
||||
Signature, SignedBeaconBlock, Slot,
|
||||
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, Checkpoint, Epoch, EthSpec,
|
||||
FixedBytesExtended, Hash256, Signature, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
/// An empty struct used to "witness" all the `BeaconChainTypes` traits. It has no user-facing
|
||||
@@ -1292,7 +1292,7 @@ mod test {
|
||||
}
|
||||
|
||||
for v in state.validators() {
|
||||
let creds = v.withdrawal_credentials.as_bytes();
|
||||
let creds = v.withdrawal_credentials.as_slice();
|
||||
assert_eq!(
|
||||
creds[0], spec.bls_withdrawal_prefix_byte,
|
||||
"first byte of withdrawal creds should be bls prefix"
|
||||
|
||||
@@ -273,7 +273,6 @@ impl<E: EthSpec> PendingComponents<E> {
|
||||
let num_blobs_expected = diet_executed_block.num_blobs_expected();
|
||||
let Some(verified_blobs) = verified_blobs
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.map(|b| b.map(|b| b.to_blob()))
|
||||
.take(num_blobs_expected)
|
||||
.collect::<Option<Vec<_>>>()
|
||||
@@ -1155,7 +1154,9 @@ mod pending_components_tests {
|
||||
use rand::SeedableRng;
|
||||
use state_processing::ConsensusContext;
|
||||
use types::test_utils::TestRandom;
|
||||
use types::{BeaconState, ForkName, MainnetEthSpec, SignedBeaconBlock, Slot};
|
||||
use types::{
|
||||
BeaconState, FixedBytesExtended, ForkName, MainnetEthSpec, SignedBeaconBlock, Slot,
|
||||
};
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
|
||||
@@ -685,7 +685,7 @@ fn is_candidate_block(block: &Eth1Block, period_start: u64, spec: &ChainSpec) ->
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use types::{DepositData, MinimalEthSpec, Signature};
|
||||
use types::{DepositData, FixedBytesExtended, MinimalEthSpec, Signature};
|
||||
|
||||
type E = MinimalEthSpec;
|
||||
|
||||
|
||||
@@ -505,7 +505,7 @@ where
|
||||
return Ok(BlockProposalContentsType::Full(
|
||||
BlockProposalContents::Payload {
|
||||
payload: FullPayload::default_at_fork(fork)?,
|
||||
block_value: Uint256::zero(),
|
||||
block_value: Uint256::ZERO,
|
||||
},
|
||||
));
|
||||
}
|
||||
@@ -523,7 +523,7 @@ where
|
||||
return Ok(BlockProposalContentsType::Full(
|
||||
BlockProposalContents::Payload {
|
||||
payload: FullPayload::default_at_fork(fork)?,
|
||||
block_value: Uint256::zero(),
|
||||
block_value: Uint256::ZERO,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ impl SszHeadTracker {
|
||||
mod test {
|
||||
use super::*;
|
||||
use ssz::{Decode, Encode};
|
||||
use types::{BeaconBlock, EthSpec, MainnetEthSpec};
|
||||
use types::{BeaconBlock, EthSpec, FixedBytesExtended, MainnetEthSpec};
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use std::iter;
|
||||
use std::time::Duration;
|
||||
use store::metadata::DataColumnInfo;
|
||||
use store::{chunked_vector::BlockRoots, AnchorInfo, BlobInfo, ChunkWriter, KeyValueStore};
|
||||
use types::{Hash256, Slot};
|
||||
use types::{FixedBytesExtended, Hash256, Slot};
|
||||
|
||||
/// Use a longer timeout on the pubkey cache.
|
||||
///
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::observed_attesters::SlotSubcommitteeIndex;
|
||||
use crate::types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT;
|
||||
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
|
||||
use bls::FixedBytesExtended;
|
||||
pub use lighthouse_metrics::*;
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
@@ -14,8 +14,8 @@ use store::iter::RootsIterator;
|
||||
use store::{Error, ItemStore, StoreItem, StoreOp};
|
||||
pub use store::{HotColdDB, MemoryStore};
|
||||
use types::{
|
||||
BeaconState, BeaconStateError, BeaconStateHash, Checkpoint, Epoch, EthSpec, Hash256,
|
||||
SignedBeaconBlockHash, Slot,
|
||||
BeaconState, BeaconStateError, BeaconStateHash, Checkpoint, Epoch, EthSpec, FixedBytesExtended,
|
||||
Hash256, SignedBeaconBlockHash, Slot,
|
||||
};
|
||||
|
||||
/// Compact at least this frequently, finalization permitting (7 days).
|
||||
|
||||
@@ -48,7 +48,7 @@ impl TreeHash for AttestationKey {
|
||||
// Combine the hash of the data with the hash of the index
|
||||
let mut hasher = MerkleHasher::with_leaves(2);
|
||||
hasher
|
||||
.write(self.data_root.as_bytes())
|
||||
.write(self.data_root.as_slice())
|
||||
.expect("should write data hash");
|
||||
hasher
|
||||
.write(&index.to_le_bytes())
|
||||
@@ -582,7 +582,8 @@ mod tests {
|
||||
use tree_hash::TreeHash;
|
||||
use types::{
|
||||
test_utils::{generate_deterministic_keypair, test_random_instance},
|
||||
Attestation, AttestationBase, AttestationElectra, Fork, Hash256, SyncCommitteeMessage,
|
||||
Attestation, AttestationBase, AttestationElectra, FixedBytesExtended, Fork, Hash256,
|
||||
SyncCommitteeMessage,
|
||||
};
|
||||
|
||||
type E = types::MainnetEthSpec;
|
||||
|
||||
@@ -473,7 +473,7 @@ where
|
||||
#[cfg(not(debug_assertions))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use types::{test_utils::test_random_instance, AttestationBase, Hash256};
|
||||
use types::{test_utils::test_random_instance, AttestationBase, FixedBytesExtended, Hash256};
|
||||
|
||||
type E = types::MainnetEthSpec;
|
||||
|
||||
|
||||
@@ -619,6 +619,7 @@ impl SlotSubcommitteeIndex {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use types::FixedBytesExtended;
|
||||
|
||||
type E = types::MainnetEthSpec;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ impl OptimisticTransitionBlock {
|
||||
store
|
||||
.as_ref()
|
||||
.hot_db
|
||||
.key_delete(OTBColumn.into(), self.root.as_bytes())
|
||||
.key_delete(OTBColumn.into(), self.root.as_slice())
|
||||
}
|
||||
|
||||
fn is_canonical<T: BeaconChainTypes>(
|
||||
|
||||
@@ -62,7 +62,7 @@ pub fn downgrade_from_v21<T: BeaconChainTypes>(
|
||||
message: format!("{e:?}"),
|
||||
})?;
|
||||
|
||||
let db_key = get_key_for_col(DBColumn::PubkeyCache.into(), key.as_bytes());
|
||||
let db_key = get_key_for_col(DBColumn::PubkeyCache.into(), key.as_slice());
|
||||
ops.push(KeyValueStoreOp::PutKeyValue(
|
||||
db_key,
|
||||
pubkey_bytes.as_ssz_bytes(),
|
||||
|
||||
@@ -2627,6 +2627,7 @@ pub fn generate_rand_block_and_blobs<E: EthSpec>(
|
||||
let inner = map_fork_name!(fork_name, BeaconBlock, <_>::random_for_test(rng));
|
||||
|
||||
let mut block = SignedBeaconBlock::from_block(inner, types::Signature::random_for_test(rng));
|
||||
|
||||
let mut blob_sidecars = vec![];
|
||||
|
||||
let bundle = match block {
|
||||
|
||||
@@ -7,7 +7,7 @@ use ssz_derive::{Decode, Encode};
|
||||
use std::collections::HashMap;
|
||||
use std::marker::PhantomData;
|
||||
use store::{DBColumn, Error as StoreError, StoreItem, StoreOp};
|
||||
use types::{BeaconState, Hash256, PublicKey, PublicKeyBytes};
|
||||
use types::{BeaconState, FixedBytesExtended, Hash256, PublicKey, PublicKeyBytes};
|
||||
|
||||
/// Provides a mapping of `validator_index -> validator_publickey`.
|
||||
///
|
||||
|
||||
@@ -24,8 +24,8 @@ use types::{
|
||||
signed_aggregate_and_proof::SignedAggregateAndProofRefMut,
|
||||
test_utils::generate_deterministic_keypair, Address, AggregateSignature, Attestation,
|
||||
AttestationRef, AttestationRefMut, BeaconStateError, BitList, ChainSpec, Epoch, EthSpec,
|
||||
ForkName, Hash256, Keypair, MainnetEthSpec, SecretKey, SelectionProof, SignedAggregateAndProof,
|
||||
Slot, SubnetId, Unsigned,
|
||||
FixedBytesExtended, ForkName, Hash256, Keypair, MainnetEthSpec, SecretKey, SelectionProof,
|
||||
SignedAggregateAndProof, Slot, SubnetId, Unsigned,
|
||||
};
|
||||
|
||||
pub type E = MainnetEthSpec;
|
||||
|
||||
@@ -1280,7 +1280,7 @@ struct OptimisticTransitionSetup {
|
||||
impl OptimisticTransitionSetup {
|
||||
async fn new(num_blocks: usize, ttd: u64) -> Self {
|
||||
let mut spec = E::default_spec();
|
||||
spec.terminal_total_difficulty = ttd.into();
|
||||
spec.terminal_total_difficulty = Uint256::from(ttd);
|
||||
let mut rig = InvalidPayloadRig::new_with_spec(spec).enable_attestations();
|
||||
rig.move_to_terminal_block();
|
||||
|
||||
@@ -1323,7 +1323,7 @@ async fn build_optimistic_chain(
|
||||
// Build a brand-new testing harness. We will apply the blocks from the previous harness to
|
||||
// this one.
|
||||
let mut spec = E::default_spec();
|
||||
spec.terminal_total_difficulty = rig_ttd.into();
|
||||
spec.terminal_total_difficulty = Uint256::from(rig_ttd);
|
||||
let rig = InvalidPayloadRig::new_with_spec(spec);
|
||||
|
||||
let spec = &rig.harness.chain.spec;
|
||||
|
||||
@@ -1093,7 +1093,7 @@ async fn delete_blocks_and_states() {
|
||||
|
||||
assert_eq!(
|
||||
harness.head_block_root(),
|
||||
honest_head.into(),
|
||||
Hash256::from(honest_head),
|
||||
"the honest chain should be the canonical chain",
|
||||
);
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ use store::{SignedContributionAndProof, SyncCommitteeMessage};
|
||||
use tree_hash::TreeHash;
|
||||
use types::consts::altair::SYNC_COMMITTEE_SUBNET_COUNT;
|
||||
use types::{
|
||||
AggregateSignature, Epoch, EthSpec, Hash256, Keypair, MainnetEthSpec, SecretKey, Slot,
|
||||
SyncContributionData, SyncSelectionProof, SyncSubnetId, Unsigned,
|
||||
AggregateSignature, Epoch, EthSpec, FixedBytesExtended, Hash256, Keypair, MainnetEthSpec,
|
||||
SecretKey, Slot, SyncContributionData, SyncSelectionProof, SyncSubnetId, Unsigned,
|
||||
};
|
||||
|
||||
pub type E = MainnetEthSpec;
|
||||
|
||||
Reference in New Issue
Block a user