Skip to content

Commit f4efb3c

Browse files
authored
feat: print beneficiary info in state miner-info (#5348)
* feat: print beneficiary info in state miner-info * feat: add beneficiary info for MinerInfo
1 parent a122811 commit f4efb3c

File tree

8 files changed

+104
-47
lines changed

8 files changed

+104
-47
lines changed

app/submodule/chain/miner_api.go

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ func (msa *minerStateAPI) StateMinerInfo(ctx context.Context, maddr address.Addr
135135
SectorSize: minfo.SectorSize,
136136
WindowPoStPartitionSectors: minfo.WindowPoStPartitionSectors,
137137
ConsensusFaultElapsed: minfo.ConsensusFaultElapsed,
138+
Beneficiary: minfo.Beneficiary,
139+
BeneficiaryTerm: &minfo.BeneficiaryTerm,
140+
PendingBeneficiaryTerm: minfo.PendingBeneficiaryTerm,
138141
}
139142

140143
if minfo.PendingWorkerKey != nil {

cmd/miner.go

+17
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,23 @@ var minerInfoCmd = &cmds.Command{
382382
}
383383
writer.Printf("Total Spendable: %s\n", types.FIL(spendable).Short())
384384

385+
if mi.Beneficiary != address.Undef {
386+
writer.Printf("Beneficiary:\t%s\n", mi.Beneficiary)
387+
if mi.Beneficiary != mi.Owner {
388+
writer.Printf("Beneficiary Quota:\t%s\n", mi.BeneficiaryTerm.Quota)
389+
writer.Printf("Beneficiary Used Quota:\t%s\n", mi.BeneficiaryTerm.UsedQuota)
390+
writer.Printf("Beneficiary Expiration:\t%s\n", mi.BeneficiaryTerm.Expiration)
391+
}
392+
}
393+
if mi.PendingBeneficiaryTerm != nil {
394+
writer.Printf("Pending Beneficiary Term:\n")
395+
writer.Printf("New Beneficiary:\t%s\n", mi.PendingBeneficiaryTerm.NewBeneficiary)
396+
writer.Printf("New Quota:\t%s\n", mi.PendingBeneficiaryTerm.NewQuota)
397+
writer.Printf("New Expiration:\t%s\n", mi.PendingBeneficiaryTerm.NewExpiration)
398+
writer.Printf("Approved By Beneficiary:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByBeneficiary)
399+
writer.Printf("Approved By Nominee:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByNominee)
400+
}
401+
385402
// TODO: grab actr state / info
386403
// * Sealed sectors (count / bytes)
387404
// * Power

cmd/miner_actor.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,15 @@ var actorSetPeeridCmd = &cmds.Command{
163163

164164
var actorWithdrawCmd = &cmds.Command{
165165
Helptext: cmds.HelpText{
166-
Tagline: "withdraw available balance.",
166+
Tagline: "withdraw available balance to beneficiary.",
167167
},
168168
Arguments: []cmds.Argument{
169169
cmds.StringArg("address", true, false, "Address of miner to show"),
170170
cmds.StringArg("amount", true, false, "[amount (FIL)]"),
171171
},
172172
Options: []cmds.Option{
173173
cmds.Uint64Option("confidence", "number of block confirmations to wait for").WithDefault(constants.MessageConfidence),
174+
cmds.BoolOption("beneficiary", "send withdraw message from the beneficiary address"),
174175
},
175176
Run: func(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment) error {
176177
ctx := req.Context
@@ -208,9 +209,14 @@ var actorWithdrawCmd = &cmds.Command{
208209
return err
209210
}
210211

212+
sender := mi.Owner
213+
if beneficiary, _ := req.Options["beneficiary"].(bool); beneficiary {
214+
sender = mi.Beneficiary
215+
}
216+
211217
smsg, err := env.(*node.Env).MessagePoolAPI.MpoolPushMessage(ctx, &types.Message{
212218
To: maddr,
213-
From: mi.Owner,
219+
From: sender,
214220
Value: big.NewInt(0),
215221
Method: builtintypes.MethodsMiner.WithdrawBalance,
216222
Params: params,

pkg/events/events_called.go

+44-41
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ type triggerID = uint64
2222
type msgH = abi.ChainEpoch
2323

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

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

4446
// Keep track of information for an event handler
@@ -374,31 +376,31 @@ type StateMatchFunc func(oldTs, newTs *types.TipSet) (bool, StateChange, error)
374376
// StateChanged registers a callback which is triggered when a specified state
375377
// change occurs or a timeout is reached.
376378
//
377-
// * `CheckFunc` callback is invoked immediately with a recent tipset, it
378-
// returns two booleans - `done`, and `more`.
379+
// - `CheckFunc` callback is invoked immediately with a recent tipset, it
380+
// returns two booleans - `done`, and `more`.
379381
//
380-
// * `done` should be true when some on-chain state change we are waiting
382+
// - `done` should be true when some on-chain state change we are waiting
381383
// for has happened. When `done` is set to true, timeout trigger is disabled.
382384
//
383-
// * `more` should be false when we don't want to receive new notifications
385+
// - `more` should be false when we don't want to receive new notifications
384386
// through StateChangeHandler. Note that notifications may still be delivered to
385387
// RevertHandler
386388
//
387-
// * `StateChangeHandler` is called when the specified state change was observed
388-
// on-chain, and a confidence threshold was reached, or the specified `timeout`
389-
// height was reached with no state change observed. When this callback is
390-
// invoked on a timeout, `oldTs` and `states are set to nil.
391-
// This callback returns a boolean specifying whether further notifications
392-
// should be sent, like `more` return param from `CheckFunc` above.
389+
// - `StateChangeHandler` is called when the specified state change was observed
390+
// on-chain, and a confidence threshold was reached, or the specified `timeout`
391+
// height was reached with no state change observed. When this callback is
392+
// invoked on a timeout, `oldTs` and `states are set to nil.
393+
// This callback returns a boolean specifying whether further notifications
394+
// should be sent, like `more` return param from `CheckFunc` above.
393395
//
394-
// * `RevertHandler` is called after apply handler, when we drop the tipset
395-
// containing the message. The tipset passed as the argument is the tipset
396-
// that is being dropped. Note that the event dropped may be re-applied
397-
// in a different tipset in small amount of time.
396+
// - `RevertHandler` is called after apply handler, when we drop the tipset
397+
// containing the message. The tipset passed as the argument is the tipset
398+
// that is being dropped. Note that the event dropped may be re-applied
399+
// in a different tipset in small amount of time.
398400
//
399-
// * `StateMatchFunc` is called against each tipset state. If there is a match,
400-
// the state change is queued up until the confidence interval has elapsed (and
401-
// `StateChangeHandler` is called)
401+
// - `StateMatchFunc` is called against each tipset state. If there is a match,
402+
// the state change is queued up until the confidence interval has elapsed (and
403+
// `StateChangeHandler` is called)
402404
func (we *watcherEvents) StateChanged(check CheckFunc, scHnd StateChangeHandler, rev RevertHandler, confidence int, timeout abi.ChainEpoch, mf StateMatchFunc) error {
403405
hnd := func(ctx context.Context, data eventData, prevTs, ts *types.TipSet, height abi.ChainEpoch) (bool, error) {
404406
states, ok := data.(StateChange)
@@ -502,33 +504,34 @@ type MsgHandler func(msg *types.Message, rec *types.MessageReceipt, ts *types.Ti
502504
type MsgMatchFunc func(msg *types.Message) (matched bool, err error)
503505

504506
// Called registers a callback which is triggered when a specified method is
505-
// called on an actor, or a timeout is reached.
506507
//
507-
// * `CheckFunc` callback is invoked immediately with a recent tipset, it
508-
// returns two booleans - `done`, and `more`.
508+
// called on an actor, or a timeout is reached.
509509
//
510-
// * `done` should be true when some on-chain action we are waiting for has
511-
// happened. When `done` is set to true, timeout trigger is disabled.
510+
// - `CheckFunc` callback is invoked immediately with a recent tipset, it
511+
// returns two booleans - `done`, and `more`.
512512
//
513-
// * `more` should be false when we don't want to receive new notifications
514-
// through MsgHandler. Note that notifications may still be delivered to
515-
// RevertHandler
513+
// - `done` should be true when some on-chain action we are waiting for has
514+
// happened. When `done` is set to true, timeout trigger is disabled.
516515
//
517-
// * `MsgHandler` is called when the specified event was observed on-chain,
518-
// and a confidence threshold was reached, or the specified `timeout` height
519-
// was reached with no events observed. When this callback is invoked on a
520-
// timeout, `msg` is set to nil. This callback returns a boolean specifying
521-
// whether further notifications should be sent, like `more` return param
522-
// from `CheckFunc` above.
516+
// - `more` should be false when we don't want to receive new notifications
517+
// through MsgHandler. Note that notifications may still be delivered to
518+
// RevertHandler
523519
//
524-
// * `RevertHandler` is called after apply handler, when we drop the tipset
525-
// containing the message. The tipset passed as the argument is the tipset
526-
// that is being dropped. Note that the message dropped may be re-applied
527-
// in a different tipset in small amount of time.
520+
// - `MsgHandler` is called when the specified event was observed on-chain,
521+
// and a confidence threshold was reached, or the specified `timeout` height
522+
// was reached with no events observed. When this callback is invoked on a
523+
// timeout, `msg` is set to nil. This callback returns a boolean specifying
524+
// whether further notifications should be sent, like `more` return param
525+
// from `CheckFunc` above.
528526
//
529-
// * `MsgMatchFunc` is called against each message. If there is a match, the
530-
// message is queued up until the confidence interval has elapsed (and
531-
// `MsgHandler` is called)
527+
// - `RevertHandler` is called after apply handler, when we drop the tipset
528+
// containing the message. The tipset passed as the argument is the tipset
529+
// that is being dropped. Note that the message dropped may be re-applied
530+
// in a different tipset in small amount of time.
531+
//
532+
// - `MsgMatchFunc` is called against each message. If there is a match, the
533+
// message is queued up until the confidence interval has elapsed (and
534+
// `MsgHandler` is called)
532535
func (me *messageEvents) Called(ctx context.Context, check CheckFunc, msgHnd MsgHandler, rev RevertHandler, confidence int, timeout abi.ChainEpoch, mf MsgMatchFunc) error {
533536
hnd := func(ctx context.Context, data eventData, prevTs, ts *types.TipSet, height abi.ChainEpoch) (bool, error) {
534537
msg, ok := data.(*types.Message)
@@ -550,7 +553,7 @@ func (me *messageEvents) Called(ctx context.Context, check CheckFunc, msgHnd Msg
550553

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

556559
me.lk.Lock()

venus-shared/api/chain/v0/method.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -3133,7 +3133,20 @@ Response:
31333133
"WindowPoStProofType": 8,
31343134
"SectorSize": 34359738368,
31353135
"WindowPoStPartitionSectors": 42,
3136-
"ConsensusFaultElapsed": 10101
3136+
"ConsensusFaultElapsed": 10101,
3137+
"Beneficiary": "f01234",
3138+
"BeneficiaryTerm": {
3139+
"Quota": "0",
3140+
"UsedQuota": "0",
3141+
"Expiration": 10101
3142+
},
3143+
"PendingBeneficiaryTerm": {
3144+
"NewBeneficiary": "f01234",
3145+
"NewQuota": "0",
3146+
"NewExpiration": 10101,
3147+
"ApprovedByBeneficiary": true,
3148+
"ApprovedByNominee": true
3149+
}
31373150
}
31383151
```
31393152

venus-shared/api/chain/v1/method.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -3461,7 +3461,20 @@ Response:
34613461
"WindowPoStProofType": 8,
34623462
"SectorSize": 34359738368,
34633463
"WindowPoStPartitionSectors": 42,
3464-
"ConsensusFaultElapsed": 10101
3464+
"ConsensusFaultElapsed": 10101,
3465+
"Beneficiary": "f01234",
3466+
"BeneficiaryTerm": {
3467+
"Quota": "0",
3468+
"UsedQuota": "0",
3469+
"Expiration": 10101
3470+
},
3471+
"PendingBeneficiaryTerm": {
3472+
"NewBeneficiary": "f01234",
3473+
"NewQuota": "0",
3474+
"NewExpiration": 10101,
3475+
"ApprovedByBeneficiary": true,
3476+
"ApprovedByNominee": true
3477+
}
34653478
}
34663479
```
34673480

venus-shared/compatible-checks/api-diff.txt

-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v0.FullNode <> github.c
8888
- StateGetRandomnessFromBeacon
8989
- StateGetRandomnessFromTickets
9090
- StateListMessages
91-
> 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}}}
9291
+ StateMinerSectorSize
9392
+ StateMinerWorkerAddress
9493
- StateReadState
@@ -202,7 +201,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c
202201
- Shutdown
203202
- StateCompute
204203
> 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}}}}}}
205-
> 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}}}
206204
+ StateMinerSectorSize
207205
+ StateMinerWorkerAddress
208206
- StateReplay

venus-shared/types/api_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/libp2p/go-libp2p/core/peer"
1414

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

1718
"github.com/filecoin-project/venus/venus-shared/actors/builtin"
1819
"github.com/filecoin-project/venus/venus-shared/actors/builtin/power"
@@ -349,6 +350,9 @@ type MinerInfo struct {
349350
SectorSize abi.SectorSize
350351
WindowPoStPartitionSectors uint64
351352
ConsensusFaultElapsed abi.ChainEpoch
353+
Beneficiary address.Address
354+
BeneficiaryTerm *miner.BeneficiaryTerm
355+
PendingBeneficiaryTerm *miner.PendingBeneficiaryChange
352356
}
353357

354358
type NetworkParams struct {

0 commit comments

Comments
 (0)