blockchain

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: Apache-2.0, Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockchainChannel = byte(0x40)
)

Variables

View Source
var (
	ErrBlockIsNil      = errors.New("the chain has no block data")
	ErrBranchNameUsed  = errors.New("blockchain:branch name has been used")
	ErrConvertToFuture = errors.New("can't revert to future height")
	ErrRevertBackup    = errors.New("revert from backup,not find data")
)
View Source
var ErrNotFound = errors.New("leveldb not found")

Functions

func BlockStoreDB

func BlockStoreDB(config *cfg.Viper) (dbm.DB, dbm.DB)

func LoadBlockStore

func LoadBlockStore(blockStoreDB, blockArchiveDB dbm.DB, height int64) (*types.Block, *types.BlockMeta, *types.BlockID)

Types

type BlockPool

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

func NewBlockPool

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

func (*BlockPool) AddBlock

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

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

func (*BlockPool) GetStatus

func (pool *BlockPool) GetStatus() (height int64, 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 *types.Block, second *types.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 int64)

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

Sets the peer's alleged blockchain height.

type BlockRequest

type BlockRequest struct {
	Height int64
	PeerID string
}

type BlockStore

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

Simple low level store for blocks.

There are three types of information stored:

  • BlockMeta: Meta information about each block
  • Block part: Parts of each block, aggregated w/ PartSet
  • Commit: The commit part of each block, for gossiping precommit votes

Currently the precommit signatures are duplicated in the Block parts as well as the Commit. In the future this may change, perhaps by moving the Commit data outside the Block.

Panics indicate probable corruption in the data

func NewBlockStore

func NewBlockStore(db, archiveDB dbm.DB) *BlockStore

func (*BlockStore) DeleteBlock

func (bs *BlockStore) DeleteBlock(height int64) (err error)

func (*BlockStore) GetReader

func (bs *BlockStore) GetReader(key []byte) io.Reader

func (*BlockStore) GetReaderFromArchive

func (bs *BlockStore) GetReaderFromArchive(key []byte) io.Reader

func (*BlockStore) Height

func (bs *BlockStore) Height() int64

Height() returns the last known contiguous block height.

func (*BlockStore) LoadBlock

func (bs *BlockStore) LoadBlock(height int64) *types.Block

func (*BlockStore) LoadBlockCommit

func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit

The +2/3 and other Precommit-votes for block at `height`. This Commit comes from block.LastCommit for `height+1`.

func (*BlockStore) LoadBlockMeta

func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta

func (*BlockStore) LoadBlockPart

func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part

func (*BlockStore) LoadSeenCommit

func (bs *BlockStore) LoadSeenCommit(height int64) *types.Commit

NOTE: the Precommit-vote heights are for the block at `height`

func (*BlockStore) OriginHeight

func (bs *BlockStore) OriginHeight() int64

func (*BlockStore) RevertToHeight

func (bs *BlockStore) RevertToHeight(height int64)

func (*BlockStore) SaveBlock

func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)

blockParts: Must be parts of the block seenCommit: The +2/3 precommits that were seen which committed at height.

If all the nodes restart after committing a block,
we need this to reload the precommits to catch-up nodes to the
most recent height.  Otherwise they'd stall at H-1.

func (*BlockStore) SaveBlockToArchive

func (bs *BlockStore) SaveBlockToArchive(height int64, block *types.Block, blockParts *types.PartSet, seenCommit *types.Commit)

func (*BlockStore) SetOriginHeight

func (bs *BlockStore) SetOriginHeight(height int64)

type BlockStoreStateJSON

type BlockStoreStateJSON struct {
	Height       int64
	OriginHeight int64
}

func LoadBlockStoreStateJSON

func LoadBlockStoreStateJSON(db dbm.DB) BlockStoreStateJSON

func (BlockStoreStateJSON) Save

func (bsj BlockStoreStateJSON) Save(db dbm.DB)

func (BlockStoreStateJSON) SaveByKey

func (bsj BlockStoreStateJSON) SaveByKey(key []byte, db dbm.DB)

type BlockchainMessage

type BlockchainMessage interface{}

func DecodeMessage

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

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(config *viper.Viper, lastBlockHeight int64, store *BlockStore, fastSync bool, arch *archive.Archive) *BlockchainReactor

func (*BlockchainReactor) AddPeer

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

Implements Reactor

func (*BlockchainReactor) BlockArchive

func (bcR *BlockchainReactor) BlockArchive()

func (*BlockchainReactor) BroadcastStatusRequest

func (bcR *BlockchainReactor) BroadcastStatusRequest() error

func (*BlockchainReactor) BroadcastStatusResponse

func (bcR *BlockchainReactor) BroadcastStatusResponse() error

func (*BlockchainReactor) GetChannels

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

Implements Reactor

func (*BlockchainReactor) OnStart

func (bcR *BlockchainReactor) OnStart() error

func (*BlockchainReactor) OnStop

func (bcR *BlockchainReactor) OnStop()

func (*BlockchainReactor) Receive

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

Implements Reactor

func (*BlockchainReactor) RemovePeer

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

Implements Reactor

func (*BlockchainReactor) SetBlockExecuter

func (bcR *BlockchainReactor) SetBlockExecuter(x func(*types.Block, *types.PartSet, *types.Commit) error)

func (*BlockchainReactor) SetBlockVerifier

func (bcR *BlockchainReactor) SetBlockVerifier(v func(types.BlockID, int64, *types.Commit) error)

func (*BlockchainReactor) SetEventSwitch

func (bcR *BlockchainReactor) SetEventSwitch(evsw types.EventSwitch)

implements events.Eventable

type StoreTool

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

func (*StoreTool) BackupLastBlock

func (st *StoreTool) BackupLastBlock(branchName string) error

func (*StoreTool) DelBackup

func (st *StoreTool) DelBackup(branchName string)

func (*StoreTool) Init

func (st *StoreTool) Init(config *cfg.Viper) error

func (*StoreTool) LastHeight

func (st *StoreTool) LastHeight() int64

func (*StoreTool) LoadBlock

func (st *StoreTool) LoadBlock(height int64) (*types.Block, *types.BlockMeta, *types.BlockID)

func (*StoreTool) RevertFromBackup

func (st *StoreTool) RevertFromBackup(branchName string) error

func (*StoreTool) SaveNewLastBlock

func (st *StoreTool) SaveNewLastBlock(toHeight int64) error

Jump to

Keyboard shortcuts

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