staking

package
v2.3.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Overview

Package staking is a generated GoMock package.

Package staking is a generated GoMock package.

Index

Constants

View Source
const (
	// StakingCandidatesNamespace is a namespace to store candidates with epoch start height
	StakingCandidatesNamespace = "stakingCandidates"
	// StakingBucketsNamespace is a namespace to store vote buckets with epoch start height
	StakingBucketsNamespace = "stakingBuckets"
	// StakingMetaNamespace is a namespace to store metadata
	StakingMetaNamespace = "stakingMeta"
)
View Source
const (
	// EndorseExpired means the endorsement is expired
	EndorseExpired = EndorsementStatus(iota)
	// UnEndorsing means the endorser has submitted unendorsement, but it is not expired yet
	UnEndorsing
	// Endorsed means the endorsement is valid
	Endorsed
)

EndorsementStatus

View Source
const (
	HandleCreateStake       = "createStake"
	HandleUnstake           = "unstake"
	HandleWithdrawStake     = "withdrawStake"
	HandleChangeCandidate   = "changeCandidate"
	HandleTransferStake     = "transferStake"
	HandleDepositToStake    = "depositToStake"
	HandleRestake           = "restake"
	HandleCandidateRegister = "candidateRegister"
	HandleCandidateUpdate   = "candidateUpdate"
)

constants

View Source
const (

	// CandsMapNS is the bucket name to store candidate map
	CandsMapNS = state.CandsMapNamespace

	// MaxDurationNumber is the maximum duration number
	MaxDurationNumber = math.MaxUint64
)

Variables

View Source
var (
	// StakingContractJSONABI is the abi json of staking contract
	//go:embed contract_staking_abi_v2.json
	StakingContractJSONABI string
	// StakingContractABI is the abi of staking contract
	StakingContractABI abi.ABI
)
View Source
var (
	ErrWithdrawnBucket     = errors.New("the bucket is already withdrawn")
	ErrEndorsementNotExist = errors.New("the endorsement does not exist")
	ErrNoSelfStakeBucket   = errors.New("no self-stake bucket")
	ErrCandidateNotExist   = errors.New("the candidate does not exist")
	TotalBucketKey         = append([]byte{_const}, []byte("totalBucket")...)
)

Errors

View Source
var (
	ErrInvalidOwner        = errors.New("invalid owner address")
	ErrInvalidOperator     = errors.New("invalid operator address")
	ErrInvalidReward       = errors.New("invalid reward address")
	ErrInvalidSelfStkIndex = errors.New("invalid self-staking bucket index")
	ErrMissingField        = errors.New("missing data field")
	ErrTypeAssertion       = errors.New("failed type assertion")
	ErrDurationTooHigh     = errors.New("stake duration cannot exceed 1050 days")
)

Errors

View Source
var (
	ErrNilParameters = errors.New("parameter is nil")
)

Errors and vars

Functions

func AddrKeyWithPrefix

func AddrKeyWithPrefix(addr address.Address, prefix byte) []byte

AddrKeyWithPrefix returns address key with prefix

func BucketIndexFromReceiptLog

func BucketIndexFromReceiptLog(log *iotextypes.Log) (uint64, bool)

BucketIndexFromReceiptLog extracts bucket index from log

func CalculateVoteWeight

func CalculateVoteWeight(c genesis.VoteWeightCalConsts, v *VoteBucket, selfStake bool) *big.Int

CalculateVoteWeight calculates the vote weight

func CreateBaseView

func CreateBaseView(ctx protocol.FeatureCtx, sr protocol.StateReader, enableSMStorage bool) (*viewData, uint64, error)

CreateBaseView creates the base view from state reader

func NewContractStakeViewBuilder added in v2.3.0

func NewContractStakeViewBuilder(
	indexer ContractStakingIndexer,
	blockdao BlockStore,
) *contractStakeViewBuilder

func ProtocolAddr

func ProtocolAddr() address.Address

ProtocolAddr returns the address generated from protocol id

Types

type BlockStore added in v2.3.0

type BlockStore interface {
	GetReceipts(uint64) ([]*action.Receipt, error)
	HeaderByHeight(height uint64) (*block.Header, error)
}

type BucketIndices

type BucketIndices []uint64

BucketIndices defines the array of bucket index for a

func (*BucketIndices) Decode added in v2.3.0

Decode decodes bucket indices from generic value

func (*BucketIndices) Deserialize

func (bis *BucketIndices) Deserialize(data []byte) error

Deserialize deserializes bytes into bucket indices

func (*BucketIndices) Encode added in v2.3.0

Encode encodes bucket indices into generic value

func (*BucketIndices) LoadProto

func (bis *BucketIndices) LoadProto(bucketIndicesPb *stakingpb.BucketIndices) error

LoadProto converts protobuf to bucket indices

func (*BucketIndices) Proto

func (bis *BucketIndices) Proto() *stakingpb.BucketIndices

Proto converts bucket indices to protobuf

func (*BucketIndices) Serialize

func (bis *BucketIndices) Serialize() ([]byte, error)

Serialize serializes bucket indices into bytes

type BucketPool

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

BucketPool implements the bucket pool

func (*BucketPool) Clone added in v2.2.0

func (bp *BucketPool) Clone() *BucketPool

Clone returns a copy of the bucket pool

func (*BucketPool) Commit

func (bp *BucketPool) Commit() error

Commit is called upon workingset commit

func (*BucketPool) Count

func (bp *BucketPool) Count() uint64

Count returns the total number of buckets in bucket pool

func (*BucketPool) CreditPool

func (bp *BucketPool) CreditPool(sm protocol.StateManager, amount *big.Int, deleteBucket bool) error

CreditPool subtracts staked amount out of the pool

func (*BucketPool) DebitPool

func (bp *BucketPool) DebitPool(sm protocol.StateManager, amount *big.Int, newBucket bool) error

DebitPool adds staked amount into the pool

func (*BucketPool) EnableSMStorage added in v2.2.0

func (bp *BucketPool) EnableSMStorage()

EnableSMStorage enables state manager storage

func (*BucketPool) IsDirty added in v2.2.0

func (bp *BucketPool) IsDirty() bool

IsDirty returns true if the bucket pool is dirty

func (*BucketPool) Total

func (bp *BucketPool) Total() *big.Int

Total returns the total amount staked in bucket pool

type BucketReader added in v2.3.0

type BucketReader interface {
	DeductBucket(address.Address, uint64) (*contractstaking.Bucket, error)
}

BucketReader defines the interface to read bucket info

type BucketSet

type BucketSet interface {
	// contains filtered or unexported methods
}

BucketSet related to setting bucket

type BuilderConfig

type BuilderConfig struct {
	Staking                       genesis.Staking
	PersistStakingPatchBlock      uint64
	FixAliasForNonStopHeight      uint64
	SkipContractStakingViewHeight uint64
	StakingPatchDir               string
	Revise                        ReviseConfig
}

BuilderConfig returns the configuration of the builder

type CalculateVoteWeightFunc added in v2.3.0

type CalculateVoteWeightFunc func(bkt *contractstaking.Bucket, height uint64) *big.Int

CalculateVoteWeightFunc is a function that calculates the vote weight of a bucket.

type Candidate

type Candidate struct {
	Owner              address.Address
	Operator           address.Address
	Reward             address.Address
	Identifier         address.Address
	BLSPubKey          []byte // BLS public key
	Name               string
	Votes              *big.Int
	SelfStakeBucketIdx uint64
	SelfStake          *big.Int
}

Candidate represents the candidate

func (*Candidate) AddSelfStake

func (d *Candidate) AddSelfStake(amount *big.Int) error

AddSelfStake adds self stake

func (*Candidate) AddVote

func (d *Candidate) AddVote(amount *big.Int) error

AddVote adds vote

func (*Candidate) Clone

func (d *Candidate) Clone() *Candidate

Clone returns a copy

func (*Candidate) Collision

func (d *Candidate) Collision(c *Candidate) error

Collision checks collsion of 2 candidates

func (*Candidate) Decode added in v2.3.0

Decode decodes candidate from generic value

func (*Candidate) Deserialize

func (d *Candidate) Deserialize(buf []byte) error

Deserialize deserializes bytes to candidate

func (*Candidate) Encode added in v2.3.0

Encode encodes candidate into generic value

func (*Candidate) Equal

func (d *Candidate) Equal(c *Candidate) bool

Equal tests equality of 2 candidates

func (*Candidate) GetIdentifier

func (d *Candidate) GetIdentifier() address.Address

TODO: rename to ID GetIdentifier returns the identifier

func (*Candidate) Serialize

func (d *Candidate) Serialize() ([]byte, error)

Serialize serializes candidate to bytes

func (*Candidate) SubSelfStake

func (d *Candidate) SubSelfStake(amount *big.Int) error

SubSelfStake subtracts self stake

func (*Candidate) SubVote

func (d *Candidate) SubVote(amount *big.Int) error

SubVote subtracts vote

func (*Candidate) Validate

func (d *Candidate) Validate() error

Validate does the sanity check

type CandidateCenter

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

CandidateCenter is a struct to manage the candidates

func NewCandidateCenter

func NewCandidateCenter(all CandidateList) (*CandidateCenter, error)

NewCandidateCenter creates an instance of CandidateCenter

func (*CandidateCenter) All

func (m *CandidateCenter) All() CandidateList

All returns all candidates in candidate center

func (CandidateCenter) Base

func (m CandidateCenter) Base() *CandidateCenter

Base returns the confirmed base state

func (*CandidateCenter) Clone added in v2.2.0

func (m *CandidateCenter) Clone() *CandidateCenter

func (*CandidateCenter) Commit

Commit writes the change into base

func (*CandidateCenter) ContainsName

func (m *CandidateCenter) ContainsName(name string) bool

ContainsName returns true if the map contains the candidate by name

func (*CandidateCenter) ContainsOperator

func (m *CandidateCenter) ContainsOperator(operator address.Address) bool

ContainsOperator returns true if the map contains the candidate by operator

func (*CandidateCenter) ContainsOwner

func (m *CandidateCenter) ContainsOwner(owner address.Address) bool

ContainsOwner returns true if the map contains the candidate by owner

func (*CandidateCenter) ContainsSelfStakingBucket

func (m *CandidateCenter) ContainsSelfStakingBucket(index uint64) bool

ContainsSelfStakingBucket returns true if the map contains the self staking bucket index

func (*CandidateCenter) GetByIdentifier

func (m *CandidateCenter) GetByIdentifier(identifier address.Address) *Candidate

GetByIdentifier returns the candidate by identifier

func (*CandidateCenter) GetByName

func (m *CandidateCenter) GetByName(name string) *Candidate

GetByName returns the candidate by name

func (*CandidateCenter) GetByOperator added in v2.3.0

func (m *CandidateCenter) GetByOperator(operator address.Address) *Candidate

GetByOperator returns the candidate by operator

func (*CandidateCenter) GetByOwner

func (m *CandidateCenter) GetByOwner(owner address.Address) *Candidate

GetByOwner returns the candidate by owner

func (*CandidateCenter) GetBySelfStakingIndex

func (m *CandidateCenter) GetBySelfStakingIndex(index uint64) *Candidate

GetBySelfStakingIndex returns the candidate by self-staking index

func (*CandidateCenter) IsDirty added in v2.2.0

func (m *CandidateCenter) IsDirty() bool

IsDirty returns true if the candidate center is dirty

func (*CandidateCenter) Size

func (m *CandidateCenter) Size() int

Size returns number of candidates

func (*CandidateCenter) Upsert

func (m *CandidateCenter) Upsert(d *Candidate) error

Upsert adds a candidate into map, overwrites if already exist

func (*CandidateCenter) WriteToStateDB added in v2.3.0

func (m *CandidateCenter) WriteToStateDB(sm protocol.StateManager) error

WriteToStateDB writes the candidate center to stateDB

type CandidateList

type CandidateList []*Candidate

CandidateList is a list of candidates which is sortable

func (*CandidateList) Decode added in v2.3.0

Decode decodes candidate list from generic value

func (*CandidateList) Deserialize

func (l *CandidateList) Deserialize(buf []byte) error

Deserialize deserializes bytes to list of candidates

func (*CandidateList) Encode added in v2.3.0

Encode encodes candidate list into generic value

func (CandidateList) Len

func (l CandidateList) Len() int

func (CandidateList) Less

func (l CandidateList) Less(i, j int) bool

func (CandidateList) Serialize

func (l CandidateList) Serialize() ([]byte, error)

Serialize serializes candidate to bytes

func (CandidateList) Swap

func (l CandidateList) Swap(i, j int)

type CandidateSet

type CandidateSet interface {
	// contains filtered or unexported methods
}

CandidateSet related to setting candidates

type CandidateStateManager

type CandidateStateManager interface {
	BucketSet
	NativeBucketGetByIndex
	CandidateSet
	// candidate and bucket pool related
	DirtyView() *viewData
	ContainsName(string) bool
	ContainsOwner(address.Address) bool
	ContainsOperator(address.Address) bool
	ContainsSelfStakingBucket(uint64) bool
	GetByName(string) *Candidate
	GetByOwner(address.Address) *Candidate
	GetByIdentifier(address.Address) *Candidate
	GetByOperator(address.Address) *Candidate
	Upsert(*Candidate) error
	CreditBucketPool(*big.Int, bool) error
	DebitBucketPool(*big.Int, bool) error
	Commit(context.Context) error
	SM() protocol.StateManager
	SR() protocol.StateReader
}

CandidateStateManager is candidate state manager on top of StateManager

func NewCandidateStateManager

func NewCandidateStateManager(sm protocol.StateManager) (CandidateStateManager, error)

NewCandidateStateManager returns a new CandidateStateManager instance

type CandidateStateReader

type CandidateStateReader interface {
	NativeBucketGetByIndex
	NumOfNativeBucket() (uint64, error)
	NativeBuckets() ([]*VoteBucket, uint64, error)
	NativeBucketsWithIndices(indices BucketIndices) ([]*VoteBucket, error)
	NativeBucketIndices(addr address.Address, prefix byte) (*BucketIndices, uint64, error)
	NativeBucketIndicesByVoter(addr address.Address) (*BucketIndices, uint64, error)
	NativeBucketIndicesByCandidate(addr address.Address) (*BucketIndices, uint64, error)
	CandidateByAddress(name address.Address) (*Candidate, uint64, error)
	CreateCandidateCenter(ctx protocol.FeatureCtx) (*CandidateCenter, uint64, error)
	ReadState
	Height() uint64
	SR() protocol.StateReader
	BaseView() *viewData
	NewBucketPool(enableSMStorage bool) (*BucketPool, error)
	GetCandidateByName(string) *Candidate
	GetCandidateByOwner(address.Address) *Candidate
	AllCandidates() CandidateList
	TotalStakedAmount() *big.Int
	ActiveBucketsCount() uint64
	ContainsSelfStakingBucket(index uint64) bool
	GetByIdentifier(address.Address) *Candidate
}

CandidateStateReader contains candidate center and bucket pool

func ConstructBaseView

func ConstructBaseView(sr protocol.StateReader) (CandidateStateReader, error)

ConstructBaseView returns a candidate state reader that reflects the base view it will be used read-only

type CandidatesBucketsIndexer

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

CandidatesBucketsIndexer is an indexer to store candidates by given height

func NewStakingCandidatesBucketsIndexer

func NewStakingCandidatesBucketsIndexer(kv db.KVStoreForRangeIndex) (*CandidatesBucketsIndexer, error)

NewStakingCandidatesBucketsIndexer creates a new StakingCandidatesIndexer

func (*CandidatesBucketsIndexer) GetBuckets

func (cbi *CandidatesBucketsIndexer) GetBuckets(height uint64, offset, limit uint32) (*iotextypes.VoteBucketList, uint64, error)

GetBuckets gets vote buckets from indexer given epoch start height

func (*CandidatesBucketsIndexer) GetCandidates

func (cbi *CandidatesBucketsIndexer) GetCandidates(height uint64, offset, limit uint32) (*iotextypes.CandidateListV2, uint64, error)

GetCandidates gets candidates from indexer given epoch start height

func (*CandidatesBucketsIndexer) PutBuckets

func (cbi *CandidatesBucketsIndexer) PutBuckets(height uint64, buckets *iotextypes.VoteBucketList) error

PutBuckets puts vote buckets into indexer

func (*CandidatesBucketsIndexer) PutCandidates

func (cbi *CandidatesBucketsIndexer) PutCandidates(height uint64, candidates *iotextypes.CandidateListV2) error

PutCandidates puts candidates into indexer

func (*CandidatesBucketsIndexer) Start

Start starts the indexer

func (*CandidatesBucketsIndexer) Stop

Stop stops the indexer

type CandidiateStateCommon

type CandidiateStateCommon interface {
	ContainsSelfStakingBucket(uint64) bool
	GetByIdentifier(address.Address) *Candidate
	SR() protocol.StateReader
	NativeBucketGetByIndex
}

CandidiateStateCommon is the common interface for candidate state manager and reader

type Configuration

type Configuration struct {
	VoteWeightCalConsts               genesis.VoteWeightCalConsts
	RegistrationConsts                RegistrationConsts
	WithdrawWaitingPeriod             time.Duration
	MinStakeAmount                    *big.Int
	BootstrapCandidates               []genesis.BootstrapCandidate
	PersistStakingPatchBlock          uint64
	FixAliasForNonStopHeight          uint64
	SkipContractStakingViewHeight     uint64
	EndorsementWithdrawWaitingBlocks  uint64
	MigrateContractAddress            string
	TimestampedMigrateContractAddress string
	MinSelfStakeToBeActive            *big.Int
}

Configuration is the staking protocol configuration.

type ContractStakeView added in v2.2.0

type ContractStakeView interface {
	// Wrap wraps the contract stake view
	Wrap() ContractStakeView
	// Fork forks the contract stake view, commit will not affect the original view
	Fork() ContractStakeView
	// IsDirty checks if the contract stake view is dirty
	IsDirty() bool
	// Commit commits the contract stake view
	Commit(context.Context, protocol.StateManager) error
	// CreatePreStates creates pre states for the contract stake view
	CreatePreStates(ctx context.Context) error
	// Handle handles the receipt for the contract stake view
	Handle(ctx context.Context, receipt *action.Receipt) error
	// Migrate writes the bucket types and buckets to the state manager
	Migrate(context.Context, EventHandler) error
	// Revise updates the contract stake view with the latest bucket data
	Revise(context.Context)
	// BucketsByCandidate returns the buckets by candidate address
	CandidateStakeVotes(ctx context.Context, id address.Address) *big.Int
	AddBlockReceipts(ctx context.Context, receipts []*action.Receipt) error
}

ContractStakeView is the interface for contract stake view

type ContractStakeViewBuilder added in v2.3.0

type ContractStakeViewBuilder interface {
	Build(ctx context.Context, target uint64) (ContractStakeView, error)
}

type ContractStakingBucketType

type ContractStakingBucketType = contractstaking.BucketType

ContractStakingBucketType defines the type of contract staking bucket

type ContractStakingIndexer

type ContractStakingIndexer interface {
	lifecycle.StartStopper
	// PutBlock puts a block into the indexer
	PutBlock(context.Context, *block.Block) error
	// StartHeight returns the start height of the indexer
	StartHeight() uint64
	// Height returns the latest indexed height
	Height() (uint64, error)
	// Buckets returns active buckets
	Buckets(height uint64) ([]*VoteBucket, error)
	// BucketsByIndices returns active buckets by indices
	BucketsByIndices([]uint64, uint64) ([]*VoteBucket, error)
	// BucketsByCandidate returns active buckets by candidate
	BucketsByCandidate(ownerAddr address.Address, height uint64) ([]*VoteBucket, error)
	// TotalBucketCount returns the total number of buckets including burned buckets
	TotalBucketCount(height uint64) (uint64, error)
	// ContractAddress returns the contract address
	ContractAddress() address.Address
	// LoadStakeView loads the contract stake view from state reader
	LoadStakeView(context.Context, protocol.StateReader) (ContractStakeView, error)
	// CreateEventProcessor creates a new event processor
	CreateEventProcessor(context.Context, EventHandler) EventProcessor
	// ContractStakingBuckets returns all the contract staking buckets
	ContractStakingBuckets() (uint64, map[uint64]*contractstaking.Bucket, error)

	BucketReader
}

ContractStakingIndexer defines the interface of contract staking reader

func NewDelayTolerantIndexer added in v2.0.6

func NewDelayTolerantIndexer(indexer ContractStakingIndexer, duration time.Duration) ContractStakingIndexer

NewDelayTolerantIndexer creates a delay tolerant indexer

type ContractStakingIndexerWithBucketType

type ContractStakingIndexerWithBucketType interface {
	ContractStakingIndexer
	// BucketTypes returns the active bucket types
	BucketTypes(height uint64) ([]*ContractStakingBucketType, error)
}

ContractStakingIndexerWithBucketType defines the interface of contract staking reader with bucket type

func NewDelayTolerantIndexerWithBucketType added in v2.0.6

func NewDelayTolerantIndexerWithBucketType(indexer ContractStakingIndexerWithBucketType, duration time.Duration) ContractStakingIndexerWithBucketType

NewDelayTolerantIndexerWithBucketType creates a delay tolerant indexer with bucket type

type Endorsement

type Endorsement struct {
	// ExpireHeight is the height an endorsement is expired in legacy mode and it is the earliest height that can revoke the endorsement in new mode
	ExpireHeight uint64
}

Endorsement is a struct that contains the expire height of the Endorsement

func (*Endorsement) Decode added in v2.3.0

Decode decodes endorsement from generic value

func (*Endorsement) Deserialize

func (e *Endorsement) Deserialize(buf []byte) error

Deserialize deserializes bytes to endorsement

func (*Endorsement) Encode added in v2.3.0

Encode encodes endorsement into generic value

func (*Endorsement) LegacyStatus

func (e *Endorsement) LegacyStatus(height uint64) EndorsementStatus

func (*Endorsement) Serialize

func (e *Endorsement) Serialize() ([]byte, error)

Serialize serializes endorsement to bytes

func (*Endorsement) Status

func (e *Endorsement) Status(height uint64) EndorsementStatus

Status returns the status of the endorsement

type EndorsementStateManager

type EndorsementStateManager struct {
	protocol.StateManager
	*EndorsementStateReader
}

EndorsementStateManager defines the interface of endorsement state manager

func NewEndorsementStateManager

func NewEndorsementStateManager(sm protocol.StateManager) *EndorsementStateManager

NewEndorsementStateManager creates a new endorsement state manager

func (*EndorsementStateManager) Delete

func (esm *EndorsementStateManager) Delete(bucketIndex uint64) error

Delete deletes the endorsement of a bucket

func (*EndorsementStateManager) Put

func (esm *EndorsementStateManager) Put(bucketIndex uint64, endorse *Endorsement) error

Put puts the endorsement of a bucket

type EndorsementStateReader

type EndorsementStateReader struct {
	protocol.StateReader
}

EndorsementStateReader defines the interface of endorsement state reader

func NewEndorsementStateReader

func NewEndorsementStateReader(sr protocol.StateReader) *EndorsementStateReader

NewEndorsementStateReader creates a new endorsement state reader

func (*EndorsementStateReader) Get

func (esr *EndorsementStateReader) Get(bucketIndex uint64) (*Endorsement, error)

Get gets the endorsement of a bucket

func (*EndorsementStateReader) Status

func (esr *EndorsementStateReader) Status(ctx protocol.FeatureCtx, bucketIndex, height uint64) (EndorsementStatus, error)

Status returns the status of the endorsement of a bucket at a certain height If the endorsement does not exist, it returns EndorseExpired

type EndorsementStatus

type EndorsementStatus uint8

EndorsementStatus is a uint8 that represents the status of the endorsement

func (EndorsementStatus) String

func (s EndorsementStatus) String() string

String returns a human-readable string of the endorsement status

type EventHandler added in v2.3.0

type EventHandler interface {
	PutBucketType(address.Address, *ContractStakingBucketType) error
	DeductBucket(address.Address, uint64) (*contractstaking.Bucket, error)
	PutBucket(address.Address, uint64, *contractstaking.Bucket) error
	DeleteBucket(address.Address, uint64) error
}

EventHandler is the interface for handling staking events

type EventProcessor added in v2.3.0

type EventProcessor interface {
	// ProcessReceipts processes receipts
	ProcessReceipts(context.Context, ...*action.Receipt) error
}

EventProcessor is the interface for processing staking events

type HelperCtx

type HelperCtx struct {
	BlockInterval func(uint64) time.Duration
	DepositGas    protocol.DepositGas
}

HelperCtx is the helper context for staking protocol

type MockBucketReader added in v2.3.0

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

MockBucketReader is a mock of BucketReader interface.

func NewMockBucketReader added in v2.3.0

func NewMockBucketReader(ctrl *gomock.Controller) *MockBucketReader

NewMockBucketReader creates a new mock instance.

func (*MockBucketReader) DeductBucket added in v2.3.0

func (m *MockBucketReader) DeductBucket(arg0 address.Address, arg1 uint64) (*contractstaking.Bucket, error)

DeductBucket mocks base method.

func (*MockBucketReader) EXPECT added in v2.3.0

EXPECT returns an object that allows the caller to indicate expected use.

type MockBucketReaderMockRecorder added in v2.3.0

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

MockBucketReaderMockRecorder is the mock recorder for MockBucketReader.

func (*MockBucketReaderMockRecorder) DeductBucket added in v2.3.0

func (mr *MockBucketReaderMockRecorder) DeductBucket(arg0, arg1 any) *gomock.Call

DeductBucket indicates an expected call of DeductBucket.

type MockContractStakeView added in v2.3.0

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

MockContractStakeView is a mock of ContractStakeView interface.

func NewMockContractStakeView added in v2.3.0

func NewMockContractStakeView(ctrl *gomock.Controller) *MockContractStakeView

NewMockContractStakeView creates a new mock instance.

func (*MockContractStakeView) AddBlockReceipts added in v2.3.0

func (m *MockContractStakeView) AddBlockReceipts(ctx context.Context, receipts []*action.Receipt) error

AddBlockReceipts mocks base method.

func (*MockContractStakeView) CandidateStakeVotes added in v2.3.0

func (m *MockContractStakeView) CandidateStakeVotes(ctx context.Context, id address.Address) *big.Int

CandidateStakeVotes mocks base method.

func (*MockContractStakeView) Commit added in v2.3.0

Commit mocks base method.

func (*MockContractStakeView) CreatePreStates added in v2.3.0

func (m *MockContractStakeView) CreatePreStates(ctx context.Context) error

CreatePreStates mocks base method.

func (*MockContractStakeView) EXPECT added in v2.3.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockContractStakeView) Fork added in v2.3.0

Fork mocks base method.

func (*MockContractStakeView) Handle added in v2.3.0

func (m *MockContractStakeView) Handle(ctx context.Context, receipt *action.Receipt) error

Handle mocks base method.

func (*MockContractStakeView) IsDirty added in v2.3.0

func (m *MockContractStakeView) IsDirty() bool

IsDirty mocks base method.

func (*MockContractStakeView) Migrate added in v2.3.0

func (m *MockContractStakeView) Migrate(arg0 context.Context, arg1 EventHandler) error

Migrate mocks base method.

func (*MockContractStakeView) Revise added in v2.3.0

func (m *MockContractStakeView) Revise(arg0 context.Context)

Revise mocks base method.

func (*MockContractStakeView) Wrap added in v2.3.0

Wrap mocks base method.

type MockContractStakeViewMockRecorder added in v2.3.0

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

MockContractStakeViewMockRecorder is the mock recorder for MockContractStakeView.

func (*MockContractStakeViewMockRecorder) AddBlockReceipts added in v2.3.0

func (mr *MockContractStakeViewMockRecorder) AddBlockReceipts(ctx, receipts any) *gomock.Call

AddBlockReceipts indicates an expected call of AddBlockReceipts.

func (*MockContractStakeViewMockRecorder) CandidateStakeVotes added in v2.3.0

func (mr *MockContractStakeViewMockRecorder) CandidateStakeVotes(ctx, id any) *gomock.Call

CandidateStakeVotes indicates an expected call of CandidateStakeVotes.

func (*MockContractStakeViewMockRecorder) Commit added in v2.3.0

func (mr *MockContractStakeViewMockRecorder) Commit(arg0, arg1 any) *gomock.Call

Commit indicates an expected call of Commit.

func (*MockContractStakeViewMockRecorder) CreatePreStates added in v2.3.0

func (mr *MockContractStakeViewMockRecorder) CreatePreStates(ctx any) *gomock.Call

CreatePreStates indicates an expected call of CreatePreStates.

func (*MockContractStakeViewMockRecorder) Fork added in v2.3.0

Fork indicates an expected call of Fork.

func (*MockContractStakeViewMockRecorder) Handle added in v2.3.0

func (mr *MockContractStakeViewMockRecorder) Handle(ctx, receipt any) *gomock.Call

Handle indicates an expected call of Handle.

func (*MockContractStakeViewMockRecorder) IsDirty added in v2.3.0

IsDirty indicates an expected call of IsDirty.

func (*MockContractStakeViewMockRecorder) Migrate added in v2.3.0

func (mr *MockContractStakeViewMockRecorder) Migrate(arg0, arg1 any) *gomock.Call

Migrate indicates an expected call of Migrate.

func (*MockContractStakeViewMockRecorder) Revise added in v2.3.0

Revise indicates an expected call of Revise.

func (*MockContractStakeViewMockRecorder) Wrap added in v2.3.0

Wrap indicates an expected call of Wrap.

type MockContractStakingIndexer

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

MockContractStakingIndexer is a mock of ContractStakingIndexer interface.

func NewMockContractStakingIndexer

func NewMockContractStakingIndexer(ctrl *gomock.Controller) *MockContractStakingIndexer

NewMockContractStakingIndexer creates a new mock instance.

func (*MockContractStakingIndexer) Buckets

func (m *MockContractStakingIndexer) Buckets(height uint64) ([]*VoteBucket, error)

Buckets mocks base method.

func (*MockContractStakingIndexer) BucketsByCandidate

func (m *MockContractStakingIndexer) BucketsByCandidate(ownerAddr address.Address, height uint64) ([]*VoteBucket, error)

BucketsByCandidate mocks base method.

func (*MockContractStakingIndexer) BucketsByIndices

func (m *MockContractStakingIndexer) BucketsByIndices(arg0 []uint64, arg1 uint64) ([]*VoteBucket, error)

BucketsByIndices mocks base method.

func (*MockContractStakingIndexer) ContractAddress

func (m *MockContractStakingIndexer) ContractAddress() address.Address

ContractAddress mocks base method.

func (*MockContractStakingIndexer) ContractStakingBuckets added in v2.3.0

func (m *MockContractStakingIndexer) ContractStakingBuckets() (uint64, map[uint64]*contractstaking.Bucket, error)

ContractStakingBuckets mocks base method.

func (*MockContractStakingIndexer) CreateEventProcessor added in v2.3.0

func (m *MockContractStakingIndexer) CreateEventProcessor(arg0 context.Context, arg1 EventHandler) EventProcessor

CreateEventProcessor mocks base method.

func (*MockContractStakingIndexer) DeductBucket added in v2.3.0

DeductBucket mocks base method.

func (*MockContractStakingIndexer) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockContractStakingIndexer) Height added in v2.0.6

func (m *MockContractStakingIndexer) Height() (uint64, error)

Height mocks base method.

func (*MockContractStakingIndexer) LoadStakeView added in v2.3.0

LoadStakeView mocks base method.

func (*MockContractStakingIndexer) PutBlock added in v2.3.0

func (m *MockContractStakingIndexer) PutBlock(arg0 context.Context, arg1 *block.Block) error

PutBlock mocks base method.

func (*MockContractStakingIndexer) Start added in v2.3.0

Start mocks base method.

func (*MockContractStakingIndexer) StartHeight added in v2.3.0

func (m *MockContractStakingIndexer) StartHeight() uint64

StartHeight mocks base method.

func (*MockContractStakingIndexer) Stop added in v2.3.0

Stop mocks base method.

func (*MockContractStakingIndexer) TotalBucketCount

func (m *MockContractStakingIndexer) TotalBucketCount(height uint64) (uint64, error)

TotalBucketCount mocks base method.

type MockContractStakingIndexerMockRecorder

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

MockContractStakingIndexerMockRecorder is the mock recorder for MockContractStakingIndexer.

func (*MockContractStakingIndexerMockRecorder) Buckets

Buckets indicates an expected call of Buckets.

func (*MockContractStakingIndexerMockRecorder) BucketsByCandidate

func (mr *MockContractStakingIndexerMockRecorder) BucketsByCandidate(ownerAddr, height any) *gomock.Call

BucketsByCandidate indicates an expected call of BucketsByCandidate.

func (*MockContractStakingIndexerMockRecorder) BucketsByIndices

func (mr *MockContractStakingIndexerMockRecorder) BucketsByIndices(arg0, arg1 any) *gomock.Call

BucketsByIndices indicates an expected call of BucketsByIndices.

func (*MockContractStakingIndexerMockRecorder) ContractAddress

func (mr *MockContractStakingIndexerMockRecorder) ContractAddress() *gomock.Call

ContractAddress indicates an expected call of ContractAddress.

func (*MockContractStakingIndexerMockRecorder) ContractStakingBuckets added in v2.3.0

func (mr *MockContractStakingIndexerMockRecorder) ContractStakingBuckets() *gomock.Call

ContractStakingBuckets indicates an expected call of ContractStakingBuckets.

func (*MockContractStakingIndexerMockRecorder) CreateEventProcessor added in v2.3.0

func (mr *MockContractStakingIndexerMockRecorder) CreateEventProcessor(arg0, arg1 any) *gomock.Call

CreateEventProcessor indicates an expected call of CreateEventProcessor.

func (*MockContractStakingIndexerMockRecorder) DeductBucket added in v2.3.0

func (mr *MockContractStakingIndexerMockRecorder) DeductBucket(arg0, arg1 any) *gomock.Call

DeductBucket indicates an expected call of DeductBucket.

func (*MockContractStakingIndexerMockRecorder) Height added in v2.0.6

Height indicates an expected call of Height.

func (*MockContractStakingIndexerMockRecorder) LoadStakeView added in v2.3.0

func (mr *MockContractStakingIndexerMockRecorder) LoadStakeView(arg0, arg1 any) *gomock.Call

LoadStakeView indicates an expected call of LoadStakeView.

func (*MockContractStakingIndexerMockRecorder) PutBlock added in v2.3.0

func (mr *MockContractStakingIndexerMockRecorder) PutBlock(arg0, arg1 any) *gomock.Call

PutBlock indicates an expected call of PutBlock.

func (*MockContractStakingIndexerMockRecorder) Start added in v2.3.0

Start indicates an expected call of Start.

func (*MockContractStakingIndexerMockRecorder) StartHeight added in v2.3.0

StartHeight indicates an expected call of StartHeight.

func (*MockContractStakingIndexerMockRecorder) Stop added in v2.3.0

Stop indicates an expected call of Stop.

func (*MockContractStakingIndexerMockRecorder) TotalBucketCount

func (mr *MockContractStakingIndexerMockRecorder) TotalBucketCount(height any) *gomock.Call

TotalBucketCount indicates an expected call of TotalBucketCount.

type MockContractStakingIndexerWithBucketType

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

MockContractStakingIndexerWithBucketType is a mock of ContractStakingIndexerWithBucketType interface.

func NewMockContractStakingIndexerWithBucketType

func NewMockContractStakingIndexerWithBucketType(ctrl *gomock.Controller) *MockContractStakingIndexerWithBucketType

NewMockContractStakingIndexerWithBucketType creates a new mock instance.

func (*MockContractStakingIndexerWithBucketType) BucketTypes

BucketTypes mocks base method.

func (*MockContractStakingIndexerWithBucketType) Buckets

Buckets mocks base method.

func (*MockContractStakingIndexerWithBucketType) BucketsByCandidate

func (m *MockContractStakingIndexerWithBucketType) BucketsByCandidate(ownerAddr address.Address, height uint64) ([]*VoteBucket, error)

BucketsByCandidate mocks base method.

func (*MockContractStakingIndexerWithBucketType) BucketsByIndices

func (m *MockContractStakingIndexerWithBucketType) BucketsByIndices(arg0 []uint64, arg1 uint64) ([]*VoteBucket, error)

BucketsByIndices mocks base method.

func (*MockContractStakingIndexerWithBucketType) ContractAddress

ContractAddress mocks base method.

func (*MockContractStakingIndexerWithBucketType) ContractStakingBuckets added in v2.3.0

ContractStakingBuckets mocks base method.

func (*MockContractStakingIndexerWithBucketType) CreateEventProcessor added in v2.3.0

CreateEventProcessor mocks base method.

func (*MockContractStakingIndexerWithBucketType) DeductBucket added in v2.3.0

DeductBucket mocks base method.

func (*MockContractStakingIndexerWithBucketType) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockContractStakingIndexerWithBucketType) Height added in v2.0.6

Height mocks base method.

func (*MockContractStakingIndexerWithBucketType) LoadStakeView added in v2.3.0

LoadStakeView mocks base method.

func (*MockContractStakingIndexerWithBucketType) PutBlock added in v2.3.0

PutBlock mocks base method.

func (*MockContractStakingIndexerWithBucketType) Start added in v2.3.0

Start mocks base method.

func (*MockContractStakingIndexerWithBucketType) StartHeight added in v2.3.0

StartHeight mocks base method.

func (*MockContractStakingIndexerWithBucketType) Stop added in v2.3.0

Stop mocks base method.

func (*MockContractStakingIndexerWithBucketType) TotalBucketCount

func (m *MockContractStakingIndexerWithBucketType) TotalBucketCount(height uint64) (uint64, error)

TotalBucketCount mocks base method.

type MockContractStakingIndexerWithBucketTypeMockRecorder

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

MockContractStakingIndexerWithBucketTypeMockRecorder is the mock recorder for MockContractStakingIndexerWithBucketType.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) BucketTypes

BucketTypes indicates an expected call of BucketTypes.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) Buckets

Buckets indicates an expected call of Buckets.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) BucketsByCandidate

func (mr *MockContractStakingIndexerWithBucketTypeMockRecorder) BucketsByCandidate(ownerAddr, height any) *gomock.Call

BucketsByCandidate indicates an expected call of BucketsByCandidate.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) BucketsByIndices

func (mr *MockContractStakingIndexerWithBucketTypeMockRecorder) BucketsByIndices(arg0, arg1 any) *gomock.Call

BucketsByIndices indicates an expected call of BucketsByIndices.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) ContractAddress

ContractAddress indicates an expected call of ContractAddress.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) ContractStakingBuckets added in v2.3.0

ContractStakingBuckets indicates an expected call of ContractStakingBuckets.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) CreateEventProcessor added in v2.3.0

func (mr *MockContractStakingIndexerWithBucketTypeMockRecorder) CreateEventProcessor(arg0, arg1 any) *gomock.Call

CreateEventProcessor indicates an expected call of CreateEventProcessor.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) DeductBucket added in v2.3.0

DeductBucket indicates an expected call of DeductBucket.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) Height added in v2.0.6

Height indicates an expected call of Height.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) LoadStakeView added in v2.3.0

LoadStakeView indicates an expected call of LoadStakeView.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) PutBlock added in v2.3.0

PutBlock indicates an expected call of PutBlock.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) Start added in v2.3.0

Start indicates an expected call of Start.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) StartHeight added in v2.3.0

StartHeight indicates an expected call of StartHeight.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) Stop added in v2.3.0

Stop indicates an expected call of Stop.

func (*MockContractStakingIndexerWithBucketTypeMockRecorder) TotalBucketCount

TotalBucketCount indicates an expected call of TotalBucketCount.

type MockEventHandler added in v2.3.0

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

MockEventHandler is a mock of EventHandler interface.

func NewMockEventHandler added in v2.3.0

func NewMockEventHandler(ctrl *gomock.Controller) *MockEventHandler

NewMockEventHandler creates a new mock instance.

func (*MockEventHandler) DeductBucket added in v2.3.0

func (m *MockEventHandler) DeductBucket(arg0 address.Address, arg1 uint64) (*contractstaking.Bucket, error)

DeductBucket mocks base method.

func (*MockEventHandler) DeleteBucket added in v2.3.0

func (m *MockEventHandler) DeleteBucket(arg0 address.Address, arg1 uint64) error

DeleteBucket mocks base method.

func (*MockEventHandler) EXPECT added in v2.3.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockEventHandler) PutBucket added in v2.3.0

func (m *MockEventHandler) PutBucket(arg0 address.Address, arg1 uint64, arg2 *contractstaking.Bucket) error

PutBucket mocks base method.

func (*MockEventHandler) PutBucketType added in v2.3.0

func (m *MockEventHandler) PutBucketType(arg0 address.Address, arg1 *ContractStakingBucketType) error

PutBucketType mocks base method.

type MockEventHandlerMockRecorder added in v2.3.0

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

MockEventHandlerMockRecorder is the mock recorder for MockEventHandler.

func (*MockEventHandlerMockRecorder) DeductBucket added in v2.3.0

func (mr *MockEventHandlerMockRecorder) DeductBucket(arg0, arg1 any) *gomock.Call

DeductBucket indicates an expected call of DeductBucket.

func (*MockEventHandlerMockRecorder) DeleteBucket added in v2.3.0

func (mr *MockEventHandlerMockRecorder) DeleteBucket(arg0, arg1 any) *gomock.Call

DeleteBucket indicates an expected call of DeleteBucket.

func (*MockEventHandlerMockRecorder) PutBucket added in v2.3.0

func (mr *MockEventHandlerMockRecorder) PutBucket(arg0, arg1, arg2 any) *gomock.Call

PutBucket indicates an expected call of PutBucket.

func (*MockEventHandlerMockRecorder) PutBucketType added in v2.3.0

func (mr *MockEventHandlerMockRecorder) PutBucketType(arg0, arg1 any) *gomock.Call

PutBucketType indicates an expected call of PutBucketType.

type MockEventProcessor added in v2.3.0

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

MockEventProcessor is a mock of EventProcessor interface.

func NewMockEventProcessor added in v2.3.0

func NewMockEventProcessor(ctrl *gomock.Controller) *MockEventProcessor

NewMockEventProcessor creates a new mock instance.

func (*MockEventProcessor) EXPECT added in v2.3.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockEventProcessor) ProcessReceipts added in v2.3.0

func (m *MockEventProcessor) ProcessReceipts(arg0 context.Context, arg1 ...*action.Receipt) error

ProcessReceipts mocks base method.

type MockEventProcessorMockRecorder added in v2.3.0

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

MockEventProcessorMockRecorder is the mock recorder for MockEventProcessor.

func (*MockEventProcessorMockRecorder) ProcessReceipts added in v2.3.0

func (mr *MockEventProcessorMockRecorder) ProcessReceipts(arg0 any, arg1 ...any) *gomock.Call

ProcessReceipts indicates an expected call of ProcessReceipts.

type NativeBucketGetByIndex added in v2.3.0

type NativeBucketGetByIndex interface {
	NativeBucket(index uint64) (*VoteBucket, error)
}

NativeBucketGetByIndex related to obtaining bucket by index

type Option added in v2.2.0

type Option func(*Protocol)

Option is the option to create a protocol

func WithBlockStore added in v2.3.0

func WithBlockStore(bs BlockStore) Option

WithBlockStore sets the block store

func WithContractStakingIndexerV3 added in v2.2.0

func WithContractStakingIndexerV3(indexer ContractStakingIndexer) Option

WithContractStakingIndexerV3 sets the contract staking indexer v3

type PatchStore

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

PatchStore is the patch store of staking protocol

func NewPatchStore

func NewPatchStore(dir string) *PatchStore

NewPatchStore creates a new staking patch store

func (*PatchStore) Read

Read reads CandidateList by name and CandidateList by operator of given height

type Protocol

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

Protocol defines the protocol of handling staking

func FindProtocol

func FindProtocol(registry *protocol.Registry) *Protocol

FindProtocol return a registered protocol from registry

func NewProtocol

func NewProtocol(
	helperCtx HelperCtx,
	cfg *BuilderConfig,
	blocksToDurationFn func(startHeight, endHeight, currentHeight uint64) time.Duration,
	candBucketsIndexer *CandidatesBucketsIndexer,
	contractStakingIndexer ContractStakingIndexerWithBucketType,
	contractStakingIndexerV2 ContractStakingIndexer,
	opts ...Option,
) (*Protocol, error)

NewProtocol instantiates the protocol of staking

func (*Protocol) ActiveCandidates

func (p *Protocol) ActiveCandidates(ctx context.Context, sr protocol.StateReader, height uint64) (state.CandidateList, error)

ActiveCandidates returns all active candidates in candidate center

func (*Protocol) Commit

func (p *Protocol) Commit(ctx context.Context, sm protocol.StateManager) error

Commit commits the last change

func (*Protocol) ConstructExecution

func (p *Protocol) ConstructExecution(ctx context.Context, act *action.MigrateStake, nonce, gas uint64, gasPrice *big.Int, sr protocol.StateReader) (action.Envelope, error)

func (*Protocol) CreateGenesisStates

func (p *Protocol) CreateGenesisStates(
	ctx context.Context,
	sm protocol.StateManager,
) error

CreateGenesisStates is used to setup BootstrapCandidates from genesis config.

func (*Protocol) CreatePreStates

func (p *Protocol) CreatePreStates(ctx context.Context, sm protocol.StateManager) error

CreatePreStates updates state manager

func (*Protocol) ForceRegister

func (p *Protocol) ForceRegister(r *protocol.Registry) error

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

func (*Protocol) Handle

func (p *Protocol) Handle(ctx context.Context, elp action.Envelope, sm protocol.StateManager) (receipt *action.Receipt, err error)

Handle handles a staking message

func (*Protocol) HandleReceipt added in v2.2.0

func (p *Protocol) HandleReceipt(ctx context.Context, elp action.Envelope, sm protocol.StateManager, receipt *action.Receipt) error

HandleReceipt handles a receipt

func (*Protocol) Name

func (p *Protocol) Name() string

Name returns the name of protocol

func (*Protocol) PreCommit

func (p *Protocol) PreCommit(ctx context.Context, sm protocol.StateManager) error

PreCommit performs pre-commit

func (*Protocol) ReadState

func (p *Protocol) ReadState(ctx context.Context, sr protocol.StateReader, method []byte, args ...[]byte) ([]byte, uint64, error)

ReadState read the state on blockchain via protocol

func (*Protocol) Register

func (p *Protocol) Register(r *protocol.Registry) error

Register registers the protocol with a unique ID

func (*Protocol) SlashCandidate added in v2.3.0

func (p *Protocol) SlashCandidate(
	ctx context.Context,
	sm protocol.StateManager,
	operator address.Address,
	amount *big.Int,
) error

func (*Protocol) Start

Start starts the protocol

func (*Protocol) Validate

func (p *Protocol) Validate(ctx context.Context, elp action.Envelope, sr protocol.StateReader) error

Validate validates a staking message

type ReadState

type ReadState interface {
	// contains filtered or unexported methods
}

ReadState related to read bucket and candidate by request

type ReceiptError

type ReceiptError interface {
	Error() string
	ReceiptStatus() uint64
}

ReceiptError indicates a non-critical error with corresponding receipt status

type RegistrationConsts

type RegistrationConsts struct {
	Fee          *big.Int
	MinSelfStake *big.Int
}

RegistrationConsts are the registration fee and min self stake

type ReviseConfig

type ReviseConfig struct {
	VoteWeight                  genesis.VoteWeightCalConsts
	ReviseHeights               []uint64
	CorrectCandsHeight          uint64
	SelfStakeBucketReviseHeight uint64
	CorrectCandSelfStakeHeight  uint64
}

VoteReviser is used to recalculate candidate votes.

type Snapshot added in v2.2.0

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

type VoteBucket

type VoteBucket struct {
	Index            uint64
	Candidate        address.Address
	Owner            address.Address
	StakedAmount     *big.Int
	StakedDuration   time.Duration
	CreateTime       time.Time
	StakeStartTime   time.Time
	UnstakeStartTime time.Time
	AutoStake        bool
	ContractAddress  string // Corresponding contract address; Empty if it's native staking
	// only used for contract staking buckets
	StakedDurationBlockNumber uint64
	CreateBlockHeight         uint64
	StakeStartBlockHeight     uint64
	UnstakeStartBlockHeight   uint64
	Timestamped               bool
}

VoteBucket represents a vote

func NewVoteBucket

func NewVoteBucket(cand, owner address.Address, amount *big.Int, duration uint32, ctime time.Time, autoStake bool) *VoteBucket

NewVoteBucket creates a new vote bucket

func (*VoteBucket) Decode added in v2.3.0

Decode decodes VoteBucket from generic value

func (*VoteBucket) Deserialize

func (vb *VoteBucket) Deserialize(buf []byte) error

Deserialize deserializes bytes into bucket

func (*VoteBucket) Encode added in v2.3.0

func (vb *VoteBucket) Encode() (systemcontracts.GenericValue, error)

Encode encodes VoteBucket into generic value

func (*VoteBucket) Serialize

func (vb *VoteBucket) Serialize() ([]byte, error)

Serialize serializes bucket into bytes

type VoteReviser

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

VoteReviser is used to recalculate candidate votes.

func NewVoteReviser

func NewVoteReviser(cfg ReviseConfig) *VoteReviser

NewVoteReviser creates a VoteReviser.

func (*VoteReviser) NeedRevise

func (vr *VoteReviser) NeedRevise(height uint64) bool

NeedRevise returns true if height needs revise

func (*VoteReviser) Revise

func (vr *VoteReviser) Revise(ctx protocol.FeatureCtx, csm CandidateStateManager, height uint64) error

Revise recalculate candidate votes on preset revising height.

Directories

Path Synopsis
v1
v2
v3
v4

Jump to

Keyboard shortcuts

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