config

package
v0.5.0-rc10-hotfix1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: Apache-2.0 Imports: 16 Imported by: 44

Documentation

Index

Constants

View Source
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"
	// IndexTransfer is table identifier for transfer index in indexer
	IndexTransfer = "transfer"
	// IndexVote is table identifier for vote index in indexer
	IndexVote = "vote"
	// IndexExecution is table identifier for execution index in indexer
	IndexExecution = "execution"
	// IndexAction is table identifier for action index in indexer
	IndexAction = "action"
	// IndexReceipt is table identifier for receipt index in indexer
	IndexReceipt = "receipt"
)
View Source
const (
	// GatewayPlugin is the plugin of accepting user API requests and serving blockchain data to users
	GatewayPlugin = iota
)

Variables

View Source
var (
	// Default is the default config
	Default = Config{
		Plugins: make(map[int]interface{}),
		SubLogs: make(map[string]log.GlobalConfig),
		Network: Network{
			Host:            "0.0.0.0",
			Port:            4689,
			ExternalHost:    "",
			ExternalPort:    4689,
			BootstrapNodes:  []string{},
			MasterKey:       "",
			RateLimit:       p2p.DefaultRatelimitConfig,
			EnableRateLimit: true,
		},
		Chain: Chain{
			ChainDBPath:     "./chain.db",
			TrieDBPath:      "./trie.db",
			ID:              1,
			Address:         "",
			ProducerPrivKey: PrivateKey.HexString(),
			EmptyGenesis:    false,
			GravityChainDB:  DB{DbPath: "./poll.db", NumRetries: 10},
			Committee: committee.Config{
				GravityChainAPIs: []string{},
			},
			EnableFallBackToFreshDB: false,
			EnableTrielessStateDB:   true,
			EnableAsyncIndexWrite:   true,
			CompressBlock:           false,
			AllowedBlockGasResidue:  10000,
			MaxCacheSize:            0,
		},
		ActPool: ActPool{
			MaxNumActsPerPool:  32000,
			MaxGasLimitPerPool: 320000000,
			MaxNumActsPerAcct:  2000,
			ActionExpiry:       10 * time.Minute,
			MinGasPriceStr:     big.NewInt(unit.Qev).String(),
			BlackList:          []string{},
		},
		Consensus: Consensus{
			Scheme: StandaloneScheme,
			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,
					CommitTTL:                    2 * time.Second,
					EventChanSize:                10000,
				},
				ToleratedOvertime: 2 * time.Second,
				Delay:             5 * time.Second,
			},
		},
		BlockSync: BlockSync{
			Interval:        10 * time.Second,
			BufferSize:      100,
			IntervalSize:    10,
			MaxRepeat:       3,
			RepeatDecayStep: 1,
		},
		Dispatcher: Dispatcher{
			EventChanSize: 10000,
		},
		Explorer: Explorer{
			Enabled:    false,
			UseIndexer: false,
			Port:       14004,
			TpsWindow:  10,
			GasStation: GasStation{
				SuggestBlockWindow: 20,
				DefaultGas:         1,
				Percentile:         60,
			},
			MaxTransferPayloadBytes: 1024,
		},
		API: API{
			UseRDS:    false,
			Port:      14014,
			TpsWindow: 10,
			GasStation: GasStation{
				SuggestBlockWindow: 20,
				DefaultGas:         1,
				Percentile:         60,
			},
			RangeQueryLimit: 1000,
		},
		Indexer: Indexer{
			Enabled:           false,
			NodeAddr:          "",
			WhetherLocalStore: true,
			BlockByIndexList:  []string{IndexTransfer, IndexVote, IndexExecution, IndexAction, IndexReceipt},
			IndexHistoryList:  []string{IndexTransfer, IndexVote, IndexExecution, IndexAction},
		},
		System: System{
			Active:                    true,
			HeartbeatInterval:         10 * time.Second,
			HTTPStatsPort:             8080,
			HTTPAdminPort:             9009,
			StartSubChainInterval:     10 * time.Second,
			EnableExperimentalActions: false,
		},
		DB: DB{
			UseBadgerDB: false,
			NumRetries:  3,
			SQLITE3: SQLITE3{
				SQLite3File: "./explorer.db",
			},
		},
		Genesis: genesis.Default,
	}

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

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

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

Functions

func DoNotValidate added in v0.3.0

func DoNotValidate(cfg Config) error

DoNotValidate validates the given config

func ValidateAPI added in v0.5.0

func ValidateAPI(cfg Config) error

ValidateAPI validates the api configs

func ValidateActPool added in v0.3.0

func ValidateActPool(cfg Config) error

ValidateActPool validates the given config

func ValidateDispatcher added in v0.3.0

func ValidateDispatcher(cfg Config) error

ValidateDispatcher validates the dispatcher configs

func ValidateExplorer added in v0.3.0

func ValidateExplorer(cfg Config) error

ValidateExplorer validates the explorer configs

func ValidateRollDPoS added in v0.3.0

func ValidateRollDPoS(cfg Config) error

ValidateRollDPoS validates the roll-DPoS configs

Types

type API added in v0.5.0

type API struct {
	UseRDS          bool       `yaml:"useRDS"`
	Port            int        `yaml:"port"`
	TpsWindow       int        `yaml:"tpsWindow"`
	GasStation      GasStation `yaml:"gasStation"`
	RangeQueryLimit uint64     `yaml:"rangeQueryLimit"`
}

API is the api service config

type ActPool added in v0.3.0

type ActPool struct {
	// MaxNumActsPerPool indicates maximum number of actions the whole actpool can hold
	MaxNumActsPerPool uint64 `yaml:"maxNumActsPerPool"`
	// MaxGasLimitPerPool indicates maximum gas limit the whole actpool can hold
	MaxGasLimitPerPool uint64
	// MaxNumActsPerAcct indicates maximum number of actions an account queue can hold
	MaxNumActsPerAcct uint64 `yaml:"maxNumActsPerAcct"`
	// ActionExpiry defines how long an action will be kept in action pool.
	ActionExpiry time.Duration `yaml:"actionExpiry"`
	// MinGasPriceStr defines the minimal gas price the delegate will accept for an action
	MinGasPriceStr string `yaml:"minGasPrice"`
	// BlackList lists the account address that are banned from initiating actions
	BlackList []string `yaml:"blackList"`
}

ActPool is the actpool config

func (ActPool) MinGasPrice added in v0.5.0

func (ap ActPool) MinGasPrice() *big.Int

MinGasPrice returns the minimal gas price threshold

type BlockSync added in v0.2.0

type BlockSync struct {
	Interval     time.Duration `yaml:"interval"` // update duration
	BufferSize   uint64        `yaml:"bufferSize"`
	IntervalSize uint64        `yaml:"intervalSize"`
	// MaxRepeat is the maximal number of repeat of a block sync request
	MaxRepeat int `yaml:"maxRepeat"`
	// RepeatDecayStep is the step for repeat number decreasing by 1
	RepeatDecayStep int `yaml:"repeatDecayStep"`
}

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"`
	ProducerPrivKey string           `yaml:"producerPrivKey"`
	EmptyGenesis    bool             `yaml:"emptyGenesis"`
	GravityChainDB  DB               `yaml:"gravityChainDB"`
	Committee       committee.Config `yaml:"committee"`

	EnableFallBackToFreshDB bool `yaml:"enableFallbackToFreshDb"`
	EnableTrielessStateDB   bool `yaml:"enableTrielessStateDB"`
	// EnableAsyncIndexWrite enables writing the block actions' and receipts' index asynchronously
	EnableAsyncIndexWrite bool `yaml:"enableAsyncIndexWrite"`
	// CompressBlock enables gzip compression on block data
	CompressBlock bool `yaml:"compressBlock"`
	// AllowedBlockGasResidue is the amount of gas remained when block producer could stop processing more actions
	AllowedBlockGasResidue uint64 `yaml:"allowedBlockGasResidue"`
	// MaxCacheSize is the max number of blocks that will be put into an LRU cache. 0 means disabled
	MaxCacheSize int `yaml:"maxCacheSize"`
}

Chain is the config struct for blockchain package

type Config

type Config struct {
	Plugins    map[int]interface{}         `ymal:"plugins"`
	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"`
	API        API                         `yaml:"api"`
	Indexer    Indexer                     `yaml:"indexer"`
	System     System                      `yaml:"system"`
	DB         DB                          `yaml:"db"`
	Log        log.GlobalConfig            `yaml:"log"`
	SubLogs    map[string]log.GlobalConfig `yaml:"subLogs"`
	Genesis    genesis.Genesis             `yaml:"genesis"`
}

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

func New added in v0.3.0

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 added in v0.4.0

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

NewSub create config for sub chain.

func (Config) ProducerAddress added in v0.5.0

func (cfg Config) ProducerAddress() address.Address

ProducerAddress returns the configured producer address derived from key

func (Config) ProducerPrivateKey added in v0.5.0

func (cfg Config) ProducerPrivateKey() keypair.PrivateKey

ProducerPrivateKey returns the configured private key

type Consensus

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

Consensus is the config struct for consensus package

type DB added in v0.4.0

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 added in v0.2.0

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

Dispatcher is the dispatcher config

type Explorer added in v0.2.0

type Explorer struct {
	Enabled    bool       `yaml:"enabled"`
	IsTest     bool       `yaml:"isTest"`
	UseIndexer bool       `yaml:"useIndexer"`
	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 added in v0.4.4

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

GasStation is the gas station config

type Indexer added in v0.4.0

type Indexer struct {
	Enabled           bool   `yaml:"enabled"`
	NodeAddr          string `yaml:"nodeAddr"`
	WhetherLocalStore bool   `yaml:"whetherLocalStore"`
	// BlockByIndexList store list of BlockByIndex tables
	BlockByIndexList []string `yaml:"blockByIndexList"`
	// IndexHistoryList store list of IndexHistory tables
	IndexHistoryList []string `yaml:"indexHistoryList"`
}

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.
	// RelayType is the type of P2P network relay. By default, the value is empty, meaning disabled. Two relay types
	// are supported: active, nat.
	RelayType       string              `yaml:"relayType"`
	RateLimit       p2p.RateLimitConfig `yaml:"rateLimit"`
	EnableRateLimit bool                `yaml:"enableRateLimit"`
}

Network is the config struct for network package

type RDS added in v0.4.0

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 added in v0.2.0

type RollDPoS struct {
	FSM               consensusfsm.Config `yaml:"fsm"`
	ToleratedOvertime time.Duration       `yaml:"toleratedOvertime"`
	Delay             time.Duration       `yaml:"delay"`
}

RollDPoS is the config struct for RollDPoS consensus package

type SQLITE3 added in v0.4.4

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

SQLITE3 is the local sqlite3 config

type System added in v0.2.0

type System struct {
	// Active is the status of the node. True means active and false means stand-by
	Active            bool          `yaml:"active"`
	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
	HTTPAdminPort         int           `yaml:"httpAdminPort"`
	HTTPStatsPort         int           `yaml:"httpStatsPort"`
	StartSubChainInterval time.Duration `yaml:"startSubChainInterval"`
	// EnableExperimentalActions is the flag to enable experimental actions
	EnableExperimentalActions bool `yaml:"enableExperimentalActions"`
}

System is the system config

type Validate added in v0.3.0

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