35
35
accounts_db:: { AccountShrinkThreshold , AccountsDbConfig } ,
36
36
accounts_index:: AccountSecondaryIndexes ,
37
37
accounts_update_notifier_interface:: AccountsUpdateNotifier ,
38
- hardened_unpack:: { open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE } ,
38
+ hardened_unpack:: {
39
+ open_genesis_config, OpenGenesisConfigError , MAX_GENESIS_ARCHIVE_UNPACKED_SIZE ,
40
+ } ,
39
41
utils:: { move_and_async_delete_path, move_and_async_delete_path_contents} ,
40
42
} ,
41
43
solana_client:: connection_cache:: { ConnectionCache , Protocol } ,
@@ -591,9 +593,7 @@ impl Validator {
591
593
"ledger directory does not exist or is not accessible: {ledger_path:?}"
592
594
) ) ;
593
595
}
594
- let genesis_config =
595
- open_genesis_config ( ledger_path, config. max_genesis_archive_unpacked_size )
596
- . context ( "Failed to open genesis config" ) ?;
596
+ let genesis_config = load_genesis ( config, ledger_path) ?;
597
597
598
598
metrics_config_sanity_check ( genesis_config. cluster_type ) ?;
599
599
@@ -703,7 +703,6 @@ impl Validator {
703
703
PohTimingReportService :: new ( poh_timing_point_receiver, exit. clone ( ) ) ;
704
704
705
705
let (
706
- genesis_config,
707
706
bank_forks,
708
707
blockstore,
709
708
original_blockstore_root,
@@ -727,6 +726,7 @@ impl Validator {
727
726
) = load_blockstore (
728
727
config,
729
728
ledger_path,
729
+ & genesis_config,
730
730
exit. clone ( ) ,
731
731
& start_progress,
732
732
accounts_update_notifier,
@@ -1809,10 +1809,44 @@ fn blockstore_options_from_config(config: &ValidatorConfig) -> BlockstoreOptions
1809
1809
}
1810
1810
}
1811
1811
1812
+ fn load_genesis (
1813
+ config : & ValidatorConfig ,
1814
+ ledger_path : & Path ,
1815
+ ) -> Result < GenesisConfig , ValidatorError > {
1816
+ let genesis_config = open_genesis_config ( ledger_path, config. max_genesis_archive_unpacked_size )
1817
+ . map_err ( ValidatorError :: OpenGenesisConfig ) ?;
1818
+
1819
+ // This needs to be limited otherwise the state in the VoteAccount data
1820
+ // grows too large
1821
+ let leader_schedule_slot_offset = genesis_config. epoch_schedule . leader_schedule_slot_offset ;
1822
+ let slots_per_epoch = genesis_config. epoch_schedule . slots_per_epoch ;
1823
+ let leader_epoch_offset = ( leader_schedule_slot_offset + slots_per_epoch - 1 ) / slots_per_epoch;
1824
+ assert ! ( leader_epoch_offset <= MAX_LEADER_SCHEDULE_EPOCH_OFFSET ) ;
1825
+
1826
+ let genesis_hash = genesis_config. hash ( ) ;
1827
+ info ! ( "genesis hash: {}" , genesis_hash) ;
1828
+
1829
+ if let Some ( expected_genesis_hash) = config. expected_genesis_hash {
1830
+ if genesis_hash != expected_genesis_hash {
1831
+ return Err ( ValidatorError :: GenesisHashMismatch (
1832
+ genesis_hash,
1833
+ expected_genesis_hash,
1834
+ ) ) ;
1835
+ }
1836
+ }
1837
+
1838
+ if !config. no_poh_speed_test {
1839
+ check_poh_speed ( & genesis_config, None ) ?;
1840
+ }
1841
+
1842
+ Ok ( genesis_config)
1843
+ }
1844
+
1812
1845
#[ allow( clippy:: type_complexity) ]
1813
1846
fn load_blockstore (
1814
1847
config : & ValidatorConfig ,
1815
1848
ledger_path : & Path ,
1849
+ genesis_config : & GenesisConfig ,
1816
1850
exit : Arc < AtomicBool > ,
1817
1851
start_progress : & Arc < RwLock < ValidatorStartProgress > > ,
1818
1852
accounts_update_notifier : Option < AccountsUpdateNotifier > ,
@@ -1821,7 +1855,6 @@ fn load_blockstore(
1821
1855
poh_timing_point_sender : Option < PohTimingSender > ,
1822
1856
) -> Result <
1823
1857
(
1824
- GenesisConfig ,
1825
1858
Arc < RwLock < BankForks > > ,
1826
1859
Arc < Blockstore > ,
1827
1860
Slot ,
@@ -1838,30 +1871,6 @@ fn load_blockstore(
1838
1871
> {
1839
1872
info ! ( "loading ledger from {:?}..." , ledger_path) ;
1840
1873
* start_progress. write ( ) . unwrap ( ) = ValidatorStartProgress :: LoadingLedger ;
1841
- let genesis_config = open_genesis_config ( ledger_path, config. max_genesis_archive_unpacked_size )
1842
- . map_err ( |err| format ! ( "Failed to open genesis config: {err}" ) ) ?;
1843
-
1844
- // This needs to be limited otherwise the state in the VoteAccount data
1845
- // grows too large
1846
- let leader_schedule_slot_offset = genesis_config. epoch_schedule . leader_schedule_slot_offset ;
1847
- let slots_per_epoch = genesis_config. epoch_schedule . slots_per_epoch ;
1848
- let leader_epoch_offset = ( leader_schedule_slot_offset + slots_per_epoch - 1 ) / slots_per_epoch;
1849
- assert ! ( leader_epoch_offset <= MAX_LEADER_SCHEDULE_EPOCH_OFFSET ) ;
1850
-
1851
- let genesis_hash = genesis_config. hash ( ) ;
1852
- info ! ( "genesis hash: {}" , genesis_hash) ;
1853
-
1854
- if let Some ( expected_genesis_hash) = config. expected_genesis_hash {
1855
- if genesis_hash != expected_genesis_hash {
1856
- return Err ( format ! (
1857
- "genesis hash mismatch: hash={genesis_hash} expected={expected_genesis_hash}. Delete the ledger directory to continue: {ledger_path:?}" ,
1858
- ) ) ;
1859
- }
1860
- }
1861
-
1862
- if !config. no_poh_speed_test {
1863
- check_poh_speed ( & genesis_config, None ) . map_err ( |err| format ! ( "{err}" ) ) ?;
1864
- }
1865
1874
1866
1875
let mut blockstore =
1867
1876
Blockstore :: open_with_options ( ledger_path, blockstore_options_from_config ( config) )
@@ -1918,7 +1927,7 @@ fn load_blockstore(
1918
1927
1919
1928
let ( bank_forks, mut leader_schedule_cache, starting_snapshot_hashes) =
1920
1929
bank_forks_utils:: load_bank_forks (
1921
- & genesis_config,
1930
+ genesis_config,
1922
1931
& blockstore,
1923
1932
config. account_paths . clone ( ) ,
1924
1933
Some ( & config. snapshot_config ) ,
@@ -1950,7 +1959,6 @@ fn load_blockstore(
1950
1959
}
1951
1960
1952
1961
Ok ( (
1953
- genesis_config,
1954
1962
bank_forks,
1955
1963
blockstore,
1956
1964
original_blockstore_root,
@@ -2338,9 +2346,15 @@ pub enum ValidatorError {
2338
2346
#[ error( "Bad expected bank hash" ) ]
2339
2347
BadExpectedBankHash ,
2340
2348
2349
+ #[ error( "genesis hash mismatch: actual={0}, expected={1}" ) ]
2350
+ GenesisHashMismatch ( Hash , Hash ) ,
2351
+
2341
2352
#[ error( "Ledger does not have enough data to wait for supermajority" ) ]
2342
2353
NotEnoughLedgerData ,
2343
2354
2355
+ #[ error( "failed to open genesis: {0}" ) ]
2356
+ OpenGenesisConfig ( #[ source] OpenGenesisConfigError ) ,
2357
+
2344
2358
#[ error( "{0}" ) ]
2345
2359
Other ( String ) ,
2346
2360
0 commit comments