Skip to content

Commit d35a67e

Browse files
committed
feat: no some slash-filter
1 parent 462e6e7 commit d35a67e

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
3131
github.com/mitchellh/go-homedir v1.1.0
3232
github.com/multiformats/go-multiaddr v0.8.0
33+
github.com/pkg/errors v0.9.1
3334
github.com/raulk/clock v1.1.0
3435
github.com/stretchr/testify v1.8.3
3536
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
@@ -156,7 +157,6 @@ require (
156157
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
157158
github.com/pelletier/go-toml v1.9.5 // indirect
158159
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
159-
github.com/pkg/errors v0.9.1 // indirect
160160
github.com/pmezard/go-difflib v1.0.0 // indirect
161161
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect
162162
github.com/prometheus/client_golang v1.13.0 // indirect

miner/multiminer.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"context"
66
"crypto/rand"
77
"encoding/binary"
8+
"errors"
89
"fmt"
10+
"os"
911
"sync"
1012
"time"
1113

@@ -456,7 +458,7 @@ func (m *Miner) mine(ctx context.Context) {
456458
// Wait until the next epoch, plus the propagation delay, so a new tipset
457459
// has enough time to form.
458460
m.untilNextEpoch(base)
459-
461+
460462
if len(winPoSts) == 0 {
461463
base.NullRounds++
462464
}
@@ -485,16 +487,20 @@ func (m *Miner) broadCastBlock(ctx context.Context, base MiningBase, bm *sharedT
485487

486488
if err := m.sf.MinedBlock(ctx, bm.Header, base.TipSet.Height()+base.NullRounds); err != nil {
487489
log.Errorf("<!!> SLASH FILTER ERROR: %s", err)
488-
if err = m.sf.PutBlock(ctx, bm.Header, base.TipSet.Height()+base.NullRounds, time.Time{}, slashfilter.Error); err != nil {
489-
log.Errorf("failed to put block: %s", err)
490-
}
491490

492-
mtsMineBlockFailCtx, _ := tag.New(
493-
ctx,
494-
tag.Upsert(metrics.MinerID, bm.Header.Miner.String()),
495-
)
496-
stats.Record(mtsMineBlockFailCtx, metrics.NumberOfMiningError.M(1))
497-
return
491+
if !(errors.Is(err, slashfilter.ParentGrindingFaults) &&
492+
os.Getenv("SOPHON_MINER_NO_SLASHFILTER") == "_yes_i_know_and_i_accept_that_may_loss_my_fil") {
493+
if err = m.sf.PutBlock(ctx, bm.Header, base.TipSet.Height()+base.NullRounds, time.Time{}, slashfilter.Error); err != nil {
494+
log.Errorf("failed to put block: %s", err)
495+
}
496+
497+
mtsMineBlockFailCtx, _ := tag.New(
498+
ctx,
499+
tag.Upsert(metrics.MinerID, bm.Header.Miner.String()),
500+
)
501+
stats.Record(mtsMineBlockFailCtx, metrics.NumberOfMiningError.M(1))
502+
return
503+
}
498504
}
499505

500506
if err := m.api.SyncSubmitBlock(ctx, bm); err != nil {

node/modules/slashfilter/api.go

+4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ package slashfilter
22

33
import (
44
"context"
5+
"errors"
56
"time"
67

78
"github.com/filecoin-project/go-state-types/abi"
89

910
vtypes "github.com/filecoin-project/venus/venus-shared/types"
1011
)
1112

13+
var TimeOffsetMiningFaults = errors.New("time-offset mining faults")
14+
var ParentGrindingFaults = errors.New("parent-grinding fault")
15+
1216
type BlockStoreType string
1317

1418
const (

node/modules/slashfilter/local.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ipfs/go-cid"
99
"github.com/ipfs/go-datastore"
1010
"github.com/ipfs/go-datastore/namespace"
11+
"github.com/pkg/errors"
1112

1213
"github.com/filecoin-project/go-state-types/abi"
1314

@@ -59,7 +60,7 @@ func (f *localSlashFilter) MinedBlock(ctx context.Context, bh *vtypes.BlockHeade
5960
parentsKey := datastore.NewKey(fmt.Sprintf("/%s/%x", bh.Miner, vtypes.NewTipSetKey(bh.Parents...).Bytes()))
6061
{
6162
// time-offset mining faults (2 blocks with the same parents)
62-
if err := checkFault(ctx, f.byParents, parentsKey, bh, "time-offset mining faults"); err != nil {
63+
if err := checkFault(ctx, f.byParents, parentsKey, bh, TimeOffsetMiningFaults); err != nil {
6364
return err
6465
}
6566
}
@@ -94,15 +95,16 @@ func (f *localSlashFilter) MinedBlock(ctx context.Context, bh *vtypes.BlockHeade
9495
}
9596

9697
if !found {
97-
return fmt.Errorf("produced block would trigger 'parent-grinding fault' consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
98+
return errors.Wrapf(ParentGrindingFaults, "produced block would trigger consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
99+
// return fmt.Errorf("produced block would trigger 'parent-grinding fault' consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
98100
}
99101
}
100102
}
101103

102104
return nil
103105
}
104106

105-
func checkFault(ctx context.Context, t datastore.Datastore, key datastore.Key, bh *vtypes.BlockHeader, faultType string) error {
107+
func checkFault(ctx context.Context, t datastore.Datastore, key datastore.Key, bh *vtypes.BlockHeader, faultType error) error {
106108
fault, err := t.Has(ctx, key)
107109
if err != nil {
108110
return err
@@ -123,7 +125,7 @@ func checkFault(ctx context.Context, t datastore.Datastore, key datastore.Key, b
123125
return nil
124126
}
125127

126-
return fmt.Errorf("produced block would trigger '%s' consensus fault; miner: %s; bh: %s, other: %s", faultType, bh.Miner, bh.Cid(), other)
128+
return errors.Wrapf(faultType, "produced block would trigger consensus fault; miner: %s; bh: %s, other: %s", bh.Miner, bh.Cid(), other)
127129
}
128130

129131
return nil

node/modules/slashfilter/slashfilter.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/ipfs/go-cid"
99
logging "github.com/ipfs/go-log/v2"
10+
"github.com/pkg/errors"
1011
"gorm.io/driver/mysql"
1112
"gorm.io/gorm"
1213

@@ -216,7 +217,7 @@ func (f *mysqlSlashFilter) MinedBlock(ctx context.Context, bh *types.BlockHeader
216217
}
217218

218219
if !found {
219-
return fmt.Errorf("produced block would trigger 'parent-grinding fault' consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
220+
return errors.Wrapf(ParentGrindingFaults, "produced block would trigger consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
220221
}
221222
}
222223
} else if err != gorm.ErrRecordNotFound {

0 commit comments

Comments
 (0)