-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(watcher): registration management prototype (#1118)
Description --- Checks the active set of keys on the network before sending a [RegisterValidatorNode](https://github.com/tari-project/tari/blob/feature-dan2/applications/minotari_app_grpc/proto/wallet.proto#L82) request, and backs off until expected registration expires, to register the node again. Breaking Changes --- - [x] None - [ ] Requires data directory to be deleted - [ ] Other - Please specify
- Loading branch information
1 parent
f56e4b4
commit 11931c1
Showing
9 changed files
with
254 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use std::path::PathBuf; | ||
|
||
use minotari_app_grpc::tari_rpc::{GetActiveValidatorNodesResponse, TipInfoResponse}; | ||
use tari_common_types::types::PublicKey; | ||
use tari_core::transactions::transaction_components::ValidatorNodeSignature; | ||
use tari_crypto::{ristretto::RistrettoPublicKey, tari_utilities::ByteArray}; | ||
use tokio::fs; | ||
|
||
use crate::config::Config; | ||
|
||
pub async fn read_config_file(path: PathBuf) -> anyhow::Result<Config> { | ||
let content = fs::read_to_string(&path).await.map_err(|_| { | ||
format!( | ||
"Failed to read config file at {}", | ||
path.into_os_string().into_string().unwrap() | ||
) | ||
}); | ||
|
||
let config = toml::from_str(&content.unwrap())?; | ||
|
||
Ok(config) | ||
} | ||
|
||
#[derive(serde::Serialize, serde::Deserialize)] | ||
pub struct ValidatorNodeRegistration { | ||
pub signature: ValidatorNodeSignature, | ||
pub public_key: PublicKey, | ||
pub claim_fees_public_key: PublicKey, | ||
} | ||
|
||
pub async fn read_registration_file(vn_registration_file: PathBuf) -> anyhow::Result<ValidatorNodeRegistration> { | ||
log::debug!( | ||
"Using VN registration file at: {}", | ||
vn_registration_file.clone().into_os_string().into_string().unwrap() | ||
); | ||
|
||
let info = fs::read_to_string(vn_registration_file).await?; | ||
let reg = json5::from_str(&info)?; | ||
Ok(reg) | ||
} | ||
|
||
pub fn to_vn_public_keys(vns: Vec<GetActiveValidatorNodesResponse>) -> Vec<PublicKey> { | ||
vns.into_iter() | ||
.map(|vn| PublicKey::from_vec(&vn.public_key).expect("Invalid public key, should not happen")) | ||
.collect() | ||
} | ||
|
||
pub fn to_block_height(tip_info: TipInfoResponse) -> u64 { | ||
tip_info.metadata.unwrap().best_block_height | ||
} | ||
|
||
pub fn contains_key(vns: Vec<RistrettoPublicKey>, needle: PublicKey) -> bool { | ||
vns.iter().any(|vn| vn.eq(&needle)) | ||
} |
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.