store

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldUint8   = 0x01
	FieldUint16  = 0x02
	FieldUint32  = 0x03
	FieldUint64  = 0x04
	FieldUint168 = 0x05
	FieldUint256 = 0x06
	FieldInt     = 0x07
	FieldInt32   = 0x08
	FieldIn64    = 0x09
	FieldBytes   = 0x0a
	FieldString  = 0x0b
	FieldBool    = 0x0c

	DefaultMaxDataSize = 1024 * 1024
)
View Source
const BITSPERKEY = 10

used to compute the size of bloom filter bits array . too small will lead to high false positive rate.

View Source
const (
	MaxEvnetTaskNumber = 10000
)

Variables

View Source
var ConsensusEventTable = &DBTable{
	Name:       "ConsensusEvent",
	PrimaryKey: 4,
	Indexes:    []uint64{3},
	Fields: []string{
		"StartTime",
		"EndTime",
		"Height",
		"RawData",
	},
}
View Source
var ProposalEventTable = &DBTable{
	Name:       "ProposalEvent",
	PrimaryKey: 7,
	Indexes:    []uint64{1, 2, 6},
	Fields: []string{
		"Sponsor",
		"BlockHash",
		"ReceivedTime",
		"EndTime",
		"Result",
		"ProposalHash",
		"RawData",
	},
}
View Source
var ViewEventTable = &DBTable{
	Name:       "ViewEvent",
	PrimaryKey: 0,
	Indexes:    nil,
	Fields: []string{
		"ConsensusID",
		"OnDutyArbitrator",
		"StartTime",
		"Offset",
	},
}
View Source
var VoteEventTable = &DBTable{
	Name:       "VoteEvent",
	PrimaryKey: 0,
	Indexes:    nil,
	Fields: []string{
		"ProposalID",
		"Signer",
		"ReceivedTime",
		"Result",
		"RawData",
	},
}

Functions

func BytesToUint64 added in v0.3.0

func BytesToUint64(b []byte) uint64

func BytesToUint64List added in v0.3.0

func BytesToUint64List(b []byte) ([]uint64, error)

func GetIndexKey added in v0.3.0

func GetIndexKey(tableName string, index uint64, columnValue []byte) []byte

func GetRowKey added in v0.3.0

func GetRowKey(tableName string, rowID uint64) []byte

func GetTableIDKey added in v0.3.0

func GetTableIDKey(tableName string) []byte

func GetTableKey added in v0.3.0

func GetTableKey(tableName string) []byte

func Uint64ListToBytes added in v0.3.0

func Uint64ListToBytes(indexes []uint64) ([]byte, error)

func Uint64ToBytes added in v0.3.0

func Uint64ToBytes(value uint64) []byte

Types

type Batch

type Batch interface {
	Put(key []byte, value []byte) error
	Delete(key []byte) error
	Commit() error
	Rollback() error
}

type DBTable added in v0.3.0

type DBTable struct {
	// name of table
	Name string

	// primary key range from 1 to len(table.Fields)
	// if give other value, will use default rowID as primary key only
	PrimaryKey uint64

	// database index range from 1 to len(table.Fields)
	// if give values not in scope, the database index will not be effective
	Indexes []uint64

	// field name of table
	Fields []string
}

todo change fields to map[string]FieldType, change indexes to ma[uint64]struct{}

func (*DBTable) Column added in v0.3.0

func (d *DBTable) Column(fieldName string) uint64

column range from 1 to len(table.Fields), if a field name not found in table will return 0

func (*DBTable) Data added in v0.3.0

func (d *DBTable) Data(fields []*Field) ([]byte, error)

func (*DBTable) Deserialize added in v0.3.0

func (d *DBTable) Deserialize(r io.Reader) error

func (*DBTable) GetFields added in v0.3.0

func (d *DBTable) GetFields(data []byte) ([]*Field, error)

func (*DBTable) Serialize added in v0.3.0

func (d *DBTable) Serialize(w io.Writer) error

type DataEntryPrefix

type DataEntryPrefix byte

DataEntryPrefix

const (
	// DPOS
	DPOSCheckPoints        DataEntryPrefix = 0x10
	DPOSDutyIndex          DataEntryPrefix = 0x11
	DPOSCurrentArbitrators DataEntryPrefix = 0x12
	DPOSCurrentCandidates  DataEntryPrefix = 0x13
	DPOSNextArbitrators    DataEntryPrefix = 0x14
	DPOSNextCandidates     DataEntryPrefix = 0x15
	DPOSCurrentReward      DataEntryPrefix = 0x16
	DPOSNextReward         DataEntryPrefix = 0x17
	DPOSState              DataEntryPrefix = 0x18
)

type Database

type Database interface {
	Put(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Delete(key []byte) error
	NewBatch() Batch
	NewIterator(prefix []byte) blockchain.IIterator
	Close() error
}

type DirectPeers added in v0.3.0

type DirectPeers struct {
	PublicKey []byte
	Address   string
	Sequence  uint32
}

type DposStore

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

func NewDposStore

func NewDposStore(dataDir string) (*DposStore, error)

func (*DposStore) AddConsensusEvent

func (s *DposStore) AddConsensusEvent(event interface{}) error

func (*DposStore) AddProposalEvent

func (s *DposStore) AddProposalEvent(event interface{}) error

func (*DposStore) AddViewEvent

func (s *DposStore) AddViewEvent(event interface{}) error

func (*DposStore) AddVoteEvent

func (s *DposStore) AddVoteEvent(event interface{}) error

func (*DposStore) Close added in v0.3.0

func (s *DposStore) Close() error

func (*DposStore) Create

func (s *DposStore) Create(table *DBTable) error

func (*DposStore) GetCheckPoint added in v0.3.2

func (s *DposStore) GetCheckPoint(height uint32) (*state.CheckPoint, error)

func (*DposStore) GetHeightsDesc added in v0.3.2

func (s *DposStore) GetHeightsDesc() ([]uint32, error)

func (*DposStore) Insert

func (s *DposStore) Insert(table *DBTable, fields []*Field) (uint64, error)

func (*DposStore) SaveArbitersState added in v0.3.2

func (s *DposStore) SaveArbitersState(point *state.CheckPoint) (err error)

func (*DposStore) Select

func (s *DposStore) Select(table *DBTable, inputFields []*Field) ([][]*Field, error)

func (*DposStore) SelectID

func (s *DposStore) SelectID(table *DBTable, inputFields []*Field) ([]uint64, error)

func (*DposStore) StartEventRecord added in v0.3.0

func (s *DposStore) StartEventRecord()

func (*DposStore) Update

func (s *DposStore) Update(table *DBTable, inputFields []*Field, updateFields []*Field) ([]uint64, error)

func (*DposStore) UpdateConsensusEvent

func (s *DposStore) UpdateConsensusEvent(event interface{}) error

func (*DposStore) UpdateProposalEvent

func (s *DposStore) UpdateProposalEvent(event interface{}) error

type EventRecord

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

func (*EventRecord) Initialize

func (e *EventRecord) Initialize(store IEventRecord)

func (*EventRecord) OnConsensusFinished

func (e *EventRecord) OnConsensusFinished(cons *log.ConsensusEvent)

func (*EventRecord) OnConsensusStarted

func (e *EventRecord) OnConsensusStarted(cons *log.ConsensusEvent)

func (*EventRecord) OnProposalArrived

func (e *EventRecord) OnProposalArrived(prop *log.ProposalEvent)

func (*EventRecord) OnProposalFinished

func (e *EventRecord) OnProposalFinished(prop *log.ProposalEvent)

func (*EventRecord) OnViewStarted

func (e *EventRecord) OnViewStarted(view *log.ViewEvent)

func (*EventRecord) OnVoteArrived

func (e *EventRecord) OnVoteArrived(vote *log.VoteEvent)

type EventStoreAnalyzer added in v0.3.0

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

func NewEventStoreAnalyzer added in v0.3.0

func NewEventStoreAnalyzer(cfg EventStoreAnalyzerConfig) *EventStoreAnalyzer

func (*EventStoreAnalyzer) AppendConsensusVote added in v0.3.2

func (e *EventStoreAnalyzer) AppendConsensusVote(vote *payload.DPOSProposalVote)

func (*EventStoreAnalyzer) Clear added in v0.3.2

func (e *EventStoreAnalyzer) Clear()

func (*EventStoreAnalyzer) GetLastConsensusViewCount added in v0.3.2

func (e *EventStoreAnalyzer) GetLastConsensusViewCount() uint32

func (*EventStoreAnalyzer) GetLastConsensusVoteSignerHistory added in v0.3.2

func (e *EventStoreAnalyzer) GetLastConsensusVoteSignerHistory() []string

func (*EventStoreAnalyzer) IncreaseLastConsensusViewCount added in v0.3.2

func (e *EventStoreAnalyzer) IncreaseLastConsensusViewCount()

func (*EventStoreAnalyzer) ParseInactiveArbitrators added in v0.3.0

func (e *EventStoreAnalyzer) ParseInactiveArbitrators() (result []string)

type EventStoreAnalyzerConfig added in v0.3.0

type EventStoreAnalyzerConfig struct {
	Store       IDposStore
	Arbitrators state.Arbitrators
}

type Field added in v0.3.0

type Field struct {
	Name  string
	Value interface{}
}

func (*Field) Data added in v0.3.0

func (f *Field) Data() []byte

type IDBOperator added in v0.3.0

type IDBOperator interface {
	Create(table *DBTable) error
	Insert(table *DBTable, fields []*Field) (uint64, error)
	Select(table *DBTable, inputFields []*Field) ([][]*Field, error)
	Update(table *DBTable, inputFields []*Field, updateFields []*Field) ([]uint64, error)
	SelectID(table *DBTable, inputFields []*Field) ([]uint64, error)
	Close() error
}

type IDposStore added in v0.3.0

type IDposStore interface {
	IDBOperator
	IEventRecord
	state.IArbitratorsRecord
}

IDposStore provides func for dpos

type IEventRecord added in v0.3.0

type IEventRecord interface {
	StartEventRecord()
	AddProposalEvent(event interface{}) error
	UpdateProposalEvent(event interface{}) error
	AddVoteEvent(event interface{}) error
	AddViewEvent(event interface{}) error
	AddConsensusEvent(event interface{}) error
	UpdateConsensusEvent(event interface{}) error
}

type LevelDB

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

func NewLevelDB

func NewLevelDB(file string) (*LevelDB, error)

func (*LevelDB) Close

func (l *LevelDB) Close() error

func (*LevelDB) Delete

func (l *LevelDB) Delete(key []byte) error

func (*LevelDB) Get

func (l *LevelDB) Get(key []byte) ([]byte, error)

func (*LevelDB) NewBatch

func (l *LevelDB) NewBatch() Batch

func (*LevelDB) NewIterator

func (l *LevelDB) NewIterator(prefix []byte) blockchain.IIterator

func (*LevelDB) Put

func (l *LevelDB) Put(key []byte, value []byte) error

Jump to

Keyboard shortcuts

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