Skip to content

Commit

Permalink
fix: make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZexiao committed Nov 23, 2023
1 parent 1be0375 commit e05906f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 43 deletions.
2 changes: 1 addition & 1 deletion app/node/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Env struct {
PaychAPI v1api.IPaychan
CommonAPI v1api.ICommon
EthAPI v1api.IETH
SplitstoreAPI splitstore.SplitstoreController
SplitstoreAPI splitstore.Controller
}

var _ cmds.Environment = (*Env)(nil)
Expand Down
4 changes: 2 additions & 2 deletions app/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,15 @@ type RepoKeeper struct {
repo repo.Repo
}

var _ splitstore.SplitstoreController = (*RepoKeeper)(nil)
var _ splitstore.Controller = (*RepoKeeper)(nil)

func (r *RepoKeeper) Rollback() error {
ds := r.repo.Datastore()
if ds == nil {
fmt.Println("no blockstore found!")
}

rb, ok := ds.(splitstore.SplitstoreController)
rb, ok := ds.(splitstore.Controller)
if !ok {
fmt.Println("split store was disabled")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/repo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func (r *FSRepo) openDatastore() error {
}

ssPath := filepath.Join(r.path, splitstorePrefix)
opt := splitstore.SplitstoreOption{
opt := splitstore.Option{
MaxStoreCount: r.cfg.Datastore.SplitstoreCount,
StoreSize: abi.ChainEpoch(r.cfg.Datastore.SplitstoreSize),
}
Expand Down
2 changes: 1 addition & 1 deletion venus-shared/blockstore/splitstore/compose_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (cs *ComposeStore) DeleteBlock(ctx context.Context, c cid.Cid) error {
func (cs *ComposeStore) DeleteMany(ctx context.Context, cids []cid.Cid) error {
// primary and secondly can be both incomplete
// don't try to batch delete
return fmt.Errorf("DeleteMany not implemented on ComposeStore; don't do this Luke!")
return fmt.Errorf("delete many not implemented on compose store; don't do this")
}

// Flush implements blockstore.Blockstore.
Expand Down
10 changes: 6 additions & 4 deletions venus-shared/blockstore/splitstore/compose_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,18 @@ func TestComposeStoreView(t *testing.T) {

t.Run("View", func(t *testing.T) {
for _, b := range blocksInPrimary {
composeStore.View(ctx, b.Cid(), func(b []byte) error {
err := composeStore.View(ctx, b.Cid(), func(b []byte) error {
require.Equal(t, b, b)
return nil
})
require.NoError(t, err)
}
for _, b := range blocksInSecondary {
composeStore.View(ctx, b.Cid(), func(b []byte) error {
err := composeStore.View(ctx, b.Cid(), func(b []byte) error {
require.Equal(t, b, b)
return nil
})
require.NoError(t, err)
}

err := composeStore.View(ctx, blockNotExist.Cid(), func(b []byte) error {
Expand All @@ -161,12 +163,12 @@ func TestComposeStoreView(t *testing.T) {
require.True(t, ipld.IsNotFound(err))

// test for sync
// wait for sync (switch goroutine)
for _, b := range blocksInSecondary {
primaryStore.View(ctx, b.Cid(), func(b []byte) error {
err := primaryStore.View(ctx, b.Cid(), func(b []byte) error {
require.Equal(t, b, b)
return nil
})
require.NoError(t, err)
}
})
}
Expand Down
23 changes: 11 additions & 12 deletions venus-shared/blockstore/splitstore/splitstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ type InnerBlockstoreImpl struct {
BaseKeeper
}

type SplitstoreOption struct {
type Option struct {
MaxStoreCount int
StoreSize abi.ChainEpoch
}

type SplitstoreController interface {
type Controller interface {
Rollback() error
}

Expand All @@ -86,10 +86,10 @@ type Splitstore struct {
}

var _ blockstore.Blockstore = (*Splitstore)(nil)
var _ SplitstoreController = (*Splitstore)(nil)
var _ Controller = (*Splitstore)(nil)

func NewSplitstore(path string, initStore blockstore.Blockstore, opts ...SplitstoreOption) (*Splitstore, error) {
opt := SplitstoreOption{
func NewSplitstore(path string, initStore blockstore.Blockstore, opts ...Option) (*Splitstore, error) {
opt := Option{
MaxStoreCount: 3,
StoreSize: 3 * policy.ChainFinality,
}
Expand Down Expand Up @@ -522,7 +522,7 @@ func newInnerStore(path string, height int64, c cid.Cid) (*InnerBlockstoreImpl,
var store blockstore.Blockstore
storePath := filepath.Join(path, fmt.Sprintf("base_%d_%s.db", height, c))
if !c.Defined() {
storePath = filepath.Join(path, fmt.Sprintf("base_init.db"))
storePath = filepath.Join(path, "base_init.db")
}

stat, err := os.Stat(storePath)
Expand Down Expand Up @@ -575,11 +575,10 @@ func extractHeightAndCid(s string) (int64, cid.Cid, error) {
}
if match[2] == "init" {
return height, cid.Undef, nil
} else {
c, err := cid.Parse(match[2])
if err != nil {
return 0, cid.Undef, err
}
return height, c, nil
}
c, err := cid.Parse(match[2])
if err != nil {
return 0, cid.Undef, err
}
return height, c, nil
}
25 changes: 5 additions & 20 deletions venus-shared/blockstore/splitstore/splitstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"path/filepath"
"testing"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/venus/venus-shared/types"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
Expand All @@ -28,13 +26,15 @@ func TestSplitstore(t *testing.T) {

blockCid := cid.MustParse("bafy2bzaceazuutcexhvwkyyesszohrkjjzk2zgknasgs7bb7zgfnwghtnu5w2")
tskCid, err := types.NewTipSetKey(blockCid).Cid()
require.NoError(t, err)

// apply head change to append new store
b, err := ss.getBlock(ctx, blockCid)
require.NoError(t, err)
ts, err := types.NewTipSet([]*types.BlockHeader{b})
require.NoError(t, err)
ss.HeadChange(nil, []*types.TipSet{ts})
err = ss.HeadChange(nil, []*types.TipSet{ts})
require.NoError(t, err)
require.Len(t, ss.stores, 2)

seenBefore := NewSyncVisitor()
Expand Down Expand Up @@ -132,28 +132,13 @@ func TestExtractHeightAndCid(t *testing.T) {
require.Equal(t, int64(10), h)
require.Equal(t, "b1", c)

h, c, err = extractHeightAndCid("base_10_b1")
_, _, err = extractHeightAndCid("base_10_b1")
require.Error(t, err)

h, c, err = extractHeightAndCid("base_b1")
_, _, err = extractHeightAndCid("base_b1")
require.Error(t, err)
}

func fakeTipset(height abi.ChainEpoch) *types.TipSet {
c, _ := abi.CidBuilder.Sum([]byte("any"))

bh := &types.BlockHeader{
Miner: address.TestAddress,
Messages: c,
ParentStateRoot: c,
ParentMessageReceipts: c,
Height: height,
}

ts, _ := types.NewTipSet([]*types.BlockHeader{bh})
return ts
}

func TestScann(t *testing.T) {
path := "/root/tanlang/docker/test/splitstore/.venus/root/.venus1/splitstore"
bs, err := scan(path)
Expand Down
4 changes: 2 additions & 2 deletions venus-shared/blockstore/splitstore/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func WalkChain(ctx context.Context, store blockstore.Blockstore, tipsetKey cid.C
return fmt.Errorf("get block(%s): %w", tsk.Cids()[0], err)
}

deepLimit := b.Height - abi.ChainEpoch(depth)
deepLimit := b.Height - depth

blockToWalk := make(chan cid.Cid, 8)
objectToWalk := make(chan cid.Cid, 64)
Expand All @@ -89,8 +89,8 @@ func WalkChain(ctx context.Context, store blockstore.Blockstore, tipsetKey cid.C
}()

wg := sync.WaitGroup{}
wg.Add(1)
go func() {
wg.Add(1)
defer wg.Done()
for c := range objectToWalk {
err := walkObject(ctx, store, c, v)
Expand Down

0 comments on commit e05906f

Please sign in to comment.