Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage Miner Pledging #899

Merged
merged 22 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion blockchain/state_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use futures::channel::oneshot;
use futures::select;
use futures::stream::StreamExt;
use futures::FutureExt;
use interpreter::LookbackStateGetter;
use interpreter::{resolve_to_key_addr, ApplyRet, BlockMessages, Rand, VM};
use interpreter::{CircSupplyCalc, LookbackStateGetter};
use ipld_amt::Amt;
use lazycell::AtomicLazyCell;
use log::{debug, info, trace, warn};
Expand Down Expand Up @@ -1189,6 +1189,15 @@ where
}
Ok(())
}

/// Retrieves total circulating supply on the network.
pub fn get_circulating_supply(
self: &Arc<Self>,
height: ChainEpoch,
state_tree: &StateTree<DB>,
) -> Result<TokenAmount, Box<dyn StdError>> {
self.genesis_info.get_supply(height, state_tree)
}
}

pub struct MiningBaseInfo {
Expand Down
34 changes: 28 additions & 6 deletions node/rpc/src/chain_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ where
pub(crate) async fn chain_read_obj<DB, KS, B>(
data: Data<RpcState<DB, KS, B>>,
Params(params): Params<(CidJson,)>,
) -> Result<Vec<u8>, JsonRpcError>
) -> Result<String, JsonRpcError>
where
DB: BlockStore + Send + Sync + 'static,
KS: KeyStore + Send + Sync + 'static,
Expand All @@ -95,7 +95,7 @@ where
.blockstore()
.get_bytes(&obj_cid)?
.ok_or("can't find object with that cid")?;
Ok(ret)
Ok(base64::encode(ret))
}

pub(crate) async fn chain_has_obj<DB, KS, B>(
Expand Down Expand Up @@ -259,24 +259,46 @@ where
Ok(TipsetJson(ts))
}

pub(crate) async fn chain_get_randomness<DB, KS, B>(
pub(crate) async fn chain_get_randomness_from_tickets<DB, KS, B>(
data: Data<RpcState<DB, KS, B>>,
Params(params): Params<(TipsetKeys, i64, ChainEpoch, Vec<u8>)>,
Params(params): Params<(TipsetKeysJson, i64, ChainEpoch, String)>,
) -> Result<[u8; 32], JsonRpcError>
where
DB: BlockStore + Send + Sync + 'static,
KS: KeyStore + Send + Sync + 'static,
B: Beacon + Send + Sync + 'static,
{
let (tsk, pers, epoch, entropy) = params;
let (TipsetKeysJson(tsk), pers, epoch, entropy) = params;
Ok(data
.state_manager
.chain_store()
.get_chain_randomness(
&tsk,
DomainSeparationTag::from_i64(pers).ok_or("invalid DomainSeparationTag")?,
epoch,
&entropy,
&base64::decode(entropy)?,
)
.await?)
}

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)>,
) -> 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;
Ok(data
.state_manager
.chain_store()
.get_beacon_randomness(
&tsk,
DomainSeparationTag::from_i64(pers).ok_or("invalid DomainSeparationTag")?,
epoch,
&base64::decode(entropy)?,
)
.await?)
}
33 changes: 26 additions & 7 deletions node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
chain_api::chain_get_message::<DB, KS, B>,
false,
)
.with_method("Filecoin.ChainGetObj", chain_read_obj::<DB, KS, B>, false)
.with_method("Filecoin.ChainReadObj", chain_read_obj::<DB, KS, B>, false)
.with_method("Filecoin.ChainHasObj", chain_has_obj::<DB, KS, B>, false)
.with_method(
"Filecoin.ChainGetBlockMessages",
Expand Down Expand Up @@ -128,8 +128,13 @@ where
false,
)
.with_method(
"Filecoin.GetRandomness",
chain_get_randomness::<DB, KS, B>,
"Filecoin.ChainGetRandomnessFromTickets",
chain_get_randomness_from_tickets::<DB, KS, B>,
false,
)
.with_method(
"Filecoin.ChainGetRandomnessFromBeacon",
chain_get_randomness_from_beacon::<DB, KS, B>,
false,
)
.with_method(
Expand Down Expand Up @@ -243,20 +248,30 @@ where
state_miner_partitions::<DB, KS, B>,
false,
)
.with_method(
"Filecoin.StateMinerPreCommitDepositForPower",
state_miner_pre_commit_deposit_for_power::<DB, KS, B, V>,
false,
)
.with_method(
"Filecoin.StateMinerInitialPledgeCollateral",
state_miner_initial_pledge_collateral::<DB, KS, B, V>,
false,
)
.with_method("Filecoin.StateReplay", state_replay::<DB, KS, B>, false)
.with_method(
"Filecoin.StateGetActor",
state_get_actor::<DB, KS, B>,
state_get_actor::<DB, KS, B, V>,
false,
)
.with_method(
"Filecoin.StateAccountKey",
state_account_key::<DB, KS, B>,
state_account_key::<DB, KS, B, V>,
false,
)
.with_method(
"Filecoin.StateLookupId",
state_lookup_id::<DB, KS, B>,
state_lookup_id::<DB, KS, B, V>,
false,
)
.with_method(
Expand Down Expand Up @@ -295,7 +310,11 @@ where
miner_create_block::<DB, KS, B, V>,
false,
)
.with_method("Filecoin.NetworkVersion", state_get_network_version, false)
.with_method(
"Filecoin.StateNetworkVersion",
state_get_network_version::<DB, KS, B>,
false,
)
// Gas API
.with_method(
"Filecoin.GasEstimateGasLimit",
Expand Down
2 changes: 2 additions & 0 deletions node/rpc/src/mpool_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ where
if from.protocol() == Protocol::ID {
umsg.from = key_addr;
}
let nonce = data.mpool.get_sequence(&from).await?;
umsg.sequence = nonce;
let key = wallet::find_key(&key_addr, &*keystore)?;
let sig = wallet::sign(
*key.key_info.key_type(),
Expand Down
Loading