remove redundant last_update_timestamp
Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
parent
2483648b13
commit
92e82ceeee
@ -2,7 +2,7 @@
|
||||
name = "ghost-eye"
|
||||
authors = ["str3tch <stretch@ghostchain.io>"]
|
||||
description = "Application for interacting with Casper/Ghost nodes that are exposing RPC only to the localhost"
|
||||
version = "0.3.78"
|
||||
version = "0.3.79"
|
||||
edition = "2021"
|
||||
homepage = "https://git.ghostchain.io/ghostchain"
|
||||
repository = "https://git.ghostchain.io/ghostchain/ghost-eye"
|
||||
|
||||
@ -133,10 +133,8 @@ pub enum Action {
|
||||
SetChoosenGatekeeper(u64),
|
||||
SetSlashingSpansLength(usize, [u8; 32]),
|
||||
SetStoredRpcEndpoints(Vec<String>),
|
||||
SetLastUpdated(u64, u64),
|
||||
SetRateLimitDelay(u64, u64),
|
||||
UpdateStoredRpcEndpoints(u64, Vec<String>),
|
||||
NullifyLastTimestamp(u64),
|
||||
|
||||
BestBlockInformation(H256, u32),
|
||||
FinalizedBlockInformation(H256, u32),
|
||||
|
||||
@ -30,7 +30,6 @@ pub struct GatekeeperEndpoints {
|
||||
is_active: bool,
|
||||
selected: Selected,
|
||||
rate_limit_delay: u64,
|
||||
last_updated: u64,
|
||||
chain_id: u64,
|
||||
rpc_input: Input,
|
||||
action_tx: Option<UnboundedSender<Action>>,
|
||||
@ -90,11 +89,6 @@ impl GatekeeperEndpoints {
|
||||
}
|
||||
}
|
||||
}
|
||||
Selected::StoredRpcs if new_char == 'T' => {
|
||||
if let Some(network_tx) = &self.network_tx {
|
||||
let _ = network_tx.send(Action::NullifyLastTimestamp(self.chain_id));
|
||||
}
|
||||
}
|
||||
_ => match new_char {
|
||||
'j' => self.move_cursor_down(),
|
||||
'k' => self.move_cursor_up(),
|
||||
@ -238,31 +232,7 @@ impl GatekeeperEndpoints {
|
||||
}
|
||||
|
||||
fn prepare_rate_limits(&self) -> String {
|
||||
format!("Rate limit: {}", self.rate_limit_delay / 1_000)
|
||||
}
|
||||
|
||||
fn prepare_datetime_string(&self) -> String {
|
||||
let now = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.expect("Time went backwards")
|
||||
.as_millis();
|
||||
|
||||
let diff = now as i64 - self.last_updated as i64;
|
||||
let abs_diff = diff.abs();
|
||||
|
||||
if abs_diff < 60_000 {
|
||||
let secs = abs_diff / 1_000;
|
||||
format!("{}secs {}", secs, if diff >= 0 { "ago" } else { "left" })
|
||||
} else if abs_diff < 3_600_000 {
|
||||
let mins = abs_diff / 60_000;
|
||||
format!("{}mins {}", mins, if diff >= 0 { "ago" } else { "left" })
|
||||
} else if abs_diff < 86_400_000 {
|
||||
let hours = abs_diff / 3_600_000;
|
||||
format!("{}hour {}", hours, if diff >= 0 { "ago" } else { "left" })
|
||||
} else {
|
||||
let days = abs_diff / 86_400_000;
|
||||
format!("{}days {}", days, if diff >= 0 { "ago" } else { "left" })
|
||||
}
|
||||
format!("RPC call cooldown: {}s", self.rate_limit_delay)
|
||||
}
|
||||
}
|
||||
|
||||
@ -335,14 +305,9 @@ impl Component for GatekeeperEndpoints {
|
||||
fn update(&mut self, action: Action) -> Result<Option<Action>> {
|
||||
match action {
|
||||
Action::SetChoosenGatekeeper(chain_id) => self.set_chain_id(chain_id),
|
||||
Action::SetLastUpdated(chain_id, last_updated) => {
|
||||
if chain_id == self.chain_id {
|
||||
self.last_updated = last_updated;
|
||||
}
|
||||
}
|
||||
Action::SetRateLimitDelay(chain_id, rate_limit_delay) => {
|
||||
if chain_id == self.chain_id {
|
||||
self.rate_limit_delay = rate_limit_delay;
|
||||
self.rate_limit_delay = rate_limit_delay / 1_000;
|
||||
}
|
||||
}
|
||||
Action::SetGatekeepedNetwork(network) => {
|
||||
@ -400,8 +365,7 @@ impl Component for GatekeeperEndpoints {
|
||||
.title_style(self.palette.create_popup_title_style())
|
||||
.title_alignment(Alignment::Right)
|
||||
.title("Input new RPC")
|
||||
.title_bottom(Line::from(self.prepare_datetime_string()).left_aligned())
|
||||
.title_bottom(Line::from(self.prepare_rate_limits()).right_aligned()),
|
||||
.title_top(Line::from(self.prepare_rate_limits()).left_aligned()),
|
||||
);
|
||||
|
||||
let v = Layout::vertical([Constraint::Max(14)]).flex(Flex::Center);
|
||||
|
||||
@ -264,8 +264,8 @@ impl Component for Validator {
|
||||
match action {
|
||||
Action::SetActiveScreen(Mode::Validator) => {
|
||||
self.is_active = true;
|
||||
self.previous_tab = CurrentTab::NominatorsByValidator;
|
||||
self.current_tab = CurrentTab::NominatorsByValidator;
|
||||
self.previous_tab = CurrentTab::Gatekeepers;
|
||||
self.current_tab = CurrentTab::Gatekeepers;
|
||||
}
|
||||
Action::PayoutValidatorPopup(_) => {
|
||||
self.previous_tab = self.current_tab;
|
||||
|
||||
@ -169,34 +169,6 @@ pub async fn get_block_range(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_last_updated(
|
||||
action_tx: &UnboundedSender<Action>,
|
||||
rpc_client: &RpcClient,
|
||||
chain_id: u64,
|
||||
) -> Result<()> {
|
||||
let chain_id_encoded = chain_id.encode();
|
||||
let block_range_key_raw = get_slow_clap_storage_key(b"last-timestamp-", &chain_id_encoded);
|
||||
let mut block_range_key = String::from("0x");
|
||||
for byte in block_range_key_raw {
|
||||
block_range_key.push_str(&format!("{:02x}", byte));
|
||||
}
|
||||
let last_timestamp: u64 = rpc_client
|
||||
.request(
|
||||
"offchain_localStorageGet",
|
||||
rpc_params!["PERSISTENT", block_range_key],
|
||||
)
|
||||
.await
|
||||
.ok()
|
||||
.map(|hex_string: String| {
|
||||
let bytes = hex::decode(&hex_string[2..]).expect("Invalid hex string");
|
||||
u64::decode(&mut bytes.as_slice()).ok().unwrap_or_default()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
|
||||
action_tx.send(Action::SetLastUpdated(chain_id, last_timestamp))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_rate_limit_delay(
|
||||
action_tx: &UnboundedSender<Action>,
|
||||
rpc_client: &RpcClient,
|
||||
@ -342,40 +314,3 @@ pub async fn set_stored_rpc_endpoints(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn set_last_timestamp(
|
||||
action_tx: &UnboundedSender<Action>,
|
||||
rpc_client: &RpcClient,
|
||||
chain_id: u64,
|
||||
) -> Result<()> {
|
||||
let chain_id_encoded = chain_id.encode();
|
||||
let endpoint_key_raw = get_slow_clap_storage_key(b"last-timestamp-", &chain_id_encoded);
|
||||
let mut endpoint_key = String::from("0x");
|
||||
for byte in endpoint_key_raw {
|
||||
endpoint_key.push_str(&format!("{:02x}", byte));
|
||||
}
|
||||
|
||||
let encoded_zero = String::from("0x0000000000000000");
|
||||
match rpc_client
|
||||
.request::<()>(
|
||||
"offchain_localStorageSet",
|
||||
rpc_params!["PERSISTENT", endpoint_key, encoded_zero],
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
action_tx.send(Action::EventLog(
|
||||
format!("Last timestamp nullified for network #{:?}", chain_id),
|
||||
ActionLevel::Info,
|
||||
ActionTarget::ValidatorLog,
|
||||
))?;
|
||||
get_stored_rpc_endpoints(action_tx, rpc_client, chain_id).await?;
|
||||
}
|
||||
Err(err) => action_tx.send(Action::EventLog(
|
||||
format!("Last timestamp nullification failed: {:?}", err),
|
||||
ActionLevel::Error,
|
||||
ActionTarget::ValidatorLog,
|
||||
))?,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -378,8 +378,6 @@ impl Network {
|
||||
for chain_id in GATEKEEPED_CHAIN_IDS {
|
||||
legacy_rpc_calls::get_block_range(&self.action_tx, &self.rpc_client, chain_id)
|
||||
.await?;
|
||||
legacy_rpc_calls::get_last_updated(&self.action_tx, &self.rpc_client, chain_id)
|
||||
.await?;
|
||||
legacy_rpc_calls::get_rate_limit_delay(
|
||||
&self.action_tx,
|
||||
&self.rpc_client,
|
||||
@ -854,10 +852,6 @@ impl Network {
|
||||
)
|
||||
.await
|
||||
}
|
||||
Action::NullifyLastTimestamp(chain_id) => {
|
||||
legacy_rpc_calls::set_last_timestamp(&self.action_tx, &self.rpc_client, chain_id)
|
||||
.await
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user