core

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 28 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
View Source
const (
	PoolRejudgeThreshold int = 10
)

Variables

View Source
var (
	DefaultGasLimit = uint64(10000000000)

	DefaultCoinbase, _ = ogTypes.HexToAddress20("0x1234567812345678AABBCCDDEEFF998877665544")
)

Functions

func DefaultGenesis

func DefaultGenesis(genesisPath string) (*types.Sequencer, map[ogTypes.AddressKey]*math.BigInt)

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(putter *Putter, addr og_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 og_types.Address) error

DeleteBalance delete the balance of an address.

func (*Accessor) DeleteTransaction

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

deleteTransaction delete the tx or sequencer.

func (*Accessor) HasAddrLatestNonce

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

HasAddrLatestNonce returns true if addr already sent some txs.

func (*Accessor) NewBatch

func (ac *Accessor) NewBatch() *Putter

func (*Accessor) ReadAddrLatestNonce

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

ReadAddrLatestNonce get latest nonce of an address

func (*Accessor) ReadBalance

func (da *Accessor) ReadBalance(addr og_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) ([]og_types.Hash, error)

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

func (*Accessor) ReadLastStateRoot

func (da *Accessor) ReadLastStateRoot() og_types.Hash

ReadLastStateRoot read latest state root from db. TODO this is a temp function. The latest state root should be stored in latest sequencer.

func (*Accessor) ReadLatestConfirmedSeq

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

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

func (*Accessor) ReadReceipt

func (da *Accessor) ReadReceipt(seqID uint64, hash og_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 og_types.Hash) types.Txi

ReadTransaction get tx or sequencer from ogdb.

func (*Accessor) ReadTxByNonce

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

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

func (*Accessor) SetBalance

func (da *Accessor) SetBalance(putter *Putter, addr og_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(putter *Putter, addr og_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(putter *Putter, SeqHeight uint64, hashs []og_types.Hash) error

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

func (*Accessor) WriteLastStateRoot

func (da *Accessor) WriteLastStateRoot(putter *Putter, root og_types.Hash) error

WriteLastStateRoot write latest state root into db. TODO this is a temp function. The latest state root should be stored in latest sequencer.

func (*Accessor) WriteLatestConfirmedSeq

func (da *Accessor) WriteLatestConfirmedSeq(putter *Putter, seq *types.Sequencer) error

WriteLatestConfirmedSeq writes latest sequencer into db.

func (*Accessor) WriteReceipts

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

WriteReceipts write a receipt map into db.

func (*Accessor) WriteSequencerByHeight

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

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

func (*Accessor) WriteTransaction

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

writeTransaction write the tx or sequencer into ogdb.

func (*Accessor) WriteTxHashByNonce

func (da *Accessor) WriteTxHashByNonce(putter *Putter, addr og_types.Address, nonce uint64, hash og_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 state.BalanceSet) *AccountFlow

func NewAccountFlowWithFullData

func NewAccountFlowWithFullData(balanceStates map[int32]*BalanceState, txlist *TxList) *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(tokenID int32) *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) MergeFlow

func (af *AccountFlow) MergeFlow(afToMerge *AccountFlow)

func (*AccountFlow) Remove

func (af *AccountFlow) Remove(txToRemove types.Txi) 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 AccountFlowSet

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

func NewAccountFlowSet

func NewAccountFlowSet(ledger Ledger) *AccountFlowSet

func (*AccountFlowSet) Add

func (a *AccountFlowSet) Add(baseSeqHash og_types.Hash, tx types.Txi)

func (*AccountFlowSet) Get

func (*AccountFlowSet) GetBalanceState

func (a *AccountFlowSet) GetBalanceState(addr og_types.Address, tokenID int32) *BalanceState

func (*AccountFlowSet) GetLatestNonce

func (a *AccountFlowSet) GetLatestNonce(addr og_types.Address) (uint64, error)

func (*AccountFlowSet) GetTxByNonce

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

func (*AccountFlowSet) MergeFlow

func (a *AccountFlowSet) MergeFlow(addr og_types.Address, af *AccountFlow)

func (*AccountFlowSet) Remove

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

func (*AccountFlowSet) ResetFlow

func (a *AccountFlowSet) ResetFlow(addr og_types.Address, originBalance state.BalanceSet)

type BalanceState

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

func NewBalanceState

func NewBalanceState(balance *math.BigInt) *BalanceState

func NewBalanceStateWithFullData

func NewBalanceStateWithFullData(balance *math.BigInt, spent *math.BigInt) *BalanceState

func (*BalanceState) OriginBalance

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

func (*BalanceState) Spent

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

func (*BalanceState) TryProcessTx

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

TryProcessTx 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.

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.

type CachedConfirms

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

type ConfirmBatch

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

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, txProcessor TxProcessor, vmProcessor VmProcessor) (*Dag, error)

func (*Dag) CallContract

func (dag *Dag) CallContract(addr ogTypes.Address20, data []byte) ([]byte, error)

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

func (*Dag) Commit

func (dag *Dag) Commit(seqHash ogTypes.Hash) error

func (*Dag) ConfirmedSequencer

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

func (*Dag) ConfirmedSequencerHash

func (dag *Dag) ConfirmedSequencerHash() ogTypes.Hash

func (*Dag) ExistTx

func (dag *Dag) ExistTx(baseSeqHash ogTypes.Hash, hash ogTypes.Hash) bool

func (*Dag) Genesis

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

Genesis returns the genesis tx of dag

func (*Dag) GetAllTokenBalance

func (dag *Dag) GetAllTokenBalance(baseSeqHash ogTypes.Hash, addr ogTypes.Address) state.BalanceSet

func (*Dag) GetBalance

func (dag *Dag) GetBalance(baseSeqHash ogTypes.Hash, addr ogTypes.Address, tokenID int32) *math.BigInt

func (*Dag) GetConfirmedHeight

func (dag *Dag) GetConfirmedHeight() uint64

func (*Dag) GetConfirmedTx

func (dag *Dag) GetConfirmedTx(hash ogTypes.Hash) types.Txi

func (*Dag) GetHeight

func (dag *Dag) GetHeight() uint64

GetHeight get cuurent height

func (*Dag) GetLatestNonce

func (dag *Dag) GetLatestNonce(baseSeqHash ogTypes.Hash, addr ogTypes.Address) (uint64, error)

GetLatestNonce returns the latest tx of an address.

func (*Dag) GetLatestTokenId

func (dag *Dag) GetLatestTokenId(baseSeqHash ogTypes.Hash) int32

func (*Dag) GetReceipt

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

func (*Dag) GetSequencer

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

func (*Dag) GetSequencerByHash

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

func (*Dag) GetSequencerByHeight

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

GetSequencerByHeight only support those confirmed sequencers

func (*Dag) GetState

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

GetState get contract's state from statedb.

func (*Dag) GetToken

func (dag *Dag) GetToken(baseSeqHash ogTypes.Hash, tokenId int32) *state.TokenObject

func (*Dag) GetTokens

func (dag *Dag) GetTokens(baseSeqHash ogTypes.Hash) []*state.TokenObject

func (*Dag) GetTx

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

GetTx gets tx from dag network indexed by tx hash

func (*Dag) GetTxByNonce

func (dag *Dag) GetTxByNonce(baseSeqHash ogTypes.Hash, addr ogTypes.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 ogTypes.Hash) (uint64, error)

GetTxConfirmHeight returns the height of sequencer that confirm this tx.

func (*Dag) GetTxis

func (dag *Dag) GetTxis(hashs []ogTypes.Hash) types.Txis

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

func (*Dag) GetTxisByHeight

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

func (*Dag) Init

func (dag *Dag) Init(genesis *types.Sequencer, genesisBalance map[ogTypes.AddressKey]*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) LatestSequencerHash

func (dag *Dag) LatestSequencerHash() ogTypes.Hash

func (*Dag) LoadLatestConfirmedSeq

func (dag *Dag) LoadLatestConfirmedSeq() (*types.Sequencer, *types.Sequencer)

LoadLatestConfirmedSeq load genesis and latest confirmed sequencer from db.

func (*Dag) Push

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

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

func (*Dag) RollBack

func (dag *Dag) RollBack()

RollBack rolls back the dag network.

func (*Dag) Speculate

func (dag *Dag) Speculate(pushBatch *PushBatch) (ogTypes.Hash, error)

func (*Dag) Start

func (dag *Dag) Start()

func (*Dag) Stop

func (dag *Dag) Stop()

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(genesisPath string) *GenesisAccounts

type Ledger

type Ledger interface {
	LatestSequencerHash() ogTypes.Hash
	ConfirmedSequencerHash() ogTypes.Hash
	GetBalance(baseSeqHash ogTypes.Hash, addr ogTypes.Address, tokenID int32) *math.BigInt
	GetLatestNonce(baseSeqHash ogTypes.Hash, addr ogTypes.Address) (uint64, error)
}

type LedgerEngine

type LedgerEngine interface {
	GetNonce(ogTypes.Address) uint64
	SetNonce(ogTypes.Address, uint64)
	IssueToken(issuer ogTypes.Address, name, symbol string, reIssuable bool, fstIssue *math.BigInt) (int32, error)
	ReIssueToken(tokenID int32, amount *math.BigInt) error
	DestroyToken(tokenID int32) error

	GetTokenBalance(ogTypes.Address, int32) *math.BigInt
	SubTokenBalance(ogTypes.Address, int32, *math.BigInt)
	AddTokenBalance(ogTypes.Address, int32, *math.BigInt)
}

type OgLedger

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

func (*OgLedger) Commit

func (ol *OgLedger) Commit(seqHash ogTypes.Hash) (err error)

func (*OgLedger) CurrentCommittee

func (ol *OgLedger) CurrentCommittee()

func (*OgLedger) CurrentHeight

func (ol *OgLedger) CurrentHeight() int64

func (*OgLedger) GetConsensusState

func (ol *OgLedger) GetConsensusState()

func (*OgLedger) Push

func (ol *OgLedger) Push(seq *types.Sequencer) (err error)

func (*OgLedger) SetConsensusState

func (ol *OgLedger) SetConsensusState()

func (*OgLedger) Speculate

func (ol *OgLedger) Speculate(proposal Proposal) (stateRoot ogTypes.Hash, err error)

type OgTxProcessor

type OgTxProcessor struct{}

func NewOgTxProcessor

func NewOgTxProcessor() *OgTxProcessor

func (*OgTxProcessor) Process

func (tp *OgTxProcessor) Process(engine LedgerEngine, tx types.Txi) (*Receipt, error)

type OvmProcessor

type OvmProcessor struct{}

func (*OvmProcessor) CanProcess

func (op *OvmProcessor) CanProcess(txi types.Txi) bool

func (*OvmProcessor) Process

func (op *OvmProcessor) Process(statedb VmStateDB, txi types.Txi, height uint64) (*Receipt, error)

type Proposal

type Proposal interface {
	PrevBlock() ogTypes.Hash
}

type PushBatch

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

func (*PushBatch) String

func (c *PushBatch) String() string

type Putter

type Putter struct {
	ogdb.Batch
	// contains filtered or unexported fields
}

func (*Putter) Put

func (p *Putter) Put(key []byte, data []byte) error

func (Putter) Write

func (p Putter) Write() error

type Receipt

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

func ActionTxProcessor

func ActionTxProcessor(engine LedgerEngine, actionTx *types.ActionTx) (*Receipt, error)

func NewReceipt

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

func (*Receipt) MarshalMsg

func (r *Receipt) MarshalMsg() ([]byte, error)

func (*Receipt) MsgSize

func (r *Receipt) MsgSize() int

func (*Receipt) ToJsonMap

func (r *Receipt) ToJsonMap() map[string]interface{}

func (*Receipt) UnmarshalMsg

func (r *Receipt) UnmarshalMsg(b []byte) ([]byte, error)

type ReceiptSet

type ReceiptSet map[ogTypes.HashKey]*Receipt

type ReceiptStatus

type ReceiptStatus uint8
const (
	ReceiptStatusSuccess ReceiptStatus = iota
	ReceiptStatusVMFailed
	ReceiptStatusUnknownTxType
	ReceiptStatusFailed
)

type TxList

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

func NewTxList

func NewTxList() *TxList

func NewTxListByKeySet

func NewTxListByKeySet(txFlow map[uint64]types.Txi, multiKeys ...*nonceHeap) *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
}

---------------------------------------------------- TxMap

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 ogTypes.Hash) types.Txi

func (*TxMap) GetAllKeys

func (tm *TxMap) GetAllKeys() []ogTypes.HashKey

func (*TxMap) GetAllValues

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

func (*TxMap) Remove

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

type TxPool

type TxPool struct {
	OnBatchConfirmed     []chan map[ogTypes.HashKey]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, dag *Dag) *TxPool

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) Confirm

func (pool *TxPool) Confirm(seqHash ogTypes.Hash) error

func (*TxPool) Get

func (pool *TxPool) Get(hash ogTypes.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[ogTypes.HashKey]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 ogTypes.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() []ogTypes.Hash

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 ogTypes.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 ogTypes.Hash) TxStatus

GetStatus gets the current status of a tx

func (*TxPool) GetTxNum

func (pool *TxPool) GetTxNum() int

func (*TxPool) Has

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

func (*TxPool) Init

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

func (*TxPool) IsBadSeq

func (pool *TxPool) IsBadSeq(seq *types.Sequencer) error

func (*TxPool) IsLocalHash

func (pool *TxPool) IsLocalHash(hash ogTypes.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) PreConfirm

func (pool *TxPool) PreConfirm(seq *types.Sequencer) ([]types.Txi, error)

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) SeekElders

func (pool *TxPool) SeekElders(seq *types.Sequencer) ([]types.Txi, map[ogTypes.HashKey]types.Txi, error)

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"`
	ConfirmStatusRefreshTime int //minute
}

func DefaultTxPoolConfig

func DefaultTxPoolConfig() TxPoolConfig

type TxProcessor

type TxProcessor interface {
	Process(engine LedgerEngine, tx types.Txi) (*Receipt, error)
}

type TxQuality

type TxQuality uint8
const (
	TxQualityIsBad TxQuality = iota
	TxQualityIsGood
	TxQualityIsFatal
	TxQualityIgnore
)

type TxStatus

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

func (*TxStatus) String

func (ts *TxStatus) String() string

type TxType

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

type VmProcessor

type VmProcessor interface {
	CanProcess(txi types.Txi) bool
	Process(engine VmStateDB, tx types.Txi, height uint64) (*Receipt, error)
	Call(engine VmStateDB)
}

type VmStateDB

type VmStateDB interface {
	CreateAccount(ogTypes.Address)

	SubBalance(ogTypes.Address, *math.BigInt)
	AddBalance(ogTypes.Address, *math.BigInt)
	// Retrieve the balance from the given address or 0 if object not found
	GetBalance(ogTypes.Address) *math.BigInt

	GetNonce(ogTypes.Address) uint64
	SetNonce(ogTypes.Address, uint64)

	GetCodeHash(ogTypes.Address) ogTypes.Hash
	GetCode(ogTypes.Address) []byte
	SetCode(ogTypes.Address, []byte)
	GetCodeSize(ogTypes.Address) int

	// AddRefund adds gas to the refund counter
	AddRefund(uint64)
	// SubRefund removes gas from the refund counter.
	// This method will panic if the refund counter goes below zero
	SubRefund(uint64)
	// GetRefund returns the current value of the refund counter.
	GetRefund() uint64

	GetCommittedState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
	// GetState retrieves a value from the given account's storage trie.
	GetState(ogTypes.Address, ogTypes.Hash) ogTypes.Hash
	SetState(ogTypes.Address, ogTypes.Hash, ogTypes.Hash)

	// Suicide marks the given account as suicided.
	// This clears the account balance.
	//
	// The account's state object is still available until the state is committed,
	// getStateObject will return a non-nil account after Suicide.
	Suicide(ogTypes.Address) bool
	HasSuicided(ogTypes.Address) bool

	// IsAddressExists reports whether the given account exists in state.
	// Notably this should also return true for suicided accounts.
	Exist(ogTypes.Address) bool
	// Empty returns whether the given account is empty. Empty
	// is defined according to EIP161 (balance = nonce = code = 0).
	Empty(ogTypes.Address) bool

	// RevertToSnapshot reverts all state changes made since the given revision.
	RevertToSnapshot(int)
	// Snapshot creates a new revision
	Snapshot() int

	AddLog(log *vmtypes.Log)
	AddPreimage(ogTypes.Hash, []byte)

	ForEachStorage(ogTypes.Address, func(ogTypes.Hash, ogTypes.Hash) bool)
	// for debug.
	String() string
}

TODO try to delete those useless evm functions in OG. like AddRefund refund functions, Suicide functions, Log and PreImage functions etc.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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