sync

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Namespace = "spacemesh"
	Subsystem = "consensus"
)
View Source
const (
	IDLE       uint32             = 0
	RUNNING    uint32             = 1
	BLOCK      server.MessageType = 1
	LAYER_HASH server.MessageType = 2
	LAYER_IDS  server.MessageType = 3
	TX         server.MessageType = 4
	ATX        server.MessageType = 5
	POET       server.MessageType = 6
)
View Source
const (
	ValidationCacheSize = 1000
)

Variables

View Source
var (
	BlockFetchReqFactory = newFetchReqFactory(BLOCK, blocksAsItems)
	TxFetchReqFactory    = newFetchReqFactory(TX, txsAsItems)
	AtxFetchReqFactory   = newFetchReqFactory(ATX, atxsAsItems)
)

Functions

func ConfigTst

func ConfigTst() mesh.Config

func NewAtxQueue

func NewAtxQueue(s *Syncer, fetchPoetProof FetchPoetProofFunc) *atxQueue

func NewFetchWorker

func NewFetchWorker(s WorkerInfra, count int, reqFactory BatchRequestFactory, idsChan chan []types.Hash32, name string) worker

func NewNeighborhoodWorker

func NewNeighborhoodWorker(s WorkerInfra, count int, reqFactory RequestFactory) worker

func NewPeersWorker

func NewPeersWorker(s WorkerInfra, peers []p2p.Peer, mu *sync.Once, reqFactory RequestFactory) worker

func NewTxQueue

func NewTxQueue(s *Syncer) *txQueue

func NewValidationQueue

func NewValidationQueue(srvr WorkerInfra, conf Configuration, msh ValidationInfra, checkLocal CheckLocalFunc, lg log.Log) *blockQueue

Types

type AtxMemPool

type AtxMemPool interface {
	Get(id types.AtxId) (*types.ActivationTx, error)
	Put(atx *types.ActivationTx)
}

type BatchRequestFactory

type BatchRequestFactory func(s WorkerInfra, peer p2p.Peer, id []types.Hash32) (chan []Item, error)

type BlockEligibilityValidatorMock

type BlockEligibilityValidatorMock struct {
}

func (BlockEligibilityValidatorMock) BlockSignedAndEligible

func (BlockEligibilityValidatorMock) BlockSignedAndEligible(block *types.Block) (bool, error)

type BlockListener

type BlockListener struct {
	*Syncer
	BlockValidator
	log.Log
	// contains filtered or unexported fields
}

func NewBlockListener

func NewBlockListener(net service.Service, sync *Syncer, concurrency int, logger log.Log) *BlockListener

func (*BlockListener) Close

func (bl *BlockListener) Close()

func (BlockListener) GetExit

func (ms BlockListener) GetExit() chan struct{}

func (BlockListener) GetTimeout

func (ms BlockListener) GetTimeout() time.Duration

func (*BlockListener) ListenToGossipBlocks

func (bl *BlockListener) ListenToGossipBlocks()

func (*BlockListener) Start

func (bl *BlockListener) Start()

type BlockValidator

type BlockValidator interface {
	BlockSignedAndEligible(block *types.Block) (bool, error)
}

type CheckLocalFunc

type CheckLocalFunc func(ids []types.Hash32) (map[types.Hash32]Item, map[types.Hash32]Item, []types.Hash32)

type Configuration

type Configuration struct {
	LayersPerEpoch uint16
	Concurrency    int //number of workers for sync method
	LayerSize      int
	RequestTimeout time.Duration
	AtxsLimit      int
	Hdist          int
}

type EligibilityValidator

type EligibilityValidator interface {
	BlockSignedAndEligible(block *types.Block) (bool, error)
}

type FetchPoetProofFunc

type FetchPoetProofFunc func(poetProofRef []byte) error

type ForBlockInView

type ForBlockInView func(view map[types.BlockID]struct{}, layer types.LayerID, blockHandler func(block *types.Block) (bool, error)) error

type Item

type Item interface {
	Hash32() types.Hash32
	ShortString() string
}

type LayerProvider

type LayerProvider interface {
	GetLayer(index types.LayerID) (*types.Layer, error)
}

type LayerValidator

type LayerValidator interface {
	ProcessedLayer() types.LayerID
	ValidateLayer(lyr *types.Layer)
}

type MeshValidatorMock

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

func (*MeshValidatorMock) ContextualValidity

func (mlg *MeshValidatorMock) ContextualValidity(id types.BlockID) bool

func (*MeshValidatorMock) GetGoodPatternBlocks

func (m *MeshValidatorMock) GetGoodPatternBlocks(layer types.LayerID) (map[types.BlockID]struct{}, error)

func (*MeshValidatorMock) HandleIncomingLayer

func (m *MeshValidatorMock) HandleIncomingLayer(lyr *types.Layer) (types.LayerID, types.LayerID)

func (*MeshValidatorMock) HandleLateBlock

func (m *MeshValidatorMock) HandleLateBlock(bl *types.Block) (types.LayerID, types.LayerID)

func (*MeshValidatorMock) LatestComplete

func (m *MeshValidatorMock) LatestComplete() types.LayerID

func (*MeshValidatorMock) PersistTortoise

func (m *MeshValidatorMock) PersistTortoise() error

func (*MeshValidatorMock) RegisterLayerCallback

func (m *MeshValidatorMock) RegisterLayerCallback(func(id types.LayerID))

type MockAtxMemPool

type MockAtxMemPool struct{}

func (MockAtxMemPool) Get

func (MockAtxMemPool) GetAllItems

func (MockAtxMemPool) GetAllItems() []types.ActivationTx

func (MockAtxMemPool) Invalidate

func (MockAtxMemPool) Invalidate(id types.AtxId)

func (MockAtxMemPool) Put

func (MockAtxMemPool) Put(atx *types.ActivationTx)

type MockClock

type MockClock struct {
	Interval duration.Duration
	Layer    types.LayerID
	// contains filtered or unexported fields
}

func (*MockClock) GetCurrentLayer

func (c *MockClock) GetCurrentLayer() types.LayerID

func (*MockClock) Subscribe

func (c *MockClock) Subscribe() timesync.LayerTimer

func (*MockClock) Tick

func (c *MockClock) Tick()

func (*MockClock) Unsubscribe

func (c *MockClock) Unsubscribe(timer timesync.LayerTimer)

type MockIStore

type MockIStore struct {
}

func (*MockIStore) GetIdentity

func (*MockIStore) GetIdentity(id string) (types.NodeId, error)

func (*MockIStore) StoreNodeIdentity

func (*MockIStore) StoreNodeIdentity(id types.NodeId) error

type MockState

type MockState struct{}

func (MockState) AddressExists

func (MockState) AddressExists(addr types.Address) bool

func (MockState) ApplyRewards

func (MockState) ApplyRewards(layer types.LayerID, miners []types.Address, reward *big.Int)

func (MockState) ApplyTransactions

func (MockState) ApplyTransactions(layer types.LayerID, txs []*types.Transaction) (int, error)

func (MockState) GetLayerApplied

func (MockState) GetLayerApplied(txId types.TransactionId) *types.LayerID

func (MockState) GetStateRoot

func (s MockState) GetStateRoot() types.Hash32

func (MockState) LoadState

func (s MockState) LoadState(layer types.LayerID) error

func (MockState) ValidateNonceAndBalance

func (MockState) ValidateNonceAndBalance(transaction *types.Transaction) error

func (MockState) ValidateSignature

func (MockState) ValidateSignature(signed types.Signed) (types.Address, error)

type MockTxMemPool

type MockTxMemPool struct{}

func (MockTxMemPool) Get

func (MockTxMemPool) GetAllItems

func (MockTxMemPool) GetAllItems() []*types.Transaction

func (MockTxMemPool) Invalidate

func (MockTxMemPool) Invalidate(id types.TransactionId)

func (MockTxMemPool) Put

type Peers

type Peers interface {
	GetPeers() []p2p.Peer
	Close()
}

type PoetDb

type PoetDb interface {
	HasProof(proofRef []byte) bool
	ValidateAndStore(proofMessage *types.PoetProofMessage) error
	GetProofMessage(proofRef []byte) ([]byte, error)
}

type PoetDbMock

type PoetDbMock struct{}

func (*PoetDbMock) GetMembershipMap

func (*PoetDbMock) GetMembershipMap(poetRoot []byte) (map[types.Hash32]bool, error)

func (PoetDbMock) GetProofMessage

func (PoetDbMock) GetProofMessage(proofRef []byte) ([]byte, error)

func (PoetDbMock) HasProof

func (PoetDbMock) HasProof(proofRef []byte) bool

func (*PoetDbMock) SubscribeToProofRef

func (*PoetDbMock) SubscribeToProofRef(poetId []byte, roundId string) chan []byte

func (PoetDbMock) ValidateAndStore

func (PoetDbMock) ValidateAndStore(proofMessage *types.PoetProofMessage) error

type RequestFactory

type RequestFactory func(s WorkerInfra, peer p2p.Peer) (chan interface{}, error)

func HashReqFactory

func HashReqFactory(lyr types.LayerID) RequestFactory

func LayerIdsReqFactory

func LayerIdsReqFactory(lyr types.LayerID) RequestFactory

func PoetReqFactory

func PoetReqFactory(poetProofRef []byte) RequestFactory

type SValidateAtxFunc

type SValidateAtxFunc func(atx *types.ActivationTx) error

type StateMock

type StateMock struct{}

func (*StateMock) ApplyRewards

func (s *StateMock) ApplyRewards(layer types.LayerID, miners []string, underQuota map[string]int, bonusReward, diminishedReward *big.Int)

func (*StateMock) ApplyTransactions

func (s *StateMock) ApplyTransactions(id types.LayerID, tx []*types.Transaction) (uint32, error)

type Status

type Status int
const (
	Pending    Status = 0
	InProgress Status = 1
	Done       Status = 2

	ValidatingLayerNone types.LayerID = 0
)

type Syncer

type Syncer struct {
	Configuration
	log.Log
	*mesh.Mesh
	EligibilityValidator

	TickProvider

	SyncLock uint32

	LayerCh timesync.LayerTimer
	// contains filtered or unexported fields
}

func NewSync

func NewSync(srv service.Service, layers *mesh.Mesh, txpool TxMemPool, atxpool AtxMemPool, bv BlockValidator, poetdb PoetDb, conf Configuration, clock TickProvider, logger log.Log) *Syncer

fires a sync every sm.syncInterval or on force space from outside

func (*Syncer) Await

func (s *Syncer) Await() chan struct{}

func (*Syncer) Close

func (s *Syncer) Close()

func (*Syncer) DataAvailability

func (s *Syncer) DataAvailability(blk *types.Block) ([]*types.Transaction, []*types.ActivationTx, error)

func (*Syncer) FetchPoetProof

func (s *Syncer) FetchPoetProof(poetProofRef []byte) error

func (*Syncer) ForceSync

func (s *Syncer) ForceSync()

func (*Syncer) GetAndValidateLayer

func (s *Syncer) GetAndValidateLayer(id types.LayerID) error

func (Syncer) GetExit

func (ms Syncer) GetExit() chan struct{}

func (Syncer) GetTimeout

func (ms Syncer) GetTimeout() time.Duration

func (*Syncer) IsSynced

func (s *Syncer) IsSynced() bool

func (*Syncer) ListenToGossip

func (s *Syncer) ListenToGossip() bool

api for other modules to check if they should listen to gossip

func (*Syncer) Start

func (s *Syncer) Start()

func (*Syncer) Synchronise

func (s *Syncer) Synchronise()

func (*Syncer) ValidatingLayer

func (s *Syncer) ValidatingLayer() types.LayerID

type SyntacticValidatorMock

type SyntacticValidatorMock struct {
}

func (SyntacticValidatorMock) SyntacticallyValid

func (SyntacticValidatorMock) SyntacticallyValid(block *types.BlockHeader) (bool, error)

type TickProvider

type TickProvider interface {
	Subscribe() timesync.LayerTimer
	Unsubscribe(timer timesync.LayerTimer)
	GetCurrentLayer() types.LayerID
}

type TxMemPool

type TxMemPool interface {
	Get(id types.TransactionId) (*types.Transaction, error)
	Put(id types.TransactionId, item *types.Transaction)
}

type TxValidator

type TxValidator interface {
	AddressExists(addr types.Address) bool
}

type ValidationInfra

type ValidationInfra interface {
	DataAvailability(blk *types.Block) ([]*types.Transaction, []*types.ActivationTx, error)
	AddBlockWithTxs(blk *types.Block, txs []*types.Transaction, atxs []*types.ActivationTx) error
	GetBlock(id types.BlockID) (*types.Block, error)
	ForBlockInView(view map[types.BlockID]struct{}, layer types.LayerID, blockHandler func(block *types.Block) (bool, error)) error

	HandleLateBlock(bl *types.Block)
	ValidatingLayer() types.LayerID
	ProcessedLayer() types.LayerID
	// contains filtered or unexported methods
}

type ValidatorMock

type ValidatorMock struct{}

func (*ValidatorMock) Validate

func (*ValidatorMock) Validate(id signing.PublicKey, nipst *types.NIPST, expectedChallenge types.Hash32) error

func (*ValidatorMock) VerifyPost

func (*ValidatorMock) VerifyPost(id signing.PublicKey, proof *types.PostProof, space uint64) error

type WorkerInfra

type WorkerInfra interface {
	GetPeers() []p2p.Peer
	SendRequest(msgType server.MessageType, payload []byte, address p2pcrypto.PublicKey, resHandler func(msg []byte)) error
	GetTimeout() time.Duration
	GetExit() chan struct{}
	log.Logger
}

Jump to

Keyboard shortcuts

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