Vote contract (#1552)

* Add Vote Contract

* Move ownership of LeaderScheduler from Fullnode to the bank

* Modified ReplicateStage to consume leader information from bank

* Restart RPC Services in Leader To Validator Transition

* Make VoteContract Context Free

* Remove voting from ClusterInfo and Tpu

* Remove dependency on ActiveValidators in LeaderScheduler

* Switch VoteContract to have two steps 1) Register 2) Vote. Change thin client to create + register a voting account on fullnode startup

* Remove check in leader_to_validator transition for unique references to bank, b/c jsonrpc service and rpcpubsub hold references through jsonhttpserver
This commit is contained in:
carllin
2018-10-25 16:58:40 -07:00
committed by GitHub
parent 160cff4a30
commit f6c8e1a4bf
27 changed files with 1190 additions and 1195 deletions

View File

@@ -17,14 +17,16 @@ use solana::logger;
use solana::metrics::set_panic_hook;
use solana::signature::{Keypair, KeypairUtil};
use solana::thin_client::poll_gossip_for_leader;
use solana::vote_program::VoteProgram;
use solana::wallet::request_airdrop;
use std::fs::File;
use std::net::{Ipv4Addr, SocketAddr};
use std::process::exit;
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;
fn main() -> () {
fn main() {
logger::setup();
set_panic_hook("fullnode");
let matches = App::new("fullnode")
@@ -82,7 +84,6 @@ fn main() -> () {
// save off some stuff for airdrop
let node_info = node.info.clone();
let pubkey = keypair.pubkey();
let leader = match network {
Some(network) => {
@@ -91,10 +92,16 @@ fn main() -> () {
None => node_info,
};
let vote_account_keypair = Arc::new(Keypair::new());
let vote_account_id = vote_account_keypair.pubkey();
let keypair = Arc::new(keypair);
let pubkey = keypair.pubkey();
let mut fullnode = Fullnode::new(
node,
ledger_path,
keypair,
keypair.clone(),
vote_account_keypair,
network,
false,
LeaderScheduler::from_bootstrap_leader(leader.id),
@@ -129,6 +136,49 @@ fn main() -> () {
}
}
// Create the vote account
loop {
let last_id = client.get_last_id();
if client
.create_vote_account(&keypair, vote_account_id, &last_id, 1)
.is_err()
{
sleep(Duration::from_secs(2));
continue;
}
let balance = client.poll_get_balance(&vote_account_id).unwrap_or(0);
if balance > 0 {
break;
}
sleep(Duration::from_secs(2));
}
// Register the vote account to this node
loop {
let last_id = client.get_last_id();
if client
.register_vote_account(&keypair, vote_account_id, &last_id)
.is_err()
{
sleep(Duration::from_secs(2));
continue;
}
let account_user_data = client.get_account_userdata(&vote_account_id);
if let Ok(Some(account_user_data)) = account_user_data {
if let Ok(vote_state) = VoteProgram::deserialize(&account_user_data) {
if vote_state.node_id == pubkey {
break;
}
}
}
sleep(Duration::from_secs(2));
}
loop {
let status = fullnode.handle_role_transition();
match status {