core

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: GPL-3.0, GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToFloat64

func ByteToFloat64(bytes []byte) float64

func BytesToHash

func BytesToHash(b []byte) common.Hash

func GetNodeFromLeaf

func GetNodeFromLeaf(ln uint64) uint64

func HashToF64

func HashToF64(x common.Hash) float64

extract bits from the hash value to generate an f64 value this is used for extracting randomness from hash values https://news.ycombinator.com/item?id=9207874 http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/ARTICLES/dSFMT.pdf

func IsPowerOfTwo

func IsPowerOfTwo(n uint64) bool

func MapVerify

func MapVerify(proof []byte, txHash common.Hash) error

func NextPowerOfTwo

func NextPowerOfTwo(n uint64) uint64

func ProofInfoToBytes

func ProofInfoToBytes(info *ProofInfo) ([]byte, error)

func RlpHash

func RlpHash(x interface{}) (h common.Hash)

func SortAndRemoveRepeatForBlocks

func SortAndRemoveRepeatForBlocks(slc []uint64) []uint64

////////////////////////////////////////////////////////////////

func Uint64ToBytes

func Uint64ToBytes(i uint64) []byte

Types

type ChainAdapter

type ChainAdapter struct {
	Genesis      common.Hash
	ConfirmBlock *types.Header
	ProofHeader  *types.Header
	Latest       []*types.Header
}

func (*ChainAdapter) Copy

func (o *ChainAdapter) Copy() *ChainAdapter

func (*ChainAdapter) GenesisCheck

func (o *ChainAdapter) GenesisCheck(head *types.Header) error

type ChainHeaderProof

type ChainHeaderProof struct {
	Proof  *ProofInfo // the leatest blockchain and an proof of existence
	Header []*types.Header
	Right  *big.Int
}

func (*ChainHeaderProof) Data

func (b *ChainHeaderProof) Data() ([]byte, error)

type ChainInfoProof

type ChainInfoProof struct {
	Proof  *ProofInfo
	Header []*types.Header
}

type ChainProofs

type ChainProofs struct {
	Remote      *ChainAdapter `json:"remote"     rlp:"nil"`
	HeaderProof *ChainHeaderProof
	InfoProof   *ChainInfoProof
}

func NewChainProofs

func NewChainProofs() *ChainProofs

func (*ChainProofs) Data

func (cps *ChainProofs) Data() ([]byte, error)

func (*ChainProofs) Verify

func (cps *ChainProofs) Verify() error

type MapProofs

type MapProofs struct {
	ChainProof   *ChainProofs
	ReceiptProof *ReceiptProof
	End          *big.Int
	Header       *types.Header
	Result       bool
	TxHash       common.Hash
}

newBlockData is the network packet for the block propagation message.

func (*MapProofs) VerifyMapTransaction

func (mr *MapProofs) VerifyMapTransaction(txHash common.Hash) (*types.Receipt, error)

type MapTransaction

type MapTransaction struct {
	SimpUlvpP *MapProofs
	Tx        *types.Transaction
}

UlvpTransaction is the network packet for the block propagation message.

type Mmr

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

func NewMMR

func NewMMR() *Mmr

func (*Mmr) Copy

func (m *Mmr) Copy() *Mmr

func (*Mmr) CreateNewProof

func (m *Mmr) CreateNewProof(right_difficulty *big.Int) (*ProofInfo, []uint64, []uint64)

func (*Mmr) GenerateProof

func (m *Mmr) GenerateProof(proofHeight, EndHeight uint64) *ProofInfo

func (*Mmr) GenerateProof2

func (m *Mmr) GenerateProof2(proofHeight, EndHeight uint64) *ProofInfo

func (*Mmr) GetRoot2

func (m *Mmr) GetRoot2() common.Hash

func (*Mmr) Pop2

func (m *Mmr) Pop2() *Node

func (*Mmr) Push

func (m *Mmr) Push(newElem *Node)

type Node

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

func NewNode

func NewNode(v common.Hash, d, ds, de *big.Int, timeCost uint64) *Node

func (*Node) GetHash

func (n *Node) GetHash() common.Hash

func (*Node) String

func (n *Node) String() string

type NodeList

type NodeList []rlp.RawValue

NodeList stores an ordered list of trie nodes. It implements mosdb.KeyValueWriter.

func (NodeList) DataSize

func (n NodeList) DataSize() int

DataSize returns the aggregated data size of nodes in the list

func (*NodeList) Delete

func (n *NodeList) Delete(key []byte) error

Delete panics as there's no reason to remove a node from the list.

func (NodeList) NodeSet

func (n NodeList) NodeSet() *NodeSet

NodeSet converts the node list to a NodeSet

func (*NodeList) Put

func (n *NodeList) Put(key []byte, value []byte) error

Put stores a new node at the end of the list

func (NodeList) Store

func (n NodeList) Store(db ethdb.KeyValueWriter)

Store writes the contents of the list to the given database

type NodeSet

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

NodeSet stores a set of trie nodes. It implements trie.Database and can also act as a cache for another trie.Database.

func NewNodeSet

func NewNodeSet() *NodeSet

NewNodeSet creates an empty node set

func (*NodeSet) DataSize

func (db *NodeSet) DataSize() int

DataSize returns the aggregated data size of nodes in the set

func (*NodeSet) Delete

func (db *NodeSet) Delete(key []byte) error

Delete removes a node from the set

func (*NodeSet) Get

func (db *NodeSet) Get(key []byte) ([]byte, error)

Get returns a stored node

func (*NodeSet) Has

func (db *NodeSet) Has(key []byte) (bool, error)

Has returns true if the node set contains the given key

func (*NodeSet) KeyCount

func (db *NodeSet) KeyCount() int

KeyCount returns the number of nodes in the set

func (*NodeSet) NodeList

func (db *NodeSet) NodeList() NodeList

NodeList converts the node set to a NodeList

func (*NodeSet) Put

func (db *NodeSet) Put(key []byte, value []byte) error

Put stores a new node in the set

func (*NodeSet) Store

func (db *NodeSet) Store(target ethdb.KeyValueWriter)

Store writes the contents of the set to the given database

type ProofBlock

type ProofBlock struct {
	Number     uint64
	AggrWeight float64
}

func SortAndRemoveRepeatForProofBlocks

func SortAndRemoveRepeatForProofBlocks(slc []*ProofBlock) []*ProofBlock

func VerifyRequiredBlocks

func VerifyRequiredBlocks(info *ProofInfo, right_difficulty *big.Int) ([]*ProofBlock, error)

func VerifyRequiredBlocks2

func VerifyRequiredBlocks2(info *ProofInfo) ([]*ProofBlock, error)

type ProofBlocks

type ProofBlocks []*ProofBlock

func (ProofBlocks) Len

func (a ProofBlocks) Len() int

func (ProofBlocks) Less

func (a ProofBlocks) Less(i, j int) bool

func (ProofBlocks) Swap

func (a ProofBlocks) Swap(i, j int)

type ProofElem

type ProofElem struct {
	Cat     uint8 // 0--root,1--node,2 --child
	Res     *ProofRes
	Right   bool
	LeafNum uint64
}

func (*ProofElem) String

func (p *ProofElem) String() string

type ProofElems

type ProofElems []*ProofElem

type ProofInfo

type ProofInfo struct {
	RootHash       common.Hash
	RootDifficulty *big.Int
	LeafNumber     uint64
	Elems          []*ProofElem
	Checked        []uint64
}

func ProofInfoFromBytes

func ProofInfoFromBytes(data []byte) (*ProofInfo, error)

func (*ProofInfo) String

func (p *ProofInfo) String() string

func (*ProofInfo) VerifyProof

func (p *ProofInfo) VerifyProof(blocks []*ProofBlock) bool

func (*ProofInfo) VerifyProof2

func (p *ProofInfo) VerifyProof2(blocks []*ProofBlock) bool

type ProofRes

type ProofRes struct {
	H  common.Hash
	TD *big.Int
}

///////////////////////////////////////////////////////////////////////////////

func (*ProofRes) String

func (r *ProofRes) String() string

type ReceiptProof

type ReceiptProof struct {
	Proofs      NodeList
	Index       uint64
	ReceiptHash common.Hash
}

func (*ReceiptProof) Verify

func (r *ReceiptProof) Verify() (*types.Receipt, error)

type VerifyElem

type VerifyElem struct {
	Res        *ProofRes
	Index      uint64
	LeafNumber uint64
}

type VerifyElems

type VerifyElems []*VerifyElem

Jump to

Keyboard shortcuts

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