Documentation ¶
Index ¶
- Constants
- Variables
- func BloomLookup(bin Bloom, topic bytesBacked) bool
- func InitBlockNode(node *BlockNode, blockHeader *BlockHeader, parent *BlockNode)
- func LogsBloom(logs []*Log) *big.Int
- type Account
- type BestState
- type Block
- type BlockData
- type BlockHeader
- type BlockNode
- type BlockReq
- type BlockResp
- type BlockStatus
- type Bloom
- func (b *Bloom) Add(d *big.Int)
- func (b Bloom) Big() *big.Int
- func (b Bloom) Bytes() []byte
- func (b Bloom) MarshalText() ([]byte, error)
- func (b *Bloom) SetBytes(d []byte)
- func (b Bloom) Test(test *big.Int) bool
- func (b Bloom) TestBytes(test []byte) bool
- func (b *Bloom) UnmarshalText(input []byte) error
- type CancelCredit
- type CandidateData
- type ChainEvent
- type ChainHeadEvent
- type ChainIdType
- type ChainSideEvent
- type CrossChainTransaction
- type ExecuteTransactionResult
- type HeaderReq
- type HeaderRsp
- type HeightValue
- type IntersetDetail
- type Log
- type Message
- type NewMinedBlockEvent
- type NewTxsEvent
- type Node
- type OrphanBlock
- type PeerInfo
- func (peer *PeerInfo) AverageRtt() time.Duration
- func (peer *PeerInfo) CalcAverageRtt()
- func (peer *PeerInfo) GetAddr() string
- func (peer *PeerInfo) GetHeight() uint64
- func (peer *PeerInfo) GetMsgRW() p2p.MsgReadWriter
- func (peer *PeerInfo) KnownBlock(blk *Block) bool
- func (peer *PeerInfo) KnownTx(tx *Transaction) bool
- func (peer *PeerInfo) MarkBlock(blk *Block)
- func (peer *PeerInfo) MarkTx(tx *Transaction)
- func (peer *PeerInfo) SetHeight(height uint64)
- func (peer *PeerInfo) SetReqTime(t time.Time)
- type PeerInfoInterface
- type PeerState
- type PeerStateReq
- type PendingLogsEvent
- type Proof
- type Receipt
- type Receipts
- type ReceivedCredit
- type RemovedLogsEvent
- type StakeStorage
- type Storage
- type Transaction
- func NewAliasTransaction(alias string, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction
- func NewCallContractTransaction(to crypto.CommonAddress, input []byte, amount, gasPrice, gasLimit *big.Int, ...) *Transaction
- func NewCancelVoteTransaction(to crypto.CommonAddress, amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction
- func NewCancleCandidateTransaction(amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction
- func NewCandidateTransaction(amount, gasPrice, gasLimit *big.Int, nonce uint64, data []byte) *Transaction
- func NewContractTransaction(byteCode []byte, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction
- func NewTransaction(to crypto.CommonAddress, amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction
- func NewVoteTransaction(to crypto.CommonAddress, amount, gasPrice, gasLimit *big.Int, nonce uint64) *Transaction
- func (tx *Transaction) Amount() *big.Int
- func (tx *Transaction) AsPersistentMessage() []byte
- func (tx *Transaction) AsSignMessage() []byte
- func (tx *Transaction) ChainId() ChainIdType
- func (tx *Transaction) Cost() *big.Int
- func (tx *Transaction) From() (*crypto.CommonAddress, error)
- func (tx *Transaction) Gas() uint64
- func (tx *Transaction) GasLimit() *big.Int
- func (tx *Transaction) GasPrice() *big.Int
- func (tx *Transaction) GetData() []byte
- func (tx *Transaction) GetSig() []byte
- func (tx *Transaction) IntrinsicGas() (uint64, error)
- func (tx *Transaction) Nonce() uint64
- func (tx *Transaction) Time() int64
- func (tx *Transaction) To() *crypto.CommonAddress
- func (tx *Transaction) TxHash() *crypto.Hash
- func (tx *Transaction) Type() TxType
- type TransactionData
- type Transactions
- type TxType
Constants ¶
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 )
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) )
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 ¶
var ( DrepMark = []byte("Drep Coin Seed") KeyBitSize = 256 >> 3 )
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) )
var Bloom9 = bloom9
var (
ErrOutOfGas = errors.New("out of gas")
)
var NumberOfMsg = 9 //本模块定义的消息个数
Functions ¶
func BloomLookup ¶
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.
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)
type BestState ¶
func NewBestState ¶
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 (*Block) AsSignMessage ¶
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 ¶
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 ¶
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 ¶
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 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 ¶
BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.
func CreateBloom ¶
func (Bloom) MarshalText ¶
MarshalText encodes b as a hex string with 0x prefix.
func (*Bloom) SetBytes ¶
SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.
func (*Bloom) UnmarshalText ¶
UnmarshalText b as a hex string with 0x prefix.
type CancelCredit ¶
type CandidateData ¶
候选节点数据部分信息
func (*CandidateData) Marshal ¶
func (cd *CandidateData) Marshal() ([]byte, error)
func (*CandidateData) Unmarshal ¶
func (cd *CandidateData) Unmarshal(data []byte) error
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 HeaderRsp ¶
type HeaderRsp struct { //Heights []uint64 Headers []BlockHeader }
type HeightValue ¶
某个高度对应的某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 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 ¶
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 (*PeerInfo) CalcAverageRtt ¶
func (peer *PeerInfo) CalcAverageRtt()
func (*PeerInfo) KnownBlock ¶
func (*PeerInfo) SetReqTime ¶
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 PeerStateReq ¶
type PeerStateReq struct {
Height uint64
}
type PendingLogsEvent ¶
type PendingLogsEvent struct {
Logs []*Log
}
PendingLogsEvent is posted pre mining and notifies of pending logs.
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 ¶
NewReceipt creates a barebone transaction receipt, copying the init fields.
func (*Receipt) ReceiptHash ¶
type Receipts ¶
type Receipts []*Receipt
Receipts is a wrapper around a Receipt array to implement DerivableList.
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 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 Transactions ¶
type Transactions []Transaction