Skip to content

Commit 553ea8b

Browse files
ethDreamerpaulhauner
authored andcommitted
Removed PowBlock struct that never got used (#2813)
1 parent 6dd3da7 commit 553ea8b

File tree

6 files changed

+35
-129
lines changed

6 files changed

+35
-129
lines changed

beacon_node/beacon_chain/src/eth1_chain.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ use std::time::{SystemTime, UNIX_EPOCH};
1515
use store::{DBColumn, Error as StoreError, StoreItem};
1616
use task_executor::TaskExecutor;
1717
use types::{
18-
BeaconState, BeaconStateError, ChainSpec, Deposit, Eth1Data, EthSpec, ExecutionPayload,
19-
Hash256, Slot, Unsigned, DEPOSIT_TREE_DEPTH,
18+
BeaconState, BeaconStateError, ChainSpec, Deposit, Eth1Data, EthSpec, Hash256, Slot, Unsigned,
19+
DEPOSIT_TREE_DEPTH,
2020
};
2121

2222
type BlockNumber = u64;
@@ -53,8 +53,6 @@ pub enum Error {
5353
UnknownPreviousEth1BlockHash,
5454
/// An arithmetic error occurred.
5555
ArithError(safe_arith::ArithError),
56-
/// Unable to execute payload
57-
UnableToExecutePayload(String),
5856
}
5957

6058
impl From<safe_arith::ArithError> for Error {
@@ -281,15 +279,6 @@ where
281279
)
282280
}
283281

284-
pub fn on_payload(&self, execution_payload: &ExecutionPayload<E>) -> Result<bool, Error> {
285-
if self.use_dummy_backend {
286-
let dummy_backend: DummyEth1ChainBackend<E> = DummyEth1ChainBackend::default();
287-
dummy_backend.on_payload(execution_payload)
288-
} else {
289-
self.backend.on_payload(execution_payload)
290-
}
291-
}
292-
293282
/// Instantiate `Eth1Chain` from a persisted `SszEth1`.
294283
///
295284
/// The `Eth1Chain` will have the same caches as the persisted `SszEth1`.
@@ -350,9 +339,6 @@ pub trait Eth1ChainBackend<T: EthSpec>: Sized + Send + Sync {
350339
/// an idea of how up-to-date the remote eth1 node is.
351340
fn head_block(&self) -> Option<Eth1Block>;
352341

353-
/// Verifies the execution payload
354-
fn on_payload(&self, execution_payload: &ExecutionPayload<T>) -> Result<bool, Error>;
355-
356342
/// Encode the `Eth1ChainBackend` instance to bytes.
357343
fn as_bytes(&self) -> Vec<u8>;
358344

@@ -407,10 +393,6 @@ impl<T: EthSpec> Eth1ChainBackend<T> for DummyEth1ChainBackend<T> {
407393
None
408394
}
409395

410-
fn on_payload(&self, _execution_payload: &ExecutionPayload<T>) -> Result<bool, Error> {
411-
Ok(true)
412-
}
413-
414396
/// Return empty Vec<u8> for dummy backend.
415397
fn as_bytes(&self) -> Vec<u8> {
416398
Vec::new()
@@ -579,15 +561,6 @@ impl<T: EthSpec> Eth1ChainBackend<T> for CachingEth1Backend<T> {
579561
self.core.head_block()
580562
}
581563

582-
fn on_payload(&self, execution_payload: &ExecutionPayload<T>) -> Result<bool, Error> {
583-
futures::executor::block_on(async move {
584-
self.core
585-
.on_payload(execution_payload.clone())
586-
.await
587-
.map_err(|e| Error::UnableToExecutePayload(format!("{:?}", e)))
588-
})
589-
}
590-
591564
/// Return encoded byte representation of the block and deposit caches.
592565
fn as_bytes(&self) -> Vec<u8> {
593566
self.core.as_bytes()

beacon_node/eth1/src/http.rs

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::fmt;
1919
use std::ops::Range;
2020
use std::str::FromStr;
2121
use std::time::Duration;
22-
use types::{Hash256, PowBlock, Uint256};
22+
use types::Hash256;
2323

2424
/// `keccak("DepositEvent(bytes,bytes,bytes,bytes,bytes)")`
2525
pub const DEPOSIT_EVENT_TOPIC: &str =
@@ -49,7 +49,6 @@ pub enum Eth1Id {
4949
#[derive(Clone, Copy)]
5050
pub enum BlockQuery {
5151
Number(u64),
52-
Hash(Hash256),
5352
Latest,
5453
}
5554

@@ -136,6 +135,13 @@ pub async fn get_chain_id(endpoint: &SensitiveUrl, timeout: Duration) -> Result<
136135
}
137136
}
138137

138+
#[derive(Debug, PartialEq, Clone)]
139+
pub struct Block {
140+
pub hash: Hash256,
141+
pub timestamp: u64,
142+
pub number: u64,
143+
}
144+
139145
/// Returns the current block number.
140146
///
141147
/// Uses HTTP JSON RPC at `endpoint`. E.g., `http://localhost:8545`.
@@ -150,74 +156,40 @@ pub async fn get_block_number(endpoint: &SensitiveUrl, timeout: Duration) -> Res
150156
.map_err(|e| format!("Failed to get block number: {}", e))
151157
}
152158

153-
/// Gets a block by hash or block number.
159+
/// Gets a block hash by block number.
154160
///
155161
/// Uses HTTP JSON RPC at `endpoint`. E.g., `http://localhost:8545`.
156162
pub async fn get_block(
157163
endpoint: &SensitiveUrl,
158164
query: BlockQuery,
159165
timeout: Duration,
160-
) -> Result<PowBlock, String> {
166+
) -> Result<Block, String> {
161167
let query_param = match query {
162168
BlockQuery::Number(block_number) => format!("0x{:x}", block_number),
163-
BlockQuery::Hash(hash) => format!("{:?}", hash), // debug formatting ensures output not truncated
164169
BlockQuery::Latest => "latest".to_string(),
165170
};
166-
let rpc_method = match query {
167-
BlockQuery::Number(_) | BlockQuery::Latest => "eth_getBlockByNumber",
168-
BlockQuery::Hash(_) => "eth_getBlockByHash",
169-
};
170171
let params = json!([
171172
query_param,
172173
false // do not return full tx objects.
173174
]);
174175

175-
let response_body = send_rpc_request(endpoint, rpc_method, params, timeout).await?;
176+
let response_body = send_rpc_request(endpoint, "eth_getBlockByNumber", params, timeout).await?;
176177
let response = response_result_or_error(&response_body)
177-
.map_err(|e| format!("{} failed: {}", rpc_method, e))?;
178+
.map_err(|e| format!("eth_getBlockByNumber failed: {}", e))?;
178179

179-
let block_hash: Vec<u8> = hex_to_bytes(
180+
let hash: Vec<u8> = hex_to_bytes(
180181
response
181182
.get("hash")
182183
.ok_or("No hash for block")?
183184
.as_str()
184185
.ok_or("Block hash was not string")?,
185186
)?;
186-
let block_hash: Hash256 = if block_hash.len() == 32 {
187-
Hash256::from_slice(&block_hash)
187+
let hash: Hash256 = if hash.len() == 32 {
188+
Hash256::from_slice(&hash)
188189
} else {
189-
return Err(format!("Block hash was not 32 bytes: {:?}", block_hash));
190+
return Err(format!("Block has was not 32 bytes: {:?}", hash));
190191
};
191192

192-
let parent_hash: Vec<u8> = hex_to_bytes(
193-
response
194-
.get("parentHash")
195-
.ok_or("No parent hash for block")?
196-
.as_str()
197-
.ok_or("Parent hash was not string")?,
198-
)?;
199-
let parent_hash: Hash256 = if parent_hash.len() == 32 {
200-
Hash256::from_slice(&parent_hash)
201-
} else {
202-
return Err(format!("parent hash was not 32 bytes: {:?}", parent_hash));
203-
};
204-
205-
let total_difficulty_str = response
206-
.get("totalDifficulty")
207-
.ok_or("No total difficulty for block")?
208-
.as_str()
209-
.ok_or("Total difficulty was not a string")?;
210-
let total_difficulty = Uint256::from_str(total_difficulty_str)
211-
.map_err(|e| format!("total_difficulty from_str {:?}", e))?;
212-
213-
let difficulty_str = response
214-
.get("difficulty")
215-
.ok_or("No difficulty for block")?
216-
.as_str()
217-
.ok_or("Difficulty was not a string")?;
218-
let difficulty =
219-
Uint256::from_str(difficulty_str).map_err(|e| format!("difficulty from_str {:?}", e))?;
220-
221193
let timestamp = hex_to_u64_be(
222194
response
223195
.get("timestamp")
@@ -226,28 +198,22 @@ pub async fn get_block(
226198
.ok_or("Block timestamp was not string")?,
227199
)?;
228200

229-
let block_number = hex_to_u64_be(
201+
let number = hex_to_u64_be(
230202
response
231203
.get("number")
232204
.ok_or("No number for block")?
233205
.as_str()
234206
.ok_or("Block number was not string")?,
235207
)?;
236208

237-
if block_number <= usize::max_value() as u64 {
238-
Ok(PowBlock {
239-
block_hash,
240-
parent_hash,
241-
total_difficulty,
242-
difficulty,
209+
if number <= usize::max_value() as u64 {
210+
Ok(Block {
211+
hash,
243212
timestamp,
244-
block_number,
213+
number,
245214
})
246215
} else {
247-
Err(format!(
248-
"Block number {} is larger than a usize",
249-
block_number
250-
))
216+
Err(format!("Block number {} is larger than a usize", number))
251217
}
252218
.map_err(|e| format!("Failed to get block number: {}", e))
253219
}
@@ -479,7 +445,7 @@ pub async fn send_rpc_request(
479445
}
480446

481447
/// Accepts an entire HTTP body (as a string) and returns either the `result` field or the `error['message']` field, as a serde `Value`.
482-
pub fn response_result_or_error(response: &str) -> Result<Value, RpcError> {
448+
fn response_result_or_error(response: &str) -> Result<Value, RpcError> {
483449
let json = serde_json::from_str::<Value>(response)
484450
.map_err(|e| RpcError::InvalidJson(e.to_string()))?;
485451

@@ -501,7 +467,7 @@ pub fn response_result_or_error(response: &str) -> Result<Value, RpcError> {
501467
/// Therefore, this function is only useful for numbers encoded by the JSON RPC.
502468
///
503469
/// E.g., `0x01 == 1`
504-
pub fn hex_to_u64_be(hex: &str) -> Result<u64, String> {
470+
fn hex_to_u64_be(hex: &str) -> Result<u64, String> {
505471
u64::from_str_radix(strip_prefix(hex)?, 16)
506472
.map_err(|e| format!("Failed to parse hex as u64: {:?}", e))
507473
}

beacon_node/eth1/src/service.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::sync::Arc;
2121
use std::time::{SystemTime, UNIX_EPOCH};
2222
use tokio::sync::RwLock as TRwLock;
2323
use tokio::time::{interval_at, Duration, Instant};
24-
use types::{ChainSpec, EthSpec, ExecutionPayload, Unsigned};
24+
use types::{ChainSpec, EthSpec, Unsigned};
2525

2626
/// Indicates the default eth1 network id we use for the deposit contract.
2727
pub const DEFAULT_NETWORK_ID: Eth1Id = Eth1Id::Goerli;
@@ -331,8 +331,6 @@ pub enum SingleEndpointError {
331331
GetDepositCountFailed(String),
332332
/// Failed to read the deposit contract root from the eth1 node.
333333
GetDepositLogsFailed(String),
334-
/// Failed to run engine_ExecutePayload
335-
EngineExecutePayloadFailed,
336334
}
337335

338336
#[derive(Debug, PartialEq)]
@@ -671,21 +669,6 @@ impl Service {
671669
}
672670
}
673671

674-
/// This is were we call out to engine_executePayload to determine if payload is valid
675-
pub async fn on_payload<T: EthSpec>(
676-
&self,
677-
_execution_payload: ExecutionPayload<T>,
678-
) -> Result<bool, Error> {
679-
let endpoints = self.init_endpoints();
680-
681-
// TODO: call engine_executePayload and figure out how backup endpoint works..
682-
endpoints
683-
.first_success(|_e| async move { Ok(true) })
684-
.await
685-
.map(|(res, _)| res)
686-
.map_err(Error::FallbackError)
687-
}
688-
689672
/// Update the deposit and block cache, returning an error if either fail.
690673
///
691674
/// ## Returns
@@ -1259,7 +1242,7 @@ async fn download_eth1_block(
12591242
});
12601243

12611244
// Performs a `get_blockByNumber` call to an eth1 node.
1262-
let pow_block = get_block(
1245+
let http_block = get_block(
12631246
endpoint,
12641247
block_number_opt
12651248
.map(BlockQuery::Number)
@@ -1270,9 +1253,9 @@ async fn download_eth1_block(
12701253
.await?;
12711254

12721255
Ok(Eth1Block {
1273-
hash: pow_block.block_hash,
1274-
number: pow_block.block_number,
1275-
timestamp: pow_block.timestamp,
1256+
hash: http_block.hash,
1257+
number: http_block.number,
1258+
timestamp: http_block.timestamp,
12761259
deposit_root,
12771260
deposit_count,
12781261
})

beacon_node/eth1/tests/test.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg(test)]
22
use environment::{Environment, EnvironmentBuilder};
3-
use eth1::http::{get_deposit_count, get_deposit_logs_in_range, get_deposit_root, Log};
3+
use eth1::http::{get_deposit_count, get_deposit_logs_in_range, get_deposit_root, Block, Log};
44
use eth1::{Config, Service};
55
use eth1::{DepositCache, DEFAULT_CHAIN_ID, DEFAULT_NETWORK_ID};
66
use eth1_test_rig::GanacheEth1Instance;
@@ -571,9 +571,8 @@ mod deposit_tree {
571571
mod http {
572572
use super::*;
573573
use eth1::http::BlockQuery;
574-
use types::PowBlock;
575574

576-
async fn get_block(eth1: &GanacheEth1Instance, block_number: u64) -> PowBlock {
575+
async fn get_block(eth1: &GanacheEth1Instance, block_number: u64) -> Block {
577576
eth1::http::get_block(
578577
&SensitiveUrl::parse(eth1.endpoint().as_str()).unwrap(),
579578
BlockQuery::Number(block_number),
@@ -640,7 +639,7 @@ mod http {
640639
// Check the block hash.
641640
let new_block = get_block(&eth1, block_number).await;
642641
assert_ne!(
643-
new_block.block_hash, old_block.block_hash,
642+
new_block.hash, old_block.hash,
644643
"block hash should change with each deposit"
645644
);
646645

@@ -662,7 +661,7 @@ mod http {
662661
// Check to ensure the block root is changing
663662
assert_ne!(
664663
new_root,
665-
Some(new_block.block_hash),
664+
Some(new_block.hash),
666665
"the deposit root should be different to the block hash"
667666
);
668667
}

consensus/types/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ pub mod graffiti;
4747
pub mod historical_batch;
4848
pub mod indexed_attestation;
4949
pub mod pending_attestation;
50-
pub mod pow_block;
5150
pub mod proposer_slashing;
5251
pub mod relative_epoch;
5352
pub mod selection_proof;
@@ -126,7 +125,6 @@ pub use crate::indexed_attestation::IndexedAttestation;
126125
pub use crate::participation_flags::ParticipationFlags;
127126
pub use crate::participation_list::ParticipationList;
128127
pub use crate::pending_attestation::PendingAttestation;
129-
pub use crate::pow_block::PowBlock;
130128
pub use crate::preset::{AltairPreset, BasePreset};
131129
pub use crate::proposer_slashing::ProposerSlashing;
132130
pub use crate::relative_epoch::{Error as RelativeEpochError, RelativeEpoch};

consensus/types/src/pow_block.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)