blockchain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2017 License: AGPL-3.0 Imports: 47 Imported by: 0

Documentation

Overview

MemStore is a Store implementation that keeps all blockchain state in memory.

It is used in tests to avoid needing a database.

Index

Constants

View Source
const (
	// BlockchainChannel is a channel for blocks and status updates (`BlockStore` height)
	BlockchainChannel = byte(0x40)
)

Variables

View Source
var ErrNoTLS = errors.New("no TLS configuration available")

Functions

func HomeDirFromEnvironment

func HomeDirFromEnvironment() string

HomeDirFromEnvironment returns the directory to use for reading config and storing variable data. It returns $BYTOM_HOME, or, if that is empty, $HOME/.chaincore.

func TLSConfig

func TLSConfig(certFile, keyFile, rootCAs string) (*tls.Config, error)

TLSConfig returns a TLS config suitable for use as a bytom client and server. It reads a PEM-encoded X.509 certificate and private key from certFile and keyFile. If rootCAs is given, it should name a file containing a list of trusted root CA certs, otherwise the returned config uses the system cert pool.

For compatibility, it attempts to read the cert and key from the environment if certFile and keyFile both do not exist in the filesystem.

TLSCRT=[PEM-encoded X.509 certificate]
TLSKEY=[PEM-encoded X.509 private key]

If certFile and keyFile do not exist or are empty and the environment vars are both unset, TLSConfig returns ErrNoTLS.

Types

type BlockPool

type BlockPool struct {
	BaseService
	// contains filtered or unexported fields
}

func NewBlockPool

func NewBlockPool(start uint64, requestsCh chan<- BlockRequest, timeoutsCh chan<- string) *BlockPool

func (*BlockPool) AddBlock

func (pool *BlockPool) AddBlock(peerID string, block *legacy.Block, blockSize int)

TODO: ensure that blocks come in order for each peer.

func (*BlockPool) GetStatus

func (pool *BlockPool) GetStatus() (height uint64, numPending int32, lenRequesters int)

func (*BlockPool) IsCaughtUp

func (pool *BlockPool) IsCaughtUp() bool

TODO: relax conditions, prevent abuse.

func (*BlockPool) OnStart

func (pool *BlockPool) OnStart() error

func (*BlockPool) OnStop

func (pool *BlockPool) OnStop()

func (*BlockPool) PeekTwoBlocks

func (pool *BlockPool) PeekTwoBlocks() (first *legacy.Block, second *legacy.Block)

We need to see the second block's Commit to validate the first block. So we peek two blocks at a time. The caller will verify the commit.

func (*BlockPool) PopRequest

func (pool *BlockPool) PopRequest()

Pop the first block at pool.height It must have been validated by 'second'.Commit from PeekTwoBlocks().

func (*BlockPool) RedoRequest

func (pool *BlockPool) RedoRequest(height uint64)

Invalidates the block at pool.height, Remove the peer and redo request from others.

func (*BlockPool) RemovePeer

func (pool *BlockPool) RemovePeer(peerID string)

func (*BlockPool) SetPeerHeight

func (pool *BlockPool) SetPeerHeight(peerID string, height uint64)

Sets the peer's alleged blockchain height.

type BlockRequest

type BlockRequest struct {
	Height uint64
	PeerID string
}

type BlockchainMessage

type BlockchainMessage interface{}

BlockchainMessage is a generic message for this reactor.

func DecodeMessage

func DecodeMessage(bz []byte) (msgType byte, msg BlockchainMessage, err error)

DecodeMessage decodes BlockchainMessage. TODO: ensure that bz is completely read.

type BlockchainReactor

type BlockchainReactor struct {
	p2p.BaseReactor
	// contains filtered or unexported fields
}

BlockchainReactor handles long-term catchup syncing.

func NewBlockchainReactor

func NewBlockchainReactor(store *txdb.Store, chain *protocol.Chain, txPool *protocol.TxPool, accounts *account.Manager, assets *asset.Registry, hsm *pseudohsm.HSM, fastSync bool) *BlockchainReactor

func (*BlockchainReactor) AddPeer

func (bcR *BlockchainReactor) AddPeer(peer *p2p.Peer)

AddPeer implements Reactor by sending our state to peer.

func (*BlockchainReactor) BroadcastStatusRequest

func (bcR *BlockchainReactor) BroadcastStatusRequest() error

BroadcastStatusRequest broadcasts `BlockStore` height.

func (*BlockchainReactor) BroadcastTransaction

func (bcR *BlockchainReactor) BroadcastTransaction(tx *legacy.Tx) error

func (*BlockchainReactor) BuildHander

func (bcr *BlockchainReactor) BuildHander()

func (*BlockchainReactor) GetChannels

func (bcR *BlockchainReactor) GetChannels() []*p2p.ChannelDescriptor

GetChannels implements Reactor

func (*BlockchainReactor) OnStart

func (bcR *BlockchainReactor) OnStart() error

OnStart implements BaseService

func (*BlockchainReactor) OnStop

func (bcR *BlockchainReactor) OnStop()

OnStop implements BaseService

func (*BlockchainReactor) Receive

func (bcR *BlockchainReactor) Receive(chID byte, src *p2p.Peer, msgBytes []byte)

Receive implements Reactor by handling 4 types of messages (look below).

func (*BlockchainReactor) RemovePeer

func (bcR *BlockchainReactor) RemovePeer(peer *p2p.Peer, reason interface{})

RemovePeer implements Reactor by removing peer from the pool.

func (*BlockchainReactor) ServeHTTP

func (bcr *BlockchainReactor) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type BuildRequest

type BuildRequest struct {
	Tx      *legacy.TxData           `json:"base_transaction"`
	Actions []map[string]interface{} `json:"actions"`
	TTL     json.Duration            `json:"ttl"`
}

type MemStore

type MemStore struct {
	Blocks map[uint64]*legacy.Block
	// contains filtered or unexported fields
}

MemStore satisfies the Store interface.

func NewMemStore

func NewMemStore() *MemStore

New returns a new MemStore

func (*MemStore) FinalizeBlock

func (m *MemStore) FinalizeBlock(uint64) error

func (*MemStore) Height

func (m *MemStore) Height() uint64

func (*MemStore) LoadBlock

func (m *MemStore) LoadBlock(height uint64) *legacy.Block

func (*MemStore) SaveBlock

func (m *MemStore) SaveBlock(b *legacy.Block) error

type SubmitArg

type SubmitArg struct {
	Transactions []txbuilder.Template
	Wait         chainjson.Duration
	WaitUntil    string `json:"wait_until"` // values none, confirmed, processed. default: processed
}

Directories

Path Synopsis
Package accesstoken provides storage and validation of Chain Core credentials.
Package accesstoken provides storage and validation of Chain Core credentials.
Package account stores and tracks accounts within a Chain Core.
Package account stores and tracks accounts within a Chain Core.
Package query implements indexing and querying of annotated blockchain data.
Package query implements indexing and querying of annotated blockchain data.
filter
Package filter parses and evaluates Chain filter expressions.
Package filter parses and evaluates Chain filter expressions.
Package rpc implements Chain Core's RPC client.
Package rpc implements Chain Core's RPC client.
Package signers associates signers and their corresponding keys.
Package signers associates signers and their corresponding keys.
Package txbuilder builds a Chain Protocol transaction from a list of actions.
Package txbuilder builds a Chain Protocol transaction from a list of actions.
Package txdb provides storage for Chain Protocol blockchain data structures.
Package txdb provides storage for Chain Protocol blockchain data structures.
internal/storage
Package storage is a generated protocol buffer package.
Package storage is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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