Add Mpool ref to raft state and rearrange some APIs
This commit is contained in:
@@ -143,7 +143,7 @@ var ChainNode = Options(
|
||||
// Lite node API
|
||||
ApplyIf(isLiteNode,
|
||||
Override(new(messagepool.Provider), messagepool.NewProviderLite),
|
||||
Override(new(messagesigner.MpoolNonceAPI), From(new(modules.MpoolNonceAPI))),
|
||||
Override(new(messagepool.MpoolNonceAPI), From(new(modules.MpoolNonceAPI))),
|
||||
Override(new(full.ChainModuleAPI), From(new(api.Gateway))),
|
||||
Override(new(full.GasModuleAPI), From(new(api.Gateway))),
|
||||
Override(new(full.MpoolModuleAPI), From(new(api.Gateway))),
|
||||
@@ -154,7 +154,7 @@ var ChainNode = Options(
|
||||
// Full node API / service startup
|
||||
ApplyIf(isFullNode,
|
||||
Override(new(messagepool.Provider), messagepool.NewProvider),
|
||||
Override(new(messagesigner.MpoolNonceAPI), From(new(*messagepool.MessagePool))),
|
||||
Override(new(messagepool.MpoolNonceAPI), From(new(*messagepool.MessagePool))),
|
||||
Override(new(full.ChainModuleAPI), From(new(full.ChainModule))),
|
||||
Override(new(full.GasModuleAPI), From(new(full.GasModule))),
|
||||
Override(new(full.MpoolModuleAPI), From(new(full.MpoolModule))),
|
||||
|
||||
+25
-13
@@ -2,12 +2,10 @@ package config
|
||||
|
||||
import (
|
||||
"encoding"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
hraft "github.com/hashicorp/raft"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
|
||||
@@ -102,7 +100,7 @@ func DefaultFullNode() *FullNode {
|
||||
ColdStoreFullGCFrequency: 7,
|
||||
},
|
||||
},
|
||||
Raft: *DefaultClusterRaftConfig(),
|
||||
Raft: *DefaultUserRaftConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,8 +288,30 @@ var (
|
||||
DefaultDatastoreNamespace = "/raft"
|
||||
)
|
||||
|
||||
func DefaultClusterRaftConfig() *ClusterRaftConfig {
|
||||
var cfg ClusterRaftConfig
|
||||
//func DefaultClusterRaftConfig() *ClusterRaftConfig {
|
||||
// var cfg ClusterRaftConfig
|
||||
// cfg.DataFolder = "" // empty so it gets omitted
|
||||
// cfg.InitPeerset = []peer.ID{}
|
||||
// cfg.WaitForLeaderTimeout = Duration(DefaultWaitForLeaderTimeout)
|
||||
// cfg.NetworkTimeout = Duration(DefaultNetworkTimeout)
|
||||
// cfg.CommitRetries = DefaultCommitRetries
|
||||
// cfg.CommitRetryDelay = Duration(DefaultCommitRetryDelay)
|
||||
// cfg.BackupsRotate = DefaultBackupsRotate
|
||||
// cfg.DatastoreNamespace = DefaultDatastoreNamespace
|
||||
// cfg.RaftConfig = hraft.DefaultConfig()
|
||||
//
|
||||
// // These options are imposed over any Default Raft Config.
|
||||
// cfg.RaftConfig.ShutdownOnRemove = false
|
||||
// cfg.RaftConfig.LocalID = "will_be_set_automatically"
|
||||
//
|
||||
// // Set up logging
|
||||
// cfg.RaftConfig.LogOutput = ioutil.Discard
|
||||
// //cfg.RaftConfig.Logger = &hcLogToLogger{}
|
||||
// return &cfg
|
||||
//}
|
||||
|
||||
func DefaultUserRaftConfig() *UserRaftConfig {
|
||||
var cfg UserRaftConfig
|
||||
cfg.DataFolder = "" // empty so it gets omitted
|
||||
cfg.InitPeerset = []peer.ID{}
|
||||
cfg.WaitForLeaderTimeout = Duration(DefaultWaitForLeaderTimeout)
|
||||
@@ -300,14 +320,6 @@ func DefaultClusterRaftConfig() *ClusterRaftConfig {
|
||||
cfg.CommitRetryDelay = Duration(DefaultCommitRetryDelay)
|
||||
cfg.BackupsRotate = DefaultBackupsRotate
|
||||
cfg.DatastoreNamespace = DefaultDatastoreNamespace
|
||||
cfg.RaftConfig = hraft.DefaultConfig()
|
||||
|
||||
// These options are imposed over any Default Raft Config.
|
||||
cfg.RaftConfig.ShutdownOnRemove = false
|
||||
cfg.RaftConfig.LocalID = "will_be_set_automatically"
|
||||
|
||||
// Set up logging
|
||||
cfg.RaftConfig.LogOutput = ioutil.Discard
|
||||
//cfg.RaftConfig.Logger = &hcLogToLogger{}
|
||||
return &cfg
|
||||
}
|
||||
|
||||
+75
-81
@@ -117,86 +117,6 @@ without existing payment channels with available funds will fail instead
|
||||
of automatically performing on-chain operations.`,
|
||||
},
|
||||
},
|
||||
"ClusterRaftConfig": []DocField{
|
||||
{
|
||||
Name: "ClusterModeEnabled",
|
||||
Type: "bool",
|
||||
|
||||
Comment: `config to enabled node cluster with raft consensus`,
|
||||
},
|
||||
{
|
||||
Name: "HostShutdown",
|
||||
Type: "bool",
|
||||
|
||||
Comment: `will shutdown libp2p host on shutdown. Useful for testing`,
|
||||
},
|
||||
{
|
||||
Name: "DataFolder",
|
||||
Type: "string",
|
||||
|
||||
Comment: `A folder to store Raft's data.`,
|
||||
},
|
||||
{
|
||||
Name: "InitPeerset",
|
||||
Type: "[]peer.ID",
|
||||
|
||||
Comment: `InitPeerset provides the list of initial cluster peers for new Raft
|
||||
peers (with no prior state). It is ignored when Raft was already
|
||||
initialized or when starting in staging mode.`,
|
||||
},
|
||||
{
|
||||
Name: "WaitForLeaderTimeout",
|
||||
Type: "Duration",
|
||||
|
||||
Comment: `LeaderTimeout specifies how long to wait for a leader before
|
||||
failing an operation.`,
|
||||
},
|
||||
{
|
||||
Name: "NetworkTimeout",
|
||||
Type: "Duration",
|
||||
|
||||
Comment: `NetworkTimeout specifies how long before a Raft network
|
||||
operation is timed out`,
|
||||
},
|
||||
{
|
||||
Name: "CommitRetries",
|
||||
Type: "int",
|
||||
|
||||
Comment: `CommitRetries specifies how many times we retry a failed commit until
|
||||
we give up.`,
|
||||
},
|
||||
{
|
||||
Name: "CommitRetryDelay",
|
||||
Type: "Duration",
|
||||
|
||||
Comment: `How long to wait between retries`,
|
||||
},
|
||||
{
|
||||
Name: "BackupsRotate",
|
||||
Type: "int",
|
||||
|
||||
Comment: `BackupsRotate specifies the maximum number of Raft's DataFolder
|
||||
copies that we keep as backups (renaming) after cleanup.`,
|
||||
},
|
||||
{
|
||||
Name: "DatastoreNamespace",
|
||||
Type: "string",
|
||||
|
||||
Comment: `Namespace to use when writing keys to the datastore`,
|
||||
},
|
||||
{
|
||||
Name: "RaftConfig",
|
||||
Type: "*hraft.Config",
|
||||
|
||||
Comment: `A Hashicorp Raft's configuration object.`,
|
||||
},
|
||||
{
|
||||
Name: "Tracing",
|
||||
Type: "bool",
|
||||
|
||||
Comment: `Tracing enables propagation of contexts across binary boundaries.`,
|
||||
},
|
||||
},
|
||||
"Common": []DocField{
|
||||
{
|
||||
Name: "API",
|
||||
@@ -456,7 +376,7 @@ see https://lotus.filecoin.io/storage-providers/advanced-configurations/market/#
|
||||
},
|
||||
{
|
||||
Name: "Raft",
|
||||
Type: "ClusterRaftConfig",
|
||||
Type: "UserRaftConfig",
|
||||
|
||||
Comment: ``,
|
||||
},
|
||||
@@ -1303,6 +1223,80 @@ finalities beyond the compaction boundary, default is 0, -1 retains everything`,
|
||||
Comment: ``,
|
||||
},
|
||||
},
|
||||
"UserRaftConfig": []DocField{
|
||||
{
|
||||
Name: "ClusterModeEnabled",
|
||||
Type: "bool",
|
||||
|
||||
Comment: `config to enabled node cluster with raft consensus`,
|
||||
},
|
||||
{
|
||||
Name: "HostShutdown",
|
||||
Type: "bool",
|
||||
|
||||
Comment: `will shutdown libp2p host on shutdown. Useful for testing`,
|
||||
},
|
||||
{
|
||||
Name: "DataFolder",
|
||||
Type: "string",
|
||||
|
||||
Comment: `A folder to store Raft's data.`,
|
||||
},
|
||||
{
|
||||
Name: "InitPeerset",
|
||||
Type: "[]peer.ID",
|
||||
|
||||
Comment: `InitPeerset provides the list of initial cluster peers for new Raft
|
||||
peers (with no prior state). It is ignored when Raft was already
|
||||
initialized or when starting in staging mode.`,
|
||||
},
|
||||
{
|
||||
Name: "WaitForLeaderTimeout",
|
||||
Type: "Duration",
|
||||
|
||||
Comment: `LeaderTimeout specifies how long to wait for a leader before
|
||||
failing an operation.`,
|
||||
},
|
||||
{
|
||||
Name: "NetworkTimeout",
|
||||
Type: "Duration",
|
||||
|
||||
Comment: `NetworkTimeout specifies how long before a Raft network
|
||||
operation is timed out`,
|
||||
},
|
||||
{
|
||||
Name: "CommitRetries",
|
||||
Type: "int",
|
||||
|
||||
Comment: `CommitRetries specifies how many times we retry a failed commit until
|
||||
we give up.`,
|
||||
},
|
||||
{
|
||||
Name: "CommitRetryDelay",
|
||||
Type: "Duration",
|
||||
|
||||
Comment: `How long to wait between retries`,
|
||||
},
|
||||
{
|
||||
Name: "BackupsRotate",
|
||||
Type: "int",
|
||||
|
||||
Comment: `BackupsRotate specifies the maximum number of Raft's DataFolder
|
||||
copies that we keep as backups (renaming) after cleanup.`,
|
||||
},
|
||||
{
|
||||
Name: "DatastoreNamespace",
|
||||
Type: "string",
|
||||
|
||||
Comment: `Namespace to use when writing keys to the datastore`,
|
||||
},
|
||||
{
|
||||
Name: "Tracing",
|
||||
Type: "bool",
|
||||
|
||||
Comment: `Tracing enables propagation of contexts across binary boundaries.`,
|
||||
},
|
||||
},
|
||||
"Wallet": []DocField{
|
||||
{
|
||||
Name: "RemoteBackend",
|
||||
|
||||
+39
-5
@@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
hraft "github.com/hashicorp/raft"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
|
||||
@@ -29,7 +28,7 @@ type FullNode struct {
|
||||
Wallet Wallet
|
||||
Fees FeeConfig
|
||||
Chainstore Chainstore
|
||||
Raft ClusterRaftConfig
|
||||
Raft UserRaftConfig
|
||||
}
|
||||
|
||||
// // Common
|
||||
@@ -612,8 +611,43 @@ type FeeConfig struct {
|
||||
DefaultMaxFee types.FIL
|
||||
}
|
||||
|
||||
// ClusterRaftConfig allows to configure the Raft Consensus component for the node cluster.
|
||||
type ClusterRaftConfig struct {
|
||||
//// ClusterRaftConfig allows to configure the Raft Consensus component for the node cluster.
|
||||
//type ClusterRaftConfig struct {
|
||||
// // config to enabled node cluster with raft consensus
|
||||
// ClusterModeEnabled bool
|
||||
// // will shutdown libp2p host on shutdown. Useful for testing
|
||||
// HostShutdown bool
|
||||
// // A folder to store Raft's data.
|
||||
// DataFolder string
|
||||
// // InitPeerset provides the list of initial cluster peers for new Raft
|
||||
// // peers (with no prior state). It is ignored when Raft was already
|
||||
// // initialized or when starting in staging mode.
|
||||
// InitPeerset []peer.ID
|
||||
// // LeaderTimeout specifies how long to wait for a leader before
|
||||
// // failing an operation.
|
||||
// WaitForLeaderTimeout Duration
|
||||
// // NetworkTimeout specifies how long before a Raft network
|
||||
// // operation is timed out
|
||||
// NetworkTimeout Duration
|
||||
// // CommitRetries specifies how many times we retry a failed commit until
|
||||
// // we give up.
|
||||
// CommitRetries int
|
||||
// // How long to wait between retries
|
||||
// CommitRetryDelay Duration
|
||||
// // BackupsRotate specifies the maximum number of Raft's DataFolder
|
||||
// // copies that we keep as backups (renaming) after cleanup.
|
||||
// BackupsRotate int
|
||||
// // Namespace to use when writing keys to the datastore
|
||||
// DatastoreNamespace string
|
||||
//
|
||||
// // A Hashicorp Raft's configuration object.
|
||||
// RaftConfig *hraft.Config
|
||||
//
|
||||
// // Tracing enables propagation of contexts across binary boundaries.
|
||||
// Tracing bool
|
||||
//}
|
||||
|
||||
type UserRaftConfig struct {
|
||||
// config to enabled node cluster with raft consensus
|
||||
ClusterModeEnabled bool
|
||||
// will shutdown libp2p host on shutdown. Useful for testing
|
||||
@@ -642,7 +676,7 @@ type ClusterRaftConfig struct {
|
||||
DatastoreNamespace string
|
||||
|
||||
// A Hashicorp Raft's configuration object.
|
||||
RaftConfig *hraft.Config
|
||||
//RaftConfig *hraft.Config
|
||||
|
||||
// Tracing enables propagation of contexts across binary boundaries.
|
||||
Tracing bool
|
||||
|
||||
+3
-2
@@ -9,7 +9,8 @@ import (
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/build"
|
||||
consensus2 "github.com/filecoin-project/lotus/lib/consensus/raft"
|
||||
|
||||
//consensus2 "github.com/filecoin-project/lotus/lib/consensus/raft"
|
||||
"github.com/filecoin-project/lotus/node/impl/client"
|
||||
"github.com/filecoin-project/lotus/node/impl/common"
|
||||
"github.com/filecoin-project/lotus/node/impl/full"
|
||||
@@ -119,7 +120,7 @@ func (n *FullNodeAPI) NodeStatus(ctx context.Context, inclChainStatus bool) (sta
|
||||
return status, nil
|
||||
}
|
||||
|
||||
func (n *FullNodeAPI) RaftState(ctx context.Context) (*consensus2.RaftState, error) {
|
||||
func (n *FullNodeAPI) RaftState(ctx context.Context) (*api.RaftStateData, error) {
|
||||
return n.RaftAPI.GetRaftState(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@ package full
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
"go.uber.org/fx"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/filecoin-project/lotus/api"
|
||||
"github.com/filecoin-project/lotus/chain/messagesigner"
|
||||
consensus "github.com/filecoin-project/lotus/lib/consensus/raft"
|
||||
)
|
||||
|
||||
type RaftAPI struct {
|
||||
@@ -16,11 +17,15 @@ type RaftAPI struct {
|
||||
MessageSigner *messagesigner.MessageSignerConsensus `optional:"true"`
|
||||
}
|
||||
|
||||
func (r *RaftAPI) GetRaftState(ctx context.Context) (*consensus.RaftState, error) {
|
||||
func (r *RaftAPI) GetRaftState(ctx context.Context) (*api.RaftStateData, error) {
|
||||
if r.MessageSigner == nil {
|
||||
return nil, xerrors.Errorf("Raft consensus not enabled. Please check your configuration")
|
||||
}
|
||||
return r.MessageSigner.GetRaftState(ctx)
|
||||
raftState, err := r.MessageSigner.GetRaftState(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &api.RaftStateData{NonceMap: raftState.NonceMap, MsgUuids: raftState.MsgUuids}, nil
|
||||
}
|
||||
|
||||
func (r *RaftAPI) Leader(ctx context.Context) (peer.ID, error) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/messagesigner"
|
||||
"github.com/filecoin-project/lotus/chain/messagepool"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/filecoin-project/lotus/node/impl/full"
|
||||
)
|
||||
@@ -104,4 +104,4 @@ func (a *MpoolNonceAPI) GetActor(ctx context.Context, addr address.Address, tsk
|
||||
return act, nil
|
||||
}
|
||||
|
||||
var _ messagesigner.MpoolNonceAPI = (*MpoolNonceAPI)(nil)
|
||||
var _ messagepool.MpoolNonceAPI = (*MpoolNonceAPI)(nil)
|
||||
|
||||
Reference in New Issue
Block a user