Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit d08a810

Browse files
author
Tyera Eulberg
authored
v0.16: Expand Config program; implement Validator Info CLI (#5045)
* Update config program to accommodate multiple signers (#4946) * Update config program to accommodate multiple signers * Update install CLI * Remove account_type u32; add handling for unsigned keys in list * ConfigKeys doc * Make config_api more robust (#4980) * Make config_api more robust * Add test and update store instruction * Improve signature checks in config_api (#5001) automerge * Add validator-info CLI (#4970) * Add validator-info CLI * Add GetProgramAccounts method to solana-client * Update validator-info args, and add get subcommand * Update ValidatorInfo lengths * Add account filter for get --all * Update testnet participation doc to reflect validator-info * Flesh out tests * Review comments
1 parent 400610b commit d08a810

14 files changed

Lines changed: 1028 additions & 98 deletions

File tree

‎Cargo.lock‎

Lines changed: 95 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ members = [
4141
"runtime",
4242
"sdk",
4343
"upload-perf",
44+
"validator-info",
4445
"vote-signer",
4546
"wallet",
4647
]

‎book/src/testnet-participation.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,18 @@ A local InfluxDB and Grafana instance is now running on your machine. Define
240240
`start.sh` output and restart your validator.
241241

242242
Metrics should now be streaming and visible from your local Grafana dashboard.
243+
244+
#### Publishing Validator Info
245+
246+
You can publish your validator information to the chain to be publicly visible
247+
to other users.
248+
249+
Run the solana-validator-info CLI to populate a validator-info account:
250+
```bash
251+
$ solana-validator-info publish -k ~/validator-keypair.json <VALIDATOR_INFO_ARGS>
252+
```
253+
Available fields for VALIDATOR_INFO_ARGS:
254+
* Name (required)
255+
* Website
256+
* Keybase ID
257+
* Details

‎client/src/rpc_client.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,40 @@ impl RpcClient {
274274
self.get_account(pubkey).map(|account| account.lamports)
275275
}
276276

277+
pub fn get_program_accounts(&self, pubkey: &Pubkey) -> io::Result<Vec<(Pubkey, Account)>> {
278+
let params = json!([format!("{}", pubkey)]);
279+
let response = self
280+
.client
281+
.send(&RpcRequest::GetProgramAccounts, Some(params), 0)
282+
.map_err(|err| {
283+
io::Error::new(
284+
io::ErrorKind::Other,
285+
format!("AccountNotFound: pubkey={}: {}", pubkey, err),
286+
)
287+
})?;
288+
289+
let accounts: Vec<(String, Account)> =
290+
serde_json::from_value::<Vec<(String, Account)>>(response).map_err(|err| {
291+
io::Error::new(
292+
io::ErrorKind::Other,
293+
format!("GetProgramAccounts parse failure: {:?}", err),
294+
)
295+
})?;
296+
println!("{:?}", accounts);
297+
298+
let mut pubkey_accounts: Vec<(Pubkey, Account)> = Vec::new();
299+
for (string, account) in accounts.into_iter() {
300+
let pubkey = string.parse().map_err(|err| {
301+
io::Error::new(
302+
io::ErrorKind::Other,
303+
format!("GetProgramAccounts parse failure: {:?}", err),
304+
)
305+
})?;
306+
pubkey_accounts.push((pubkey, account));
307+
}
308+
Ok(pubkey_accounts)
309+
}
310+
277311
/// Request the transaction count. If the response packet is dropped by the network,
278312
/// this method will try again 5 times.
279313
pub fn get_transaction_count(&self) -> io::Result<u64> {

‎client/src/rpc_request.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum RpcRequest {
1010
GetBalance,
1111
GetClusterNodes,
1212
GetNumBlocksSinceSignatureConfirmation,
13+
GetProgramAccounts,
1314
GetRecentBlockhash,
1415
GetSignatureStatus,
1516
GetSlot,
@@ -38,6 +39,7 @@ impl RpcRequest {
3839
RpcRequest::GetNumBlocksSinceSignatureConfirmation => {
3940
"getNumBlocksSinceSignatureConfirmation"
4041
}
42+
RpcRequest::GetProgramAccounts => "getProgramAccounts",
4143
RpcRequest::GetRecentBlockhash => "getRecentBlockhash",
4244
RpcRequest::GetSignatureStatus => "getSignatureStatus",
4345
RpcRequest::GetSlot => "getSlot",

‎install/src/command.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use console::{style, Emoji};
66
use indicatif::{ProgressBar, ProgressStyle};
77
use ring::digest::{Context, Digest, SHA256};
88
use solana_client::rpc_client::RpcClient;
9-
use solana_config_api::config_instruction;
9+
use solana_config_api::config_instruction::{self, ConfigKeys};
1010
use solana_sdk::message::Message;
1111
use solana_sdk::pubkey::Pubkey;
1212
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil, Signable};
@@ -203,7 +203,8 @@ fn new_update_manifest(
203203
let new_account = config_instruction::create_account::<SignedUpdateManifest>(
204204
&from_keypair.pubkey(),
205205
&update_manifest_keypair.pubkey(),
206-
1, // lamports
206+
1, // lamports
207+
vec![], // additional keys
207208
);
208209
let mut transaction = Transaction::new_unsigned_instructions(vec![new_account]);
209210
transaction.sign(&[from_keypair], recent_blockhash);
@@ -225,6 +226,8 @@ fn store_update_manifest(
225226
let signers = [from_keypair, update_manifest_keypair];
226227
let instruction = config_instruction::store::<SignedUpdateManifest>(
227228
&update_manifest_keypair.pubkey(),
229+
true, // update_manifest_keypair is signer
230+
vec![], // additional keys
228231
update_manifest,
229232
);
230233

@@ -239,9 +242,10 @@ fn get_update_manifest(
239242
rpc_client: &RpcClient,
240243
update_manifest_pubkey: &Pubkey,
241244
) -> Result<UpdateManifest, String> {
242-
let data = rpc_client
245+
let mut data = rpc_client
243246
.get_account_data(update_manifest_pubkey)
244247
.map_err(|err| format!("Unable to fetch update manifest: {}", err))?;
248+
data.split_off(ConfigKeys::serialized_size(vec![]));
245249

246250
let signed_update_manifest =
247251
SignedUpdateManifest::deserialize(update_manifest_pubkey, &data)

‎programs/config_api/Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,3 @@ solana-runtime = { path = "../../runtime", version = "0.16.3" }
2222
[lib]
2323
crate-type = ["lib"]
2424
name = "solana_config_api"
25-
Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,59 @@
11
use crate::id;
22
use crate::ConfigState;
3+
use bincode::serialize;
4+
use serde_derive::{Deserialize, Serialize};
35
use solana_sdk::instruction::{AccountMeta, Instruction};
46
use solana_sdk::pubkey::Pubkey;
7+
use solana_sdk::short_vec;
58
use solana_sdk::system_instruction;
69

10+
/// A collection of keys to be stored in Config account data.
11+
#[derive(Debug, Default, Deserialize, Serialize)]
12+
pub struct ConfigKeys {
13+
// Each key tuple comprises a unique `Pubkey` identifier,
14+
// and `bool` whether that key is a signer of the data
15+
#[serde(with = "short_vec")]
16+
pub keys: Vec<(Pubkey, bool)>,
17+
}
18+
19+
impl ConfigKeys {
20+
pub fn serialized_size(keys: Vec<(Pubkey, bool)>) -> usize {
21+
serialize(&ConfigKeys { keys })
22+
.unwrap_or_else(|_| vec![])
23+
.len()
24+
}
25+
}
26+
727
/// Create a new, empty configuration account
828
pub fn create_account<T: ConfigState>(
929
from_account_pubkey: &Pubkey,
1030
config_account_pubkey: &Pubkey,
1131
lamports: u64,
32+
keys: Vec<(Pubkey, bool)>,
1233
) -> Instruction {
34+
let space = T::max_space() + ConfigKeys::serialized_size(keys) as u64;
1335
system_instruction::create_account(
1436
from_account_pubkey,
1537
config_account_pubkey,
1638
lamports,
17-
T::max_space(),
39+
space,
1840
&id(),
1941
)
2042
}
2143

2244
/// Store new data in a configuration account
23-
pub fn store<T: ConfigState>(config_account_pubkey: &Pubkey, data: &T) -> Instruction {
24-
let account_metas = vec![AccountMeta::new(*config_account_pubkey, true)];
25-
Instruction::new(id(), data, account_metas)
45+
pub fn store<T: ConfigState>(
46+
config_account_pubkey: &Pubkey,
47+
is_config_signer: bool,
48+
keys: Vec<(Pubkey, bool)>,
49+
data: &T,
50+
) -> Instruction {
51+
let mut account_metas = vec![AccountMeta::new(*config_account_pubkey, is_config_signer)];
52+
for (signer_pubkey, _) in keys.iter().filter(|(_, is_signer)| *is_signer) {
53+
if signer_pubkey != config_account_pubkey {
54+
account_metas.push(AccountMeta::new(*signer_pubkey, true));
55+
}
56+
}
57+
let account_data = (ConfigKeys { keys }, data);
58+
Instruction::new(id(), &account_data, account_metas)
2659
}

0 commit comments

Comments
 (0)