Skip to content

Commit

Permalink
add NilJournal; fix call sites to ChainStore constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Jul 17, 2020
1 parent 4bcf019 commit becbff0
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 8 deletions.
3 changes: 2 additions & 1 deletion chain/blocksync/graphsync_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

store "github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/journal"

cidlink "github.com/ipld/go-ipld-prime/linking/cid"
basicnode "github.com/ipld/go-ipld-prime/node/basic"
Expand Down Expand Up @@ -138,7 +139,7 @@ func (bs *BlockSync) fetchBlocksGraphSync(ctx context.Context, p peer.ID, req *B
}

// Now pull the data we fetched out of the chainstore (where it should now be persisted)
tempcs := store.NewChainStore(bs.bserv.Blockstore(), datastore.NewMapDatastore(), nil)
tempcs := store.NewChainStore(bs.bserv.Blockstore(), datastore.NewMapDatastore(), nil, journal.NilJournal())

opts := ParseBSOptions(req.Options)
tsk := types.NewTipSetKey(req.Start...)
Expand Down
3 changes: 2 additions & 1 deletion chain/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/filecoin-project/lotus/chain/wallet"
"github.com/filecoin-project/lotus/cmd/lotus-seed/seed"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/lib/sigs"
"github.com/filecoin-project/lotus/node/repo"
"github.com/filecoin-project/sector-storage/ffiwrapper"
Expand Down Expand Up @@ -204,7 +205,7 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) {
return nil, xerrors.Errorf("make genesis block failed: %w", err)
}

cs := store.NewChainStore(bs, ds, sys)
cs := store.NewChainStore(bs, ds, sys, journal.NilJournal())

genfb := &types.FullBlock{Header: genb.Genesis}
gents := store.NewFullTipSet([]*types.FullBlock{genfb})
Expand Down
3 changes: 2 additions & 1 deletion chain/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/journal"
)

const AccountStart = 100
Expand Down Expand Up @@ -302,7 +303,7 @@ func MakeGenesisBlock(ctx context.Context, bs bstore.Blockstore, sys runtime.Sys
}

// temp chainstore
cs := store.NewChainStore(bs, datastore.NewMapDatastore(), sys)
cs := store.NewChainStore(bs, datastore.NewMapDatastore(), sys, journal.NilJournal())

// Verify PreSealed Data
stateroot, err = VerifyPreSealedData(ctx, cs, stateroot, template)
Expand Down
3 changes: 2 additions & 1 deletion chain/validation/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/journal"
)

// Applier applies messages to state trees and storage.
Expand Down Expand Up @@ -67,7 +68,7 @@ func (a *Applier) ApplySignedMessage(epoch abi.ChainEpoch, msg *vtypes.SignedMes
}

func (a *Applier) ApplyTipSetMessages(epoch abi.ChainEpoch, blocks []vtypes.BlockMessagesInfo, rnd vstate.RandomnessSource) (vtypes.ApplyTipSetResult, error) {
cs := store.NewChainStore(a.stateWrapper.bs, a.stateWrapper.ds, a.syscalls)
cs := store.NewChainStore(a.stateWrapper.bs, a.stateWrapper.ds, a.syscalls, journal.NilJournal())
sm := stmgr.NewStateManager(cs)

var bms []stmgr.BlockMessages
Expand Down
3 changes: 2 additions & 1 deletion cmd/lotus-bench/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/lotus/journal"
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
"github.com/filecoin-project/sector-storage/ffiwrapper"
Expand Down Expand Up @@ -85,7 +86,7 @@ var importBenchCmd = &cli.Command{
}
bs = cbs
ds := datastore.NewMapDatastore()
cs := store.NewChainStore(bs, ds, vm.Syscalls(ffiwrapper.ProofVerifier))
cs := store.NewChainStore(bs, ds, vm.Syscalls(ffiwrapper.ProofVerifier), journal.NilJournal())
stm := stmgr.NewStateManager(cs)

prof, err := os.Create("import-bench.prof")
Expand Down
3 changes: 2 additions & 1 deletion cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/journal"

paramfetch "github.com/filecoin-project/go-paramfetch"
blockstore "github.com/ipfs/go-ipfs-blockstore"
Expand Down Expand Up @@ -336,7 +337,7 @@ func ImportChain(r repo.Repo, fname string) error {

bs := blockstore.NewBlockstore(ds)

cst := store.NewChainStore(bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier))
cst := store.NewChainStore(bs, mds, vm.Syscalls(ffiwrapper.ProofVerifier), journal.NilJournal())

log.Info("importing chain from file...")
ts, err := cst.Import(fi)
Expand Down
16 changes: 16 additions & 0 deletions journal/nil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package journal

type nilJournal struct{}

// nilj is a singleton nil journal.
var nilj Journal = &nilJournal{}

func NilJournal() Journal {
return nilj
}

func (n *nilJournal) RegisterEventType(_, _ string) EventType { return EventType{} }

func (n *nilJournal) AddEntry(_ EventType, _ interface{}) {}

func (n *nilJournal) Close() error { return nil }
6 changes: 6 additions & 0 deletions journal/sugar.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package journal
// MaybeAddEntry is a convenience function that evaluates if the EventType is
// enabled, and if so, it calls the supplier to create the entry and
// subsequently journal.AddEntry on the provided journal to record it.
//
// This is safe to call with a nil Journal, either because the value is nil,
// or because a journal obtained through NilJournal() is in use.
func MaybeAddEntry(journal Journal, evtType EventType, supplier func() interface{}) {
if journal == nil || journal == nilj {
return
}
if !evtType.Enabled() {
return
}
Expand Down
5 changes: 3 additions & 2 deletions node/modules/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/node/modules/dtypes"
"github.com/filecoin-project/lotus/node/modules/helpers"
"github.com/filecoin-project/lotus/node/repo"
Expand Down Expand Up @@ -83,8 +84,8 @@ func ChainBlockservice(bs dtypes.ChainBlockstore, rem dtypes.ChainExchange) dtyp
return blockservice.New(bs, rem)
}

func ChainStore(lc fx.Lifecycle, bs dtypes.ChainBlockstore, ds dtypes.MetadataDS, syscalls runtime.Syscalls) *store.ChainStore {
chain := store.NewChainStore(bs, ds, syscalls)
func ChainStore(lc fx.Lifecycle, bs dtypes.ChainBlockstore, ds dtypes.MetadataDS, syscalls runtime.Syscalls, journal journal.Journal) *store.ChainStore {
chain := store.NewChainStore(bs, ds, syscalls, journal)

if err := chain.Load(); err != nil {
log.Warnf("loading chain state from disk: %s", err)
Expand Down

0 comments on commit becbff0

Please sign in to comment.