Skip to content

Commit

Permalink
miner: Config to disable owner/worker addcess fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 17, 2021
1 parent bcd3e92 commit 21dbf58
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 2 deletions.
3 changes: 3 additions & 0 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ type AddressConfig struct {
PreCommitControl []address.Address
CommitControl []address.Address
TerminateControl []address.Address

DisableOwnerFallback bool
DisableWorkerFallback bool
}

// PendingDealInfo has info about pending deals and when they are due to be
Expand Down
14 changes: 14 additions & 0 deletions cmd/lotus-storage-miner/actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ var actorControlList = &cli.Command{

commit := map[address.Address]struct{}{}
precommit := map[address.Address]struct{}{}
terminate := map[address.Address]struct{}{}
post := map[address.Address]struct{}{}

for _, ca := range mi.ControlAddresses {
Expand All @@ -446,6 +447,16 @@ var actorControlList = &cli.Command{
commit[ca] = struct{}{}
}

for _, ca := range ac.TerminateControl {
ca, err := api.StateLookupID(ctx, ca, types.EmptyTSK)
if err != nil {
return err
}

delete(post, ca)
terminate[ca] = struct{}{}
}

printKey := func(name string, a address.Address) {
b, err := api.WalletBalance(ctx, a)
if err != nil {
Expand Down Expand Up @@ -487,6 +498,9 @@ var actorControlList = &cli.Command{
if _, ok := commit[a]; ok {
uses = append(uses, color.BlueString("commit"))
}
if _, ok := terminate[a]; ok {
uses = append(uses, color.YellowString("terminate"))
}

tw.Write(map[string]interface{}{
"name": name,
Expand Down
4 changes: 3 additions & 1 deletion documentation/en/api-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ Response:
{
"PreCommitControl": null,
"CommitControl": null,
"TerminateControl": null
"TerminateControl": null,
"DisableOwnerFallback": true,
"DisableWorkerFallback": true
}
```

Expand Down
9 changes: 9 additions & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ type MinerFeeConfig struct {
type MinerAddressConfig struct {
PreCommitControl []string
CommitControl []string
TerminateControl []string

// DisableOwnerFallback disables usage of the owner address for messages
// sent automatically
DisableOwnerFallback bool
// DisableWorkerFallback disables usage of the worker address for messages
// sent automatically if control addresses are configured, even if those
// addresses don't have enough funds available
DisableWorkerFallback bool
}

// API contains configs for API endpoint
Expand Down
12 changes: 12 additions & 0 deletions node/modules/storageminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func AddressSelector(addrConf *config.MinerAddressConfig) func() (*storage.Addre
return as, nil
}

as.DisableOwnerFallback = addrConf.DisableOwnerFallback
as.DisableWorkerFallback = addrConf.DisableWorkerFallback

for _, s := range addrConf.PreCommitControl {
addr, err := address.NewFromString(s)
if err != nil {
Expand All @@ -175,6 +178,15 @@ func AddressSelector(addrConf *config.MinerAddressConfig) func() (*storage.Addre
as.CommitControl = append(as.CommitControl, addr)
}

for _, s := range addrConf.TerminateControl {
addr, err := address.NewFromString(s)
if err != nil {
return nil, xerrors.Errorf("parsing terminate control address: %w", err)
}

as.TerminateControl = append(as.TerminateControl, addr)
}

return as, nil
}
}
Expand Down
8 changes: 7 additions & 1 deletion storage/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ func (as *AddressSelector) AddressFor(ctx context.Context, a addrSelectApi, mi m
addrs = append(addrs, a)
}
}
addrs = append(addrs, mi.Owner, mi.Worker)

if len(addrs) == 0 || !as.DisableWorkerFallback {
addrs = append(addrs, mi.Worker)
}
if !as.DisableOwnerFallback {
addrs = append(addrs, mi.Owner)
}

return pickAddress(ctx, a, mi, goodFunds, minFunds, addrs)
}
Expand Down

0 comments on commit 21dbf58

Please sign in to comment.