Skip to content

Commit

Permalink
Nullable Entropy in Randomness RPC and Fix Gas Base Fee Estimation (#947
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
ec2 authored Jan 22, 2021
1 parent 4825a6a commit ccd4fbd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
7 changes: 5 additions & 2 deletions node/rpc/src/chain_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,15 @@ where

pub(crate) async fn chain_get_randomness_from_tickets<DB, KS, B>(
data: Data<RpcState<DB, KS, B>>,
Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, String)>,
Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, Option<String>)>,
) -> Result<[u8; 32], JsonRpcError>
where
DB: BlockStore + Send + Sync + 'static,
KS: KeyStore + Send + Sync + 'static,
B: Beacon + Send + Sync + 'static,
{
let (TipsetKeysJson(tsk), pers, epoch, entropy) = params;
let entropy = entropy.unwrap_or_default();
Ok(data
.state_manager
.chain_store()
Expand All @@ -278,14 +279,16 @@ where

pub(crate) async fn chain_get_randomness_from_beacon<DB, KS, B>(
data: Data<RpcState<DB, KS, B>>,
Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, String)>,
Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, Option<String>)>,
) -> Result<[u8; 32], JsonRpcError>
where
DB: BlockStore + Send + Sync + 'static,
KS: KeyStore + Send + Sync + 'static,
B: Beacon + Send + Sync + 'static,
{
let (TipsetKeysJson(tsk), pers, epoch, entropy) = params;
let entropy = entropy.unwrap_or_default();

Ok(data
.state_manager
.chain_store()
Expand Down
19 changes: 2 additions & 17 deletions node/rpc/src/gas_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DB, KS, B>(
Expand Down Expand Up @@ -54,29 +53,15 @@ 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);

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)
}

Expand Down
1 change: 0 additions & 1 deletion node/rpc/src/wallet_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down

0 comments on commit ccd4fbd

Please sign in to comment.