correct rpc save_stakes and add save_votes
This commit is contained in:
parent
05e6dcd318
commit
47ccd6c4d2
|
@ -18,7 +18,7 @@ curl http://localhost:3000 -X POST -H "Content-Type: application/json" -d '
|
||||||
"method": "stake_accounts",
|
"method": "stake_accounts",
|
||||||
"params": []
|
"params": []
|
||||||
}
|
}
|
||||||
' -o extract_stake_529_end.json
|
' -o extract_stake_533_3.json
|
||||||
|
|
||||||
|
|
||||||
curl http://localhost:3000 -X POST -H "Content-Type: application/json" -d '
|
curl http://localhost:3000 -X POST -H "Content-Type: application/json" -d '
|
||||||
|
|
|
@ -244,6 +244,34 @@ pub(crate) async fn run_server(request_tx: Sender<Requests>) -> Result<ServerHan
|
||||||
.unwrap_or_else(|err| serde_json::Value::String(err.to_string()))
|
.unwrap_or_else(|err| serde_json::Value::String(err.to_string()))
|
||||||
})?;
|
})?;
|
||||||
module.register_async_method("stake_accounts", |_params, request_tx| async move {
|
module.register_async_method("stake_accounts", |_params, request_tx| async move {
|
||||||
|
log::trace!("RPC bootstrap_accounts");
|
||||||
|
let (tx, rx) = oneshot::channel();
|
||||||
|
if let Err(err) = request_tx.send(Requests::GetStakestore(tx)).await {
|
||||||
|
return serde_json::Value::String(format!("error during query processing:{err}",));
|
||||||
|
}
|
||||||
|
rx.await
|
||||||
|
.map_err(|err| format!("error during bootstrap query processing:{err}"))
|
||||||
|
.and_then(|(accounts, slot)| {
|
||||||
|
println!("RPC end request status");
|
||||||
|
if slot == 0 {
|
||||||
|
Err("Error stake store extracted".to_string())
|
||||||
|
} else {
|
||||||
|
//replace pubkey with String. Json only allow distionary key with string.
|
||||||
|
let ret: HashMap<String, StoredStake> = accounts
|
||||||
|
.into_iter()
|
||||||
|
.map(|(pk, acc)| (pk.to_string(), acc))
|
||||||
|
.collect();
|
||||||
|
serde_json::to_value((slot, ret)).map_err(|err| {
|
||||||
|
format!(
|
||||||
|
"error during json serialisation:{}",
|
||||||
|
JsonRpcError::ParseError(err)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|err| serde_json::Value::String(err.to_string()))
|
||||||
|
})?;
|
||||||
|
module.register_async_method("vote_accounts", |_params, request_tx| async move {
|
||||||
log::trace!("RPC bootstrap_accounts");
|
log::trace!("RPC bootstrap_accounts");
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
if let Err(err) = request_tx.send(Requests::GetVotestore(tx)).await {
|
if let Err(err) = request_tx.send(Requests::GetVotestore(tx)).await {
|
||||||
|
|
|
@ -51,29 +51,18 @@ fn stake_map_notify_stake(map: &mut StakeMap, stake: StoredStake, current_epoch:
|
||||||
//doesn't erase new state with an old one. Can arrive during bootstrapping.
|
//doesn't erase new state with an old one. Can arrive during bootstrapping.
|
||||||
//several instructions can be done in the same slot.
|
//several instructions can be done in the same slot.
|
||||||
if strstake.last_update_slot <= stake.last_update_slot {
|
if strstake.last_update_slot <= stake.last_update_slot {
|
||||||
if stake.is_removed(current_epoch) {
|
|
||||||
log::info!(
|
|
||||||
"stake_map_notify_stake Stake store remove stake: {} stake:{stake:?} current_epoch:{current_epoch}",
|
|
||||||
stake.pubkey
|
|
||||||
);
|
|
||||||
//TODO activate when remove algo is validated.
|
|
||||||
//map.remove(&stake.pubkey);
|
|
||||||
} else {
|
|
||||||
log::info!("stake_map_notify_stake Stake store updated stake: {} old_stake:{strstake:?} stake:{stake:?}", stake.pubkey);
|
log::info!("stake_map_notify_stake Stake store updated stake: {} old_stake:{strstake:?} stake:{stake:?}", stake.pubkey);
|
||||||
*strstake = stake;
|
*strstake = stake;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// If value doesn't exist yet, then insert a new value of 1
|
// If value doesn't exist yet, then insert a new value of 1
|
||||||
std::collections::hash_map::Entry::Vacant(vacant) => {
|
std::collections::hash_map::Entry::Vacant(vacant) => {
|
||||||
if stake.is_inserted(current_epoch) {
|
|
||||||
log::info!(
|
log::info!(
|
||||||
"stake_map_notify_stake Stake store insert stake: {} stake:{stake:?}",
|
"stake_map_notify_stake Stake store insert stake: {} stake:{stake:?}",
|
||||||
stake.pubkey
|
stake.pubkey
|
||||||
);
|
);
|
||||||
vacant.insert(stake);
|
vacant.insert(stake);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,16 +108,16 @@ pub struct StoredStake {
|
||||||
pub write_version: u64,
|
pub write_version: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StoredStake {
|
// impl StoredStake {
|
||||||
fn is_removed(&self, current_epoch: u64) -> bool {
|
// fn is_removed(&self, current_epoch: u64) -> bool {
|
||||||
self.stake.activation_epoch != crate::leader_schedule::MAX_EPOCH_VALUE
|
// self.stake.activation_epoch != crate::leader_schedule::MAX_EPOCH_VALUE
|
||||||
&& self.stake.deactivation_epoch < current_epoch
|
// && self.stake.deactivation_epoch < current_epoch
|
||||||
}
|
// }
|
||||||
fn is_inserted(&self, current_epoch: u64) -> bool {
|
// fn is_inserted(&self, current_epoch: u64) -> bool {
|
||||||
self.stake.activation_epoch == crate::leader_schedule::MAX_EPOCH_VALUE
|
// self.stake.activation_epoch == crate::leader_schedule::MAX_EPOCH_VALUE
|
||||||
|| self.stake.deactivation_epoch >= current_epoch
|
// || self.stake.deactivation_epoch >= current_epoch
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct StakeStore {
|
pub struct StakeStore {
|
||||||
stakes: StakeMap,
|
stakes: StakeMap,
|
||||||
|
|
Loading…
Reference in New Issue