From e31d9cbb7c1c8b3995172146cef2ece45d636c09 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Wed, 28 Sep 2022 14:44:23 +0800 Subject: [PATCH 1/2] feat: print beneficiary info in state miner-info --- cmd/miner.go | 17 ++++++++ cmd/miner_actor.go | 10 ++++- pkg/events/events_called.go | 85 +++++++++++++++++++------------------ 3 files changed, 69 insertions(+), 43 deletions(-) diff --git a/cmd/miner.go b/cmd/miner.go index bed6bde4e2..1e0e74762a 100644 --- a/cmd/miner.go +++ b/cmd/miner.go @@ -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 diff --git a/cmd/miner_actor.go b/cmd/miner_actor.go index 75d19f0fcc..9890fdc5bb 100644 --- a/cmd/miner_actor.go +++ b/cmd/miner_actor.go @@ -163,7 +163,7 @@ 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"), @@ -171,6 +171,7 @@ var actorWithdrawCmd = &cmds.Command{ }, 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 @@ -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, diff --git a/pkg/events/events_called.go b/pkg/events/events_called.go index e5f10b3d12..1ee53f91fe 100644 --- a/pkg/events/events_called.go +++ b/pkg/events/events_called.go @@ -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{} @@ -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 @@ -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) @@ -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) @@ -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() From a3ade91fd248d4d336524609629932bcef27716f Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Sat, 8 Oct 2022 13:23:35 +0800 Subject: [PATCH 2/2] feat: add beneficiary info for MinerInfo --- app/submodule/chain/miner_api.go | 3 +++ venus-shared/api/chain/v0/method.md | 15 ++++++++++++++- venus-shared/api/chain/v1/method.md | 15 ++++++++++++++- venus-shared/compatible-checks/api-diff.txt | 2 -- venus-shared/types/api_types.go | 4 ++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/submodule/chain/miner_api.go b/app/submodule/chain/miner_api.go index 479192e5a8..ee59ea5ddf 100644 --- a/app/submodule/chain/miner_api.go +++ b/app/submodule/chain/miner_api.go @@ -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 { diff --git a/venus-shared/api/chain/v0/method.md b/venus-shared/api/chain/v0/method.md index 4ef8596fc2..2f946d8185 100644 --- a/venus-shared/api/chain/v0/method.md +++ b/venus-shared/api/chain/v0/method.md @@ -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 + } } ``` diff --git a/venus-shared/api/chain/v1/method.md b/venus-shared/api/chain/v1/method.md index ed1a36f4db..9edb4b01e1 100644 --- a/venus-shared/api/chain/v1/method.md +++ b/venus-shared/api/chain/v1/method.md @@ -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 + } } ``` diff --git a/venus-shared/compatible-checks/api-diff.txt b/venus-shared/compatible-checks/api-diff.txt index 70e9d0d81a..0817664219 100644 --- a/venus-shared/compatible-checks/api-diff.txt +++ b/venus-shared/compatible-checks/api-diff.txt @@ -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 @@ -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 diff --git a/venus-shared/types/api_types.go b/venus-shared/types/api_types.go index 610df5adfa..8ee07d2b18 100644 --- a/venus-shared/types/api_types.go +++ b/venus-shared/types/api_types.go @@ -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" @@ -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 {