-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[config] move config.Consensus to consensus package (#3735)
- Loading branch information
Showing
12 changed files
with
445 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package consensus | ||
|
||
import ( | ||
"github.com/iotexproject/iotex-core/consensus/scheme/rolldpos" | ||
) | ||
|
||
const ( | ||
// RollDPoSScheme means randomized delegated proof of stake | ||
RollDPoSScheme = "ROLLDPOS" | ||
// StandaloneScheme means that the node creates a block periodically regardless of others (if there is any) | ||
StandaloneScheme = "STANDALONE" | ||
// NOOPScheme means that the node does not create only block | ||
NOOPScheme = "NOOP" | ||
) | ||
|
||
var ( | ||
//DefaultConfig is the default config for blocksync | ||
DefaultConfig = Config{ | ||
Scheme: StandaloneScheme, | ||
RollDPoS: rolldpos.DefaultConfig, | ||
} | ||
) | ||
|
||
type ( | ||
// Config is the config struct for consensus package | ||
Config struct { | ||
// There are three schemes that are supported | ||
Scheme string `yaml:"scheme"` | ||
RollDPoS rolldpos.Config `yaml:"rollDPoS"` | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"context" | ||
|
||
"github.com/facebookgo/clock" | ||
"github.com/iotexproject/iotex-proto/golang/iotextypes" | ||
"github.com/pkg/errors" | ||
"go.uber.org/zap" | ||
|
||
|
@@ -18,14 +19,12 @@ import ( | |
"github.com/iotexproject/iotex-core/blockchain" | ||
"github.com/iotexproject/iotex-core/blockchain/block" | ||
"github.com/iotexproject/iotex-core/blockchain/genesis" | ||
"github.com/iotexproject/iotex-core/config" | ||
"github.com/iotexproject/iotex-core/consensus/scheme" | ||
"github.com/iotexproject/iotex-core/consensus/scheme/rolldpos" | ||
"github.com/iotexproject/iotex-core/pkg/lifecycle" | ||
"github.com/iotexproject/iotex-core/pkg/log" | ||
"github.com/iotexproject/iotex-core/state" | ||
"github.com/iotexproject/iotex-core/state/factory" | ||
"github.com/iotexproject/iotex-proto/golang/iotextypes" | ||
) | ||
|
||
// Consensus is the interface for handling IotxConsensus view change. | ||
|
@@ -42,7 +41,7 @@ type Consensus interface { | |
|
||
// IotxConsensus implements Consensus | ||
type IotxConsensus struct { | ||
cfg config.Consensus | ||
cfg Config | ||
scheme scheme.Scheme | ||
} | ||
|
||
|
@@ -81,7 +80,7 @@ func WithPollProtocol(pp poll.Protocol) Option { | |
|
||
// NewConsensus creates a IotxConsensus struct. | ||
func NewConsensus( | ||
cfg config.Config, | ||
cfg rolldpos.BuilderConfig, | ||
This comment has been minimized.
Sorry, something went wrong.
CoderZhi
Collaborator
|
||
bc blockchain.Blockchain, | ||
sf factory.Factory, | ||
opts ...Option, | ||
|
@@ -94,10 +93,13 @@ func NewConsensus( | |
} | ||
|
||
clock := clock.New() | ||
cs := &IotxConsensus{cfg: cfg.Consensus} | ||
cs := &IotxConsensus{cfg: Config{ | ||
Scheme: cfg.Scheme, | ||
RollDPoS: cfg.Consensus, | ||
}} | ||
var err error | ||
switch cfg.Consensus.Scheme { | ||
case config.RollDPoSScheme: | ||
switch cfg.Scheme { | ||
case RollDPoSScheme: | ||
bd := rolldpos.NewRollDPoSBuilder(). | ||
SetAddr(cfg.Chain.ProducerAddress().String()). | ||
SetPriKey(cfg.Chain.ProducerPrivateKey()). | ||
|
@@ -143,9 +145,9 @@ func NewConsensus( | |
if err != nil { | ||
log.Logger("consensus").Panic("Error when constructing RollDPoS.", zap.Error(err)) | ||
} | ||
case config.NOOPScheme: | ||
case NOOPScheme: | ||
cs.scheme = scheme.NewNoop() | ||
case config.StandaloneScheme: | ||
case StandaloneScheme: | ||
mintBlockCB := func() (*block.Block, error) { | ||
blk, err := bc.MintNewBlock(clock.Now()) | ||
if err != nil { | ||
|
@@ -178,7 +180,7 @@ func NewConsensus( | |
cfg.Genesis.BlockInterval, | ||
) | ||
default: | ||
return nil, errors.Errorf("unexpected IotxConsensus scheme %s", cfg.Consensus.Scheme) | ||
return nil, errors.Errorf("unexpected IotxConsensus scheme %s", cfg.Scheme) | ||
} | ||
|
||
return cs, nil | ||
|
Oops, something went wrong.
Why is the code on L35 unremoved?