Skip to content

Commit 75a220f

Browse files
authored
reputation: index info, reputation module, metrics, and more fixes (textileio#48)
* pr Signed-off-by: jsign <jsign.uy@gmail.com> * not panic Signed-off-by: jsign <jsign.uy@gmail.com>
1 parent 5285868 commit 75a220f

30 files changed

Lines changed: 2342 additions & 840 deletions

File tree

api/server/ip2location-ip4.bin

63.8 MB
Binary file not shown.

api/server/server.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import (
88
ma "github.com/multiformats/go-multiaddr"
99
"github.com/textileio/filecoin/deals"
1010
dealsPb "github.com/textileio/filecoin/deals/pb"
11+
"github.com/textileio/filecoin/fchost"
1112
"github.com/textileio/filecoin/index/ask"
13+
"github.com/textileio/filecoin/index/miner"
14+
"github.com/textileio/filecoin/index/slashing"
15+
"github.com/textileio/filecoin/iplocation/ip2location"
1216
"github.com/textileio/filecoin/lotus"
1317
"github.com/textileio/filecoin/tests"
1418
"github.com/textileio/filecoin/util"
@@ -27,6 +31,8 @@ type Server struct {
2731
dm *deals.Module
2832
ai *ask.AskIndex
2933
wm *wallet.Module
34+
si *slashing.SlashingIndex
35+
mi *miner.MinerIndex
3036

3137
rpc *grpc.Server
3238
dealsService *deals.Service
@@ -52,8 +58,19 @@ func NewServer(conf Config) (*Server, error) {
5258
ds := tests.NewTxMapDatastore()
5359

5460
ai := ask.New(ds, c)
55-
dm := deals.New(c, ds)
61+
dm := deals.New(ds, c)
5662
wm := wallet.New(c)
63+
fchost, err := fchost.New()
64+
if err != nil {
65+
return nil, err
66+
}
67+
if err := fchost.Bootstrap(); err != nil {
68+
return nil, err
69+
}
70+
// ToDo: Flags or embed
71+
ip2l := ip2location.New([]string{"ip2location-ip4.bin"})
72+
mi := miner.New(ds, c, fchost, ip2l)
73+
si := slashing.New(ds, c)
5774
dealsService := deals.NewService(dm, ai)
5875
walletService := wallet.NewService(wm)
5976

@@ -64,6 +81,8 @@ func NewServer(conf Config) (*Server, error) {
6481
dm: dm,
6582
ai: ai,
6683
wm: wm,
84+
mi: mi,
85+
si: si,
6786
dealsService: dealsService,
6887
walletService: walletService,
6988
closeLotus: cls,
@@ -90,7 +109,15 @@ func NewServer(conf Config) (*Server, error) {
90109
func (s *Server) Close() {
91110
s.rpc.GracefulStop()
92111
s.closeLotus()
93-
s.ai.Close()
112+
if err := s.ai.Close(); err != nil {
113+
log.Errorf("error when closing ask index: %s", err)
114+
}
115+
if err := s.mi.Close(); err != nil {
116+
log.Errorf("error when closing miner index: %s", err)
117+
}
118+
if err := s.si.Close(); err != nil {
119+
log.Errorf("error when closing slashing index: %s", err)
120+
}
94121
if err := s.ds.Close(); err != nil {
95122
log.Errorf("error when closing datastore: %s", err)
96123
}

chainsync/chainsync.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package chainsync
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/textileio/filecoin/lotus/types"
8+
)
9+
10+
// ToDo: consider avoiding the API and ask for deps in parameters
11+
12+
// API provides an abstraction to a lotus node
13+
type API interface {
14+
ChainGetTipSet(context.Context, types.TipSetKey) (*types.TipSet, error)
15+
ChainHead(context.Context) (*types.TipSet, error)
16+
}
17+
18+
// GetPathToHead returns an ordered tipset slice from the base tipset to the current
19+
// head.
20+
func GetPathToHead(ctx context.Context, c API, base types.TipSetKey) ([]*types.TipSet, error) {
21+
// ToDo: this is a temporary impl to start preparing for a possible new API that can
22+
// return HeadChanges from a checkpoint tipset to the head.
23+
bts, err := c.ChainGetTipSet(ctx, base)
24+
if err != nil {
25+
return nil, err
26+
}
27+
ts, err := c.ChainHead(ctx)
28+
if err != nil {
29+
return nil, fmt.Errorf("error when getting heaviest head from chain: %s", err)
30+
}
31+
if ts.Height < bts.Height {
32+
return nil, fmt.Errorf("reversed node or chain rollback, current height %d, last height %d", ts.Height, bts.Height)
33+
}
34+
path := make([]*types.TipSet, 0, ts.Height-bts.Height+1)
35+
for ts.Height >= bts.Height {
36+
path = append(path, ts)
37+
ts, err = c.ChainGetTipSet(ctx, types.NewTipSetKey(ts.Blocks[0].Parents...))
38+
if err != nil {
39+
return nil, err
40+
}
41+
}
42+
return path, nil
43+
}

cmd/server/main.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,14 @@ var (
2121

2222
func main() {
2323
logging.SetDebugLogging()
24-
logging.SetLogLevel("deals", "warn")
24+
logging.SetLogLevel("*", "error")
2525
instrumentationSetup()
2626

27-
lotusAddr, _ := tests.ClientConfigMA()
27+
lotusAddr, token := tests.ClientConfigMA()
2828
grpcAddr, err := ma.NewMultiaddr(grpcHostAddr)
2929
if err != nil {
3030
panic(err)
3131
}
32-
token, ok := os.LookupEnv("TEXTILE_LOTUS_TOKEN")
33-
if !ok {
34-
home, err := os.UserHomeDir()
35-
if err != nil {
36-
panic(err)
37-
}
38-
token, err = tests.GetLotusToken(home)
39-
if err != nil {
40-
panic(err)
41-
}
42-
}
4332
conf := server.Config{
4433
LotusAddress: lotusAddr,
4534
LotusAuthToken: token,

deals/deals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type API interface {
6161
}
6262

6363
// New creates a new deal module
64-
func New(api API, ds datastore.Datastore) *Module {
64+
func New(ds datastore.Datastore, api API) *Module {
6565
// can't avoid home base path, ipfs checks: cannot add filestore references outside ipfs root (home folder)
6666
home, err := os.UserHomeDir()
6767
if err != nil {

deals/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ type storeResult struct {
2727
}
2828

2929
// NewService is a helper to create a new Service
30-
func NewService(m *Module, ai *ask.AskIndex) *Service {
30+
func NewService(dm *Module, ai *ask.AskIndex) *Service {
3131
return &Service{
32-
Module: m,
32+
Module: dm,
3333
askIndex: ai,
3434
}
3535
}
@@ -59,7 +59,7 @@ func (s *Service) AvailableAsks(ctx context.Context, req *pb.AvailableAsksReques
5959
Limit: int(req.GetQuery().GetLimit()),
6060
Offset: int(req.GetQuery().GetOffset()),
6161
}
62-
asks, err := s.askIndex.AvailableAsks(q)
62+
asks, err := s.askIndex.Query(q)
6363
if err != nil {
6464
return nil, err
6565
}

docker/Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
LT = $(shell cat ~/.lotus/token)
2+
13
fresh: down up
24
.PHONY: fresh-up
35

46
down:
5-
@docker-compose down
7+
@TEXTILE_LOTUS_TOKEN=$(LT) docker-compose down
68
.PHONY: down
79

810
up:
9-
TEXTILE_LOTUS_TOKEN=$(shell cat ~/.lotus/token) docker-compose up --build
11+
TEXTILE_LOTUS_TOKEN=$(LT) docker-compose up --build
12+
.PHONY: up

0 commit comments

Comments
 (0)