Skip to content

Commit de49c7d

Browse files
1.1.5 merge spec tests (#2781)
* Fix arbitrary check kintsugi * Add merge chain spec fields, and a function to determine which constant to use based on the state variant * increment spec test version * Remove `Transaction` enum wrapper * Remove Transaction new-type * Remove gas validations * Add `--terminal-block-hash-epoch-override` flag * Increment spec tests version to 1.1.5 * Remove extraneous gossip verification ethereum/consensus-specs#2687 * - Remove unused Error variants - Require both "terminal-block-hash-epoch-override" and "terminal-block-hash-override" when either flag is used * - Remove a couple more unused Error variants Co-authored-by: Paul Hauner <[email protected]>
1 parent cdbe603 commit de49c7d

File tree

20 files changed

+210
-208
lines changed

20 files changed

+210
-208
lines changed

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,6 @@ pub enum ExecutionPayloadError {
278278
///
279279
/// The block is invalid and the peer is faulty
280280
InvalidPayloadTimestamp { expected: u64, found: u64 },
281-
/// The gas used in the block exceeds the gas limit
282-
///
283-
/// ## Peer scoring
284-
///
285-
/// The block is invalid and the peer is faulty
286-
GasUsedExceedsLimit,
287-
/// The payload block hash equals the parent hash
288-
///
289-
/// ## Peer scoring
290-
///
291-
/// The block is invalid and the peer is faulty
292-
BlockHashEqualsParentHash,
293281
/// The execution payload transaction list data exceeds size limits
294282
///
295283
/// ## Peer scoring
@@ -1353,18 +1341,6 @@ fn validate_execution_payload<T: BeaconChainTypes>(
13531341
},
13541342
));
13551343
}
1356-
// Gas used is less than the gas limit
1357-
if execution_payload.gas_used > execution_payload.gas_limit {
1358-
return Err(BlockError::ExecutionPayloadError(
1359-
ExecutionPayloadError::GasUsedExceedsLimit,
1360-
));
1361-
}
1362-
// The execution payload block hash is not equal to the parent hash
1363-
if execution_payload.block_hash == execution_payload.parent_hash {
1364-
return Err(BlockError::ExecutionPayloadError(
1365-
ExecutionPayloadError::BlockHashEqualsParentHash,
1366-
));
1367-
}
13681344
// The execution payload transaction list data is within expected size limits
13691345
if execution_payload.transactions.len() > T::EthSpec::max_transactions_per_payload() {
13701346
return Err(BlockError::ExecutionPayloadError(

beacon_node/client/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ where
152152
.terminal_total_difficulty_override
153153
.unwrap_or(spec.terminal_total_difficulty);
154154
let terminal_block_hash = config
155-
.terminal_block_hash
155+
.terminal_block_hash_override
156156
.unwrap_or(spec.terminal_block_hash);
157157

158158
let execution_layer = if let Some(execution_endpoints) = config.execution_endpoints {

beacon_node/client/src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use beacon_chain::types::Epoch;
12
use directory::DEFAULT_ROOT_DIR;
23
use network::NetworkConfig;
34
use sensitive_url::SensitiveUrl;
@@ -76,7 +77,8 @@ pub struct Config {
7677
pub eth1: eth1::Config,
7778
pub execution_endpoints: Option<Vec<SensitiveUrl>>,
7879
pub terminal_total_difficulty_override: Option<Uint256>,
79-
pub terminal_block_hash: Option<Hash256>,
80+
pub terminal_block_hash_override: Option<Hash256>,
81+
pub terminal_block_hash_epoch_override: Option<Epoch>,
8082
pub fee_recipient: Option<Address>,
8183
pub http_api: http_api::Config,
8284
pub http_metrics: http_metrics::Config,
@@ -100,7 +102,8 @@ impl Default for Config {
100102
eth1: <_>::default(),
101103
execution_endpoints: None,
102104
terminal_total_difficulty_override: None,
103-
terminal_block_hash: None,
105+
terminal_block_hash_override: None,
106+
terminal_block_hash_epoch_override: None,
104107
fee_recipient: None,
105108
disabled_forks: Vec::new(),
106109
graffiti: Graffiti::default(),

beacon_node/execution_layer/src/engine_api/http.rs

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,8 @@ pub struct JsonExecutionPayload<T: EthSpec> {
308308
pub base_fee_per_gas: Uint256,
309309
pub block_hash: Hash256,
310310
#[serde(with = "serde_transactions")]
311-
pub transactions: VariableList<Transaction<T>, T::MaxTransactionsPerPayload>,
311+
pub transactions:
312+
VariableList<Transaction<T::MaxBytesPerTransaction>, T::MaxTransactionsPerPayload>,
312313
}
313314

314315
impl<T: EthSpec> From<ExecutionPayload<T>> for JsonExecutionPayload<T> {
@@ -410,16 +411,16 @@ pub mod serde_transactions {
410411
use serde::{de, Deserializer, Serializer};
411412
use std::marker::PhantomData;
412413

413-
type Value<T, N> = VariableList<Transaction<T>, N>;
414+
type Value<M, N> = VariableList<Transaction<M>, N>;
414415

415416
#[derive(Default)]
416-
pub struct ListOfBytesListVisitor<T, N> {
417-
_phantom_t: PhantomData<T>,
417+
pub struct ListOfBytesListVisitor<M, N> {
418+
_phantom_m: PhantomData<M>,
418419
_phantom_n: PhantomData<N>,
419420
}
420421

421-
impl<'a, T: EthSpec, N: Unsigned> serde::de::Visitor<'a> for ListOfBytesListVisitor<T, N> {
422-
type Value = Value<T, N>;
422+
impl<'a, M: Unsigned, N: Unsigned> serde::de::Visitor<'a> for ListOfBytesListVisitor<M, N> {
423+
type Value = Value<M, N>;
423424

424425
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
425426
write!(formatter, "a list of 0x-prefixed byte lists")
@@ -433,10 +434,9 @@ pub mod serde_transactions {
433434

434435
while let Some(val) = seq.next_element::<String>()? {
435436
let inner_vec = hex::decode(&val).map_err(de::Error::custom)?;
436-
let opaque_transaction = VariableList::new(inner_vec).map_err(|e| {
437+
let transaction = VariableList::new(inner_vec).map_err(|e| {
437438
serde::de::Error::custom(format!("transaction too large: {:?}", e))
438439
})?;
439-
let transaction = Transaction::OpaqueTransaction(opaque_transaction);
440440
outer.push(transaction).map_err(|e| {
441441
serde::de::Error::custom(format!("too many transactions: {:?}", e))
442442
})?;
@@ -446,8 +446,8 @@ pub mod serde_transactions {
446446
}
447447
}
448448

449-
pub fn serialize<S, T: EthSpec, N: Unsigned>(
450-
value: &Value<T, N>,
449+
pub fn serialize<S, M: Unsigned, N: Unsigned>(
450+
value: &Value<M, N>,
451451
serializer: S,
452452
) -> Result<S::Ok, S::Error>
453453
where
@@ -458,21 +458,19 @@ pub mod serde_transactions {
458458
// It's important to match on the inner values of the transaction. Serializing the
459459
// entire `Transaction` will result in appending the SSZ union prefix byte. The
460460
// execution node does not want that.
461-
let hex = match transaction {
462-
Transaction::OpaqueTransaction(val) => hex::encode(&val[..]),
463-
};
461+
let hex = hex::encode(&transaction[..]);
464462
seq.serialize_element(&hex)?;
465463
}
466464
seq.end()
467465
}
468466

469-
pub fn deserialize<'de, D, T: EthSpec, N: Unsigned>(
467+
pub fn deserialize<'de, D, M: Unsigned, N: Unsigned>(
470468
deserializer: D,
471-
) -> Result<Value<T, N>, D::Error>
469+
) -> Result<Value<M, N>, D::Error>
472470
where
473471
D: Deserializer<'de>,
474472
{
475-
let visitor: ListOfBytesListVisitor<T, N> = <_>::default();
473+
let visitor: ListOfBytesListVisitor<M, N> = <_>::default();
476474
deserializer.deserialize_any(visitor)
477475
}
478476
}
@@ -558,7 +556,10 @@ mod test {
558556
const LOGS_BLOOM_01: &str = "0x01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101";
559557

560558
fn encode_transactions<E: EthSpec>(
561-
transactions: VariableList<Transaction<E>, E::MaxTransactionsPerPayload>,
559+
transactions: VariableList<
560+
Transaction<E::MaxBytesPerTransaction>,
561+
E::MaxTransactionsPerPayload,
562+
>,
562563
) -> Result<serde_json::Value, serde_json::Error> {
563564
let ep: JsonExecutionPayload<E> = JsonExecutionPayload {
564565
transactions,
@@ -570,7 +571,10 @@ mod test {
570571

571572
fn decode_transactions<E: EthSpec>(
572573
transactions: serde_json::Value,
573-
) -> Result<VariableList<Transaction<E>, E::MaxTransactionsPerPayload>, serde_json::Error> {
574+
) -> Result<
575+
VariableList<Transaction<E::MaxBytesPerTransaction>, E::MaxTransactionsPerPayload>,
576+
serde_json::Error,
577+
> {
574578
let json = json!({
575579
"parentHash": HASH_00,
576580
"coinbase": ADDRESS_01,
@@ -593,35 +597,35 @@ mod test {
593597

594598
fn assert_transactions_serde<E: EthSpec>(
595599
name: &str,
596-
as_obj: VariableList<Transaction<E>, E::MaxTransactionsPerPayload>,
600+
as_obj: VariableList<Transaction<E::MaxBytesPerTransaction>, E::MaxTransactionsPerPayload>,
597601
as_json: serde_json::Value,
598602
) {
599603
assert_eq!(
600-
encode_transactions(as_obj.clone()).unwrap(),
604+
encode_transactions::<E>(as_obj.clone()).unwrap(),
601605
as_json,
602606
"encoding for {}",
603607
name
604608
);
605609
assert_eq!(
606-
decode_transactions(as_json).unwrap(),
610+
decode_transactions::<E>(as_json).unwrap(),
607611
as_obj,
608612
"decoding for {}",
609613
name
610614
);
611615
}
612616

613617
/// Example: if `spec == &[1, 1]`, then two one-byte transactions will be created.
614-
fn generate_opaque_transactions<E: EthSpec>(
618+
fn generate_transactions<E: EthSpec>(
615619
spec: &[usize],
616-
) -> VariableList<Transaction<E>, E::MaxTransactionsPerPayload> {
620+
) -> VariableList<Transaction<E::MaxBytesPerTransaction>, E::MaxTransactionsPerPayload> {
617621
let mut txs = VariableList::default();
618622

619623
for &num_bytes in spec {
620624
let mut tx = VariableList::default();
621625
for _ in 0..num_bytes {
622626
tx.push(0).unwrap();
623627
}
624-
txs.push(Transaction::OpaqueTransaction(tx)).unwrap();
628+
txs.push(tx).unwrap();
625629
}
626630

627631
txs
@@ -631,32 +635,32 @@ mod test {
631635
fn transaction_serde() {
632636
assert_transactions_serde::<MainnetEthSpec>(
633637
"empty",
634-
generate_opaque_transactions(&[]),
638+
generate_transactions::<MainnetEthSpec>(&[]),
635639
json!([]),
636640
);
637641
assert_transactions_serde::<MainnetEthSpec>(
638642
"one empty tx",
639-
generate_opaque_transactions(&[0]),
643+
generate_transactions::<MainnetEthSpec>(&[0]),
640644
json!(["0x"]),
641645
);
642646
assert_transactions_serde::<MainnetEthSpec>(
643647
"two empty txs",
644-
generate_opaque_transactions(&[0, 0]),
648+
generate_transactions::<MainnetEthSpec>(&[0, 0]),
645649
json!(["0x", "0x"]),
646650
);
647651
assert_transactions_serde::<MainnetEthSpec>(
648652
"one one-byte tx",
649-
generate_opaque_transactions(&[1]),
653+
generate_transactions::<MainnetEthSpec>(&[1]),
650654
json!(["0x00"]),
651655
);
652656
assert_transactions_serde::<MainnetEthSpec>(
653657
"two one-byte txs",
654-
generate_opaque_transactions(&[1, 1]),
658+
generate_transactions::<MainnetEthSpec>(&[1, 1]),
655659
json!(["0x00", "0x00"]),
656660
);
657661
assert_transactions_serde::<MainnetEthSpec>(
658662
"mixed bag",
659-
generate_opaque_transactions(&[0, 1, 3, 0]),
663+
generate_transactions::<MainnetEthSpec>(&[0, 1, 3, 0]),
660664
json!(["0x", "0x00", "0x000000", "0x"]),
661665
);
662666

@@ -680,7 +684,7 @@ mod test {
680684

681685
use eth2_serde_utils::hex;
682686

683-
let num_max_bytes = <MainnetEthSpec as EthSpec>::MaxBytesPerOpaqueTransaction::to_usize();
687+
let num_max_bytes = <MainnetEthSpec as EthSpec>::MaxBytesPerTransaction::to_usize();
684688
let max_bytes = (0..num_max_bytes).map(|_| 0_u8).collect::<Vec<_>>();
685689
let too_many_bytes = (0..=num_max_bytes).map(|_| 0_u8).collect::<Vec<_>>();
686690
decode_transactions::<MainnetEthSpec>(

beacon_node/src/cli.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
420420
the broad Ethereum community has elected to override the terminal PoW block. \
421421
Incorrect use of this flag will cause your node to experience a consensus
422422
failure. Be extremely careful with this flag.")
423+
.requires("terminal-block-hash-epoch-override")
424+
.takes_value(true)
425+
)
426+
.arg(
427+
Arg::with_name("terminal-block-hash-epoch-override")
428+
.long("terminal-block-hash-epoch-override")
429+
.value_name("EPOCH")
430+
.help("Used to coordinate manual overrides to the TERMINAL_BLOCK_HASH_ACTIVATION_EPOCH \
431+
parameter. This flag should only be used if the user has a clear understanding \
432+
that the broad Ethereum community has elected to override the terminal PoW block. \
433+
Incorrect use of this flag will cause your node to experience a consensus
434+
failure. Be extremely careful with this flag.")
435+
.requires("terminal-block-hash-override")
423436
.takes_value(true)
424437
)
425438
.arg(

beacon_node/src/config.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ pub fn get_config<E: EthSpec>(
264264
}
265265

266266
client_config.fee_recipient = clap_utils::parse_optional(cli_args, "fee-recipient")?;
267-
client_config.terminal_block_hash =
268-
clap_utils::parse_optional(cli_args, "terminal-block-hash")?;
267+
client_config.terminal_block_hash_override =
268+
clap_utils::parse_optional(cli_args, "terminal-block-hash-override")?;
269+
client_config.terminal_block_hash_epoch_override =
270+
clap_utils::parse_optional(cli_args, "terminal-block-hash-epoch-override")?;
269271

270272
if let Some(freezer_dir) = cli_args.value_of("freezer-dir") {
271273
client_config.freezer_db_path = Some(PathBuf::from(freezer_dir));
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//! Serialize `VaraibleList<VariableList<u8, M>, N>` as list of 0x-prefixed hex string.
2+
use crate::VariableList;
3+
use serde::{ser::SerializeSeq, Deserialize, Deserializer, Serialize, Serializer};
4+
use std::marker::PhantomData;
5+
use typenum::Unsigned;
6+
7+
#[derive(Deserialize)]
8+
#[serde(transparent)]
9+
pub struct WrappedListOwned<N: Unsigned>(
10+
#[serde(with = "crate::serde_utils::hex_var_list")] VariableList<u8, N>,
11+
);
12+
13+
#[derive(Serialize)]
14+
#[serde(transparent)]
15+
pub struct WrappedListRef<'a, N: Unsigned>(
16+
#[serde(with = "crate::serde_utils::hex_var_list")] &'a VariableList<u8, N>,
17+
);
18+
19+
pub fn serialize<S, M, N>(
20+
list: &VariableList<VariableList<u8, M>, N>,
21+
serializer: S,
22+
) -> Result<S::Ok, S::Error>
23+
where
24+
S: Serializer,
25+
M: Unsigned,
26+
N: Unsigned,
27+
{
28+
let mut seq = serializer.serialize_seq(Some(list.len()))?;
29+
for bytes in list {
30+
seq.serialize_element(&WrappedListRef(bytes))?;
31+
}
32+
seq.end()
33+
}
34+
35+
#[derive(Default)]
36+
pub struct Visitor<M, N> {
37+
_phantom_m: PhantomData<M>,
38+
_phantom_n: PhantomData<N>,
39+
}
40+
41+
impl<'a, M, N> serde::de::Visitor<'a> for Visitor<M, N>
42+
where
43+
M: Unsigned,
44+
N: Unsigned,
45+
{
46+
type Value = VariableList<VariableList<u8, M>, N>;
47+
48+
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
49+
write!(formatter, "a list of 0x-prefixed hex bytes")
50+
}
51+
52+
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
53+
where
54+
A: serde::de::SeqAccess<'a>,
55+
{
56+
let mut list: VariableList<VariableList<u8, M>, N> = <_>::default();
57+
58+
while let Some(val) = seq.next_element::<WrappedListOwned<M>>()? {
59+
list.push(val.0).map_err(|e| {
60+
serde::de::Error::custom(format!("failed to push value to list: {:?}.", e))
61+
})?;
62+
}
63+
64+
Ok(list)
65+
}
66+
}
67+
68+
pub fn deserialize<'de, D, M, N>(
69+
deserializer: D,
70+
) -> Result<VariableList<VariableList<u8, M>, N>, D::Error>
71+
where
72+
D: Deserializer<'de>,
73+
M: Unsigned,
74+
N: Unsigned,
75+
{
76+
deserializer.deserialize_seq(Visitor::default())
77+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod hex_fixed_vec;
22
pub mod hex_var_list;
3+
pub mod list_of_hex_var_list;
34
pub mod quoted_u64_fixed_vec;
45
pub mod quoted_u64_var_list;

0 commit comments

Comments
 (0)