types

package
v0.0.0-...-9faecf3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: LGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BloomByteLength represents the number of bytes used in a header log bloom.
	BloomByteLength = 256

	// BloomBitLength represents the number of bits used in a header log bloom.
	BloomBitLength = 8 * BloomByteLength
)
View Source
const (
	// ReceiptStatusFailed is the status code of a transaction if execution failed.
	ReceiptStatusFailed = uint64(0)

	// ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
	ReceiptStatusSuccessful = uint64(1)
)
View Source
const (
	MsgTypeBlockReq     = 1 //同步块请求
	MsgTypeBlockResp    = 2 //同步块回复
	MsgTypeBlock        = 3 //新块通知
	MsgTypeTransaction  = 4 //广播交易
	MsgTypePeerState    = 5 //Peer状态回复/或者状态通知
	MsgTypePeerStateReq = 6 //peer状态请求
	MsgTypeHeaderReq    = 7 //请求区块头
	MsgTypeHeaderRsp    = 8 //请求区块头回复

	MaxMsgSize = 20 << 20 //每个消息最大大小20MB
)

本模块的消息只能在调用本模块(chain及对应的子模块)的函数中使用

Variables

View Source
var (
	DrepMark   = []byte("Drep Coin Seed")
	KeyBitSize = 256 >> 3
)
View Source
var (
	TransferGas         = big.NewInt(30000)
	MinerGas            = big.NewInt(20000)
	CreateContractGas   = big.NewInt(1000000)
	CallContractGas     = big.NewInt(10000000)
	CrossChainGas       = big.NewInt(10000000)
	SeAliasGas          = big.NewInt(10000000)
	RegisterProducerGas = big.NewInt(10000000)
)
View Source
var Bloom9 = bloom9
View Source
var (
	ErrOutOfGas = errors.New("out of gas")
)
View Source
var NumberOfMsg = 9 //本模块定义的消息个数

Functions

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

func InitBlockNode

func InitBlockNode(node *BlockNode, blockHeader *BlockHeader, parent *BlockNode)

initBlockNode initializes a block node from the given header and parent node, calculating the height and workSum from the respective fields on the parent. This function is NOT safe for concurrent access. It must only be called when initially creating a node.

func LogsBloom

func LogsBloom(logs []*Log) *big.Int

Types

type Account

type Account struct {
	Address *crypto.CommonAddress
	Node    *Node
	Storage *Storage
}

func NewContractAccount

func NewContractAccount(address crypto.CommonAddress) (*Account, error)

func NewNormalAccount

func NewNormalAccount(parent *Node, chainId ChainIdType) (*Account, error)

func (*Account) Sign

func (account *Account) Sign(hash []byte) ([]byte, error)

type BestState

type BestState struct {
	Hash       crypto.Hash
	PrevHash   crypto.Hash
	Height     uint64
	MedianTime time.Time
}

func NewBestState

func NewBestState(node *BlockNode) *BestState

newBestState returns a new best stats instance for the given parameters.

type Block

type Block struct {
	Header *BlockHeader
	Data   *BlockData
	Proof  Proof
}

func BlockFromMessage

func BlockFromMessage(bytes []byte) (*Block, error)

func (*Block) AsMessage

func (block *Block) AsMessage() []byte

func (*Block) AsSignMessage

func (block *Block) AsSignMessage() []byte

func (*Block) GasLimit

func (block *Block) GasLimit() uint64

func (*Block) GasUsed

func (block *Block) GasUsed() uint64

type BlockData

type BlockData struct {
	TxCount uint64
	TxList  []*Transaction
}

type BlockHeader

type BlockHeader struct {
	ChainId      ChainIdType
	Version      int32
	PreviousHash crypto.Hash
	GasLimit     big.Int
	GasUsed      big.Int
	Height       uint64
	Timestamp    uint64
	StateRoot    []byte
	TxRoot       []byte
	ReceiptRoot  crypto.Hash
	Bloom        Bloom
	// contains filtered or unexported fields
}

func (*BlockHeader) Hash

func (blockHeader *BlockHeader) Hash() *crypto.Hash

type BlockNode

type BlockNode struct {

	// parent is the parent block for this node.
	Parent *BlockNode `binary:"ignore"`

	// hash is the double sha 256 of the block.
	Hash *crypto.Hash

	StateRoot []byte

	TimeStamp uint64
	// heigh is the position in the block chain.
	Height uint64

	ChainId      ChainIdType
	Version      int32
	PreviousHash *crypto.Hash
	GasLimit     big.Int
	GasUsed      big.Int
	MerkleRoot   []byte
	ReceiptRoot  crypto.Hash
	Bloom        Bloom
	Status       BlockStatus
}

func NewBlockNode

func NewBlockNode(blockHeader *BlockHeader, parent *BlockNode) *BlockNode

NewBlockNode returns a new block node for the given block header and parent node, calculating the height and workSum from the respective fields on the parent. This function is NOT safe for concurrent access.

func (*BlockNode) Ancestor

func (node *BlockNode) Ancestor(height uint64) *BlockNode

Ancestor returns the ancestor block node at the provided height by following the chain backwards from this node. The returned block will be nil when a height is requested that is after the height of the passed node or is less than zero.

This function is safe for concurrent access.

func (*BlockNode) CalcPastMedianTime

func (node *BlockNode) CalcPastMedianTime() time.Time

CalcPastMedianTime calculates the median time of the previous few blocks prior to, and including, the block node.

This function is safe for concurrent access.

func (*BlockNode) Header

func (node *BlockNode) Header() BlockHeader

Header constructs a block header from the node and returns it.

This function is safe for concurrent access.

func (*BlockNode) RelativeAncestor

func (node *BlockNode) RelativeAncestor(distance uint64) *BlockNode

RelativeAncestor returns the ancestor block node a relative 'distance' blocks before this node. This is equivalent to calling Ancestor with the node's height minus provided distance.

This function is safe for concurrent access.

type BlockReq

type BlockReq struct {
	BlockHashs []crypto.Hash
}

type BlockResp

type BlockResp struct {
	Height uint64
	Blocks []*Block
}

type BlockStatus

type BlockStatus byte

blockStatus is a bit field representing the validation state of the block.

const (
	// statusDataStored indicates that the block's payload is stored on disk.
	StatusDataStored BlockStatus = 1 << iota

	// statusValid indicates that the block has been fully validated.
	StatusValid

	// statusValidateFailed indicates that the block has failed validation.
	StatusValidateFailed

	// statusInvalidAncestor indicates that one of the block's ancestors has
	// has failed validation, thus the block is also invalid.
	StatusInvalidAncestor

	// statusNone indicates that the block has no validation state flags set.
	//
	// NOTE: This must be defined last in order to avoid influencing iota.
	StatusNone BlockStatus = 0
)

func (BlockStatus) HaveData

func (status BlockStatus) HaveData() bool

HaveData returns whether the full block Data is stored in the database. This will return false for a block node where only the header is downloaded or kept.

func (BlockStatus) KnownInvalid

func (status BlockStatus) KnownInvalid() bool

KnownInvalid returns whether the block is known to be invalid. This may be because the block itself failed validation or any of its ancestors is invalid. This will return false for invalid blocks that have not been proven invalid yet.

func (BlockStatus) KnownValid

func (status BlockStatus) KnownValid() bool

KnownValid returns whether the block is known to be valid. This will return false for a valid block that has not been fully validated yet.

type Bloom

type Bloom [BloomByteLength]byte

Bloom represents a 2048 bit bloom filter.

func BytesToBloom

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func CreateBloom

func CreateBloom(receipts []*Receipt) Bloom

func (*Bloom) Add

func (b *Bloom) Add(d *big.Int)

Add adds d to the filter. Future calls of Test(d) will return true.

func (Bloom) Big

func (b Bloom) Big() *big.Int

Big converts b to a big integer.

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

func (Bloom) MarshalText

func (b Bloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (Bloom) Test

func (b Bloom) Test(test *big.Int) bool

func (Bloom) TestBytes

func (b Bloom) TestBytes(test []byte) bool

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

UnmarshalText b as a hex string with 0x prefix.

type CancelCredit

type CancelCredit struct {
	CancelCreditHeight uint64
	CancelCreditValue  []big.Int
}

type CandidateData

type CandidateData struct {
	Pubkey *secp256k1.PublicKey //出块节点的pubkey
	Node   string               //出块节点的地址
}

候选节点数据部分信息

func (*CandidateData) Marshal

func (cd *CandidateData) Marshal() ([]byte, error)

func (*CandidateData) Unmarshal

func (cd *CandidateData) Unmarshal(data []byte) error

type ChainEvent

type ChainEvent struct {
	Block *Block
	Hash  crypto.Hash
	Logs  []*Log
}

type ChainHeadEvent

type ChainHeadEvent struct{ Block *Block }

type ChainIdType

type ChainIdType uint32

func (ChainIdType) Bytes

func (chainId ChainIdType) Bytes() []byte

type ChainSideEvent

type ChainSideEvent struct {
	Block *Block
}

type CrossChainTransaction

type CrossChainTransaction struct {
	ChainId   ChainIdType
	StateRoot []byte
	Trans     []*Transaction
}

type ExecuteTransactionResult

type ExecuteTransactionResult struct {
	TxResult              []byte               //Transaction execution results
	ContractTxExecuteFail bool                 //contract transaction execution results
	ContractTxLog         []*Log               //contract transaction execution logs
	Txerror               error                //transaction execution fail info
	ContractAddr          crypto.CommonAddress //create new contract address
}

type HeaderReq

type HeaderReq struct {
	FromHeight uint64
	ToHeight   uint64
}

type HeaderRsp

type HeaderRsp struct {
	//Heights []uint64
	Headers []BlockHeader
}

type HeightValue

type HeightValue struct {
	CreditHeight uint64
	CreditValue  common.Big
}

某个高度对应的某creadit value

type IntersetDetail

type IntersetDetail struct {
	PrincipalData []HeightValue
	IntersetData  []HeightValue
}

func (IntersetDetail) Error

func (IntersetDetail) Error() string

type Log

type Log struct {
	TxType TxType
	// Consensus fields:
	// address of the contract that generated the event
	Address crypto.CommonAddress
	// list of topics provided by the contract.
	Topics []crypto.Hash
	// supplied by the contract, usually ABI-encoded
	Data []byte

	// Derived fields. These fields are filled in by the node but not secured by consensus.
	ChainId ChainIdType
	// hash of the transaction
	TxHash crypto.Hash
	// block in which the transaction was included
	Height uint64
	// index of the transaction in the block
	TxIndex uint

	// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool
}

type Message

type Message struct {
	To         *crypto.CommonAddress
	From       *crypto.CommonAddress
	Nonce      uint64
	Amount     *big.Int
	GasLimit   uint64
	GasPrice   *big.Int
	Data       []byte
	CheckNonce bool
}

type NewMinedBlockEvent

type NewMinedBlockEvent struct{ Block *Block }

NewMinedBlockEvent is posted when a block has been imported.

type NewTxsEvent

type NewTxsEvent struct{ Txs []*Transaction }

NewTxsEvent is posted when a batch of transactions enter the transaction pool.

type Node

type Node struct {
	Address    *crypto.CommonAddress
	PrivateKey *secp256k1.PrivateKey
	ChainId    ChainIdType
	ChainCode  []byte
}

func NewNode

func NewNode(parent *Node, chainId ChainIdType) *Node

type OrphanBlock

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

orphanBlock represents a block that we don't yet have the parent for. It is a normal block plus an expiration time to prevent caching the orphan forever.

type PeerInfo

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

业务层peerknown blk height:

func NewPeerInfo

func NewPeerInfo(p *p2p.Peer, rw p2p.MsgReadWriter) *PeerInfo

func (*PeerInfo) AverageRtt

func (peer *PeerInfo) AverageRtt() time.Duration

func (*PeerInfo) CalcAverageRtt

func (peer *PeerInfo) CalcAverageRtt()

func (*PeerInfo) GetAddr

func (peer *PeerInfo) GetAddr() string

func (*PeerInfo) GetHeight

func (peer *PeerInfo) GetHeight() uint64

func (*PeerInfo) GetMsgRW

func (peer *PeerInfo) GetMsgRW() p2p.MsgReadWriter

获取读写句柄

func (*PeerInfo) KnownBlock

func (peer *PeerInfo) KnownBlock(blk *Block) bool

func (*PeerInfo) KnownTx

func (peer *PeerInfo) KnownTx(tx *Transaction) bool

peer端是否已经知道此tx

func (*PeerInfo) MarkBlock

func (peer *PeerInfo) MarkBlock(blk *Block)

记录block,以免多次同步块

func (*PeerInfo) MarkTx

func (peer *PeerInfo) MarkTx(tx *Transaction)

记录对应的tx,避免多次相互发送

func (*PeerInfo) SetHeight

func (peer *PeerInfo) SetHeight(height uint64)

func (*PeerInfo) SetReqTime

func (peer *PeerInfo) SetReqTime(t time.Time)

type PeerInfoInterface

type PeerInfoInterface interface {
	GetMsgRW() p2p.MsgReadWriter
	GetHeight() uint64
	GetAddr() string

	SetHeight(height uint64)
	KnownTx(tx *Transaction) bool
	MarkTx(tx *Transaction)
	KnownBlock(blk *Block) bool
	MarkBlock(blk *Block)

	SetReqTime(t time.Time)
	CalcAverageRtt()
	AverageRtt() time.Duration
}

type PeerState

type PeerState struct {
	Height uint64
}

type PeerStateReq

type PeerStateReq struct {
	Height uint64
}

type PendingLogsEvent

type PendingLogsEvent struct {
	Logs []*Log
}

PendingLogsEvent is posted pre mining and notifies of pending logs.

type Proof

type Proof struct {
	Type     int
	Evidence []byte
}

type Receipt

type Receipt struct {
	// Consensus fields
	PostState         []byte
	Status            uint64
	CumulativeGasUsed uint64
	Logs              []*Log
	Bloom             Bloom

	// Implementation fields (don't reorder!)
	TxHash          crypto.Hash
	ContractAddress crypto.CommonAddress
	GasUsed         uint64

	// Inclusion information: These fields provide information about the inclusion of the
	// transaction corresponding to this receipt.
	BlockHash   crypto.Hash
	BlockNumber uint64
}

Receipt represents the results of a transaction.

func NewReceipt

func NewReceipt(root []byte, failed bool, cumulativeGasUsed uint64) *Receipt

NewReceipt creates a barebone transaction receipt, copying the init fields.

func (*Receipt) ReceiptHash

func (r *Receipt) ReceiptHash() *crypto.Hash

type Receipts

type Receipts []*Receipt

Receipts is a wrapper around a Receipt array to implement DerivableList.

func (Receipts) Len

func (r Receipts) Len() int

Len returns the number of receipts in this list.

type ReceivedCredit

type ReceivedCredit struct {
	Addr        crypto.CommonAddress
	HeghtValues []HeightValue
}

type RemovedLogsEvent

type RemovedLogsEvent struct{ Logs []*Log }

RemovedLogsEvent is posted when a reorg happens

type StakeStorage

type StakeStorage struct {
	RC []ReceivedCredit

	//撤销给与别人的信任数据存放于此;
	//CancelCreditHeight []uint64
	//CancelCreditValue  []big.Int
	CC []CancelCredit

	CandidateData []byte //注册候选节点时,需要携带的pubkey/ip等信息
}

type Storage

type Storage struct {
	Balance    big.Int
	Reputation big.Int

	Nonce uint64
	//contract
	ByteCode crypto.ByteCode
	CodeHash crypto.Hash

	Alias      string
	BalanceMap map[string]big.Int
}

func (*Storage) Empty

func (s *Storage) Empty() bool

type Transaction

type Transaction struct {
	Data TransactionData
	Sig  []byte
	// contains filtered or unexported fields
}

func NewAliasTransaction

func NewAliasTransaction(alias string, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction

给地址srcAddr设置别名

func NewCallContractTransaction

func NewCallContractTransaction(to crypto.CommonAddress, input []byte, amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction

func NewCancelVoteTransaction

func NewCancelVoteTransaction(to crypto.CommonAddress, amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction

func NewCancleCandidateTransaction

func NewCancleCandidateTransaction(amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction

func NewCandidateTransaction

func NewCandidateTransaction(amount, gasPrice, gasLimit *big.Int, nonce uint64, data []byte) *Transaction

func NewContractTransaction

func NewContractTransaction(byteCode []byte, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction

func NewTransaction

func NewTransaction(to crypto.CommonAddress, amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction

func NewVoteTransaction

func NewVoteTransaction(to crypto.CommonAddress, amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction

func (*Transaction) Amount

func (tx *Transaction) Amount() *big.Int

func (*Transaction) AsPersistentMessage

func (tx *Transaction) AsPersistentMessage() []byte

func (*Transaction) AsSignMessage

func (tx *Transaction) AsSignMessage() []byte

func (*Transaction) ChainId

func (tx *Transaction) ChainId() ChainIdType

func (*Transaction) Cost

func (tx *Transaction) Cost() *big.Int

func (*Transaction) From

func (tx *Transaction) From() (*crypto.CommonAddress, error)

func (*Transaction) Gas

func (tx *Transaction) Gas() uint64

func (*Transaction) GasLimit

func (tx *Transaction) GasLimit() *big.Int

func (*Transaction) GasPrice

func (tx *Transaction) GasPrice() *big.Int

func (*Transaction) GetData

func (tx *Transaction) GetData() []byte

func (*Transaction) GetSig

func (tx *Transaction) GetSig() []byte

func (*Transaction) IntrinsicGas

func (tx *Transaction) IntrinsicGas() (uint64, error)

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

func (*Transaction) Time

func (tx *Transaction) Time() int64

func (*Transaction) To

func (tx *Transaction) To() *crypto.CommonAddress

func (*Transaction) TxHash

func (tx *Transaction) TxHash() *crypto.Hash

func (*Transaction) Type

func (tx *Transaction) Type() TxType

type TransactionData

type TransactionData struct {
	Version   int32
	Nonce     uint64 //交易序列号
	Type      TxType
	To        crypto.CommonAddress
	ChainId   ChainIdType
	Amount    common.Big
	GasPrice  common.Big
	GasLimit  common.Big
	Timestamp int64
	Data      []byte
}

type Transactions

type Transactions []Transaction

type TxType

type TxType uint64
const (
	TransferType TxType = iota

	CreateContractType
	CallContractType

	SetAliasType         //给地址设置昵称
	VoteCreditType       //质押给别人
	CancelVoteCreditType //撤销质押币
	CandidateType        //申请成为候选出块节点
	CancelCandidateType  //申请成为候选出块节点
	RegisterProducer
)

Jump to

Keyboard shortcuts

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