forkdb

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	deadlock.RWMutex
	// contains filtered or unexported fields
}

DB ...

func NewDB

func NewDB(lg *logrus.Logger) *DB

NewDB ...

func (*DB) Commit

func (db *DB) Commit(id common.BlockID)

Commit sets the block pointed by id as irreversible. It peals off all other branches, sets id as the start block. It should be regularly called when a block is commited to save ram.

func (*DB) Empty

func (db *DB) Empty() bool

Empty returns true if DB contains no block

func (*DB) FetchBlock

func (db *DB) FetchBlock(id common.BlockID) (common.ISignedBlock, error)

FetchBlock fetches a block corresponding to id

func (*DB) FetchBlockByNum

func (db *DB) FetchBlockByNum(num uint64) []common.ISignedBlock

FetchBlockByNum fetches a block corresponding to the block num

func (*DB) FetchBlockFromMainBranch

func (db *DB) FetchBlockFromMainBranch(num uint64) (common.ISignedBlock, error)

FetchBlockFromMainBranch returns the num'th block on main branch

func (*DB) FetchBlocksFromMainBranch added in v1.0.2

func (db *DB) FetchBlocksFromMainBranch(num uint64) ([]common.ISignedBlock, error)

FetchBlocksFromMainBranch fetches blocks from [num, head]

func (*DB) FetchBlocksSince

func (db *DB) FetchBlocksSince(id common.BlockID) ([]common.ISignedBlock, []common.BlockID, error)

FetchBlocksSince fetches the main branch starting from id.next

func (*DB) FetchBranch

func (db *DB) FetchBranch(id1, id2 common.BlockID) ([2][]common.BlockID, error)

FetchBranch finds the nearest ancestor of id1 and id2, then returns the 2 branches

func (*DB) FetchUnlinkBlockTail added in v1.0.2

func (db *DB) FetchUnlinkBlockTail() (*common.BlockID, error)

func (*DB) Head

func (db *DB) Head() common.ISignedBlock

Head returns the head block of the longest chain, returns nil if the db is empty

func (*DB) Illegal

func (db *DB) Illegal(id common.BlockID) bool

Illegal determines if the block has illegal transactions

func (*DB) LastCommitted

func (db *DB) LastCommitted() common.BlockID

LastCommitted...

func (*DB) LoadSnapshot

func (db *DB) LoadSnapshot(avatar reflect.Type, dir string, blog *blocklog.BLog)

LoadSnapshot...

func (*DB) MarkAsIllegal

func (db *DB) MarkAsIllegal(id common.BlockID)

MarkAsIllegal put the block in a blacklist to prevent DDoS attack

func (*DB) Pop

func (db *DB) Pop() common.ISignedBlock

Pop pops the head block NOTE: The only scenarios Pop should be called are when:

 1.a fork switch occurs, hence the main branch and the fork
	  branch has a common ancestor that should NEVER be popped,
   which also means the main branch cannot be popped empty
 2.the newly appended block contains illegal transactions

Popping an empty db results in undefined behaviour

func (*DB) PurgeBranch added in v1.0.2

func (db *DB) PurgeBranch()

func (*DB) PushBlock

func (db *DB) PushBlock(b common.ISignedBlock) RetCode

PushBlock adds a block. If any of the forkchain has more than defaultSize blocks, purge will be triggered.

func (*DB) Reset added in v1.0.2

func (db *DB) Reset()

func (*DB) ResetHead

func (db *DB) ResetHead(head common.BlockID)

ResetHead... WARNING: DO NOT call this method unless you know what you are doing

func (*DB) RewindBranch added in v1.0.3

func (db *DB) RewindBranch(to common.BlockID) *Rewind

func (*DB) Snapshot

func (db *DB) Snapshot(dir string)

Snapshot...

func (*DB) TotalBlockNum

func (db *DB) TotalBlockNum() int

TotalBlockNum returns the total number of blocks contained in the DB

type RetCode added in v1.0.2

type RetCode string
const (
	RTDetached     RetCode = "detached block"
	RTDuplicated   RetCode = "duplicated block"
	RTPushedOnFork RetCode = "block is pushed on fork branch"
	RTPushedOnMain RetCode = "block is pushed on main branch"
	RTInvalid      RetCode = "block is invalid"
	RTOutOfRange   RetCode = "block number is out of range"
)

type Rewind added in v1.0.3

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

func (*Rewind) ApplyBlock added in v1.0.3

func (r *Rewind) ApplyBlock(id common.BlockID)

func (*Rewind) Done added in v1.0.3

func (r *Rewind) Done()

func (*Rewind) Undo added in v1.0.3

func (r *Rewind) Undo()

Jump to

Keyboard shortcuts

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