protocol

package
v1.14.1-rc0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 17 Imported by: 41

Documentation

Index

Constants

View Source
const (
	// SystemNamespace is the namespace to store system information such as candidates/probationList/unproductiveDelegates
	SystemNamespace = "System"
)

Variables

View Source
var (
	ErrNoName = errors.New("name does not exist")
)

Errors

View Source
var (
	// ErrUnimplemented indicates a method is not implemented yet
	ErrUnimplemented = errors.New("method is unimplemented")
)

Functions

func GetVMConfigCtx added in v1.6.3

func GetVMConfigCtx(ctx context.Context) (vm.Config, bool)

GetVMConfigCtx returns the vm config from context

func HashStringToAddress added in v1.7.1

func HashStringToAddress(str string) address.Address

HashStringToAddress generates the contract address from the protocolID of each protocol

func NewKVStoreForTrieWithStateManager added in v1.7.0

func NewKVStoreForTrieWithStateManager(ns string, sm StateManager) trie.KVStore

NewKVStoreForTrieWithStateManager creates a trie.KVStore with state manager

func NewKVStoreForTrieWithStateReader added in v1.7.0

func NewKVStoreForTrieWithStateReader(ns string, sr StateReader) trie.KVStore

NewKVStoreForTrieWithStateReader creates a trie.KVStore with state reader

func WithActionCtx added in v0.11.0

func WithActionCtx(ctx context.Context, ac ActionCtx) context.Context

WithActionCtx add ActionCtx into context.

func WithBlockCtx added in v0.11.0

func WithBlockCtx(ctx context.Context, blk BlockCtx) context.Context

WithBlockCtx add BlockCtx into context.

func WithBlockchainCtx added in v0.11.0

func WithBlockchainCtx(ctx context.Context, bc BlockchainCtx) context.Context

WithBlockchainCtx add BlockchainCtx into context.

func WithFeatureCtx added in v1.6.3

func WithFeatureCtx(ctx context.Context) context.Context

WithFeatureCtx add FeatureCtx into context.

func WithFeatureWithHeightCtx added in v1.6.3

func WithFeatureWithHeightCtx(ctx context.Context) context.Context

WithFeatureWithHeightCtx add FeatureWithHeightCtx into context.

func WithRegistry added in v1.0.0

func WithRegistry(ctx context.Context, reg *Registry) context.Context

WithRegistry adds registry to context

func WithVMConfigCtx added in v1.6.3

func WithVMConfigCtx(ctx context.Context, vmConfig vm.Config) context.Context

WithVMConfigCtx adds vm config to context

Types

type AccountState added in v0.11.0

type AccountState func(context.Context, StateReader, address.Address) (*state.Account, error)

AccountState defines a function to return the account state of a given address

type ActionCtx added in v0.11.0

type ActionCtx struct {
	// Caller is the address of whom issues this action
	Caller address.Address
	// ActionHash is the hash of the action with the sealed envelope
	ActionHash hash.Hash256
	// GasPrice is the action gas price
	GasPrice *big.Int
	// IntrinsicGas is the action intrinsic gas
	IntrinsicGas uint64
	// Nonce is the nonce of the action
	Nonce uint64
}

ActionCtx provides action auxiliary information.

func GetActionCtx added in v0.11.0

func GetActionCtx(ctx context.Context) (ActionCtx, bool)

GetActionCtx gets ActionCtx

func MustGetActionCtx added in v0.11.0

func MustGetActionCtx(ctx context.Context) ActionCtx

MustGetActionCtx must get ActionCtx . If context doesn't exist, this function panic.

type ActionHandler

type ActionHandler interface {
	Handle(context.Context, action.Action, StateManager) (*action.Receipt, error)
}

ActionHandler is the interface for the action handlers. For each incoming action, the assembled actions will be called one by one to process it. ActionHandler implementation is supposed to parse the sub-type of the action to decide if it wants to handle this action or not.

type ActionValidator

type ActionValidator interface {
	Validate(context.Context, action.Action, StateReader) error
}

ActionValidator is the interface of validating an action

type BaseStateContext added in v1.9.0

type BaseStateContext struct {
	Parameter *Parameters
}

BaseStateContext base state context

func (*BaseStateContext) Parameters added in v1.9.0

func (r *BaseStateContext) Parameters() *Parameters

Parameters base state parameters

type BlockCtx added in v0.11.0

type BlockCtx struct {
	// height of block containing those actions
	BlockHeight uint64
	// timestamp of block containing those actions
	BlockTimeStamp time.Time
	// gas Limit for perform those actions
	GasLimit uint64
	// Producer is the address of whom composes the block containing this action
	Producer address.Address
}

BlockCtx provides block auxiliary information.

func GetBlockCtx added in v0.11.0

func GetBlockCtx(ctx context.Context) (BlockCtx, bool)

GetBlockCtx gets BlockCtx

func MustGetBlockCtx added in v0.11.0

func MustGetBlockCtx(ctx context.Context) BlockCtx

MustGetBlockCtx must get BlockCtx . If context doesn't exist, this function panic.

type BlockchainCtx added in v0.11.0

type BlockchainCtx struct {
	// Tip is the information of tip block
	Tip TipInfo
	//ChainID is the native chain ID
	ChainID uint32
	// EvmNetworkID is the EVM network ID
	EvmNetworkID uint32
}

BlockchainCtx provides blockchain auxiliary information.

func GetBlockchainCtx added in v0.11.0

func GetBlockchainCtx(ctx context.Context) (BlockchainCtx, bool)

GetBlockchainCtx gets BlockchainCtx

func MustGetBlockchainCtx added in v0.11.0

func MustGetBlockchainCtx(ctx context.Context) BlockchainCtx

MustGetBlockchainCtx must get BlockchainCtx. If context doesn't exist, this function panic.

type CheckFunc added in v1.6.3

type CheckFunc func(height uint64) bool

CheckFunc is function type to check by height.

type Committer added in v1.0.0

type Committer interface {
	Commit(context.Context, StateManager) error
}

Committer performs commit action of the protocol

type Dock added in v1.0.0

type Dock interface {
	ProtocolDirty(string) bool
	Load(string, string, interface{}) error
	Unload(string, string, interface{}) error
	Reset()
}

Dock defines an interface for protocol to read/write their private data in StateReader/Manager data are stored as interface{}, user needs to type-assert on their own upon Unload()

func NewDock added in v1.0.0

func NewDock() Dock

NewDock returns a new dock

type FeatureCtx added in v1.6.3

type FeatureCtx struct {
	FixDoubleChargeGas                      bool
	SystemWideActionGasLimit                bool
	NotFixTopicCopyBug                      bool
	SetRevertMessageToReceipt               bool
	FixGetHashFnHeight                      bool
	FixSortCacheContractsAndUsePendingNonce bool
	AsyncContractTrie                       bool
	AddOutOfGasToTransactionLog             bool
	AddChainIDToConfig                      bool
	UseV2Storage                            bool
	CannotUnstakeAgain                      bool
	SkipStakingIndexer                      bool
	ReturnFetchError                        bool
	CannotTranferToSelf                     bool
	NewStakingReceiptFormat                 bool
	UpdateBlockMeta                         bool
	CurrentEpochProductivity                bool
	FixSnapshotOrder                        bool
	AllowCorrectDefaultChainID              bool
	CorrectGetHashFn                        bool
	CorrectTxLogIndex                       bool
	RevertLog                               bool
	TolerateLegacyAddress                   bool
	CreateLegacyNonceAccount                bool
	FixGasAndNonceUpdate                    bool
	FixUnproductiveDelegates                bool
	CorrectGasRefund                        bool
	SkipSystemActionNonce                   bool
	ValidateSystemAction                    bool
	AllowCorrectChainIDOnly                 bool
	AddContractStakingVotes                 bool
	FixContractStakingWeightedVotes         bool
	ExecutionSizeLimit32KB                  bool
	UseZeroNonceForFreshAccount             bool
	SharedGasWithDapp                       bool
	CandidateRegisterMustWithStake          bool
	DisableDelegateEndorsement              bool
	RefactorFreshAccountConversion          bool
	SuicideTxLogMismatchPanic               bool
}

FeatureCtx provides features information.

func GetFeatureCtx added in v1.6.3

func GetFeatureCtx(ctx context.Context) (FeatureCtx, bool)

GetFeatureCtx gets FeatureCtx.

func MustGetFeatureCtx added in v1.6.3

func MustGetFeatureCtx(ctx context.Context) FeatureCtx

MustGetFeatureCtx must get FeatureCtx. If context doesn't exist, this function panic.

type FeatureWithHeightCtx added in v1.6.3

type FeatureWithHeightCtx struct {
	GetUnproductiveDelegates CheckFunc
	ReadStateFromDB          CheckFunc
	UseV2Staking             CheckFunc
	EnableNativeStaking      CheckFunc
	StakingCorrectGas        CheckFunc
	CalculateProbationList   CheckFunc
	LoadCandidatesLegacy     CheckFunc
	CandCenterHasAlias       CheckFunc
}

FeatureWithHeightCtx provides feature check functions.

func GetFeatureWithHeightCtx added in v1.6.3

func GetFeatureWithHeightCtx(ctx context.Context) (FeatureWithHeightCtx, bool)

GetFeatureWithHeightCtx gets FeatureWithHeightCtx.

func MustGetFeatureWithHeightCtx added in v1.6.3

func MustGetFeatureWithHeightCtx(ctx context.Context) FeatureWithHeightCtx

MustGetFeatureWithHeightCtx must get FeatureWithHeightCtx. If context doesn't exist, this function panic.

type GenericValidator

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

GenericValidator is the validator for generic action verification

func NewGenericValidator

func NewGenericValidator(sr StateReader, accountState AccountState) *GenericValidator

NewGenericValidator constructs a new genericValidator

func (*GenericValidator) Validate

func (v *GenericValidator) Validate(ctx context.Context, selp *action.SealedEnvelope) error

Validate validates a generic action

type GenesisStateCreator added in v0.11.0

type GenesisStateCreator interface {
	CreateGenesisStates(context.Context, StateManager) error
}

GenesisStateCreator creates some genesis states

type Parameters added in v1.9.0

type Parameters struct {
	MethodName []byte
	Arguments  [][]byte
}

Parameters state request parameters

type PostSystemActionsCreator added in v0.11.0

type PostSystemActionsCreator interface {
	CreatePostSystemActions(context.Context, StateReader) ([]action.Envelope, error)
}

PostSystemActionsCreator creates a list of system actions to be appended to block actions

type PreCommitter added in v1.8.4

type PreCommitter interface {
	PreCommit(context.Context, StateManager) error
}

PreCommitter performs pre-commit action of the protocol

type PreStatesCreator added in v0.11.0

type PreStatesCreator interface {
	CreatePreStates(context.Context, StateManager) error
}

PreStatesCreator creates preliminary states for state manager

type Protocol

type Protocol interface {
	ActionHandler
	ReadState(context.Context, StateReader, []byte, ...[]byte) ([]byte, uint64, error)
	Register(*Registry) error
	ForceRegister(*Registry) error
	Name() string
}

Protocol defines the protocol interfaces atop IoTeX blockchain

type Registry added in v0.5.0

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

Registry is the hub of all protocols deployed on the chain

func GetRegistry added in v1.0.0

func GetRegistry(ctx context.Context) (*Registry, bool)

GetRegistry returns the registry from context

func MustGetRegistry added in v1.0.0

func MustGetRegistry(ctx context.Context) *Registry

MustGetRegistry returns the registry from context

func NewRegistry added in v0.11.0

func NewRegistry() *Registry

NewRegistry create a new Registry

func (*Registry) All added in v0.5.0

func (r *Registry) All() []Protocol

All returns all protocols

func (*Registry) Find added in v0.5.0

func (r *Registry) Find(id string) (Protocol, bool)

Find finds a protocol by ID

func (*Registry) ForceRegister added in v0.5.0

func (r *Registry) ForceRegister(id string, p Protocol) error

ForceRegister registers the protocol with a unique ID and force replacing the previous protocol if it exists

func (*Registry) Register added in v0.5.0

func (r *Registry) Register(id string, p Protocol) error

Register registers the protocol with a unique ID

func (*Registry) StartAll added in v1.0.0

func (r *Registry) StartAll(ctx context.Context, sr StateReader) (View, error)

StartAll starts all protocols which are startable

type SerializableBytes added in v1.7.0

type SerializableBytes []byte

SerializableBytes defines a type of serializable bytes

func (*SerializableBytes) Deserialize added in v1.7.0

func (sb *SerializableBytes) Deserialize(data []byte) error

Deserialize copies data into bytes

func (SerializableBytes) Serialize added in v1.7.0

func (sb SerializableBytes) Serialize() ([]byte, error)

Serialize copies and return bytes

type Starter added in v1.0.0

type Starter interface {
	Start(context.Context, StateReader) (interface{}, error)
}

Starter starts the protocol

type StateConfig added in v0.11.0

type StateConfig struct {
	Namespace string // namespace used by state's storage
	Key       []byte
	Keys      [][]byte
}

StateConfig is the config for accessing stateDB

func CreateStateConfig added in v0.11.0

func CreateStateConfig(opts ...StateOption) (*StateConfig, error)

CreateStateConfig creates a config for accessing stateDB

type StateContext added in v1.9.0

type StateContext interface {
	Parameters() *Parameters
	EncodeToEth(*iotexapi.ReadStateResponse) (string, error)
}

StateContext context for ReadState

type StateManager

type StateManager interface {
	StateReader
	// Accounts
	Snapshot() int
	Revert(int) error
	// General state
	PutState(interface{}, ...StateOption) (uint64, error)
	DelState(...StateOption) (uint64, error)
	WriteView(string, interface{}) error
	Dock
}

StateManager defines the stateDB interface atop IoTeX blockchain

type StateOption added in v0.11.0

type StateOption func(*StateConfig) error

StateOption sets parameter for access state

func KeyOption added in v0.11.0

func KeyOption(key []byte) StateOption

KeyOption sets the key for call

func KeysOption added in v1.8.0

func KeysOption(f func() ([][]byte, error)) StateOption

KeysOption sets the key for call

func LegacyKeyOption added in v0.11.0

func LegacyKeyOption(key hash.Hash160) StateOption

LegacyKeyOption sets the key for call with legacy key

func NamespaceOption added in v0.11.0

func NamespaceOption(ns string) StateOption

NamespaceOption creates an option for given namesapce

type StateReader added in v0.11.0

type StateReader interface {
	Height() (uint64, error)
	State(interface{}, ...StateOption) (uint64, error)
	States(...StateOption) (uint64, state.Iterator, error)
	ReadView(string) (interface{}, error)
}

StateReader defines an interface to read stateDB

type TipInfo added in v0.11.0

type TipInfo struct {
	Height    uint64
	Hash      hash.Hash256
	Timestamp time.Time
}

TipInfo contains the tip block information

type View added in v1.1.0

type View map[string]interface{}

View stores the view for all protocols

func (View) Read added in v1.1.0

func (view View) Read(name string) (interface{}, error)

func (View) Write added in v1.1.0

func (view View) Write(name string, v interface{}) error

Directories

Path Synopsis
evm
Package staking is a generated GoMock package.
Package staking is a generated GoMock package.

Jump to

Keyboard shortcuts

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