app

package
v0.0.0-...-59e56fa Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PoiPeriod

func PoiPeriod(t inter.Timestamp, config *lachesis.EconomyConfig) uint64

PoiPeriod calculate POI period from int64 unix time

Types

type App

type App struct {
	logger.Instance
	// contains filtered or unexported fields
}

App is a prototype of Tendermint ABCI Application

func New

func New(cfg Config, s *Store) *App

New is a constructor

func (*App) BeginBlock

func (a *App) BeginBlock(block *inter.Block, cheaters inter.Cheaters, stateHash common.Hash, stateReader evmcore.DummyChain)

BeginBlock is a prototype of ABCIApplication.BeginBlock

func (*App) DeliverTxs

func (a *App) DeliverTxs(
	block *inter.Block,
	evmBlock *evmcore.EvmBlock,
) (
	*inter.Block,
	*evmcore.EvmBlock,
	*big.Int,
	types.Receipts,
	bool,
)

DeliverTxs includes a set of ABCIApplication.DeliverTx() calls It execs ordered txns of new block on state.

func (*App) EndBlock

func (a *App) EndBlock(
	block *inter.Block,
	evmBlock *evmcore.EvmBlock,
	receipts types.Receipts,
	cheaters inter.Cheaters,
	stats *sfctype.EpochStats,
	txPositions map[common.Hash]TxPosition,
	blockParticipated map[idx.StakerID]bool,
) common.Hash

EndBlock is a prototype of ABCIApplication.EndBlock

func (*App) EthAPIBackend

func (a *App) EthAPIBackend() *EthAPIBackend

EthAPIBackend getter

func (*App) GetEpoch

func (a *App) GetEpoch() idx.Epoch

GetEpoch returns current epoch num to 3rd party.

func (App) GetEpochValidators

func (a App) GetEpochValidators(epoch idx.Epoch) []sfctype.SfcStakerAndID

GetEpochValidators provides store's method.

func (App) GetSfcConstants

func (a App) GetSfcConstants(epoch idx.Epoch) SfcConstants

GetSfcConstants provides store's method.

func (App) HasEpochValidator

func (a App) HasEpochValidator(epoch idx.Epoch, stakerID idx.StakerID) bool

HasEpochValidator provides store's method.

func (*App) InitChain

func (a *App) InitChain(current idx.Epoch)

InitChain is a prototype of ABCIApplication.InitChain. It should be Called once upon genesis.

func (App) StateDB

func (a App) StateDB(from common.Hash) *state.StateDB

StateDB provides store's method.

type BlockInfo

type BlockInfo struct {
	Index idx.Block
	Time  inter.Timestamp
}

BlockInfo includes only necessary information about inter.Block

type BlocksMissed

type BlocksMissed struct {
	Num    idx.Block
	Period inter.Timestamp
}

BlocksMissed is information about missed blocks from a staker.

type Config

type Config struct {
	Net lachesis.Config
	StoreConfig

	// TxIndex enables indexing transactions and receipts
	TxIndex bool
	// EpochDowntimeIndex enables indexing downtime by epoch
	EpochDowntimeIndex bool
	// EpochActiveValidationScoreIndex enables indexing validation score by epoch
	EpochActiveValidationScoreIndex bool
}

Config for the application.

func DefaultConfig

func DefaultConfig(network lachesis.Config) Config

DefaultConfig for product.

type EthAPIBackend

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

EthAPIBackend provides methods for ethapi.Backend

func (*EthAPIBackend) ChainDb

func (b *EthAPIBackend) ChainDb() ethdb.Database

func (*EthAPIBackend) EvmLogIndex

func (b *EthAPIBackend) EvmLogIndex() *topicsdb.Index

func (*EthAPIBackend) ForEachSfcDelegator

func (b *EthAPIBackend) ForEachSfcDelegator(do func(sfctype.SfcDelegatorAndAddr))

ForEachSfcDelegator provides store's method.

func (*EthAPIBackend) ForEachSfcStaker

func (b *EthAPIBackend) ForEachSfcStaker(do func(sfctype.SfcStakerAndID))

ForEachSfcStaker provides store's method.

func (*EthAPIBackend) GetDelegator

func (b *EthAPIBackend) GetDelegator(ctx context.Context, addr common.Address) (*sfctype.SfcDelegator, error)

GetDelegator returns SFC delegator info

func (*EthAPIBackend) GetDelegatorClaimedRewards

func (b *EthAPIBackend) GetDelegatorClaimedRewards(ctx context.Context, addr common.Address) (*big.Int, error)

GetDelegatorClaimedRewards returns sum of claimed rewards in past, by this delegator

func (*EthAPIBackend) GetDowntime

func (b *EthAPIBackend) GetDowntime(
	ctx context.Context, stakerID idx.StakerID, epoch rpc.BlockNumber,
) (
	num idx.Block, period inter.Timestamp, err error,
)

GetDowntime returns staker's Downtime for epoch. * When epoch is "pending" the downtime for latest epoch are returned. * When epoch is "latest" the downtime for latest sealed epoch are returned.

func (*EthAPIBackend) GetOriginationScore

func (b *EthAPIBackend) GetOriginationScore(ctx context.Context, stakerID idx.StakerID) (*big.Int, error)

GetOriginationScore returns staker's OriginationScore.

func (*EthAPIBackend) GetReceipts

func (b *EthAPIBackend) GetReceipts(n idx.Block) types.Receipts

func (*EthAPIBackend) GetSfcStaker

func (b *EthAPIBackend) GetSfcStaker(stakerID idx.StakerID) *sfctype.SfcStaker

GetSfcStaker provides store's method.

func (*EthAPIBackend) GetStakerClaimedRewards

func (b *EthAPIBackend) GetStakerClaimedRewards(ctx context.Context, stakerID idx.StakerID) (*big.Int, error)

GetStakerClaimedRewards returns sum of claimed rewards in past, by this staker

func (*EthAPIBackend) GetStakerDelegatorsClaimedRewards

func (b *EthAPIBackend) GetStakerDelegatorsClaimedRewards(ctx context.Context, stakerID idx.StakerID) (*big.Int, error)

GetStakerDelegatorsClaimedRewards returns sum of claimed rewards in past, by this delegators of this staker

func (*EthAPIBackend) GetStakerPoI

func (b *EthAPIBackend) GetStakerPoI(ctx context.Context, stakerID idx.StakerID) (*big.Int, error)

GetStakerPoI returns staker's PoI.

func (*EthAPIBackend) GetValidationScore

func (b *EthAPIBackend) GetValidationScore(
	ctx context.Context, stakerID idx.StakerID, epoch rpc.BlockNumber,
) (
	score *big.Int, err error,
)

GetValidationScore returns staker's ValidationScore for epoch. * When epoch is "pending" the validation score for latest epoch are returned. * When epoch is "latest" the validation score for latest sealed epoch are returned.

func (*EthAPIBackend) HasSfcStaker

func (b *EthAPIBackend) HasSfcStaker(stakerID idx.StakerID) bool

HasSfcStaker provides store's method.

type SfcConstants

type SfcConstants struct {
	ShortGasPowerAllocPerSec uint64
	LongGasPowerAllocPerSec  uint64
	BaseRewardPerSec         *big.Int
}

SfcConstants are constants which may be changed by SFC contract

type Store

type Store struct {
	logger.Instance
	// contains filtered or unexported fields
}

Store is a node persistent storage working over physical key-value database.

func NewMemStore

func NewMemStore() *Store

NewMemStore creates store over memory map.

func NewStore

func NewStore(dbs *flushable.SyncedPool, cfg StoreConfig) *Store

NewStore creates store over key-value db.

func (*Store) AddDirtyOriginationScore

func (s *Store) AddDirtyOriginationScore(stakerID idx.StakerID, v *big.Int)

AddDirtyOriginationScore add gas value for active validation score

func (*Store) AddDirtyValidationScore

func (s *Store) AddDirtyValidationScore(stakerID idx.StakerID, v *big.Int)

AddDirtyValidationScore add gas value for active validation score

func (*Store) AddPoiFee

func (s *Store) AddPoiFee(poiPeriod uint64, diff *big.Int)

AddPoiFee add gas used to POI period

func (*Store) ApplyGenesis

func (s *Store) ApplyGenesis(net *lachesis.Config) (block *evmcore.EvmBlock, isNew bool, err error)

ApplyGenesis writes initial state.

func (*Store) Close

func (s *Store) Close()

Close leaves underlying database.

func (*Store) DelActiveOriginationScore

func (s *Store) DelActiveOriginationScore(stakerID idx.StakerID)

DelActiveOriginationScore deletes record about active origination score of a staker

func (*Store) DelActiveValidationScore

func (s *Store) DelActiveValidationScore(stakerID idx.StakerID)

DelActiveValidationScore deletes record about active validation score of a staker

func (*Store) DelAllActiveOriginationScores

func (s *Store) DelAllActiveOriginationScores()

DelAllActiveOriginationScores deletes all the record about dirty origination scores of stakers

func (*Store) DelAllActiveValidationScores

func (s *Store) DelAllActiveValidationScores()

DelAllActiveValidationScores deletes all the record about dirty validation scores of stakers

func (*Store) DelAllWeightedDelegatorsFee

func (s *Store) DelAllWeightedDelegatorsFee()

DelAllWeightedDelegatorsFee deletes all the records about gas used by delegators of all stakers

func (*Store) DelDelegatorClaimedRewards

func (s *Store) DelDelegatorClaimedRewards(addr common.Address)

DelDelegatorClaimedRewards deletes record about sum of claimed rewards in past

func (*Store) DelDirtyOriginationScore

func (s *Store) DelDirtyOriginationScore(stakerID idx.StakerID)

DelDirtyOriginationScore deletes record about dirty origination score of a staker

func (*Store) DelDirtyValidationScore

func (s *Store) DelDirtyValidationScore(stakerID idx.StakerID)

DelDirtyValidationScore deletes record about dirty validation score of a staker

func (*Store) DelSfcDelegator

func (s *Store) DelSfcDelegator(address common.Address)

DelSfcDelegator deletes SfcDelegator

func (*Store) DelSfcStaker

func (s *Store) DelSfcStaker(stakerID idx.StakerID)

DelSfcStaker deletes SfcStaker

func (*Store) DelStakerClaimedRewards

func (s *Store) DelStakerClaimedRewards(stakerID idx.StakerID)

DelStakerClaimedRewards deletes record about sum of claimed rewards in past

func (*Store) DelStakerDelegatorsClaimedRewards

func (s *Store) DelStakerDelegatorsClaimedRewards(stakerID idx.StakerID)

DelStakerDelegatorsClaimedRewards deletes record about sum of claimed rewards in past

func (*Store) DelStakerPOI

func (s *Store) DelStakerPOI(stakerID idx.StakerID)

DelStakerPOI deletes record about staker's PoI

func (*Store) DelWeightedDelegatorsFee

func (s *Store) DelWeightedDelegatorsFee(stakerID idx.StakerID)

DelWeightedDelegatorsFee deletes record about gas used by delegators of a staker

func (*Store) EvmLogs

func (s *Store) EvmLogs() *topicsdb.Index

func (*Store) EvmTable

func (s *Store) EvmTable() ethdb.Database

func (*Store) FlushState

func (s *Store) FlushState()

FlushState changes.

func (*Store) ForEachSfcDelegator

func (s *Store) ForEachSfcDelegator(do func(sfctype.SfcDelegatorAndAddr))

ForEachSfcDelegator iterates all stored SfcDelegators

func (*Store) ForEachSfcStaker

func (s *Store) ForEachSfcStaker(do func(sfctype.SfcStakerAndID))

ForEachSfcStaker iterates all stored SfcStakers

func (*Store) GetActiveOriginationScore

func (s *Store) GetActiveOriginationScore(stakerID idx.StakerID) *big.Int

GetActiveOriginationScore return gas value for active validator score

func (*Store) GetActiveSfcStakers

func (s *Store) GetActiveSfcStakers() []sfctype.SfcStakerAndID

GetActiveSfcStakers returns stakers which will become validators in next epoch

func (*Store) GetActiveValidationScore

func (s *Store) GetActiveValidationScore(stakerID idx.StakerID) *big.Int

GetActiveValidationScore return gas value for active validator score

func (*Store) GetActiveValidationScoreEpoch

func (s *Store) GetActiveValidationScoreEpoch(stakerID idx.StakerID, epoch idx.Epoch) *big.Int

GetActiveValidationScore return gas value for active validator score

func (*Store) GetAddressFee

func (s *Store) GetAddressFee(addr common.Address, poiPeriod uint64) *big.Int

GetAddressFee get gas used by address

func (*Store) GetAddressLastTxTime

func (s *Store) GetAddressLastTxTime(addr common.Address) inter.Timestamp

GetAddressLastTxTime get last time for last tx from this address

func (*Store) GetAddressPOI

func (s *Store) GetAddressPOI(address common.Address) *big.Int

GetAddressPOI get POI value for user address

func (*Store) GetBlock

func (s *Store) GetBlock(n idx.Block) *BlockInfo

GetBlock returns stored block.

func (*Store) GetBlocksMissed

func (s *Store) GetBlocksMissed(stakerID idx.StakerID) BlocksMissed

GetBlocksMissed return blocks missed num for validator

func (*Store) GetBlocksMissedEpoch

func (s *Store) GetBlocksMissedEpoch(stakerID idx.StakerID, epoch idx.Epoch) BlocksMissed

func (*Store) GetDelegatorClaimedRewards

func (s *Store) GetDelegatorClaimedRewards(addr common.Address) *big.Int

GetDelegatorClaimedRewards returns sum of claimed rewards in past, by this delegator

func (*Store) GetDirtyOriginationScore

func (s *Store) GetDirtyOriginationScore(stakerID idx.StakerID) *big.Int

GetDirtyOriginationScore return gas value for active validator score

func (*Store) GetDirtyValidationScore

func (s *Store) GetDirtyValidationScore(stakerID idx.StakerID) *big.Int

GetDirtyValidationScore return gas value for active validator score

func (*Store) GetEpochValidators

func (s *Store) GetEpochValidators(epoch idx.Epoch) []sfctype.SfcStakerAndID

GetEpochValidators returns all stored EpochValidators on the epoch

func (*Store) GetLastVoting

func (s *Store) GetLastVoting() (block idx.Block, start inter.Timestamp)

GetLastVoting says when last voting was (sealed epoch)

func (*Store) GetPoiFee

func (s *Store) GetPoiFee(poiPeriod uint64) *big.Int

GetPoiFee get gas used for POI period

func (*Store) GetReceipts

func (s *Store) GetReceipts(n idx.Block) types.Receipts

GetReceipts returns stored transaction receipts.

func (*Store) GetSfcConstants

func (s *Store) GetSfcConstants(epoch idx.Epoch) SfcConstants

GetSfcConstants returns stored SfcConstants

func (*Store) GetSfcDelegator

func (s *Store) GetSfcDelegator(address common.Address) *sfctype.SfcDelegator

GetSfcDelegator returns stored SfcDelegator

func (*Store) GetSfcStaker

func (s *Store) GetSfcStaker(stakerID idx.StakerID) *sfctype.SfcStaker

GetSfcStaker returns stored SfcStaker

func (*Store) GetSfcStakers

func (s *Store) GetSfcStakers() []sfctype.SfcStakerAndID

GetSfcStakers returns all stored SfcStakers

func (*Store) GetStakerClaimedRewards

func (s *Store) GetStakerClaimedRewards(stakerID idx.StakerID) *big.Int

GetStakerClaimedRewards returns sum of claimed rewards in past, by this staker

func (*Store) GetStakerDelegatorsClaimedRewards

func (s *Store) GetStakerDelegatorsClaimedRewards(stakerID idx.StakerID) *big.Int

GetStakerDelegatorsClaimedRewards returns sum of claimed rewards in past, by this delegators of this staker

func (*Store) GetStakerPOI

func (s *Store) GetStakerPOI(stakerID idx.StakerID) *big.Int

GetStakerPOI get POI value for staker

func (*Store) GetTotalSupply

func (s *Store) GetTotalSupply() *big.Int

GetTotalSupply returns total supply

func (*Store) GetWeightedDelegatorsFee

func (s *Store) GetWeightedDelegatorsFee(stakerID idx.StakerID) *big.Int

GetWeightedDelegatorsFee get gas used by delegators of a staker

func (*Store) HasEpochValidator

func (s *Store) HasEpochValidator(epoch idx.Epoch, stakerID idx.StakerID) bool

HasEpochValidator returns true if validator exists

func (*Store) HasSfcConstants

func (s *Store) HasSfcConstants(epoch idx.Epoch) bool

HasSfcConstants returns true if SFC constants are stored

func (*Store) HasSfcStaker

func (s *Store) HasSfcStaker(stakerID idx.StakerID) bool

HasSfcStaker returns true if staker exists

func (*Store) IncBlocksMissed

func (s *Store) IncBlocksMissed(stakerID idx.StakerID, periodDiff inter.Timestamp)

IncBlocksMissed add count of missed blocks for validator

func (*Store) IncDelegatorClaimedRewards

func (s *Store) IncDelegatorClaimedRewards(addr common.Address, diff *big.Int)

IncDelegatorClaimedRewards increments sum of claimed rewards in past

func (*Store) IncStakerClaimedRewards

func (s *Store) IncStakerClaimedRewards(stakerID idx.StakerID, diff *big.Int)

IncStakerClaimedRewards increments sum of claimed rewards in past

func (*Store) IncStakerDelegatorsClaimedRewards

func (s *Store) IncStakerDelegatorsClaimedRewards(stakerID idx.StakerID, diff *big.Int)

IncStakerDelegatorsClaimedRewards increments sum of claimed rewards in past

func (*Store) IndexLogs

func (s *Store) IndexLogs(recs ...*types.Log)

StateDB returns state database.

func (*Store) MoveDirtyOriginationScoresToActive

func (s *Store) MoveDirtyOriginationScoresToActive()

MoveDirtyOriginationScoresToActive moves all the dirty records to active

func (*Store) MoveDirtyValidationScoresToActive

func (s *Store) MoveDirtyValidationScoresToActive()

MoveDirtyValidationScoresToActive moves all the dirty records to active

func (*Store) NewDowntimeSnapshotEpoch

func (s *Store) NewDowntimeSnapshotEpoch(epoch idx.Epoch)

NewDowntimeSnapshotEpoch add count of missed blocks for validator by epoch

func (*Store) NewScoreSnapshotEpoch

func (s *Store) NewScoreSnapshotEpoch(epoch idx.Epoch)

NewScoreSnapshotEpoch add scores for validator by epoch

func (*Store) ResetBlocksMissed

func (s *Store) ResetBlocksMissed(stakerID idx.StakerID)

ResetBlocksMissed set to 0 missed blocks for validator

func (*Store) SetAddressFee

func (s *Store) SetAddressFee(addr common.Address, poiPeriod uint64, val *big.Int)

SetAddressFee save gas used by address

func (*Store) SetAddressLastTxTime

func (s *Store) SetAddressLastTxTime(addr common.Address, t inter.Timestamp)

SetAddressLastTxTime save last time for tx from this address

func (*Store) SetAddressPOI

func (s *Store) SetAddressPOI(address common.Address, poi *big.Int)

SetAddressPOI save POI value for a user address

func (*Store) SetBlock

func (s *Store) SetBlock(b *BlockInfo)

SetBlock stores chain block.

func (*Store) SetDelegatorClaimedRewards

func (s *Store) SetDelegatorClaimedRewards(addr common.Address, amount *big.Int)

SetDelegatorClaimedRewards sets sum of claimed rewards in past

func (*Store) SetEpochValidators

func (s *Store) SetEpochValidators(epoch idx.Epoch, vv []sfctype.SfcStakerAndID)

SetEpochValidator stores EpochValidator

func (*Store) SetLastVoting

func (s *Store) SetLastVoting(block idx.Block, start inter.Timestamp)

SetLastVoting saves when last voting was (sealed epoch)

func (*Store) SetPoiFee

func (s *Store) SetPoiFee(poiPeriod uint64, val *big.Int)

SetPoiFee save gas used for POI period

func (*Store) SetReceipts

func (s *Store) SetReceipts(n idx.Block, receipts types.Receipts)

SetReceipts stores transaction receipts.

func (*Store) SetSfcConstants

func (s *Store) SetSfcConstants(epoch idx.Epoch, constants SfcConstants)

SetSfcConstants stores SfcConstants

func (*Store) SetSfcDelegator

func (s *Store) SetSfcDelegator(address common.Address, v *sfctype.SfcDelegator)

SetSfcDelegator stores SfcDelegator

func (*Store) SetSfcStaker

func (s *Store) SetSfcStaker(stakerID idx.StakerID, v *sfctype.SfcStaker)

SetSfcStaker stores SfcStaker

func (*Store) SetStakerClaimedRewards

func (s *Store) SetStakerClaimedRewards(stakerID idx.StakerID, amount *big.Int)

SetStakerClaimedRewards sets sum of claimed rewards in past

func (*Store) SetStakerDelegatorsClaimedRewards

func (s *Store) SetStakerDelegatorsClaimedRewards(stakerID idx.StakerID, amount *big.Int)

SetStakerDelegatorsClaimedRewards sets sum of claimed rewards in past

func (*Store) SetStakerPOI

func (s *Store) SetStakerPOI(stakerID idx.StakerID, poi *big.Int)

SetStakerPOI save POI value for staker

func (*Store) SetTotalSupply

func (s *Store) SetTotalSupply(amount *big.Int)

SetTotalSupply stores total supply

func (*Store) SetWeightedDelegatorsFee

func (s *Store) SetWeightedDelegatorsFee(stakerID idx.StakerID, val *big.Int)

SetWeightedDelegatorsFee stores gas used by delegators of a staker

func (*Store) StateDB

func (s *Store) StateDB(from common.Hash) *state.StateDB

StateDB returns state database.

type StoreConfig

type StoreConfig struct {
	// Cache size for Block.
	BlockCacheSize int
	// Cache size for Receipts.
	ReceiptsCacheSize int
	// Cache size for Stakers.
	StakersCacheSize int
	// Cache size for Delegators.
	DelegatorsCacheSize int
}

StoreConfig is a config for store db.

func DefaultStoreConfig

func DefaultStoreConfig() StoreConfig

DefaultStoreConfig for product.

func LiteStoreConfig

func LiteStoreConfig() StoreConfig

LiteStoreConfig is for tests or inmemory.

type TxPosition

type TxPosition struct {
	Block       idx.Block
	Event       hash.Event
	Creator     idx.StakerID
	EventOffset uint32
	BlockOffset uint32
}

TxPosition includes block and event.

Jump to

Keyboard shortcuts

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