Skip to content

Commit

Permalink
Merge pull request #9296 from filecoin-project/gstuart/beneficiary-wi…
Browse files Browse the repository at this point in the history
…thdraw-api

feat: api/cli: beneficiary withdraw api and cli
  • Loading branch information
geoff-vball authored Sep 14, 2022
2 parents 3e8eaa8 + d94cdaa commit f567db6
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 9 deletions.
5 changes: 5 additions & 0 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ type StorageMiner interface {
// and does not wait for message execution
ActorWithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) //perm:admin

// BeneficiaryWithdrawBalance allows the beneficiary of a miner to withdraw balance from miner actor
// Specify amount as "0" to withdraw full balance. This method returns a message CID
// and does not wait for message execution
BeneficiaryWithdrawBalance(context.Context, abi.TokenAmount) (cid.Cid, error) //perm:admin

MiningBase(context.Context) (*types.TipSet, error) //perm:read

ComputeWindowPoSt(ctx context.Context, dlIdx uint64, tsk types.TipSetKey) ([]miner.SubmitWindowedPoStParams, error) //perm:admin
Expand Down
13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
datatransfer "github.com/filecoin-project/go-data-transfer"
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/builtin/v9/miner"

"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/node/modules/dtypes"
Expand Down Expand Up @@ -295,6 +296,9 @@ type MinerInfo struct {
SectorSize abi.SectorSize
WindowPoStPartitionSectors uint64
ConsensusFaultElapsed abi.ChainEpoch
Beneficiary address.Address
BeneficiaryTerm *miner.BeneficiaryTerm
PendingBeneficiaryTerm *miner.PendingBeneficiaryChange
}

type NetworkParams struct {
Expand Down
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
14 changes: 12 additions & 2 deletions cmd/lotus-miner/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/fatih/color"
"github.com/ipfs/go-cid"
cbor "github.com/ipfs/go-ipld-cbor"
"github.com/libp2p/go-libp2p/core/peer"
ma "github.com/multiformats/go-multiaddr"
Expand Down Expand Up @@ -232,14 +233,18 @@ var actorSetPeeridCmd = &cli.Command{

var actorWithdrawCmd = &cli.Command{
Name: "withdraw",
Usage: "withdraw available balance",
Usage: "withdraw available balance to beneficiary",
ArgsUsage: "[amount (FIL)]",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "confidence",
Usage: "number of block confirmations to wait for",
Value: int(build.MessageConfidence),
},
&cli.BoolFlag{
Name: "beneficiary",
Usage: "send withdraw message from the beneficiary address",
},
},
Action: func(cctx *cli.Context) error {
amount := abi.NewTokenAmount(0)
Expand Down Expand Up @@ -267,7 +272,12 @@ var actorWithdrawCmd = &cli.Command{

ctx := lcli.ReqContext(cctx)

res, err := nodeApi.ActorWithdrawBalance(ctx, amount)
var res cid.Cid
if cctx.IsSet("beneficiary") {
res, err = nodeApi.BeneficiaryWithdrawBalance(ctx, amount)
} else {
res, err = nodeApi.ActorWithdrawBalance(ctx, amount)
}
if err != nil {
return err
}
Expand Down
15 changes: 13 additions & 2 deletions cmd/lotus-shed/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var actorCmd = &cli.Command{

var actorWithdrawCmd = &cli.Command{
Name: "withdraw",
Usage: "withdraw available balance",
Usage: "withdraw available balance to beneficiary",
ArgsUsage: "[amount (FIL)]",
Flags: []cli.Flag{
&cli.StringFlag{
Expand All @@ -50,6 +50,10 @@ var actorWithdrawCmd = &cli.Command{
Usage: "number of block confirmations to wait for",
Value: int(build.MessageConfidence),
},
&cli.BoolFlag{
Name: "beneficiary",
Usage: "send withdraw message from the beneficiary address",
},
},
Action: func(cctx *cli.Context) error {
var maddr address.Address
Expand Down Expand Up @@ -113,9 +117,16 @@ var actorWithdrawCmd = &cli.Command{
return err
}

var sender address.Address
if cctx.IsSet("beneficiary") {
sender = mi.Beneficiary
} else {
sender = mi.Owner
}

smsg, err := nodeAPI.MpoolPushMessage(ctx, &types.Message{
To: maddr,
From: mi.Owner,
From: sender,
Value: types.NewInt(0),
Method: builtin.MethodsMiner.WithdrawBalance,
Params: params,
Expand Down
27 changes: 27 additions & 0 deletions documentation/en/api-v0-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* [Auth](#Auth)
* [AuthNew](#AuthNew)
* [AuthVerify](#AuthVerify)
* [Beneficiary](#Beneficiary)
* [BeneficiaryWithdrawBalance](#BeneficiaryWithdrawBalance)
* [Check](#Check)
* [CheckProvable](#CheckProvable)
* [Compute](#Compute)
Expand Down Expand Up @@ -364,6 +366,31 @@ Response:
]
```

## Beneficiary


### BeneficiaryWithdrawBalance
BeneficiaryWithdrawBalance allows the beneficiary of a miner to withdraw balance from miner actor
Specify amount as "0" to withdraw full balance. This method returns a message CID
and does not wait for message execution


Perms: admin

Inputs:
```json
[
"0"
]
```

Response:
```json
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
}
```

## Check


Expand Down
15 changes: 14 additions & 1 deletion documentation/en/api-v0-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -5811,7 +5811,20 @@ Response:
"WindowPoStProofType": 8,
"SectorSize": 34359738368,
"WindowPoStPartitionSectors": 42,
"ConsensusFaultElapsed": 10101
"ConsensusFaultElapsed": 10101,
"Beneficiary": "f01234",
"BeneficiaryTerm": {
"Quota": "0",
"UsedQuota": "0",
"Expiration": 10101
},
"PendingBeneficiaryTerm": {
"NewBeneficiary": "f01234",
"NewQuota": "0",
"NewExpiration": 10101,
"ApprovedByBeneficiary": true,
"ApprovedByNominee": true
}
}
```

Expand Down
15 changes: 14 additions & 1 deletion documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -6328,7 +6328,20 @@ Response:
"WindowPoStProofType": 8,
"SectorSize": 34359738368,
"WindowPoStPartitionSectors": 42,
"ConsensusFaultElapsed": 10101
"ConsensusFaultElapsed": 10101,
"Beneficiary": "f01234",
"BeneficiaryTerm": {
"Quota": "0",
"UsedQuota": "0",
"Expiration": 10101
},
"PendingBeneficiaryTerm": {
"NewBeneficiary": "f01234",
"NewQuota": "0",
"NewExpiration": 10101,
"ApprovedByBeneficiary": true,
"ApprovedByNominee": true
}
}
```

Expand Down
5 changes: 3 additions & 2 deletions documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ USAGE:
COMMANDS:
set-addresses, set-addrs set addresses that your miner can be publicly dialed on
withdraw withdraw available balance
withdraw withdraw available balance to beneficiary
repay-debt pay down a miner's debt
set-peer-id set the peer id of your miner
set-owner Set owner address (this command should be invoked twice, first with the old owner as the senderAddress, and then with the new owner)
Expand All @@ -254,12 +254,13 @@ OPTIONS:
### lotus-miner actor withdraw
```
NAME:
lotus-miner actor withdraw - withdraw available balance
lotus-miner actor withdraw - withdraw available balance to beneficiary
USAGE:
lotus-miner actor withdraw [command options] [amount (FIL)]
OPTIONS:
--beneficiary send withdraw message from the beneficiary address (default: false)
--confidence value number of block confirmations to wait for (default: 5)
```
Expand Down
3 changes: 3 additions & 0 deletions node/impl/full/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func (m *StateModule) StateMinerInfo(ctx context.Context, actor address.Address,
SectorSize: info.SectorSize,
WindowPoStPartitionSectors: info.WindowPoStPartitionSectors,
ConsensusFaultElapsed: info.ConsensusFaultElapsed,
Beneficiary: info.Beneficiary,
BeneficiaryTerm: &info.BeneficiaryTerm,
PendingBeneficiaryTerm: info.PendingBeneficiaryTerm,
}

if info.PendingWorkerKey != nil {
Expand Down
17 changes: 16 additions & 1 deletion node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,14 @@ func (sm *StorageMinerAPI) RuntimeSubsystems(context.Context) (res api.MinerSubs
}

func (sm *StorageMinerAPI) ActorWithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) {
return sm.withdrawBalance(ctx, amount, true)
}

func (sm *StorageMinerAPI) BeneficiaryWithdrawBalance(ctx context.Context, amount abi.TokenAmount) (cid.Cid, error) {
return sm.withdrawBalance(ctx, amount, false)
}

func (sm *StorageMinerAPI) withdrawBalance(ctx context.Context, amount abi.TokenAmount, fromOwner bool) (cid.Cid, error) {
available, err := sm.Full.StateMinerAvailableBalance(ctx, sm.Miner.Address(), types.EmptyTSK)
if err != nil {
return cid.Undef, xerrors.Errorf("Error getting miner balance: %w", err)
Expand All @@ -1374,9 +1382,16 @@ func (sm *StorageMinerAPI) ActorWithdrawBalance(ctx context.Context, amount abi.
return cid.Undef, xerrors.Errorf("Error getting miner's owner address: %w", err)
}

var sender address.Address
if fromOwner {
sender = mi.Owner
} else {
sender = mi.Beneficiary
}

smsg, err := sm.Full.MpoolPushMessage(ctx, &types.Message{
To: sm.Miner.Address(),
From: mi.Owner,
From: sender,
Value: types.NewInt(0),
Method: builtintypes.MethodsMiner.WithdrawBalance,
Params: params,
Expand Down

0 comments on commit f567db6

Please sign in to comment.