repo

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AriesTestnetName  = "aries"
	TaurusTestnetName = "taurus"
)
View Source
const (
	AppName = "AxiomLedger"

	// CfgFileName is the default config name
	CfgFileName = "config.toml"

	AccountKeyFileName = "account.key"

	LogsDirName = "logs"
)
View Source
const (
	ConsensusTypeSolo    = "solo"
	ConsensusTypeRbft    = "rbft"
	ConsensusTypeSoloDev = "solo_dev"

	ConsensusStorageTypeMinifile = "minifile"
	ConsensusStorageTypeRosedb   = "rosedb"

	KVStorageTypeLeveldb = "leveldb"
	KVStorageTypePebble  = "pebble"
	KVStorageCacheSize   = 16
	KVStorageSync        = true

	P2PSecurityTLS   = "tls"
	P2PSecurityNoise = "noise"

	PprofModeMem     = "mem"
	PprofModeCpu     = "cpu"
	PprofTypeHTTP    = "http"
	PprofTypeRuntime = "runtime"

	P2PPipeBroadcastSimple = "simple"
	P2PPipeBroadcastGossip = "gossip"

	ExecTypeNative = "native"
	ExecTypeDev    = "dev"

	// DefaultTxMaxSize is the maximum size a single transaction can have. This field has
	// non-trivial consequences: larger transactions are significantly harder and
	// more expensive to propagate; larger transactions also take more resources
	// to validate whether they fit into the pool or not.
	DefaultTxMaxSize = 4 * txSlotSize // 128KB
)

Variables

View Source
var (
	TestNetConfigBuilderMap = map[string]func() *Config{
		AriesTestnetName:  AriesConfig,
		TaurusTestnetName: TaurusConfig,
	}

	TestNetConsensusConfigBuilderMap = map[string]func() *ConsensusConfig{
		AriesTestnetName:  AriesConsensusConfig,
		TaurusTestnetName: TaurusConsensusConfig,
	}

	TestNetGenesisConfigBuilderMap = map[string]func() *GenesisConfig{
		AriesTestnetName:  AriesGenesisConfig,
		TaurusTestnetName: TaurusGenesisConfig,
	}
)
View Source
var (
	DefaultAdminNames = []string{
		"S2luZw==",
		"UmVk",
		"QXBwbGU=",
		"Q2F0",
	}

	DefaultNodeNames = []string{
		"S2luZw==",
		"UmVk",
		"QXBwbGU=",
		"Q2F0",

		"bm9kZTU=",
		"bm9kZTY=",
		"bm9kZTc=",
		"bm9kZTg=",
	}

	DefaultNodeKeys = []string{
		"b6477143e17f889263044f6cf463dc37177ac4526c4c39a7a344198457024a2f",
		"05c3708d30c2c72c4b36314a41f30073ab18ea226cf8c6b9f566720bfe2e8631",
		"85a94dd51403590d4f149f9230b6f5de3a08e58899dcaf0f77768efb1825e854",
		"72efcf4bb0e8a300d3e47e6a10f630bcd540de933f01ed5380897fc5e10dc95d",

		"06bf783a69c860a2ab33fe2f99fed38d14bbdba7ef2295bbcb5a073e6c8847ec",
		"bfee1d369f1a98070f85b3b5b3508aaf071440fcdf7bdcb9c725fea835f17433",
		"508d3fd4ec16aff6443cc58bf3df44e55d5d384b1e56529bf52b0c25e8fcf8f7",
		"ffa932acb7c1099de1029070e7def812f8b2c9433adfb8a90b3cb132233a7690",
	}

	DefaultNodeAddrs = []string{
		"0xc7F999b83Af6DF9e67d0a37Ee7e900bF38b3D013",
		"0x79a1215469FaB6f9c63c1816b45183AD3624bE34",
		"0x97c8B516D19edBf575D72a172Af7F418BE498C37",
		"0xc0Ff2e0b3189132D815b8eb325bE17285AC898f8",

		"0xd0091F6D0b39B9E9D2E9051fA46d13B63b8C7B18",
		"0xFd19030f51719D5601Bb079e5c5Be1eD07E01de2",
		"0xE4b988C0BEa762B8809a0E4D14F3ac3f922B41B3",
		"0x5FC85d64dE2125986b1581b4805a43Bfb3af5E52",
	}
)
View Source
var (
	// BuildCommit build git commit hash
	BuildCommit = ""

	// BuildBranch build git branch
	BuildBranch = ""

	// BuildVersion build project version
	BuildVersion = "0.0.0"

	// BuildDate compile date
	BuildDate = ""

	BuildVersionSecret = "Hangzhou"

	BuildNet = ""

	// GoVersion system go version
	GoVersion = runtime.Version()

	// Platform info
	Platform = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
)
View Source
var SupportMultiNode = make(map[string]bool)

Functions

func CheckWritable

func CheckWritable(dir string) error

func GenerateKey

func GenerateKey() (*ecdsa.PrivateKey, error)

GenerateKey use secp256k1

func GenesisEpochInfo

func GenesisEpochInfo(epochEnable bool) *rbft.EpochInfo

func GetStoragePath

func GetStoragePath(repoRoot string, subPath ...string) string

func KeyString

func KeyString(key *ecdsa.PrivateKey) string

func KeyToNodeID

func KeyToNodeID(sk *ecdsa.PrivateKey) (string, error)

func Libp2pKeyFromECDSAKey

func Libp2pKeyFromECDSAKey(sk *ecdsa.PrivateKey) (libp2pcrypto.PrivKey, error)

func LoadAccountKey

func LoadAccountKey(repoRoot string) (*ecdsa.PrivateKey, error)

func LoadP2PKey

func LoadP2PKey(repoRoot string) (*ecdsa.PrivateKey, error)

func LoadRepoRootFromEnv

func LoadRepoRootFromEnv(repoRoot string) (string, error)

func MarshalConfig

func MarshalConfig(config any) (string, error)

func ParseKey

func ParseKey(keyBytes []byte) (*ecdsa.PrivateKey, error)

func ReadKey

func ReadKey(keyPath string) (*ecdsa.PrivateKey, error)

func Register

func Register(consensusType string, isSupported bool)

func RemovePID

func RemovePID(rootPath string) error

func StringToTimeDurationHookFunc

func StringToTimeDurationHookFunc() mapstructure.DecodeHookFunc

func WriteKey

func WriteKey(keyPath string, key *ecdsa.PrivateKey) error

func WritePid

func WritePid(rootPath string) error

Types

type Access

type Access struct {
	EnableWhiteList bool `mapstructure:"enable_white_list" toml:"enable_white_list"`
}

type Admin

type Admin struct {
	Address string `mapstructure:"address" toml:"address"`
	Weight  uint64 `mapstructure:"weight" toml:"weight"`
	Name    string `mapstructure:"name" toml:"name"`
}

type Config

type Config struct {
	Ulimit    uint64    `mapstructure:"ulimit" toml:"ulimit"`
	Port      Port      `mapstructure:"port" toml:"port"`
	JsonRPC   JsonRPC   `mapstructure:"jsonrpc" toml:"jsonrpc"`
	P2P       P2P       `mapstructure:"p2p" toml:"p2p"`
	Sync      Sync      `mapstructure:"sync" toml:"sync"`
	Consensus Consensus `mapstructure:"consensus" toml:"consensus"`
	Storage   Storage   `mapstructure:"storage" toml:"storage"`
	Ledger    Ledger    `mapstructure:"ledger" toml:"ledger"`
	Executor  Executor  `mapstructure:"executor" toml:"executor"`
	PProf     PProf     `mapstructure:"pprof" toml:"pprof"`
	Monitor   Monitor   `mapstructure:"monitor" toml:"monitor"`
	Log       Log       `mapstructure:"log" toml:"log"`
	Access    Access    `mapstructure:"access" toml:"access"`
}

func AriesConfig

func AriesConfig() *Config

func DefaultConfig

func DefaultConfig() *Config

func LoadConfig

func LoadConfig(repoRoot string) (*Config, error)

func TaurusConfig added in v0.4.1

func TaurusConfig() *Config

func (*Config) Bytes

func (c *Config) Bytes() ([]byte, error)

type Consensus

type Consensus struct {
	Type        string `mapstructure:"type" toml:"type"`
	StorageType string `mapstructure:"storage_type" toml:"storage_type"`
}

type ConsensusConfig

type ConsensusConfig struct {
	TimedGenBlock TimedGenBlock     `mapstructure:"timed_gen_block" toml:"timed_gen_block"`
	Limit         ReceiveMsgLimiter `mapstructure:"limit" toml:"limit"`
	TxPool        TxPool            `mapstructure:"tx_pool" toml:"tx_pool"`
	TxCache       TxCache           `mapstructure:"tx_cache" toml:"tx_cache"`
	Rbft          RBFT              `mapstructure:"rbft" toml:"rbft"`
	Solo          Solo              `mapstructure:"solo" toml:"solo"`
}

func AriesConsensusConfig

func AriesConsensusConfig() *ConsensusConfig

func DefaultConsensusConfig

func DefaultConsensusConfig() *ConsensusConfig

func LoadConsensusConfig

func LoadConsensusConfig(repoRoot string) (*ConsensusConfig, error)

func TaurusConsensusConfig added in v0.4.1

func TaurusConsensusConfig() *ConsensusConfig

type Duration

type Duration time.Duration

func (*Duration) MarshalText

func (d *Duration) MarshalText() (text []byte, err error)

func (*Duration) String

func (d *Duration) String() string

func (*Duration) ToDuration

func (d *Duration) ToDuration() time.Duration

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

type EVM

type EVM struct {
	DisableMaxCodeSizeLimit bool `mapstructure:"disable_max_code_size_limit" toml:"disable_max_code_size_limit"`
}

type Executor

type Executor struct {
	Type            string `mapstructure:"type" toml:"type"`
	DisableRollback bool   `mapstructure:"disable_rollback" toml:"disable_rollback"`
	EVM             EVM    `mapstructure:"evm" toml:"evm"`
}

type GenesisConfig

type GenesisConfig struct {
	ChainID                uint64          `mapstructure:"chainid" toml:"chainid"`
	Balance                string          `mapstructure:"balance" toml:"balance"`
	Admins                 []*Admin        `mapstructure:"admins" toml:"admins"`
	InitWhiteListProviders []string        `mapstructure:"init_white_list_providers" toml:"init_white_list_providers"`
	Accounts               []string        `mapstructure:"accounts" toml:"accounts"`
	EpochInfo              *rbft.EpochInfo `mapstructure:"epoch_info" toml:"epoch_info"`
	NodeNames              []*NodeName     `mapstructure:"node_names" toml:"node_names"`
}

func AriesGenesisConfig

func AriesGenesisConfig() *GenesisConfig

func DefaultGenesisConfig

func DefaultGenesisConfig(epochEnable bool) *GenesisConfig

func LoadGenesisConfig

func LoadGenesisConfig(repoRoot string) (*GenesisConfig, error)

func TaurusGenesisConfig added in v0.4.1

func TaurusGenesisConfig() *GenesisConfig

type JLimiter

type JLimiter struct {
	Interval Duration `mapstructure:"interval" toml:"interval"`
	Quantum  int64    `mapstructure:"quantum" toml:"quantum"`
	Capacity int64    `mapstructure:"capacity" toml:"capacity"`
	Enable   bool     `mapstructure:"enable" toml:"enable"`
}

type JsonRPC

type JsonRPC struct {
	GasCap                       uint64     `mapstructure:"gas_cap" toml:"gas_cap"`
	EVMTimeout                   Duration   `mapstructure:"evm_timeout" toml:"evm_timeout"`
	ReadLimiter                  JLimiter   `mapstructure:"read_limiter" toml:"read_limiter"`
	WriteLimiter                 JLimiter   `mapstructure:"write_limiter" toml:"write_limiter"`
	RejectTxsIfConsensusAbnormal bool       `mapstructure:"reject_txs_if_consensus_abnormal" toml:"reject_txs_if_consensus_abnormal"`
	QueryLimit                   QueryLimit `mapstructure:"query_limit" toml:"query_limit"`
}

type Ledger

type Ledger struct {
	ChainLedgerCacheSize           int `mapstructure:"chain_ledger_cache_size" toml:"chain_ledger_cache_size"`
	StateLedgerCacheMegabytesLimit int `mapstructure:"state_ledger_cache_megabytes_limit" toml:"state_ledger_cache_megabytes_limit"`
	StateLedgerAccountCacheSize    int `mapstructure:"state_ledger_account_cache_size" toml:"state_ledger_account_cache_size"`
}

type Log

type Log struct {
	Level            string `mapstructure:"level" toml:"level"`
	Filename         string `mapstructure:"filename" toml:"filename"`
	ReportCaller     bool   `mapstructure:"report_caller" toml:"report_caller"`
	EnableCompress   bool   `mapstructure:"enable_compress" toml:"enable_compress"`
	EnableColor      bool   `mapstructure:"enable_color" toml:"enable_color"`
	DisableTimestamp bool   `mapstructure:"disable_timestamp" toml:"disable_timestamp"`

	// unit: day
	MaxAge uint `mapstructure:"max_age" toml:"max_age"`

	// unit: MB
	MaxSize uint `mapstructure:"max_size" toml:"max_size"`

	RotationTime Duration  `mapstructure:"rotation_time" toml:"rotation_time"`
	Module       LogModule `mapstructure:"module" toml:"module"`
}

type LogModule

type LogModule struct {
	P2P        string `mapstructure:"p2p" toml:"p2p"`
	Consensus  string `mapstructure:"consensus" toml:"consensus"`
	Executor   string `mapstructure:"executor" toml:"executor"`
	Governance string `mapstructure:"governance" toml:"governance"`
	API        string `mapstructure:"api" toml:"api"`
	APP        string `mapstructure:"app" toml:"app"`
	CoreAPI    string `mapstructure:"coreapi" toml:"coreapi"`
	Storage    string `mapstructure:"storage" toml:"storage"`
	Profile    string `mapstructure:"profile" toml:"profile"`
	Finance    string `mapstructure:"finance" toml:"finance"`
	TxPool     string `mapstructure:"txpool" toml:"txpool"`
	Access     string `mapstructure:"access" toml:"access"`
	BlockSync  string `mapstructure:"blocksync" toml:"blocksync"`
	Epoch      string `mapstructure:"epoch" toml:"epoch"`
}

type Monitor

type Monitor struct {
	Enable          bool `mapstructure:"enable" toml:"enable"`
	EnableExpensive bool `mapstructure:"enable_expensive" toml:"enable_expensive"`
}

type NodeName

type NodeName struct {
	ID   uint64 `mapstructure:"id" toml:"id"`
	Name string `mapstructure:"name" toml:"name"`
}

func GenesisNodeNameInfo

func GenesisNodeNameInfo(epochEnable bool) []*NodeName

type P2P

type P2P struct {
	BootstrapNodeAddresses []string `mapstructure:"bootstrap_node_addresses" toml:"bootstrap_node_addresses"`
	Security               string   `mapstructure:"security" toml:"security"`
	SendTimeout            Duration `mapstructure:"send_timeout" toml:"send_timeout"`
	ReadTimeout            Duration `mapstructure:"read_timeout" toml:"read_timeout"`
	Pipe                   P2PPipe  `mapstructure:"pipe" toml:"pipe"`
}

type P2PPipe

type P2PPipe struct {
	ReceiveMsgCacheSize      int                    `mapstructure:"receive_msg_cache_size" toml:"receive_msg_cache_size"`
	BroadcastType            string                 `mapstructure:"broadcast_type" toml:"broadcast_type"`
	SimpleBroadcast          P2PPipeSimpleBroadcast `mapstructure:"simple_broadcast" toml:"simple_broadcast"`
	Gossipsub                P2PPipeGossipsub       `mapstructure:"gossipsub" toml:"gossipsub"`
	UnicastReadTimeout       Duration               `mapstructure:"unicast_read_timeout" toml:"unicast_read_timeout"`
	UnicastSendRetryNumber   int                    `mapstructure:"unicast_send_retry_number" toml:"unicast_send_retry_number"`
	UnicastSendRetryBaseTime Duration               `mapstructure:"unicast_send_retry_base_time" toml:"unicast_send_retry_base_time"`
	FindPeerTimeout          Duration               `mapstructure:"find_peer_timeout" toml:"find_peer_timeout"`
	ConnectTimeout           Duration               `mapstructure:"connect_timeout" toml:"connect_timeout"`
}

type P2PPipeGossipsub

type P2PPipeGossipsub struct {
	DisableCustomMsgIDFn   bool     `mapstructure:"disable_custom_msg_id_fn" toml:"disable_custom_msg_id_fn"`
	SubBufferSize          int      `mapstructure:"sub_buffer_size" toml:"sub_buffer_size"`
	PeerOutboundBufferSize int      `mapstructure:"peer_outbound_buffer_size" toml:"peer_outbound_buffer_size"`
	ValidateBufferSize     int      `mapstructure:"validate_buffer_size" toml:"validate_buffer_size"`
	SeenMessagesTTL        Duration `mapstructure:"seen_messages_ttl" toml:"seen_messages_ttl"`
	EnableMetrics          bool     `mapstructure:"enable_metrics" toml:"enable_metrics"`
}

type P2PPipeSimpleBroadcast

type P2PPipeSimpleBroadcast struct {
	WorkerCacheSize        int `mapstructure:"worker_cache_size" toml:"worker_cache_size"`
	WorkerConcurrencyLimit int `mapstructure:"worker_concurrency_limit" toml:"worker_concurrency_limit"`
}

type PProf

type PProf struct {
	Enable   bool     `mapstructure:"enable" toml:"enbale"`
	PType    string   `mapstructure:"ptype" toml:"ptype"`
	Mode     string   `mapstructure:"mode" toml:"mode"`
	Duration Duration `mapstructure:"duration" toml:"duration"`
}

type Port

type Port struct {
	JsonRpc   int64 `mapstructure:"jsonrpc" toml:"jsonrpc"`
	WebSocket int64 `mapstructure:"websocket" toml:"websocket"`
	P2P       int64 `mapstructure:"p2p" toml:"p2p"`
	PProf     int64 `mapstructure:"pprof" toml:"pprof"`
	Monitor   int64 `mapstructure:"monitor" toml:"monitor"`
}

type QueryLimit added in v0.4.1

type QueryLimit struct {
	GetLogsBlockRangeLimit uint64 `mapstructure:"get_logs_block_range_limit" toml:"get_logs_block_range_limit"`
}

type RBFT

type RBFT struct {
	EnableMultiPipes          bool        `mapstructure:"enable_multi_pipes" toml:"enable_multi_pipes"`
	EnableMetrics             bool        `mapstructure:"enable_metrics" toml:"enable_metrics"`
	CommittedBlockCacheNumber uint64      `mapstructure:"committed_block_cache_number" toml:"committed_block_cache_number"`
	Timeout                   RBFTTimeout `mapstructure:"timeout" toml:"timeout"`
}

type RBFTTimeout

type RBFTTimeout struct {
	NullRequest      Duration `mapstructure:"null_request" toml:"null_request"`
	Request          Duration `mapstructure:"request" toml:"request"`
	ResendViewChange Duration `mapstructure:"resend_viewchange" toml:"resend_viewchange"`
	CleanViewChange  Duration `mapstructure:"clean_viewchange" toml:"clean_viewchange"`
	NewView          Duration `mapstructure:"new_view" toml:"new_view"`
	SyncState        Duration `mapstructure:"sync_state" toml:"sync_state"`
	SyncStateRestart Duration `mapstructure:"sync_state_restart" toml:"sync_state_restart"`
	FetchCheckpoint  Duration `mapstructure:"fetch_checkpoint" toml:"fetch_checkpoint"`
	FetchView        Duration `mapstructure:"fetch_view" toml:"fetch_view"`
	BatchTimeout     Duration `mapstructure:"batch_timeout" toml:"batch_timeout"`
}

type ReceiveMsgLimiter

type ReceiveMsgLimiter struct {
	Enable bool  `mapstructure:"enable" toml:"enable"`
	Limit  int64 `mapstructure:"limit" toml:"limit"`
	Burst  int64 `mapstructure:"burst" toml:"burst"`
}

type Repo

type Repo struct {
	RepoRoot        string
	Config          *Config
	ConsensusConfig *ConsensusConfig
	GenesisConfig   *GenesisConfig
	AccountKey      *ecdsa.PrivateKey
	AccountAddress  string
	P2PKey          *ecdsa.PrivateKey
	P2PID           string

	// TODO: Move to epoch manager service
	// Track current epoch info, will be updated bt executor
	EpochInfo *rbft.EpochInfo

	ReadonlyMode bool
}

func Default

func Default(repoRoot string) (*Repo, error)

func DefaultWithNodeIndex

func DefaultWithNodeIndex(repoRoot string, nodeIndex int, epochEnable bool) (*Repo, error)

func Load

func Load(repoRoot string) (*Repo, error)

load config from the repo, which is automatically initialized when the repo is empty

func (*Repo) AccountKeySign

func (r *Repo) AccountKeySign(data []byte) ([]byte, error)

func (*Repo) Flush

func (r *Repo) Flush() error

func (*Repo) PrintNodeInfo

func (r *Repo) PrintNodeInfo()

type Solo

type Solo struct {
	BatchTimeout     Duration `mapstructure:"batch_timeout" toml:"batch_timeout"`
	CheckpointPeriod uint64   `mapstructure:"checkpoint_period" toml:"checkpoint_period"`
}

type Storage

type Storage struct {
	KvType      string `mapstructure:"kv_type" toml:"kv_type"`
	KvCacheSize int    `mapstructure:"kv_cache_size" toml:"kv_cache_size"`
	Sync        bool   `mapstructure:"sync" toml:"sync"`
}

type Sync

type Sync struct {
	RequesterRetryTimeout Duration `mapstructure:"requester_retry_timeout" toml:"requester_retry_timeout"`
	TimeoutCountLimit     uint64   `mapstructure:"timeout_count_limit" toml:"timeout_count_limit"`
	ConcurrencyLimit      uint64   `mapstructure:"concurrency_limit" toml:"concurrency_limit"`
}

type TimedGenBlock

type TimedGenBlock struct {
	NoTxBatchTimeout Duration `mapstructure:"no_tx_batch_timeout" toml:"no_tx_batch_timeout"`
}

type TxCache

type TxCache struct {
	SetSize    int      `mapstructure:"set_size" toml:"set_size"`
	SetTimeout Duration `mapstructure:"set_timeout" toml:"set_timeout"`
}

type TxPool

type TxPool struct {
	PoolSize              uint64   `mapstructure:"pool_size" toml:"pool_size"`
	ToleranceTime         Duration `mapstructure:"tolerance_time" toml:"tolerance_time"`
	ToleranceRemoveTime   Duration `mapstructure:"tolerance_remove_time" toml:"tolerance_remove_time"`
	CleanEmptyAccountTime Duration `mapstructure:"clean_empty_account_time" toml:"clean_empty_account_time"`
	ToleranceNonceGap     uint64   `mapstructure:"tolerance_nonce_gap" toml:"tolerance_nonce_gap"`
}

Jump to

Keyboard shortcuts

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