-
Notifications
You must be signed in to change notification settings - Fork 743
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store pubkey cache decompressed on disk (#5897)
* Support uncompressed keys in crypto/bls * Use uncompressed keys in cache * Implement DB upgrade * Implement downgrade * More logging on v20 upgrade * Revert "More logging on v20 upgrade" This reverts commit cc5789b. * Merge remote-tracking branch 'origin/unstable' into uncompressed-pubkeys * Add a little more logging * Merge remote-tracking branch 'origin/unstable' into uncompressed-pubkeys
- Loading branch information
1 parent
d9ad1f5
commit d84e3e3
Showing
10 changed files
with
199 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
beacon_node/beacon_chain/src/schema_change/migration_schema_v21.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use crate::beacon_chain::BeaconChainTypes; | ||
use crate::validator_pubkey_cache::DatabasePubkey; | ||
use slog::{info, Logger}; | ||
use ssz::{Decode, Encode}; | ||
use std::sync::Arc; | ||
use store::{ | ||
get_key_for_col, DBColumn, Error, HotColdDB, KeyValueStore, KeyValueStoreOp, StoreItem, | ||
}; | ||
use types::{Hash256, PublicKey}; | ||
|
||
const LOG_EVERY: usize = 200_000; | ||
|
||
pub fn upgrade_to_v21<T: BeaconChainTypes>( | ||
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>, | ||
log: Logger, | ||
) -> Result<Vec<KeyValueStoreOp>, Error> { | ||
info!(log, "Upgrading from v20 to v21"); | ||
|
||
let mut ops = vec![]; | ||
|
||
// Iterate through all pubkeys and decompress them. | ||
for (i, res) in db | ||
.hot_db | ||
.iter_column::<Hash256>(DBColumn::PubkeyCache) | ||
.enumerate() | ||
{ | ||
let (key, value) = res?; | ||
let pubkey = PublicKey::from_ssz_bytes(&value)?; | ||
let decompressed = DatabasePubkey::from_pubkey(&pubkey); | ||
ops.push(decompressed.as_kv_store_op(key)); | ||
|
||
if i > 0 && i % LOG_EVERY == 0 { | ||
info!( | ||
log, | ||
"Public key decompression in progress"; | ||
"keys_decompressed" => i | ||
); | ||
} | ||
} | ||
info!(log, "Public key decompression complete"); | ||
|
||
Ok(ops) | ||
} | ||
|
||
pub fn downgrade_from_v21<T: BeaconChainTypes>( | ||
db: Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>, | ||
log: Logger, | ||
) -> Result<Vec<KeyValueStoreOp>, Error> { | ||
info!(log, "Downgrading from v21 to v20"); | ||
|
||
let mut ops = vec![]; | ||
|
||
// Iterate through all pubkeys and recompress them. | ||
for (i, res) in db | ||
.hot_db | ||
.iter_column::<Hash256>(DBColumn::PubkeyCache) | ||
.enumerate() | ||
{ | ||
let (key, value) = res?; | ||
let decompressed = DatabasePubkey::from_ssz_bytes(&value)?; | ||
let (_, pubkey_bytes) = decompressed.as_pubkey().map_err(|e| Error::DBError { | ||
message: format!("{e:?}"), | ||
})?; | ||
|
||
let db_key = get_key_for_col(DBColumn::PubkeyCache.into(), key.as_bytes()); | ||
ops.push(KeyValueStoreOp::PutKeyValue( | ||
db_key, | ||
pubkey_bytes.as_ssz_bytes(), | ||
)); | ||
|
||
if i > 0 && i % LOG_EVERY == 0 { | ||
info!( | ||
log, | ||
"Public key compression in progress"; | ||
"keys_compressed" => i | ||
); | ||
} | ||
} | ||
|
||
info!(log, "Public key compression complete"); | ||
|
||
Ok(ops) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.