Documentation ¶
Index ¶
- type DB
- func (db *DB) Commit(id common.BlockID)
- func (db *DB) Empty() bool
- func (db *DB) FetchBlock(id common.BlockID) (common.ISignedBlock, error)
- func (db *DB) FetchBlockByNum(num uint64) []common.ISignedBlock
- func (db *DB) FetchBlockFromMainBranch(num uint64) (common.ISignedBlock, error)
- func (db *DB) FetchBlocksFromMainBranch(num uint64) ([]common.ISignedBlock, error)
- func (db *DB) FetchBlocksSince(id common.BlockID) ([]common.ISignedBlock, []common.BlockID, error)
- func (db *DB) FetchBranch(id1, id2 common.BlockID) ([2][]common.BlockID, error)
- func (db *DB) FetchUnlinkBlockTail() (*common.BlockID, error)
- func (db *DB) Head() common.ISignedBlock
- func (db *DB) Illegal(id common.BlockID) bool
- func (db *DB) LastCommitted() common.BlockID
- func (db *DB) LoadSnapshot(avatar reflect.Type, dir string, blog *blocklog.BLog)
- func (db *DB) MarkAsIllegal(id common.BlockID)
- func (db *DB) Pop() common.ISignedBlock
- func (db *DB) PurgeBranch()
- func (db *DB) PushBlock(b common.ISignedBlock) RetCode
- func (db *DB) Reset()
- func (db *DB) ResetHead(head common.BlockID)
- func (db *DB) RewindBranch(to common.BlockID) *Rewind
- func (db *DB) Snapshot(dir string)
- func (db *DB) TotalBlockNum() int
- type RetCode
- type Rewind
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 (*DB) Commit ¶
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) FetchBlock ¶
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 ¶
FetchBlocksSince fetches the main branch starting from id.next
func (*DB) FetchBranch ¶
FetchBranch finds the nearest ancestor of id1 and id2, then returns the 2 branches
func (*DB) FetchUnlinkBlockTail ¶ added in v1.0.2
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) LoadSnapshot ¶
LoadSnapshot...
func (*DB) MarkAsIllegal ¶
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) ResetHead ¶
ResetHead... WARNING: DO NOT call this method unless you know what you are doing
func (*DB) TotalBlockNum ¶
TotalBlockNum returns the total number of blocks contained in the DB
type Rewind ¶ added in v1.0.3
type Rewind struct {
// contains filtered or unexported fields
}