core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2019 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2019 Annchain Authors <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const MaxAccountCount = 255

Variables

View Source
var (
	DefaultGasLimit = uint64(10000000000)

	DefaultCoinbase = types.HexToAddress("0x1234567812345678AABBCCDDEEFF998877665544")
)

Functions

func DefaultGenesis

func DefaultGenesis(cryptoType crypto.CryptoType, genesisPath string) (*types.Sequencer, map[types.Address]*math.BigInt)

func GetSampleAccounts

func GetSampleAccounts(cryptoType crypto.CryptoType) []*account.SampleAccount

Types

type Accessor

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

func NewAccessor

func NewAccessor(db ogdb.Database) *Accessor

func (*Accessor) AddBalance

func (da *Accessor) AddBalance(addr types.Address, amount *math.BigInt) error

AddBalance adds an amount of value to the address balance. Note that AddBalance doesn't hold any locks so upper level program must manage this.

func (*Accessor) DeleteBalance

func (da *Accessor) DeleteBalance(addr types.Address) error

DeleteBalance delete the balance of an address.

func (*Accessor) DeleteTransaction

func (da *Accessor) DeleteTransaction(hash types.Hash) error

DeleteTransaction delete the tx or sequencer.

func (*Accessor) HasAddrLatestNonce

func (da *Accessor) HasAddrLatestNonce(addr types.Address) (bool, error)

HasAddrLatestNonce returns true if addr already sent some txs.

func (*Accessor) ReadAddrLatestNonce

func (da *Accessor) ReadAddrLatestNonce(addr types.Address) (uint64, error)

ReadAddrLatestNonce get latest nonce of an address

func (*Accessor) ReadBalance

func (da *Accessor) ReadBalance(addr types.Address) *math.BigInt

ReadBalance get the balance of an address.

func (*Accessor) ReadGenesis

func (da *Accessor) ReadGenesis() *types.Sequencer

ReadGenesis get genesis sequencer from db. return nil if there is no genesis.

func (*Accessor) ReadIndexedTxHashs

func (da *Accessor) ReadIndexedTxHashs(SeqHeight uint64) (*types.Hashes, error)

ReadIndexedTxHashs get a list of txs that is confirmed by the sequencer that holds the id 'SeqHeight'.

func (*Accessor) ReadLatestSequencer

func (da *Accessor) ReadLatestSequencer() *types.Sequencer

ReadLatestSequencer get latest sequencer from db. return nil if there is no sequencer.

func (*Accessor) ReadReceipt

func (da *Accessor) ReadReceipt(seqID uint64, hash types.Hash) *Receipt

ReadReceipt try get receipt by tx hash and seqID.

func (*Accessor) ReadSequencerByHeight

func (da *Accessor) ReadSequencerByHeight(SeqHeight uint64) (*types.Sequencer, error)

ReadSequencerByHeight get sequencer from db by sequencer id.

func (*Accessor) ReadTransaction

func (da *Accessor) ReadTransaction(hash types.Hash) types.Txi

ReadTransaction get tx or sequencer from ogdb.

func (*Accessor) ReadTxByNonce

func (da *Accessor) ReadTxByNonce(addr types.Address, nonce uint64) types.Txi

ReadTxByNonce get tx from db by sender's address and nonce.

func (*Accessor) SetBalance

func (da *Accessor) SetBalance(addr types.Address, value *math.BigInt) error

SetBalance write the balance of an address into ogdb. Data will be overwritten if it already exist in db.

func (*Accessor) SubBalance

func (da *Accessor) SubBalance(addr types.Address, amount *math.BigInt) error

SubBalance subs an amount of value to the address balance. Note that SubBalance doesn't hold any locks so upper level program must manage this.

func (*Accessor) WriteGenesis

func (da *Accessor) WriteGenesis(genesis *types.Sequencer) error

WriteGenesis writes geneis into db.

func (*Accessor) WriteIndexedTxHashs

func (da *Accessor) WriteIndexedTxHashs(SeqHeight uint64, hashs *types.Hashes) error

WriteIndexedTxHashs stores a list of tx hashs. These related hashs are all confirmed by sequencer that holds the id 'SeqHeight'.

func (*Accessor) WriteLatestSequencer

func (da *Accessor) WriteLatestSequencer(seq *types.Sequencer) error

WriteGenesis writes latest sequencer into db.

func (*Accessor) WriteReceipts

func (da *Accessor) WriteReceipts(seqID uint64, receipts ReceiptSet) error

WriteReceipts write a receipt map into db.

func (*Accessor) WriteSequencerByHeight

func (da *Accessor) WriteSequencerByHeight(seq *types.Sequencer) error

WriteSequencerByHeight stores the sequencer into db and indexed by its id.

func (*Accessor) WriteTransaction

func (da *Accessor) WriteTransaction(putter ogdb.Putter, tx types.Txi) error

WriteTransaction write the tx or sequencer into ogdb.

func (*Accessor) WriteTxHashByNonce

func (da *Accessor) WriteTxHashByNonce(addr types.Address, nonce uint64, hash types.Hash) error

WriteTxHashByNonce writes tx hash into db and construct key with address and nonce.

type Account

type Account struct {
	Address string `json:"address"`
	Balance uint64 `json:"balance"`
	// contains filtered or unexported fields
}

type AccountFlow

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

AccountFlow stores the information about an address. It includes the balance state of the account among the txpool,

func NewAccountFlow

func NewAccountFlow(originBalance *math.BigInt) *AccountFlow

func (*AccountFlow) Add

func (af *AccountFlow) Add(tx types.Txi) error

Add new tx into account flow. This function should 1. update account's balance state. 2. add tx into nonce sorted txlist.

func (*AccountFlow) BalanceState

func (af *AccountFlow) BalanceState() *BalanceState

func (*AccountFlow) GetTx

func (af *AccountFlow) GetTx(nonce uint64) types.Txi

GetTx get a tx from accountflow.

func (*AccountFlow) LatestNonce

func (af *AccountFlow) LatestNonce() (uint64, error)

LatestNonce returns the largest nonce stored in txlist.

func (*AccountFlow) Len

func (af *AccountFlow) Len() int

return the count of txs sent by this account.

func (*AccountFlow) Remove

func (af *AccountFlow) Remove(nonce uint64) error

Remove a tx from account flow, find tx by nonce first, then rolls back the balance and remove tx from txlist.

func (*AccountFlow) TxList

func (af *AccountFlow) TxList() *TxList

type AccountFlows

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

func NewAccountFlows

func NewAccountFlows() *AccountFlows

func (*AccountFlows) Add

func (a *AccountFlows) Add(tx types.Txi)

func (*AccountFlows) Get

func (a *AccountFlows) Get(addr types.Address) *AccountFlow

func (*AccountFlows) GetBalanceState

func (a *AccountFlows) GetBalanceState(addr types.Address) *BalanceState

func (*AccountFlows) GetLatestNonce

func (a *AccountFlows) GetLatestNonce(addr types.Address) (uint64, error)

func (*AccountFlows) GetTxByNonce

func (a *AccountFlows) GetTxByNonce(addr types.Address, nonce uint64) types.Txi

func (*AccountFlows) Remove

func (a *AccountFlows) Remove(tx types.Txi)

func (*AccountFlows) ResetFlow

func (a *AccountFlows) ResetFlow(addr types.Address, originBalance *math.BigInt)

type BalanceState

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

func NewBalanceState

func NewBalanceState(balance *math.BigInt) *BalanceState

func (*BalanceState) OriginBalance

func (bs *BalanceState) OriginBalance() *math.BigInt

func (*BalanceState) Spent

func (bs *BalanceState) Spent() *math.BigInt

func (*BalanceState) TryRemoveValue

func (bs *BalanceState) TryRemoveValue(txValue *math.BigInt) error

TryRemoveValue is called when remove a tx from pool. It reduce the total spent by the value of removed tx.

func (*BalanceState) TrySubBalance

func (bs *BalanceState) TrySubBalance(value *math.BigInt) error

TrySubBalance checks if origin balance is enough for total spent of txs in pool. It trys to add new spent "value" into total spent and compare total spent with origin balance.

type BatchDetail

type BatchDetail struct {
	TxList *TxList
	Neg    *math.BigInt
	Pos    *math.BigInt
}

BatchDetail describes all the details of a specific address within a sequencer confirmation term. - TxList - represents the txs sent by this addrs, ordered by nonce. - Neg - means the amount this address should spent out. - Pos - means the amount this address get paid.

type ConfirmBatch

type ConfirmBatch struct {
	Seq *types.Sequencer
	Txs types.Txis
}

type Dag

type Dag struct {
	OnConsensusTXConfirmed chan []types.Txi
	// contains filtered or unexported fields
}

func NewDag

func NewDag(conf DagConfig, stateDBConfig state.StateDBConfig, db ogdb.Database, oldDb ogdb.Database, cryptoType crypto.CryptoType) (*Dag, error)

func (*Dag) Accessor

func (dag *Dag) Accessor() *Accessor

Accessor returns the db accessor of dag

func (*Dag) CallContract

func (dag *Dag) CallContract(addr types.Address, data []byte) ([]byte, error)

CallContract calls contract but disallow any modifications on statedb. This method will call ovm.StaticCall() to satisfy this.

func (*Dag) DeleteTransaction

func (dag *Dag) DeleteTransaction(hash types.Hash) error

func (*Dag) Exist

func (dag *Dag) Exist(addr types.Address) bool

func (*Dag) Finalize

func (dag *Dag) Finalize() error

Finalize

func (*Dag) Genesis

func (dag *Dag) Genesis() *types.Sequencer

Genesis returns the genesis tx of dag

func (*Dag) GetBalance

func (dag *Dag) GetBalance(addr types.Address) *math.BigInt

GetBalance read the confirmed balance of an address from ogdb.

func (*Dag) GetConfirmTime

func (dag *Dag) GetConfirmTime(seqHeight uint64) *types.ConfirmTime

func (*Dag) GetHeight

func (dag *Dag) GetHeight() uint64

GetHeight get cuurent height

func (*Dag) GetLatestNonce

func (dag *Dag) GetLatestNonce(addr types.Address) (uint64, error)

GetLatestNonce returns the latest tx of an addresss.

func (*Dag) GetOldTx

func (dag *Dag) GetOldTx(addr types.Address, nonce uint64) types.Txi

func (*Dag) GetReceipt

func (dag *Dag) GetReceipt(hash types.Hash) *Receipt

func (*Dag) GetSequencer

func (dag *Dag) GetSequencer(hash types.Hash, seqHeight uint64) *types.Sequencer

func (*Dag) GetSequencerByHash

func (dag *Dag) GetSequencerByHash(hash types.Hash) *types.Sequencer

func (*Dag) GetSequencerByHeight

func (dag *Dag) GetSequencerByHeight(height uint64) *types.Sequencer

func (*Dag) GetSequencerHashByHeight

func (dag *Dag) GetSequencerHashByHeight(height uint64) *types.Hash

func (*Dag) GetState

func (dag *Dag) GetState(addr types.Address, key types.Hash) types.Hash

GetState get contract's state from statedb.

func (*Dag) GetTx

func (dag *Dag) GetTx(hash types.Hash) types.Txi

GetTx gets tx from dag network indexed by tx hash. This function querys ogdb only.

func (*Dag) GetTxByNonce

func (dag *Dag) GetTxByNonce(addr types.Address, nonce uint64) types.Txi

GetTxByNonce gets tx from dag by sender's address and tx nonce

func (*Dag) GetTxConfirmHeight

func (dag *Dag) GetTxConfirmHeight(hash types.Hash) (uint64, error)

GetTxConfirmHeight returns the height of sequencer that confirm this tx.

func (*Dag) GetTxis

func (dag *Dag) GetTxis(hashs types.Hashes) types.Txis

GetTxs get a bundle of txs according to a hash list.

func (*Dag) GetTxisByNumber

func (dag *Dag) GetTxisByNumber(height uint64) types.Txis

func (*Dag) GetTxsByAddress

func (dag *Dag) GetTxsByAddress(addr types.Address) []types.Txi

GetTxsByAddress get all txs from this address

func (*Dag) GetTxsByNumberAndType

func (dag *Dag) GetTxsByNumberAndType(height uint64, txType types.TxBaseType) types.Txis

func (*Dag) GetTxsHashesByNumber

func (dag *Dag) GetTxsHashesByNumber(Height uint64) *types.Hashes

func (*Dag) Has

func (dag *Dag) Has(hash types.Hash) bool

func (*Dag) Init

func (dag *Dag) Init(genesis *types.Sequencer, genesisBalance map[types.Address]*math.BigInt) error

Init inits genesis sequencer and genesis state of the network.

func (*Dag) LatestSequencer

func (dag *Dag) LatestSequencer() *types.Sequencer

LatestSequencer returns the latest sequencer stored in dag

func (*Dag) LoadLastState

func (dag *Dag) LoadLastState() (bool, types.Hash)

LoadLastState load genesis and latestsequencer data from ogdb. return false if there is no genesis stored in the db.

func (*Dag) LoadStateRoot

func (dag *Dag) LoadStateRoot() types.Hash

TODO This is a temp function to solve the not working problem when restart the node. The perfect solution is to load the root from latest sequencer every time restart the node.

func (*Dag) ProcessTransaction

func (dag *Dag) ProcessTransaction(tx types.Txi) ([]byte, *Receipt, error)

ProcessTransaction execute the tx and update the data in statedb.

Besides balance and nonce, if a tx is trying to create or call a contract, vm part will be initiated to handle this.

func (*Dag) Push

func (dag *Dag) Push(batch *ConfirmBatch) error

Push trys to move a tx from tx pool to dag db.

func (*Dag) ReadConfirmTime

func (dag *Dag) ReadConfirmTime(seqHeight uint64) *types.ConfirmTime

func (*Dag) RollBack

func (dag *Dag) RollBack()

RollBack rolls back the dag network.

func (*Dag) SaveStateRoot

func (dag *Dag) SaveStateRoot()

TODO This is a temp function to solve the not working problem when restart the node. The perfect solution is to load the root from latest sequencer every time restart the node.

func (*Dag) Start

func (dag *Dag) Start()

func (*Dag) StateDatabase

func (dag *Dag) StateDatabase() *state.StateDB

StateDatabase is for testing only

func (*Dag) Stop

func (dag *Dag) Stop()

func (*Dag) WriteTransaction

func (dag *Dag) WriteTransaction(putter ogdb.Putter, tx types.Txi) error

WriteTransaction write the tx or sequencer into ogdb. It first writes the latest nonce of the tx's sender, then write the ([address, nonce] -> hash) relation into db, finally write the tx itself. Data will be overwritten if it already exists in db.

type DagConfig

type DagConfig struct {
	GenesisPath string
}

func DefaultDagConfig

func DefaultDagConfig() DagConfig

type GenesisAccounts

type GenesisAccounts struct {
	Accounts []Account `json:"accounts"`
}

func GetGenesisAccounts

func GetGenesisAccounts(cryptoType crypto.CryptoType, genesisPath string) *GenesisAccounts

type Receipt

type Receipt struct {
	TxHash          types.Hash
	Status          ReceiptStatus
	ProcessResult   string
	ContractAddress types.Address
}

func NewReceipt

func NewReceipt(hash types.Hash, status ReceiptStatus, pResult string, addr types.Address) *Receipt

func (*Receipt) DecodeMsg

func (z *Receipt) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (*Receipt) EncodeMsg

func (z *Receipt) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (*Receipt) MarshalMsg

func (z *Receipt) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (*Receipt) Msgsize

func (z *Receipt) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*Receipt) ToJsonMap

func (r *Receipt) ToJsonMap() map[string]string

func (*Receipt) UnmarshalMsg

func (z *Receipt) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ReceiptSet

type ReceiptSet map[string]*Receipt

func (*ReceiptSet) DecodeMsg

func (z *ReceiptSet) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (ReceiptSet) EncodeMsg

func (z ReceiptSet) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (ReceiptSet) MarshalMsg

func (z ReceiptSet) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (ReceiptSet) Msgsize

func (z ReceiptSet) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ReceiptSet) UnmarshalMsg

func (z *ReceiptSet) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type ReceiptStatus

type ReceiptStatus int
const (
	ReceiptStatusSeqSuccess ReceiptStatus = iota
	ReceiptStatusTxSuccess
	ReceiptStatusOVMFailed
	ReceiptStatusCampaignSuccess
	ReceiptStatusTermChangeSuccess
)

func (*ReceiptStatus) DecodeMsg

func (z *ReceiptStatus) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (ReceiptStatus) EncodeMsg

func (z ReceiptStatus) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (ReceiptStatus) MarshalMsg

func (z ReceiptStatus) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (ReceiptStatus) Msgsize

func (z ReceiptStatus) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*ReceiptStatus) UnmarshalMsg

func (z *ReceiptStatus) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type TxList

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

func NewTxList

func NewTxList() *TxList

func (*TxList) Get

func (t *TxList) Get(nonce uint64) types.Txi

func (*TxList) Len

func (t *TxList) Len() int

func (*TxList) Put

func (t *TxList) Put(txi types.Txi)

func (*TxList) Remove

func (t *TxList) Remove(nonce uint64) bool

type TxMap

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

func NewTxMap

func NewTxMap() *TxMap

func (*TxMap) Add

func (tm *TxMap) Add(tx types.Txi)

func (*TxMap) Count

func (tm *TxMap) Count() int

func (*TxMap) Exists

func (tm *TxMap) Exists(tx types.Txi) bool

func (*TxMap) Get

func (tm *TxMap) Get(hash types.Hash) types.Txi

func (*TxMap) GetAllKeys

func (tm *TxMap) GetAllKeys() types.Hashes

func (*TxMap) GetAllValues

func (tm *TxMap) GetAllValues() []types.Txi

func (*TxMap) Remove

func (tm *TxMap) Remove(hash types.Hash)

type TxPool

type TxPool struct {
	OnConsensusTXConfirmed []chan map[types.Hash]types.Txi // for notifications of  consensus tx confirmation.
	OnBatchConfirmed       []chan map[types.Hash]types.Txi // for notifications of confirmation.
	OnNewLatestSequencer   []chan bool                     //for broadcasting new latest sequencer to record height
	// contains filtered or unexported fields
}

func NewTxPool

func NewTxPool(conf TxPoolConfig, d *Dag) *TxPool

func (*TxPool) AddLocalTx

func (pool *TxPool) AddLocalTx(tx types.Txi, noFeedBack bool) error

AddLocalTx adds a tx to txpool if it is valid, note that if success it returns nil. AddLocalTx only process tx that sent by local node.

func (*TxPool) AddLocalTxs

func (pool *TxPool) AddLocalTxs(txs []types.Txi, noFeedBack bool) []error

AddLocalTxs adds a list of txs to txpool if they are valid. It returns the process result of each tx with an error list. AddLocalTxs only process txs that sent by local node.

func (*TxPool) AddRemoteTx

func (pool *TxPool) AddRemoteTx(tx types.Txi, noFeedBack bool) error

AddRemoteTx adds a tx to txpool if it is valid. AddRemoteTx only process tx sent by remote nodes, and will hold extra functions to prevent from ddos (large amount of invalid tx sent from one node in a short time) attack.

func (*TxPool) AddRemoteTxs

func (pool *TxPool) AddRemoteTxs(txs []types.Txi, noFeedBack bool) []error

AddRemoteTxs works as same as AddRemoteTx but processes a list of txs

func (*TxPool) ClearAll

func (pool *TxPool) ClearAll()

ClearAll removes all the txs in the pool.

Note that ClearAll should only be called when solving conflicts during a sequencer confirmation time.

func (*TxPool) Get

func (pool *TxPool) Get(hash types.Hash) types.Txi

Get get a transaction or sequencer according to input hash, if tx not exists return nil

func (*TxPool) GetAllTips

func (pool *TxPool) GetAllTips() map[types.Hash]types.Txi

GetAllTips returns all the tips in TxPool.

func (*TxPool) GetBenchmarks

func (pool *TxPool) GetBenchmarks() map[string]interface{}

func (*TxPool) GetByNonce

func (pool *TxPool) GetByNonce(addr types.Address, nonce uint64) types.Txi

GetByNonce get a tx or sequencer from account flows by sender's address and tx's nonce.

func (*TxPool) GetHashOrder

func (pool *TxPool) GetHashOrder() types.Hashes

GetHashOrder returns a hash list of txs in pool, ordered by the time that txs added into pool.

func (*TxPool) GetLatestNonce

func (pool *TxPool) GetLatestNonce(addr types.Address) (uint64, error)

GetLatestNonce get the latest nonce of an address

func (*TxPool) GetMaxWeight

func (pool *TxPool) GetMaxWeight() uint64

func (*TxPool) GetRandomTips

func (pool *TxPool) GetRandomTips(n int) (v []types.Txi)

GetRandomTips returns n tips randomly.

func (*TxPool) GetStatus

func (pool *TxPool) GetStatus(hash types.Hash) TxStatus

GetStatus gets the current status of a tx

func (*TxPool) GetTxNum

func (pool *TxPool) GetTxNum() uint32

func (*TxPool) Has

func (pool *TxPool) Has(hash types.Hash) bool

func (*TxPool) Init

func (pool *TxPool) Init(genesis *types.Sequencer)

func (*TxPool) IsLocalHash

func (pool *TxPool) IsLocalHash(hash types.Hash) bool

func (*TxPool) Name

func (pool *TxPool) Name() string

func (*TxPool) PoolStatus

func (pool *TxPool) PoolStatus() (int, int, int)

PoolStatus returns the current number of tips, bad txs and pending txs stored in pool.

func (*TxPool) RegisterOnNewTxReceived

func (pool *TxPool) RegisterOnNewTxReceived(c chan types.Txi, chanName string, allTx bool)

func (*TxPool) Remove

func (pool *TxPool) Remove(tx types.Txi, removeType hashOrderRemoveType)

Remove totally removes a tx from pool, it checks badtxs, tips, pendings and txlookup.

func (*TxPool) Start

func (pool *TxPool) Start()

Start begin the txpool sevices

func (*TxPool) Stop

func (pool *TxPool) Stop()

Stop stops all the txpool sevices

type TxPoolConfig

type TxPoolConfig struct {
	QueueSize              int `mapstructure:"queue_size"`
	TipsSize               int `mapstructure:"tips_size"`
	ResetDuration          int `mapstructure:"reset_duration"`
	TxVerifyTime           int `mapstructure:"tx_verify_time"`
	TxValidTime            int `mapstructure:"tx_valid_time"`
	TimeOutPoolQueue       int `mapstructure:"timeout_pool_queue_ms"`
	TimeoutSubscriber      int `mapstructure:"timeout_subscriber_ms"`
	TimeoutConfirmation    int `mapstructure:"timeout_confirmation_ms"`
	TimeoutLatestSequencer int `mapstructure:"timeout_latest_seq_ms"`
}

func DefaultTxPoolConfig

func DefaultTxPoolConfig() TxPoolConfig

type TxQuality

type TxQuality int
const (
	TxQualityIsBad TxQuality = iota
	TxQualityIsGood
	TxQualityIsFatal
)

type TxStatus

type TxStatus int
const (
	TxStatusNotExist TxStatus = iota
	TxStatusQueue
	TxStatusTip
	TxStatusBadTx
	TxStatusPending
)

func (*TxStatus) String

func (ts *TxStatus) String() string

type TxType

type TxType int
const (
	TxTypeGenesis TxType = iota
	TxTypeLocal
	TxTypeRemote
	TxTypeRejudge
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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