Skip to content

Commit

Permalink
feat(rpc): Add MpoolPushUntrusted as an alias of MpoolPush (#4547)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemmih authored Jul 17, 2024
1 parent 7794269 commit c46451b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
- [#4474](https://github.com/ChainSafe/forest/pull/4474) Add new subcommand
`forest-cli healthcheck ready`.

- [#4547](https://github.com/ChainSafe/forest/pull/4547) Add support for the
`Filecoin.MpoolPushUntrusted` RPC method.

### Changed

### Removed
Expand Down
26 changes: 26 additions & 0 deletions src/rpc/methods/mpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,32 @@ impl RpcMethod<1> for MpoolPush {
}
}

/// Add `SignedMessage` from untrusted source to `mpool`, return message CID
pub enum MpoolPushUntrusted {}
impl RpcMethod<1> for MpoolPushUntrusted {
const NAME: &'static str = "Filecoin.MpoolPushUntrusted";
const PARAM_NAMES: [&'static str; 1] = ["msg"];
const API_PATHS: ApiPaths = ApiPaths::V0;
/// Lotus limits this method to [`Permission::Write`].
/// However, since messages can always be pushed over the p2p protocol,
/// limiting the RPC doesn't improve security.
const PERMISSION: Permission = Permission::Read;

type Params = (SignedMessage,);
type Ok = Cid;

async fn handle(
ctx: Ctx<impl Blockstore + Send + Sync + 'static>,
(msg,): Self::Params,
) -> Result<Self::Ok, ServerError> {
// Lotus implements a few extra sanity checks that we skip. We skip them
// because those checks aren't used for messages received from peers and
// therefore aren't safety critical.
let cid = ctx.mpool.as_ref().push(msg).await?;
Ok(cid)
}
}

/// Sign given `UnsignedMessage` and add it to `mpool`, return `SignedMessage`
pub enum MpoolPushMessage {}
impl RpcMethod<2> for MpoolPushMessage {
Expand Down
1 change: 1 addition & 0 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ macro_rules! for_each_method {
$callback!(crate::rpc::mpool::MpoolPending);
$callback!(crate::rpc::mpool::MpoolSelect);
$callback!(crate::rpc::mpool::MpoolPush);
$callback!(crate::rpc::mpool::MpoolPushUntrusted);
$callback!(crate::rpc::mpool::MpoolPushMessage);

// msig vertical
Expand Down

0 comments on commit c46451b

Please sign in to comment.