Skip to content

Commit

Permalink
debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
eserilev committed Sep 4, 2023
1 parent 133c289 commit 272cb76
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 35 deletions.
28 changes: 24 additions & 4 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4353,7 +4353,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
move || {
chain.complete_partial_beacon_block_v3(
partial_beacon_block,
block_contents,
Some(block_contents),
verification,
)
},
Expand All @@ -4373,7 +4373,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
move || {
chain.complete_partial_beacon_block_v3(
partial_beacon_block,
block_contents,
Some(block_contents),
verification,
)
},
Expand All @@ -4387,7 +4387,24 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
}
} else {
Err(BlockProductionError::FailedToFetchBlock)
let chain = self.clone();
let beacon_block_and_state = self
.task_executor
.spawn_blocking_handle(
move || {
chain.complete_partial_beacon_block_v3(
partial_beacon_block,
None,
verification,
)
},
"complete_partial_beacon_block",
)
.ok_or(BlockProductionError::ShuttingDown)?
.await
.map_err(BlockProductionError::TokioJoin)??;

Ok(BeaconBlockAndStateResponse::Full(beacon_block_and_state))
}
}

Expand Down Expand Up @@ -4547,6 +4564,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
self.op_pool.get_slashings_and_exits(&state, &self.spec);

let eth1_data = eth1_chain.eth1_data_for_block_production(&state, &self.spec)?;

let deposits = eth1_chain.deposits_for_block_inclusion(&state, &eth1_data, &self.spec)?;

let bls_to_execution_changes = self
Expand Down Expand Up @@ -4957,7 +4975,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
fn complete_partial_beacon_block_v3<Payload: AbstractExecPayload<T::EthSpec>>(
&self,
partial_beacon_block: PartialBeaconBlockV3<T::EthSpec>,
block_contents: BlockProposalContents<T::EthSpec, Payload>,
block_contents: Option<BlockProposalContents<T::EthSpec, Payload>>,
verification: ProduceBlockVerification,
) -> Result<BeaconBlockAndState<T::EthSpec, Payload>, BlockProductionError> {
let PartialBeaconBlockV3 {
Expand Down Expand Up @@ -5035,6 +5053,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
sync_aggregate: sync_aggregate
.ok_or(BlockProductionError::MissingSyncAggregate)?,
execution_payload: block_contents
.ok_or(BlockProductionError::MissingExecutionPayload)?
.to_payload()
.try_into()
.map_err(|_| BlockProductionError::InvalidPayloadFork)?,
Expand All @@ -5057,6 +5076,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
sync_aggregate: sync_aggregate
.ok_or(BlockProductionError::MissingSyncAggregate)?,
execution_payload: block_contents
.ok_or(BlockProductionError::MissingExecutionPayload)?
.to_payload()
.try_into()
.map_err(|_| BlockProductionError::InvalidPayloadFork)?,
Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/execution_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ where
// Note: the suggested_fee_recipient is stored in the `execution_layer`, it will add this parameter.
//
// This future is not executed here, it's up to the caller to await it.
println!("ATTEMPT TO FETCH PAYLOAD");
let block_contents = execution_layer
.get_payload::<Payload>(
parent_hash,
Expand Down
2 changes: 2 additions & 0 deletions beacon_node/builder_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ impl BuilderHttpClient {
) -> Result<(), Error> {
let mut path = self.server.full.clone();

println!("post_builder_validators");

path.path_segments_mut()
.map_err(|()| Error::InvalidUrl(self.server.clone()))?
.push("eth")
Expand Down
3 changes: 3 additions & 0 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
) -> Result<BlockProposalContents<T, Payload>, Error> {
let payload_result = match Payload::block_type() {
BlockType::Blinded => {
println!("BLOCK TYPE IS BLINDED");
let _timer = metrics::start_timer_vec(
&metrics::EXECUTION_LAYER_REQUEST_TIMES,
&[metrics::GET_BLINDED_PAYLOAD],
Expand All @@ -753,6 +754,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
.await
}
BlockType::Full => {
println!("BLOCK TYPE IS FULL");
let _timer = metrics::start_timer_vec(
&metrics::EXECUTION_LAYER_REQUEST_TIMES,
&[metrics::GET_PAYLOAD],
Expand Down Expand Up @@ -1092,6 +1094,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
current_fork: ForkName,
spec: &ChainSpec,
) -> Result<ProvenancedPayload<BlockProposalContents<T, Payload>>, Error> {
println!("BLINDED");
if let Some(builder) = self.builder() {
let slot = builder_params.slot;
let pubkey = builder_params.pubkey;
Expand Down
14 changes: 13 additions & 1 deletion beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,8 @@ pub fn serve<T: BeaconChainTypes>(
chain: Arc<BeaconChain<T>>,
log: Logger,
register_val_data: Vec<SignedValidatorRegistrationData>| async {

println!("post_validator_register_validator");
let (tx, rx) = oneshot::channel();

let initial_result = task_spawner
Expand All @@ -3532,12 +3534,16 @@ pub fn serve<T: BeaconChainTypes>(
.map_err(warp_utils::reject::beacon_chain_error)?;
let current_epoch = current_slot.epoch(T::EthSpec::slots_per_epoch());

println!("post_validator_register_validator 1");

debug!(
log,
"Received register validator request";
"count" => register_val_data.len(),
);

println!("post_validator_register_validator 2");

let head_snapshot = chain.head_snapshot();
let spec = &chain.spec;

Expand Down Expand Up @@ -3609,6 +3615,8 @@ pub fn serve<T: BeaconChainTypes>(
"count" => filtered_registration_data.len(),
);

println!("yo 1");

// It's a waste of a `BeaconProcessor` worker to just
// wait on a response from the builder (especially since
// they have frequent timeouts). Spawn a new task and
Expand All @@ -3624,7 +3632,7 @@ pub fn serve<T: BeaconChainTypes>(
.as_ref()
.ok_or(BeaconChainError::BuilderMissing)
.map_err(warp_utils::reject::beacon_chain_error)?;

println!("yo 2");
builder
.post_builder_validators(&filtered_registration_data)
.await
Expand All @@ -3639,6 +3647,7 @@ pub fn serve<T: BeaconChainTypes>(
// Forward the HTTP status code if we are able to, otherwise fall back
// to a server error.
if let eth2::Error::ServerMessage(message) = e {
println!("SERVER MESSAGE 1");
if message.code == StatusCode::BAD_REQUEST.as_u16() {
return warp_utils::reject::custom_bad_request(
message.message,
Expand All @@ -3651,6 +3660,7 @@ pub fn serve<T: BeaconChainTypes>(
);
}
}
println!("SERVER MESSAGE 2");
warp_utils::reject::custom_server_error(format!("{e:?}"))
})
};
Expand All @@ -3663,6 +3673,8 @@ pub fn serve<T: BeaconChainTypes>(
})
.await;

println!("{:?}", initial_result);

if initial_result.is_err() {
return task_spawner::convert_rejection(initial_result).await;
}
Expand Down
96 changes: 73 additions & 23 deletions beacon_node/http_api/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use beacon_chain::{
BeaconBlockAndStateResponse, BeaconChain, BeaconChainError, BeaconChainTypes,
ProduceBlockVerification,
};
use eth2::types::{self as api_types, EndpointVersion, SkipRandaoVerification};
use eth2::types::{
self as api_types, EndpointVersion, SkipRandaoVerification, ValidatorBlocksQuery,
};
use ssz::Encode;
use warp::{
hyper::{Body, Response},
Expand Down Expand Up @@ -54,6 +56,51 @@ pub fn get_randao_verification(
Ok(randao_verification)
}

pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
endpoint_version: EndpointVersion,
chain: Arc<BeaconChain<T>>,
slot: Slot,
query: api_types::ValidatorBlocksQuery,
) -> Result<Response<Body>, warp::Rejection> {
let randao_reveal = query.randao_reveal.decompress().map_err(|e| {
warp_utils::reject::custom_bad_request(format!(
"randao reveal is not a valid BLS signature: {:?}",
e
))
})?;

let randao_verification = get_randao_verification(&query, randao_reveal.is_infinity())?;
let block_response = chain
.determine_and_produce_block_with_verification(
randao_reveal,
slot,
query.graffiti.map(Into::into),
randao_verification,
BlockProductionVersion::FullV2,
)
.await
.map_err(warp_utils::reject::block_production_error)?;

match block_response {
BeaconBlockAndStateResponse::Full((_, _)) => {
println!("We shouldnt ever make it in here");
Err(warp_utils::reject::custom_server_error(
"Returned a blinded block. It should be impossible to return a blinded block via the Full Payload V2 block fetching flow.".to_string()
))
}
BeaconBlockAndStateResponse::Blinded((block, _)) => {
let fork_name = block
.to_ref()
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;

fork_versioned_response(endpoint_version, fork_name, block)
.map(|response| warp::reply::json(&response).into_response())
.map(|res| add_consensus_version_header(res, fork_name))
}
}
}

pub async fn produce_block_v2<T: BeaconChainTypes>(
endpoint_version: EndpointVersion,
chain: Arc<BeaconChain<T>>,
Expand Down Expand Up @@ -92,6 +139,7 @@ pub async fn produce_block_v2<T: BeaconChainTypes>(
.map(|res| add_consensus_version_header(res, fork_name))
}
BeaconBlockAndStateResponse::Blinded((_, _)) => {
println!("We shouldnt ever make it in here");
Err(warp_utils::reject::custom_server_error(
"Returned a blinded block. It should be impossible to return a blinded block via the Full Payload V2 block fetching flow.".to_string()
))
Expand Down Expand Up @@ -148,30 +196,10 @@ pub async fn determine_and_produce_block_json<T: BeaconChainTypes>(

match block_response {
BeaconBlockAndStateResponse::Full((block, _)) => {
let fork_name = block
.to_ref()
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;

fork_versioned_response(endpoint_version, fork_name, block)
.map(|response| warp::reply::json(&response).into_response())
.map(|res| add_consensus_version_header(res, fork_name))
.map(|res| add_execution_payload_blinded_header(res, false))
.map(|res: Response<Body>| add_execution_payload_value_header(res, 0))
// TODO
generate_json_response_v3(chain, block, endpoint_version, false)
}
BeaconBlockAndStateResponse::Blinded((block, _)) => {
let fork_name = block
.to_ref()
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;

fork_versioned_response(endpoint_version, fork_name, block)
.map(|response| warp::reply::json(&response).into_response())
.map(|res| add_consensus_version_header(res, fork_name))
.map(|res| add_execution_payload_blinded_header(res, true))
.map(|res: Response<Body>| add_execution_payload_value_header(res, 0))
// TODO
generate_json_response_v3(chain, block, endpoint_version, true)
}
}
}
Expand Down Expand Up @@ -232,3 +260,25 @@ pub async fn determine_and_produce_block_ssz<T: BeaconChainTypes>(
warp_utils::reject::custom_server_error(format!("failed to create response: {}", e))
})
}

pub fn generate_json_response_v3<
T: BeaconChainTypes,
E: EthSpec,
Payload: AbstractExecPayload<E>,
>(
chain: Arc<BeaconChain<T>>,
block: BeaconBlock<E, Payload>,
endpoint_version: EndpointVersion,
blinded_payload_flag: bool,
) -> Result<Response<Body>, warp::Rejection> {
let fork_name = block
.to_ref()
.fork_name(&chain.spec)
.map_err(inconsistent_fork_rejection)?;

fork_versioned_response(endpoint_version, fork_name, block)
.map(|response| warp::reply::json(&response).into_response())
.map(|res| add_consensus_version_header(res, fork_name))
.map(|res| add_execution_payload_blinded_header(res, blinded_payload_flag))
.map(|res: Response<Body>| add_execution_payload_value_header(res, 0))
}
4 changes: 2 additions & 2 deletions beacon_node/http_api/tests/interactive_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ pub async fn proposer_boost_re_org_test(
.get_validator_blocks_v3::<E>(slot_c, &randao_reveal, None)
.await
.unwrap();

/*
let block_c = match unsigned_block_type {
Full(unsigned_block_c) => {
println!("full");
Expand Down Expand Up @@ -723,7 +723,7 @@ pub async fn proposer_boost_re_org_test(
payload_attribs.timestamp(),
payload_attribs.prev_randao(),
);
}
}*/
}

// Test that running fork choice before proposing results in selection of the correct head.
Expand Down
13 changes: 12 additions & 1 deletion beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3038,6 +3038,8 @@ impl ApiTester {
.await
.unwrap();

println!("MADE IT FAR");

for (val_index, (_, fee_recipient)) in self
.chain
.head_snapshot()
Expand Down Expand Up @@ -3413,13 +3415,17 @@ impl ApiTester {
.parse::<Hash256>()
.unwrap();

println!("test1");

// Mutate prev randao.
self.mock_builder
.as_ref()
.unwrap()
.builder
.add_operation(Operation::PrevRandao(invalid_prev_randao));

println!("test2");

let slot = self.chain.slot().unwrap();
let epoch = self.chain.epoch().unwrap();
let expected_prev_randao = self
Expand All @@ -3428,9 +3434,12 @@ impl ApiTester {
.cached_head()
.head_random()
.unwrap();

println!("test3");
let (_, randao_reveal) = self.get_test_randao(slot, epoch).await;


println!("test4");

let payload: BlindedPayload<E> = self
.client
.get_validator_blinded_blocks::<E, BlindedPayload<E>>(slot, &randao_reveal, None)
Expand All @@ -3442,6 +3451,8 @@ impl ApiTester {
.unwrap()
.into();

println!("{:?}", payload);

assert_eq!(payload.prev_randao(), expected_prev_randao);

// If this cache is populated, it indicates fallback to the local EE was correctly used.
Expand Down
Loading

0 comments on commit 272cb76

Please sign in to comment.