address code review
This commit is contained in:
parent
2ce8dbbb06
commit
4b76a06224
@ -236,6 +236,10 @@ func NewChainStore(bs bstore.Blockstore, ds dstore.Batching) *ChainStore {
|
|||||||
|
|
||||||
func (cs *ChainStore) Load() error {
|
func (cs *ChainStore) Load() error {
|
||||||
head, err := cs.ds.Get(chainHeadKey)
|
head, err := cs.ds.Get(chainHeadKey)
|
||||||
|
if err == dstore.ErrNotFound {
|
||||||
|
log.Warn("no previous chain state found")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to load chain state from datastore")
|
return errors.Wrap(err, "failed to load chain state from datastore")
|
||||||
}
|
}
|
||||||
@ -353,9 +357,8 @@ func (cs *ChainStore) maybeTakeHeavierTipSet(ts *TipSet) error {
|
|||||||
cs.heaviest = ts
|
cs.heaviest = ts
|
||||||
|
|
||||||
if err := cs.writeHead(ts); err != nil {
|
if err := cs.writeHead(ts); err != nil {
|
||||||
// TODO: should this error? we've already accepted it as our best
|
log.Errorf("failed to write chain head: %s", err)
|
||||||
// head and told everyone...
|
return nil
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -128,6 +128,10 @@ func defaults() []Option {
|
|||||||
return []Option{
|
return []Option{
|
||||||
Override(new(helpers.MetricsCtx), context.Background),
|
Override(new(helpers.MetricsCtx), context.Background),
|
||||||
Override(new(record.Validator), modules.RecordValidator),
|
Override(new(record.Validator), modules.RecordValidator),
|
||||||
|
|
||||||
|
// Filecoin modules
|
||||||
|
|
||||||
|
Override(new(*chain.ChainStore), modules.ChainStore),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/gbrlsnchs/jwt/v3"
|
"github.com/gbrlsnchs/jwt/v3"
|
||||||
|
|
||||||
"github.com/ipfs/go-bitswap"
|
"github.com/ipfs/go-bitswap"
|
||||||
"github.com/ipfs/go-bitswap/network"
|
"github.com/ipfs/go-bitswap/network"
|
||||||
"github.com/ipfs/go-blockservice"
|
"github.com/ipfs/go-blockservice"
|
||||||
@ -163,3 +164,15 @@ func ClientDAG(lc fx.Lifecycle, fstore *filestore.Filestore) ipld.DAGService {
|
|||||||
|
|
||||||
return dag
|
return dag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ChainStore(lc fx.Lifecycle, bs blockstore.Blockstore, ds datastore.Batching) *chain.ChainStore {
|
||||||
|
chain := chain.NewChainStore(bs, ds)
|
||||||
|
|
||||||
|
lc.Append(fx.Hook{
|
||||||
|
OnStart: func(ctx context.Context) error {
|
||||||
|
return chain.Load()
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return chain
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user