Skip to content

Commit e45dac1

Browse files
authored
Merge of #7497
2 parents f06d1d0 + 9b0ee53 commit e45dac1

File tree

7 files changed

+83
-128
lines changed

7 files changed

+83
-128
lines changed

Cargo.lock

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

testing/web3signer_tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ edition = { workspace = true }
1010
account_utils = { workspace = true }
1111
async-channel = { workspace = true }
1212
environment = { workspace = true }
13+
eth2 = { workspace = true }
1314
eth2_keystore = { workspace = true }
1415
eth2_network_config = { workspace = true }
1516
futures = { workspace = true }

testing/web3signer_tests/src/lib.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mod tests {
2020
use account_utils::validator_definitions::{
2121
SigningDefinition, ValidatorDefinition, ValidatorDefinitions, Web3SignerDefinition,
2222
};
23+
use eth2::types::FullBlockContents;
2324
use eth2_keystore::KeystoreBuilder;
2425
use eth2_network_config::Eth2NetworkConfig;
2526
use initialized_validators::{
@@ -45,7 +46,9 @@ mod tests {
4546
use tokio::time::sleep;
4647
use types::{attestation::AttestationBase, *};
4748
use url::Url;
48-
use validator_store::{Error as ValidatorStoreError, SignedBlock, ValidatorStore};
49+
use validator_store::{
50+
Error as ValidatorStoreError, SignedBlock, UnsignedBlock, ValidatorStore,
51+
};
4952

5053
/// If the we are unable to reach the Web3Signer HTTP API within this time out then we will
5154
/// assume it failed to start.
@@ -595,8 +598,9 @@ mod tests {
595598
async move {
596599
let block = BeaconBlock::<E>::Base(BeaconBlockBase::empty(&spec));
597600
let block_slot = block.slot();
601+
let unsigned_block = UnsignedBlock::Full(FullBlockContents::Block(block));
598602
validator_store
599-
.sign_block(pubkey, block.into(), block_slot)
603+
.sign_block(pubkey, unsigned_block, block_slot)
600604
.await
601605
.unwrap()
602606
}
@@ -665,12 +669,10 @@ mod tests {
665669
async move {
666670
let mut altair_block = BeaconBlockAltair::empty(&spec);
667671
altair_block.slot = altair_fork_slot;
672+
let unsigned_block =
673+
UnsignedBlock::Full(FullBlockContents::Block(altair_block.into()));
668674
validator_store
669-
.sign_block(
670-
pubkey,
671-
BeaconBlock::<E>::Altair(altair_block).into(),
672-
altair_fork_slot,
673-
)
675+
.sign_block(pubkey, unsigned_block, altair_fork_slot)
674676
.await
675677
.unwrap()
676678
}
@@ -752,12 +754,10 @@ mod tests {
752754
async move {
753755
let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec);
754756
bellatrix_block.slot = bellatrix_fork_slot;
757+
let unsigned_block =
758+
UnsignedBlock::Full(FullBlockContents::Block(bellatrix_block.into()));
755759
validator_store
756-
.sign_block(
757-
pubkey,
758-
BeaconBlock::<E>::Bellatrix(bellatrix_block).into(),
759-
bellatrix_fork_slot,
760-
)
760+
.sign_block(pubkey, unsigned_block, bellatrix_fork_slot)
761761
.await
762762
.unwrap()
763763
}
@@ -876,8 +876,9 @@ mod tests {
876876
.assert_signatures_match("first_block", |pubkey, validator_store| async move {
877877
let block = first_block();
878878
let slot = block.slot();
879+
let unsigned_block = UnsignedBlock::Full(FullBlockContents::Block(block));
879880
validator_store
880-
.sign_block(pubkey, block.into(), slot)
881+
.sign_block(pubkey, unsigned_block, slot)
881882
.await
882883
.unwrap()
883884
})
@@ -887,8 +888,9 @@ mod tests {
887888
move |pubkey, validator_store| async move {
888889
let block = double_vote_block();
889890
let slot = block.slot();
891+
let unsigned_block = UnsignedBlock::Full(FullBlockContents::Block(block));
890892
validator_store
891-
.sign_block(pubkey, block.into(), slot)
893+
.sign_block(pubkey, unsigned_block, slot)
892894
.await
893895
.map(|_| ())
894896
},

validator_client/lighthouse_validator_store/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use account_utils::validator_definitions::{PasswordStorage, ValidatorDefinition};
22
use doppelganger_service::DoppelgangerService;
3+
use eth2::types::PublishBlockRequest;
34
use initialized_validators::InitializedValidators;
45
use logging::crit;
56
use parking_lot::{Mutex, RwLock};
@@ -733,14 +734,18 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore for LighthouseValidatorS
733734
current_slot: Slot,
734735
) -> Result<SignedBlock<E>, Error> {
735736
match block {
736-
UnsignedBlock::Full(block) => self
737-
.sign_abstract_block(validator_pubkey, block, current_slot)
738-
.await
739-
.map(SignedBlock::Full),
737+
UnsignedBlock::Full(block) => {
738+
let (block, blobs) = block.deconstruct();
739+
self.sign_abstract_block(validator_pubkey, block, current_slot)
740+
.await
741+
.map(|block| {
742+
SignedBlock::Full(PublishBlockRequest::new(Arc::new(block), blobs))
743+
})
744+
}
740745
UnsignedBlock::Blinded(block) => self
741746
.sign_abstract_block(validator_pubkey, block, current_slot)
742747
.await
743-
.map(SignedBlock::Blinded),
748+
.map(|block| SignedBlock::Blinded(Arc::new(block))),
744749
}
745750
}
746751

validator_client/validator_services/src/block_service.rs

Lines changed: 43 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use beacon_node_fallback::{ApiTopic, BeaconNodeFallback, Error as FallbackError, Errors};
22
use bls::SignatureBytes;
3-
use eth2::types::{FullBlockContents, PublishBlockRequest};
43
use eth2::{BeaconNodeHttpClient, StatusCode};
54
use graffiti_file::{determine_graffiti, GraffitiFile};
65
use logging::crit;
@@ -13,11 +12,8 @@ use std::time::Duration;
1312
use task_executor::TaskExecutor;
1413
use tokio::sync::mpsc;
1514
use tracing::{debug, error, info, trace, warn};
16-
use types::{
17-
BlindedBeaconBlock, BlockType, ChainSpec, EthSpec, Graffiti, PublicKeyBytes,
18-
SignedBlindedBeaconBlock, Slot,
19-
};
20-
use validator_store::{Error as ValidatorStoreError, ValidatorStore};
15+
use types::{BlockType, ChainSpec, EthSpec, Graffiti, PublicKeyBytes, Slot};
16+
use validator_store::{Error as ValidatorStoreError, SignedBlock, UnsignedBlock, ValidatorStore};
2117

2218
#[derive(Debug)]
2319
pub enum BlockError {
@@ -335,26 +331,10 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
335331
) -> Result<(), BlockError> {
336332
let signing_timer = validator_metrics::start_timer(&validator_metrics::BLOCK_SIGNING_TIMES);
337333

338-
let (block, maybe_blobs) = match unsigned_block {
339-
UnsignedBlock::Full(block_contents) => {
340-
let (block, maybe_blobs) = block_contents.deconstruct();
341-
(block.into(), maybe_blobs)
342-
}
343-
UnsignedBlock::Blinded(block) => (block.into(), None),
344-
};
345-
346334
let res = self
347335
.validator_store
348-
.sign_block(*validator_pubkey, block, slot)
349-
.await
350-
.map(|block| match block {
351-
validator_store::SignedBlock::Full(block) => {
352-
SignedBlock::Full(PublishBlockRequest::new(Arc::new(block), maybe_blobs))
353-
}
354-
validator_store::SignedBlock::Blinded(block) => {
355-
SignedBlock::Blinded(Arc::new(block))
356-
}
357-
});
336+
.sign_block(*validator_pubkey, unsigned_block, slot)
337+
.await;
358338

359339
let signed_block = match res {
360340
Ok(block) => block,
@@ -398,12 +378,13 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
398378
})
399379
.await?;
400380

381+
let metadata = BlockMetadata::from(&signed_block);
401382
info!(
402-
block_type = ?signed_block.block_type(),
403-
deposits = signed_block.num_deposits(),
404-
attestations = signed_block.num_attestations(),
383+
block_type = ?metadata.block_type,
384+
deposits = metadata.num_deposits,
385+
attestations = metadata.num_attestations,
405386
graffiti = ?graffiti.map(|g| g.as_utf8_lossy()),
406-
slot = signed_block.slot().as_u64(),
387+
slot = metadata.slot.as_u64(),
407388
"Successfully published block"
408389
);
409390
Ok(())
@@ -508,7 +489,6 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
508489
signed_block: &SignedBlock<S::E>,
509490
beacon_node: BeaconNodeHttpClient,
510491
) -> Result<(), BlockError> {
511-
let slot = signed_block.slot();
512492
match signed_block {
513493
SignedBlock::Full(signed_block) => {
514494
let _post_timer = validator_metrics::start_timer_vec(
@@ -518,7 +498,9 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
518498
beacon_node
519499
.post_beacon_blocks_v2_ssz(signed_block, None)
520500
.await
521-
.or_else(|e| handle_block_post_error(e, slot))?
501+
.or_else(|e| {
502+
handle_block_post_error(e, signed_block.signed_block().message().slot())
503+
})?
522504
}
523505
SignedBlock::Blinded(signed_block) => {
524506
let _post_timer = validator_metrics::start_timer_vec(
@@ -528,7 +510,7 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
528510
beacon_node
529511
.post_beacon_blinded_blocks_v2_ssz(signed_block, None)
530512
.await
531-
.or_else(|e| handle_block_post_error(e, slot))?
513+
.or_else(|e| handle_block_post_error(e, signed_block.message().slot()))?
532514
}
533515
}
534516
Ok::<_, BlockError>(())
@@ -557,13 +539,17 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
557539
))
558540
})?;
559541

560-
let unsigned_block = match block_response.data {
561-
eth2::types::ProduceBlockV3Response::Full(block) => UnsignedBlock::Full(block),
562-
eth2::types::ProduceBlockV3Response::Blinded(block) => UnsignedBlock::Blinded(block),
542+
let (block_proposer, unsigned_block) = match block_response.data {
543+
eth2::types::ProduceBlockV3Response::Full(block) => {
544+
(block.block().proposer_index(), UnsignedBlock::Full(block))
545+
}
546+
eth2::types::ProduceBlockV3Response::Blinded(block) => {
547+
(block.proposer_index(), UnsignedBlock::Blinded(block))
548+
}
563549
};
564550

565551
info!(slot = slot.as_u64(), "Received unsigned block");
566-
if proposer_index != Some(unsigned_block.proposer_index()) {
552+
if proposer_index != Some(block_proposer) {
567553
return Err(BlockError::Recoverable(
568554
"Proposer index does not match block proposer. Beacon chain re-orged".to_string(),
569555
));
@@ -573,49 +559,30 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
573559
}
574560
}
575561

576-
pub enum UnsignedBlock<E: EthSpec> {
577-
Full(FullBlockContents<E>),
578-
Blinded(BlindedBeaconBlock<E>),
579-
}
580-
581-
impl<E: EthSpec> UnsignedBlock<E> {
582-
pub fn proposer_index(&self) -> u64 {
583-
match self {
584-
UnsignedBlock::Full(block) => block.block().proposer_index(),
585-
UnsignedBlock::Blinded(block) => block.proposer_index(),
586-
}
587-
}
562+
/// Wrapper for values we want to log about a block we signed, for easy extraction from the possible
563+
/// variants.
564+
struct BlockMetadata {
565+
block_type: BlockType,
566+
slot: Slot,
567+
num_deposits: usize,
568+
num_attestations: usize,
588569
}
589570

590-
#[derive(Debug)]
591-
pub enum SignedBlock<E: EthSpec> {
592-
Full(PublishBlockRequest<E>),
593-
Blinded(Arc<SignedBlindedBeaconBlock<E>>),
594-
}
595-
596-
impl<E: EthSpec> SignedBlock<E> {
597-
pub fn block_type(&self) -> BlockType {
598-
match self {
599-
SignedBlock::Full(_) => BlockType::Full,
600-
SignedBlock::Blinded(_) => BlockType::Blinded,
601-
}
602-
}
603-
pub fn slot(&self) -> Slot {
604-
match self {
605-
SignedBlock::Full(block) => block.signed_block().message().slot(),
606-
SignedBlock::Blinded(block) => block.message().slot(),
607-
}
608-
}
609-
pub fn num_deposits(&self) -> usize {
610-
match self {
611-
SignedBlock::Full(block) => block.signed_block().message().body().deposits().len(),
612-
SignedBlock::Blinded(block) => block.message().body().deposits().len(),
613-
}
614-
}
615-
pub fn num_attestations(&self) -> usize {
616-
match self {
617-
SignedBlock::Full(block) => block.signed_block().message().body().attestations_len(),
618-
SignedBlock::Blinded(block) => block.message().body().attestations_len(),
571+
impl<E: EthSpec> From<&SignedBlock<E>> for BlockMetadata {
572+
fn from(value: &SignedBlock<E>) -> Self {
573+
match value {
574+
SignedBlock::Full(block) => BlockMetadata {
575+
block_type: BlockType::Full,
576+
slot: block.signed_block().message().slot(),
577+
num_deposits: block.signed_block().message().body().deposits().len(),
578+
num_attestations: block.signed_block().message().body().attestations_len(),
579+
},
580+
SignedBlock::Blinded(block) => BlockMetadata {
581+
block_type: BlockType::Blinded,
582+
slot: block.message().slot(),
583+
num_deposits: block.message().body().deposits().len(),
584+
num_attestations: block.message().body().attestations_len(),
585+
},
619586
}
620587
}
621588
}

validator_client/validator_store/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ edition = { workspace = true }
55
authors = ["Sigma Prime <[email protected]>"]
66

77
[dependencies]
8+
eth2 = { workspace = true }
89
slashing_protection = { workspace = true }
910
types = { workspace = true }

validator_client/validator_store/src/lib.rs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use eth2::types::{FullBlockContents, PublishBlockRequest};
12
use slashing_protection::NotSafe;
23
use std::fmt::Debug;
34
use std::future::Future;
5+
use std::sync::Arc;
46
use types::{
5-
Address, Attestation, AttestationError, BeaconBlock, BlindedBeaconBlock, Epoch, EthSpec,
6-
Graffiti, Hash256, PublicKeyBytes, SelectionProof, Signature, SignedAggregateAndProof,
7-
SignedBeaconBlock, SignedBlindedBeaconBlock, SignedContributionAndProof,
8-
SignedValidatorRegistrationData, Slot, SyncCommitteeContribution, SyncCommitteeMessage,
9-
SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData,
7+
Address, Attestation, AttestationError, BlindedBeaconBlock, Epoch, EthSpec, Graffiti, Hash256,
8+
PublicKeyBytes, SelectionProof, Signature, SignedAggregateAndProof, SignedBlindedBeaconBlock,
9+
SignedContributionAndProof, SignedValidatorRegistrationData, Slot, SyncCommitteeContribution,
10+
SyncCommitteeMessage, SyncSelectionProof, SyncSubnetId, ValidatorRegistrationData,
1011
};
1112

1213
#[derive(Debug, PartialEq, Clone)]
@@ -170,40 +171,16 @@ pub trait ValidatorStore: Send + Sync {
170171
fn proposal_data(&self, pubkey: &PublicKeyBytes) -> Option<ProposalData>;
171172
}
172173

173-
#[derive(Clone, Debug, PartialEq)]
174+
#[derive(Debug)]
174175
pub enum UnsignedBlock<E: EthSpec> {
175-
Full(BeaconBlock<E>),
176+
Full(FullBlockContents<E>),
176177
Blinded(BlindedBeaconBlock<E>),
177178
}
178179

179-
impl<E: EthSpec> From<BeaconBlock<E>> for UnsignedBlock<E> {
180-
fn from(block: BeaconBlock<E>) -> Self {
181-
UnsignedBlock::Full(block)
182-
}
183-
}
184-
185-
impl<E: EthSpec> From<BlindedBeaconBlock<E>> for UnsignedBlock<E> {
186-
fn from(block: BlindedBeaconBlock<E>) -> Self {
187-
UnsignedBlock::Blinded(block)
188-
}
189-
}
190-
191180
#[derive(Clone, Debug, PartialEq)]
192181
pub enum SignedBlock<E: EthSpec> {
193-
Full(SignedBeaconBlock<E>),
194-
Blinded(SignedBlindedBeaconBlock<E>),
195-
}
196-
197-
impl<E: EthSpec> From<SignedBeaconBlock<E>> for SignedBlock<E> {
198-
fn from(block: SignedBeaconBlock<E>) -> Self {
199-
SignedBlock::Full(block)
200-
}
201-
}
202-
203-
impl<E: EthSpec> From<SignedBlindedBeaconBlock<E>> for SignedBlock<E> {
204-
fn from(block: SignedBlindedBeaconBlock<E>) -> Self {
205-
SignedBlock::Blinded(block)
206-
}
182+
Full(PublishBlockRequest<E>),
183+
Blinded(Arc<SignedBlindedBeaconBlock<E>>),
207184
}
208185

209186
/// A wrapper around `PublicKeyBytes` which encodes information about the status of a validator

0 commit comments

Comments
 (0)