structure

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: GPL-3.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

View Source
const (
	SnapshotTypeInit = iota
	SnapshotTypeFinal
	SnapshotTypeSync
	SnapshotTypeUnknown
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BestState

type BestState struct {
	Hash            string           `json:"hash"`             // The hash of the block.
	Height          int32            `json:"height"`           // The height of the block.
	Bits            uint32           `json:"bits"`             // The difficulty bits of the block.
	BlockSize       uint64           `json:"block_size"`       // The size of the block.
	BlockWeight     uint64           `json:"block_weight"`     // The weight of the block.
	NumTxns         uint64           `json:"num_txns"`         // The number of txns in the block.
	TotalTxns       uint64           `json:"total_txns"`       // The total number of txns in the chain.
	MedianTimestamp common.Timestamp `json:"median_timestamp"` // Median time as per CalcPastMedianTime.
}

BestState from btcd chain.BestState

type Revision

type Revision struct {
	SnapshotID string       `json:"snapshot_id"`
	Type       RevisionType `json:"revision_type"` // 代表区块同步过程的一个阶段

	InitTimestamp  common.Timestamp `json:"init_timestamp"`  // Revision 开始时间戳
	InitData       RevisionData     `json:"init_data"`       // 根据 Tag 不同获取不同的数据,在 Revision 开始和时输出
	FinalTimestamp common.Timestamp `json:"final_timestamp"` // Revision 生效时间,结合 Timestamp 和 CommitTimestamp 确定 Revision 持续时间
	FinalData      RevisionData     `json:"final_data"`      // 根据 Tag 不同获取不同的数据,在 Revision 结束时输出
}

Revision 代表一个区块同步过程中的某一个阶段结束, 同一个 Snapshot 期间,每一个过程结束时输出一次

func NewRevision

func NewRevision(t RevisionType, snapshotID string, data RevisionData) *Revision

func (*Revision) Commit

func (r *Revision) Commit(finalTime time.Time, data RevisionData)

Commit 当前 Revision 生效,需要切换到下一个 Revision

type RevisionData

type RevisionData interface{}

type RevisionDataBlockReceive

type RevisionDataBlockReceive struct {
}

type RevisionDataBlockVerify

type RevisionDataBlockVerify struct {
}

type RevisionDataChainSwap

type RevisionDataChainSwap struct {
}

type RevisionDataChainVerify

type RevisionDataChainVerify struct {
}

type RevisionDataMainChainExtend

type RevisionDataMainChainExtend struct {
}

type RevisionDataOrphanExtend

type RevisionDataOrphanExtend struct {
}

type RevisionDataOrphanProcess

type RevisionDataOrphanProcess struct {
}

type RevisionDataSideChainExtend

type RevisionDataSideChainExtend struct {
}

type RevisionType

type RevisionType int
const (
	RevisionTypeBlockReceive RevisionType = iota
	RevisionTypeBlockVerify
	RevisionTypeChainVerify
	RevisionTypeOrphanProcess
	RevisionTypeOrphanExtend
	RevisionTypeMainChainExtend
	RevisionTypeSideChainExtend
	RevisionTypeChainSwap

	RevisionTypeUnknown
)

每一种 Type 都对应一种 RevisionData

type Snapshot

type Snapshot struct {
	ID                string           `json:"snapshot_id"` // 19+1+2+1+10:init timestamp string + chain id + chain height
	TargetChainID     string           `json:"target_chain_id"`
	TargetChainHeight int32            `json:"target_chain_height"`
	Type              SnapshotType     `json:"snapshot_type"`
	Timestamp         common.Timestamp `json:"timestamp"`

	// for init and final snapshot
	RevisionList []*Revision `json:"revision_list"`

	// for all snapshot
	State *BestState `json:"state"` // 当前先用 any,目前不包括任何信息,后面可以加
}

Snapshot 代表一次完整的区块同步流程,主要由一系列的 Revision 组成, 输出两次,初始化一次,结束一次,之间所有 ID 一致的 Revision 都属于这个 Snapshot, 在 Resolver 处会将一对 Snapshot 合并为一个,然后写入数据库

func NewInitSnapshot

func NewInitSnapshot(targetChainID string, targetChainHeight int32, initTime time.Time, state *BestState) *Snapshot

func NewSyncSnapshot

func NewSyncSnapshot(bestChainID string, bestChainHeight int32, syncTime time.Time, state *BestState) *Snapshot

func (*Snapshot) Commit

func (s *Snapshot) Commit(finalTime time.Time, state *BestState) *Snapshot

Commit 被 init snapshot 调用

func (*Snapshot) CommitRevision

func (s *Snapshot) CommitRevision(revision *Revision)

CommitRevision 被 init snapshot 调用

type SnapshotType

type SnapshotType int

Jump to

Keyboard shortcuts

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