Skip to content

Commit 2c1f1c1

Browse files
jchavarrimacladson
andauthored
Migrate derivative to educe (#8125)
Fixes #7001. Mostly mechanical replacement of `derivative` attributes with `educe` ones. ### **Attribute Syntax Changes** ```rust // Bounds: = "..." → (...) #[derivative(Hash(bound = "E: EthSpec"))] #[educe(Hash(bound(E: EthSpec)))] // Ignore: = "ignore" → (ignore) #[derivative(PartialEq = "ignore")] #[educe(PartialEq(ignore))] // Default values: value = "..." → expression = ... #[derivative(Default(value = "ForkName::Base"))] #[educe(Default(expression = ForkName::Base))] // Methods: format_with/compare_with = "..." → method(...) #[derivative(Debug(format_with = "fmt_peer_set_as_len"))] #[educe(Debug(method(fmt_peer_set_as_len)))] // Empty bounds: removed entirely, educe can infer appropriate bounds #[derivative(Default(bound = ""))] #[educe(Default)] // Transparent debug: manual implementation (educe doesn't support it) #[derivative(Debug = "transparent")] // Replaced with manual Debug impl that delegates to inner field ``` **Note**: Some bounds use strings (`bound("E: EthSpec")`) for superstruct compatibility (`expected ','` errors). Co-Authored-By: Javier Chávarri <javier.chavarri@gmail.com> Co-Authored-By: Mac L <mjladson@pm.me>
1 parent 0090b35 commit 2c1f1c1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+277
-287
lines changed

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ context_deserialize_derive = { path = "consensus/context_deserialize/context_des
128128
criterion = "0.5"
129129
delay_map = "0.4"
130130
deposit_contract = { path = "common/deposit_contract" }
131-
derivative = "2"
132131
directory = { path = "common/directory" }
133132
dirs = "3"
134133
discv5 = { version = "0.10", features = ["libp2p"] }
135134
doppelganger_service = { path = "validator_client/doppelganger_service" }
135+
educe = "0.6"
136136
eip_3076 = { path = "common/eip_3076" }
137137
either = "1.9"
138138
environment = { path = "lighthouse/environment" }

beacon_node/beacon_chain/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ test_backfill = []
1818
alloy-primitives = { workspace = true }
1919
bitvec = { workspace = true }
2020
bls = { workspace = true }
21-
derivative = { workspace = true }
21+
educe = { workspace = true }
2222
eth2 = { workspace = true }
2323
eth2_network_config = { workspace = true }
2424
ethereum_hashing = { workspace = true }

beacon_node/beacon_chain/src/beacon_fork_choice_store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! reads when fork choice requires the validator balances of the justified state.
66
77
use crate::{BeaconSnapshot, metrics};
8-
use derivative::Derivative;
8+
use educe::Educe;
99
use fork_choice::ForkChoiceStore;
1010
use proto_array::JustifiedBalances;
1111
use safe_arith::ArithError;
@@ -127,10 +127,10 @@ impl BalancesCache {
127127

128128
/// Implements `fork_choice::ForkChoiceStore` in order to provide a persistent backing to the
129129
/// `fork_choice::ForkChoice` struct.
130-
#[derive(Debug, Derivative)]
131-
#[derivative(PartialEq(bound = "E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>"))]
130+
#[derive(Debug, Educe)]
131+
#[educe(PartialEq(bound(E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>)))]
132132
pub struct BeaconForkChoiceStore<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> {
133-
#[derivative(PartialEq = "ignore")]
133+
#[educe(PartialEq(ignore))]
134134
store: Arc<HotColdDB<E, Hot, Cold>>,
135135
balances_cache: BalancesCache,
136136
time: Slot,

beacon_node/beacon_chain/src/blob_verification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use derivative::Derivative;
1+
use educe::Educe;
22
use slot_clock::SlotClock;
33
use std::marker::PhantomData;
44
use std::sync::Arc;
@@ -245,8 +245,8 @@ impl<T: BeaconChainTypes, O: ObservationStrategy> GossipVerifiedBlob<T, O> {
245245

246246
/// Wrapper over a `BlobSidecar` for which we have completed kzg verification.
247247
/// i.e. `verify_blob_kzg_proof(blob, commitment, proof) == true`.
248-
#[derive(Debug, Derivative, Clone, Encode, Decode)]
249-
#[derivative(PartialEq, Eq)]
248+
#[derive(Debug, Educe, Clone, Encode, Decode)]
249+
#[educe(PartialEq, Eq)]
250250
#[ssz(struct_behaviour = "transparent")]
251251
pub struct KzgVerifiedBlob<E: EthSpec> {
252252
blob: Arc<BlobSidecar<E>>,

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use crate::{
6666
beacon_chain::{BeaconForkChoice, ForkChoiceError},
6767
metrics,
6868
};
69-
use derivative::Derivative;
69+
use educe::Educe;
7070
use eth2::types::{BlockGossip, EventKind};
7171
use execution_layer::PayloadStatus;
7272
pub use fork_choice::{AttestationFromBlock, PayloadVerificationStatus};
@@ -689,8 +689,8 @@ pub fn signature_verify_chain_segment<T: BeaconChainTypes>(
689689

690690
/// A wrapper around a `SignedBeaconBlock` that indicates it has been approved for re-gossiping on
691691
/// the p2p network.
692-
#[derive(Derivative)]
693-
#[derivative(Debug(bound = "T: BeaconChainTypes"))]
692+
#[derive(Educe)]
693+
#[educe(Debug(bound(T: BeaconChainTypes)))]
694694
pub struct GossipVerifiedBlock<T: BeaconChainTypes> {
695695
pub block: Arc<SignedBeaconBlock<T::EthSpec>>,
696696
pub block_root: Hash256,

beacon_node/beacon_chain/src/block_verification_types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::data_availability_checker::AvailabilityCheckError;
22
pub use crate::data_availability_checker::{AvailableBlock, MaybeAvailableBlock};
33
use crate::data_column_verification::{CustodyDataColumn, CustodyDataColumnList};
44
use crate::{PayloadVerificationOutcome, get_block_root};
5-
use derivative::Derivative;
5+
use educe::Educe;
66
use ssz_types::VariableList;
77
use state_processing::ConsensusContext;
88
use std::fmt::{Debug, Formatter};
@@ -26,8 +26,8 @@ use types::{
2626
/// Note: We make a distinction over blocks received over gossip because
2727
/// in a post-deneb world, the blobs corresponding to a given block that are received
2828
/// over rpc do not contain the proposer signature for dos resistance.
29-
#[derive(Clone, Derivative)]
30-
#[derivative(Hash(bound = "E: EthSpec"))]
29+
#[derive(Clone, Educe)]
30+
#[educe(Hash(bound(E: EthSpec)))]
3131
pub struct RpcBlock<E: EthSpec> {
3232
block_root: Hash256,
3333
block: RpcBlockInner<E>,
@@ -80,8 +80,8 @@ impl<E: EthSpec> RpcBlock<E> {
8080
/// Note: This variant is intentionally private because we want to safely construct the
8181
/// internal variants after applying consistency checks to ensure that the block and blobs
8282
/// are consistent with respect to each other.
83-
#[derive(Debug, Clone, Derivative)]
84-
#[derivative(Hash(bound = "E: EthSpec"))]
83+
#[derive(Debug, Clone, Educe)]
84+
#[educe(Hash(bound(E: EthSpec)))]
8585
enum RpcBlockInner<E: EthSpec> {
8686
/// Single block lookup response. This should potentially hit the data availability cache.
8787
Block(Arc<SignedBeaconBlock<E>>),

beacon_node/beacon_chain/src/data_column_verification.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::block_verification::{
44
use crate::kzg_utils::{reconstruct_data_columns, validate_data_columns};
55
use crate::observed_data_sidecars::{ObservationStrategy, Observe};
66
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes, metrics};
7-
use derivative::Derivative;
7+
use educe::Educe;
88
use fork_choice::ProtoBlock;
99
use kzg::{Error as KzgError, Kzg};
1010
use proto_array::Block;
@@ -296,8 +296,8 @@ impl<T: BeaconChainTypes, O: ObservationStrategy> GossipVerifiedDataColumn<T, O>
296296
}
297297

298298
/// Wrapper over a `DataColumnSidecar` for which we have completed kzg verification.
299-
#[derive(Debug, Derivative, Clone, Encode, Decode)]
300-
#[derivative(PartialEq, Eq)]
299+
#[derive(Debug, Educe, Clone, Encode, Decode)]
300+
#[educe(PartialEq, Eq)]
301301
#[ssz(struct_behaviour = "transparent")]
302302
pub struct KzgVerifiedDataColumn<E: EthSpec> {
303303
data: Arc<DataColumnSidecar<E>>,
@@ -353,8 +353,8 @@ pub type CustodyDataColumnList<E> =
353353
VariableList<CustodyDataColumn<E>, <E as EthSpec>::NumberOfColumns>;
354354

355355
/// Data column that we must custody
356-
#[derive(Debug, Derivative, Clone, Encode, Decode)]
357-
#[derivative(PartialEq, Eq, Hash(bound = "E: EthSpec"))]
356+
#[derive(Debug, Educe, Clone, Encode, Decode)]
357+
#[educe(PartialEq, Eq, Hash(bound(E: EthSpec)))]
358358
#[ssz(struct_behaviour = "transparent")]
359359
pub struct CustodyDataColumn<E: EthSpec> {
360360
data: Arc<DataColumnSidecar<E>>,
@@ -383,8 +383,8 @@ impl<E: EthSpec> CustodyDataColumn<E> {
383383
}
384384

385385
/// Data column that we must custody and has completed kzg verification
386-
#[derive(Debug, Derivative, Clone, Encode, Decode)]
387-
#[derivative(PartialEq, Eq)]
386+
#[derive(Debug, Educe, Clone, Encode, Decode)]
387+
#[educe(PartialEq, Eq)]
388388
#[ssz(struct_behaviour = "transparent")]
389389
pub struct KzgVerifiedCustodyDataColumn<E: EthSpec> {
390390
data: Arc<DataColumnSidecar<E>>,

beacon_node/beacon_chain/src/light_client_finality_update_verification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{BeaconChain, BeaconChainTypes};
2-
use derivative::Derivative;
2+
use educe::Educe;
33
use slot_clock::SlotClock;
44
use std::time::Duration;
55
use strum::AsRefStr;
@@ -55,8 +55,8 @@ pub enum Error {
5555
}
5656

5757
/// Wraps a `LightClientFinalityUpdate` that has been verified for propagation on the gossip network.
58-
#[derive(Derivative)]
59-
#[derivative(Clone(bound = "T: BeaconChainTypes"))]
58+
#[derive(Educe)]
59+
#[educe(Clone(bound(T: BeaconChainTypes)))]
6060
pub struct VerifiedLightClientFinalityUpdate<T: BeaconChainTypes> {
6161
light_client_finality_update: LightClientFinalityUpdate<T::EthSpec>,
6262
seen_timestamp: Duration,

beacon_node/beacon_chain/src/light_client_optimistic_update_verification.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{BeaconChain, BeaconChainTypes};
2-
use derivative::Derivative;
2+
use educe::Educe;
33
use eth2::types::Hash256;
44
use slot_clock::SlotClock;
55
use std::time::Duration;
@@ -49,8 +49,8 @@ pub enum Error {
4949
}
5050

5151
/// Wraps a `LightClientOptimisticUpdate` that has been verified for propagation on the gossip network.
52-
#[derive(Derivative)]
53-
#[derivative(Clone(bound = "T: BeaconChainTypes"))]
52+
#[derive(Educe)]
53+
#[educe(Clone(bound(T: BeaconChainTypes)))]
5454
pub struct VerifiedLightClientOptimisticUpdate<T: BeaconChainTypes> {
5555
light_client_optimistic_update: LightClientOptimisticUpdate<T::EthSpec>,
5656
pub parent_root: Hash256,

0 commit comments

Comments
 (0)