Persistent beacon state (consensus/types)

This commit is contained in:
Michael Sproul
2021-11-24 17:21:01 +11:00
parent 0b319d4926
commit 1b4dad0d76
7 changed files with 237 additions and 107 deletions

218
Cargo.lock generated
View File

@@ -298,9 +298,9 @@ dependencies = [
"eth1", "eth1",
"eth2", "eth2",
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_types", "eth2_ssz_types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fork_choice", "fork_choice",
"futures", "futures",
"genesis", "genesis",
@@ -331,7 +331,7 @@ dependencies = [
"task_executor", "task_executor",
"tempfile", "tempfile",
"tokio", "tokio",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]
@@ -450,14 +450,14 @@ dependencies = [
"blst", "blst",
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.12.1", "ethereum-types 0.12.1",
"hex", "hex",
"milagro_bls", "milagro_bls",
"rand 0.7.3", "rand 0.7.3",
"serde", "serde",
"serde_derive", "serde_derive",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"zeroize", "zeroize",
] ]
@@ -480,7 +480,7 @@ dependencies = [
"beacon_node", "beacon_node",
"clap", "clap",
"clap_utils", "clap_utils",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hex", "hex",
"lighthouse_network", "lighthouse_network",
"log", "log",
@@ -581,14 +581,14 @@ name = "cached_tree_hash"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_types", "eth2_ssz_types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.12.1", "ethereum-types 0.12.1",
"quickcheck", "quickcheck",
"quickcheck_macros", "quickcheck_macros",
"smallvec", "smallvec",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -681,7 +681,7 @@ dependencies = [
"clap", "clap",
"dirs", "dirs",
"eth2_network_config", "eth2_network_config",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hex", "hex",
] ]
@@ -1072,13 +1072,13 @@ checksum = "b72465f46d518f6015d9cf07f7f3013a95dd6b9c2747c3d65ae0cce43929d14f"
name = "deposit_contract" name = "deposit_contract"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethabi 12.0.0", "ethabi 12.0.0",
"hex", "hex",
"reqwest", "reqwest",
"serde_json", "serde_json",
"sha2", "sha2",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]
@@ -1270,8 +1270,8 @@ dependencies = [
"compare_fields", "compare_fields",
"compare_fields_derive", "compare_fields_derive",
"derivative", "derivative",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.12.1", "ethereum-types 0.12.1",
"fs2", "fs2",
"hex", "hex",
@@ -1284,8 +1284,8 @@ dependencies = [
"state_processing", "state_processing",
"store", "store",
"swap_or_not_shuffle", "swap_or_not_shuffle",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tree_hash_derive", "tree_hash_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]
@@ -1413,8 +1413,8 @@ dependencies = [
"environment", "environment",
"eth1_test_rig", "eth1_test_rig",
"eth2", "eth2",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fallback", "fallback",
"futures", "futures",
"hex", "hex",
@@ -1432,7 +1432,7 @@ dependencies = [
"task_executor", "task_executor",
"tokio", "tokio",
"toml", "toml",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
"web3", "web3",
] ]
@@ -1456,8 +1456,8 @@ dependencies = [
"bytes", "bytes",
"eth2_keystore", "eth2_keystore",
"eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures", "futures",
"futures-util", "futures-util",
"libsecp256k1 0.6.0", "libsecp256k1 0.6.0",
@@ -1561,7 +1561,7 @@ version = "0.2.0"
dependencies = [ dependencies = [
"enr", "enr",
"eth2_config", "eth2_config",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml", "serde_yaml",
"tempfile", "tempfile",
"types", "types",
@@ -1593,7 +1593,17 @@ dependencies = [
name = "eth2_ssz" name = "eth2_ssz"
version = "0.4.0" version = "0.4.0"
dependencies = [ dependencies = [
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.12.1",
"smallvec",
]
[[package]]
name = "eth2_ssz"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "948e343aa022785c07193f41ed37adfd9dd0350368060803b8302c7f798e8306"
dependencies = [
"ethereum-types 0.12.1", "ethereum-types 0.12.1",
"smallvec", "smallvec",
] ]
@@ -1608,18 +1618,45 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "eth2_ssz_derive"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "635b86d2c941bb71e7419a571e1763d65c93e51a1bafc400352e3bef6ff59fc9"
dependencies = [
"darling 0.13.0",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "eth2_ssz_types" name = "eth2_ssz_types"
version = "0.2.1" version = "0.2.1"
dependencies = [ dependencies = [
"arbitrary", "arbitrary",
"eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tree_hash_derive", "tree_hash_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"typenum",
]
[[package]]
name = "eth2_ssz_types"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9423ac7fb37037f828a32b724cdfa65ea62290055811731402a90fb8a5bcbb1"
dependencies = [
"arbitrary",
"eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde",
"serde_derive",
"tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"typenum", "typenum",
] ]
@@ -1884,8 +1921,8 @@ name = "fork_choice"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"beacon_chain", "beacon_chain",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proto_array", "proto_array",
"store", "store",
"types", "types",
@@ -2047,7 +2084,7 @@ dependencies = [
"eth1", "eth1",
"eth1_test_rig", "eth1_test_rig",
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures", "futures",
"int_to_bytes", "int_to_bytes",
"merkle_proof", "merkle_proof",
@@ -2056,7 +2093,7 @@ dependencies = [
"slog", "slog",
"state_processing", "state_processing",
"tokio", "tokio",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]
@@ -2329,7 +2366,7 @@ dependencies = [
"environment", "environment",
"eth1", "eth1",
"eth2", "eth2",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"futures", "futures",
"hex", "hex",
"lazy_static", "lazy_static",
@@ -2345,7 +2382,7 @@ dependencies = [
"store", "store",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
"warp", "warp",
"warp_utils", "warp_utils",
@@ -2670,7 +2707,7 @@ dependencies = [
"eth1_test_rig", "eth1_test_rig",
"eth2", "eth2",
"eth2_network_config", "eth2_network_config",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_wallet", "eth2_wallet",
"genesis", "genesis",
"lighthouse_network", "lighthouse_network",
@@ -2681,7 +2718,7 @@ dependencies = [
"serde_json", "serde_json",
"serde_yaml", "serde_yaml",
"state_processing", "state_processing",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
"validator_dir", "validator_dir",
"web3", "web3",
@@ -3215,9 +3252,9 @@ dependencies = [
"dirs", "dirs",
"discv5", "discv5",
"error-chain", "error-chain",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_types", "eth2_ssz_types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"exit-future", "exit-future",
"fnv", "fnv",
"futures", "futures",
@@ -3240,7 +3277,7 @@ dependencies = [
"smallvec", "smallvec",
"snap", "snap",
"strum", "strum",
"superstruct", "superstruct 0.2.0",
"task_executor", "task_executor",
"tempfile", "tempfile",
"tiny-keccak 2.0.2", "tiny-keccak 2.0.2",
@@ -3435,6 +3472,19 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "milhouse"
version = "0.1.0"
dependencies = [
"derivative",
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot",
"serde",
"tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"typenum",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.3.16" version = "0.3.16"
@@ -3611,8 +3661,8 @@ dependencies = [
"beacon_chain", "beacon_chain",
"environment", "environment",
"error-chain", "error-chain",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_types", "eth2_ssz_types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"exit-future", "exit-future",
"fnv", "fnv",
"futures", "futures",
@@ -3876,8 +3926,8 @@ version = "0.2.0"
dependencies = [ dependencies = [
"beacon_chain", "beacon_chain",
"derivative", "derivative",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools", "itertools",
"lazy_static", "lazy_static",
"lighthouse_metrics", "lighthouse_metrics",
@@ -4387,8 +4437,8 @@ dependencies = [
name = "proto_array" name = "proto_array"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_yaml", "serde_yaml",
@@ -5229,8 +5279,8 @@ version = "0.1.0"
dependencies = [ dependencies = [
"bincode", "bincode",
"byteorder", "byteorder",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"filesystem", "filesystem",
"flate2", "flate2",
"lazy_static", "lazy_static",
@@ -5248,8 +5298,8 @@ dependencies = [
"slog", "slog",
"sloggers", "sloggers",
"tempfile", "tempfile",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tree_hash_derive", "tree_hash_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]
@@ -5508,8 +5558,8 @@ dependencies = [
"bls", "bls",
"env_logger 0.9.0", "env_logger 0.9.0",
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_types", "eth2_ssz_types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"int_to_bytes", "int_to_bytes",
"integer-sqrt", "integer-sqrt",
"itertools", "itertools",
@@ -5519,7 +5569,7 @@ dependencies = [
"rayon", "rayon",
"safe_arith", "safe_arith",
"smallvec", "smallvec",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]
@@ -5528,7 +5578,7 @@ name = "state_transition_vectors"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"beacon_chain", "beacon_chain",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static", "lazy_static",
"state_processing", "state_processing",
"types", "types",
@@ -5547,8 +5597,8 @@ dependencies = [
"beacon_chain", "beacon_chain",
"db-key", "db-key",
"directory", "directory",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools", "itertools",
"lazy_static", "lazy_static",
"leveldb", "leveldb",
@@ -5603,6 +5653,17 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "superstruct"
version = "0.1.0"
dependencies = [
"darling 0.13.0",
"itertools",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "superstruct" name = "superstruct"
version = "0.2.0" version = "0.2.0"
@@ -6093,15 +6154,26 @@ version = "0.4.0"
dependencies = [ dependencies = [
"beacon_chain", "beacon_chain",
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.12.1", "ethereum-types 0.12.1",
"rand 0.7.3", "rand 0.7.3",
"smallvec", "smallvec",
"tree_hash_derive", "tree_hash_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]
[[package]]
name = "tree_hash"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9c8a86fad3169a65aad2265d3c6a8bc119d0b771046af3c1b2fb0e9b12182b"
dependencies = [
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.12.1",
"smallvec",
]
[[package]] [[package]]
name = "tree_hash_derive" name = "tree_hash_derive"
version = "0.4.0" version = "0.4.0"
@@ -6111,6 +6183,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "tree_hash_derive"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cd22d128157837a4434bb51119aef11103f17bfe8c402ce688cf25aa1e608ad"
dependencies = [
"darling 0.13.0",
"quote",
"syn",
]
[[package]] [[package]]
name = "trust-dns-proto" name = "trust-dns-proto"
version = "0.20.3" version = "0.20.3"
@@ -6211,15 +6294,16 @@ dependencies = [
"eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_hashing 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_interop_keypairs", "eth2_interop_keypairs",
"eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "eth2_serde_utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz", "eth2_ssz 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_derive", "eth2_ssz_derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"eth2_ssz_types", "eth2_ssz_types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.12.1", "ethereum-types 0.12.1",
"hex", "hex",
"int_to_bytes", "int_to_bytes",
"itertools", "itertools",
"lazy_static", "lazy_static",
"log", "log",
"milhouse",
"parking_lot", "parking_lot",
"rand 0.7.3", "rand 0.7.3",
"rand_xorshift", "rand_xorshift",
@@ -6232,12 +6316,12 @@ dependencies = [
"serde_yaml", "serde_yaml",
"slog", "slog",
"state_processing", "state_processing",
"superstruct", "superstruct 0.1.0",
"swap_or_not_shuffle", "swap_or_not_shuffle",
"tempfile", "tempfile",
"test_random_derive", "test_random_derive",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tree_hash_derive", "tree_hash_derive 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@@ -6426,7 +6510,7 @@ dependencies = [
"task_executor", "task_executor",
"tempfile", "tempfile",
"tokio", "tokio",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
"url", "url",
"validator_dir", "validator_dir",
@@ -6447,7 +6531,7 @@ dependencies = [
"lockfile", "lockfile",
"rand 0.7.3", "rand 0.7.3",
"tempfile", "tempfile",
"tree_hash", "tree_hash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"types", "types",
] ]

View File

@@ -85,10 +85,5 @@ members = [
[patch] [patch]
[patch.crates-io] [patch.crates-io]
eth2_ssz = { path = "consensus/ssz" }
eth2_ssz_types = { path = "consensus/ssz_types" }
eth2_ssz_derive = { path = "consensus/ssz_derive" }
tree_hash = { path = "consensus/tree_hash" }
tree_hash_derive = { path = "consensus/tree_hash_derive" }
fixed-hash = { git = "https://github.com/paritytech/parity-common", rev="df638ab0885293d21d656dc300d39236b69ce57d" } fixed-hash = { git = "https://github.com/paritytech/parity-common", rev="df638ab0885293d21d656dc300d39236b69ce57d" }
warp = { git = "https://github.com/macladson/warp", rev ="7e75acc" } warp = { git = "https://github.com/macladson/warp", rev ="7e75acc" }

View File

@@ -43,7 +43,9 @@ regex = "1.3.9"
lazy_static = "1.4.0" lazy_static = "1.4.0"
parking_lot = "0.11.1" parking_lot = "0.11.1"
itertools = "0.10.0" itertools = "0.10.0"
superstruct = "0.2.0" # superstruct = "0.2.0"
superstruct = { path = "../../../superstruct" }
milhouse = { path = "../../../milhouse", optional = true }
[dev-dependencies] [dev-dependencies]
criterion = "0.3.3" criterion = "0.3.3"

View File

@@ -12,7 +12,7 @@ use safe_arith::{ArithError, SafeArith};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use ssz::{ssz_encode, Decode, DecodeError, Encode}; use ssz::{ssz_encode, Decode, DecodeError, Encode};
use ssz_derive::{Decode, Encode}; use ssz_derive::{Decode, Encode};
use ssz_types::{typenum::Unsigned, BitVector, FixedVector}; use ssz_types::{typenum::Unsigned, BitVector};
use std::convert::TryInto; use std::convert::TryInto;
use std::{fmt, mem, sync::Arc}; use std::{fmt, mem, sync::Arc};
use superstruct::superstruct; use superstruct::superstruct;
@@ -28,7 +28,12 @@ pub use self::committee_cache::{
pub use clone_config::CloneConfig; pub use clone_config::CloneConfig;
pub use eth_spec::*; pub use eth_spec::*;
pub use iter::BlockRootsIter; pub use iter::BlockRootsIter;
pub use tree_hash_cache::BeaconTreeHashCache;
#[cfg(feature = "milhouse")]
use milhouse::prelude::{List as VList, *};
#[cfg(not(feature = "milhouse"))]
use {ssz_types::FixedVector, tree_hash_cache::BeaconTreeHashCache, VariableList as VList};
#[macro_use] #[macro_use]
mod committee_cache; mod committee_cache;
@@ -37,8 +42,13 @@ mod exit_cache;
mod iter; mod iter;
mod pubkey_cache; mod pubkey_cache;
mod tests; mod tests;
#[cfg(not(feature = "milhouse"))]
mod tree_hash_cache; mod tree_hash_cache;
#[cfg(feature = "milhouse")]
pub type ListMut<'a, T, N> = Interface<T, &'a mut List<T, N>>;
pub type ValidatorsMut<'a, N> = ListMut<'a, Validator, N>;
pub const CACHED_EPOCHS: usize = 3; pub const CACHED_EPOCHS: usize = 3;
const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1; const MAX_RANDOM_BYTE: u64 = (1 << 8) - 1;
@@ -230,8 +240,8 @@ where
pub eth1_deposit_index: u64, pub eth1_deposit_index: u64,
// Registry // Registry
#[compare_fields(as_slice)] #[test_random(default)]
pub validators: VariableList<Validator, T::ValidatorRegistryLimit>, pub validators: VList<Validator, T::ValidatorRegistryLimit>,
#[compare_fields(as_slice)] #[compare_fields(as_slice)]
#[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")] #[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")]
pub balances: VariableList<u64, T::ValidatorRegistryLimit>, pub balances: VariableList<u64, T::ValidatorRegistryLimit>,
@@ -306,6 +316,7 @@ where
#[tree_hash(skip_hashing)] #[tree_hash(skip_hashing)]
#[test_random(default)] #[test_random(default)]
#[derivative(Clone(clone_with = "clone_default"))] #[derivative(Clone(clone_with = "clone_default"))]
#[cfg(not(feature = "milhouse"))]
pub tree_hash_cache: BeaconTreeHashCache<T>, pub tree_hash_cache: BeaconTreeHashCache<T>,
} }
@@ -343,8 +354,8 @@ impl<T: EthSpec> BeaconState<T> {
eth1_deposit_index: 0, eth1_deposit_index: 0,
// Validator registry // Validator registry
validators: VariableList::empty(), // Set later. validators: VList::empty(), // Set later.
balances: VariableList::empty(), // Set later. balances: VariableList::empty(), // Set later.
// Randomness // Randomness
randao_mixes: FixedVector::from_elem(Hash256::zero()), randao_mixes: FixedVector::from_elem(Hash256::zero()),
@@ -371,6 +382,7 @@ impl<T: EthSpec> BeaconState<T> {
], ],
pubkey_cache: PubkeyCache::default(), pubkey_cache: PubkeyCache::default(),
exit_cache: ExitCache::default(), exit_cache: ExitCache::default(),
#[cfg(not(feature = "milhouse"))]
tree_hash_cache: <_>::default(), tree_hash_cache: <_>::default(),
}) })
} }
@@ -1085,6 +1097,7 @@ impl<T: EthSpec> BeaconState<T> {
} }
/// Convenience accessor for validators and balances simultaneously. /// Convenience accessor for validators and balances simultaneously.
#[cfg(not(feature = "milhouse"))]
pub fn validators_and_balances_mut(&mut self) -> (&mut [Validator], &mut [u64]) { pub fn validators_and_balances_mut(&mut self) -> (&mut [Validator], &mut [u64]) {
match self { match self {
BeaconState::Base(state) => (&mut state.validators, &mut state.balances), BeaconState::Base(state) => (&mut state.validators, &mut state.balances),
@@ -1092,6 +1105,16 @@ impl<T: EthSpec> BeaconState<T> {
} }
} }
#[cfg(feature = "milhouse")]
pub fn validators_and_balances_mut(
&mut self,
) -> (ValidatorsMut<T::ValidatorRegistryLimit>, &mut [u64]) {
match self {
BeaconState::Base(state) => (state.validators.as_mut(), &mut state.balances),
BeaconState::Altair(state) => (state.validators.as_mut(), &mut state.balances),
}
}
/// Generate a seed for the given `epoch`. /// Generate a seed for the given `epoch`.
pub fn get_seed( pub fn get_seed(
&self, &self,
@@ -1134,12 +1157,14 @@ impl<T: EthSpec> BeaconState<T> {
.ok_or(Error::UnknownValidator(validator_index)) .ok_or(Error::UnknownValidator(validator_index))
} }
/* FIXME(sproul): lens?
/// Safe mutator for the `validators` list. /// Safe mutator for the `validators` list.
pub fn get_validator_mut(&mut self, validator_index: usize) -> Result<&mut Validator, Error> { pub fn get_validator_mut(&mut self, validator_index: usize) -> Result<&mut Validator, Error> {
self.validators_mut() self.validators_mut()
.get_mut(validator_index) .get_mut(validator_index)
.ok_or(Error::UnknownValidator(validator_index)) .ok_or(Error::UnknownValidator(validator_index))
} }
*/
/// Return the effective balance for a validator with the given `validator_index`. /// Return the effective balance for a validator with the given `validator_index`.
pub fn get_effective_balance(&self, validator_index: usize) -> Result<u64, Error> { pub fn get_effective_balance(&self, validator_index: usize) -> Result<u64, Error> {
@@ -1519,6 +1544,7 @@ impl<T: EthSpec> BeaconState<T> {
/// Initialize but don't fill the tree hash cache, if it isn't already initialized. /// Initialize but don't fill the tree hash cache, if it isn't already initialized.
pub fn initialize_tree_hash_cache(&mut self) { pub fn initialize_tree_hash_cache(&mut self) {
#[cfg(not(feature = "milhouse"))]
if !self.tree_hash_cache().is_initialized() { if !self.tree_hash_cache().is_initialized() {
*self.tree_hash_cache_mut() = BeaconTreeHashCache::new(self) *self.tree_hash_cache_mut() = BeaconTreeHashCache::new(self)
} }
@@ -1528,42 +1554,53 @@ impl<T: EthSpec> BeaconState<T> {
/// ///
/// Initialize the tree hash cache if it isn't already initialized. /// Initialize the tree hash cache if it isn't already initialized.
pub fn update_tree_hash_cache(&mut self) -> Result<Hash256, Error> { pub fn update_tree_hash_cache(&mut self) -> Result<Hash256, Error> {
self.initialize_tree_hash_cache(); #[cfg(not(feature = "milhouse"))]
{
self.initialize_tree_hash_cache();
let cache = self.tree_hash_cache_mut().take(); let cache = self.tree_hash_cache_mut().take();
if let Some(mut cache) = cache { if let Some(mut cache) = cache {
// Note: we return early if the tree hash fails, leaving `self.tree_hash_cache` as // Note: we return early if the tree hash fails, leaving `self.tree_hash_cache` as
// None. There's no need to keep a cache that fails. // None. There's no need to keep a cache that fails.
let root = cache.recalculate_tree_hash_root(self)?; let root = cache.recalculate_tree_hash_root(self)?;
self.tree_hash_cache_mut().restore(cache); self.tree_hash_cache_mut().restore(cache);
Ok(root) Ok(root)
} else { } else {
Err(Error::TreeHashCacheNotInitialized) Err(Error::TreeHashCacheNotInitialized)
}
} }
#[cfg(feature = "milhouse")]
Ok(self.tree_hash_root())
} }
/// Compute the tree hash root of the validators using the tree hash cache. /// Compute the tree hash root of the validators using the tree hash cache.
/// ///
/// Initialize the tree hash cache if it isn't already initialized. /// Initialize the tree hash cache if it isn't already initialized.
pub fn update_validators_tree_hash_cache(&mut self) -> Result<Hash256, Error> { pub fn update_validators_tree_hash_cache(&mut self) -> Result<Hash256, Error> {
self.initialize_tree_hash_cache(); #[cfg(not(feature = "milhouse"))]
{
self.initialize_tree_hash_cache();
let cache = self.tree_hash_cache_mut().take(); let cache = self.tree_hash_cache_mut().take();
if let Some(mut cache) = cache { if let Some(mut cache) = cache {
// Note: we return early if the tree hash fails, leaving `self.tree_hash_cache` as // Note: we return early if the tree hash fails, leaving `self.tree_hash_cache` as
// None. There's no need to keep a cache that fails. // None. There's no need to keep a cache that fails.
let root = cache.recalculate_validators_tree_hash_root(self.validators())?; let root = cache.recalculate_validators_tree_hash_root(self.validators())?;
self.tree_hash_cache_mut().restore(cache); self.tree_hash_cache_mut().restore(cache);
Ok(root) Ok(root)
} else { } else {
Err(Error::TreeHashCacheNotInitialized) Err(Error::TreeHashCacheNotInitialized)
}
} }
#[cfg(feature = "milhouse")]
Ok(self.validators().tree_hash_root())
} }
/// Completely drops the tree hash cache, replacing it with a new, empty cache. /// Completely drops the tree hash cache, replacing it with a new, empty cache.
pub fn drop_tree_hash_cache(&mut self) { pub fn drop_tree_hash_cache(&mut self) {
#[cfg(not(feature = "milhouse"))]
self.tree_hash_cache_mut().uninitialize(); self.tree_hash_cache_mut().uninitialize();
} }
@@ -1583,6 +1620,7 @@ impl<T: EthSpec> BeaconState<T> {
if config.exit_cache { if config.exit_cache {
*res.exit_cache_mut() = self.exit_cache().clone(); *res.exit_cache_mut() = self.exit_cache().clone();
} }
#[cfg(not(feature = "milhouse"))]
if config.tree_hash_cache { if config.tree_hash_cache {
*res.tree_hash_cache_mut() = self.tree_hash_cache().clone(); *res.tree_hash_cache_mut() = self.tree_hash_cache().clone();
} }

View File

@@ -10,6 +10,9 @@ use ssz_derive::{Decode, Encode};
use std::ops::Range; use std::ops::Range;
use swap_or_not_shuffle::shuffle_list; use swap_or_not_shuffle::shuffle_list;
#[cfg(feature = "milhouse")]
use milhouse::prelude::*;
mod tests; mod tests;
// Define "legacy" implementations of `Option<Epoch>`, `Option<NonZeroUsize>` which use four bytes // Define "legacy" implementations of `Option<Epoch>`, `Option<NonZeroUsize>` which use four bytes
@@ -312,17 +315,21 @@ pub fn epoch_committee_count(committees_per_slot: usize, slots_per_epoch: usize)
/// `epoch`. /// `epoch`.
/// ///
/// Spec v0.12.1 /// Spec v0.12.1
pub fn get_active_validator_indices(validators: &[Validator], epoch: Epoch) -> Vec<usize> { pub fn get_active_validator_indices<'a, V, I>(validators: V, epoch: Epoch) -> Vec<usize>
let mut active = Vec::with_capacity(validators.len()); where
V: IntoIterator<Item = &'a Validator, IntoIter = I>,
I: ExactSizeIterator + Iterator<Item = &'a Validator>,
{
let iter = validators.into_iter();
for (index, validator) in validators.iter().enumerate() { let mut active = Vec::with_capacity(iter.len());
for (index, validator) in iter.enumerate() {
if validator.is_active_at(epoch) { if validator.is_active_at(epoch) {
active.push(index) active.push(index)
} }
} }
active.shrink_to_fit();
active active
} }

View File

@@ -12,14 +12,18 @@ pub struct ExitCache {
impl ExitCache { impl ExitCache {
/// Initialize a new cache for the given list of validators. /// Initialize a new cache for the given list of validators.
pub fn new(validators: &[Validator], spec: &ChainSpec) -> Result<Self, BeaconStateError> { pub fn new<'a, V, I>(validators: V, spec: &ChainSpec) -> Result<Self, BeaconStateError>
where
V: IntoIterator<Item = &'a Validator, IntoIter = I>,
I: ExactSizeIterator + Iterator<Item = &'a Validator>,
{
let mut exit_cache = ExitCache { let mut exit_cache = ExitCache {
initialized: true, initialized: true,
..ExitCache::default() ..ExitCache::default()
}; };
// Add all validators with a non-default exit epoch to the cache. // Add all validators with a non-default exit epoch to the cache.
validators validators
.iter() .into_iter()
.filter(|validator| validator.exit_epoch != spec.far_future_epoch) .filter(|validator| validator.exit_epoch != spec.far_future_epoch)
.try_for_each(|validator| exit_cache.record_validator_exit(validator.exit_epoch))?; .try_for_each(|validator| exit_cache.record_validator_exit(validator.exit_epoch))?;
Ok(exit_cache) Ok(exit_cache)

View File

@@ -98,7 +98,7 @@ pub use crate::beacon_block_body::{
}; };
pub use crate::beacon_block_header::BeaconBlockHeader; pub use crate::beacon_block_header::BeaconBlockHeader;
pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee}; pub use crate::beacon_committee::{BeaconCommittee, OwnedBeaconCommittee};
pub use crate::beacon_state::{BeaconTreeHashCache, Error as BeaconStateError, *}; pub use crate::beacon_state::{Error as BeaconStateError, *};
pub use crate::chain_spec::{ChainSpec, Config, Domain}; pub use crate::chain_spec::{ChainSpec, Config, Domain};
pub use crate::checkpoint::Checkpoint; pub use crate::checkpoint::Checkpoint;
pub use crate::config_and_preset::ConfigAndPreset; pub use crate::config_and_preset::ConfigAndPreset;