From 1e5e7f8e69f15e473f345c94679f34bf16810686 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:28:40 +0000 Subject: [PATCH] v1.17: Initialize fork graph in program cache during bank_forks creation (backport of #33810) (#33817) * Initialize fork graph in program cache during bank_forks creation (#33810) * Initialize fork graph in program cache during bank_forks creation * rename BankForks::new to BankForks::new_rw_arc * fix compilation * no need to set fork_graph on insert() * fix partition tests (cherry picked from commit 9d42cd7efe869223040f68c0a9b2bdfa99f1018a) # Conflicts: # core/src/repair/repair_service.rs # core/tests/epoch_accounts_hash.rs # ledger/src/blockstore_processor.rs # rpc/src/rpc_service.rs # runtime/src/bank/tests.rs * fix merge conflicts --------- Co-authored-by: Pankaj Garg --- Cargo.lock | 377 +++++++++--------- banking-bench/src/main.rs | 2 +- banks-client/src/lib.rs | 4 +- client-test/tests/client.rs | 12 +- core/benches/banking_stage.rs | 4 +- core/benches/consensus.rs | 10 +- core/src/banking_stage.rs | 10 +- core/src/banking_stage/consume_worker.rs | 2 +- core/src/banking_stage/forward_worker.rs | 2 +- core/src/banking_stage/forwarder.rs | 2 +- core/src/cluster_info_vote_listener.rs | 10 +- core/src/commitment_service.rs | 3 +- .../consensus/heaviest_subtree_fork_choice.rs | 3 +- core/src/repair/ancestor_hashes_service.rs | 2 +- core/src/repair/quic_endpoint.rs | 2 +- core/src/repair/repair_service.rs | 4 +- core/src/repair/serve_repair.rs | 10 +- core/src/replay_stage.rs | 38 +- core/src/tvu.rs | 5 +- core/src/validator.rs | 6 +- core/src/vote_simulator.rs | 16 +- core/tests/epoch_accounts_hash.rs | 25 +- core/tests/snapshots.rs | 82 ++-- gossip/src/duplicate_shred_handler.rs | 18 +- gossip/tests/gossip.rs | 2 +- ledger/src/bank_forks_utils.rs | 14 +- ledger/src/blockstore_processor.rs | 15 +- program-runtime/src/loaded_programs.rs | 2 +- program-test/src/lib.rs | 2 +- .../optimistically_confirmed_bank_tracker.rs | 2 +- rpc/src/rpc.rs | 9 +- rpc/src/rpc_health.rs | 2 +- rpc/src/rpc_pubsub.rs | 26 +- rpc/src/rpc_pubsub_service.rs | 2 +- rpc/src/rpc_service.rs | 4 +- rpc/src/rpc_subscription_tracker.rs | 4 +- rpc/src/rpc_subscriptions.rs | 38 +- runtime/benches/prioritization_fee_cache.rs | 4 +- runtime/src/bank/tests.rs | 17 +- runtime/src/bank_forks.rs | 106 +++-- runtime/src/prioritization_fee_cache.rs | 8 +- runtime/src/root_bank_cache.rs | 2 +- .../src/send_transaction_service.rs | 8 +- turbine/benches/cluster_info.rs | 9 +- turbine/benches/retransmit_stage.rs | 7 +- turbine/src/broadcast_stage.rs | 2 +- .../broadcast_stage/standard_broadcast_run.rs | 2 +- turbine/src/quic_endpoint.rs | 2 +- turbine/src/sigverify_shreds.rs | 2 +- validator/src/admin_rpc_service.rs | 5 +- 50 files changed, 501 insertions(+), 444 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55974005a539bf..a4c713f1984c57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,14 +76,15 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" +checksum = "72832d73be48bac96a5d7944568f305d829ed55b0ce3b483647089dfaf6cf704" dependencies = [ "cfg-if 1.0.0", "getrandom 0.2.10", "once_cell", "version_check", + "zerocopy", ] [[package]] @@ -430,13 +431,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -590,7 +591,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -864,9 +865,9 @@ dependencies = [ [[package]] name = "bytecount" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c676a478f63e9fa2dd5368a42f28bba0d6c560b775f38583c8bbaa7fcd67c9c" +checksum = "ad152d03a2c813c80bb94fedbf3a3f02b28f793e39e7c214c8a0bcc196343de7" [[package]] name = "bytemuck" @@ -890,9 +891,9 @@ dependencies = [ [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" @@ -963,7 +964,7 @@ checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" dependencies = [ "camino", "cargo-platform", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_json", "thiserror", @@ -1228,18 +1229,18 @@ checksum = "e4c78c047431fee22c1a7bb92e00ad095a02a983affe4d8a72e2a2c62c1b94f3" [[package]] name = "const_format" -version = "0.2.31" +version = "0.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c990efc7a285731f9a4378d81aff2f0e85a2c8781a05ef0f8baa8dac54d0ff48" +checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" dependencies = [ "const_format_proc_macros", ] [[package]] name = "const_format_proc_macros" -version = "0.2.31" +version = "0.2.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e026b6ce194a874cb9cf32cd5772d1ef9767cc8fcb5765948d74f37a9d8b2bf6" +checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" dependencies = [ "proc-macro2", "quote", @@ -1423,9 +1424,9 @@ dependencies = [ [[package]] name = "csv" -version = "1.2.2" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "626ae34994d3d8d668f4269922248239db4ae42d538b14c398b74a52208e8086" +checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" dependencies = [ "csv-core", "itoa", @@ -1435,9 +1436,9 @@ dependencies = [ [[package]] name = "csv-core" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" dependencies = [ "memchr", ] @@ -1496,7 +1497,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1507,7 +1508,7 @@ checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ "darling_core", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1523,13 +1524,15 @@ dependencies = [ [[package]] name = "dashmap" -version = "5.2.0" +version = "5.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8858831f7781322e539ea39e72449c46b059638250c14344fec8d0aa6e539c" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" dependencies = [ "cfg-if 1.0.0", - "num_cpus", - "parking_lot 0.12.1", + "hashbrown 0.14.1", + "lock_api", + "once_cell", + "parking_lot_core 0.9.8", ] [[package]] @@ -1699,7 +1702,7 @@ checksum = "a6cbae11b3de8fce2a456e8ea3dada226b35fe791f0dc1d360c0941f0bb681f3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1746,7 +1749,7 @@ dependencies = [ "derivation-path", "ed25519-dalek", "hmac 0.12.1", - "sha2 0.10.7", + "sha2 0.10.8", ] [[package]] @@ -1799,7 +1802,7 @@ checksum = "eecf8589574ce9b895052fa12d69af7a233f99e6107f5cb8dd1044f2a17bfdcb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -1946,9 +1949,9 @@ checksum = "398ea4fabe40b9b0d885340a2a991a44c8a645624075ad966d21f88688e2b69e" [[package]] name = "flate2" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6c98ee8095e9d1dcbf2fcc6d95acccb90d1c81db1e44725c6a984b1dbdfb010" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" dependencies = [ "crc32fast", "miniz_oxide", @@ -2074,7 +2077,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -2316,14 +2319,14 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ - "ahash 0.8.3", + "ahash 0.8.4", ] [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "7dfda62a12f55daeae5015f81b0baea145391cb4520f86c248fc615d72640d12" [[package]] name = "headers" @@ -2626,12 +2629,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad227c3af19d4914570ad36d30409928b75967c298feb9ea1969db3a610bb14e" +checksum = "8adf3ddd720272c6ea8bf59463c04e0f93d0bbf7c5439b691bca2987e0270897" dependencies = [ "equivalent", - "hashbrown 0.14.0", + "hashbrown 0.14.1", "rayon", ] @@ -2868,9 +2871,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" [[package]] name = "libloading" @@ -2987,10 +2990,11 @@ checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" [[package]] name = "lock_api" -version = "0.4.6" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88943dd7ef4a2e5a4bfa2753aaab3013e34ce2533d1996fb18ef591e315e2b3b" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ + "autocfg", "scopeguard", ] @@ -3301,13 +3305,13 @@ dependencies = [ [[package]] name = "num-derive" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e6a0fd4f737c707bd9086cc16c925f294943eb62eb71499e9fd4cf71f8b9f4e" +checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3345,9 +3349,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", "libm", @@ -3411,7 +3415,7 @@ dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3423,7 +3427,7 @@ dependencies = [ "proc-macro-crate 1.1.0", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3617,7 +3621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", - "parking_lot_core 0.9.1", + "parking_lot_core 0.9.8", ] [[package]] @@ -3636,15 +3640,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.1" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28141e0cc4143da2443301914478dc976a61ffdb3f043058310c70df2fed8954" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.2.10", + "redox_syscall 0.3.5", "smallvec", - "windows-sys 0.32.0", + "windows-targets 0.48.0", ] [[package]] @@ -3930,7 +3934,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ceca8aaf45b5c46ec7ed39fff75f57290368c1846d33d24a122ca81416ab058" dependencies = [ "proc-macro2", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -3978,28 +3982,28 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.67" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" -version = "1.2.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e35c06b98bf36aba164cc17cb25f7e232f5c4aeea73baa14b8a9f0d92dbfa65" +checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e" dependencies = [ "bit-set", - "bitflags 1.3.2", - "byteorder", + "bit-vec", + "bitflags 2.3.3", "lazy_static", "num-traits", "rand 0.8.5", "rand_chacha 0.3.1", "rand_xorshift", - "regex-syntax 0.6.29", + "regex-syntax 0.7.5", "rusty-fork", "tempfile", "unarray", @@ -4093,7 +4097,7 @@ checksum = "9e2e25ee72f5b24d773cae88422baddefff7714f97aab68d96fe2b6fc4a28fb2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -4145,7 +4149,7 @@ checksum = "6df19e284d93757a9fb91d63672f7741b129246a669db09d1c0063071debc0c0" dependencies = [ "bytes", "libc", - "socket2 0.5.4", + "socket2 0.5.5", "tracing", "windows-sys 0.48.0", ] @@ -4284,9 +4288,9 @@ checksum = "655b020bbf5c89791160a30f0d4706d8ec7aa5718d6a198f6df19c400e4f4470" [[package]] name = "rayon" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -4294,14 +4298,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] @@ -4374,14 +4376,14 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.6" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick 1.0.1", "memchr", - "regex-automata 0.3.9", - "regex-syntax 0.7.5", + "regex-automata 0.4.3", + "regex-syntax 0.8.2", ] [[package]] @@ -4392,32 +4394,32 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-automata" -version = "0.3.9" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick 1.0.1", "memchr", - "regex-syntax 0.7.5", + "regex-syntax 0.8.2", ] [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "regex-syntax" -version = "0.7.5" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.20" +version = "0.11.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" dependencies = [ "async-compression", "base64 0.21.4", @@ -4444,6 +4446,7 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", + "system-configuration", "tokio", "tokio-native-tls", "tokio-rustls", @@ -4539,7 +4542,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ - "semver 1.0.19", + "semver 1.0.20", ] [[package]] @@ -4729,9 +4732,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.19" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0" +checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" dependencies = [ "serde", ] @@ -4747,9 +4750,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] @@ -4765,13 +4768,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -4816,7 +4819,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -4837,7 +4840,7 @@ version = "0.9.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574" dependencies = [ - "indexmap 2.0.1", + "indexmap 2.0.2", "itoa", "ryu", "serde", @@ -4850,7 +4853,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e56dd856803e253c8f298af3f4d7eb0ae5e23a737252cd90bb4f3b435033b2d" dependencies = [ - "dashmap 5.2.0", + "dashmap 5.5.3", "futures 0.3.28", "lazy_static", "log", @@ -4866,7 +4869,7 @@ checksum = "91d129178576168c589c9ec973feedf7d3126c01ac2bf08795109aa35b69fb8f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -4931,9 +4934,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if 1.0.0", "cpufeatures", @@ -5038,9 +5041,9 @@ checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" [[package]] name = "smallvec" -version = "1.7.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "smpl_jwt" @@ -5070,9 +5073,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4031e820eb552adee9295814c0ced9e5cf38ddf1e8b7d566d6de8e2538ea989e" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" dependencies = [ "libc", "windows-sys 0.48.0", @@ -5463,7 +5466,7 @@ dependencies = [ "predicates", "regex", "reqwest", - "semver 1.0.19", + "semver 1.0.20", "serial_test", "solana-download-utils", "solana-logger", @@ -5540,7 +5543,7 @@ dependencies = [ "num-traits", "pretty-hex", "reqwest", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_derive", "serde_json", @@ -5602,7 +5605,7 @@ dependencies = [ "humantime", "indicatif", "pretty-hex", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_json", "solana-account-decoder", @@ -5625,7 +5628,7 @@ dependencies = [ "dashmap 4.0.2", "futures 0.3.28", "futures-util", - "indexmap 2.0.1", + "indexmap 2.0.2", "indicatif", "log", "quinn", @@ -5706,7 +5709,7 @@ dependencies = [ "bincode", "crossbeam-channel", "futures-util", - "indexmap 2.0.1", + "indexmap 2.0.2", "indicatif", "log", "rand 0.8.5", @@ -5931,7 +5934,7 @@ dependencies = [ name = "solana-frozen-abi" version = "1.17.4" dependencies = [ - "ahash 0.8.3", + "ahash 0.8.4", "bitflags 2.3.3", "blake3", "block-buffer 0.10.4", @@ -5950,7 +5953,7 @@ dependencies = [ "serde_bytes", "serde_derive", "serde_json", - "sha2 0.10.7", + "sha2 0.10.8", "solana-frozen-abi-macro", "solana-logger", "subtle", @@ -5964,7 +5967,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.0", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -6048,7 +6051,7 @@ dependencies = [ "clap 2.33.3", "crossbeam-channel", "flate2", - "indexmap 2.0.1", + "indexmap 2.0.2", "itertools", "log", "lru", @@ -6107,7 +6110,7 @@ dependencies = [ "nix 0.26.4", "reqwest", "scopeguard", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_yaml 0.8.26", "serde_yaml 0.9.25", @@ -6173,7 +6176,7 @@ dependencies = [ "scopeguard", "serde", "serde_bytes", - "sha2 0.10.7", + "sha2 0.10.8", "solana-account-decoder", "solana-accounts-db", "solana-bpf-loader-program", @@ -6403,7 +6406,7 @@ dependencies = [ "rand 0.8.5", "serde", "serde_derive", - "socket2 0.5.4", + "socket2 0.5.5", "solana-logger", "solana-sdk", "solana-version", @@ -6425,7 +6428,7 @@ dependencies = [ name = "solana-perf" version = "1.17.4" dependencies = [ - "ahash 0.8.3", + "ahash 0.8.4", "assert_matches", "bincode", "bv", @@ -6532,7 +6535,7 @@ dependencies = [ "serde_bytes", "serde_derive", "serde_json", - "sha2 0.10.7", + "sha2 0.10.8", "sha3 0.10.4", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -6612,7 +6615,7 @@ dependencies = [ "futures-util", "log", "reqwest", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_derive", "serde_json", @@ -6676,7 +6679,7 @@ dependencies = [ "num-traits", "parking_lot 0.12.1", "qstring", - "semver 1.0.19", + "semver 1.0.20", "solana-sdk", "thiserror", "uriparse", @@ -6757,7 +6760,7 @@ dependencies = [ "jsonrpc-http-server", "log", "reqwest", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_derive", "serde_json", @@ -6778,7 +6781,7 @@ dependencies = [ "bs58", "jsonrpc-core", "reqwest", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_derive", "serde_json", @@ -6960,7 +6963,7 @@ dependencies = [ "serde_derive", "serde_json", "serde_with", - "sha2 0.10.7", + "sha2 0.10.8", "sha3 0.10.4", "solana-frozen-abi", "solana-frozen-abi-macro", @@ -6983,7 +6986,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -7104,7 +7107,7 @@ dependencies = [ "crossbeam-channel", "futures-util", "histogram", - "indexmap 2.0.1", + "indexmap 2.0.2", "itertools", "libc", "log", @@ -7195,7 +7198,7 @@ dependencies = [ "console", "csv", "ctrlc", - "indexmap 2.0.1", + "indexmap 2.0.2", "indicatif", "pickledb", "serde", @@ -7224,7 +7227,7 @@ dependencies = [ "async-trait", "bincode", "futures-util", - "indexmap 2.0.1", + "indexmap 2.0.2", "indicatif", "log", "rayon", @@ -7417,7 +7420,7 @@ version = "1.17.4" dependencies = [ "log", "rustc_version 0.4.0", - "semver 1.0.19", + "semver 1.0.20", "serde", "serde_derive", "solana-frozen-abi", @@ -7609,7 +7612,7 @@ checksum = "385e31c29981488f2820b2022d8e731aae3b02e6e18e2fd854e4c9a94dc44fc3" dependencies = [ "assert_matches", "borsh 0.10.3", - "num-derive 0.4.0", + "num-derive 0.4.1", "num-traits", "solana-program", "spl-token", @@ -7636,7 +7639,7 @@ checksum = "fadbefec4f3c678215ca72bd71862697bb06b41fd77c0088902dd3203354387b" dependencies = [ "quote", "spl-discriminator-syn", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -7647,8 +7650,8 @@ checksum = "0e5f2044ca42c8938d54d1255ce599c79a1ffd86b677dfab695caa20f9ffc3f2" dependencies = [ "proc-macro2", "quote", - "sha2 0.10.7", - "syn 2.0.37", + "sha2 0.10.8", + "syn 2.0.38", "thiserror", ] @@ -7690,7 +7693,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "249e0318493b6bcf27ae9902600566c689b7dfba9f1bdff5893e92253374e78c" dependencies = [ - "num-derive 0.4.0", + "num-derive 0.4.1", "num-traits", "solana-program", "spl-program-error-derive", @@ -7705,8 +7708,8 @@ checksum = "ab5269c8e868da17b6552ef35a51355a017bd8e0eae269c201fef830d35fa52c" dependencies = [ "proc-macro2", "quote", - "sha2 0.10.7", - "syn 2.0.37", + "sha2 0.10.8", + "syn 2.0.38", ] [[package]] @@ -7746,7 +7749,7 @@ checksum = "e4abf34a65ba420584a0c35f3903f8d727d1f13ababbdc3f714c6b065a686e86" dependencies = [ "arrayref", "bytemuck", - "num-derive 0.4.0", + "num-derive 0.4.1", "num-traits", "num_enum 0.7.0", "solana-program", @@ -7879,9 +7882,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.37" +version = "2.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" +checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" dependencies = [ "proc-macro2", "quote", @@ -7929,6 +7932,27 @@ dependencies = [ "walkdir", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "systemstat" version = "0.2.3" @@ -8036,7 +8060,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -8048,7 +8072,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "test-case-core", ] @@ -8069,22 +8093,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" +checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.49" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" +checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -8223,7 +8247,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] @@ -8714,7 +8738,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-shared", ] @@ -8748,7 +8772,7 @@ checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -8838,19 +8862,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-sys" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df6e476185f92a12c072be4a189a0210dcdcf512a1891d6dff9edb874deadc6" -dependencies = [ - "windows_aarch64_msvc 0.32.0", - "windows_i686_gnu 0.32.0", - "windows_i686_msvc 0.32.0", - "windows_x86_64_gnu 0.32.0", - "windows_x86_64_msvc 0.32.0", -] - [[package]] name = "windows-sys" version = "0.45.0" @@ -8911,12 +8922,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" -[[package]] -name = "windows_aarch64_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8e92753b1c443191654ec532f14c199742964a061be25d77d7a96f09db20bf5" - [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -8929,12 +8934,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" -[[package]] -name = "windows_i686_gnu" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a711c68811799e017b6038e0922cb27a5e2f43a2ddb609fe0b6f3eeda9de615" - [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -8947,12 +8946,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" -[[package]] -name = "windows_i686_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c11bb1a02615db74680b32a68e2d61f553cc24c4eb5b4ca10311740e44172" - [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -8965,12 +8958,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" -[[package]] -name = "windows_x86_64_gnu" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c912b12f7454c6620635bbff3450962753834be2a594819bd5e945af18ec64bc" - [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -8995,12 +8982,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" -[[package]] -name = "windows_x86_64_msvc" -version = "0.32.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "504a2476202769977a040c6364301a3f65d0cc9e3fb08600b2bda150a0488316" - [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -9068,6 +9049,26 @@ dependencies = [ "time", ] +[[package]] +name = "zerocopy" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c19fae0c8a9efc6a8281f2e623db8af1db9e57852e04cde3e754dd2dc29340f" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc56589e9ddd1f1c28d4b4b5c773ce232910a6bb67a70133d61c9e347585efe9" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.38", +] + [[package]] name = "zeroize" version = "1.3.0" @@ -9085,7 +9086,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.37", + "syn 2.0.38", ] [[package]] diff --git a/banking-bench/src/main.rs b/banking-bench/src/main.rs index bb5149f47c85b9..524928aee7c06d 100644 --- a/banking-bench/src/main.rs +++ b/banking-bench/src/main.rs @@ -334,7 +334,7 @@ fn main() { let (replay_vote_sender, _replay_vote_receiver) = unbounded(); let bank0 = Bank::new_for_benches(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0))); + let bank_forks = BankForks::new_rw_arc(bank0); let mut bank = bank_forks.read().unwrap().working_bank(); // set cost tracker limits to MAX so it will not filter out TXs diff --git a/banks-client/src/lib.rs b/banks-client/src/lib.rs index f0c2f17d8c01e7..61105575e2ca2e 100644 --- a/banks-client/src/lib.rs +++ b/banks-client/src/lib.rs @@ -587,7 +587,7 @@ mod tests { let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::new_for_tests_with_slots(slot, slot), )); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bob_pubkey = solana_sdk::pubkey::new_rand(); let mint_pubkey = genesis.mint_keypair.pubkey(); @@ -626,7 +626,7 @@ mod tests { let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::new_for_tests_with_slots(slot, slot), )); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let mint_pubkey = &genesis.mint_keypair.pubkey(); let bob_pubkey = solana_sdk::pubkey::new_rand(); diff --git a/client-test/tests/client.rs b/client-test/tests/client.rs index 65acd1adaae39d..d74361a76d100e 100644 --- a/client-test/tests/client.rs +++ b/client-test/tests/client.rs @@ -132,7 +132,7 @@ fn test_account_subscription() { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -230,7 +230,7 @@ fn test_block_subscription() { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let rent_exempt_amount = bank.get_minimum_balance_for_rent_exemption(0); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); // setup Blockstore let ledger_path = get_tmp_ledger_path!(); @@ -338,7 +338,7 @@ fn test_program_subscription() { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -425,7 +425,7 @@ fn test_root_subscription() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -477,7 +477,7 @@ fn test_slot_subscription() { let exit = Arc::new(AtomicBool::new(false)); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); @@ -553,7 +553,7 @@ async fn test_slot_subscription_async() { let exit = Arc::new(AtomicBool::new(false)); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index 2526c2a6369c5a..b399abba0a9e5b 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -55,7 +55,7 @@ use { }, std::{ iter::repeat_with, - sync::{atomic::Ordering, Arc, RwLock}, + sync::{atomic::Ordering, Arc}, time::{Duration, Instant}, }, test::Bencher, @@ -219,7 +219,7 @@ fn bench_banking(bencher: &mut Bencher, tx_type: TransactionType) { let mut bank = Bank::new_for_benches(&genesis_config); // Allow arbitrary transaction processing time for the purposes of this bench bank.ns_per_slot = u128::MAX; - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); // set cost tracker limits to MAX so it will not filter out TXs diff --git a/core/benches/consensus.rs b/core/benches/consensus.rs index a3dd97755e9bb4..cff71502df977e 100644 --- a/core/benches/consensus.rs +++ b/core/benches/consensus.rs @@ -28,7 +28,10 @@ fn bench_save_tower(bench: &mut Bencher) { let vote_account_pubkey = &Pubkey::default(); let node_keypair = Arc::new(Keypair::new()); - let heaviest_bank = BankForks::new(Bank::default_for_tests()).working_bank(); + let heaviest_bank = BankForks::new_rw_arc(Bank::default_for_tests()) + .read() + .unwrap() + .working_bank(); let tower_storage = FileTowerStorage::new(dir.path().to_path_buf()); let tower = Tower::new( &node_keypair.pubkey(), @@ -47,7 +50,10 @@ fn bench_save_tower(bench: &mut Bencher) { fn bench_generate_ancestors_descendants(bench: &mut Bencher) { let vote_account_pubkey = &Pubkey::default(); let node_keypair = Arc::new(Keypair::new()); - let heaviest_bank = BankForks::new(Bank::default_for_tests()).working_bank(); + let heaviest_bank = BankForks::new_rw_arc(Bank::default_for_tests()) + .read() + .unwrap() + .working_bank(); let mut tower = Tower::new( &node_keypair.pubkey(), vote_account_pubkey, diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index e8b61de94dce2d..ad52db88ac42fc 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -670,7 +670,7 @@ mod tests { fn test_banking_stage_shutdown1() { let genesis_config = create_genesis_config(2).genesis_config; let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); let banking_tracer = BankingTracer::new_disabled(); let (non_vote_sender, non_vote_receiver) = banking_tracer.create_channel_non_vote(); @@ -722,7 +722,7 @@ mod tests { genesis_config.ticks_per_slot = 4; let num_extra_ticks = 2; let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); let start_hash = bank.last_blockhash(); let banking_tracer = BankingTracer::new_disabled(); @@ -802,7 +802,7 @@ mod tests { .. } = create_slow_genesis_config(10); let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); let start_hash = bank.last_blockhash(); let banking_tracer = BankingTracer::new_disabled(); @@ -974,7 +974,7 @@ mod tests { let entry_receiver = { // start a banking_stage to eat verified receiver let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); let blockstore = Arc::new( Blockstore::open(ledger_path.path()) @@ -1155,7 +1155,7 @@ mod tests { .. } = create_slow_genesis_config(10000); let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); let start_hash = bank.last_blockhash(); let banking_tracer = BankingTracer::new_disabled(); diff --git a/core/src/banking_stage/consume_worker.rs b/core/src/banking_stage/consume_worker.rs index 1795db97439a50..d2451efa1c4c66 100644 --- a/core/src/banking_stage/consume_worker.rs +++ b/core/src/banking_stage/consume_worker.rs @@ -174,7 +174,7 @@ mod tests { .. } = create_slow_genesis_config(10_000); let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().working_bank(); let ledger_path = get_tmp_ledger_path_auto_delete!(); diff --git a/core/src/banking_stage/forward_worker.rs b/core/src/banking_stage/forward_worker.rs index cabd891e761c87..c13b8c426378be 100644 --- a/core/src/banking_stage/forward_worker.rs +++ b/core/src/banking_stage/forward_worker.rs @@ -129,7 +129,7 @@ mod tests { .. } = create_slow_genesis_config(10_000); let bank = Bank::new_no_wallclock_throttle_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().working_bank(); let ledger_path = get_tmp_ledger_path_auto_delete!(); diff --git a/core/src/banking_stage/forwarder.rs b/core/src/banking_stage/forwarder.rs index 777ea12d95bc58..1cb656f0ddc701 100644 --- a/core/src/banking_stage/forwarder.rs +++ b/core/src/banking_stage/forwarder.rs @@ -307,7 +307,7 @@ mod tests { let GenesisConfigInfo { genesis_config, .. } = &genesis_config_info; let bank: Bank = Bank::new_no_wallclock_throttle_for_tests(genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().working_bank(); let ledger_path = TempDir::new().unwrap(); diff --git a/core/src/cluster_info_vote_listener.rs b/core/src/cluster_info_vote_listener.rs index 183cabcf04dbce..782f10d976b60e 100644 --- a/core/src/cluster_info_vote_listener.rs +++ b/core/src/cluster_info_vote_listener.rs @@ -1439,7 +1439,7 @@ mod tests { ); let bank = Bank::new_for_tests(&genesis_config); let exit = Arc::new(AtomicBool::new(false)); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); let vote_tracker = VoteTracker::default(); let optimistically_confirmed_bank = @@ -1556,7 +1556,7 @@ mod tests { let bank = Bank::new_for_tests(&genesis_config); let vote_tracker = VoteTracker::default(); let exit = Arc::new(AtomicBool::new(false)); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().get(0).unwrap(); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); @@ -1584,7 +1584,7 @@ mod tests { solana_logger::setup(); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = RwLock::new(BankForks::new(bank)); + let bank_forks = BankForks::new_rw_arc(bank); let votes = vec![]; let (vote_txs, packets) = ClusterInfoVoteListener::verify_votes(votes, &bank_forks); assert!(vote_txs.is_empty()); @@ -1629,7 +1629,7 @@ mod tests { vec![100; voting_keypairs.len()], // stakes ); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = RwLock::new(BankForks::new(bank)); + let bank_forks = BankForks::new_rw_arc(bank); let vote_tx = test_vote_tx(voting_keypairs.first(), hash); let votes = vec![vote_tx]; let (vote_txs, packets) = ClusterInfoVoteListener::verify_votes(votes, &bank_forks); @@ -1654,7 +1654,7 @@ mod tests { vec![100; voting_keypairs.len()], // stakes ); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = RwLock::new(BankForks::new(bank)); + let bank_forks = BankForks::new_rw_arc(bank); let vote_tx = test_vote_tx(voting_keypairs.first(), hash); let mut bad_vote = vote_tx.clone(); bad_vote.signatures[0] = Signature::default(); diff --git a/core/src/commitment_service.rs b/core/src/commitment_service.rs index bdadb1ff72f54f..b15c6d2fec5fe0 100644 --- a/core/src/commitment_service.rs +++ b/core/src/commitment_service.rs @@ -509,7 +509,8 @@ mod tests { ); let bank0 = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank0); + let bank_forks = BankForks::new_rw_arc(bank0); + let mut bank_forks = bank_forks.write().unwrap(); // Fill bank_forks with banks with votes landing in the next slot // Create enough banks such that vote account will root slots 0 and 1 diff --git a/core/src/consensus/heaviest_subtree_fork_choice.rs b/core/src/consensus/heaviest_subtree_fork_choice.rs index 639272e1048b17..4b58ee78b99da7 100644 --- a/core/src/consensus/heaviest_subtree_fork_choice.rs +++ b/core/src/consensus/heaviest_subtree_fork_choice.rs @@ -244,7 +244,8 @@ impl HeaviestSubtreeForkChoice { heaviest_subtree_fork_choice } - pub fn new_from_bank_forks(bank_forks: &BankForks) -> Self { + pub fn new_from_bank_forks(bank_forks: Arc>) -> Self { + let bank_forks = bank_forks.read().unwrap(); let mut frozen_banks: Vec<_> = bank_forks.frozen_banks().values().cloned().collect(); frozen_banks.sort_by_key(|bank| bank.slot()); diff --git a/core/src/repair/ancestor_hashes_service.rs b/core/src/repair/ancestor_hashes_service.rs index 3214c89e14ea15..fc70dbab16c825 100644 --- a/core/src/repair/ancestor_hashes_service.rs +++ b/core/src/repair/ancestor_hashes_service.rs @@ -1928,7 +1928,7 @@ mod test { #[test] fn test_verify_and_process_ancestor_responses_invalid_packet() { let bank0 = Bank::default_for_tests(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0))); + let bank_forks = BankForks::new_rw_arc(bank0); let ManageAncestorHashesState { ancestor_hashes_request_statuses, diff --git a/core/src/repair/quic_endpoint.rs b/core/src/repair/quic_endpoint.rs index 7d1cd29a32589f..031de37f94b5a0 100644 --- a/core/src/repair/quic_endpoint.rs +++ b/core/src/repair/quic_endpoint.rs @@ -736,7 +736,7 @@ mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(/*mint_lamports:*/ 100_000); let bank = Bank::new_for_tests(&genesis_config); - Arc::new(RwLock::new(BankForks::new(bank))) + BankForks::new_rw_arc(bank) }; let (endpoints, senders, tasks): (Vec<_>, Vec<_>, Vec<_>) = multiunzip( keypairs diff --git a/core/src/repair/repair_service.rs b/core/src/repair/repair_service.rs index c7cfab03f8f8ed..ad8bc413b68362 100644 --- a/core/src/repair/repair_service.rs +++ b/core/src/repair/repair_service.rs @@ -1202,7 +1202,7 @@ mod test { pub fn test_generate_and_send_duplicate_repairs() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let blockstore_path = get_tmp_ledger_path!(); let blockstore = Blockstore::open(&blockstore_path).unwrap(); let cluster_slots = ClusterSlots::default(); @@ -1301,7 +1301,7 @@ mod test { pub fn test_update_duplicate_slot_repair_addr() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let dummy_addr = Some(( Pubkey::default(), UdpSocket::bind("0.0.0.0:0").unwrap().local_addr().unwrap(), diff --git a/core/src/repair/serve_repair.rs b/core/src/repair/serve_repair.rs index 8ab42c28829f1d..fb9256be7eb91e 100644 --- a/core/src/repair/serve_repair.rs +++ b/core/src/repair/serve_repair.rs @@ -1561,7 +1561,7 @@ mod tests { fn test_serialize_deserialize_signed_request() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let cluster_info = Arc::new(new_test_cluster_info()); let serve_repair = ServeRepair::new( cluster_info.clone(), @@ -1611,7 +1611,7 @@ mod tests { let mut bank = Bank::new_for_tests(&genesis_config); bank.feature_set = Arc::new(FeatureSet::all_enabled()); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let serve_repair = ServeRepair::new( cluster_info, bank_forks, @@ -1647,7 +1647,7 @@ mod tests { fn test_map_requests_signed() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let cluster_info = Arc::new(new_test_cluster_info()); let serve_repair = ServeRepair::new( cluster_info.clone(), @@ -1976,7 +1976,7 @@ mod tests { fn window_index_request() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let cluster_slots = ClusterSlots::default(); let cluster_info = Arc::new(new_test_cluster_info()); let serve_repair = ServeRepair::new( @@ -2318,7 +2318,7 @@ mod tests { fn test_repair_with_repair_validators() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let cluster_slots = ClusterSlots::default(); let cluster_info = Arc::new(new_test_cluster_info()); let me = cluster_info.my_contact_info(); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index f27f3e3d00f959..19edf8b18d0f54 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -4360,7 +4360,7 @@ pub(crate) mod tests { fn test_handle_new_root() { let genesis_config = create_genesis_config(10_000).genesis_config; let bank0 = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0))); + let bank_forks = BankForks::new_rw_arc(bank0); let root = 3; let root_bank = Bank::new_from_parent( @@ -4446,7 +4446,7 @@ pub(crate) mod tests { fn test_handle_new_root_ahead_of_highest_super_majority_root() { let genesis_config = create_genesis_config(10_000).genesis_config; let bank0 = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0))); + let bank_forks = BankForks::new_rw_arc(bank0); let confirmed_root = 1; let fork = 2; let bank1 = Bank::new_from_parent( @@ -4849,7 +4849,7 @@ pub(crate) mod tests { } bank0.freeze(); let arc_bank0 = Arc::new(bank0); - let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks(&[arc_bank0], 0))); + let bank_forks = BankForks::new_from_banks(&[arc_bank0], 0); let exit = Arc::new(AtomicBool::new(false)); let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default())); @@ -5028,7 +5028,7 @@ pub(crate) mod tests { vote_simulator::initialize_state(&keypairs, 10_000); let mut latest_validator_votes_for_frozen_banks = LatestValidatorVotesForFrozenBanks::default(); - let bank0 = bank_forks.get(0).unwrap(); + let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let my_keypairs = keypairs.get(&my_node_pubkey).unwrap(); let vote_tx = vote_transaction::new_vote_transaction( vec![0], @@ -5040,7 +5040,6 @@ pub(crate) mod tests { None, ); - let bank_forks = RwLock::new(bank_forks); let bank1 = Bank::new_from_parent(bank0.clone(), &my_node_pubkey, 1); bank1.process_transaction(&vote_tx).unwrap(); bank1.freeze(); @@ -5373,7 +5372,7 @@ pub(crate) mod tests { ) { let stake = 10_000; let (bank_forks, _, _) = vote_simulator::initialize_state(all_keypairs, stake); - let root_bank = bank_forks.root_bank(); + let root_bank = bank_forks.read().unwrap().root_bank(); let mut propagated_stats = PropagatedStats { total_epoch_stake: stake * all_keypairs.len() as u64, ..PropagatedStats::default() @@ -5487,8 +5486,9 @@ pub(crate) mod tests { let vote_pubkey = vote_keypairs.vote_keypair.pubkey(); let keypairs: HashMap<_, _> = vec![(node_pubkey, vote_keypairs)].into_iter().collect(); let stake = 10_000; - let (mut bank_forks, mut progress_map, _) = + let (bank_forks_arc, mut progress_map, _) = vote_simulator::initialize_state(&keypairs, stake); + let mut bank_forks = bank_forks_arc.write().unwrap(); let bank0 = bank_forks.get(0).unwrap(); bank_forks.insert(Bank::new_from_parent(bank0.clone(), &Pubkey::default(), 9)); @@ -5530,12 +5530,14 @@ pub(crate) mod tests { // runs in `update_propagation_status` assert!(!progress_map.get_leader_propagation_slot_must_exist(10).0); + drop(bank_forks); + let vote_tracker = VoteTracker::default(); vote_tracker.insert_vote(10, vote_pubkey); ReplayStage::update_propagation_status( &mut progress_map, 10, - &RwLock::new(bank_forks), + &bank_forks_arc, &vote_tracker, &ClusterSlots::default(), ); @@ -5579,8 +5581,9 @@ pub(crate) mod tests { .collect(); let stake_per_validator = 10_000; - let (mut bank_forks, mut progress_map, _) = + let (bank_forks_arc, mut progress_map, _) = vote_simulator::initialize_state(&keypairs, stake_per_validator); + let mut bank_forks = bank_forks_arc.write().unwrap(); progress_map .get_propagated_stats_mut(0) .unwrap() @@ -5621,12 +5624,14 @@ pub(crate) mod tests { vote_tracker.insert_vote(10, *vote_pubkey); } + drop(bank_forks); + // The last bank should reach propagation threshold, and propagate it all // the way back through earlier leader banks ReplayStage::update_propagation_status( &mut progress_map, 10, - &RwLock::new(bank_forks), + &bank_forks_arc, &vote_tracker, &ClusterSlots::default(), ); @@ -5659,8 +5664,9 @@ pub(crate) mod tests { .collect(); let stake_per_validator = 10_000; - let (mut bank_forks, mut progress_map, _) = + let (bank_forks_arc, mut progress_map, _) = vote_simulator::initialize_state(&keypairs, stake_per_validator); + let mut bank_forks = bank_forks_arc.write().unwrap(); progress_map .get_propagated_stats_mut(0) .unwrap() @@ -5706,12 +5712,13 @@ pub(crate) mod tests { // Insert a new vote vote_tracker.insert_vote(10, vote_pubkeys[2]); + drop(bank_forks); // The last bank should reach propagation threshold, and propagate it all // the way back through earlier leader banks ReplayStage::update_propagation_status( &mut progress_map, 10, - &RwLock::new(bank_forks), + &bank_forks_arc, &vote_tracker, &ClusterSlots::default(), ); @@ -5817,7 +5824,8 @@ pub(crate) mod tests { let bank0 = Bank::new_for_tests(&genesis_config::create_genesis_config(10000).0); let parent_slot_bank = Bank::new_from_parent(Arc::new(bank0), &Pubkey::default(), parent_slot); - let mut bank_forks = BankForks::new(parent_slot_bank); + let bank_forks = BankForks::new_rw_arc(parent_slot_bank); + let mut bank_forks = bank_forks.write().unwrap(); let bank5 = Bank::new_from_parent(bank_forks.get(parent_slot).unwrap(), &Pubkey::default(), 5); bank_forks.insert(bank5); @@ -6367,7 +6375,7 @@ pub(crate) mod tests { &vote_tracker, &ClusterSlots::default(), &bank_forks, - &mut HeaviestSubtreeForkChoice::new_from_bank_forks(&bank_forks.read().unwrap()), + &mut HeaviestSubtreeForkChoice::new_from_bank_forks(bank_forks.clone()), &mut LatestValidatorVotesForFrozenBanks::default(), ); @@ -8133,7 +8141,7 @@ pub(crate) mod tests { let in_vote_only_mode = AtomicBool::new(false); let genesis_config = create_genesis_config(10_000).genesis_config; let bank0 = Bank::new_for_tests(&genesis_config); - let bank_forks = RwLock::new(BankForks::new(bank0)); + let bank_forks = BankForks::new_rw_arc(bank0); ReplayStage::check_for_vote_only_mode(1000, 0, &in_vote_only_mode, &bank_forks); assert!(in_vote_only_mode.load(Ordering::Relaxed)); ReplayStage::check_for_vote_only_mode(10, 0, &in_vote_only_mode, &bank_forks); diff --git a/core/src/tvu.rs b/core/src/tvu.rs index 0b8358863fbceb..0fa619033ae3db 100644 --- a/core/src/tvu.rs +++ b/core/src/tvu.rs @@ -401,7 +401,7 @@ pub mod tests { let starting_balance = 10_000; let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(starting_balance); - let bank_forks = BankForks::new(Bank::new_for_tests(&genesis_config)); + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config)); let keypair = Arc::new(Keypair::new()); let (turbine_quic_endpoint_sender, _turbine_quic_endpoint_receiver) = @@ -423,7 +423,7 @@ pub mod tests { } = Blockstore::open_with_signal(&blockstore_path, BlockstoreOptions::default()) .expect("Expected to successfully open ledger"); let blockstore = Arc::new(blockstore); - let bank = bank_forks.working_bank(); + let bank = bank_forks.read().unwrap().working_bank(); let (exit, poh_recorder, poh_service, _entry_receiver) = create_test_recorder(bank.clone(), blockstore.clone(), None, None); let vote_keypair = Keypair::new(); @@ -435,7 +435,6 @@ pub mod tests { let (replay_vote_sender, _replay_vote_receiver) = unbounded(); let (completed_data_sets_sender, _completed_data_sets_receiver) = unbounded(); let (_, gossip_confirmed_slots_receiver) = unbounded(); - let bank_forks = Arc::new(RwLock::new(bank_forks)); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let ignored_prioritization_fee_cache = Arc::new(PrioritizationFeeCache::new(0u64)); diff --git a/core/src/validator.rs b/core/src/validator.rs index 5eca0ccaad28ef..fac592aedb8620 100644 --- a/core/src/validator.rs +++ b/core/src/validator.rs @@ -2584,7 +2584,7 @@ mod tests { ); let (genesis_config, _mint_keypair) = create_genesis_config(1); - let bank_forks = RwLock::new(BankForks::new(Bank::new_for_tests(&genesis_config))); + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config)); let mut config = ValidatorConfig::default_for_test(); let rpc_override_health_check = Arc::new(AtomicBool::new(false)); let start_progress = Arc::new(RwLock::new(ValidatorStartProgress::default())); @@ -2614,11 +2614,11 @@ mod tests { ); // bank=1, wait=0, should pass, bank is past the wait slot - let bank_forks = RwLock::new(BankForks::new(Bank::new_from_parent( + let bank_forks = BankForks::new_rw_arc(Bank::new_from_parent( bank_forks.read().unwrap().root_bank(), &Pubkey::default(), 1, - ))); + )); config.wait_for_supermajority = Some(0); assert!(!wait_for_supermajority( &config, diff --git a/core/src/vote_simulator.rs b/core/src/vote_simulator.rs index 79c418bcc7892f..77cf818f620ed0 100644 --- a/core/src/vote_simulator.rs +++ b/core/src/vote_simulator.rs @@ -57,7 +57,7 @@ impl VoteSimulator { validator_keypairs, node_pubkeys, vote_pubkeys, - bank_forks: Arc::new(RwLock::new(bank_forks)), + bank_forks, progress, heaviest_subtree_fork_choice, latest_validator_votes_for_frozen_banks: LatestValidatorVotesForFrozenBanks::default(), @@ -296,13 +296,14 @@ impl VoteSimulator { false } + #[allow(clippy::type_complexity)] fn init_state( num_keypairs: usize, ) -> ( HashMap, Vec, Vec, - BankForks, + Arc>, ProgressMap, HeaviestSubtreeForkChoice, ) { @@ -338,7 +339,11 @@ impl VoteSimulator { pub fn initialize_state( validator_keypairs_map: &HashMap, stake: u64, -) -> (BankForks, ProgressMap, HeaviestSubtreeForkChoice) { +) -> ( + Arc>, + ProgressMap, + HeaviestSubtreeForkChoice, +) { let validator_keypairs: Vec<_> = validator_keypairs_map.values().collect(); let GenesisConfigInfo { mut genesis_config, @@ -366,7 +371,8 @@ pub fn initialize_state( 0, ForkProgress::new_from_bank(&bank0, bank0.collector_id(), &Pubkey::default(), None, 0, 0), ); - let bank_forks = BankForks::new(bank0); - let heaviest_subtree_fork_choice = HeaviestSubtreeForkChoice::new_from_bank_forks(&bank_forks); + let bank_forks = BankForks::new_rw_arc(bank0); + let heaviest_subtree_fork_choice = + HeaviestSubtreeForkChoice::new_from_bank_forks(bank_forks.clone()); (bank_forks, progress, heaviest_subtree_fork_choice) } diff --git a/core/tests/epoch_accounts_hash.rs b/core/tests/epoch_accounts_hash.rs index 8fa6919e99db1f..5cc507b1551946 100755 --- a/core/tests/epoch_accounts_hash.rs +++ b/core/tests/epoch_accounts_hash.rs @@ -116,13 +116,18 @@ impl TestEnvironment { ..snapshot_config }; - let mut bank_forks = BankForks::new(Bank::new_for_tests_with_config( + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests_with_config( &genesis_config_info.genesis_config, BankTestConfig::default(), )); - bank_forks.set_snapshot_config(Some(snapshot_config.clone())); - bank_forks.set_accounts_hash_interval_slots(Self::ACCOUNTS_HASH_INTERVAL); - let bank_forks = Arc::new(RwLock::new(bank_forks)); + bank_forks + .write() + .unwrap() + .set_snapshot_config(Some(snapshot_config.clone())); + bank_forks + .write() + .unwrap() + .set_accounts_hash_interval_slots(Self::ACCOUNTS_HASH_INTERVAL); let exit = Arc::new(AtomicBool::new(false)); let node_id = Arc::new(Keypair::new()); @@ -264,7 +269,7 @@ fn test_epoch_accounts_hash_basic(test_environment: TestEnvironment) { const NUM_EPOCHS_TO_TEST: u64 = 2; const SET_ROOT_INTERVAL: Slot = 3; - let bank_forks = &test_environment.bank_forks; + let bank_forks = test_environment.bank_forks.clone(); let mut expected_epoch_accounts_hash = None; @@ -299,6 +304,7 @@ fn test_epoch_accounts_hash_basic(test_environment: TestEnvironment) { // Set roots so that ABS requests are sent (this is what requests EAH calculations) if bank.slot().checked_rem(SET_ROOT_INTERVAL).unwrap() == 0 { trace!("rooting bank {}", bank.slot()); + bank_forks.read().unwrap().prune_program_cache(bank.slot()); bank_forks.write().unwrap().set_root( bank.slot(), &test_environment @@ -379,7 +385,7 @@ fn test_snapshots_have_expected_epoch_accounts_hash() { let test_environment = TestEnvironment::new_with_snapshots(FULL_SNAPSHOT_INTERVAL, FULL_SNAPSHOT_INTERVAL); - let bank_forks = &test_environment.bank_forks; + let bank_forks = test_environment.bank_forks.clone(); let slots_per_epoch = test_environment .genesis_config_info @@ -411,6 +417,7 @@ fn test_snapshots_have_expected_epoch_accounts_hash() { // Root every bank. This is what a normal validator does as well. // `set_root()` is also what requests snapshots and EAH calculations. + bank_forks.read().unwrap().prune_program_cache(bank.slot()); bank_forks.write().unwrap().set_root( bank.slot(), &test_environment @@ -496,7 +503,7 @@ fn test_background_services_request_handling_for_epoch_accounts_hash() { let test_environment = TestEnvironment::new_with_snapshots(FULL_SNAPSHOT_INTERVAL, FULL_SNAPSHOT_INTERVAL); - let bank_forks = &test_environment.bank_forks; + let bank_forks = test_environment.bank_forks.clone(); let snapshot_config = &test_environment.snapshot_config; let slots_per_epoch = test_environment @@ -534,6 +541,7 @@ fn test_background_services_request_handling_for_epoch_accounts_hash() { if bank.block_height() == set_root_slot { info!("Calling set_root() on bank {}...", bank.slot()); + bank_forks.read().unwrap().prune_program_cache(bank.slot()); bank_forks.write().unwrap().set_root( bank.slot(), &test_environment @@ -577,7 +585,7 @@ fn test_epoch_accounts_hash_and_warping() { solana_logger::setup(); let test_environment = TestEnvironment::new(); - let bank_forks = &test_environment.bank_forks; + let bank_forks = test_environment.bank_forks.clone(); let bank = bank_forks.read().unwrap().working_bank(); let epoch_schedule = test_environment .genesis_config_info @@ -590,6 +598,7 @@ fn test_epoch_accounts_hash_and_warping() { let eah_stop_slot_in_next_epoch = epoch_schedule.get_first_slot_in_epoch(bank.epoch() + 1) + eah_stop_offset; // have to set root here so that we can flush the write cache + bank_forks.read().unwrap().prune_program_cache(bank.slot()); bank_forks.write().unwrap().set_root( bank.slot(), &test_environment diff --git a/core/tests/snapshots.rs b/core/tests/snapshots.rs index 674c039bee2353..e7156f435eea25 100644 --- a/core/tests/snapshots.rs +++ b/core/tests/snapshots.rs @@ -66,7 +66,7 @@ use { }; struct SnapshotTestConfig { - bank_forks: BankForks, + bank_forks: Arc>, genesis_config_info: GenesisConfigInfo, snapshot_config: SnapshotConfig, incremental_snapshot_archives_dir: TempDir, @@ -109,7 +109,8 @@ impl SnapshotTestConfig { ); bank0.freeze(); bank0.set_startup_verification_complete(); - let mut bank_forks = BankForks::new(bank0); + let bank_forks_arc = BankForks::new_rw_arc(bank0); + let mut bank_forks = bank_forks_arc.write().unwrap(); bank_forks.accounts_hash_interval_slots = accounts_hash_interval_slots; let snapshot_config = SnapshotConfig { @@ -125,7 +126,7 @@ impl SnapshotTestConfig { }; bank_forks.set_snapshot_config(Some(snapshot_config.clone())); SnapshotTestConfig { - bank_forks, + bank_forks: bank_forks_arc.clone(), genesis_config_info, snapshot_config, incremental_snapshot_archives_dir, @@ -138,11 +139,12 @@ impl SnapshotTestConfig { } fn restore_from_snapshot( - old_bank_forks: &BankForks, + old_bank_forks: Arc>, old_last_slot: Slot, old_genesis_config: &GenesisConfig, account_paths: &[PathBuf], ) { + let old_bank_forks = old_bank_forks.read().unwrap(); let snapshot_config = old_bank_forks.snapshot_config.as_ref().unwrap(); let old_last_bank = old_bank_forks.get(old_last_slot).unwrap(); @@ -198,7 +200,7 @@ fn run_bank_forks_snapshot_n( { solana_logger::setup(); // Set up snapshotting config - let mut snapshot_test_config = SnapshotTestConfig::new( + let snapshot_test_config = SnapshotTestConfig::new( snapshot_version, cluster_type, set_root_interval, @@ -206,7 +208,7 @@ fn run_bank_forks_snapshot_n( DISABLED_SNAPSHOT_ARCHIVE_INTERVAL, ); - let bank_forks = &mut snapshot_test_config.bank_forks; + let bank_forks = snapshot_test_config.bank_forks.clone(); let mint_keypair = &snapshot_test_config.genesis_config_info.mint_keypair; let (accounts_package_sender, _accounts_package_receiver) = crossbeam_channel::unbounded(); @@ -219,16 +221,22 @@ fn run_bank_forks_snapshot_n( accounts_package_sender, }; for slot in 1..=last_slot { + let mut bank_forks_w = bank_forks.write().unwrap(); let mut bank = - Bank::new_from_parent(bank_forks[slot - 1].clone(), &Pubkey::default(), slot); + Bank::new_from_parent(bank_forks_w[slot - 1].clone(), &Pubkey::default(), slot); f(&mut bank, mint_keypair); - let bank = bank_forks.insert(bank); + let bank = bank_forks_w.insert(bank); + drop(bank_forks_w); // Set root to make sure we don't end up with too many account storage entries // and to allow snapshotting of bank and the purging logic on status_cache to // kick in if slot % set_root_interval == 0 || slot == last_slot { // set_root should send a snapshot request - bank_forks.set_root(bank.slot(), &request_sender, None); + bank_forks.read().unwrap().prune_program_cache(bank.slot()); + bank_forks + .write() + .unwrap() + .set_root(bank.slot(), &request_sender, None); snapshot_request_handler.handle_snapshot_requests( false, 0, @@ -239,7 +247,7 @@ fn run_bank_forks_snapshot_n( } // Generate a snapshot package for last bank - let last_bank = bank_forks.get(last_slot).unwrap(); + let last_bank = bank_forks.read().unwrap().get(last_slot).unwrap(); let snapshot_config = &snapshot_test_config.snapshot_config; let bank_snapshots_dir = &snapshot_config.bank_snapshots_dir; let last_bank_snapshot_info = snapshot_utils::get_highest_bank_snapshot_pre(bank_snapshots_dir) @@ -278,7 +286,12 @@ fn run_bank_forks_snapshot_n( let (_tmp_dir, temporary_accounts_dir) = create_tmp_accounts_dir_for_tests(); let account_paths = &[temporary_accounts_dir]; let genesis_config = &snapshot_test_config.genesis_config_info.genesis_config; - restore_from_snapshot(bank_forks, last_slot, genesis_config, account_paths); + restore_from_snapshot( + snapshot_test_config.bank_forks.clone(), + last_slot, + genesis_config, + account_paths, + ); } #[test_case(V1_2_0, Development)] @@ -331,7 +344,7 @@ fn test_concurrent_snapshot_packaging( const MAX_BANK_SNAPSHOTS_TO_RETAIN: usize = 8; // Set up snapshotting config - let mut snapshot_test_config = SnapshotTestConfig::new( + let snapshot_test_config = SnapshotTestConfig::new( snapshot_version, cluster_type, 1, @@ -339,7 +352,7 @@ fn test_concurrent_snapshot_packaging( DISABLED_SNAPSHOT_ARCHIVE_INTERVAL, ); - let bank_forks = &mut snapshot_test_config.bank_forks; + let mut bank_forks = snapshot_test_config.bank_forks.write().unwrap(); let snapshot_config = &snapshot_test_config.snapshot_config; let bank_snapshots_dir = &snapshot_config.bank_snapshots_dir; let full_snapshot_archives_dir = &snapshot_config.full_snapshot_archives_dir; @@ -586,24 +599,31 @@ fn test_slots_to_snapshot(snapshot_version: SnapshotVersion, cluster_type: Clust for add_root_interval in &[1, 3, 9] { let (snapshot_sender, _snapshot_receiver) = unbounded(); // Make sure this test never clears bank.slots_since_snapshot - let mut snapshot_test_config = SnapshotTestConfig::new( + let snapshot_test_config = SnapshotTestConfig::new( snapshot_version, cluster_type, (*add_root_interval * num_set_roots * 2) as Slot, (*add_root_interval * num_set_roots * 2) as Slot, DISABLED_SNAPSHOT_ARCHIVE_INTERVAL, ); - let mut current_bank = snapshot_test_config.bank_forks[0].clone(); + let bank_forks = snapshot_test_config.bank_forks.clone(); + let bank_forks_r = bank_forks.read().unwrap(); + let mut current_bank = bank_forks_r[0].clone(); + drop(bank_forks_r); let request_sender = AbsRequestSender::new(snapshot_sender); for _ in 0..num_set_roots { for _ in 0..*add_root_interval { let new_slot = current_bank.slot() + 1; let new_bank = Bank::new_from_parent(current_bank, &Pubkey::default(), new_slot); - snapshot_test_config.bank_forks.insert(new_bank); - current_bank = snapshot_test_config.bank_forks[new_slot].clone(); + current_bank = bank_forks.write().unwrap().insert(new_bank).clone(); } - snapshot_test_config - .bank_forks + bank_forks + .read() + .unwrap() + .prune_program_cache(current_bank.slot()); + bank_forks + .write() + .unwrap() .set_root(current_bank.slot(), &request_sender, None); // Since the accounts background services are not runnning, EpochAccountsHash @@ -629,10 +649,10 @@ fn test_slots_to_snapshot(snapshot_version: SnapshotVersion, cluster_type: Clust let expected_slots_to_snapshot = num_old_slots as u64..=num_set_roots as u64 * *add_root_interval as u64; - let slots_to_snapshot = snapshot_test_config - .bank_forks - .get(snapshot_test_config.bank_forks.root()) + let slots_to_snapshot = bank_forks + .read() .unwrap() + .root_bank() .status_cache .read() .unwrap() @@ -704,7 +724,7 @@ fn test_bank_forks_incremental_snapshot( info!("Running bank forks incremental snapshot test, full snapshot interval: {} slots, incremental snapshot interval: {} slots, last slot: {}, set root interval: {} slots", FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS, INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS, LAST_SLOT, SET_ROOT_INTERVAL); - let mut snapshot_test_config = SnapshotTestConfig::new( + let snapshot_test_config = SnapshotTestConfig::new( snapshot_version, cluster_type, SET_ROOT_INTERVAL, @@ -714,7 +734,7 @@ fn test_bank_forks_incremental_snapshot( trace!("SnapshotTestConfig:\naccounts_dir: {}\nbank_snapshots_dir: {}\nfull_snapshot_archives_dir: {}\nincremental_snapshot_archives_dir: {}", snapshot_test_config.accounts_dir.display(), snapshot_test_config.bank_snapshots_dir.path().display(), snapshot_test_config.full_snapshot_archives_dir.path().display(), snapshot_test_config.incremental_snapshot_archives_dir.path().display()); - let bank_forks = &mut snapshot_test_config.bank_forks; + let bank_forks = snapshot_test_config.bank_forks.clone(); let mint_keypair = &snapshot_test_config.genesis_config_info.mint_keypair; let (accounts_package_sender, _accounts_package_receiver) = crossbeam_channel::unbounded(); @@ -731,8 +751,8 @@ fn test_bank_forks_incremental_snapshot( for slot in 1..=LAST_SLOT { // Make a new bank and perform some transactions let bank = { - let bank = - Bank::new_from_parent(bank_forks[slot - 1].clone(), &Pubkey::default(), slot); + let parent = bank_forks.read().unwrap().get(slot - 1).unwrap(); + let bank = Bank::new_from_parent(parent, &Pubkey::default(), slot); let key = solana_sdk::pubkey::new_rand(); let tx = system_transaction::transfer(mint_keypair, &key, 1, bank.last_blockhash()); @@ -746,7 +766,7 @@ fn test_bank_forks_incremental_snapshot( bank.register_tick(&Hash::new_unique()); } - bank_forks.insert(bank) + bank_forks.write().unwrap().insert(bank) }; // Set root to make sure we don't end up with too many account storage entries @@ -754,7 +774,11 @@ fn test_bank_forks_incremental_snapshot( // kick in if slot % SET_ROOT_INTERVAL == 0 { // set_root sends a snapshot request - bank_forks.set_root(bank.slot(), &request_sender, None); + bank_forks.read().unwrap().prune_program_cache(bank.slot()); + bank_forks + .write() + .unwrap() + .set_root(bank.slot(), &request_sender, None); snapshot_request_handler.handle_snapshot_requests( false, 0, @@ -964,7 +988,7 @@ fn test_snapshots_with_background_services( let (accounts_package_sender, accounts_package_receiver) = unbounded(); let (snapshot_package_sender, snapshot_package_receiver) = unbounded(); - let bank_forks = Arc::new(RwLock::new(snapshot_test_config.bank_forks)); + let bank_forks = snapshot_test_config.bank_forks.clone(); bank_forks .read() .unwrap() diff --git a/gossip/src/duplicate_shred_handler.rs b/gossip/src/duplicate_shred_handler.rs index 366eef0913a463..ba95178bc88441 100644 --- a/gossip/src/duplicate_shred_handler.rs +++ b/gossip/src/duplicate_shred_handler.rs @@ -271,15 +271,12 @@ mod tests { let my_pubkey = my_keypair.pubkey(); let genesis_config_info = create_genesis_config_with_leader(10_000, &my_pubkey, 10_000); let GenesisConfigInfo { genesis_config, .. } = genesis_config_info; - let bank_forks = BankForks::new(Bank::new_for_tests(&genesis_config)); + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config)); let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank( - &bank_forks.working_bank(), + &bank_forks.read().unwrap().working_bank(), )); - let mut duplicate_shred_handler = DuplicateShredHandler::new( - blockstore.clone(), - leader_schedule_cache, - Arc::new(RwLock::new(bank_forks)), - ); + let mut duplicate_shred_handler = + DuplicateShredHandler::new(blockstore.clone(), leader_schedule_cache, bank_forks); let chunks = create_duplicate_proof( my_keypair.clone(), None, @@ -340,13 +337,12 @@ mod tests { let my_pubkey = my_keypair.pubkey(); let genesis_config_info = create_genesis_config_with_leader(10_000, &my_pubkey, 10_000); let GenesisConfigInfo { genesis_config, .. } = genesis_config_info; - let bank_forks = BankForks::new(Bank::new_for_tests(&genesis_config)); + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config)); let leader_schedule_cache = Arc::new(LeaderScheduleCache::new_from_bank( - &bank_forks.working_bank(), + &bank_forks.read().unwrap().working_bank(), )); - let bank_forks_ptr = Arc::new(RwLock::new(bank_forks)); let mut duplicate_shred_handler = - DuplicateShredHandler::new(blockstore.clone(), leader_schedule_cache, bank_forks_ptr); + DuplicateShredHandler::new(blockstore.clone(), leader_schedule_cache, bank_forks); let start_slot: Slot = 1; // This proof will not be accepted because num_chunks is too large. diff --git a/gossip/tests/gossip.rs b/gossip/tests/gossip.rs index d9abeec31b5569..569f7c480dfa1e 100644 --- a/gossip/tests/gossip.rs +++ b/gossip/tests/gossip.rs @@ -309,7 +309,7 @@ pub fn cluster_info_scale() { vec![100; vote_keypairs.len()], ); let bank0 = Bank::new_for_tests(&genesis_config_info.genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0))); + let bank_forks = BankForks::new_rw_arc(bank0); let nodes: Vec<_> = vote_keypairs .into_iter() diff --git a/ledger/src/bank_forks_utils.rs b/ledger/src/bank_forks_utils.rs index 8552a59033326f..c75380581fc16d 100644 --- a/ledger/src/bank_forks_utils.rs +++ b/ledger/src/bank_forks_utils.rs @@ -189,15 +189,6 @@ pub fn load_bank_forks( (bank_forks, None) }; - bank_forks - .read() - .expect("Failed to read lock the bank forks") - .root_bank() - .loaded_programs_cache - .write() - .expect("Failed to write lock the program cache") - .set_fork_graph(bank_forks.clone()); - let mut leader_schedule_cache = LeaderScheduleCache::new_from_bank(&bank_forks.read().unwrap().root_bank()); if process_options.full_leader_cache { @@ -367,8 +358,5 @@ fn bank_forks_from_snapshot( incremental: incremental_snapshot_hash, }; - ( - Arc::new(RwLock::new(BankForks::new(bank))), - starting_snapshot_hashes, - ) + (BankForks::new_rw_arc(bank), starting_snapshot_hashes) } diff --git a/ledger/src/blockstore_processor.rs b/ledger/src/blockstore_processor.rs index 647666806c91f1..ff30c87b7e27d2 100644 --- a/ledger/src/blockstore_processor.rs +++ b/ledger/src/blockstore_processor.rs @@ -715,7 +715,7 @@ pub(crate) fn process_blockstore_for_bank_0( accounts_update_notifier, exit, ); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank0))); + let bank_forks = BankForks::new_rw_arc(bank0); info!("Processing ledger for slot 0..."); process_bank_0( @@ -3559,8 +3559,8 @@ pub mod tests { blockstore.set_roots([3, 5].iter()).unwrap(); // Set up bank1 - let mut bank_forks = BankForks::new(Bank::new_for_tests(&genesis_config)); - let bank0 = bank_forks.get(0).unwrap(); + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config)); + let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let opts = ProcessOptions { run_verification: true, accounts_db_test_hash_calculation: true, @@ -3569,7 +3569,11 @@ pub mod tests { let recyclers = VerifyRecyclers::default(); process_bank_0(&bank0, &blockstore, &opts, &recyclers, None, None); let bank0_last_blockhash = bank0.last_blockhash(); - let bank1 = bank_forks.insert(Bank::new_from_parent(bank0, &Pubkey::default(), 1)); + let bank1 = + bank_forks + .write() + .unwrap() + .insert(Bank::new_from_parent(bank0, &Pubkey::default(), 1)); confirm_full_slot( &blockstore, &bank1, @@ -3582,7 +3586,7 @@ pub mod tests { &mut ExecuteTimings::default(), ) .unwrap(); - bank_forks.set_root( + bank_forks.write().unwrap().set_root( 1, &solana_runtime::accounts_background_service::AbsRequestSender::default(), None, @@ -3591,7 +3595,6 @@ pub mod tests { let leader_schedule_cache = LeaderScheduleCache::new_from_bank(&bank1); // Test process_blockstore_from_root() from slot 1 onwards - let bank_forks = RwLock::new(bank_forks); process_blockstore_from_root( &blockstore, &bank_forks, diff --git a/program-runtime/src/loaded_programs.rs b/program-runtime/src/loaded_programs.rs index 8b2b165136bf42..a65593491b10d3 100644 --- a/program-runtime/src/loaded_programs.rs +++ b/program-runtime/src/loaded_programs.rs @@ -456,7 +456,7 @@ pub struct LoadedPrograms { /// Environments of the current epoch pub environments: ProgramRuntimeEnvironments, pub stats: Stats, - fork_graph: Option>>, + pub fork_graph: Option>>, } impl Default for LoadedPrograms { diff --git a/program-test/src/lib.rs b/program-test/src/lib.rs index 1f8d7d18c013d8..c3252d05e40caa 100644 --- a/program-test/src/lib.rs +++ b/program-test/src/lib.rs @@ -847,7 +847,7 @@ impl ProgramTest { }; let slot = bank.slot(); let last_blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let block_commitment_cache = Arc::new(RwLock::new( BlockCommitmentCache::new_for_tests_with_slots(slot, slot), )); diff --git a/rpc/src/optimistically_confirmed_bank_tracker.rs b/rpc/src/optimistically_confirmed_bank_tracker.rs index 0cd37fb8a3f3ce..6a9e0e2a8a5ea7 100644 --- a/rpc/src/optimistically_confirmed_bank_tracker.rs +++ b/rpc/src/optimistically_confirmed_bank_tracker.rs @@ -424,7 +424,7 @@ mod tests { let exit = Arc::new(AtomicBool::new(false)); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 709c186889995e..2d55d2bb2f2c02 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -346,10 +346,7 @@ impl JsonRpcRequestProcessor { connection_cache: Arc, ) -> Self { let genesis_hash = bank.hash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new_from_banks( - &[bank.clone()], - bank.slot(), - ))); + let bank_forks = BankForks::new_from_banks(&[bank.clone()], bank.slot()); let blockstore = Arc::new(Blockstore::open(&get_tmp_ledger_path!()).unwrap()); let exit = Arc::new(AtomicBool::new(false)); let cluster_info = Arc::new({ @@ -6627,7 +6624,7 @@ pub mod tests { let bank = Bank::new_for_tests_with_config(&genesis_config, config); ( - Arc::new(RwLock::new(BankForks::new(bank))), + BankForks::new_rw_arc(bank), mint_keypair, Arc::new(voting_keypair), ) @@ -8310,7 +8307,7 @@ pub mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); diff --git a/rpc/src/rpc_health.rs b/rpc/src/rpc_health.rs index 8a6347cc7a6bd0..aff4fa48f03633 100644 --- a/rpc/src/rpc_health.rs +++ b/rpc/src/rpc_health.rs @@ -150,7 +150,7 @@ pub mod tests { let blockstore = Arc::new(Blockstore::open(ledger_path.path()).unwrap()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let bank0 = bank_forks.read().unwrap().root_bank(); diff --git a/rpc/src/rpc_pubsub.rs b/rpc/src/rpc_pubsub.rs index e45a5f8af68517..6bb6fd7854642c 100644 --- a/rpc/src/rpc_pubsub.rs +++ b/rpc/src/rpc_pubsub.rs @@ -684,7 +684,7 @@ mod tests { let bob_pubkey = bob.pubkey(); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let rpc_subscriptions = Arc::new(RpcSubscriptions::new_for_tests( @@ -813,7 +813,7 @@ mod tests { let bob_pubkey = solana_sdk::pubkey::new_rand(); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let mut io = IoHandler::<()>::default(); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); @@ -871,7 +871,7 @@ mod tests { let stake_program_id = stake::program::id(); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -999,7 +999,7 @@ mod tests { let nonce_account = Keypair::new(); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -1088,9 +1088,7 @@ mod tests { let bob_pubkey = solana_sdk::pubkey::new_rand(); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); - let bank_forks = Arc::new(RwLock::new(BankForks::new(Bank::new_for_tests( - &genesis_config, - )))); + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config)); let mut io = IoHandler::<()>::default(); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); @@ -1138,7 +1136,7 @@ mod tests { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bob = Keypair::new(); let exit = Arc::new(AtomicBool::new(false)); @@ -1190,7 +1188,7 @@ mod tests { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -1272,7 +1270,7 @@ mod tests { fn test_slot_subscribe() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let rpc_subscriptions = Arc::new(RpcSubscriptions::default_with_bank_forks( @@ -1305,7 +1303,7 @@ mod tests { fn test_slot_unsubscribe() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let rpc_subscriptions = Arc::new(RpcSubscriptions::default_with_bank_forks( @@ -1348,7 +1346,7 @@ mod tests { ); let exit = Arc::new(AtomicBool::new(false)); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); // Setup Subscriptions let optimistically_confirmed_bank = @@ -1390,7 +1388,7 @@ mod tests { fn test_vote_unsubscribe() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let rpc_subscriptions = Arc::new(RpcSubscriptions::default_with_bank_forks( @@ -1409,7 +1407,7 @@ mod tests { fn test_get_version() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let rpc_subscriptions = Arc::new(RpcSubscriptions::default_with_bank_forks( diff --git a/rpc/src/rpc_pubsub_service.rs b/rpc/src/rpc_pubsub_service.rs index 99eab0a2353670..85b753815ab003 100644 --- a/rpc/src/rpc_pubsub_service.rs +++ b/rpc/src/rpc_pubsub_service.rs @@ -485,7 +485,7 @@ mod tests { let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let subscriptions = Arc::new(RpcSubscriptions::new_for_tests( diff --git a/rpc/src/rpc_service.rs b/rpc/src/rpc_service.rs index 2011578b70d3d8..9aac1f929bc29b 100644 --- a/rpc/src/rpc_service.rs +++ b/rpc/src/rpc_service.rs @@ -617,7 +617,7 @@ mod tests { ip_addr, solana_net_utils::find_available_port_in_range(ip_addr, (10000, 65535)).unwrap(), ); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let ledger_path = get_tmp_ledger_path!(); let blockstore = Arc::new(Blockstore::open(&ledger_path).unwrap()); let block_commitment_cache = Arc::new(RwLock::new(BlockCommitmentCache::default())); @@ -674,7 +674,7 @@ mod tests { } = create_genesis_config(10_000); genesis_config.cluster_type = ClusterType::MainnetBeta; let bank = Bank::new_for_tests(&genesis_config); - Arc::new(RwLock::new(BankForks::new(bank))) + BankForks::new_rw_arc(bank) } #[test] diff --git a/rpc/src/rpc_subscription_tracker.rs b/rpc/src/rpc_subscription_tracker.rs index 41a2f3506cb67c..97ceb576636465 100644 --- a/rpc/src/rpc_subscription_tracker.rs +++ b/rpc/src/rpc_subscription_tracker.rs @@ -700,7 +700,7 @@ mod tests { fn subscription_info() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let mut tracker = SubscriptionsTracker::new(bank_forks); tracker.subscribe(SubscriptionParams::Slot, 0.into(), || 0); @@ -746,7 +746,7 @@ mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let mut tracker = SubscriptionsTracker::new(bank_forks); tracker.subscribe(SubscriptionParams::Slot, 0.into(), || 0); diff --git a/rpc/src/rpc_subscriptions.rs b/rpc/src/rpc_subscriptions.rs index 6fca7d45035837..4b01e078f78a76 100644 --- a/rpc/src/rpc_subscriptions.rs +++ b/rpc/src/rpc_subscriptions.rs @@ -1324,7 +1324,7 @@ pub(crate) mod tests { } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -1470,7 +1470,7 @@ pub(crate) mod tests { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let rent_exempt_amount = bank.get_minimum_balance_for_rent_exemption(0); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let ledger_path = get_tmp_ledger_path!(); @@ -1590,7 +1590,7 @@ pub(crate) mod tests { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let rent_exempt_amount = bank.get_minimum_balance_for_rent_exemption(0); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let ledger_path = get_tmp_ledger_path!(); @@ -1708,7 +1708,7 @@ pub(crate) mod tests { } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); let rent_exempt_amount = bank.get_minimum_balance_for_rent_exemption(0); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let ledger_path = get_tmp_ledger_path!(); @@ -1826,7 +1826,7 @@ pub(crate) mod tests { } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let alice = Keypair::new(); let tx = system_transaction::create_account( &mint_keypair, @@ -1938,7 +1938,7 @@ pub(crate) mod tests { bank.lazy_rent_collection.store(true, Relaxed); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); @@ -2133,7 +2133,7 @@ pub(crate) mod tests { bank.lazy_rent_collection.store(true, Relaxed); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); @@ -2249,7 +2249,7 @@ pub(crate) mod tests { bank.lazy_rent_collection.store(true, Relaxed); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0, &Pubkey::default(), 1); @@ -2435,7 +2435,8 @@ pub(crate) mod tests { } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let mut bank_forks = BankForks::new(bank); + let bank_forks_arc = BankForks::new_rw_arc(bank); + let mut bank_forks = bank_forks_arc.write().unwrap(); let alice = Keypair::new(); let past_bank_tx = @@ -2465,8 +2466,6 @@ pub(crate) mod tests { .unwrap(); let bank1 = bank_forks[1].clone(); - let bank_forks = Arc::new(RwLock::new(bank_forks)); - let mut cache0 = BlockCommitment::default(); cache0.increase_confirmation_stake(1, 10); let cache1 = BlockCommitment::default(); @@ -2483,16 +2482,19 @@ pub(crate) mod tests { }, ); + // Drop the write locked bank_forks + drop(bank_forks); + let exit = Arc::new(AtomicBool::new(false)); let optimistically_confirmed_bank = - OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); + OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks_arc); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); let subscriptions = Arc::new(RpcSubscriptions::new_for_tests( exit, max_complete_transaction_status_slot, max_complete_rewards_slot, - bank_forks, + bank_forks_arc, Arc::new(RwLock::new(block_commitment_cache)), optimistically_confirmed_bank, )); @@ -2659,7 +2661,7 @@ pub(crate) mod tests { let exit = Arc::new(AtomicBool::new(false)); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); @@ -2706,7 +2708,7 @@ pub(crate) mod tests { let exit = Arc::new(AtomicBool::new(false)); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let optimistically_confirmed_bank = OptimisticallyConfirmedBank::locked_from_bank_forks_root(&bank_forks); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); @@ -2755,7 +2757,7 @@ pub(crate) mod tests { } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().get(0).unwrap(); let bank1 = Bank::new_from_parent(bank0.clone(), &Pubkey::default(), 1); bank_forks.write().unwrap().insert(bank1); @@ -2969,7 +2971,7 @@ pub(crate) mod tests { } = create_genesis_config(100); let bank = Bank::new_for_tests(&genesis_config); let blockhash = bank.last_blockhash(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let alice = Keypair::new(); @@ -3053,7 +3055,7 @@ pub(crate) mod tests { let bank = Bank::new_for_tests(&genesis_config); let max_complete_transaction_status_slot = Arc::new(AtomicU64::default()); let max_complete_rewards_slot = Arc::new(AtomicU64::default()); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let subscriptions = Arc::new(RpcSubscriptions::default_with_bank_forks( max_complete_transaction_status_slot, max_complete_rewards_slot, diff --git a/runtime/benches/prioritization_fee_cache.rs b/runtime/benches/prioritization_fee_cache.rs index 95efc8cefd29ea..506aac4fb729a3 100644 --- a/runtime/benches/prioritization_fee_cache.rs +++ b/runtime/benches/prioritization_fee_cache.rs @@ -100,8 +100,8 @@ fn bench_process_transactions_multiple_slots(bencher: &mut Bencher) { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank0 = Bank::new_for_benches(&genesis_config); - let bank_forks = BankForks::new(bank0); - let bank = bank_forks.working_bank(); + let bank_forks = BankForks::new_rw_arc(bank0); + let bank = bank_forks.read().unwrap().working_bank(); let collector = solana_sdk::pubkey::new_rand(); let banks = (1..=NUM_SLOTS) .map(|n| Arc::new(Bank::new_from_parent(bank.clone(), &collector, n as u64))) diff --git a/runtime/src/bank/tests.rs b/runtime/src/bank/tests.rs index df776061ce6ed5..10acc085916228 100644 --- a/runtime/src/bank/tests.rs +++ b/runtime/src/bank/tests.rs @@ -12505,8 +12505,8 @@ fn test_runtime_feature_enable_with_program_cache() { genesis_config .accounts .remove(&feature_set::reject_callx_r10::id()); - let mut bank_forks = BankForks::new(Bank::new_for_tests(&genesis_config)); - let root_bank = bank_forks.root_bank(); + let bank_forks = BankForks::new_rw_arc(Bank::new_for_tests(&genesis_config)); + let root_bank = bank_forks.read().unwrap().root_bank(); // Test a basic transfer let amount = genesis_config.rent.minimum_balance(0); @@ -12565,9 +12565,16 @@ fn test_runtime_feature_enable_with_program_cache() { // Reroot to call LoadedPrograms::prune() and end the current recompilation phase goto_end_of_slot(&bank); - bank_forks.insert(Arc::into_inner(bank).unwrap()); - let bank = bank_forks.working_bank(); - bank_forks.set_root(bank.slot, &AbsRequestSender::default(), None); + bank_forks + .write() + .unwrap() + .insert(Arc::into_inner(bank).unwrap()); + let bank = bank_forks.read().unwrap().working_bank(); + bank_forks.read().unwrap().prune_program_cache(bank.slot); + bank_forks + .write() + .unwrap() + .set_root(bank.slot, &AbsRequestSender::default(), None); // Advance to next epoch, which starts the next recompilation phase let bank = new_from_parent_next_epoch(bank, 1); diff --git a/runtime/src/bank_forks.rs b/runtime/src/bank_forks.rs index 8ed5dd084efd68..631afb536c0756 100644 --- a/runtime/src/bank_forks.rs +++ b/runtime/src/bank_forks.rs @@ -15,7 +15,7 @@ use { ops::Index, sync::{ atomic::{AtomicBool, AtomicU64, Ordering}, - Arc, + Arc, RwLock, }, time::Instant, }, @@ -77,7 +77,7 @@ impl Index for BankForks { } impl BankForks { - pub fn new(bank: Bank) -> Self { + pub fn new_rw_arc(bank: Bank) -> Arc> { let root = bank.slot(); Self::new_from_banks(&[Arc::new(bank)], root) } @@ -154,7 +154,7 @@ impl BankForks { self[self.root()].clone() } - pub fn new_from_banks(initial_forks: &[Arc], root: Slot) -> Self { + pub fn new_from_banks(initial_forks: &[Arc], root: Slot) -> Arc> { let mut banks = HashMap::new(); // Iterate through the heads of all the different forks @@ -175,7 +175,7 @@ impl BankForks { descendants.entry(parent).or_default().insert(*slot); } } - Self { + let bank_forks = Arc::new(RwLock::new(Self { root: Arc::new(AtomicSlot::new(root)), banks, descendants, @@ -184,7 +184,16 @@ impl BankForks { last_accounts_hash_slot: root, in_vote_only_mode: Arc::new(AtomicBool::new(false)), highest_slot_at_startup: 0, + })); + + for bank in bank_forks.read().unwrap().banks.values() { + bank.loaded_programs_cache + .write() + .unwrap() + .set_fork_graph(bank_forks.clone()); } + + bank_forks } pub fn insert(&mut self, mut bank: Bank) -> Arc { @@ -696,7 +705,8 @@ mod tests { fn test_bank_forks_new() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); + let mut bank_forks = bank_forks.write().unwrap(); let child_bank = Bank::new_from_parent(bank_forks[0].clone(), &Pubkey::default(), 1); child_bank.register_tick(&Hash::default()); bank_forks.insert(child_bank); @@ -711,19 +721,20 @@ mod tests { let child_bank = Arc::new(Bank::new_from_parent(bank.clone(), &Pubkey::default(), 1)); let bank_forks = BankForks::new_from_banks(&[bank.clone(), child_bank.clone()], 0); - assert_eq!(bank_forks.root(), 0); - assert_eq!(bank_forks.working_bank().slot(), 1); + assert_eq!(bank_forks.read().unwrap().root(), 0); + assert_eq!(bank_forks.read().unwrap().working_bank().slot(), 1); let bank_forks = BankForks::new_from_banks(&[child_bank, bank], 0); - assert_eq!(bank_forks.root(), 0); - assert_eq!(bank_forks.working_bank().slot(), 1); + assert_eq!(bank_forks.read().unwrap().root(), 0); + assert_eq!(bank_forks.read().unwrap().working_bank().slot(), 1); } #[test] fn test_bank_forks_descendants() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); + let mut bank_forks = bank_forks.write().unwrap(); let bank0 = bank_forks[0].clone(); let bank = Bank::new_from_parent(bank0.clone(), &Pubkey::default(), 1); bank_forks.insert(bank); @@ -740,7 +751,8 @@ mod tests { fn test_bank_forks_ancestors() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); + let mut bank_forks = bank_forks.write().unwrap(); let bank0 = bank_forks[0].clone(); let bank = Bank::new_from_parent(bank0.clone(), &Pubkey::default(), 1); bank_forks.insert(bank); @@ -758,7 +770,8 @@ mod tests { fn test_bank_forks_frozen_banks() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); + let mut bank_forks = bank_forks.write().unwrap(); let bank0 = bank_forks[0].clone(); let child_bank = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.insert(child_bank); @@ -770,7 +783,8 @@ mod tests { fn test_bank_forks_active_banks() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); + let mut bank_forks = bank_forks.write().unwrap(); let bank0 = bank_forks[0].clone(); let child_bank = Bank::new_from_parent(bank0, &Pubkey::default(), 1); bank_forks.insert(child_bank); @@ -822,11 +836,13 @@ mod tests { }; let bank0 = Bank::new_for_tests(&genesis_config); - let mut bank_forks0 = BankForks::new(bank0); + let bank_forks0 = BankForks::new_rw_arc(bank0); + let mut bank_forks0 = bank_forks0.write().unwrap(); bank_forks0.set_root(0, &abs_request_sender, None); let bank1 = Bank::new_for_tests(&genesis_config); - let mut bank_forks1 = BankForks::new(bank1); + let bank_forks1 = BankForks::new_rw_arc(bank1); + let mut bank_forks1 = bank_forks1.write().unwrap(); let additional_timestamp_secs = 2; @@ -882,10 +898,11 @@ mod tests { .collect() } - fn extend_bank_forks(bank_forks: &mut BankForks, parent_child_pairs: &[(Slot, Slot)]) { + fn extend_bank_forks(bank_forks: Arc>, parent_child_pairs: &[(Slot, Slot)]) { for (parent, child) in parent_child_pairs.iter() { - bank_forks.insert(Bank::new_from_parent( - bank_forks[*parent].clone(), + let parent: Arc = bank_forks.read().unwrap().banks[parent].clone(); + bank_forks.write().unwrap().insert(Bank::new_from_parent( + parent, &Pubkey::default(), *child, )); @@ -896,13 +913,13 @@ mod tests { fn test_bank_forks_with_set_root() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); let parent_child_pairs = vec![(0, 1), (1, 2), (0, 3), (3, 4)]; - extend_bank_forks(&mut bank_forks, &parent_child_pairs); + extend_bank_forks(bank_forks.clone(), &parent_child_pairs); assert_eq!( - bank_forks.ancestors(), + bank_forks.read().unwrap().ancestors(), make_hash_map(vec![ (0, vec![]), (1, vec![0]), @@ -912,7 +929,7 @@ mod tests { ]) ); assert_eq!( - bank_forks.descendants(), + bank_forks.read().unwrap().descendants(), make_hash_map(vec![ (0, vec![1, 2, 3, 4]), (1, vec![2]), @@ -921,26 +938,29 @@ mod tests { (4, vec![]), ]) ); - bank_forks.set_root( + bank_forks.write().unwrap().set_root( 2, &AbsRequestSender::default(), None, // highest confirmed root ); - bank_forks[2].squash(); - assert_eq!(bank_forks.ancestors(), make_hash_map(vec![(2, vec![]),])); + bank_forks.read().unwrap().get(2).unwrap().squash(); assert_eq!( - bank_forks.descendants(), + bank_forks.read().unwrap().ancestors(), + make_hash_map(vec![(2, vec![]),]) + ); + assert_eq!( + bank_forks.read().unwrap().descendants(), make_hash_map(vec![(0, vec![2]), (1, vec![2]), (2, vec![]),]) ); let parent_child_pairs = vec![(2, 5), (5, 6)]; - extend_bank_forks(&mut bank_forks, &parent_child_pairs); + extend_bank_forks(bank_forks.clone(), &parent_child_pairs); assert_eq!( - bank_forks.ancestors(), + bank_forks.read().unwrap().ancestors(), make_hash_map(vec![(2, vec![]), (5, vec![2]), (6, vec![2, 5])]) ); assert_eq!( - bank_forks.descendants(), + bank_forks.read().unwrap().descendants(), make_hash_map(vec![ (0, vec![2]), (1, vec![2]), @@ -956,13 +976,13 @@ mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); assert_eq!(bank.slot(), 0); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); let parent_child_pairs = vec![(0, 1), (1, 2), (0, 3), (3, 4)]; - extend_bank_forks(&mut bank_forks, &parent_child_pairs); + extend_bank_forks(bank_forks.clone(), &parent_child_pairs); assert_eq!( - bank_forks.ancestors(), + bank_forks.read().unwrap().ancestors(), make_hash_map(vec![ (0, vec![]), (1, vec![0]), @@ -972,7 +992,7 @@ mod tests { ]) ); assert_eq!( - bank_forks.descendants(), + bank_forks.read().unwrap().descendants(), make_hash_map(vec![ (0, vec![1, 2, 3, 4]), (1, vec![2]), @@ -981,25 +1001,25 @@ mod tests { (4, vec![]), ]) ); - bank_forks.set_root( + bank_forks.write().unwrap().set_root( 2, &AbsRequestSender::default(), Some(1), // highest confirmed root ); - bank_forks[2].squash(); + bank_forks.read().unwrap().get(2).unwrap().squash(); assert_eq!( - bank_forks.ancestors(), + bank_forks.read().unwrap().ancestors(), make_hash_map(vec![(1, vec![]), (2, vec![]),]) ); assert_eq!( - bank_forks.descendants(), + bank_forks.read().unwrap().descendants(), make_hash_map(vec![(0, vec![1, 2]), (1, vec![2]), (2, vec![]),]) ); let parent_child_pairs = vec![(2, 5), (5, 6)]; - extend_bank_forks(&mut bank_forks, &parent_child_pairs); + extend_bank_forks(bank_forks.clone(), &parent_child_pairs); assert_eq!( - bank_forks.ancestors(), + bank_forks.read().unwrap().ancestors(), make_hash_map(vec![ (1, vec![]), (2, vec![]), @@ -1008,7 +1028,7 @@ mod tests { ]) ); assert_eq!( - bank_forks.descendants(), + bank_forks.read().unwrap().descendants(), make_hash_map(vec![ (0, vec![1, 2]), (1, vec![2]), @@ -1023,7 +1043,7 @@ mod tests { fn test_fork_graph() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let mut bank_forks = BankForks::new(bank); + let bank_forks = BankForks::new_rw_arc(bank); let parent_child_pairs = vec![ (0, 1), @@ -1036,7 +1056,7 @@ mod tests { (4, 6), (6, 12), ]; - extend_bank_forks(&mut bank_forks, &parent_child_pairs); + extend_bank_forks(bank_forks.clone(), &parent_child_pairs); // Fork graph created for the test // 0 @@ -1048,7 +1068,7 @@ mod tests { // 8 5 6 // | | // 10 12 - + let mut bank_forks = bank_forks.write().unwrap(); assert_matches!(bank_forks.relationship(0, 3), BlockRelation::Ancestor); assert_matches!(bank_forks.relationship(0, 10), BlockRelation::Ancestor); assert_matches!(bank_forks.relationship(0, 12), BlockRelation::Ancestor); diff --git a/runtime/src/prioritization_fee_cache.rs b/runtime/src/prioritization_fee_cache.rs index 5f8e3d9220d459..c41d5a72bd397f 100644 --- a/runtime/src/prioritization_fee_cache.rs +++ b/runtime/src/prioritization_fee_cache.rs @@ -612,8 +612,8 @@ mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank0 = Bank::new_for_benches(&genesis_config); - let bank_forks = BankForks::new(bank0); - let bank = bank_forks.working_bank(); + let bank_forks = BankForks::new_rw_arc(bank0); + let bank = bank_forks.read().unwrap().working_bank(); let collector = solana_sdk::pubkey::new_rand(); let bank1 = Arc::new(Bank::new_from_parent(bank.clone(), &collector, 1)); let bank2 = Arc::new(Bank::new_from_parent(bank.clone(), &collector, 2)); @@ -864,8 +864,8 @@ mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank0 = Bank::new_for_benches(&genesis_config); - let bank_forks = BankForks::new(bank0); - let bank = bank_forks.working_bank(); + let bank_forks = BankForks::new_rw_arc(bank0); + let bank = bank_forks.read().unwrap().working_bank(); let collector = solana_sdk::pubkey::new_rand(); let slot: Slot = 999; let bank1 = Arc::new(Bank::new_from_parent(bank.clone(), &collector, slot)); diff --git a/runtime/src/root_bank_cache.rs b/runtime/src/root_bank_cache.rs index 8a9ff1b8b50fe2..09a8f2690c44ce 100644 --- a/runtime/src/root_bank_cache.rs +++ b/runtime/src/root_bank_cache.rs @@ -60,7 +60,7 @@ mod tests { fn test_root_bank_cache() { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let mut root_bank_cache = RootBankCache::new(bank_forks.clone()); diff --git a/send-transaction-service/src/send_transaction_service.rs b/send-transaction-service/src/send_transaction_service.rs index 137160844da6c7..27aa1bea400ac4 100644 --- a/send-transaction-service/src/send_transaction_service.rs +++ b/send-transaction-service/src/send_transaction_service.rs @@ -826,7 +826,7 @@ mod test { fn service_exit() { let tpu_address = "127.0.0.1:0".parse().unwrap(); let bank = Bank::default_for_tests(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let (sender, receiver) = unbounded(); let connection_cache = Arc::new(ConnectionCache::new("connection_cache_test")); @@ -849,7 +849,7 @@ mod test { fn validator_exit() { let tpu_address = "127.0.0.1:0".parse().unwrap(); let bank = Bank::default_for_tests(); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let (sender, receiver) = bounded(0); let dummy_tx_info = || TransactionInfo { @@ -893,7 +893,7 @@ mod test { let (genesis_config, mint_keypair) = create_genesis_config(4); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let tpu_address = "127.0.0.1:0".parse().unwrap(); let config = Config { leader_forward_count: 1, @@ -1159,7 +1159,7 @@ mod test { let (genesis_config, mint_keypair) = create_genesis_config(4); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let tpu_address = "127.0.0.1:0".parse().unwrap(); let config = Config { leader_forward_count: 1, diff --git a/turbine/benches/cluster_info.rs b/turbine/benches/cluster_info.rs index 954e32903c3e2f..1f15137175acdb 100644 --- a/turbine/benches/cluster_info.rs +++ b/turbine/benches/cluster_info.rs @@ -25,12 +25,7 @@ use { }, cluster_nodes::ClusterNodesCache, }, - std::{ - collections::HashMap, - net::UdpSocket, - sync::{Arc, RwLock}, - time::Duration, - }, + std::{collections::HashMap, net::UdpSocket, sync::Arc, time::Duration}, test::Bencher, }; @@ -49,7 +44,7 @@ fn broadcast_shreds_bench(bencher: &mut Bencher) { let socket = UdpSocket::bind("0.0.0.0:0").unwrap(); let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_benches(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); const NUM_SHREDS: usize = 32; let shred = Shred::new_from_data(0, 0, 0, &[], ShredFlags::empty(), 0, 0, 0); diff --git a/turbine/benches/retransmit_stage.rs b/turbine/benches/retransmit_stage.rs index b0dd67db8225ec..bfd68239feedab 100644 --- a/turbine/benches/retransmit_stage.rs +++ b/turbine/benches/retransmit_stage.rs @@ -32,7 +32,7 @@ use { net::{Ipv4Addr, UdpSocket}, sync::{ atomic::{AtomicUsize, Ordering}, - Arc, RwLock, + Arc, }, thread::{sleep, Builder}, time::Duration, @@ -74,9 +74,8 @@ fn bench_retransmitter(bencher: &mut Bencher) { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(100_000); let bank0 = Bank::new_for_benches(&genesis_config); - let bank_forks = BankForks::new(bank0); - let bank = bank_forks.working_bank(); - let bank_forks = Arc::new(RwLock::new(bank_forks)); + let bank_forks = BankForks::new_rw_arc(bank0); + let bank = bank_forks.read().unwrap().working_bank(); let (shreds_sender, shreds_receiver) = unbounded(); const NUM_THREADS: usize = 2; let sockets = (0..NUM_THREADS) diff --git a/turbine/src/broadcast_stage.rs b/turbine/src/broadcast_stage.rs index 07be0d0bfd6daa..cccda977b1637a 100644 --- a/turbine/src/broadcast_stage.rs +++ b/turbine/src/broadcast_stage.rs @@ -668,7 +668,7 @@ pub mod test { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(10_000); let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank = bank_forks.read().unwrap().root_bank(); // Start up the broadcast stage diff --git a/turbine/src/broadcast_stage/standard_broadcast_run.rs b/turbine/src/broadcast_stage/standard_broadcast_run.rs index 031e72012340e7..37850d6ba9998a 100644 --- a/turbine/src/broadcast_stage/standard_broadcast_run.rs +++ b/turbine/src/broadcast_stage/standard_broadcast_run.rs @@ -544,7 +544,7 @@ mod test { genesis_config.ticks_per_slot = max_ticks_per_n_shreds(num_shreds_per_slot, None) + 1; let bank = Bank::new_for_tests(&genesis_config); - let bank_forks = Arc::new(RwLock::new(BankForks::new(bank))); + let bank_forks = BankForks::new_rw_arc(bank); let bank0 = bank_forks.read().unwrap().root_bank(); ( blockstore, diff --git a/turbine/src/quic_endpoint.rs b/turbine/src/quic_endpoint.rs index 0f362fd1a34c69..e9789357c015d6 100644 --- a/turbine/src/quic_endpoint.rs +++ b/turbine/src/quic_endpoint.rs @@ -598,7 +598,7 @@ mod tests { let GenesisConfigInfo { genesis_config, .. } = create_genesis_config(/*mint_lamports:*/ 100_000); let bank = Bank::new_for_tests(&genesis_config); - Arc::new(RwLock::new(BankForks::new(bank))) + BankForks::new_rw_arc(bank) }; let (endpoints, senders, tasks): (Vec<_>, Vec<_>, Vec<_>) = multiunzip(keypairs.iter().zip(sockets).zip(senders).map( diff --git a/turbine/src/sigverify_shreds.rs b/turbine/src/sigverify_shreds.rs index 35e4977de850c5..76088a8115a837 100644 --- a/turbine/src/sigverify_shreds.rs +++ b/turbine/src/sigverify_shreds.rs @@ -284,7 +284,7 @@ mod tests { &create_genesis_config_with_leader(100, &leader_pubkey, 10).genesis_config, ); let leader_schedule_cache = LeaderScheduleCache::new_from_bank(&bank); - let bank_forks = RwLock::new(BankForks::new(bank)); + let bank_forks = BankForks::new_rw_arc(bank); let batch_size = 2; let mut batch = PacketBatch::with_capacity(batch_size); batch.resize(batch_size, Packet::default()); diff --git a/validator/src/admin_rpc_service.rs b/validator/src/admin_rpc_service.rs index e10ab05ea01577..69584822097c45 100644 --- a/validator/src/admin_rpc_service.rs +++ b/validator/src/admin_rpc_service.rs @@ -917,10 +917,7 @@ mod tests { } = create_genesis_config(1_000_000_000); let bank = Bank::new_for_tests_with_config(&genesis_config, config); - ( - Arc::new(RwLock::new(BankForks::new(bank))), - Arc::new(voting_keypair), - ) + (BankForks::new_rw_arc(bank), Arc::new(voting_keypair)) } #[test]