gossip

package
v1.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 85 Imported by: 1

Documentation

Index

Constants

View Source
const (
	MimetypeEvent    = "application/event"
	TxTimeBufferSize = 20000
	TxTurnPeriod     = 4 * time.Second
	TxTurnNonces     = 8
)
View Source
const (
	// Protocol messages belonging to eth/62
	EthStatusMsg = 0x00
	EvmTxMsg     = 0x02

	// Signals about the current synchronization status.
	// The current peer's status is used during packs downloading,
	// and to estimate may peer be interested in the new event or not
	// (based on peer's epoch).
	ProgressMsg = 0xf0

	// Non-aggressive events propagation. Signals about newly-connected
	// batch of events, sending only their IDs.
	NewEventHashesMsg = 0xf1

	// Request the batch of events by IDs
	GetEventsMsg = 0xf2
	// Contains the batch of events.
	// May be an answer to GetEventsMsg, or be sent during aggressive events propagation.
	EventsMsg = 0xf3

	// Request pack infos by epoch:pack indexes
	GetPackInfosMsg = 0xf4
	// Contains the requested pack infos. An answer to GetPackInfosMsg.
	PackInfosMsg = 0xf5

	// Request pack by epoch:pack index
	GetPackMsg = 0xf6
	// Contains the requested pack. An answer to GetPackMsg.
	PackMsg = 0xf7
)

protocol message codes

View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIDMismatch
	ErrGenesisMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrSuspendedPeer
	ErrEmptyMessage = 0xf00
)

Variables

View Source
var ErrNotImplemented = func(name string) error { return errors.New(name + " method is not implemented yet") }
View Source
var (
	ErrUnderpriced = evmcore.ErrUnderpriced
)
View Source
var ProtocolVersions = []uint{lachesis62}

ProtocolVersions are the supported versions of the protocol (first is primary).

Functions

func PoiPeriod

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

PoiPeriod calculate POI period from int64 unix time

func ReadGasPowerContext

func ReadGasPowerContext(s *Store, a *app.Store, validators *pos.Validators, epoch idx.Epoch, cfg *lachesis.EconomyConfig) *gaspowercheck.ValidationContext

ReadGasPowerContext reads current validation context for gaspowercheck

Types

type Config

type Config struct {
	Net     lachesis.Config
	Emitter EmitterConfig
	TxPool  evmcore.TxPoolConfig
	StoreConfig

	TxIndex             bool // Whether to enable indexing transactions and receipts or not
	DecisiveEventsIndex bool // Whether to enable indexing events which decide blocks or not
	EventLocalTimeIndex bool // Whether to enable indexing arrival time of events or not

	Upgrade UpgradeConfig

	// Protocol options
	Protocol ProtocolConfig

	// Gas Price Oracle options
	GPO gasprice.Config

	// Enables tracking of SHA3 preimages in the VM
	EnablePreimageRecording bool // TODO

	// Type of the EWASM interpreter ("" for default)
	EWASMInterpreter string

	// Type of the EVM interpreter ("" for default)
	EVMInterpreter string // TODO custom interpreter

	// RPCGasCap is the global gas cap for eth-call variants.
	RPCGasCap uint64 `toml:",omitempty"`

	// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
	// send-transction variants. The unit is ether.
	RPCTxFeeCap float64 `toml:",omitempty"`

	ExtRPCEnabled bool

	RPCLogsBloom bool
}

Config for the gossip service.

func DefaultConfig

func DefaultConfig(network lachesis.Config) Config

DefaultConfig returns the default configurations for the gossip service.

type Consensus

type Consensus interface {
	// PushEvent takes event for processing.
	ProcessEvent(e *inter.Event) error
	// GetGenesisHash returns hash of genesis poset works with.
	GetGenesisHash() common.Hash
	// GetVectorIndex returns internal vector clock if exists
	GetVectorIndex() *vector.Index
	// Sets consensus fields. Returns nil if event should be dropped.
	Prepare(e *inter.Event) *inter.Event
	// LastBlock returns current block.
	LastBlock() (idx.Block, hash.Event)
	// GetEpoch returns current epoch num.
	GetEpoch() idx.Epoch
	// GetValidators returns validators of current epoch.
	GetValidators() *pos.Validators
	// GetEpochValidators atomically returns validators of current epoch, and the epoch.
	GetEpochValidators() (*pos.Validators, idx.Epoch)
	// GetConsensusTime calc consensus timestamp for given event.
	GetConsensusTime(id hash.Event) (inter.Timestamp, error)

	// Bootstrap must be called (once) before calling other methods
	Bootstrap(callbacks inter.ConsensusCallbacks)
}

Consensus is a consensus interface.

type EmitIntervals

type EmitIntervals struct {
	Min                time.Duration `json:"min"`
	Max                time.Duration `json:"max"`
	Confirming         time.Duration `json:"confirming"` // emit time when there's no txs to originate, but at least 1 tx to confirm
	SelfForkProtection time.Duration `json:"selfForkProtection"`
}

EmitIntervals is the configuration of emit intervals.

func (*EmitIntervals) RandomizeEmitTime

func (cfg *EmitIntervals) RandomizeEmitTime(r *rand.Rand) *EmitIntervals

RandomizeEmitTime and return new config

type Emitter

type Emitter struct {
	logger.Periodic
	// contains filtered or unexported fields
}

func NewEmitter

func NewEmitter(
	net *lachesis.Config,
	config *EmitterConfig,
	world EmitterWorld,
) *Emitter

NewEmitter creation.

func (*Emitter) EmitEvent

func (em *Emitter) EmitEvent() *inter.Event

func (*Emitter) GetValidator

func (em *Emitter) GetValidator() (idx.StakerID, common.Address)

GetValidator gets event creator.

func (*Emitter) OnNewEpoch

func (em *Emitter) OnNewEpoch(newValidators *pos.Validators, newEpoch idx.Epoch)

OnNewEpoch should be called after each epoch change, and on startup

func (*Emitter) OnNewEvent

func (em *Emitter) OnNewEvent(e *inter.Event)

OnNewEvent tracks new events to find out am I properly synced or not

func (*Emitter) SetValidator

func (em *Emitter) SetValidator(addr common.Address)

SetValidator sets event creator.

func (*Emitter) StartEventEmission

func (em *Emitter) StartEventEmission()

StartEventEmission starts event emission.

func (*Emitter) StopEventEmission

func (em *Emitter) StopEventEmission()

StopEventEmission stops event emission.

type EmitterConfig

type EmitterConfig struct {
	VersionToPublish string

	Validator common.Address `json:"validator"`

	EmitIntervals EmitIntervals `json:"emitIntervals"` // event emission intervals

	MaxGasRateGrowthFactor float64 `json:"maxGasRateGrowthFactor"` // fine to use float, because no need in determinism

	MaxTxsFromSender int `json:"maxTxsFromSender"`

	EpochTailLength idx.Frame `json:"epochTailLength"` // number of frames before event is considered epoch

	MaxParents int `json:"maxParents"`

	// thresholds on GasLeft
	SmoothTpsThreshold uint64 `json:"smoothTpsThreshold"`
	NoTxsThreshold     uint64 `json:"noTxsThreshold"`
	EmergencyThreshold uint64 `json:"emergencyThreshold"`
}

EmitterConfig is the configuration of events emitter.

func DefaultEmitterConfig

func DefaultEmitterConfig() EmitterConfig

DefaultEmitterConfig returns the default configurations for the events emitter.

func FakeEmitterConfig

func FakeEmitterConfig() EmitterConfig

FakeEmitterConfig returns the testing configurations for the events emitter.

type EmitterWorld

type EmitterWorld struct {
	Store       *Store
	App         *app.Store
	Engine      Consensus
	EngineMu    *sync.RWMutex
	Txpool      txPool
	Am          *accounts.Manager
	OccurredTxs *occuredtxs.Buffer

	Checkers *eventcheck.Checkers

	MinGasPrice        func() *big.Int
	OnEmitted          func(e *inter.Event)
	IsSynced           func() bool
	LastBlockProcessed func() time.Time
	PeersNum           func() int

	IsMigration func() bool

	AddVersion func(e *inter.Event) *inter.Event
}

EmitterWorld is emitter's external world

type Enr

type Enr struct {
	ForkID forkid.ID
	// Ignore additional fields (for forward compatibility).
	Rest []rlp.RawValue `rlp:"tail"`
}

Enr is ENR entry which advertises eth protocol on the discovery network.

func (Enr) ENRKey

func (e Enr) ENRKey() string

ENRKey implements enr.Entry.

type EthAPIBackend

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

EthAPIBackend implements ethapi.Backend.

func (*EthAPIBackend) AccountManager

func (b *EthAPIBackend) AccountManager() *accounts.Manager

func (*EthAPIBackend) BlockByHash

func (b *EthAPIBackend) BlockByHash(ctx context.Context, h common.Hash) (*evmcore.EvmBlock, error)

func (*EthAPIBackend) BlockByNumber

func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*evmcore.EvmBlock, error)

BlockByNumber returns block by its number.

func (*EthAPIBackend) BlocksTTF

func (b *EthAPIBackend) BlocksTTF(ctx context.Context, untilBlock rpc.BlockNumber, maxBlocks idx.Block, mode string) (map[hash.Event]time.Duration, error)

BlocksTTF for a range of blocks

func (*EthAPIBackend) CalcLogsBloom

func (b *EthAPIBackend) CalcLogsBloom() bool

func (*EthAPIBackend) ChainConfig

func (b *EthAPIBackend) ChainConfig() *params.ChainConfig

ChainConfig returns the active chain configuration.

func (*EthAPIBackend) ChainDb

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

func (*EthAPIBackend) CurrentBlock

func (b *EthAPIBackend) CurrentBlock() *evmcore.EvmBlock

func (*EthAPIBackend) CurrentEpoch

func (b *EthAPIBackend) CurrentEpoch(ctx context.Context) idx.Epoch

CurrentEpoch returns current epoch number.

func (*EthAPIBackend) EvmLogIndex

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

func (*EthAPIBackend) ExtRPCEnabled

func (b *EthAPIBackend) ExtRPCEnabled() bool

func (*EthAPIBackend) ForEachEpochEvent

func (b *EthAPIBackend) ForEachEpochEvent(ctx context.Context, epoch rpc.BlockNumber, onEvent func(event *inter.Event) bool) error

ForEachEpochEvent iterates all the events which are observed by head, and accepted by a filter. filter CANNOT called twice for the same event.

func (*EthAPIBackend) GetConsensusTime

func (b *EthAPIBackend) GetConsensusTime(ctx context.Context, shortEventID string) (inter.Timestamp, error)

GetConsensusTime returns event's consensus time, if event is confirmed.

func (*EthAPIBackend) GetDelegation

GetDelegation returns SFC delegation info

func (*EthAPIBackend) GetDelegationClaimedRewards

func (b *EthAPIBackend) GetDelegationClaimedRewards(ctx context.Context, id sfctype.DelegationID) (*big.Int, error)

GetDelegationClaimedRewards returns sum of claimed rewards in past, by this delegation

func (*EthAPIBackend) GetDelegationsByAddress

func (b *EthAPIBackend) GetDelegationsByAddress(ctx context.Context, addr common.Address) ([]sfctype.SfcDelegationAndID, error)

GetDelegationsByAddress returns SFC delegations info by address

func (*EthAPIBackend) GetDelegationsOf

func (b *EthAPIBackend) GetDelegationsOf(ctx context.Context, stakerID idx.StakerID) ([]sfctype.SfcDelegationAndID, error)

GetDelegationsOf returns SFC delegations who delegated to a staker

func (*EthAPIBackend) GetDowntime

func (b *EthAPIBackend) GetDowntime(ctx context.Context, stakerID idx.StakerID) (idx.Block, inter.Timestamp, error)

GetDowntime returns staker's Downtime.

func (*EthAPIBackend) GetEVM

func (b *EthAPIBackend) GetEVM(ctx context.Context, msg evmcore.Message, state *state.StateDB, header *evmcore.EvmHeader) (*vm.EVM, func() error, error)

func (*EthAPIBackend) GetEpochStats

func (b *EthAPIBackend) GetEpochStats(ctx context.Context, requestedEpoch rpc.BlockNumber) (*sfctype.EpochStats, error)

GetEpochStats returns epoch statistics. * When epoch is -2 the statistics for latest epoch is returned. * When epoch is -1 the statistics for latest sealed epoch is returned.

func (*EthAPIBackend) GetEvent

func (b *EthAPIBackend) GetEvent(ctx context.Context, shortEventID string) (*inter.Event, error)

GetEvent returns Lachesis event by hash or short ID.

func (*EthAPIBackend) GetEventHeader

func (b *EthAPIBackend) GetEventHeader(ctx context.Context, shortEventID string) (*inter.EventHeaderData, error)

GetEventHeader returns the Lachesis event header by hash or short ID.

func (*EthAPIBackend) GetEventTime

func (b *EthAPIBackend) GetEventTime(ctx context.Context, id hash.Event, arrivalTime bool) inter.Timestamp

GetEventTime returns estimation of when event was created

func (*EthAPIBackend) GetFullEventID

func (b *EthAPIBackend) GetFullEventID(shortEventID string) (hash.Event, error)

GetFullEventID "converts" ShortID to full event's hash, by searching in events DB.

func (*EthAPIBackend) GetHeads

func (b *EthAPIBackend) GetHeads(ctx context.Context, epoch rpc.BlockNumber) (heads hash.Events, err error)

GetHeads returns IDs of all the epoch events with no descendants. * When epoch is -2 the heads for latest epoch are returned. * When epoch is -1 the heads for latest sealed epoch are returned.

func (*EthAPIBackend) GetLogs

func (b *EthAPIBackend) GetLogs(ctx context.Context, block common.Hash) ([][]*types.Log, error)

func (*EthAPIBackend) GetOriginationScore

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

GetOriginationScore returns staker's OriginationScore.

func (*EthAPIBackend) GetPoolNonce

func (b *EthAPIBackend) GetPoolNonce(ctx context.Context, addr common.Address) (uint64, error)

func (*EthAPIBackend) GetPoolTransaction

func (b *EthAPIBackend) GetPoolTransaction(hash common.Hash) *types.Transaction

func (*EthAPIBackend) GetPoolTransactions

func (b *EthAPIBackend) GetPoolTransactions() (types.Transactions, error)

func (*EthAPIBackend) GetReceipts

func (b *EthAPIBackend) GetReceipts(ctx context.Context, block common.Hash) (types.Receipts, error)

GetReceipts retrieves the receipts for all transactions in a given block.

func (*EthAPIBackend) GetReceiptsByNumber

func (b *EthAPIBackend) GetReceiptsByNumber(ctx context.Context, number rpc.BlockNumber) (types.Receipts, error)

GetReceiptsByNumber returns receipts by block number.

func (*EthAPIBackend) GetRewardWeights

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

GetRewardWeights returns staker's reward weights.

func (*EthAPIBackend) GetStaker

func (b *EthAPIBackend) GetStaker(ctx context.Context, stakerID idx.StakerID) (*sfctype.SfcStaker, error)

GetStaker returns SFC staker's info

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) GetStakerDelegationsClaimedRewards

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

GetStakerDelegationsClaimedRewards returns sum of claimed rewards in past, by this delegations of this staker

func (*EthAPIBackend) GetStakerID

func (b *EthAPIBackend) GetStakerID(ctx context.Context, addr common.Address) (idx.StakerID, error)

GetStakerID returns SFC staker's Id by address

func (*EthAPIBackend) GetStakerPoI

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

GetStakerPoI returns staker's PoI.

func (*EthAPIBackend) GetStakers

func (b *EthAPIBackend) GetStakers(ctx context.Context) ([]sfctype.SfcStakerAndID, error)

GetStakers returns SFC stakers info

func (*EthAPIBackend) GetTd

func (b *EthAPIBackend) GetTd(blockHash common.Hash) *big.Int

func (*EthAPIBackend) GetTransaction

func (b *EthAPIBackend) GetTransaction(ctx context.Context, txHash common.Hash) (*types.Transaction, uint64, uint64, error)

func (*EthAPIBackend) GetValidationScore

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

GetValidationScore returns staker's ValidationScore.

func (*EthAPIBackend) GetValidators

func (b *EthAPIBackend) GetValidators(ctx context.Context) *pos.Validators

func (*EthAPIBackend) HeaderByHash

func (b *EthAPIBackend) HeaderByHash(ctx context.Context, h common.Hash) (*evmcore.EvmHeader, error)

HeaderByHash returns evm header by its (atropos) hash.

func (*EthAPIBackend) HeaderByNumber

func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*evmcore.EvmHeader, error)

func (*EthAPIBackend) MinGasPrice

func (b *EthAPIBackend) MinGasPrice() *big.Int

func (*EthAPIBackend) Progress

func (b *EthAPIBackend) Progress() ethapi.PeerProgress

Progress returns current synchronization status of this node

func (*EthAPIBackend) ProtocolVersion

func (b *EthAPIBackend) ProtocolVersion() int

func (*EthAPIBackend) RPCGasCap

func (b *EthAPIBackend) RPCGasCap() uint64

func (*EthAPIBackend) RPCTxFeeCap

func (b *EthAPIBackend) RPCTxFeeCap() float64

func (*EthAPIBackend) SendTx

func (b *EthAPIBackend) SendTx(ctx context.Context, signedTx *types.Transaction) error

func (*EthAPIBackend) StateAndHeaderByNumberOrHash

func (b *EthAPIBackend) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *evmcore.EvmHeader, error)

func (*EthAPIBackend) Stats

func (b *EthAPIBackend) Stats() (pending int, queued int)

func (*EthAPIBackend) SubscribeLogsEvent

func (b *EthAPIBackend) SubscribeLogsEvent(ch chan<- []*types.Log) notify.Subscription

func (*EthAPIBackend) SubscribeNewBlockEvent

func (b *EthAPIBackend) SubscribeNewBlockEvent(ch chan<- evmcore.ChainHeadNotify) notify.Subscription

func (*EthAPIBackend) SubscribeNewTxsEvent

func (b *EthAPIBackend) SubscribeNewTxsEvent(ch chan<- core.NewTxsEvent) notify.Subscription

func (*EthAPIBackend) SubscribeNewTxsNotify

func (b *EthAPIBackend) SubscribeNewTxsNotify(ch chan<- evmcore.NewTxsNotify) notify.Subscription

func (*EthAPIBackend) SuggestPrice

func (b *EthAPIBackend) SuggestPrice(ctx context.Context) (*big.Int, error)

func (*EthAPIBackend) TxPoolContent

func (*EthAPIBackend) ValidatorTimeDrifts

func (b *EthAPIBackend) ValidatorTimeDrifts(ctx context.Context, epoch rpc.BlockNumber, maxEvents idx.Event) (map[idx.StakerID]map[hash.Event]time.Duration, error)

ValidatorTimeDrifts returns data to estimate time drift of each validator

type EvmStateReader

type EvmStateReader struct {
	*ServiceFeed
	// contains filtered or unexported fields
}

func (*EvmStateReader) CurrentBlock

func (r *EvmStateReader) CurrentBlock() *evmcore.EvmBlock

func (*EvmStateReader) CurrentHeader

func (r *EvmStateReader) CurrentHeader() *evmcore.EvmHeader

func (*EvmStateReader) GetBlock

func (r *EvmStateReader) GetBlock(h common.Hash, n uint64) *evmcore.EvmBlock

func (*EvmStateReader) GetDagBlock

func (r *EvmStateReader) GetDagBlock(h hash.Event, n idx.Block) *evmcore.EvmBlock

func (*EvmStateReader) GetDagHeader

func (r *EvmStateReader) GetDagHeader(h hash.Event, n idx.Block) *evmcore.EvmHeader

func (*EvmStateReader) GetHeader

func (r *EvmStateReader) GetHeader(h common.Hash, n uint64) *evmcore.EvmHeader

func (*EvmStateReader) MinGasPrice

func (r *EvmStateReader) MinGasPrice() *big.Int

func (*EvmStateReader) StateAt

func (r *EvmStateReader) StateAt(root common.Hash) (*state.StateDB, error)

type GasPowerCheckReader

type GasPowerCheckReader struct {
	Ctx atomic.Value
}

GasPowerCheckReader is a helper to run gas power check

func (*GasPowerCheckReader) GetValidationContext

func (r *GasPowerCheckReader) GetValidationContext() *gaspowercheck.ValidationContext

GetValidationContext returns current validation context for gaspowercheck

type GenesisMismatchError

type GenesisMismatchError struct {
	Stored, New hash.Event
}

GenesisMismatchError is raised when trying to overwrite an existing genesis block with an incompatible one.

func (*GenesisMismatchError) Error

func (e *GenesisMismatchError) Error() string

Error implements error interface.

type HeavyCheckReader

type HeavyCheckReader struct {
	Addrs atomic.Value
}

HeavyCheckReader is a helper to run heavy power checks

func (*HeavyCheckReader) GetEpochPubKeys

func (r *HeavyCheckReader) GetEpochPubKeys() (map[idx.StakerID]common.Address, idx.Epoch)

GetEpochPubKeys is safe for concurrent use

type HookedEngine

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

HookedEngine is a wrapper around any engine, which hooks ProcessEvent()

func (*HookedEngine) Bootstrap

func (hook *HookedEngine) Bootstrap(callbacks inter.ConsensusCallbacks)

Bootstrap restores poset's state from store.

func (*HookedEngine) GetConsensusTime

func (hook *HookedEngine) GetConsensusTime(id hash.Event) (inter.Timestamp, error)

GetConsensusTime calc consensus timestamp for given event, if event is confirmed.

func (*HookedEngine) GetEpoch

func (hook *HookedEngine) GetEpoch() idx.Epoch

GetEpoch returns current epoch num to 3rd party.

func (*HookedEngine) GetEpochValidators

func (hook *HookedEngine) GetEpochValidators() (*pos.Validators, idx.Epoch)

GetEpochValidators atomically returns validators of current epoch, and the epoch.

func (*HookedEngine) GetGenesisHash

func (hook *HookedEngine) GetGenesisHash() common.Hash

GetGenesisHash returns PrevEpochHash of first epoch.

func (*HookedEngine) GetValidators

func (hook *HookedEngine) GetValidators() *pos.Validators

GetValidators returns validators of current epoch.

func (*HookedEngine) GetVectorIndex

func (hook *HookedEngine) GetVectorIndex() *vector.Index

GetVectorIndex returns vector clock.

func (*HookedEngine) LastBlock

func (hook *HookedEngine) LastBlock() (idx.Block, hash.Event)

LastBlock returns current block.

func (*HookedEngine) Prepare

func (hook *HookedEngine) Prepare(e *inter.Event) *inter.Event

Prepare fills consensus-related fields: Frame, IsRoot, MedianTimestamp, PrevEpochHash, GasPowerLeft returns nil if event should be dropped

func (*HookedEngine) ProcessEvent

func (hook *HookedEngine) ProcessEvent(e *inter.Event) error

ProcessEvent takes event into processing. Event order matter: parents first. ProcessEvent is not safe for concurrent use

type NodeInfo

type NodeInfo struct {
	Network     uint64      `json:"network"` // network ID
	Genesis     common.Hash `json:"genesis"` // SHA3 hash of the host's genesis object
	Epoch       idx.Epoch   `json:"epoch"`
	NumOfBlocks idx.Block   `json:"blocks"`
}

NodeInfo represents a short summary of the sub-protocol metadata known about the host peer.

type PackInfo

type PackInfo struct {
	Index       idx.Pack
	Size        uint32
	NumOfEvents uint32
	Heads       hash.Events
}

type PeerInfo

type PeerInfo struct {
	Version     int       `json:"version"` // protocol version negotiated
	Epoch       idx.Epoch `json:"epoch"`
	NumOfBlocks idx.Block `json:"blocks"`
}

PeerInfo represents a short summary of the sub-protocol metadata known about a connected peer.

type PeerProgress

type PeerProgress struct {
	Epoch        idx.Epoch
	NumOfBlocks  idx.Block
	LastPackInfo PackInfo
	LastBlock    hash.Event
}

PeerProgress is synchronization status of a peer

func (*PeerProgress) Less

func (a *PeerProgress) Less(b PeerProgress) bool

type ProtocolConfig

type ProtocolConfig struct {
	LatencyImportance    int
	ThroughputImportance int
}

ProtocolConfig is config for p2p protocol

type ProtocolManager

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

func NewProtocolManager

func NewProtocolManager(
	config *Config,
	notifier dagNotifier,
	txpool txPool,
	engineMu *sync.RWMutex,
	checkers *eventcheck.Checkers,
	s *Store,
	engine Consensus,
	serverPool *serverPool,
	isMigration func() bool,
) (
	*ProtocolManager,
	error,
)

NewProtocolManager returns a new Fantom sub protocol manager. The Fantom sub protocol manages peers capable with the Fantom network.

func (*ProtocolManager) BroadcastEvent

func (pm *ProtocolManager) BroadcastEvent(event *inter.Event, passed time.Duration) int

BroadcastEvent will either propagate a event to a subset of it's peers, or will only announce it's availability (depending what's requested).

func (*ProtocolManager) BroadcastTxs

func (pm *ProtocolManager) BroadcastTxs(txs types.Transactions)

BroadcastTxs will propagate a batch of transactions to all peers which are not known to already have the given transaction.

func (*ProtocolManager) NodeInfo

func (pm *ProtocolManager) NodeInfo() *NodeInfo

NodeInfo retrieves some protocol metadata about the running host node.

func (*ProtocolManager) Start

func (pm *ProtocolManager) Start(maxPeers int)

func (*ProtocolManager) Stop

func (pm *ProtocolManager) Stop()

type PublicEthereumAPI

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

PublicEthereumAPI provides an API to access Ethereum-like information. It is a github.com/ethereum/go-ethereum/eth simulation for console.

func NewPublicEthereumAPI

func NewPublicEthereumAPI(s *Service) *PublicEthereumAPI

NewPublicEthereumAPI creates a new Ethereum protocol API for gossip.

func (*PublicEthereumAPI) ChainId

func (api *PublicEthereumAPI) ChainId() hexutil.Uint64

ChainId is the EIP-155 replay-protection chain id for the current ethereum chain config.

func (*PublicEthereumAPI) Coinbase

func (api *PublicEthereumAPI) Coinbase() (common.Address, error)

Coinbase is the validator address

func (*PublicEthereumAPI) Etherbase

func (api *PublicEthereumAPI) Etherbase() (common.Address, error)

Etherbase is the validator address

func (*PublicEthereumAPI) Hashrate

func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64

Hashrate returns the POW hashrate

func (*PublicEthereumAPI) Validator

func (api *PublicEthereumAPI) Validator() (common.Address, error)

Validator is the validator address

type Service

type Service struct {
	Name  string
	Topic discv5.Topic

	EthAPI *EthAPIBackend

	logger.Instance
	// contains filtered or unexported fields
}

Service implements go-ethereum/node.Service interface.

func NewService

func NewService(stack *node.Node, config *Config, store *Store, engine Consensus) (*Service, error)

func (*Service) APIs

func (s *Service) APIs() []rpc.API

APIs returns api methods the service wants to expose on rpc channels.

func (*Service) AccountManager

func (s *Service) AccountManager() *accounts.Manager

AccountManager return node's account manager

func (*Service) Emitter

func (s *Service) Emitter() *Emitter

func (*Service) GetActiveSfcStakers

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

GetActiveSfcStakers returns stakers which will become validators in next epoch

func (*Service) GetEngine

func (s *Service) GetEngine() Consensus

GetEngine returns service's engine

func (*Service) GetEvmStateReader

func (s *Service) GetEvmStateReader() *EvmStateReader

func (*Service) IsMigration

func (s *Service) IsMigration() bool

func (*Service) MinGasPrice

func (s *Service) MinGasPrice() *big.Int

func (*Service) ProcessEvent

func (s *Service) ProcessEvent(e *inter.Event) error

ProcessEvent takes event into processing. Event order matter: parents first. ProcessEvent is safe for concurrent use

func (*Service) Protocols

func (s *Service) Protocols() []p2p.Protocol

Protocols returns protocols the service can communicate on.

func (*Service) Start

func (s *Service) Start() error

Start method invoked when the node is ready to start the service.

func (*Service) Stop

func (s *Service) Stop() error

Stop method invoked when the node terminates the service.

func (*Service) UpdateAddressPOI

func (s *Service) UpdateAddressPOI(address common.Address, senderTotalFee *big.Int, poiPeriod uint64)

UpdateAddressPOI calculate and save POI for user

func (*Service) UpdateStakerPOI

func (s *Service) UpdateStakerPOI(stakerID idx.StakerID, stakerAddress common.Address, poiPeriod uint64)

UpdateStakerPOI calculate and save POI for staker

func (*Service) ValidateEvent

func (s *Service) ValidateEvent(e *inter.Event) error

ValidateEvent runs all the checkers for an event

type ServiceFeed

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

func (*ServiceFeed) SubscribeNewBlock

func (f *ServiceFeed) SubscribeNewBlock(ch chan<- evmcore.ChainHeadNotify) notify.Subscription

func (*ServiceFeed) SubscribeNewEmitted

func (f *ServiceFeed) SubscribeNewEmitted(ch chan<- *inter.Event) notify.Subscription

func (*ServiceFeed) SubscribeNewEpoch

func (f *ServiceFeed) SubscribeNewEpoch(ch chan<- idx.Epoch) notify.Subscription

func (*ServiceFeed) SubscribeNewLogs

func (f *ServiceFeed) SubscribeNewLogs(ch chan<- []*types.Log) notify.Subscription

func (*ServiceFeed) SubscribeNewPack

func (f *ServiceFeed) SubscribeNewPack(ch chan<- idx.Pack) notify.Subscription

func (*ServiceFeed) SubscribeNewTxs

func (f *ServiceFeed) SubscribeNewTxs(ch chan<- core.NewTxsEvent) notify.Subscription

type Store

type Store struct {
	EpochDbs *temporary.Dbs

	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, appCfg app.StoreConfig) *Store

NewStore creates store over key-value db.

func (*Store) AddHead

func (s *Store) AddHead(epoch idx.Epoch, id hash.Event)

func (*Store) AddLastHeader

func (s *Store) AddLastHeader(epoch idx.Epoch, header *inter.EventHeaderData)

AddLastHeader adds/updates a records about last header from a validator

func (*Store) AddToPack

func (s *Store) AddToPack(epoch idx.Epoch, idx idx.Pack, e hash.Event)

func (*Store) App

func (s *Store) App() *app.Store

func (*Store) ApplyGenesis

func (s *Store) ApplyGenesis(net *lachesis.Config) (genesisAtropos hash.Event, genesisState common.Hash, new bool, err error)

ApplyGenesis writes initial state.

func (*Store) Close

func (s *Store) Close()

Close leaves underlying database.

func (*Store) Commit

func (s *Store) Commit(flushID []byte, immediately bool) error

Commit changes.

func (*Store) DelEventHeader

func (s *Store) DelEventHeader(epoch idx.Epoch, h hash.Event)

DelEventHeader removes stored event header.

func (*Store) DelHead

func (s *Store) DelHead(epoch idx.Epoch, id hash.Event)

func (*Store) DelLastHeader

func (s *Store) DelLastHeader(epoch idx.Epoch, creator idx.StakerID)

DelLastHeader deletes record about last header from a validator

func (*Store) DelLastHeaders

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

DelLastHeaders deletes all the records about last headers

func (*Store) DeleteEvent

func (s *Store) DeleteEvent(epoch idx.Epoch, id hash.Event)

DeleteEvent deletes event.

func (*Store) FindEventHashes

func (s *Store) FindEventHashes(epoch idx.Epoch, lamport idx.Lamport, hashPrefix []byte) hash.Events

func (*Store) ForEachBlock

func (s *Store) ForEachBlock(fn func(index idx.Block, block *inter.Block))

func (*Store) ForEachEpochEvent

func (s *Store) ForEachEpochEvent(epoch idx.Epoch, onEvent func(event *inter.Event) bool)

func (*Store) ForEachEvent

func (s *Store) ForEachEvent(start idx.Epoch, onEvent func(event *inter.Event) bool)

func (*Store) ForEachEventRLP

func (s *Store) ForEachEventRLP(start idx.Epoch, onEvent func(key hash.Event, event rlp.RawValue) bool)

func (*Store) GetBlock

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

GetBlock returns stored block.

func (*Store) GetBlockByHash

func (s *Store) GetBlockByHash(id hash.Event) *inter.Block

GetBlockByHash get block by block hash

func (*Store) GetBlockDecidedBy

func (s *Store) GetBlockDecidedBy(block idx.Block) hash.Event

GetBlockDecidedBy get event which decided block (off-chain data)

func (*Store) GetBlockIndex

func (s *Store) GetBlockIndex(id hash.Event) *idx.Block

GetBlockIndex returns stored block index.

func (*Store) GetBlockTransactions

func (s *Store) GetBlockTransactions(block *inter.Block) types.Transactions

func (*Store) GetDirtyEpochStats

func (s *Store) GetDirtyEpochStats() *sfctype.EpochStats

GetDirtyEpochStats returns EpochStats for current (not sealed) epoch

func (*Store) GetEpochStats

func (s *Store) GetEpochStats(epoch idx.Epoch) *sfctype.EpochStats

GetEpochStats returns EpochStats for an already sealed epoch

func (*Store) GetEvent

func (s *Store) GetEvent(id hash.Event) *inter.Event

GetEvent returns stored event.

func (*Store) GetEventHeader

func (s *Store) GetEventHeader(epoch idx.Epoch, h hash.Event) *inter.EventHeaderData

GetEventHeader returns stored event header.

func (*Store) GetEventRLP

func (s *Store) GetEventRLP(id hash.Event) rlp.RawValue

GetEventRLP returns stored event. Serialized.

func (*Store) GetEventReceivingTime

func (s *Store) GetEventReceivingTime(e hash.Event) inter.Timestamp

GetEventReceivingTime get local event time (off-chain data)

func (*Store) GetHeads

func (s *Store) GetHeads(epoch idx.Epoch) hash.Events

GetHeads returns IDs of all the epoch events with no descendants

func (*Store) GetHighestLamport

func (s *Store) GetHighestLamport() idx.Lamport

func (*Store) GetLastEvent

func (s *Store) GetLastEvent(epoch idx.Epoch, from idx.StakerID) *hash.Event

GetLastEvent returns stored last unconfirmed event from a validator (off-chain)

func (*Store) GetLastHeaders

func (s *Store) GetLastHeaders(epoch idx.Epoch) inter.HeadersByCreator

GetLastHeaders retrieves all the records about last headers from validators

func (*Store) GetNetworkVersion

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

GetNetworkVersion returns stored network version.

func (*Store) GetNonSupportedUpgrade

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

GetNonSupportedUpgrade returns stored non-supported network upgrade.

func (*Store) GetPack

func (s *Store) GetPack(epoch idx.Epoch, idx idx.Pack) hash.Events

func (*Store) GetPackInfo

func (s *Store) GetPackInfo(epoch idx.Epoch, idx idx.Pack) *PackInfo

func (*Store) GetPackInfoOrDefault

func (s *Store) GetPackInfoOrDefault(epoch idx.Epoch, idx idx.Pack) PackInfo

returns default value if not found

func (*Store) GetPackInfoRLP

func (s *Store) GetPackInfoRLP(epoch idx.Epoch, idx idx.Pack) rlp.RawValue

func (*Store) GetPacksNum

func (s *Store) GetPacksNum(epoch idx.Epoch) (idx.Pack, bool)

func (*Store) GetPacksNumOrDefault

func (s *Store) GetPacksNumOrDefault(epoch idx.Epoch) idx.Pack

func (*Store) GetTxPosition

func (s *Store) GetTxPosition(txid common.Hash) *TxPosition

GetTxPosition returns stored transaction block and position.

func (*Store) HasEvent

func (s *Store) HasEvent(h hash.Event) bool

HasEvent returns true if event exists.

func (*Store) HasEventHeader

func (s *Store) HasEventHeader(h hash.Event) bool

HasEvent returns true if event exists.

func (*Store) IsHead

func (s *Store) IsHead(epoch idx.Epoch, id hash.Event) bool

func (*Store) Migrate

func (s *Store) Migrate() error

func (*Store) SetBlock

func (s *Store) SetBlock(b *inter.Block)

SetBlock stores chain block.

func (*Store) SetBlockDecidedBy

func (s *Store) SetBlockDecidedBy(block idx.Block, event hash.Event)

SetBlockDecidedBy stores event which decided block (off-chain data)

func (*Store) SetBlockIndex

func (s *Store) SetBlockIndex(id hash.Event, n idx.Block)

SetBlockIndex stores chain block index.

func (*Store) SetDirtyEpochStats

func (s *Store) SetDirtyEpochStats(value *sfctype.EpochStats)

SetDirtyEpochStats set EpochStats for current (not sealed) epoch

func (*Store) SetEpochStats

func (s *Store) SetEpochStats(epoch idx.Epoch, value *sfctype.EpochStats)

SetEpochStats set EpochStats for an already sealed epoch

func (*Store) SetEvent

func (s *Store) SetEvent(e *inter.Event)

SetEvent stores event.

func (*Store) SetEventHeader

func (s *Store) SetEventHeader(epoch idx.Epoch, h hash.Event, e *inter.EventHeaderData)

SetEventHeader returns stored event header.

func (*Store) SetEventReceivingTime

func (s *Store) SetEventReceivingTime(e hash.Event, time inter.Timestamp)

SetEventReceivingTime stores local event time (off-chain data)

func (*Store) SetHighestLamport

func (s *Store) SetHighestLamport(lamport idx.Lamport)

func (*Store) SetLastEvent

func (s *Store) SetLastEvent(epoch idx.Epoch, from idx.StakerID, id hash.Event)

SetLastEvent stores last unconfirmed event from a validator (off-chain)

func (*Store) SetNetworkVersion

func (s *Store) SetNetworkVersion(v *big.Int)

SetNetworkVersion stores network version.

func (*Store) SetNonSupportedUpgrade

func (s *Store) SetNonSupportedUpgrade(v *big.Int)

SetNonSupportedUpgrade stores non-supported network upgrade.

func (*Store) SetPackInfo

func (s *Store) SetPackInfo(epoch idx.Epoch, idx idx.Pack, value PackInfo)

func (*Store) SetPacksNum

func (s *Store) SetPacksNum(epoch idx.Epoch, num idx.Pack)

func (*Store) SetTxPosition

func (s *Store) SetTxPosition(txid common.Hash, position *TxPosition)

SetTxPosition stores transaction block and position.

type StoreConfig

type StoreConfig struct {
	// Cache size for Events.
	EventsCacheSize int
	// Cache size for EventHeaderData (Epoch db).
	EventsHeadersCacheSize int
	// Cache size for Block.
	BlockCacheSize int
	// Cache size for PackInfos.
	PackInfosCacheSize int
	// Cache size for TxPositions.
	TxPositionsCacheSize int
	// Cache size for EpochStats.
	EpochStatsCacheSize int

	// NOTE: fields for config-file back compatibility
	// Cache size for Receipts.
	ReceiptsCacheSize int
	// Cache size for Stakers.
	StakersCacheSize int
	// Cache size for Delegations.
	DelegationsCacheSize 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
	EventOffset uint32
	BlockOffset uint32
}

type Txs

type Txs struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTxs

func NewTxs() *Txs

func (*Txs) Finish

func (d *Txs) Finish(tx common.Hash) (latency time.Duration, err error)

func (*Txs) Start

func (d *Txs) Start(tx common.Hash)

type UpgradeConfig

type UpgradeConfig struct {
	ShutDownIfNotUpgraded bool // shut down the node in a case of non-supported network upgrade
	WarningIfNotUpgraded  bool // show a warning in a case of non-supported network upgrade
}

UpgradeConfig defines behaviour for network upgrades

type ValidatorsPubKeys

type ValidatorsPubKeys struct {
	Epoch     idx.Epoch
	Addresses map[idx.StakerID]common.Address
}

ValidatorsPubKeys stores info to authenticate validators

func ReadEpochPubKeys

func ReadEpochPubKeys(a *app.Store, epoch idx.Epoch) *ValidatorsPubKeys

ReadEpochPubKeys is the same as GetEpochValidators, but returns only addresses

Directories

Path Synopsis
Package filters implements an ethereum filtering system for block, transactions and log events.
Package filters implements an ethereum filtering system for block, transactions and log events.

Jump to

Keyboard shortcuts

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