feat: chain node: Move consensus slasher to internal service
This commit is contained in:
@@ -128,6 +128,8 @@ const (
|
||||
SetupFallbackBlockstoresKey
|
||||
GoRPCServer
|
||||
|
||||
ConsensusReporterKey
|
||||
|
||||
SetApiEndpointKey
|
||||
|
||||
StoreEventsKey
|
||||
|
||||
@@ -280,6 +280,11 @@ func ConfigFullNode(c interface{}) Option {
|
||||
// enable message index for full node when configured by the user, otherwise use dummy.
|
||||
If(cfg.Index.EnableMsgIndex, Override(new(index.MsgIndex), modules.MsgIndex)),
|
||||
If(!cfg.Index.EnableMsgIndex, Override(new(index.MsgIndex), modules.DummyMsgIndex)),
|
||||
|
||||
// enable fault reporter when configured by the user
|
||||
If(cfg.FaultReporter.EnableConsensusFaultReporter,
|
||||
Override(ConsensusReporterKey, modules.RunConsensusFaultReporter(cfg.FaultReporter)),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -394,6 +394,35 @@ the database must already exist and be writeable. If a relative path is provided
|
||||
relative to the CWD (current working directory).`,
|
||||
},
|
||||
},
|
||||
"FaultReporterConfig": []DocField{
|
||||
{
|
||||
Name: "EnableConsensusFaultReporter",
|
||||
Type: "bool",
|
||||
|
||||
Comment: `EnableConsensusFaultReporter controls whether the node will monitor and
|
||||
report consensus faults. When enabled, the node will watch for malicious
|
||||
behaviors like double-mining and parent grinding, and submit reports to the
|
||||
network. This can earn reporter rewards, but is not guaranteed. Nodes should
|
||||
enable fault reporting with care, as it may increase resource usage, and may
|
||||
generate gas fees without earning rewards.`,
|
||||
},
|
||||
{
|
||||
Name: "ConsensusFaultReporterDataDir",
|
||||
Type: "string",
|
||||
|
||||
Comment: `ConsensusFaultReporterDataDir is the path where fault reporter state will be
|
||||
persisted. This directory should have adequate space and permissions for the
|
||||
node process.`,
|
||||
},
|
||||
{
|
||||
Name: "ConsensusFaultReporterAddress",
|
||||
Type: "string",
|
||||
|
||||
Comment: `ConsensusFaultReporterAddress is the wallet address used for submitting
|
||||
ReportConsensusFault messages. It will pay for gas fees, and receive any
|
||||
rewards. This address should have adequate funds to cover gas fees.`,
|
||||
},
|
||||
},
|
||||
"FeeConfig": []DocField{
|
||||
{
|
||||
Name: "DefaultMaxFee",
|
||||
@@ -465,6 +494,12 @@ Set to 0 to keep all mappings`,
|
||||
Name: "Index",
|
||||
Type: "IndexConfig",
|
||||
|
||||
Comment: ``,
|
||||
},
|
||||
{
|
||||
Name: "FaultReporter",
|
||||
Type: "FaultReporterConfig",
|
||||
|
||||
Comment: ``,
|
||||
},
|
||||
},
|
||||
|
||||
+28
-7
@@ -22,13 +22,14 @@ type Common struct {
|
||||
// FullNode is a full node config
|
||||
type FullNode struct {
|
||||
Common
|
||||
Client Client
|
||||
Wallet Wallet
|
||||
Fees FeeConfig
|
||||
Chainstore Chainstore
|
||||
Cluster UserRaftConfig
|
||||
Fevm FevmConfig
|
||||
Index IndexConfig
|
||||
Client Client
|
||||
Wallet Wallet
|
||||
Fees FeeConfig
|
||||
Chainstore Chainstore
|
||||
Cluster UserRaftConfig
|
||||
Fevm FevmConfig
|
||||
Index IndexConfig
|
||||
FaultReporter FaultReporterConfig
|
||||
}
|
||||
|
||||
// // Common
|
||||
@@ -732,3 +733,23 @@ type IndexConfig struct {
|
||||
// EnableMsgIndex enables indexing of messages on chain.
|
||||
EnableMsgIndex bool
|
||||
}
|
||||
|
||||
type FaultReporterConfig struct {
|
||||
// EnableConsensusFaultReporter controls whether the node will monitor and
|
||||
// report consensus faults. When enabled, the node will watch for malicious
|
||||
// behaviors like double-mining and parent grinding, and submit reports to the
|
||||
// network. This can earn reporter rewards, but is not guaranteed. Nodes should
|
||||
// enable fault reporting with care, as it may increase resource usage, and may
|
||||
// generate gas fees without earning rewards.
|
||||
EnableConsensusFaultReporter bool
|
||||
|
||||
// ConsensusFaultReporterDataDir is the path where fault reporter state will be
|
||||
// persisted. This directory should have adequate space and permissions for the
|
||||
// node process.
|
||||
ConsensusFaultReporterDataDir string
|
||||
|
||||
// ConsensusFaultReporterAddress is the wallet address used for submitting
|
||||
// ReportConsensusFault messages. It will pay for gas fees, and receive any
|
||||
// rewards. This address should have adequate funds to cover gas fees.
|
||||
ConsensusFaultReporterAddress string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"go.uber.org/fx"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/gen/slashfilter/slashsvc"
|
||||
"github.com/filecoin-project/lotus/node/config"
|
||||
"github.com/filecoin-project/lotus/node/impl/full"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
)
|
||||
|
||||
type consensusReporterModules struct {
|
||||
fx.In
|
||||
|
||||
full.WalletAPI
|
||||
full.ChainAPI
|
||||
full.MpoolAPI
|
||||
full.SyncAPI
|
||||
}
|
||||
|
||||
func RunConsensusFaultReporter(config config.FaultReporterConfig) func(mctx helpers.MetricsCtx, lc fx.Lifecycle, mod consensusReporterModules) error {
|
||||
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, mod consensusReporterModules) error {
|
||||
ctx := helpers.LifecycleCtx(mctx, lc)
|
||||
|
||||
return slashsvc.SlashConsensus(ctx, &mod, config.ConsensusFaultReporterDataDir, config.ConsensusFaultReporterAddress)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user