config

package
v0.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DelegateType represents the delegate node type
	DelegateType = "delegate"
	// FullNodeType represents the full node type
	FullNodeType = "full_node"
	// LightweightType represents the lightweight type
	LightweightType = "lightweight"

	// 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"
)

Variables

View Source
var (
	// Default is the default config
	Default = Config{
		NodeType: FullNodeType,
		Network: Network{
			Host:           "0.0.0.0",
			Port:           4689,
			ExternalHost:   "",
			ExternalPort:   4689,
			BootstrapNodes: make([]string, 0),
			MasterKey:      "",
		},
		Chain: Chain{
			ChainDBPath:                  "/tmp/chain.db",
			TrieDBPath:                   "/tmp/trie.db",
			ID:                           1,
			Address:                      "",
			ProducerPubKey:               keypair.EncodePublicKey(&PrivateKey.PublicKey),
			ProducerPrivKey:              keypair.EncodePrivateKey(PrivateKey),
			GenesisActionsPath:           "",
			EmptyGenesis:                 false,
			NumCandidates:                101,
			EnableFallBackToFreshDB:      false,
			EnableSubChainStartInGenesis: false,
			EnableGasCharge:              false,
			EnableTrielessStateDB:        true,
			EnableIndex:                  false,
			EnableAsyncIndexWrite:        false,
		},
		ActPool: ActPool{
			MaxNumActsPerPool: 32000,
			MaxNumActsPerAcct: 2000,
			MaxNumActsToPick:  0,
			ActionExpiry:      10 * time.Minute,
		},
		Consensus: Consensus{
			Scheme: NOOPScheme,
			RollDPoS: RollDPoS{
				FSM: consensusfsm.Config{
					UnmatchedEventTTL:            3 * time.Second,
					UnmatchedEventInterval:       100 * time.Millisecond,
					AcceptBlockTTL:               4 * time.Second,
					AcceptProposalEndorsementTTL: 2 * time.Second,
					AcceptLockEndorsementTTL:     2 * time.Second,
					EventChanSize:                10000,
				},
				ToleratedOvertime: 2 * time.Second,
				DelegateInterval:  10 * time.Second,
				Delay:             5 * time.Second,
				NumSubEpochs:      1,
				NumDelegates:      21,
				TimeBasedRotation: false,
			},
			BlockCreationInterval: 10 * time.Second,
		},
		BlockSync: BlockSync{
			Interval:   10 * time.Second,
			BufferSize: 16,
		},
		Dispatcher: Dispatcher{
			EventChanSize: 10000,
		},
		Explorer: Explorer{
			Enabled:   false,
			UseRDS:    false,
			Port:      14004,
			TpsWindow: 10,
			GasStation: GasStation{
				SuggestBlockWindow: 20,
				DefaultGas:         1,
				Percentile:         60,
			},
			MaxTransferPayloadBytes: 1024,
		},
		Indexer: Indexer{
			Enabled:           false,
			NodeAddr:          "",
			WhetherLocalStore: true,
		},
		System: System{
			HeartbeatInterval:     10 * time.Second,
			HTTPProfilingPort:     0,
			HTTPMetricsPort:       8080,
			HTTPProbePort:         7788,
			StartSubChainInterval: 10 * time.Second,
		},
		DB: DB{
			UseBadgerDB: false,
			NumRetries:  3,
			SQLITE3: SQLITE3{
				SQLite3File: "./explorer.db",
			},
		},
	}

	// ErrInvalidCfg indicates the invalid config value
	ErrInvalidCfg = errors.New("invalid config value")

	// Validates is the collection config validation functions
	Validates = []Validate{
		ValidateKeyPair,
		ValidateConsensusScheme,
		ValidateRollDPoS,
		ValidateDispatcher,
		ValidateExplorer,
		ValidateActPool,
		ValidateChain,
	}

	// PrivateKey is a randomly generated producer's key for testing purpose
	PrivateKey, _ = crypto.GenerateKey()
)

Functions

func DoNotValidate

func DoNotValidate(cfg Config) error

DoNotValidate validates the given config

func ValidateActPool

func ValidateActPool(cfg Config) error

ValidateActPool validates the given config

func ValidateChain

func ValidateChain(cfg Config) error

ValidateChain validates the chain configure

func ValidateConsensusScheme

func ValidateConsensusScheme(cfg Config) error

ValidateConsensusScheme validates the if scheme and node type match

func ValidateDispatcher

func ValidateDispatcher(cfg Config) error

ValidateDispatcher validates the dispatcher configs

func ValidateExplorer

func ValidateExplorer(cfg Config) error

ValidateExplorer validates the explorer configs

func ValidateKeyPair

func ValidateKeyPair(cfg Config) error

ValidateKeyPair validates the block producer address

func ValidateRollDPoS

func ValidateRollDPoS(cfg Config) error

ValidateRollDPoS validates the roll-DPoS configs

Types

type ActPool

type ActPool struct {
	// MaxNumActsPerPool indicates maximum number of actions the whole actpool can hold
	MaxNumActsPerPool uint64 `yaml:"maxNumActsPerPool"`
	// MaxNumActsPerAcct indicates maximum number of actions an account queue can hold
	MaxNumActsPerAcct uint64 `yaml:"maxNumActsPerAcct"`
	// MaxNumActsToPick indicates maximum number of actions to pick to mint a block. Default is 0, which means no
	// limit on the number of actions to pick.
	MaxNumActsToPick uint64 `yaml:"maxNumActsToPick"`
	// ActionExpiry defines how long an action will be kept in action pool.
	ActionExpiry time.Duration `yaml:"actionExpiry"`
}

ActPool is the actpool config

type BlockSync

type BlockSync struct {
	Interval   time.Duration `yaml:"interval"` // update duration
	BufferSize uint64        `yaml:"bufferSize"`
}

BlockSync is the config struct for the BlockSync

type Chain

type Chain struct {
	ChainDBPath                  string `yaml:"chainDBPath"`
	TrieDBPath                   string `yaml:"trieDBPath"`
	ID                           uint32 `yaml:"id"`
	Address                      string `yaml:"address"`
	ProducerPubKey               string `yaml:"producerPubKey"`
	ProducerPrivKey              string `yaml:"producerPrivKey"`
	GenesisActionsPath           string `yaml:"genesisActionsPath"`
	EmptyGenesis                 bool   `yaml:"emptyGenesis"`
	NumCandidates                uint   `yaml:"numCandidates"`
	EnableFallBackToFreshDB      bool   `yaml:"enableFallbackToFreshDb"`
	EnableSubChainStartInGenesis bool   `yaml:"enableSubChainStartInGenesis"`
	EnableTrielessStateDB        bool   `yaml:"enableTrielessStateDB"`

	// enable gas charge for block producer
	EnableGasCharge bool `yaml:"enableGasCharge"`
	// enable index the block actions and receipts
	EnableIndex bool `yaml:"enableIndex"`
	// enable writing the block actions' and receipts' index asynchronously
	EnableAsyncIndexWrite bool `yaml:"enableAsyncIndexWrite"`
}

Chain is the config struct for blockchain package

type Config

type Config struct {
	NodeType   string           `yaml:"nodeType"`
	Network    Network          `yaml:"network"`
	Chain      Chain            `yaml:"chain"`
	ActPool    ActPool          `yaml:"actPool"`
	Consensus  Consensus        `yaml:"consensus"`
	BlockSync  BlockSync        `yaml:"blockSync"`
	Dispatcher Dispatcher       `yaml:"dispatcher"`
	Explorer   Explorer         `yaml:"explorer"`
	Indexer    Indexer          `yaml:"indexer"`
	System     System           `yaml:"system"`
	DB         DB               `yaml:"db"`
	Log        log.GlobalConfig `yaml:"log"`
}

Config is the root config struct, each package's config should be put as its sub struct

func New

func New(validates ...Validate) (Config, error)

New creates a config instance. It first loads the default configs. If the config path is not empty, it will read from the file and override the default configs. By default, it will apply all validation functions. To bypass validation, use DoNotValidate instead.

func NewSub

func NewSub(validates ...Validate) (Config, error)

NewSub create config for sub chain.

func (Config) BlockchainAddress

func (cfg Config) BlockchainAddress() (address.Address, error)

BlockchainAddress returns the address derived from the configured chain ID and public key

func (Config) IsDelegate

func (cfg Config) IsDelegate() bool

IsDelegate returns true if the node type is Delegate

func (Config) IsFullnode

func (cfg Config) IsFullnode() bool

IsFullnode returns true if the node type is Fullnode

func (Config) IsLightweight

func (cfg Config) IsLightweight() bool

IsLightweight returns true if the node type is Lightweight

func (Config) KeyPair

func (cfg Config) KeyPair() (keypair.PublicKey, keypair.PrivateKey, error)

KeyPair returns the decoded public and private key pair

type Consensus

type Consensus struct {
	// There are three schemes that are supported
	Scheme                string        `yaml:"scheme"`
	RollDPoS              RollDPoS      `yaml:"rollDPoS"`
	BlockCreationInterval time.Duration `yaml:"blockCreationInterval"`
}

Consensus is the config struct for consensus package

type DB

type DB struct {
	DbPath string `yaml:"dbPath"`
	// Use BadgerDB, otherwise use BoltDB
	UseBadgerDB bool `yaml:"useBadgerDB"`
	// NumRetries is the number of retries
	NumRetries uint8 `yaml:"numRetries"`

	// RDS is the config for rds
	RDS RDS `yaml:"RDS"`

	// SQLite3 is the config for SQLITE3
	SQLITE3 SQLITE3 `yaml:"SQLITE3"`
}

DB is the config for database

type Dispatcher

type Dispatcher struct {
	EventChanSize uint `yaml:"eventChanSize"`
}

Dispatcher is the dispatcher config

type Explorer

type Explorer struct {
	Enabled    bool       `yaml:"enabled"`
	IsTest     bool       `yaml:"isTest"`
	UseRDS     bool       `yaml:"useRDS"`
	Port       int        `yaml:"port"`
	TpsWindow  int        `yaml:"tpsWindow"`
	GasStation GasStation `yaml:"gasStation"`
	// MaxTransferPayloadBytes limits how many bytes a playload can contain at most
	MaxTransferPayloadBytes uint64 `yaml:"maxTransferPayloadBytes"`
}

Explorer is the explorer service config

type GasStation

type GasStation struct {
	SuggestBlockWindow int `yaml:"suggestBlockWindow"`
	DefaultGas         int `yaml:"defaultGas"`
	Percentile         int `yaml:"Percentile"`
}

GasStation is the gas station config

type Indexer

type Indexer struct {
	Enabled           bool   `yaml:"enabled"`
	NodeAddr          string `yaml:"nodeAddr"`
	WhetherLocalStore bool   `yaml:"whetherLocalStore"`
}

Indexer is the index service config

type Network

type Network struct {
	Host           string   `yaml:"host"`
	Port           int      `yaml:"port"`
	ExternalHost   string   `yaml:"externalHost"`
	ExternalPort   int      `yaml:"externalPort"`
	BootstrapNodes []string `yaml:"bootstrapNodes"`
	MasterKey      string   `yaml:"masterKey"` // master key will be PrivateKey if not set.
}

Network is the config struct for network package

type RDS

type RDS struct {
	// AwsRDSEndpoint is the endpoint of aws rds
	AwsRDSEndpoint string `yaml:"awsRDSEndpoint"`
	// AwsRDSPort is the port of aws rds
	AwsRDSPort uint64 `yaml:"awsRDSPort"`
	// AwsRDSUser is the user to access aws rds
	AwsRDSUser string `yaml:"awsRDSUser"`
	// AwsPass is the pass to access aws rds
	AwsPass string `yaml:"awsPass"`
	// AwsDBName is the db name of aws rds
	AwsDBName string `yaml:"awsDBName"`
}

RDS is the cloud rds config

type RollDPoS

type RollDPoS struct {
	FSM               consensusfsm.Config `yaml:"fsm"`
	ToleratedOvertime time.Duration       `yaml:"toleratedOvertime"`
	DelegateInterval  time.Duration       `yaml:"delegateInterval"`
	Delay             time.Duration       `yaml:"delay"`
	NumSubEpochs      uint                `yaml:"numSubEpochs"`
	NumDelegates      uint                `yaml:"numDelegates"`
	TimeBasedRotation bool                `yaml:"timeBasedRotation"`
}

RollDPoS is the config struct for RollDPoS consensus package

type SQLITE3

type SQLITE3 struct {
	// SQLite3File is the sqlite3 db file
	SQLite3File string `yaml:"sqlite3File"`
}

SQLITE3 is the local sqlite3 config

type System

type System struct {
	HeartbeatInterval time.Duration `yaml:"heartbeatInterval"`
	// HTTPProfilingPort is the port number to access golang performance profiling data of a blockchain node. It is
	// 0 by default, meaning performance profiling has been disabled
	HTTPProfilingPort     int           `yaml:"httpProfilingPort"`
	HTTPMetricsPort       int           `yaml:"httpMetricsPort"`
	HTTPProbePort         int           `yaml:"httpProbePort"`
	StartSubChainInterval time.Duration `yaml:"startSubChainInterval"`
}

System is the system config

type Validate

type Validate func(Config) error

Validate is the interface of validating the config

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL