structure

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: GPL-3.0 Imports: 3 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 EventOrphan added in v0.0.2

type EventOrphan struct {
	SnapshotID            string           `json:"snapshot_id"`
	Type                  EventType        `json:"event_type_orphan"`
	OrphanParentBlockHash string           `json:"orphan_parent_block_hash"`
	OrphanBlockHash       string           `json:"orphan_block_hash"`
	ConnectMainChain      bool             `json:"connect_main_chain"`
	Timestamp             common.Timestamp `json:"timestamp"` // Revision 开始时间戳
}

func NewEventOrphan added in v0.0.2

func NewEventOrphan(t EventType, snapshotID string, parentBlockHash, blockHash string, connectMainChain bool) *EventOrphan

type EventType added in v0.0.2

type EventType int
const (
	EventTypeOrphanHappen EventType = iota
	EventTypeOrphanConnect
	EventTypeOrphanDiscard
	EventTypeUnknown
)

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 RevisionDataBlockReceiveFinal added in v0.0.2

type RevisionDataBlockReceiveFinal struct {
	OK bool `json:"ok"`
}

type RevisionDataBlockReceiveInit added in v0.0.2

type RevisionDataBlockReceiveInit struct {
	PeerIPAddr      string `json:"peer_ip_addr"` // ipv4 or ipv6
	MinerWalletAddr string `json:"miner_wallet_addr"`
}

type RevisionDataBlockVerifyFinal added in v0.0.2

type RevisionDataBlockVerifyFinal struct {
	OK     bool   `json:"ok"`
	Result string `json:"result"`
}

type RevisionDataBlockVerifyInit added in v0.0.2

type RevisionDataBlockVerifyInit struct {
	Hash       string `json:"hash"`
	ParentHash string `json:"parent_hash"`
	Height     int32  `json:"height"`
	NumTxns    uint64 `json:"num_txns"`

	Version        int32  `json:"version"`
	Bits           uint32 `json:"bits"`
	WorkSum        string `json:"work_sum"`
	MerkleRootHash string `json:"merkle_root_hash"`
	Nonce          uint32 `json:"nonce"`
}

type RevisionDataChainSwapFinal added in v0.0.2

type RevisionDataChainSwapFinal struct {
	NewBestBlockHash    string `json:"new_best_block_hash"`
	ForkParentBlockHash string `json:"fork_parent_block_hash"`
	ForkBlockHash       string `json:"fork_block_hash"`

	OK bool `json:"ok"`
}

type RevisionDataChainSwapInit added in v0.0.2

type RevisionDataChainSwapInit struct {
	OldBestBlockHash string `json:"old_best_block_hash"`
}

type RevisionDataChainVerifyFinal added in v0.0.2

type RevisionDataChainVerifyFinal struct {
}

type RevisionDataChainVerifyInit added in v0.0.2

type RevisionDataChainVerifyInit struct {
}

type RevisionDataMainChainExtendFinal added in v0.0.2

type RevisionDataMainChainExtendFinal struct {
	OK bool `json:"ok"`
}

type RevisionDataMainChainExtendInit added in v0.0.2

type RevisionDataMainChainExtendInit struct {
	BlockHash string `json:"block_hash"`
}

type RevisionDataOrphanExtendFinal added in v0.0.2

type RevisionDataOrphanExtendFinal struct {
}

type RevisionDataOrphanExtendInit added in v0.0.2

type RevisionDataOrphanExtendInit struct {
}

type RevisionDataOrphanProcessFinal added in v0.0.2

type RevisionDataOrphanProcessFinal struct {
}

type RevisionDataOrphanProcessInit added in v0.0.2

type RevisionDataOrphanProcessInit struct {
}

type RevisionDataSideChainExtendFinal added in v0.0.2

type RevisionDataSideChainExtendFinal struct {
	ForkBlockHash string `json:"fork_block_hash"`
	IsExtend      bool   `json:"is_extend"`
}

type RevisionDataSideChainExtendInit added in v0.0.2

type RevisionDataSideChainExtendInit struct {
	ForkParentBlockHash string `json:"fork_parent_block_hash"`
}

type RevisionType

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

	RevisionTypeUnknown
)

每一种 Type 都对应一种 RevisionData

type Snapshot

type Snapshot struct {
	// for all snapshot
	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"`
	State             *BestState       `json:"state"` // 当前先用 any,目前不包括任何信息,后面可以加

	// for init and final snapshot
	BlockHash       string         `json:"block_hash"`
	IsOrphan        bool           `json:"is_orphan"`
	RevisionList    []*Revision    `json:"revision_list"`
	EventOrphanList []*EventOrphan `json:"event_orphan_list"`
}

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

func NewInitSnapshot

func NewInitSnapshot(targetChainID string, targetChainHeight int32, initTime time.Time, blockHash string, 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) CommitOrphanEvent added in v0.0.2

func (s *Snapshot) CommitOrphanEvent(eventOrphan *EventOrphan)

CommitOrphanEvent 被 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