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

feat: print beneficiary info in state miner-info #5348

Merged
merged 2 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions app/submodule/chain/miner_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func (msa *minerStateAPI) StateMinerInfo(ctx context.Context, maddr address.Addr
SectorSize: minfo.SectorSize,
WindowPoStPartitionSectors: minfo.WindowPoStPartitionSectors,
ConsensusFaultElapsed: minfo.ConsensusFaultElapsed,
Beneficiary: minfo.Beneficiary,
BeneficiaryTerm: &minfo.BeneficiaryTerm,
PendingBeneficiaryTerm: minfo.PendingBeneficiaryTerm,
}

if minfo.PendingWorkerKey != nil {
Expand Down
17 changes: 17 additions & 0 deletions cmd/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,23 @@ var minerInfoCmd = &cmds.Command{
}
writer.Printf("Total Spendable: %s\n", types.FIL(spendable).Short())

if mi.Beneficiary != address.Undef {
writer.Printf("Beneficiary:\t%s\n", mi.Beneficiary)
if mi.Beneficiary != mi.Owner {
writer.Printf("Beneficiary Quota:\t%s\n", mi.BeneficiaryTerm.Quota)
writer.Printf("Beneficiary Used Quota:\t%s\n", mi.BeneficiaryTerm.UsedQuota)
writer.Printf("Beneficiary Expiration:\t%s\n", mi.BeneficiaryTerm.Expiration)
}
}
if mi.PendingBeneficiaryTerm != nil {
writer.Printf("Pending Beneficiary Term:\n")
writer.Printf("New Beneficiary:\t%s\n", mi.PendingBeneficiaryTerm.NewBeneficiary)
writer.Printf("New Quota:\t%s\n", mi.PendingBeneficiaryTerm.NewQuota)
writer.Printf("New Expiration:\t%s\n", mi.PendingBeneficiaryTerm.NewExpiration)
writer.Printf("Approved By Beneficiary:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByBeneficiary)
writer.Printf("Approved By Nominee:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByNominee)
}

// TODO: grab actr state / info
// * Sealed sectors (count / bytes)
// * Power
Expand Down
10 changes: 8 additions & 2 deletions cmd/miner_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,15 @@ var actorSetPeeridCmd = &cmds.Command{

var actorWithdrawCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "withdraw available balance.",
Tagline: "withdraw available balance to beneficiary.",
},
Arguments: []cmds.Argument{
cmds.StringArg("address", true, false, "Address of miner to show"),
cmds.StringArg("amount", true, false, "[amount (FIL)]"),
},
Options: []cmds.Option{
cmds.Uint64Option("confidence", "number of block confirmations to wait for").WithDefault(constants.MessageConfidence),
cmds.BoolOption("beneficiary", "send withdraw message from the beneficiary address"),
},
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
ctx := req.Context
Expand Down Expand Up @@ -208,9 +209,14 @@ var actorWithdrawCmd = &cmds.Command{
return err
}

sender := mi.Owner
if beneficiary, _ := req.Options["beneficiary"].(bool); beneficiary {
sender = mi.Beneficiary
}

smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{
To: maddr,
From: mi.Owner,
From: sender,
Value: big.NewInt(0),
Method: builtintypes.MethodsMiner.WithdrawBalance,
Params: params,
Expand Down
85 changes: 44 additions & 41 deletions pkg/events/events_called.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ type triggerID = uint64
type msgH = abi.ChainEpoch

// triggerH is the block height at which the listener will be notified about the
// message (msgH+confidence)
//
// message (msgH+confidence)
type triggerH = abi.ChainEpoch

type eventData interface{}
Expand All @@ -38,7 +39,8 @@ type EventHandler func(ctx context.Context, data eventData, prevTs, ts *types.Ti
//
// If `done` is true, timeout won't be triggered
// If `more` is false, no messages will be sent to EventHandler (RevertHandler
// may still be called)
//
// may still be called)
type CheckFunc func(ctx context.Context, ts *types.TipSet) (done bool, more bool, err error)

// Keep track of information for an event handler
Expand Down Expand Up @@ -374,31 +376,31 @@ type StateMatchFunc func(oldTs, newTs *types.TipSet) (bool, StateChange, error)
// StateChanged registers a callback which is triggered when a specified state
// change occurs or a timeout is reached.
//
// * `CheckFunc` callback is invoked immediately with a recent tipset, it
// returns two booleans - `done`, and `more`.
// - `CheckFunc` callback is invoked immediately with a recent tipset, it
// returns two booleans - `done`, and `more`.
//
// * `done` should be true when some on-chain state change we are waiting
// - `done` should be true when some on-chain state change we are waiting
// for has happened. When `done` is set to true, timeout trigger is disabled.
//
// * `more` should be false when we don't want to receive new notifications
// - `more` should be false when we don't want to receive new notifications
// through StateChangeHandler. Note that notifications may still be delivered to
// RevertHandler
//
// * `StateChangeHandler` is called when the specified state change was observed
// on-chain, and a confidence threshold was reached, or the specified `timeout`
// height was reached with no state change observed. When this callback is
// invoked on a timeout, `oldTs` and `states are set to nil.
// This callback returns a boolean specifying whether further notifications
// should be sent, like `more` return param from `CheckFunc` above.
// - `StateChangeHandler` is called when the specified state change was observed
// on-chain, and a confidence threshold was reached, or the specified `timeout`
// height was reached with no state change observed. When this callback is
// invoked on a timeout, `oldTs` and `states are set to nil.
// This callback returns a boolean specifying whether further notifications
// should be sent, like `more` return param from `CheckFunc` above.
//
// * `RevertHandler` is called after apply handler, when we drop the tipset
// containing the message. The tipset passed as the argument is the tipset
// that is being dropped. Note that the event dropped may be re-applied
// in a different tipset in small amount of time.
// - `RevertHandler` is called after apply handler, when we drop the tipset
// containing the message. The tipset passed as the argument is the tipset
// that is being dropped. Note that the event dropped may be re-applied
// in a different tipset in small amount of time.
//
// * `StateMatchFunc` is called against each tipset state. If there is a match,
// the state change is queued up until the confidence interval has elapsed (and
// `StateChangeHandler` is called)
// - `StateMatchFunc` is called against each tipset state. If there is a match,
// the state change is queued up until the confidence interval has elapsed (and
// `StateChangeHandler` is called)
func (we *watcherEvents) StateChanged(check CheckFunc, scHnd StateChangeHandler, rev RevertHandler, confidence int, timeout abi.ChainEpoch, mf StateMatchFunc) error {
hnd := func(ctx context.Context, data eventData, prevTs, ts *types.TipSet, height abi.ChainEpoch) (bool, error) {
states, ok := data.(StateChange)
Expand Down Expand Up @@ -502,33 +504,34 @@ type MsgHandler func(msg *types.Message, rec *types.MessageReceipt, ts *types.Ti
type MsgMatchFunc func(msg *types.Message) (matched bool, err error)

// Called registers a callback which is triggered when a specified method is
// called on an actor, or a timeout is reached.
//
// * `CheckFunc` callback is invoked immediately with a recent tipset, it
// returns two booleans - `done`, and `more`.
// called on an actor, or a timeout is reached.
//
// * `done` should be true when some on-chain action we are waiting for has
// happened. When `done` is set to true, timeout trigger is disabled.
// - `CheckFunc` callback is invoked immediately with a recent tipset, it
// returns two booleans - `done`, and `more`.
//
// * `more` should be false when we don't want to receive new notifications
// through MsgHandler. Note that notifications may still be delivered to
// RevertHandler
// - `done` should be true when some on-chain action we are waiting for has
// happened. When `done` is set to true, timeout trigger is disabled.
//
// * `MsgHandler` is called when the specified event was observed on-chain,
// and a confidence threshold was reached, or the specified `timeout` height
// was reached with no events observed. When this callback is invoked on a
// timeout, `msg` is set to nil. This callback returns a boolean specifying
// whether further notifications should be sent, like `more` return param
// from `CheckFunc` above.
// - `more` should be false when we don't want to receive new notifications
// through MsgHandler. Note that notifications may still be delivered to
// RevertHandler
//
// * `RevertHandler` is called after apply handler, when we drop the tipset
// containing the message. The tipset passed as the argument is the tipset
// that is being dropped. Note that the message dropped may be re-applied
// in a different tipset in small amount of time.
// - `MsgHandler` is called when the specified event was observed on-chain,
// and a confidence threshold was reached, or the specified `timeout` height
// was reached with no events observed. When this callback is invoked on a
// timeout, `msg` is set to nil. This callback returns a boolean specifying
// whether further notifications should be sent, like `more` return param
// from `CheckFunc` above.
//
// * `MsgMatchFunc` is called against each message. If there is a match, the
// message is queued up until the confidence interval has elapsed (and
// `MsgHandler` is called)
// - `RevertHandler` is called after apply handler, when we drop the tipset
// containing the message. The tipset passed as the argument is the tipset
// that is being dropped. Note that the message dropped may be re-applied
// in a different tipset in small amount of time.
//
// - `MsgMatchFunc` is called against each message. If there is a match, the
// message is queued up until the confidence interval has elapsed (and
// `MsgHandler` is called)
func (me *messageEvents) Called(ctx context.Context, check CheckFunc, msgHnd MsgHandler, rev RevertHandler, confidence int, timeout abi.ChainEpoch, mf MsgMatchFunc) error {
hnd := func(ctx context.Context, data eventData, prevTs, ts *types.TipSet, height abi.ChainEpoch) (bool, error) {
msg, ok := data.(*types.Message)
Expand All @@ -550,7 +553,7 @@ func (me *messageEvents) Called(ctx context.Context, check CheckFunc, msgHnd Msg

id, err := me.hcAPI.onHeadChanged(ctx, check, hnd, rev, confidence, timeout)
if err != nil {
return err
return fmt.Errorf("on head changed error: %w", err)
}

me.lk.Lock()
Expand Down
15 changes: 14 additions & 1 deletion venus-shared/api/chain/v0/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,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 venus-shared/api/chain/v1/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -3461,7 +3461,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
2 changes: 0 additions & 2 deletions venus-shared/compatible-checks/api-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v0.FullNode <> github.c
- StateGetRandomnessFromBeacon
- StateGetRandomnessFromTickets
- StateListMessages
> StateMinerInfo {[func(context.Context, address.Address, types.TipSetKey) (types.MinerInfo, error) <> func(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error)] base=func out type: #0 input; nested={[types.MinerInfo <> api.MinerInfo] base=struct field; nested={[types.MinerInfo <> api.MinerInfo] base=exported fields count: 11 != 14; nested=nil}}}
+ StateMinerSectorSize
+ StateMinerWorkerAddress
- StateReadState
Expand Down Expand Up @@ -202,7 +201,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c
- Shutdown
- StateCompute
> StateGetNetworkParams {[func(context.Context) (*types.NetworkParams, error) <> func(context.Context) (*api.NetworkParams, error)] base=func out type: #0 input; nested={[*types.NetworkParams <> *api.NetworkParams] base=pointed type; nested={[types.NetworkParams <> api.NetworkParams] base=struct field; nested={[types.NetworkParams <> api.NetworkParams] base=exported field type: #5 field named ForkUpgradeParams; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=struct field; nested={[types.ForkUpgradeParams <> api.ForkUpgradeParams] base=exported field name: #8 field, BreezeGasTampingDuration != UpgradePriceListOopsHeight; nested=nil}}}}}}
> StateMinerInfo {[func(context.Context, address.Address, types.TipSetKey) (types.MinerInfo, error) <> func(context.Context, address.Address, types.TipSetKey) (api.MinerInfo, error)] base=func out type: #0 input; nested={[types.MinerInfo <> api.MinerInfo] base=struct field; nested={[types.MinerInfo <> api.MinerInfo] base=exported fields count: 11 != 14; nested=nil}}}
+ StateMinerSectorSize
+ StateMinerWorkerAddress
- StateReplay
Expand Down
4 changes: 4 additions & 0 deletions venus-shared/types/api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/libp2p/go-libp2p/core/peer"

"github.com/filecoin-project/go-state-types/builtin/v8/market"
"github.com/filecoin-project/go-state-types/builtin/v9/miner"

"github.com/filecoin-project/venus/venus-shared/actors/builtin"
"github.com/filecoin-project/venus/venus-shared/actors/builtin/power"
Expand Down Expand Up @@ -349,6 +350,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