fork

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Keys in IBFT Configuration
	KeyType          = "type"
	KeyTypes         = "types"
	KeyValidatorType = "validator_type"
	KeyBlockTime     = "blockTime"
)

Variables

View Source
var (
	ErrForkNotFound           = errors.New("fork not found")
	ErrSignerNotFound         = errors.New("signer not found")
	ErrValidatorStoreNotFound = errors.New("validator set not found")
	ErrKeyManagerNotFound     = errors.New("key manager not found")
)
View Source
var (
	ErrTxInLastEpochOfBlock = errors.New("block must not have transactions in the last of epoch")
)
View Source
var (
	ErrUndefinedIBFTConfig = errors.New("IBFT config is not defined")
)

Functions

This section is empty.

Types

type ContractValidatorStoreWrapper

type ContractValidatorStoreWrapper struct {
	*contract.ContractValidatorStore
	// contains filtered or unexported fields
}

ContractValidatorStoreWrapper is a wrapper of *contract.ContractValidatorStore in order to add Close and GetValidators

func NewContractValidatorStoreWrapper

func NewContractValidatorStoreWrapper(
	logger hclog.Logger,
	blockchain store.HeaderGetter,
	executor contract.Executor,
	getSigner func(uint64) (signer.Signer, error),
) (*ContractValidatorStoreWrapper, error)

NewContractValidatorStoreWrapper creates *ContractValidatorStoreWrapper

func (*ContractValidatorStoreWrapper) Close

Close is closer process

func (*ContractValidatorStoreWrapper) GetValidators

func (w *ContractValidatorStoreWrapper) GetValidators(
	height, epochSize, forkFrom uint64,
) (validators.Validators, error)

GetValidators gets and returns validators at the given height

type ForkManager

type ForkManager struct {
	// contains filtered or unexported fields
}

ForkManager is the module that has Fork configuration and multiple version of submodules and returns the proper submodule at specified height

func NewForkManager

func NewForkManager(
	logger hclog.Logger,
	blockchain store.HeaderGetter,
	executor contract.Executor,
	secretManager secrets.SecretsManager,
	filePath string,
	epochSize uint64,
	ibftConfig map[string]interface{},
) (*ForkManager, error)

NewForkManager is a constructor of ForkManager

func (*ForkManager) Close

func (m *ForkManager) Close() error

Close calls termination process of submodules

func (*ForkManager) GetHooks

func (m *ForkManager) GetHooks(height uint64) HooksInterface

GetHooks returns a hooks at specified height

func (*ForkManager) GetSigner

func (m *ForkManager) GetSigner(height uint64) (signer.Signer, error)

GetSigner returns a proper signer at specified height

func (*ForkManager) GetValidatorStore

func (m *ForkManager) GetValidatorStore(height uint64) (ValidatorStore, error)

GetValidatorStore returns a proper validator set at specified height

func (*ForkManager) GetValidators

func (m *ForkManager) GetValidators(height uint64) (validators.Validators, error)

GetValidators returns validators at specified height

func (*ForkManager) Initialize

func (m *ForkManager) Initialize() error

Initialize initializes ForkManager on initialization phase

type HeaderModifier

type HeaderModifier interface {
	ModifyHeader(*types.Header, types.Address) error
	VerifyHeader(*types.Header) error
	ProcessHeader(*types.Header) error
}

HeaderModifier is an interface for the struct that modifies block header for additional process

type HooksInterface

type HooksInterface interface {
	ShouldWriteTransactions(uint64) bool
	ModifyHeader(*types.Header, types.Address) error
	VerifyHeader(*types.Header) error
	VerifyBlock(*types.Block) error
	ProcessHeader(*types.Header) error
	PreCommitState(*types.Header, *state.Transition) error
	PostInsertBlock(*types.Block) error
}

HooksInterface is an interface of hooks to be called by IBFT This interface is referred from fork and ibft package

type HooksRegister

type HooksRegister interface {
	// RegisterHooks register hooks for the given block height
	RegisterHooks(hooks *hook.Hooks, height uint64)
}

HookRegister is an interface that ForkManager calls for hook registrations

type IBFTFork

type IBFTFork struct {
	Type          IBFTType                 `json:"type"`
	ValidatorType validators.ValidatorType `json:"validator_type"`
	Deployment    *common.JSONNumber       `json:"deployment,omitempty"`
	From          common.JSONNumber        `json:"from"`
	To            *common.JSONNumber       `json:"to,omitempty"`
	BlockTime     *common.Duration         `json:"blockTime,omitempty"`

	// PoA
	Validators validators.Validators `json:"validators,omitempty"`

	// PoS
	MaxValidatorCount *common.JSONNumber `json:"maxValidatorCount,omitempty"`
	MinValidatorCount *common.JSONNumber `json:"minValidatorCount,omitempty"`
}

IBFT Fork represents setting in params.engine.ibft of genesis.json

func (*IBFTFork) UnmarshalJSON

func (f *IBFTFork) UnmarshalJSON(data []byte) error

type IBFTForks

type IBFTForks []*IBFTFork

func GetIBFTForks

func GetIBFTForks(ibftConfig map[string]interface{}) (IBFTForks, error)

GetIBFTForks returns IBFT fork configurations from chain config

type IBFTType

type IBFTType string

Define the type of the IBFT consensus

const (
	// PoA defines the Proof of Authority IBFT type,
	// where the validator set is changed through voting / pre-set in genesis
	PoA IBFTType = "PoA"

	// PoS defines the Proof of Stake IBFT type,
	// where the validator set it changed through staking on the Staking Smart Contract
	PoS IBFTType = "PoS"
)

func ParseIBFTType

func ParseIBFTType(ibftType string) (IBFTType, error)

ParseIBFTType converts a ibftType string representation to a IBFTType

func (IBFTType) String

func (t IBFTType) String() string

String is a helper method for casting a IBFTType to a string representation

type PoAHookRegister

type PoAHookRegister struct {
	// contains filtered or unexported fields
}

PoAHookRegisterer that registers hooks for PoA mode

func NewPoAHookRegisterer

func NewPoAHookRegisterer(
	getValidatorsStore func(*IBFTFork) ValidatorStore,
	forks IBFTForks,
) *PoAHookRegister

NewPoAHookRegisterer is a constructor of PoAHookRegister

func (*PoAHookRegister) RegisterHooks

func (r *PoAHookRegister) RegisterHooks(hooks *hook.Hooks, height uint64)

RegisterHooks registers hooks of PoA for voting and validators updating

type PoSHookRegister

type PoSHookRegister struct {
	// contains filtered or unexported fields
}

PoAHookRegisterer that registers hooks for PoS mode

func NewPoSHookRegister

func NewPoSHookRegister(
	forks IBFTForks,
	epochSize uint64,
) *PoSHookRegister

NewPoSHookRegister is a constructor of PoSHookRegister

func (*PoSHookRegister) RegisterHooks

func (r *PoSHookRegister) RegisterHooks(hooks *hook.Hooks, height uint64)

RegisterHooks registers hooks of PoA for additional block verification and contract deployment

type SnapshotValidatorStoreWrapper

type SnapshotValidatorStoreWrapper struct {
	*snapshot.SnapshotValidatorStore
	// contains filtered or unexported fields
}

SnapshotValidatorStoreWrapper is a wrapper of store.SnapshotValidatorStore in order to add initialization and closer process with side effect

func NewSnapshotValidatorStoreWrapper

func NewSnapshotValidatorStoreWrapper(
	logger hclog.Logger,
	blockchain store.HeaderGetter,
	getSigner func(uint64) (signer.Signer, error),
	dirPath string,
	epochSize uint64,
) (*SnapshotValidatorStoreWrapper, error)

NewSnapshotValidatorStoreWrapper loads data from local storage and creates *SnapshotValidatorStoreWrapper

func (*SnapshotValidatorStoreWrapper) Close

Close saves SnapshotValidator data into local storage

func (*SnapshotValidatorStoreWrapper) GetValidators

func (w *SnapshotValidatorStoreWrapper) GetValidators(height, _, _ uint64) (validators.Validators, error)

GetValidators returns validators at the specific height

type Updatable

type Updatable interface {
	// UpdateValidatorSet updates validators forcibly
	// in order that new validators are available from the given height
	UpdateValidatorSet(validators.Validators, uint64) error
}

Updatable is an interface for the struct that updates validators in the middle

type ValidatorStore

type ValidatorStore interface {
	store.ValidatorStore
	// Close defines termination process
	Close() error
	// GetValidators is a method to return validators at the given height
	GetValidators(height, epochSize, forkFrom uint64) (validators.Validators, error)
}

ValidatorStore is an interface that ForkManager calls for Validator Store

Jump to

Keyboard shortcuts

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