Skip to content

Commit

Permalink
Merge pull request #218 from ipfs-force-community/feat/disable-mine-r…
Browse files Browse the repository at this point in the history
…ecord-by-default

feat: disable mine record by default
  • Loading branch information
simlecode authored Aug 22, 2023
2 parents c4c7152 + 3fc5acb commit 10ac056
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package build
var CurrentCommit string

// BuildVersion is the local build version, set by build system
const BuildVersion = "1.13.0-rc1"
const BuildVersion = "1.13.0-rc2"
const Version = "1130"

func UserVersion() string {
Expand Down
5 changes: 5 additions & 0 deletions docs/zh/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# sophon-miner changelog

## 1.13.0-rc2 / 2023-08-18

### New Feature
* feat: disable mine record by default [[#218](https://github.com/ipfs-force-community/sophon-miner/pull/218)]

## 1.13.0-rc1 / 2023-08-18

### New Feature
Expand Down
7 changes: 3 additions & 4 deletions node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,16 @@ func ConfigMinerOptions(c interface{}) Option {

Override(new(jwtclient.IAuthClient), minermanager.NewVenusAuth(cfg.Auth.Addr, cfg.Auth.Token)),
Override(new(minermanager.MinerManageAPI), minermanager.NewMinerManager),
Override(SetRecorderDatastoreKey, func(ds types.MetadataDS) minerecorder.Recorder {
if cfg.Recorder != nil {
Override(SetRecorderDatastoreKey, func(ds types.MetadataDS) {
if cfg.Recorder != nil && cfg.Recorder.Enable {
if cfg.Recorder.MaxRecordPerQuery > 0 {
minerecorder.MaxRecordPerQuery = cfg.Recorder.MaxRecordPerQuery
}
if cfg.Recorder.ExpireEpoch > 0 {
minerecorder.ExpireEpoch = abi.ChainEpoch(cfg.Recorder.ExpireEpoch)
}
minerecorder.SetDatastore(ds)
}
minerecorder.SetDatastore(ds)
return nil
}),
Override(new(miner.MiningAPI), modules.NewMinerProcessor),
)
Expand Down
1 change: 1 addition & 0 deletions node/config/def.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type SlashFilterConfig struct {
}

type RecorderConfig struct {
Enable bool
ExpireEpoch uint64
MaxRecordPerQuery uint
}
Expand Down
20 changes: 13 additions & 7 deletions node/modules/mine-recorder/inner_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@ package minerecorder

import (
"context"
"errors"
"fmt"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
)

var (
ErrDatastoreNotSet = fmt.Errorf("database not set")
ErrDatastoreNotSet = fmt.Errorf("database not set")
ErrRecorderDisabled = fmt.Errorf("recorder disabled")
)
var innerRecorder = DefaultRecorder{}
var innerRecorder Recorder
var enable = false

func SetDatastore(ds datastore.Datastore) {
innerRecorder.ds = namespace.Wrap(ds, DatastoreNamespaceKey)
innerRecorder = NewDefaultRecorder(ds)
enable = true
}

func checkAvailable() error {
if innerRecorder.ds == nil {
return ErrDatastoreNotSet
if !enable {
return ErrRecorderDisabled
}
return nil
}
Expand Down Expand Up @@ -49,7 +52,10 @@ type subRecorder struct {

func (s *subRecorder) Record(ctx context.Context, r Records) {
err := checkAvailable()
if err != nil {
if errors.Is(err, ErrRecorderDisabled) {
log.Debugf("recorder disabled, skip record")
return
} else if err != nil {
log.Warnf("record failed: %s", err.Error())
}
err = innerRecorder.Record(ctx, s.miner, s.epoch, r)
Expand Down

0 comments on commit 10ac056

Please sign in to comment.