consensus

package
v0.0.0-...-85922c0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Sync Blockchain

Index

Constants

View Source
const (
	MaxEqealBlockWeight = 10
	MaxExpiration       = time.Hour
	MaxOrphanBlocks     = 200
)
View Source
const HashSize int = 32

Variables

This section is empty.

Functions

func CheckNonce

func CheckNonce(nonceMp map[address.Address]uint64, bc blockchain.Blockchains, from address.Address, txNonce uint64) bool

Types

type BlockChain

type BlockChain struct {
	BlockHeader *block.Block
	Bc          blockchain.Blockchains

	Oranphs     map[Hash]*OrphanBlock
	PrevOrphans map[Hash][]*OrphanBlock
	// contains filtered or unexported fields
}

func New

func (*BlockChain) AddOrphanBlock

func (b *BlockChain) AddOrphanBlock(block *block.Block)

add block to orphan pool,According to the expiration time to determine whether to retain

func (*BlockChain) BlockExists

func (b *BlockChain) BlockExists(hash []byte) bool

judge block by hash exist

func (*BlockChain) FindBranchPoint

func (bc *BlockChain) FindBranchPoint(prevhash, tiphash []byte) ([][]byte, uint64, error)

func (*BlockChain) OrphanBlockIsExist

func (b *BlockChain) OrphanBlockIsExist(hash []byte) (*block.Block, bool)

func (*BlockChain) ProcessBlock

func (b *BlockChain) ProcessBlock(newblock *block.Block, globalDifficulty *big.Int, basePledge uint64) bool

ProcessBlock is the main workhorse for handling insertion of new blocks into the block chain. It includes functionality such as rejecting duplicate blocks, ensuring blocks follow all rules, orphan handling, and insertion into the block chain along with best chain selection and reorganization.

When no errors occurred during processing, the first return value indicates whether or not the block is on the main chain and the second indicates whether or not the block is an orphan.

func (*BlockChain) ProcessOrphan

func (b *BlockChain) ProcessOrphan(block *block.Block) bool

ProcessOrphan if block prevhash is exist in orphan pool , move all matched orphan blcoks to mainchain,

type Hash

type Hash [HashSize]byte

func BytesToHash

func BytesToHash(in []byte) Hash

type OrphanBlock

type OrphanBlock struct {
	Block      *block.Block
	Expiration time.Time
}

orphan Block data structure

Jump to

Keyboard shortcuts

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