2019-08-01 14:19:53 +00:00
|
|
|
package modules
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-10-14 20:49:43 +00:00
|
|
|
"time"
|
2020-02-27 21:45:31 +00:00
|
|
|
|
2019-08-01 14:19:53 +00:00
|
|
|
"github.com/ipfs/go-blockservice"
|
2023-01-27 22:01:51 +00:00
|
|
|
"github.com/ipfs/go-libipfs/bitswap"
|
|
|
|
"github.com/ipfs/go-libipfs/bitswap/network"
|
2022-08-25 18:20:41 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/host"
|
|
|
|
"github.com/libp2p/go-libp2p/core/routing"
|
2019-08-01 14:19:53 +00:00
|
|
|
"go.uber.org/fx"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2021-01-29 20:01:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2021-03-01 16:15:39 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore/splitstore"
|
2020-09-24 21:30:11 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2019-11-13 21:53:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain"
|
2020-03-25 23:16:17 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/beacon"
|
2021-09-02 16:07:23 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus"
|
2022-04-04 17:06:49 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/consensus/filcns"
|
2020-09-07 18:31:43 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/exchange"
|
2020-08-06 01:16:54 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/gen/slashfilter"
|
2019-12-01 23:11:43 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/messagepool"
|
2019-11-13 21:53:18 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/stmgr"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
2020-07-23 02:05:11 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/vm"
|
2021-02-28 22:48:36 +00:00
|
|
|
"github.com/filecoin-project/lotus/journal"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
|
|
"github.com/filecoin-project/lotus/node/modules/helpers"
|
2019-08-01 14:19:53 +00:00
|
|
|
)
|
|
|
|
|
2021-02-28 22:48:36 +00:00
|
|
|
// ChainBitswap uses a blockstore that bypasses all caches.
|
2021-12-17 09:42:09 +00:00
|
|
|
func ChainBitswap(lc fx.Lifecycle, mctx helpers.MetricsCtx, host host.Host, rt routing.Routing, bs dtypes.ExposedBlockstore) dtypes.ChainBitswap {
|
2019-08-06 22:04:21 +00:00
|
|
|
// prefix protocol for chain bitswap
|
|
|
|
// (so bitswap uses /chain/ipfs/bitswap/1.0.0 internally for chain sync stuff)
|
2019-08-08 17:16:41 +00:00
|
|
|
bitswapNetwork := network.NewFromIpfsHost(host, rt, network.Prefix("/chain"))
|
2020-04-27 22:54:16 +00:00
|
|
|
bitswapOptions := []bitswap.Option{bitswap.ProvideEnabled(false)}
|
2020-08-31 17:24:04 +00:00
|
|
|
|
2020-10-14 20:49:43 +00:00
|
|
|
// Write all incoming bitswap blocks into a temporary blockstore for two
|
|
|
|
// block times. If they validate, they'll be persisted later.
|
2021-01-29 23:17:25 +00:00
|
|
|
cache := blockstore.NewTimedCacheBlockstore(2 * time.Duration(build.BlockDelaySecs) * time.Second)
|
2020-10-14 20:49:43 +00:00
|
|
|
lc.Append(fx.Hook{OnStop: cache.Stop, OnStart: cache.Start})
|
|
|
|
|
2021-01-29 20:01:00 +00:00
|
|
|
bitswapBs := blockstore.NewTieredBstore(bs, cache)
|
2020-10-14 20:49:43 +00:00
|
|
|
|
2020-08-31 17:24:04 +00:00
|
|
|
// Use just exch.Close(), closing the context is not needed
|
2020-10-14 20:49:43 +00:00
|
|
|
exch := bitswap.New(mctx, bitswapNetwork, bitswapBs, bitswapOptions...)
|
2019-08-01 14:19:53 +00:00
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStop: func(ctx context.Context) error {
|
|
|
|
return exch.Close()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
return exch
|
|
|
|
}
|
|
|
|
|
2021-02-28 22:48:36 +00:00
|
|
|
func ChainBlockService(bs dtypes.ExposedBlockstore, rem dtypes.ChainBitswap) dtypes.ChainBlockService {
|
|
|
|
return blockservice.New(bs, rem)
|
|
|
|
}
|
|
|
|
|
2021-12-17 09:42:09 +00:00
|
|
|
func MessagePool(lc fx.Lifecycle, mctx helpers.MetricsCtx, us stmgr.UpgradeSchedule, mpp messagepool.Provider, ds dtypes.MetadataDS, nn dtypes.NetworkName, j journal.Journal, protector dtypes.GCReferenceProtector) (*messagepool.MessagePool, error) {
|
|
|
|
mp, err := messagepool.New(helpers.LifecycleCtx(mctx, lc), mpp, ds, us, nn, j)
|
2019-11-23 19:01:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, xerrors.Errorf("constructing mpool: %w", err)
|
|
|
|
}
|
2019-11-13 21:53:18 +00:00
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStop: func(_ context.Context) error {
|
|
|
|
return mp.Close()
|
|
|
|
},
|
|
|
|
})
|
2022-12-17 12:12:33 +00:00
|
|
|
protector.AddProtector(mp.TryForEachPendingMessage)
|
2019-11-23 19:01:56 +00:00
|
|
|
return mp, nil
|
2019-11-13 21:53:18 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
func ChainStore(lc fx.Lifecycle,
|
2021-12-17 09:42:09 +00:00
|
|
|
mctx helpers.MetricsCtx,
|
2021-09-02 16:07:23 +00:00
|
|
|
cbs dtypes.ChainBlockstore,
|
|
|
|
sbs dtypes.StateBlockstore,
|
|
|
|
ds dtypes.MetadataDS,
|
|
|
|
basebs dtypes.BaseBlockstore,
|
|
|
|
weight store.WeightFunc,
|
2021-12-03 10:11:54 +00:00
|
|
|
us stmgr.UpgradeSchedule,
|
2021-09-02 16:07:23 +00:00
|
|
|
j journal.Journal) *store.ChainStore {
|
|
|
|
|
|
|
|
chain := store.NewChainStore(cbs, sbs, ds, weight, j)
|
2019-08-01 14:19:53 +00:00
|
|
|
|
2021-12-17 09:42:09 +00:00
|
|
|
if err := chain.Load(helpers.LifecycleCtx(mctx, lc)); err != nil {
|
2019-08-02 06:46:14 +00:00
|
|
|
log.Warnf("loading chain state from disk: %s", err)
|
|
|
|
}
|
2019-08-01 14:19:53 +00:00
|
|
|
|
2021-03-01 17:38:02 +00:00
|
|
|
var startHook func(context.Context) error
|
2021-02-26 13:45:30 +00:00
|
|
|
if ss, ok := basebs.(*splitstore.SplitStore); ok {
|
2021-03-01 17:38:02 +00:00
|
|
|
startHook = func(_ context.Context) error {
|
2021-12-03 10:11:54 +00:00
|
|
|
err := ss.Start(chain, us)
|
2021-03-01 17:38:02 +00:00
|
|
|
if err != nil {
|
|
|
|
err = xerrors.Errorf("error starting splitstore: %w", err)
|
|
|
|
}
|
|
|
|
return err
|
2020-12-01 15:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 22:22:08 +00:00
|
|
|
lc.Append(fx.Hook{
|
2021-03-01 17:38:02 +00:00
|
|
|
OnStart: startHook,
|
2020-11-16 22:22:08 +00:00
|
|
|
OnStop: func(_ context.Context) error {
|
|
|
|
return chain.Close()
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2019-08-01 14:19:53 +00:00
|
|
|
return chain
|
|
|
|
}
|
|
|
|
|
2021-09-02 16:07:23 +00:00
|
|
|
func NetworkName(mctx helpers.MetricsCtx,
|
|
|
|
lc fx.Lifecycle,
|
|
|
|
cs *store.ChainStore,
|
|
|
|
tsexec stmgr.Executor,
|
|
|
|
syscalls vm.SyscallBuilder,
|
|
|
|
us stmgr.UpgradeSchedule,
|
|
|
|
_ dtypes.AfterGenesisSet) (dtypes.NetworkName, error) {
|
2020-09-24 21:30:11 +00:00
|
|
|
if !build.Devnet {
|
|
|
|
return "testnetnet", nil
|
|
|
|
}
|
|
|
|
|
2020-03-31 23:13:37 +00:00
|
|
|
ctx := helpers.LifecycleCtx(mctx, lc)
|
|
|
|
|
2021-09-18 17:57:04 +00:00
|
|
|
sm, err := stmgr.NewStateManager(cs, tsexec, syscalls, us, nil)
|
2020-10-09 00:36:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
netName, err := stmgr.GetNetworkName(ctx, sm, cs.GetHeaviestTipSet().ParentState())
|
2020-03-31 23:13:37 +00:00
|
|
|
return netName, err
|
2019-08-01 14:19:53 +00:00
|
|
|
}
|
2019-11-15 21:35:29 +00:00
|
|
|
|
2020-09-14 20:58:59 +00:00
|
|
|
type SyncerParams struct {
|
|
|
|
fx.In
|
|
|
|
|
|
|
|
Lifecycle fx.Lifecycle
|
|
|
|
MetadataDS dtypes.MetadataDS
|
|
|
|
StateManager *stmgr.StateManager
|
|
|
|
ChainXchg exchange.Client
|
|
|
|
SyncMgrCtor chain.SyncManagerCtor
|
|
|
|
Host host.Host
|
|
|
|
Beacon beacon.Schedule
|
2021-09-02 16:07:23 +00:00
|
|
|
Gent chain.Genesis
|
|
|
|
Consensus consensus.Consensus
|
2020-09-14 20:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewSyncer(params SyncerParams) (*chain.Syncer, error) {
|
|
|
|
var (
|
|
|
|
lc = params.Lifecycle
|
|
|
|
ds = params.MetadataDS
|
|
|
|
sm = params.StateManager
|
|
|
|
ex = params.ChainXchg
|
|
|
|
smCtor = params.SyncMgrCtor
|
|
|
|
h = params.Host
|
|
|
|
b = params.Beacon
|
|
|
|
)
|
2021-09-02 16:07:23 +00:00
|
|
|
syncer, err := chain.NewSyncer(ds, sm, ex, smCtor, h.ConnManager(), h.ID(), b, params.Gent, params.Consensus)
|
2019-11-15 21:35:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
lc.Append(fx.Hook{
|
|
|
|
OnStart: func(_ context.Context) error {
|
|
|
|
syncer.Start()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
OnStop: func(_ context.Context) error {
|
|
|
|
syncer.Stop()
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
return syncer, nil
|
|
|
|
}
|
2020-08-06 01:14:13 +00:00
|
|
|
|
|
|
|
func NewSlashFilter(ds dtypes.MetadataDS) *slashfilter.SlashFilter {
|
|
|
|
return slashfilter.New(ds)
|
|
|
|
}
|
2022-04-04 17:06:49 +00:00
|
|
|
|
feat: refactor: actor bundling system (#8838)
1. Include the builtin-actors in the lotus source tree.
2. Embed the bundle on build instead of downloading at runtime.
3. Avoid reading the bundle whenever possible by including bundle
metadata (the bundle CID, the actor CIDs, etc.).
4. Remove everything related to dependency injection.
1. We're no longer downloading the bundle, so doing anything ahead
of time doesn't really help.
2. We register the manifests on init because, unfortunately, they're
global.
3. We explicitly load the current actors bundle in the genesis
state-tree method.
4. For testing, we just change the in-use bundle with a bit of a
hack. It's not great, but using dependency injection doesn't make
any sense either because, again, the manifest information is
global.
5. Remove the bundle.toml file. Bundles may be overridden by
specifying an override path in the parameters file, or an
environment variable.
fixes #8701
2022-06-13 17:15:00 +00:00
|
|
|
func UpgradeSchedule() stmgr.UpgradeSchedule {
|
2022-04-04 17:06:49 +00:00
|
|
|
return filcns.DefaultUpgradeSchedule()
|
|
|
|
}
|