-
Notifications
You must be signed in to change notification settings - Fork 160
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
feat(rpc): implement Filecoin.MsigGetVested and Filecoin.MsigGetVestingSchedule #4304
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b6c37fb
added MsigGetVested rpc method
sudo-shashank 0819f6f
add test
sudo-shashank 489ae50
fix
sudo-shashank 199173c
lint fix
sudo-shashank eae315d
Implement MsigGetVestingSchedule with test
sudo-shashank 15cc623
fix
sudo-shashank 84ea3d4
move all msig together
sudo-shashank 290ff83
lint fix
sudo-shashank 2558e8d
Merge branch 'main' into shashank/rpc-msig-vested
sudo-shashank ba42d9c
restructure
sudo-shashank 6bd623d
Merge branch 'main' into shashank/rpc-msig-vested
sudo-shashank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// Copyright 2019-2024 ChainSafe Systems | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use crate::rpc::error::ServerError; | ||
use crate::rpc::types::ApiTipsetKey; | ||
use crate::rpc::types::*; | ||
use crate::rpc::{ApiVersion, Ctx, Permission, RpcMethod}; | ||
use crate::shim::{address::Address, econ::TokenAmount}; | ||
use fil_actor_interface::multisig; | ||
use fvm_ipld_blockstore::Blockstore; | ||
use num_bigint::BigInt; | ||
|
||
macro_rules! for_each_method { | ||
($callback:ident) => { | ||
$callback!(crate::rpc::msig::MsigGetAvailableBalance); | ||
$callback!(crate::rpc::msig::MsigGetPending); | ||
$callback!(crate::rpc::msig::MsigGetVested); | ||
$callback!(crate::rpc::msig::MsigGetVestingSchedule); | ||
}; | ||
} | ||
pub(crate) use for_each_method; | ||
|
||
pub enum MsigGetAvailableBalance {} | ||
|
||
impl RpcMethod<2> for MsigGetAvailableBalance { | ||
const NAME: &'static str = "Filecoin.MsigGetAvailableBalance"; | ||
const PARAM_NAMES: [&'static str; 2] = ["address", "tipset_key"]; | ||
const API_VERSION: ApiVersion = ApiVersion::V0; | ||
const PERMISSION: Permission = Permission::Read; | ||
|
||
type Params = (Address, ApiTipsetKey); | ||
type Ok = TokenAmount; | ||
|
||
async fn handle( | ||
ctx: Ctx<impl Blockstore>, | ||
(address, ApiTipsetKey(tsk)): Self::Params, | ||
) -> Result<Self::Ok, ServerError> { | ||
let ts = ctx.chain_store.load_required_tipset_or_heaviest(&tsk)?; | ||
let height = ts.epoch(); | ||
let actor = ctx | ||
.state_manager | ||
.get_required_actor(&address, *ts.parent_state())?; | ||
let actor_balance = TokenAmount::from(&actor.balance); | ||
let ms = multisig::State::load(ctx.store(), actor.code, actor.state)?; | ||
let locked_balance = ms.locked_balance(height)?.into(); | ||
let avail_balance = &actor_balance - locked_balance; | ||
Ok(avail_balance) | ||
} | ||
} | ||
|
||
pub enum MsigGetPending {} | ||
|
||
impl RpcMethod<2> for MsigGetPending { | ||
const NAME: &'static str = "Filecoin.MsigGetPending"; | ||
const PARAM_NAMES: [&'static str; 2] = ["address", "tipset_key"]; | ||
const API_VERSION: ApiVersion = ApiVersion::V0; | ||
const PERMISSION: Permission = Permission::Read; | ||
|
||
type Params = (Address, ApiTipsetKey); | ||
type Ok = Vec<Transaction>; | ||
|
||
async fn handle( | ||
ctx: Ctx<impl Blockstore>, | ||
(address, ApiTipsetKey(tsk)): Self::Params, | ||
) -> Result<Self::Ok, ServerError> { | ||
let ts = ctx.chain_store.load_required_tipset_or_heaviest(&tsk)?; | ||
let actor = ctx | ||
.state_manager | ||
.get_required_actor(&address, *ts.parent_state())?; | ||
let ms = multisig::State::load(ctx.store(), actor.code, actor.state)?; | ||
let txns = ms | ||
.get_pending_txn(ctx.store())? | ||
.iter() | ||
.map(|txn| Transaction { | ||
id: txn.id, | ||
to: txn.to.into(), | ||
value: txn.value.clone().into(), | ||
method: txn.method, | ||
params: txn.params.clone(), | ||
approved: txn.approved.iter().map(|item| item.into()).collect(), | ||
}) | ||
.collect(); | ||
Ok(txns) | ||
} | ||
} | ||
|
||
pub enum MsigGetVested {} | ||
impl RpcMethod<3> for MsigGetVested { | ||
const NAME: &'static str = "Filecoin.MsigGetVested"; | ||
const PARAM_NAMES: [&'static str; 3] = ["address", "start_tsk", "end_tsk"]; | ||
const API_VERSION: ApiVersion = ApiVersion::V0; | ||
const PERMISSION: Permission = Permission::Read; | ||
|
||
type Params = (Address, ApiTipsetKey, ApiTipsetKey); | ||
type Ok = BigInt; | ||
|
||
async fn handle( | ||
ctx: Ctx<impl Blockstore + Send + Sync + 'static>, | ||
(addr, ApiTipsetKey(start_tsk), ApiTipsetKey(end_tsk)): Self::Params, | ||
) -> Result<Self::Ok, ServerError> { | ||
let start_ts = ctx | ||
.chain_store | ||
.load_required_tipset_or_heaviest(&start_tsk)?; | ||
let end_ts = ctx.chain_store.load_required_tipset_or_heaviest(&end_tsk)?; | ||
|
||
match start_ts.epoch().cmp(&end_ts.epoch()) { | ||
std::cmp::Ordering::Greater => Err(ServerError::internal_error( | ||
"start tipset is after end tipset", | ||
None, | ||
)), | ||
std::cmp::Ordering::Equal => Ok(BigInt::from(0)), | ||
std::cmp::Ordering::Less => { | ||
let msig_actor = ctx | ||
.state_manager | ||
.get_required_actor(&addr, *end_ts.parent_state())?; | ||
let ms = multisig::State::load(ctx.store(), msig_actor.code, msig_actor.state)?; | ||
let start_lb: TokenAmount = ms.locked_balance(start_ts.epoch())?.into(); | ||
let end_lb: TokenAmount = ms.locked_balance(end_ts.epoch())?.into(); | ||
Ok(start_lb.atto() - end_lb.atto()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub enum MsigGetVestingSchedule {} | ||
impl RpcMethod<2> for MsigGetVestingSchedule { | ||
const NAME: &'static str = "Filecoin.MsigGetVestingSchedule"; | ||
const PARAM_NAMES: [&'static str; 2] = ["address", "tsk"]; | ||
const API_VERSION: ApiVersion = ApiVersion::V0; | ||
const PERMISSION: Permission = Permission::Read; | ||
|
||
type Params = (Address, ApiTipsetKey); | ||
type Ok = MsigVesting; | ||
|
||
async fn handle( | ||
ctx: Ctx<impl Blockstore + Send + Sync + 'static>, | ||
(addr, ApiTipsetKey(tsk)): Self::Params, | ||
) -> Result<Self::Ok, ServerError> { | ||
let ts = ctx.chain_store.load_required_tipset_or_heaviest(&tsk)?; | ||
|
||
let msig_actor = ctx | ||
.state_manager | ||
.get_required_actor(&addr, *ts.parent_state())?; | ||
let ms = multisig::State::load(ctx.store(), msig_actor.code, msig_actor.state)?; | ||
|
||
let msig_vesting = match &ms { | ||
multisig::State::V8(st) => MsigVesting { | ||
initial_balance: st.initial_balance.atto().clone(), | ||
start_epoch: st.start_epoch, | ||
unlock_duration: st.unlock_duration, | ||
}, | ||
multisig::State::V9(st) => MsigVesting { | ||
initial_balance: st.initial_balance.atto().clone(), | ||
start_epoch: st.start_epoch, | ||
unlock_duration: st.unlock_duration, | ||
}, | ||
multisig::State::V10(st) => MsigVesting { | ||
initial_balance: st.initial_balance.atto().clone(), | ||
start_epoch: st.start_epoch, | ||
unlock_duration: st.unlock_duration, | ||
}, | ||
multisig::State::V11(st) => MsigVesting { | ||
initial_balance: st.initial_balance.atto().clone(), | ||
start_epoch: st.start_epoch, | ||
unlock_duration: st.unlock_duration, | ||
}, | ||
multisig::State::V12(st) => MsigVesting { | ||
initial_balance: st.initial_balance.atto().clone(), | ||
start_epoch: st.start_epoch, | ||
unlock_duration: st.unlock_duration, | ||
}, | ||
multisig::State::V13(st) => MsigVesting { | ||
initial_balance: st.initial_balance.atto().clone(), | ||
start_epoch: st.start_epoch, | ||
unlock_duration: st.unlock_duration, | ||
}, | ||
}; | ||
|
||
Ok(msig_vesting) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a good place for this? @hanabi1224 implemented it
src/shim/actors/market/balance_table.rs
, which allows re-usability.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I remember we usually have this state matching code in
fil-actor-states
, I guess we should either keep it that way or move all of that logic out toshim
. It's much better to have all the similar logic in predictable places, otherwise it's hard to navigate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, we have a custom struct here. Then perhaps it belongs to
forest
.The stuff I was talking about before:
https://github.com/ChainSafe/fil-actor-states/blob/main/fil_actor_interface/src/builtin/market/mod.rs#L171
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved inside
src/shim/actors/multisig