From ccd4fbd011b67609dcc634c39727e6d5591a7874 Mon Sep 17 00:00:00 2001 From: Eric Tu <6364934+ec2@users.noreply.github.com> Date: Fri, 22 Jan 2021 10:22:12 -0500 Subject: [PATCH] Nullable Entropy in Randomness RPC and Fix Gas Base Fee Estimation (#947) * fix the beacon randomness for null entropy, and fixed some gas base fee api * did the randomness null entropy for beacon too * lint * clipperoni * unwrap or default --- node/rpc/src/chain_api.rs | 7 +++++-- node/rpc/src/gas_api.rs | 19 ++----------------- node/rpc/src/wallet_api.rs | 1 - 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/node/rpc/src/chain_api.rs b/node/rpc/src/chain_api.rs index 45483bb31ebd..32a65cbc6287 100644 --- a/node/rpc/src/chain_api.rs +++ b/node/rpc/src/chain_api.rs @@ -256,7 +256,7 @@ where pub(crate) async fn chain_get_randomness_from_tickets( data: Data>, - Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, String)>, + Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, Option)>, ) -> Result<[u8; 32], JsonRpcError> where DB: BlockStore + Send + Sync + 'static, @@ -264,6 +264,7 @@ where B: Beacon + Send + Sync + 'static, { let (TipsetKeysJson(tsk), pers, epoch, entropy) = params; + let entropy = entropy.unwrap_or_default(); Ok(data .state_manager .chain_store() @@ -278,7 +279,7 @@ where pub(crate) async fn chain_get_randomness_from_beacon( data: Data>, - Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, String)>, + Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, Option)>, ) -> Result<[u8; 32], JsonRpcError> where DB: BlockStore + Send + Sync + 'static, @@ -286,6 +287,8 @@ where B: Beacon + Send + Sync + 'static, { let (TipsetKeysJson(tsk), pers, epoch, entropy) = params; + let entropy = entropy.unwrap_or_default(); + Ok(data .state_manager .chain_store() diff --git a/node/rpc/src/gas_api.rs b/node/rpc/src/gas_api.rs index 25ee48afb374..99a37c0bc48d 100644 --- a/node/rpc/src/gas_api.rs +++ b/node/rpc/src/gas_api.rs @@ -17,7 +17,6 @@ use num_traits::{FromPrimitive, Zero}; use rand_distr::{Distribution, Normal}; use wallet::KeyStore; const MIN_GAS_PREMIUM: f64 = 100000.0; -const MAX_SPEND_ON_FEE_DENOM: i64 = 100; /// Estimate the fee cap pub(crate) async fn gas_estimate_fee_cap( @@ -54,11 +53,6 @@ where .await .ok_or("can't find heaviest tipset")?; - let act = data - .state_manager - .get_actor(msg.from(), ts.parent_state())? - .ok_or("could not load actor")?; - let parent_base_fee = ts.blocks()[0].parent_base_fee(); let increase_factor = (1.0 + (BASE_FEE_MAX_CHANGE_DENOM as f64).recip()).powf(max_queue_blks as f64); @@ -66,17 +60,8 @@ where let fee_in_future = parent_base_fee * BigInt::from_f64(increase_factor * (1 << 8) as f64) .ok_or("failed to convert fee_in_future f64 to bigint")?; - let fee_in_future = fee_in_future / (1 << 8); - - let gas_limit_big: BigInt = msg.gas_limit().into(); - let max_accepted = act.balance / MAX_SPEND_ON_FEE_DENOM; - let expected_fee = &fee_in_future * &gas_limit_big; - - let out = if expected_fee > max_accepted { - max_accepted / gas_limit_big - } else { - fee_in_future - }; + let mut out = fee_in_future / (1 << 8); + out += msg.gas_premium(); Ok(out) } diff --git a/node/rpc/src/wallet_api.rs b/node/rpc/src/wallet_api.rs index 752cb2a13b88..625ec587f102 100644 --- a/node/rpc/src/wallet_api.rs +++ b/node/rpc/src/wallet_api.rs @@ -122,7 +122,6 @@ where let key = Key::try_from(key_info)?; let addr = format!("wallet-{}", key.address.to_string()); - let mut keystore = data.keystore.write().await; keystore.put(addr, key.key_info)?;