Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: no some slash-filter #205

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ gen:
print-%:
@echo $*=$($*)

lint:
golangci-lint run


# docker
.PHONY: docker
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-multiaddr v0.9.0
github.com/pkg/errors v0.9.1
github.com/raulk/clock v1.1.0
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
Expand Down Expand Up @@ -168,7 +169,6 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ func TestParentGridFail(t *testing.T) {
}

assert.True(t, len(chain.dropBlks) > 0)
chain.logMatcher.match("SLASH FILTER ERROR: produced block would trigger 'parent-grinding fault'")
chain.logMatcher.match("SLASH FILTER ERROR: produced block would trigger")
chain.logMatcher.match("parent-grinding fault")
}

func TestSameHeight(t *testing.T) {
Expand Down
24 changes: 15 additions & 9 deletions miner/multiminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"context"
"crypto/rand"
"encoding/binary"
"errors"
"fmt"
"os"
"sync"
"time"

Expand Down Expand Up @@ -545,16 +547,20 @@ func (m *Miner) broadCastBlock(ctx context.Context, base MiningBase, bm *sharedT

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

mtsMineBlockFailCtx, _ := tag.New(
ctx,
tag.Upsert(metrics.MinerID, bm.Header.Miner.String()),
)
stats.Record(mtsMineBlockFailCtx, metrics.NumberOfMiningError.M(1))
return
if !(errors.Is(err, slashfilter.ParentGrindingFaults) &&
os.Getenv("SOPHON_MINER_NO_SLASHFILTER") != "_yes_i_know_and_i_accept_that_may_loss_my_fil") {
if err = m.sf.PutBlock(ctx, bm.Header, base.TipSet.Height()+base.NullRounds, time.Time{}, types.Error); err != nil {
log.Errorf("failed to put block: %s", err)
}

mtsMineBlockFailCtx, _ := tag.New(
ctx,
tag.Upsert(metrics.MinerID, bm.Header.Miner.String()),
)
stats.Record(mtsMineBlockFailCtx, metrics.NumberOfMiningError.M(1))
return
}
}

if err := m.api.SyncSubmitBlock(ctx, bm); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions node/modules/slashfilter/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package slashfilter

import (
"context"
"errors"
"time"

"github.com/filecoin-project/go-state-types/abi"
Expand All @@ -10,6 +11,9 @@ import (
vtypes "github.com/filecoin-project/venus/venus-shared/types"
)

var TimeOffsetMiningFaults = errors.New("time-offset mining faults")
var ParentGrindingFaults = errors.New("parent-grinding fault")

type BlockStoreType string

const (
Expand Down
10 changes: 6 additions & 4 deletions node/modules/slashfilter/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
"github.com/pkg/errors"

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

Expand Down Expand Up @@ -59,7 +60,7 @@ func (f *localSlashFilter) MinedBlock(ctx context.Context, bh *vtypes.BlockHeade
parentsKey := datastore.NewKey(fmt.Sprintf("/%s/%x", bh.Miner, vtypes.NewTipSetKey(bh.Parents...).Bytes()))
{
// time-offset mining faults (2 blocks with the same parents)
if err := checkFault(ctx, f.byParents, parentsKey, bh, "time-offset mining faults"); err != nil {
if err := checkFault(ctx, f.byParents, parentsKey, bh, TimeOffsetMiningFaults); err != nil {
return err
}
}
Expand Down Expand Up @@ -94,7 +95,8 @@ func (f *localSlashFilter) MinedBlock(ctx context.Context, bh *vtypes.BlockHeade
}

if !found {
return fmt.Errorf("produced block would trigger 'parent-grinding fault' consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
return errors.Wrapf(ParentGrindingFaults, "produced block would trigger consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
// return fmt.Errorf("produced block would trigger 'parent-grinding fault' consensus fault; miner: %s; bh: %s, expected parent: %s", bh.Miner, bh.Cid(), parent)
}
}
}
Expand All @@ -106,7 +108,7 @@ func (f *localSlashFilter) ListBlock(ctx context.Context, params *types.BlocksQu
return nil, fmt.Errorf("you are using levelDB, List Block is not supported")
}

func checkFault(ctx context.Context, t datastore.Datastore, key datastore.Key, bh *vtypes.BlockHeader, faultType string) error {
func checkFault(ctx context.Context, t datastore.Datastore, key datastore.Key, bh *vtypes.BlockHeader, faultType error) error {
fault, err := t.Has(ctx, key)
if err != nil {
return err
Expand All @@ -127,7 +129,7 @@ func checkFault(ctx context.Context, t datastore.Datastore, key datastore.Key, b
return nil
}

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

return nil
Expand Down
3 changes: 2 additions & 1 deletion node/modules/slashfilter/slashfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"github.com/pkg/errors"
"gorm.io/driver/mysql"
"gorm.io/gorm"

Expand Down Expand Up @@ -202,7 +203,7 @@ func (f *mysqlSlashFilter) MinedBlock(ctx context.Context, bh *venusTypes.BlockH
}

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