{"modulePath":"github.com/eric-erki/https-hyperledger.org","version":"v1.4.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package state\n\n## Constants\n\n```go\nconst (\n\tDefAntiEntropyInterval             = 10 * time.Second\n\tDefAntiEntropyStateResponseTimeout = 3 * time.Second\n\tDefAntiEntropyBatchSize            = 10\n\n\tDefChannelBufferSize     = 100\n\tDefAntiEntropyMaxRetries = 3\n\n\tDefMaxBlockDistance = 100\n\n\tBlocking    = true\n\tNonBlocking = false\n)\n```\n\n## Types\n\n```go\ntype Configuration struct {\n\tAntiEntropyInterval             time.Duration\n\tAntiEntropyStateResponseTimeout time.Duration\n\tAntiEntropyBatchSize            uint64\n\tMaxBlockDistance                int\n\tAntiEntropyMaxRetries           int\n\tChannelBufferSize               int\n\tEnableStateTransfer             bool\n\tBlockingMode                    bool\n}\n```\nConfiguration keeps state transfer configuration parameters\n\n```go\ntype GossipAdapter interface {\n\t// Send sends a message to remote peers\n\tSend(msg *proto.GossipMessage, peers ...*comm.RemotePeer)\n\n\t// Accept returns a dedicated read-only channel for messages sent by other nodes that match a certain predicate.\n\t// If passThrough is false, the messages are processed by the gossip layer beforehand.\n\t// If passThrough is true, the gossip layer doesn't intervene and the messages\n\t// can be used to send a reply back to the sender\n\tAccept(acceptor common2.MessageAcceptor, passThrough bool) (\u003c-chan *proto.GossipMessage, \u003c-chan proto.ReceivedMessage)\n\n\t// UpdateLedgerHeight updates the ledger height the peer\n\t// publishes to other peers in the channel\n\tUpdateLedgerHeight(height uint64, chainID common2.ChainID)\n\n\t// PeersOfChannel returns the NetworkMembers considered alive\n\t// and also subscribed to the channel given\n\tPeersOfChannel(common2.ChainID) []discovery.NetworkMember\n}\n```\nGossipAdapter defines gossip/communication required interface for state provider\n\n```go\ntype GossipStateProvider interface {\n\tAddPayload(payload *proto.Payload) error\n\n\t// Stop terminates state transfer object\n\tStop()\n}\n```\nGossipStateProvider is the interface to acquire sequences of the ledger blocks capable to full fill missing blocks by running state replication and sending request to get missing block to other nodes\n\n```go\nfunc NewGossipStateProvider(chainID string, services *ServicesMediator, ledger ledgerResources, stateMetrics *metrics.StateMetrics, config *Configuration) GossipStateProvider\n```\nNewGossipStateProvider creates state provider with coordinator instance to orchestrate arrival of private rwsets and blocks before committing them into the ledger.\n\n```go\ntype GossipStateProviderImpl struct {\n\t// contains filtered or unexported fields\n}\n```\nGossipStateProviderImpl the implementation of the GossipStateProvider interface the struct to handle in memory sliding window of new ledger block to be acquired by hyper ledger\n\n```go\nfunc (s *GossipStateProviderImpl) AddPayload(payload *proto.Payload) error\n```\nAddPayload adds new payload into state.\n\n```go\nfunc (s *GossipStateProviderImpl) Stop()\n```\nStop function sends halting signal to all go routines\n\n```go\ntype MCSAdapter interface {\n\t// VerifyBlock returns nil if the block is properly signed, and the claimed seqNum is the\n\t// sequence number that the block's header contains.\n\t// else returns error\n\tVerifyBlock(chainID common2.ChainID, seqNum uint64, signedBlock []byte) error\n\n\t// VerifyByChannel checks that signature is a valid signature of message\n\t// under a peer's verification key, but also in the context of a specific channel.\n\t// If the verification succeeded, Verify returns nil meaning no error occurred.\n\t// If peerIdentity is nil, then the verification fails.\n\tVerifyByChannel(chainID common2.ChainID, peerIdentity api.PeerIdentityType, signature, message []byte) error\n}\n```\nMCSAdapter adapter of message crypto service interface to bound specific APIs required by state transfer service\n\n```go\ntype PayloadsBuffer interface {\n\t// Adds new block into the buffer\n\tPush(payload *proto.Payload)\n\n\t// Returns next expected sequence number\n\tNext() uint64\n\n\t// Remove and return payload with given sequence number\n\tPop() *proto.Payload\n\n\t// Get current buffer size\n\tSize() int\n\n\t// Channel to indicate event when new payload pushed with sequence\n\t// number equal to the next expected value.\n\tReady() chan struct{}\n\n\tClose()\n}\n```\nPayloadsBuffer is used to store payloads into which used to support payloads with blocks reordering according to the sequence numbers. It also will provide the capability to signal whenever expected block has arrived.\n\n```go\nfunc NewPayloadsBuffer(next uint64) PayloadsBuffer\n```\nNewPayloadsBuffer is factory function to create new payloads buffer\n\n```go\ntype PayloadsBufferImpl struct {\n\t// contains filtered or unexported fields\n}\n```\nPayloadsBufferImpl structure to implement PayloadsBuffer interface store inner state of available payloads and sequence numbers\n\n```go\nfunc (b *PayloadsBufferImpl) Close()\n```\nClose cleanups resources and channels in maintained\n\n```go\nfunc (b *PayloadsBufferImpl) Next() uint64\n```\nNext function provides the number of the next expected block\n\n```go\nfunc (b *PayloadsBufferImpl) Pop() *proto.Payload\n```\nPop function extracts the payload according to the next expected block number, if no next block arrived yet, function returns nil.\n\n```go\nfunc (b *PayloadsBufferImpl) Push(payload *proto.Payload)\n```\nPush new payload into the buffer structure in case new arrived payload sequence number is below the expected next block number payload will be thrown away. TODO return bool to indicate if payload was added or not, so that caller can log result.\n\n```go\nfunc (b *PayloadsBufferImpl) Ready() chan struct{}\n```\nReady function returns the channel which indicates whenever expected next block has arrived and one could safely pop out next sequence of blocks\n\n```go\nfunc (b *PayloadsBufferImpl) Size() int\n```\nSize returns current number of payloads stored within buffer\n\n```go\ntype ServicesMediator struct {\n\tGossipAdapter\n\tMCSAdapter\n}\n```\nServicesMediator aggregated adapter to compound all mediator required by state transfer into single struct\n\n","path":"github.com/eric-erki/https-hyperledger.org/gossip/state","name":"state","synopsis":"","isRedistributable":true}
