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
- Variables
- func DefaultGenesis(genesisPath string) (*tx_types.Sequencer, map[common.Address]*math.BigInt)
- func GetSampleAccounts() []*account.SampleAccount
- type Accessor
- func (da *Accessor) AddBalance(putter *Putter, addr common.Address, amount *math.BigInt) error
- func (da *Accessor) DeleteBalance(addr common.Address) error
- func (da *Accessor) DeleteTransaction(hash common.Hash) error
- func (da *Accessor) HasAddrLatestNonce(addr common.Address) (bool, error)
- func (ac *Accessor) NewBatch() *Putter
- func (da *Accessor) ReadAddrLatestNonce(addr common.Address) (uint64, error)
- func (da *Accessor) ReadBalance(addr common.Address) *math.BigInt
- func (da *Accessor) ReadGenesis() *tx_types.Sequencer
- func (da *Accessor) ReadIndexedTxHashs(SeqHeight uint64) (*common.Hashes, error)
- func (da *Accessor) ReadLastStateRoot() common.Hash
- func (da *Accessor) ReadLatestSequencer() *tx_types.Sequencer
- func (da *Accessor) ReadReceipt(seqID uint64, hash common.Hash) *Receipt
- func (da *Accessor) ReadSequencerByHeight(SeqHeight uint64) (*tx_types.Sequencer, error)
- func (da *Accessor) ReadTransaction(hash common.Hash) types.Txi
- func (da *Accessor) ReadTxByNonce(addr common.Address, nonce uint64) types.Txi
- func (da *Accessor) SetBalance(putter *Putter, addr common.Address, value *math.BigInt) error
- func (da *Accessor) SubBalance(putter *Putter, addr common.Address, amount *math.BigInt) error
- func (da *Accessor) WriteGenesis(genesis *tx_types.Sequencer) error
- func (da *Accessor) WriteIndexedTxHashs(putter *Putter, SeqHeight uint64, hashs *common.Hashes) error
- func (da *Accessor) WriteLastStateRoot(putter *Putter, root common.Hash) error
- func (da *Accessor) WriteLatestSequencer(putter *Putter, seq *tx_types.Sequencer) error
- func (da *Accessor) WriteReceipts(putter *Putter, seqID uint64, receipts ReceiptSet) error
- func (da *Accessor) WriteSequencerByHeight(putter *Putter, seq *tx_types.Sequencer) error
- func (da *Accessor) WriteTransaction(putter *Putter, tx types.Txi) error
- func (da *Accessor) WriteTxHashByNonce(putter *Putter, addr common.Address, nonce uint64, hash common.Hash) error
- type Account
- type AccountFlow
- func (af *AccountFlow) Add(tx types.Txi) error
- func (af *AccountFlow) BalanceState(tokenID int32) *BalanceState
- func (af *AccountFlow) GetTx(nonce uint64) types.Txi
- func (af *AccountFlow) LatestNonce() (uint64, error)
- func (af *AccountFlow) Len() int
- func (af *AccountFlow) Remove(nonce uint64) error
- func (af *AccountFlow) TxList() *TxList
- type AccountFlows
- func (a *AccountFlows) Add(tx types.Txi)
- func (a *AccountFlows) Get(addr common.Address) *AccountFlow
- func (a *AccountFlows) GetBalanceState(addr common.Address, tokenID int32) *BalanceState
- func (a *AccountFlows) GetLatestNonce(addr common.Address) (uint64, error)
- func (a *AccountFlows) GetTxByNonce(addr common.Address, nonce uint64) types.Txi
- func (a *AccountFlows) Remove(tx types.Txi)
- func (a *AccountFlows) ResetFlow(addr common.Address, originBalance state.BalanceSet)
- type BalanceState
- type BatchDetail
- type ConfirmBatch
- type ConfirmInfo
- type ConfirmStatus
- type Dag
- func (dag *Dag) Accessor() *Accessor
- func (dag *Dag) CallContract(addr common.Address, data []byte) ([]byte, error)
- func (dag *Dag) DeleteTransaction(hash common.Hash) error
- func (dag *Dag) Exist(addr common.Address) bool
- func (dag *Dag) Genesis() *tx_types.Sequencer
- func (dag *Dag) GetAllTokenBalance(addr common.Address) state.BalanceSet
- func (dag *Dag) GetBalance(addr common.Address, tokenID int32) *math.BigInt
- func (dag *Dag) GetConfirmTime(seqHeight uint64) *types.ConfirmTime
- func (dag *Dag) GetHeight() uint64
- func (dag *Dag) GetLatestNonce(addr common.Address) (uint64, error)
- func (dag *Dag) GetLatestTokenId() int32
- func (dag *Dag) GetReceipt(hash common.Hash) *Receipt
- func (dag *Dag) GetSequencer(hash common.Hash, seqHeight uint64) *tx_types.Sequencer
- func (dag *Dag) GetSequencerByHash(hash common.Hash) *tx_types.Sequencer
- func (dag *Dag) GetSequencerByHeight(height uint64) *tx_types.Sequencer
- func (dag *Dag) GetSequencerHashByHeight(height uint64) *common.Hash
- func (dag *Dag) GetState(addr common.Address, key common.Hash) common.Hash
- func (dag *Dag) GetTestTxByAddressAndNonce(addr common.Address, nonce uint64) types.Txi
- func (dag *Dag) GetTestTxisByNumber(height uint64) (types.Txis, *tx_types.Sequencer)
- func (dag *Dag) GetToken(tokenId int32) *state.TokenObject
- func (dag *Dag) GetTokens() []*state.TokenObject
- func (dag *Dag) GetTx(hash common.Hash) types.Txi
- func (dag *Dag) GetTxByNonce(addr common.Address, nonce uint64) types.Txi
- func (dag *Dag) GetTxConfirmHeight(hash common.Hash) (uint64, error)
- func (dag *Dag) GetTxis(hashs common.Hashes) types.Txis
- func (dag *Dag) GetTxisByNumber(height uint64) types.Txis
- func (dag *Dag) GetTxsByAddress(addr common.Address) []types.Txi
- func (dag *Dag) GetTxsByNumberAndType(height uint64, txType types.TxBaseType) types.Txis
- func (dag *Dag) GetTxsHashesByNumber(Height uint64) *common.Hashes
- func (dag *Dag) Has(hash common.Hash) bool
- func (dag *Dag) Init(genesis *tx_types.Sequencer, genesisBalance map[common.Address]*math.BigInt) error
- func (dag *Dag) LatestSequencer() *tx_types.Sequencer
- func (dag *Dag) LoadLastState() (bool, common.Hash)
- func (dag *Dag) LoadStateRoot() common.Hash
- func (dag *Dag) PrePush(batch *ConfirmBatch) (common.Hash, error)
- func (dag *Dag) ProcessTransaction(tx types.Txi, preload bool) ([]byte, *Receipt, error)
- func (dag *Dag) Push(batch *ConfirmBatch) error
- func (dag *Dag) ReadConfirmTime(seqHeight uint64) *types.ConfirmTime
- func (dag *Dag) Revert(snapShotID int, txs types.Txis)
- func (dag *Dag) RollBack()
- func (dag *Dag) Start()
- func (dag *Dag) StateDatabase() *state.StateDB
- func (dag *Dag) Stop()
- func (dag *Dag) TestWriteConfirmTIme(cf *types.ConfirmTime) error
- func (dag *Dag) WriteTransaction(putter *Putter, tx types.Txi) error
- type DagConfig
- type GenesisAccounts
- type Putter
- type Receipt
- func (z *Receipt) DecodeMsg(dc *msgp.Reader) (err error)
- func (z *Receipt) EncodeMsg(en *msgp.Writer) (err error)
- func (z *Receipt) MarshalMsg(b []byte) (o []byte, err error)
- func (z *Receipt) Msgsize() (s int)
- func (r *Receipt) ToJsonMap() map[string]interface{}
- func (z *Receipt) UnmarshalMsg(bts []byte) (o []byte, err error)
- type ReceiptSet
- type ReceiptStatus
- func (z *ReceiptStatus) DecodeMsg(dc *msgp.Reader) (err error)
- func (z ReceiptStatus) EncodeMsg(en *msgp.Writer) (err error)
- func (z ReceiptStatus) MarshalMsg(b []byte) (o []byte, err error)
- func (z ReceiptStatus) Msgsize() (s int)
- func (z *ReceiptStatus) UnmarshalMsg(bts []byte) (o []byte, err error)
- type TxList
- type TxMap
- type TxPool
- func (pool *TxPool) AddLocalTx(tx types.Txi, noFeedBack bool) error
- func (pool *TxPool) AddLocalTxs(txs []types.Txi, noFeedBack bool) []error
- func (pool *TxPool) AddRemoteTx(tx types.Txi, noFeedBack bool) error
- func (pool *TxPool) AddRemoteTxs(txs []types.Txi, noFeedBack bool) []error
- func (pool *TxPool) ClearAll()
- func (pool *TxPool) Get(hash common.Hash) types.Txi
- func (pool *TxPool) GetAllTips() map[common.Hash]types.Txi
- func (pool *TxPool) GetBenchmarks() map[string]interface{}
- func (pool *TxPool) GetByNonce(addr common.Address, nonce uint64) types.Txi
- func (pool *TxPool) GetConfirmStatus() *ConfirmInfo
- func (pool *TxPool) GetHashOrder() common.Hashes
- func (pool *TxPool) GetLatestNonce(addr common.Address) (uint64, error)
- func (pool *TxPool) GetMaxWeight() uint64
- func (pool *TxPool) GetOrder() common.Hashes
- func (pool *TxPool) GetRandomTips(n int) (v []types.Txi)
- func (pool *TxPool) GetStatus(hash common.Hash) TxStatus
- func (pool *TxPool) GetTxNum() int
- func (pool *TxPool) Has(hash common.Hash) bool
- func (pool *TxPool) Init(genesis *tx_types.Sequencer)
- func (pool *TxPool) IsBadSeq(seq *tx_types.Sequencer) error
- func (pool *TxPool) IsLocalHash(hash common.Hash) bool
- func (pool *TxPool) Name() string
- func (pool *TxPool) PoolStatus() (int, int, int)
- func (pool *TxPool) PreConfirm(seq *tx_types.Sequencer) (hash common.Hash, err error)
- func (pool *TxPool) RegisterOnNewTxReceived(c chan types.Txi, chanName string, allTx bool)
- func (pool *TxPool) Remove(tx types.Txi, removeType hashOrderRemoveType)
- func (pool *TxPool) Start()
- func (pool *TxPool) Stop()
- type TxPoolConfig
- type TxQuality
- type TxStatus
- type TxType
Constants ¶
const MaxAccountCount = 255
const (
PoolRejudgeThreshold int = 10
)
Variables ¶
var ( DefaultGasLimit = uint64(10000000000) DefaultCoinbase = common.HexToAddress("0x1234567812345678AABBCCDDEEFF998877665544") )
Functions ¶
func DefaultGenesis ¶
func GetSampleAccounts ¶
func GetSampleAccounts() []*account.SampleAccount
Types ¶
type Accessor ¶
type Accessor struct {
// contains filtered or unexported fields
}
func NewAccessor ¶
func (*Accessor) AddBalance ¶
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 ¶
DeleteBalance delete the balance of an address.
func (*Accessor) DeleteTransaction ¶
DeleteTransaction delete the tx or sequencer.
func (*Accessor) HasAddrLatestNonce ¶
HasAddrLatestNonce returns true if addr already sent some txs.
func (*Accessor) ReadAddrLatestNonce ¶
ReadAddrLatestNonce get latest nonce of an address
func (*Accessor) ReadBalance ¶
ReadBalance get the balance of an address.
func (*Accessor) ReadGenesis ¶
ReadGenesis get genesis sequencer from db. return nil if there is no genesis.
func (*Accessor) ReadIndexedTxHashs ¶
ReadIndexedTxHashs get a list of txs that is confirmed by the sequencer that holds the id 'SeqHeight'.
func (*Accessor) ReadLastStateRoot ¶ added in v0.0.4
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) ReadLatestSequencer ¶
ReadLatestSequencer get latest sequencer from db. return nil if there is no sequencer.
func (*Accessor) ReadReceipt ¶
ReadReceipt try get receipt by tx hash and seqID.
func (*Accessor) ReadSequencerByHeight ¶
ReadSequencerByHeight get sequencer from db by sequencer id.
func (*Accessor) ReadTransaction ¶
ReadTransaction get tx or sequencer from ogdb.
func (*Accessor) ReadTxByNonce ¶
ReadTxByNonce get tx from db by sender's address and nonce.
func (*Accessor) SetBalance ¶
SetBalance write the balance of an address into ogdb. Data will be overwritten if it already exist in db.
func (*Accessor) SubBalance ¶
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 ¶
WriteGenesis writes geneis into db.
func (*Accessor) WriteIndexedTxHashs ¶
func (da *Accessor) WriteIndexedTxHashs(putter *Putter, SeqHeight uint64, hashs *common.Hashes) error
WriteIndexedTxHashs stores a list of tx hashs. These related hashs are all confirmed by sequencer that holds the id 'SeqHeight'.
func (*Accessor) WriteLastStateRoot ¶ added in v0.0.4
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) WriteLatestSequencer ¶
WriteGenesis 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 ¶
WriteSequencerByHeight stores the sequencer into db and indexed by its id.
func (*Accessor) WriteTransaction ¶
WriteTransaction write the tx or sequencer into ogdb.
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 (*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) 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(pool *TxPool) *AccountFlows
func (*AccountFlows) Add ¶
func (a *AccountFlows) Add(tx types.Txi)
func (*AccountFlows) Get ¶
func (a *AccountFlows) Get(addr common.Address) *AccountFlow
func (*AccountFlows) GetBalanceState ¶
func (a *AccountFlows) GetBalanceState(addr common.Address, tokenID int32) *BalanceState
func (*AccountFlows) GetLatestNonce ¶
func (a *AccountFlows) GetLatestNonce(addr common.Address) (uint64, error)
func (*AccountFlows) GetTxByNonce ¶
func (*AccountFlows) Remove ¶
func (a *AccountFlows) Remove(tx types.Txi)
func (*AccountFlows) ResetFlow ¶
func (a *AccountFlows) ResetFlow(addr common.Address, originBalance state.BalanceSet)
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 ¶
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.
type ConfirmBatch ¶
func (*ConfirmBatch) String ¶ added in v0.0.2
func (c *ConfirmBatch) String() string
type ConfirmInfo ¶ added in v0.0.2
type ConfirmStatus ¶ added in v0.0.2
type ConfirmStatus struct {
TxNum uint64
ConfirmNum uint64
Confirm time.Duration
RefreshTime time.Duration
// contains filtered or unexported fields
}
func (*ConfirmStatus) AddConfirm ¶ added in v0.0.2
func (c *ConfirmStatus) AddConfirm(d time.Duration)
func (*ConfirmStatus) AddTxNum ¶ added in v0.0.2
func (c *ConfirmStatus) AddTxNum()
func (*ConfirmStatus) GetInfo ¶ added in v0.0.2
func (c *ConfirmStatus) GetInfo() *ConfirmInfo
type Dag ¶
type Dag struct {
OnConsensusTXConfirmed chan []types.Txi
// contains filtered or unexported fields
}
func (*Dag) CallContract ¶
CallContract calls contract but disallow any modifications on statedb. This method will call ovm.StaticCall() to satisfy this.
func (*Dag) GetAllTokenBalance ¶ added in v0.0.2
func (dag *Dag) GetAllTokenBalance(addr common.Address) state.BalanceSet
func (*Dag) GetBalance ¶
GetBalance read the confirmed balance of an address from ogdb.
func (*Dag) GetConfirmTime ¶
func (dag *Dag) GetConfirmTime(seqHeight uint64) *types.ConfirmTime
func (*Dag) GetLatestNonce ¶
GetLatestNonce returns the latest tx of an addresss.
func (*Dag) GetLatestTokenId ¶ added in v0.0.2
func (*Dag) GetSequencer ¶
func (*Dag) GetSequencerByHash ¶
func (*Dag) GetSequencerByHeight ¶
func (*Dag) GetSequencerHashByHeight ¶
func (*Dag) GetTestTxByAddressAndNonce ¶ added in v0.0.2
func (*Dag) GetTestTxisByNumber ¶ added in v0.0.2
func (*Dag) GetTokens ¶ added in v0.0.2
func (dag *Dag) GetTokens() []*state.TokenObject
func (*Dag) GetTx ¶
GetTx gets tx from dag network indexed by tx hash. This function querys ogdb only.
func (*Dag) GetTxByNonce ¶
GetTxByNonce gets tx from dag by sender's address and tx nonce
func (*Dag) GetTxConfirmHeight ¶
GetTxConfirmHeight returns the height of sequencer that confirm this tx.
func (*Dag) GetTxsByAddress ¶
GetTxsByAddress get all txs from this address
func (*Dag) GetTxsByNumberAndType ¶
func (*Dag) GetTxsHashesByNumber ¶
func (*Dag) Init ¶
func (dag *Dag) Init(genesis *tx_types.Sequencer, genesisBalance map[common.Address]*math.BigInt) error
Init inits genesis sequencer and genesis state of the network.
func (*Dag) LatestSequencer ¶
LatestSequencer returns the latest sequencer stored in dag
func (*Dag) LoadLastState ¶
LoadLastState load genesis and latestsequencer data from ogdb. return false if there is no genesis stored in the db.
func (*Dag) LoadStateRoot ¶
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) PrePush ¶ added in v0.0.2
func (dag *Dag) PrePush(batch *ConfirmBatch) (common.Hash, error)
PrePush simulates the action of pushing sequencer into Dag ledger. Simulates will store the changes into cache statedb. Once the same sequencer comes, the cached states will becomes regular ones.
func (*Dag) ProcessTransaction ¶
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) StateDatabase ¶
StateDatabase is for testing only
func (*Dag) TestWriteConfirmTIme ¶ added in v0.0.2
func (dag *Dag) TestWriteConfirmTIme(cf *types.ConfirmTime) error
func (*Dag) WriteTransaction ¶
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(genesisPath string) *GenesisAccounts
type Receipt ¶
type Receipt struct {
TxHash common.Hash
Status ReceiptStatus
ProcessResult string
ContractAddress common.Address
}
func NewReceipt ¶
func (*Receipt) MarshalMsg ¶
MarshalMsg implements msgp.Marshaler
type ReceiptSet ¶
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 uint8
const ( ReceiptStatusSuccess ReceiptStatus = iota ReceiptStatusOVMFailed ReceiptStatusUnknownTxType ReceiptStatusFailed )
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 TxMap ¶
type TxMap struct {
// contains filtered or unexported fields
}
func (*TxMap) GetAllKeys ¶
func (*TxMap) GetAllValues ¶
type TxPool ¶
type TxPool struct {
OnBatchConfirmed []chan map[common.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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Get get a transaction or sequencer according to input hash, if tx not exists return nil
func (*TxPool) GetAllTips ¶
GetAllTips returns all the tips in TxPool.
func (*TxPool) GetBenchmarks ¶
func (*TxPool) GetByNonce ¶
GetByNonce get a tx or sequencer from account flows by sender's address and tx's nonce.
func (*TxPool) GetConfirmStatus ¶ added in v0.0.2
func (pool *TxPool) GetConfirmStatus() *ConfirmInfo
func (*TxPool) GetHashOrder ¶
GetHashOrder returns a hash list of txs in pool, ordered by the time that txs added into pool.
func (*TxPool) GetLatestNonce ¶
GetLatestNonce get the latest nonce of an address
func (*TxPool) GetMaxWeight ¶
func (*TxPool) GetRandomTips ¶
GetRandomTips returns n tips randomly.
func (*TxPool) PoolStatus ¶
PoolStatus returns the current number of tips, bad txs and pending txs stored in pool.
func (*TxPool) PreConfirm ¶ added in v0.0.2
PreConfirm simulates the confirm process of a sequencer and store the related data into pool.cached. Once a real sequencer with same hash comes, reload cached data without any more calculates.
func (*TxPool) RegisterOnNewTxReceived ¶
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