blockcache

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2018 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DelSingleBlockTime ...
	DelSingleBlockTime int64 = 10
)

Variables

View Source
var BcMessageType_name = map[int32]string{
	0: "LinkType",
	1: "SetRootType",
}
View Source
var BcMessageType_value = map[string]int32{
	"LinkType":    0,
	"SetRootType": 1,
}

Functions

func CleanBlockCacheWAL added in v1.1.0

func CleanBlockCacheWAL() error

CleanBlockCacheWAL used in test to clean dir

Types

type BCNType

type BCNType int

BCNType type of BlockCacheNode

const (
	Linked BCNType = iota
	Single
	Virtual
)

The types of BlockCacheNode

type BcMessage added in v1.1.0

type BcMessage struct {
	Data                 []byte        `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"`
	Type                 BcMessageType `protobuf:"varint,2,opt,name=type,proto3,enum=blockcache.BcMessageType" json:"type,omitempty"`
	XXX_NoUnkeyedLiteral struct{}      `json:"-"`
	XXX_unrecognized     []byte        `json:"-"`
	XXX_sizecache        int32         `json:"-"`
}

func (*BcMessage) Descriptor added in v1.1.0

func (*BcMessage) Descriptor() ([]byte, []int)

func (*BcMessage) GetData added in v1.1.0

func (m *BcMessage) GetData() []byte

func (*BcMessage) GetType added in v1.1.0

func (m *BcMessage) GetType() BcMessageType

func (*BcMessage) ProtoMessage added in v1.1.0

func (*BcMessage) ProtoMessage()

func (*BcMessage) Reset added in v1.1.0

func (m *BcMessage) Reset()

func (*BcMessage) String added in v1.1.0

func (m *BcMessage) String() string

func (*BcMessage) XXX_DiscardUnknown added in v1.1.0

func (m *BcMessage) XXX_DiscardUnknown()

func (*BcMessage) XXX_Marshal added in v1.1.0

func (m *BcMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BcMessage) XXX_Merge added in v1.1.0

func (dst *BcMessage) XXX_Merge(src proto.Message)

func (*BcMessage) XXX_Size added in v1.1.0

func (m *BcMessage) XXX_Size() int

func (*BcMessage) XXX_Unmarshal added in v1.1.0

func (m *BcMessage) XXX_Unmarshal(b []byte) error

type BcMessageType added in v1.1.0

type BcMessageType int32
const (
	BcMessageType_LinkType    BcMessageType = 0
	BcMessageType_SetRootType BcMessageType = 1
)

func (BcMessageType) EnumDescriptor added in v1.1.0

func (BcMessageType) EnumDescriptor() ([]byte, []int)

func (BcMessageType) String added in v1.1.0

func (x BcMessageType) String() string

type BlockCache

type BlockCache interface {
	Add(*block.Block) *BlockCacheNode
	AddWithWit(blk *block.Block, witnessList WitnessList) (bcn *BlockCacheNode)
	AddGenesis(*block.Block)
	Link(*BlockCacheNode)
	Del(*BlockCacheNode)
	Flush(*BlockCacheNode)
	Find([]byte) (*BlockCacheNode, error)
	GetBlockByNumber(int64) (*block.Block, error)
	GetBlockByHash([]byte) (*block.Block, error)
	LinkedRoot() *BlockCacheNode
	Head() *BlockCacheNode
	Draw() string
	CleanDir() error
	Recover(p conAlgo) (err error)
	NewWAL(config *common.Config) (err error)
}

BlockCache defines BlockCache's API

type BlockCacheImpl

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

BlockCacheImpl is the implementation of BlockCache

func NewBlockCache

func NewBlockCache(baseVariable global.BaseVariable) (*BlockCacheImpl, error)

NewBlockCache return a new BlockCache instance

func (*BlockCacheImpl) Add

func (bc *BlockCacheImpl) Add(blk *block.Block) *BlockCacheNode

Add is add a block

func (*BlockCacheImpl) AddGenesis

func (bc *BlockCacheImpl) AddGenesis(blk *block.Block)

AddGenesis is add genesis block

func (*BlockCacheImpl) AddWithWit added in v1.1.0

func (bc *BlockCacheImpl) AddWithWit(blk *block.Block, witnessList WitnessList) (bcn *BlockCacheNode)

AddWithWit add block with witnessList

func (*BlockCacheImpl) CleanDir added in v1.1.0

func (bc *BlockCacheImpl) CleanDir() error

CleanDir used in test to clean dir

func (*BlockCacheImpl) Del

func (bc *BlockCacheImpl) Del(bcn *BlockCacheNode)

Del is delete a block

func (*BlockCacheImpl) Draw

func (bc *BlockCacheImpl) Draw() string

Draw returns the linkedroot's and singleroot's tree graph.

func (*BlockCacheImpl) Find

func (bc *BlockCacheImpl) Find(hash []byte) (*BlockCacheNode, error)

Find is find the block

func (*BlockCacheImpl) Flush

func (bc *BlockCacheImpl) Flush(bcn *BlockCacheNode)

Flush is save a block

func (*BlockCacheImpl) GetBlockByHash

func (bc *BlockCacheImpl) GetBlockByHash(hash []byte) (*block.Block, error)

GetBlockByHash get a block by hash

func (*BlockCacheImpl) GetBlockByNumber

func (bc *BlockCacheImpl) GetBlockByNumber(num int64) (*block.Block, error)

GetBlockByNumber get a block by number

func (*BlockCacheImpl) Head

func (bc *BlockCacheImpl) Head() *BlockCacheNode

Head return head of block cache

func (bc *BlockCacheImpl) Link(bcn *BlockCacheNode)

Link call this when you run the block verify after Add() to ensure add single bcn to linkedRoot

func (*BlockCacheImpl) LinkedRoot

func (bc *BlockCacheImpl) LinkedRoot() *BlockCacheNode

LinkedRoot return the root node

func (*BlockCacheImpl) NewWAL added in v1.1.0

func (bc *BlockCacheImpl) NewWAL(config *common.Config) (err error)

NewWAL New wal when old one is not recoverable. Move Old File into Corrupted for later analysis.

func (*BlockCacheImpl) Recover added in v1.1.0

func (bc *BlockCacheImpl) Recover(p conAlgo) (err error)

Recover recover previews block cache

func (*BlockCacheImpl) SetHead added in v1.1.0

func (bc *BlockCacheImpl) SetHead(n *BlockCacheNode)

SetHead sets head blockcache node.

func (*BlockCacheImpl) SetLinkedRoot added in v1.1.0

func (bc *BlockCacheImpl) SetLinkedRoot(n *BlockCacheNode)

SetLinkedRoot sets linked blockcache node.

type BlockCacheNode

type BlockCacheNode struct {
	*block.Block

	Children map[*BlockCacheNode]bool
	Type     BCNType

	ConfirmUntil int64
	WitnessList
	// contains filtered or unexported fields
}

BlockCacheNode is the implementation of BlockCacheNode

func NewBCN

func NewBCN(parent *BlockCacheNode, blk *block.Block) *BlockCacheNode

NewBCN return a new block cache node instance

func NewVirtualBCN

func NewVirtualBCN(parent *BlockCacheNode, blk *block.Block) *BlockCacheNode

NewVirtualBCN return a new virtual block cache node instance

func (*BlockCacheNode) GetParent added in v1.1.0

func (bcn *BlockCacheNode) GetParent() *BlockCacheNode

GetParent returns the node's parent node.

func (*BlockCacheNode) SetParent added in v1.1.0

func (bcn *BlockCacheNode) SetParent(p *BlockCacheNode)

SetParent sets the node's parent.

type BlockCacheRaw added in v1.1.0

type BlockCacheRaw struct {
	BlockBytes           []byte       `protobuf:"bytes,1,opt,name=blockBytes,proto3" json:"blockBytes,omitempty"`
	WitnessList          *WitnessList `protobuf:"bytes,2,opt,name=witnessList,proto3" json:"witnessList,omitempty"`
	XXX_NoUnkeyedLiteral struct{}     `json:"-"`
	XXX_unrecognized     []byte       `json:"-"`
	XXX_sizecache        int32        `json:"-"`
}

func (*BlockCacheRaw) Descriptor added in v1.1.0

func (*BlockCacheRaw) Descriptor() ([]byte, []int)

func (*BlockCacheRaw) GetBlockBytes added in v1.1.0

func (m *BlockCacheRaw) GetBlockBytes() []byte

func (*BlockCacheRaw) GetWitnessList added in v1.1.0

func (m *BlockCacheRaw) GetWitnessList() *WitnessList

func (*BlockCacheRaw) ProtoMessage added in v1.1.0

func (*BlockCacheRaw) ProtoMessage()

func (*BlockCacheRaw) Reset added in v1.1.0

func (m *BlockCacheRaw) Reset()

func (*BlockCacheRaw) String added in v1.1.0

func (m *BlockCacheRaw) String() string

func (*BlockCacheRaw) XXX_DiscardUnknown added in v1.1.0

func (m *BlockCacheRaw) XXX_DiscardUnknown()

func (*BlockCacheRaw) XXX_Marshal added in v1.1.0

func (m *BlockCacheRaw) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*BlockCacheRaw) XXX_Merge added in v1.1.0

func (dst *BlockCacheRaw) XXX_Merge(src proto.Message)

func (*BlockCacheRaw) XXX_Size added in v1.1.0

func (m *BlockCacheRaw) XXX_Size() int

func (*BlockCacheRaw) XXX_Unmarshal added in v1.1.0

func (m *BlockCacheRaw) XXX_Unmarshal(b []byte) error

type CacheStatus

type CacheStatus int

CacheStatus ...

type WitnessInfo added in v1.1.0

type WitnessInfo struct {
	Loc                  string   `protobuf:"bytes,1,opt,name=Loc,proto3" json:"Loc,omitempty"`
	URL                  string   `protobuf:"bytes,2,opt,name=URL,proto3" json:"URL,omitempty"`
	NetID                string   `protobuf:"bytes,3,opt,name=NetID,proto3" json:"NetID,omitempty"`
	Online               bool     `protobuf:"varint,4,opt,name=Online,proto3" json:"Online,omitempty"`
	Score                int64    `protobuf:"varint,5,opt,name=Score,proto3" json:"Score,omitempty"`
	Votes                int64    `protobuf:"varint,6,opt,name=Votes,proto3" json:"Votes,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*WitnessInfo) Descriptor added in v1.1.0

func (*WitnessInfo) Descriptor() ([]byte, []int)

func (*WitnessInfo) GetLoc added in v1.1.0

func (m *WitnessInfo) GetLoc() string

func (*WitnessInfo) GetNetID added in v1.1.0

func (m *WitnessInfo) GetNetID() string

func (*WitnessInfo) GetOnline added in v1.1.0

func (m *WitnessInfo) GetOnline() bool

func (*WitnessInfo) GetScore added in v1.1.0

func (m *WitnessInfo) GetScore() int64

func (*WitnessInfo) GetURL added in v1.1.0

func (m *WitnessInfo) GetURL() string

func (*WitnessInfo) GetVotes added in v1.1.0

func (m *WitnessInfo) GetVotes() int64

func (*WitnessInfo) ProtoMessage added in v1.1.0

func (*WitnessInfo) ProtoMessage()

func (*WitnessInfo) Reset added in v1.1.0

func (m *WitnessInfo) Reset()

func (*WitnessInfo) String added in v1.1.0

func (m *WitnessInfo) String() string

func (*WitnessInfo) XXX_DiscardUnknown added in v1.1.0

func (m *WitnessInfo) XXX_DiscardUnknown()

func (*WitnessInfo) XXX_Marshal added in v1.1.0

func (m *WitnessInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*WitnessInfo) XXX_Merge added in v1.1.0

func (dst *WitnessInfo) XXX_Merge(src proto.Message)

func (*WitnessInfo) XXX_Size added in v1.1.0

func (m *WitnessInfo) XXX_Size() int

func (*WitnessInfo) XXX_Unmarshal added in v1.1.0

func (m *WitnessInfo) XXX_Unmarshal(b []byte) error

type WitnessList

type WitnessList struct {
	ActiveWitnessList    []string                `protobuf:"bytes,1,rep,name=activeWitnessList,proto3" json:"activeWitnessList,omitempty"`
	PendingWitnessList   []string                `protobuf:"bytes,2,rep,name=pendingWitnessList,proto3" json:"pendingWitnessList,omitempty"`
	PendingWitnessNumber int64                   `protobuf:"varint,3,opt,name=pendingWitnessNumber,proto3" json:"pendingWitnessNumber,omitempty"`
	WitnessInfo          map[string]*WitnessInfo `` /* 163-byte string literal not displayed */
	XXX_NoUnkeyedLiteral struct{}                `json:"-"`
	XXX_unrecognized     []byte                  `json:"-"`
	XXX_sizecache        int32                   `json:"-"`
}

func (*WitnessList) Active

func (wl *WitnessList) Active() []string

Active get active witness list

func (*WitnessList) CopyWitness

func (wl *WitnessList) CopyWitness(n *BlockCacheNode)

CopyWitness is copy witness

func (*WitnessList) Descriptor added in v1.1.0

func (*WitnessList) Descriptor() ([]byte, []int)

func (*WitnessList) GetActiveWitnessList added in v1.1.0

func (m *WitnessList) GetActiveWitnessList() []string

func (*WitnessList) GetPendingWitnessList added in v1.1.0

func (m *WitnessList) GetPendingWitnessList() []string

func (*WitnessList) GetPendingWitnessNumber added in v1.1.0

func (m *WitnessList) GetPendingWitnessNumber() int64

func (*WitnessList) GetWitnessInfo added in v1.1.0

func (m *WitnessList) GetWitnessInfo() map[string]*WitnessInfo

func (*WitnessList) LibWitnessHandle

func (wl *WitnessList) LibWitnessHandle()

LibWitnessHandle is set active list

func (*WitnessList) NetID

func (wl *WitnessList) NetID() []string

NetID get net id

func (*WitnessList) Pending

func (wl *WitnessList) Pending() []string

Pending get pending witness list

func (*WitnessList) PendingNum

func (wl *WitnessList) PendingNum() int64

PendingNum get block number of pending witness

func (*WitnessList) ProtoMessage added in v1.1.0

func (*WitnessList) ProtoMessage()

func (*WitnessList) Reset added in v1.1.0

func (m *WitnessList) Reset()

func (*WitnessList) SetActive

func (wl *WitnessList) SetActive(al []string)

SetActive set active witness list

func (*WitnessList) SetPending

func (wl *WitnessList) SetPending(pl []string)

SetPending set pending witness list

func (*WitnessList) SetPendingNum

func (wl *WitnessList) SetPendingNum(n int64)

SetPendingNum set block number of pending witness

func (*WitnessList) String added in v1.1.0

func (m *WitnessList) String() string

func (*WitnessList) UpdateInfo

func (wl *WitnessList) UpdateInfo(mv db.MVCCDB) error

UpdateInfo update pending witness list

func (*WitnessList) UpdatePending

func (wl *WitnessList) UpdatePending(mv db.MVCCDB) error

UpdatePending update pending witness list

func (*WitnessList) XXX_DiscardUnknown added in v1.1.0

func (m *WitnessList) XXX_DiscardUnknown()

func (*WitnessList) XXX_Marshal added in v1.1.0

func (m *WitnessList) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*WitnessList) XXX_Merge added in v1.1.0

func (dst *WitnessList) XXX_Merge(src proto.Message)

func (*WitnessList) XXX_Size added in v1.1.0

func (m *WitnessList) XXX_Size() int

func (*WitnessList) XXX_Unmarshal added in v1.1.0

func (m *WitnessList) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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