Documentation
¶
Index ¶
- Constants
- Variables
- func Productivity(bc Blockchain, startHeight uint64, endHeight uint64) (map[string]uint64, error)
- type BlockCreationSubscriber
- type BlockMinter
- type BlockValidationCfg
- type BlockValidationOption
- type Blockchain
- type Config
- type MintOption
- type MintOptions
- type Option
- type PubSubManager
Constants ¶
const ( SigP256k1 = "secp256k1" SigP256sm2 = "p256sm2" )
const
Variables ¶
var ( // ErrInvalidTipHeight is the error returned when the block height is not valid ErrInvalidTipHeight = errors.New("invalid tip height") // ErrInvalidBlock is the error returned when the block is not valid ErrInvalidBlock = errors.New("failed to validate the block") // ErrActionNonce is the error when the nonce of the action is wrong ErrActionNonce = errors.New("invalid action nonce") // ErrInsufficientGas indicates the error of insufficient gas value for data storage ErrInsufficientGas = errors.New("insufficient intrinsic gas value") // ErrBalance indicates the error of balance ErrBalance = errors.New("invalid balance") )
var ( // DefaultConfig is the default config of chain DefaultConfig = Config{ ChainDBPath: "/var/data/chain.db", TrieDBPatchFile: "/var/data/trie.db.patch", TrieDBPath: "/var/data/trie.db", StakingPatchDir: "/var/data", IndexDBPath: "/var/data/index.db", BloomfilterIndexDBPath: "/var/data/bloomfilter.index.db", CandidateIndexDBPath: "/var/data/candidate.index.db", StakingIndexDBPath: "/var/data/staking.index.db", SGDIndexDBPath: "/var/data/sgd.index.db", ContractStakingIndexDBPath: "/var/data/contractstaking.index.db", BlobStoreDBPath: "/var/data/blob.db", BlobStoreRetentionDays: 21, ID: 1, EVMNetworkID: 4689, Address: "", ProducerPrivKey: generateRandomKey(SigP256k1), SignatureScheme: []string{SigP256k1}, EmptyGenesis: false, GravityChainDB: db.Config{DbPath: "/var/data/poll.db", NumRetries: 10}, Committee: committee.Config{ GravityChainAPIs: []string{}, }, EnableTrielessStateDB: true, EnableStateDBCaching: false, EnableArchiveMode: false, EnableAsyncIndexWrite: true, EnableSystemLogIndexer: false, EnableStakingProtocol: true, EnableStakingIndexer: false, AllowedBlockGasResidue: 10000, MaxCacheSize: 0, PollInitialCandidatesInterval: 10 * time.Second, StateDBCacheSize: 1000, WorkingSetCacheSize: 20, StreamingBlockBufferSize: 200, PersistStakingPatchBlock: 19778037, FixAliasForNonStopHeight: 19778036, FactoryDBType: db.DBBolt, MintTimeout: 700 * time.Millisecond, } // ErrConfig config error ErrConfig = errors.New("config error") )
var ErrVault = errors.New("vault error")
ErrVault vault error
Functions ¶
func Productivity ¶
Productivity returns the map of the number of blocks produced per delegate in given epoch
Types ¶
type BlockCreationSubscriber ¶
BlockCreationSubscriber is an interface which will get notified when a block is created
type BlockMinter ¶ added in v2.2.0
type BlockMinter interface { // Mint creates a new block Mint(context.Context, crypto.PrivateKey) (*block.Block, error) }
BlockMinter is the block minter interface
type BlockValidationCfg ¶
type BlockValidationCfg struct {
// contains filtered or unexported fields
}
type BlockValidationOption ¶
type BlockValidationOption func(*BlockValidationCfg)
func SkipSidecarValidationOption ¶
func SkipSidecarValidationOption() BlockValidationOption
type Blockchain ¶
type Blockchain interface { lifecycle.StartStopper // For exposing blockchain states // BlockHeaderByHeight return block header by height BlockHeaderByHeight(height uint64) (*block.Header, error) // BlockHeader return block header by hash BlockHeader(hash hash.Hash256) (*block.Header, error) BlockFooterByHeight(height uint64) (*block.Footer, error) // ChainID returns the chain ID ChainID() uint32 // EvmNetworkID returns the evm network ID EvmNetworkID() uint32 // ChainAddress returns chain address on parent chain, the root chain return empty. ChainAddress() string // TipHash returns tip block's hash TipHash() hash.Hash256 // TipHeight returns tip block's height TipHeight() uint64 // Genesis returns the genesis Genesis() genesis.Genesis // Context returns current context Context(context.Context) (context.Context, error) // ContextAtHeight returns context at given height ContextAtHeight(context.Context, uint64) (context.Context, error) // For block operations // MintNewBlock creates a new block with given actions // Note: the coinbase transfer will be added to the given transfers when minting a new block MintNewBlock(time.Time, ...MintOption) (*block.Block, error) // CommitBlock validates and appends a block to the chain CommitBlock(blk *block.Block) error // ValidateBlock validates a new block before adding it to the blockchain ValidateBlock(*block.Block, ...BlockValidationOption) error // AddSubscriber make you listen to every single produced block AddSubscriber(BlockCreationSubscriber) error // RemoveSubscriber make you listen to every single produced block RemoveSubscriber(BlockCreationSubscriber) error }
Blockchain represents the blockchain data structure and hosts the APIs to access it
func NewBlockchain ¶
func NewBlockchain(cfg Config, g genesis.Genesis, dao blockdao.BlockDAO, bbf BlockMinter, opts ...Option) Blockchain
NewBlockchain creates a new blockchain and DB instance
type Config ¶
type Config struct { ChainDBPath string `yaml:"chainDBPath"` TrieDBPatchFile string `yaml:"trieDBPatchFile"` TrieDBPath string `yaml:"trieDBPath"` StakingPatchDir string `yaml:"stakingPatchDir"` IndexDBPath string `yaml:"indexDBPath"` BloomfilterIndexDBPath string `yaml:"bloomfilterIndexDBPath"` CandidateIndexDBPath string `yaml:"candidateIndexDBPath"` StakingIndexDBPath string `yaml:"stakingIndexDBPath"` // deprecated SGDIndexDBPath string `yaml:"sgdIndexDBPath"` ContractStakingIndexDBPath string `yaml:"contractStakingIndexDBPath"` BlobStoreDBPath string `yaml:"blobStoreDBPath"` BlobStoreRetentionDays uint32 `yaml:"blobStoreRetentionDays"` ID uint32 `yaml:"id"` EVMNetworkID uint32 `yaml:"evmNetworkID"` Address string `yaml:"address"` ProducerPrivKey string `yaml:"producerPrivKey"` ProducerPrivKeySchema string `yaml:"producerPrivKeySchema"` SignatureScheme []string `yaml:"signatureScheme"` EmptyGenesis bool `yaml:"emptyGenesis"` GravityChainDB db.Config `yaml:"gravityChainDB"` Committee committee.Config `yaml:"committee"` // EnableTrielessStateDB enables trieless state db (deprecated) EnableTrielessStateDB bool `yaml:"enableTrielessStateDB"` // EnableStateDBCaching enables cachedStateDBOption EnableStateDBCaching bool `yaml:"enableStateDBCaching"` // EnableArchiveMode is only meaningful when EnableTrielessStateDB is false EnableArchiveMode bool `yaml:"enableArchiveMode"` // EnableAsyncIndexWrite enables writing the block actions' and receipts' index asynchronously EnableAsyncIndexWrite bool `yaml:"enableAsyncIndexWrite"` // deprecated EnableSystemLogIndexer bool `yaml:"enableSystemLog"` // EnableStakingProtocol enables staking protocol EnableStakingProtocol bool `yaml:"enableStakingProtocol"` // EnableStakingIndexer enables staking indexer EnableStakingIndexer bool `yaml:"enableStakingIndexer"` // 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"` // PollInitialCandidatesInterval is the config for committee init db PollInitialCandidatesInterval time.Duration `yaml:"pollInitialCandidatesInterval"` // StateDBCacheSize is the max size of statedb LRU cache StateDBCacheSize int `yaml:"stateDBCacheSize"` // WorkingSetCacheSize is the max size of workingset cache in state factory WorkingSetCacheSize uint64 `yaml:"workingSetCacheSize"` // StreamingBlockBufferSize StreamingBlockBufferSize uint64 `yaml:"streamingBlockBufferSize"` // PersistStakingPatchBlock is the block to persist staking patch PersistStakingPatchBlock uint64 `yaml:"persistStakingPatchBlock"` // FixAliasForNonStopHeight is the height to fix candidate alias for a non-stopping node FixAliasForNonStopHeight uint64 `yaml:"fixAliasForNonStopHeight"` // FactoryDBType is the type of factory db FactoryDBType string `yaml:"factoryDBType"` // MintTimeout is the timeout for minting MintTimeout time.Duration `yaml:"-"` }
Config is the config struct for blockchain package
func (*Config) ProducerAddress ¶
ProducerAddress() returns the configured producer address derived from key
func (*Config) ProducerPrivateKeys ¶ added in v2.2.0
func (cfg *Config) ProducerPrivateKeys() []crypto.PrivateKey
ProducerPrivateKeys returns the configured private keys
func (*Config) SetProducerPrivKey ¶
SetProducerPrivKey set producer privKey by PrivKeyConfigFile info
type MintOption ¶ added in v2.2.0
type MintOption func(*MintOptions)
MintOption sets the mint options
func WithProducerPrivateKey ¶ added in v2.2.0
func WithProducerPrivateKey(pk crypto.PrivateKey) MintOption
WithProducerPrivateKey sets the producer private key
type MintOptions ¶ added in v2.2.0
type MintOptions struct {
ProducerPrivateKey crypto.PrivateKey
}
MintOptions is the options to mint a new block
type Option ¶
type Option func(*blockchain) error
Option sets blockchain construction parameter
func BlockValidatorOption ¶
BlockValidatorOption sets block validator
type PubSubManager ¶
type PubSubManager interface { Start(ctx context.Context) error Stop(ctx context.Context) error AddBlockListener(BlockCreationSubscriber) error RemoveBlockListener(BlockCreationSubscriber) error SendBlockToSubscribers(*block.Block) }
PubSubManager is an interface which handles multi-thread publisher and subscribers
func NewPubSub ¶
func NewPubSub(bufferSize uint64) PubSubManager
NewPubSub creates new pubSub struct with buffersize for pendingBlock buffer channel