Skip to content

Commit

Permalink
Merge pull request #6375 from filecoin-project/feat/nv23
Browse files Browse the repository at this point in the history
feat: implement nv23
  • Loading branch information
LinZexiao authored Jul 9, 2024
2 parents 8ccc6be + 5faee07 commit 33b9f35
Show file tree
Hide file tree
Showing 190 changed files with 7,687 additions and 1,767 deletions.
14 changes: 9 additions & 5 deletions app/node/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/filecoin-project/venus/app/submodule/dagservice"
"github.com/filecoin-project/venus/app/submodule/eth"
"github.com/filecoin-project/venus/app/submodule/f3"
"github.com/filecoin-project/venus/app/submodule/network"
"github.com/ipfs-force-community/sophon-auth/core"
"github.com/ipfs-force-community/sophon-auth/jwtclient"
Expand Down Expand Up @@ -103,9 +104,6 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
chainClock: b.chainClock,
}

// modules
nd.circulatiingSupplyCalculator = chain2.NewCirculatingSupplyCalculator(b.repo.Datastore(), b.genBlk.ParentStateRoot, b.repo.Config().NetworkParams.ForkUpgradeParam)

// services
nd.configModule = config2.NewConfigModule(b.repo)

Expand All @@ -114,7 +112,7 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
return nil, errors.Wrap(err, "failed to build node.blockstore")
}

nd.chain, err = chain.NewChainSubmodule(ctx, (*builder)(b), nd.circulatiingSupplyCalculator)
nd.chain, err = chain.NewChainSubmodule(ctx, (*builder)(b))
if err != nil {
return nil, errors.Wrap(err, "failed to build node.Chain")
}
Expand All @@ -129,7 +127,7 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
return nil, errors.Wrap(err, "failed to build node.dagservice")
}

nd.syncer, err = syncer.NewSyncerSubmodule(ctx, (*builder)(b), nd.blockstore, nd.network, nd.chain, nd.circulatiingSupplyCalculator)
nd.syncer, err = syncer.NewSyncerSubmodule(ctx, (*builder)(b), nd.blockstore, nd.network, nd.chain, nd.chain.CirculatingSupplyCalculator)
if err != nil {
return nil, errors.Wrap(err, "failed to build node.Syncer")
}
Expand All @@ -139,6 +137,11 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
return nil, errors.Wrap(err, "failed to build node.wallet")
}

nd.f3, err = f3.NewF3Submodule(ctx, nd.repo, nd.chain, nd.network, nd.wallet.API())
if err != nil {
return nil, errors.Wrap(err, "failed to build node.f3")
}

nd.mpool, err = mpool.NewMpoolSubmodule(ctx, (*builder)(b), nd.network, nd.chain, nd.wallet)
if err != nil {
return nil, errors.Wrap(err, "failed to build node.mpool")
Expand Down Expand Up @@ -194,6 +197,7 @@ func (b *Builder) build(ctx context.Context) (*Node, error) {
nd.common,
nd.eth,
nd.actorEvent,
nd.f3,
)

if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions app/node/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/filecoin-project/venus/app/submodule/storagenetworking"
v1api "github.com/filecoin-project/venus/venus-shared/api/chain/v1"
"github.com/filecoin-project/venus/venus-shared/api/f3"
)

// Env is the environment for command API handlers.
Expand All @@ -26,6 +27,7 @@ type Env struct {
PaychAPI v1api.IPaychan
CommonAPI v1api.ICommon
EthAPI v1api.IETH
F3API f3.F3
}

var _ cmds.Environment = (*Env)(nil)
Expand Down
6 changes: 3 additions & 3 deletions app/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
configModule "github.com/filecoin-project/venus/app/submodule/config"
"github.com/filecoin-project/venus/app/submodule/dagservice"
"github.com/filecoin-project/venus/app/submodule/eth"
"github.com/filecoin-project/venus/app/submodule/f3"
"github.com/filecoin-project/venus/app/submodule/market"
"github.com/filecoin-project/venus/app/submodule/mining"
"github.com/filecoin-project/venus/app/submodule/mpool"
Expand All @@ -26,7 +27,6 @@ import (
"github.com/filecoin-project/venus/app/submodule/storagenetworking"
syncer2 "github.com/filecoin-project/venus/app/submodule/syncer"
"github.com/filecoin-project/venus/app/submodule/wallet"
"github.com/filecoin-project/venus/pkg/chain"
"github.com/filecoin-project/venus/pkg/clock"
"github.com/filecoin-project/venus/pkg/config"
_ "github.com/filecoin-project/venus/pkg/crypto/bls" // enable bls signatures
Expand Down Expand Up @@ -71,8 +71,6 @@ type Node struct {
// It contains all persistent artifacts of the filecoin node.
repo repo.Repo

// moduls
circulatiingSupplyCalculator chain.ICirculatingSupplyCalcualtor
//
// Core services
//
Expand All @@ -94,6 +92,7 @@ type Node struct {
wallet *wallet.WalletSubmodule
mpool *mpool.MessagePoolSubmodule
storageNetworking *storagenetworking.StorageNetworkingSubmodule
f3 *f3.F3Submodule

// paychannel and market
market *market.MarketSubmodule
Expand Down Expand Up @@ -381,6 +380,7 @@ func (node *Node) createServerEnv(ctx context.Context) *Env {
MarketAPI: node.market.API(),
CommonAPI: node.common,
EthAPI: node.eth.API(),
F3API: node.f3.API(),
}

return &env
Expand Down
1 change: 1 addition & 0 deletions app/node/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func aliasETHAPI(rpcServer *jsonrpc.RPCServer) {

rpcServer.AliasMethod("trace_block", "Filecoin.EthTraceBlock")
rpcServer.AliasMethod("trace_replayBlockTransactions", "Filecoin.EthTraceReplayBlockTransactions")
rpcServer.AliasMethod("trace_transaction", "Filecoin.EthTraceTransaction")

rpcServer.AliasMethod("net_version", "Filecoin.NetVersion")
rpcServer.AliasMethod("net_listening", "Filecoin.NetListening")
Expand Down
38 changes: 21 additions & 17 deletions app/submodule/chain/chain_submodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (

// ChainSubmodule enhances the `Node` with chain capabilities.
type ChainSubmodule struct { //nolint
ChainReader *chain.Store
MessageStore *chain.MessageStore
Processor *consensus.DefaultProcessor
Fork fork.IFork
SystemCall vm.SyscallsImpl
ChainReader *chain.Store
MessageStore *chain.MessageStore
Processor *consensus.DefaultProcessor
Fork fork.IFork
SystemCall vm.SyscallsImpl
CirculatingSupplyCalculator *chain.CirculatingSupplyCalculator

CheckPoint types.TipSetKey
Drand beacon.Schedule
Expand All @@ -52,11 +53,10 @@ type chainConfig interface {
// NewChainSubmodule creates a new chain submodule.
func NewChainSubmodule(ctx context.Context,
config chainConfig,
circulatiingSupplyCalculator chain.ICirculatingSupplyCalcualtor,
) (*ChainSubmodule, error) {
repo := config.Repo()
// initialize chain store
chainStore := chain.NewStore(repo.ChainDatastore(), repo.Datastore(), config.GenesisCid(), circulatiingSupplyCalculator, chainselector.Weight)
chainStore := chain.NewStore(repo.ChainDatastore(), repo.Datastore(), config.GenesisCid(), chainselector.Weight)
// drand
genBlk, err := chainStore.GetGenesisBlock(context.TODO())
if err != nil {
Expand All @@ -73,22 +73,26 @@ func NewChainSubmodule(ctx context.Context,
if err != nil {
return nil, err
}

circulatingSupplyCalculator := chain.NewCirculatingSupplyCalculator(repo.Datastore(), genBlk.ParentStateRoot, repo.Config().NetworkParams.ForkUpgradeParam, fork.GetNetworkVersion)

faultChecker := consensusfault.NewFaultChecker(chainStore, fork)
syscalls := vmsupport.NewSyscalls(faultChecker, config.Verifier())
processor := consensus.NewDefaultProcessor(syscalls, circulatiingSupplyCalculator, chainStore, config.Repo().Config().NetworkParams)
processor := consensus.NewDefaultProcessor(syscalls, circulatingSupplyCalculator, chainStore, config.Repo().Config().NetworkParams)

waiter := chain.NewWaiter(chainStore, messageStore, config.Repo().Datastore(), cbor.NewCborStore(config.Repo().Datastore()))

store := &ChainSubmodule{
ChainReader: chainStore,
MessageStore: messageStore,
Processor: processor,
SystemCall: syscalls,
Fork: fork,
Drand: drand,
config: config,
Waiter: waiter,
CheckPoint: chainStore.GetCheckPoint(),
ChainReader: chainStore,
MessageStore: messageStore,
Processor: processor,
SystemCall: syscalls,
Fork: fork,
CirculatingSupplyCalculator: circulatingSupplyCalculator,
Drand: drand,
config: config,
Waiter: waiter,
CheckPoint: chainStore.GetCheckPoint(),
}
err = store.ChainReader.Load(context.TODO())
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions app/submodule/chain/chaininfo_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ func (cia *chainInfoAPI) StateGetNetworkParams(ctx context.Context) (*types.Netw
UpgradeWatermelonHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeWatermelonHeight,
UpgradeDragonHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeDragonHeight,
UpgradePhoenixHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradePhoenixHeight,
UpgradeWaffleHeight: cfg.NetworkParams.ForkUpgradeParam.UpgradeWaffleHeight,
},
Eip155ChainID: cfg.NetworkParams.Eip155ChainID,
}
Expand Down
42 changes: 35 additions & 7 deletions app/submodule/chain/miner_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (msa *minerStateAPI) StateSectorPreCommitInfo(ctx context.Context, maddr ad
// NOTE: returned info.Expiration may not be accurate in some cases, use StateSectorExpiration to get accurate
// expiration epoch
// return nil if sector not found
func (msa *minerStateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*types.SectorOnChainInfo, error) {
func (msa *minerStateAPI) StateSectorGetInfo(ctx context.Context, maddr address.Address, n abi.SectorNumber, tsk types.TipSetKey) (*lminer.SectorOnChainInfo, error) {
_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("loading tipset %s: %v", tsk, err)
Expand Down Expand Up @@ -141,8 +141,21 @@ func (msa *minerStateAPI) StateMinerInfo(ctx context.Context, maddr address.Addr
ConsensusFaultElapsed: minfo.ConsensusFaultElapsed,
PendingOwnerAddress: minfo.PendingOwnerAddress,
Beneficiary: minfo.Beneficiary,
BeneficiaryTerm: &minfo.BeneficiaryTerm,
PendingBeneficiaryTerm: minfo.PendingBeneficiaryTerm,
BeneficiaryTerm: &types.BeneficiaryTerm{
Quota: minfo.BeneficiaryTerm.Quota,
UsedQuota: minfo.BeneficiaryTerm.UsedQuota,
Expiration: minfo.BeneficiaryTerm.Expiration,
},
}

if minfo.PendingBeneficiaryTerm != nil {
ret.PendingBeneficiaryTerm = &types.PendingBeneficiaryChange{
NewBeneficiary: minfo.PendingBeneficiaryTerm.NewBeneficiary,
NewQuota: minfo.PendingBeneficiaryTerm.NewQuota,
NewExpiration: minfo.PendingBeneficiaryTerm.NewExpiration,
ApprovedByBeneficiary: minfo.PendingBeneficiaryTerm.ApprovedByBeneficiary,
ApprovedByNominee: minfo.PendingBeneficiaryTerm.ApprovedByNominee,
}
}

if minfo.PendingWorkerKey != nil {
Expand Down Expand Up @@ -320,7 +333,7 @@ func (msa *minerStateAPI) StateMinerDeadlines(ctx context.Context, maddr address
}

// StateMinerSectors returns info about the given miner's sectors. If the filter bitfield is nil, all sectors are included.
func (msa *minerStateAPI) StateMinerSectors(ctx context.Context, maddr address.Address, sectorNos *bitfield.BitField, tsk types.TipSetKey) ([]*types.SectorOnChainInfo, error) {
func (msa *minerStateAPI) StateMinerSectors(ctx context.Context, maddr address.Address, sectorNos *bitfield.BitField, tsk types.TipSetKey) ([]*lminer.SectorOnChainInfo, error) {
_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("Stmgr.ParentStateViewTsk failed:%v", err)
Expand Down Expand Up @@ -856,7 +869,7 @@ func (msa *minerStateAPI) StateVMCirculatingSupplyInternal(ctx context.Context,
return types.CirculatingSupply{}, err
}

return msa.ChainReader.GetCirculatingSupplyDetailed(ctx, ts.Height(), sTree)
return msa.CirculatingSupplyCalculator.GetCirculatingSupplyDetailed(ctx, ts.Height(), sTree)
}

// StateCirculatingSupply returns the exact circulating supply of Filecoin at the given tipset.
Expand All @@ -869,7 +882,22 @@ func (msa *minerStateAPI) StateCirculatingSupply(ctx context.Context, tsk types.
tsk.String(), err)
}

return msa.ChainReader.StateCirculatingSupply(ctx, parent.Key())
ts, err := msa.ChainReader.GetTipSet(ctx, parent.Key())
if err != nil {
return abi.TokenAmount{}, err
}

root, err := msa.ChainReader.GetTipSetStateRoot(ctx, ts)
if err != nil {
return abi.TokenAmount{}, err
}

sTree, err := tree.LoadState(ctx, msa.ChainReader.StateStore(), root)
if err != nil {
return abi.TokenAmount{}, err
}

return msa.CirculatingSupplyCalculator.GetCirculatingSupply(ctx, ts.Height(), sTree)
}

// StateMarketDeals returns information about every deal in the Storage Market
Expand All @@ -882,7 +910,7 @@ func (msa *minerStateAPI) StateMarketDeals(ctx context.Context, tsk types.TipSet
}

// StateMinerActiveSectors returns info about sectors that a given miner is actively proving.
func (msa *minerStateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*types.SectorOnChainInfo, error) { // TODO: only used in cli
func (msa *minerStateAPI) StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*lminer.SectorOnChainInfo, error) { // TODO: only used in cli
_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("Stmgr.ParentStateViewTsk failed:%v", err)
Expand Down
4 changes: 4 additions & 0 deletions app/submodule/eth/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func (e *ethAPIDummy) EthTraceReplayBlockTransactions(ctx context.Context, blkNu
return nil, ErrModuleDisabled
}

func (e *ethAPIDummy) EthTraceTransaction(ctx context.Context, txHash string) ([]*types.EthTraceTransaction, error) {
return nil, ErrModuleDisabled
}

func (e *ethAPIDummy) start(_ context.Context) error {
return nil
}
Expand Down
Loading

0 comments on commit 33b9f35

Please sign in to comment.