core

package
v0.0.0-...-508c5de Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: LGPL-2.1-or-later Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlockReward *big.Int = big.NewInt(1.5e+18)

Initial block reward for miners. See the function BlockManager.AccumelateRewards in the 'core' package (file block_manager.go)

View Source
var EmptyListRoot = crypto.Sha3(ethutil.Encode(""))

Used to set the tx root and receipt root of the genesis block

View Source
var EmptyShaList = crypto.Sha3(ethutil.Encode([]interface{}{}))

Used to set the root state of the genesis block

View Source
var Found bool
View Source
var Genesis = []interface{}{GenesisHeader, []interface{}{}, []interface{}{}}

Used to be able to RLP-encode the genesis block. To rlp-encode a block we provide it's header, transactions and uncles. The genesis block does not have any transactions and uncles, thus the use of the 2 'empty' objects.

ZeroHash256: Previous hash (none)

EmptyShaList: Empty uncles

ZeroHash160: Coinbase

EmptyShaList: Root state

EmptyListRoot: tx root

EmptyListRoot: receipt root

ZeroHash512: bloom field

big.NewInt(131072): difficulty

ethutil.Big0: number of block

big.NewInt(1000000): Block upper gas bound

ethutil.Big0: Block gas used

ethutil.Big0: Time field

nil: Extra field.

crypto.Sha3(big.NewInt(42).Bytes()): Nonce field

View Source
var MinGasPrice = big.NewInt(10000000000000)

Although defined, this variable is never used in this go-ethereum version.

View Source
var ZeroHash160 = make([]byte, 20)

Used to set the coinbase of the genesis block

View Source
var ZeroHash256 = make([]byte, 32)

Used to set the parent's hash of the genesis block

View Source
var ZeroHash512 = make([]byte, 64)

Used to set the bloom field of the genesis block

Functions

func AddTestNetFunds

func AddTestNetFunds(block *types.Block)

Sets the following accounts with a balance of 1606938044258990275541962092341162602522202 Ether for testing.

51ba59315b3a95761d0863b05ccc7a7f54703d99

e4157b34ea9615cfbde6b4fda419828124b70c78

b9c015918bdaba24b4ff057a92a3873d6eb201be

6c386a4b26f73c802f34673f7248bb118f97424a

cd2a3d9f938e13cd947ec05abc7fe734df8dd826

2ef47100e0787b915105fd5e3f4ff6752079d5cb

e6716f9544a56c530d868e4bfbacb172315bdead

1a26338f0d905e295fccb71fa9ea849ffa12aaf4

func AddressFromMessage

func AddressFromMessage(msg Message) []byte

creates and returns a new address based on a msg sender and nonce fields.

func CalcDifficulty

func CalcDifficulty(block, parent *types.Block) *big.Int

Calculates the difficulty of a block and returns it. If the block was mined in less than 5 seconds, the difficulty of the block is increased by 1/1024th of the parent's difficulty. If the block was mined in more than 5 seconds, the difficulty is decreased by 1/1024th of the parent's difficulty.

func DaggerVerify

func DaggerVerify(hash, diff, nonce *big.Int) bool

func Disassemble

func Disassemble(script []byte) (asm []string)

Returns a string representation of a sequence of bytes that consist an evm bytecode. The opcodes are defined in vm/types.go. In case that we have a PUSHi opcode we expect the next i bytes to be the i items that we want to push to the stack.

script: The evm bytecode. An example can be found here: https://rinkeby.etherscan.io/address/0x147b8eb97fd247d06c4006d269c90c1908fb5d54#code

Example: Passing the first series of bytes of the above link to this function as

script = []byte(0x60, 0x80, 0x60, 0x40, 0x52, 0x34, 0x80, 0x15, 0x61, 0x00, 0x10, 0x57, 0x60, 0x00, 0x80, 0xfd, 0x5b, 0x50, 0x60, 0x40, 0x51)

will yield the following output:

0x60 0000: PUSH1

0x80 0001: 0x80

0x60 0002: PUSH1 (we got a PUSH1, so the next value is pushed onto the stack)

0x40 0003: 0x40

0x52 0004: MSTORE

0x34 0005: CALLVALUE

0x80 0006: DUP1

0x15 0007: ISZERO

0x61 0008: PUSH2 (we got a PUSH2, so the next 2 values are pushed onto the stack)

0x00 0009: 0x00

0x10 0010: 0x10

0x57 0011: JUMPI

0x60 0012: PUSH1

0x00 0013: 0x00

0x80 0014: DUP1

0xfd 0015: Missing opcode 0xfd

0x5b 0016: JUMPDEST

0x50 0017: POP

0x60 0018: PUSH1

0x40 0019: 0x40

0x51 0020: MLOAD

func EachTx

func EachTx(pool *list.List, it func(*types.Transaction, *list.Element) bool)

todo EachTx is used as a means to iterate over the _pool_ list of transactions.

func FindTx

func FindTx(pool *list.List, finder func(*types.Transaction, *list.Element) bool) *types.Transaction

todo FindTx searches in the caller's transactions for _finder_ and returns either the matching transaction if found, or nil. This is a neat way of searching for transactions that match the criteria defined from the _finder_ param. For example, todo Add uses the hash of a transaction as a searching criterion.

func IsGasLimitErr

func IsGasLimitErr(err error) bool

Returns whether 'err' is a GasLimitErr error.

func IsKnownBlockErr

func IsKnownBlockErr(e error) bool

Returns whether 'e' is a KnownBlockErr error.

func IsNonceErr

func IsNonceErr(err error) bool

Returns whether 'err' is a NonceErr error.

func IsOutOfGasErr

func IsOutOfGasErr(err error) bool

Returns whether 'err' is an OutOfGasErr error.

func IsParentErr

func IsParentErr(err error) bool

Returns whether 'err' is a ParentErr error.

func IsTDError

func IsTDError(e error) bool

Returns whether 'e' is a TDError error.

func IsUncleErr

func IsUncleErr(err error) bool

Returns whether 'err' is an UncleErr error.

func IsValidationErr

func IsValidationErr(err error) bool

Returns whether 'err' is a ValidationErr error.

func MakeContract

func MakeContract(msg Message, state *state.StateDB) *state.StateObject

Converts an transaction in to a state object

func MessageCreatesContract

func MessageCreatesContract(msg Message) bool

returns whether the _msg_ is a contract creation aka whether the msg's/transaction's recipient is 0.

func MessageGasValue

func MessageGasValue(msg Message) *big.Int

returns the amount of Wei based on the msg's/transaction's gas and gasPrice fields. gasValue = gas * gasPrice

func ParentError

func ParentError(hash []byte) error

Creates a ParentError object by setting it's message to a message that includes the 'hash' and returns it.

func Sum

func Sum(sha hash.Hash) []byte

func UncleError

func UncleError(str string) error

Creates an UncleErr error by setting it's message to 'str' and returns it.

Types

type AccountChange

type AccountChange struct {
	Address, StateAddress []byte
}

type BlockManager

type BlockManager struct {
	Pow pow.PoW
	// contains filtered or unexported fields
}

State manager for processing new blocks and managing the overall state

mutex: Mutex for locking the block processor. Blocks can only be handled one at a time

bc: Canonical block chain

mem: non-persistent key/value memory storage

Pow: Proof of work used for validating

txpool: The transaction pool. See type 'TxPool' of the 'core' package.

lastAttemptedBlock: The last attempted block is mainly used for debugging purposes.

This does not have to be a valid block and will be set during 'Process' & canonical validation.

events: Provides a way to subscribe to events.

eventMux: event mutex, used to dispatch events to subscribers.

func NewBlockManager

func NewBlockManager(txpool *TxPool, chainManager *ChainManager, eventMux *event.TypeMux) *BlockManager

Creates a new BlockManager object by initializing these fields of a BlockManager object type: mem, Pow, bc, eventMux, txpool. The Pow object will have it's 'turbo' field set to true when created. See the type 'EasyPow' of the 'ezp' package for more. (file pow/ezp/pow.go)

func (*BlockManager) AccumelateRewards

func (sm *BlockManager) AccumelateRewards(statedb *state.StateDB, block, parent *types.Block) error

Calculates the reward of the miner. Returns an error if an error has occured during the validation process. If no errors have occured, nil is returned.

More specifically an error is returned: 1. if the parent of any of the uncles of the 'block' is nil, or

2. if the (block) number of the parent of any of the uncles of the 'block' and the 'block' itself have a difference greater than 6, or

3. if the hash of any of the uncles of the param 'block' matches any of the uncles of the param 'parent'.

4. if the nonce of any of the uncles of the param 'block' is included in the nonce of the 'block'

The reward to be appointed to the miner will be:

If the 'block' has 1 uncle: r1 = BlockReward + BlockReward/32,

If the 'block' has 2 uncles: r2 = r1 + r1/32, etc., where BlockReward = 1.5 Ether,( defined in the core package, file fees.go)

Finally, a message is added to the state manifest regarding the value to be transferred to the miner address. This value will be the sum of the above calculated reward and the block.Reward.

func (*BlockManager) ApplyTransactions

func (self *BlockManager) ApplyTransactions(coinbase *state.StateObject, state *state.StateDB, block *types.Block, txs types.Transactions, transientProcess bool) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error)

This function will apply the transactions of a block to the world state and return the results as a tuple. It gets called by the BlockManager.TransitionState function, then calls the latter again, and so on, to form a recursion algorithm that will apply the transactions one by one. In case where an IsGasLimitErr error occurs during the application of any transaction, the process of the transactions stops.

Returns: (receipts, handled, unhandled, erroneous, err)

receipts: The receipts up to but not including any transaction that has caused an IsGasLimitErr error.

handled: All transactions that were handled up to but not including any transaction that has caused an IsGasLimitErr error.

unhandled: In case of an IsGasLimitErr error this object will contain all the transactions that were not applied (includes the transaction that caused the error). Otherwise, this object will be nil.

erroneous: Any transactions that caused an error other than an IsGasLimitErr and/or an IsNonceErr errors.

err: The err will be either an IsGasLimitErr error type or nil.

A short description on what this function does follows.

1. Clear all state logs.

2. Get (or create a new) coinbase state object and call the TransitionState function.

3. The latter function will call this function again, forming the recursion.

4. If an error occured and is an IsGasLimitErr error then stop the process and set the 'unhandled' variable (to be returned later). If it is a IsNonceErr error, ignore it. If it is any other error, also ignore it, but append to the variable 'erroneous' (to be returned later) the transaction that caused that error.

5. Calculate the gas used so far and the current reward for the miner. Update the state.

6. Create the receipt of the current transaction and set the receipt's logs and Bloom field.

7. If the parameter 'transientProcess' is false, notify all subscribers about the transaction.

8. Append receipt, transaction to the 'receipts', 'handled' variables (to be returned later)

9. When the processing has ended, set the block's reward and totalUsedGas fields.

10.Return the results.

func (*BlockManager) CalculateTD

func (sm *BlockManager) CalculateTD(block *types.Block) (*big.Int, bool)

Calculates the total difficulty for a given block.

TD(genesis_block)=0 and TD(block)=TD(block.parent) + sum(u.difficulty for u in block.uncles) + block.difficulty

Returns: If the calculated total difficulty is greater than the previous the tuple (total_difficulty, true) is returned. Otherwise, the tuple (nil, false) is returned.

func (*BlockManager) GetMessages

func (sm *BlockManager) GetMessages(block *types.Block) (messages []*state.Message, err error)

Returns either the tuple (state.Manifest().Messages, nil) or (nil, error)

If an error is returned it will be a ParentError regarding the parent of the 'block' (the error includes the hash of the parent of the 'block'). This error happens in the case where the the hash of the parent of the 'block' already exists.

In essence, the state manifest's messages are the transactions that occured during the world state transition of the addition of a 'block'.

To get those messages a simple trick is used: a deferred call on state.Reset() is queued and only then a call of the function TransitionState and following that a call on AccumelateRewards happen.

func (*BlockManager) Process

func (sm *BlockManager) Process(block *types.Block) (td *big.Int, msgs state.Messages, err error)

Processes a block. When successful, returns the return result of a call to the ProcessWithParent function.

Otherwise, in case that the hash of the block or the hash of the parent of the block already exist in the ChainManager, returns the tuple (nil, nil KnownBlockError) or (nil, nil, ParentError) accordingly.

Before calling the ProcessWithParent function, this function takes care of locking the BlockManager with a mutex and only after the ProcessWithParent function has returned the BlockManager is being unlocked.

func (*BlockManager) ProcessWithParent

func (sm *BlockManager) ProcessWithParent(block, parent *types.Block) (td *big.Int, messages state.Messages, err error)

The main process function of a block. Gets called by the function Process.

Returns a tuple (td, messages, error) where td: total difficulty of the processed block, messages: messages generated by the application of the transactions of the block (and some extra messages like transactions regarding rewarding miners). If an error occured the returned tuple becomes (nil, nil, error). If no errors have occured the returned tuple becomes (td, messages, nil)

1. Saves a copy of the state. Also queues a reset of the state after the function's return based on that copy.

2. Validates the block with a call to the function ValidateBlock. If errors happened, returns

3. Calls TransitionState to attempt to do the state transition. If errors, returns.

4. Creates the bloom field of the receipts returned from step 2. If for some reason the bloom field is different from the bloom field of the provided block, it returns.

5. Validates the transactions and the receipts root hashes. If errors, returns.

6. Calls AccumelateRewards to calculate the miner rewards. If errors, returns.

7. Sets the state to 0 and makes a call to CalculateTD in order to calculate the total difficulty of the block. If errors, returns. If not, the last step is to remove the block's transactions from the BlockManager's txpool, sync the state db, cancel the queued state reset, send a message to the chainlogger channel and finally return the tuple (td, messages, nil).

func (*BlockManager) TransitionState

func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *types.Block) (receipts types.Receipts, err error)

Returns (receipts, nil) or (nil, error) if an IsGasLimitErr error has occured. This function together with the BlockManager.ApplyTransactions function form a recursion algorithm meant to apply all transactions of the current block to the world state. The main logic/application happens in the latter function. However, this function is the one to be called when we want to apply the transactions of a block. The TransitionState function sets the total gas pool (amount of gas left) for the coinbase address of the block before calling the ApplyTransactions function which in turn will call the TransitionState function again, and so on, until all transactions have been applied or an IsGasLimitErr error has occured. If no such an error has occured then the 'receipts' object returned by this function will hold the receipts that are the result of the application of the transactions of the 'block' param.

func (*BlockManager) ValidateBlock

func (sm *BlockManager) ValidateBlock(block, parent *types.Block) error

Validates the current block. Returns an error if the block was invalid, an uncle or anything that isn't on the current block chain. Validation validates easy over difficult (dagger takes longer time = difficult)

type ChainManager

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

ChainManager is mainly used for the creation of genesis or any other blocks

processor: An interface. A neat way of calling the function Process of a BlockManager object.

eventMux: Used to dispatch events to subscribers.

genesisBlock: The special genesis block.

mu: a mutex for the ChainManager object.

td: the total difficulty. TD(genesis_block) = 0 and TD(B) = TD(B.parent) + sum(u.difficulty for u in B.uncles) + B.difficulty

lastBlockNumber: the last block's number. (the last successfully inserted block on the chain)

currentBlock: During the creation of a new block, the currentBlock will point to the parent of the block to be created.

lastBlockHash: the last block's hash.

transState: represents the world state.

func NewChainManager

func NewChainManager(mux *event.TypeMux) *ChainManager

Creates and returns a new ChainManager object by setting the genesisBlock and the eventMux field of the ChainManager.

func (*ChainManager) BlockInfo

func (bc *ChainManager) BlockInfo(block *types.Block) types.BlockInfo

Returns the block's BlockInfo object representation. See types.BlockInfo for more.

func (*ChainManager) CalcTotalDiff

func (self *ChainManager) CalcTotalDiff(block *types.Block) (*big.Int, error)

Calculates the total difficulty of the ChainManager and returns it in a tuple (td, nil). If an error occured, then the tuple (nil, error) is returned.

TD(genesis_block) = 0 and TD(B) = TD(B.parent) + sum(u.difficulty for u in B.uncles) + B.difficulty

func (*ChainManager) CurrentBlock

func (self *ChainManager) CurrentBlock() *types.Block

Returns the current block todo

func (*ChainManager) Export

func (self *ChainManager) Export() []byte

Returns the RLP-encoding of all blocks of the chain.

func (*ChainManager) Genesis

func (bc *ChainManager) Genesis() *types.Block

Returns the genesis block.

func (*ChainManager) GetBlock

func (self *ChainManager) GetBlock(hash []byte) *types.Block

Returns the block of the chain that has the given hash.

func (*ChainManager) GetBlockByNumber

func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block

Returns the block of the chain that has the given num .

func (*ChainManager) GetChainHashesFromHash

func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain [][]byte)

Returns a list of hashes of the chain starting from the genesis hash and up to, but not including, the 'max' block.

func (*ChainManager) HasBlock

func (bc *ChainManager) HasBlock(hash []byte) bool

Returns whether the given hash param matches a block's hash present in the chain.

func (*ChainManager) InsertChain

func (self *ChainManager) InsertChain(chain types.Blocks) error

This function iterates over the blocks in the chain param and does the following:

1. It calls the `Process` method of the `BlockProcessor` interface.

2. writes the block to the database.

4. sets the total difficulty of the block.

5. inserts the block into the chain.

6. posts a `NewBlockEvent` to the event mux.

7. posts the messages to the event mux.

Returns: either nil for success or an error.

func (*ChainManager) LastBlockHash

func (self *ChainManager) LastBlockHash() []byte

Returns the last block's hash

func (*ChainManager) LastBlockNumber

func (self *ChainManager) LastBlockNumber() uint64

Returns the last block number.

func (*ChainManager) NewBlock

func (bc *ChainManager) NewBlock(coinbase []byte) *types.Block

Creates a new Block by making a call to the function CreateBlock of the types package, sets it's difficulty, number and gaslimit and returns it.

func (*ChainManager) Reset

func (bc *ChainManager) Reset()

Resets the chain to the point where the chain will only contain the genesis block. This includes the call on the function AddTestNetFunds.

func (*ChainManager) SetProcessor

func (self *ChainManager) SetProcessor(proc types.BlockProcessor)

Sets the processor field of the ChainManager object

func (*ChainManager) State

func (self *ChainManager) State() *state.StateDB

Returns the world state as 'seen' by the current block.

func (*ChainManager) Stop

func (bc *ChainManager) Stop()

Sends a stop message to the chain logger channel if and only if the currentBlock field of the ChainManager is not nil.

func (*ChainManager) Td

func (self *ChainManager) Td() *big.Int

Returns the total difficulty.

TD(genesis_block) = 0 and TD(B) = TD(B.parent) + sum(u.difficulty for u in B.uncles) + B.difficulty

func (*ChainManager) TransState

func (self *ChainManager) TransState() *state.StateDB

Returns the world state.

type Dagger

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

func (*Dagger) Eval

func (dag *Dagger) Eval(N *big.Int) *big.Int

func (*Dagger) Find

func (dag *Dagger) Find(obj *big.Int, resChan chan int64)

func (*Dagger) Node

func (dag *Dagger) Node(L uint64, i uint64) *big.Int

func (*Dagger) Search

func (dag *Dagger) Search(hash, diff *big.Int) *big.Int

func (*Dagger) Verify

func (dag *Dagger) Verify(hash, diff, nonce *big.Int) bool

type EthManager

type EthManager interface {
	BlockManager() *BlockManager
	ChainManager() *ChainManager
	TxPool() *TxPool
	Broadcast(msgType wire.MsgType, data []interface{})
	PeerCount() int
	IsMining() bool
	IsListening() bool
	Peers() *list.List
	KeyManager() *crypto.KeyManager
	ClientIdentity() wire.ClientIdentity
	Db() ethutil.Database
	EventMux() *event.TypeMux
}

The 'EthManager' interface is only implemented by the 'Ethereum' object, defined in the package 'eth' (file ethereum.go)

BlockManager: See type 'BlockManager' of the 'core' package.

ChainManager: See type 'ChainManager' of the 'core' package.

TxPool: See type 'TxPool' of the 'core' package.

Broadcast: Used to broacast messages to all peers.

IsMining: Returns whether the peer is mining.

IsListening: Returns whether the peer is listening.

Peers: Returns all connected peers.

KeyManager: Key manager for the account(s) of the node.

ClientIdentity: Used mainly for communication between peers.

Db: The ethereum database. This should be a representation of the World State.

EventMux: Used to dispatch events to registered nodes

type Execution

type Execution struct {
	Gas          *big.Int
	SkipTransfer bool
	// contains filtered or unexported fields
}

func NewExecution

func NewExecution(env vm.Environment, address, input []byte, gas, gasPrice, value *big.Int) *Execution

Execution Constructor

func (*Execution) Addr

func (self *Execution) Addr() []byte

Get the Execution address.

func (*Execution) Call

func (self *Execution) Call(codeAddr []byte, caller vm.ClosureRef) ([]byte, error)

func (*Execution) Create

func (self *Execution) Create(caller vm.ClosureRef) (ret []byte, err error, account *state.StateObject)

ret: the byte code.

type Filter

type Filter struct {
	Altered         []AccountChange
	BlockCallback   func(*types.Block)
	MessageCallback func(state.Messages)
	// contains filtered or unexported fields
}

Filtering interface

func NewFilter

func NewFilter(eth EthManager) *Filter

Create a new filter which uses a bloom filter on blocks to figure out whether a particular block is interesting or not.

func (*Filter) AddAltered

func (self *Filter) AddAltered(address, stateAddress []byte)

func (*Filter) AddFrom

func (self *Filter) AddFrom(addr []byte)

func (*Filter) AddTo

func (self *Filter) AddTo(addr []byte)

func (*Filter) FilterMessages

func (self *Filter) FilterMessages(msgs []*state.Message) []*state.Message

func (*Filter) Find

func (self *Filter) Find() []*state.Message

Run filters messages with the current parameters set

func (*Filter) SetEarliestBlock

func (self *Filter) SetEarliestBlock(earliest int64)

Set the earliest and latest block for filtering. -1 = latest block (i.e., the current block) hash = particular hash from-to

func (*Filter) SetFrom

func (self *Filter) SetFrom(addr [][]byte)

func (*Filter) SetLatestBlock

func (self *Filter) SetLatestBlock(latest int64)

func (*Filter) SetMax

func (self *Filter) SetMax(max int)

func (*Filter) SetSkip

func (self *Filter) SetSkip(skip int)

func (*Filter) SetTo

func (self *Filter) SetTo(addr [][]byte)

type GasLimitErr

type GasLimitErr struct {
	Message string
	Is, Max *big.Int
}

Happens when the total gas left for the coinbase address is less than the gas to be bought.

func GasLimitError

func GasLimitError(is, max *big.Int) *GasLimitErr

Creates and returns a GasLimitError given the total gas left to be bought by a coinbase address and the actual gas.

func (*GasLimitErr) Error

func (err *GasLimitErr) Error() string

Returns the error message of a GasLimitErr error.

type KnownBlockError

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

Happens when there is already a block in the chain with the same hash. The number field is the number of the existing block.

func (*KnownBlockError) Error

func (self *KnownBlockError) Error() string

Creates and returns a KnownBlockError error.

type Message

type Message interface {
	Hash() []byte
	From() []byte
	To() []byte
	GasPrice() *big.Int
	Gas() *big.Int
	Value() *big.Int
	Nonce() uint64
	Data() []byte
}

A Message represents a Transaction.

type NewBlockEvent

type NewBlockEvent struct{ Block *types.Block }

NewBlockEvent is posted when a block has been imported.

type NonceErr

type NonceErr struct {
	Message string
	Is, Exp uint64
}

Happens when a transaction's nonce is incorrect.

func NonceError

func NonceError(is, exp uint64) *NonceErr

Creates and returns a NonceError given the transaction's nonce and the nonce of the sender of the transaction.

func (*NonceErr) Error

func (err *NonceErr) Error() string

Returns the error message of a NonceErr error.

type OutOfGasErr

type OutOfGasErr struct {
	Message string
}

Happens when the gas provided runs out before the state transition happens.

func OutOfGasError

func OutOfGasError() *OutOfGasErr

Creates and returns an OutOfGasError error.

func (*OutOfGasErr) Error

func (self *OutOfGasErr) Error() string

Returns the error message of an OutOfGasError error.

type ParentErr

type ParentErr struct {
	Message string
}

Parent error. In case a parent is unknown this error will be thrown by the block manager

func (*ParentErr) Error

func (err *ParentErr) Error() string

Returns the error message of the caller.

type Peer

type Peer interface {
	Inbound() bool
	LastSend() time.Time
	LastPong() int64
	Host() []byte
	Port() uint16
	Version() string
	PingTime() string
	Connected() *int32
	Caps() *ethutil.Value
}

This interface is only implemented by a "Peer" object defined in the 'eth' package (file peer.go)

Inbound(): Determines whether it's an inbound or outbound peer

LastSend(): Last known message send time.

LastPong(): Last received pong message

Host(): the host.

Port(): the port of the connection

Version(): client identity

PingTime(): Used to give some kind of pingtime to a node, not very accurate.

Connected(): Flag for checking the peer's connectivity state

Caps(): getter for the protocolCaps field of a Peer object.

type StateTransition

type StateTransition struct {
	Env vm.Environment
	// contains filtered or unexported fields
}

* The State transitioning model * * A state transition is a change made when a transaction is applied to the current world state * The state transitioning model does all all the necessary work to work out a valid new state root. * 1) Nonce handling * 2) Pre pay / buy gas of the coinbase (miner) * 3) Create a new state object if the recipient is \0*32, aka contract creation. * 4) Value transfer * == If contract creation == * 4a) Attempt to run transaction data * 4b) If valid, use result as code for the new state object * == end == * 5) Run Script section * 6) Derive new state root

func NewStateTransition

func NewStateTransition(coinbase *state.StateObject, msg Message, state *state.StateDB, block *types.Block) *StateTransition

creates and returns a todo StateTransition object. The fields _gas_ and initialGas are set to 0 The fields rec, sen and Env are set to nil The field coinbase is set to the address of the _coinbase_ param. The field cb is set to the param _coinbase_. All other fields are set to the corresponding params.

func (*StateTransition) AddGas

func (self *StateTransition) AddGas(amount *big.Int)

adds _amount_ gas to the caller's gas.

func (*StateTransition) BuyGas

func (self *StateTransition) BuyGas() error

attempts to reward the miner with the gas of the transaction. If the sender's balance is less than the calculated gas in Wei (gas*gasPrice of caller), an error is returned. Buying the gas does not directly happen in this function. Instead, the BuyGas function of the miner StateObject is called through this function. If the latter does not return an error, this function will increase the _gas_ field of the caller, set the caller's _initialGas_ field and decrease the sender's balance by an amount of _gas_ *_gasPrice_

func (*StateTransition) Coinbase

func (self *StateTransition) Coinbase() *state.StateObject

returns the miner's account as a StateObject. If the miner does not exist in the current world state, it's created.

func (*StateTransition) From

func (self *StateTransition) From() *state.StateObject

returns the _from_ field of the caller as a StateObject. If _from_ does not exist in the current world state, it's created.

func (*StateTransition) GasUsed

func (self *StateTransition) GasUsed() *big.Int

func (*StateTransition) RefundGas

func (self *StateTransition) RefundGas()

func (*StateTransition) To

func (self *StateTransition) To() *state.StateObject

returns the _to_ field of the caller as a StateObject. If _to_ does not exist in the current world state, it's created. This function will return nil in the case where the msg is about a contract creation (aka if _to_ is 0)

func (*StateTransition) TransitionState

func (self *StateTransition) TransitionState() (ret []byte, err error)

func (*StateTransition) UseGas

func (self *StateTransition) UseGas(amount *big.Int) error

attempts to use _amount_ gas of the caller's gas. If the caller's gas is less than the _amount_ provided, an OutOfGasError is returned. Otherwise, nil is returned for success. In case of success, the new gas of the caller will become newGas = prevGas - amount.

func (*StateTransition) VmEnv

func (self *StateTransition) VmEnv() vm.Environment

is a getter method for the Env field of a StateTransition object. If the Env field of the caller is nil, a new Env is created by calling the function todo NewEnv defined in the file todo vm_env.go

type TDError

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

Defined, but not used. Meant to be used when there is a total difficulty error, a < b.

func (*TDError) Error

func (self *TDError) Error() string

Creates and returns a TDError error.

type TxMsg

type TxMsg struct {
	Tx   *types.Transaction
	Type TxMsgTy
}

todo TxMsg represents the type of the channel of the _subscribers_ field of a TxPool object. However, that field is never actually used in the whole codebase of this go-ethereum version.

type TxMsgTy

type TxMsgTy byte

The only use of a TxMsgTy type is as a field of a TxMsg type. Although it's not clear how this type is supposed to be used, since there are no other references to it in the whole codebase, we could make a guess based on the fact that there are 3 types of transactions in ethereum: Regular transactions: a transaction from one wallet to another. Contract deployment transactions: a transaction without a 'to' address, where the data field is used for the contract code. Execution of a contract: a transaction that interacts with a deployed smart contract. In this case, 'to' address is the smart contract address. TxMsgTy may had been used to represent the above types of transactions.

type TxPool

type TxPool struct {
	SecondaryProcessor TxProcessor
	// contains filtered or unexported fields
}

TxPool is a thread safe transaction pool handler. In order to guarantee a non blocking pool the _queueChan_ is used which can be independently read without needing access to the actual pool. If the pool is being drained or synced for whatever reason, the transactions will simply queue up and be handled when the mutex is freed. mutex: a mutex for accessing the Tx pool. queueChan: Queueing channel for reading and writing incoming transactions to quit: Quiting channel (quitting is equivalent to emptying the TxPool) pool: The actual pool, aka the list of transactions. SecondaryProcessor: This field is actually never used as the todo TxProcessor interface is not implemented. subscribers: Although defined, this channel is never used. broadcaster: used to broadcast messages to all connected peers. chainManager: the chain to which the TxPool object is attached to. eventMux: used to dispatch events to subscribers.

func NewTxPool

func NewTxPool(chainManager *ChainManager, broadcaster types.Broadcaster, eventMux *event.TypeMux) *TxPool

todo NewTxPool creates a new todo TxPool object and sets it's fields. TxPool.pool will be empty. TxPool.queueChain wil be set to a Transaction channel with a txPoolQueueSize size. TxPool.quit will be set to a boolean channel. TxPool.chainManager will be assigned the param _chainManager_ TxPool.eventMux will be assigned the param _eventMux_ TxPool.broadcaster will be assigned the param _broadcaster_ All other fields of the todo TxPool object that gets created are not set by NewTxPool.

func (*TxPool) Add

func (self *TxPool) Add(tx *types.Transaction) error

todo Add is the function to be called for adding a todo Transaction to the todo TxPool caller. Returns either an error on not successfully adding _tx_ or nil for success. If _tx_ was added, a message is posted to the subscribed peers, containing the _tx_ from, to, value and hash fields. An error is returned in any of these cases: 1. _tx_'s hash already exists in the todo TxPool caller, aka the transaction to be added is already part of the caller. 2. _tx_ validation returned an error when calling todo ValidateTransaction. If no errors are produced from steps 1. and 2. todo Add makes a call to the inner function todo addTransaction to add _tx_ to the current todo TxPool.

func (*TxPool) CurrentTransactions

func (pool *TxPool) CurrentTransactions() []*types.Transaction

todo CurrentTransactions returns the transactions of the todo TxPool caller as a slice.

func (*TxPool) Flush

func (pool *TxPool) Flush() []*types.Transaction

todo Flush resets the caller's transactions list to an empty list.

func (*TxPool) RemoveInvalid

func (pool *TxPool) RemoveInvalid(state *state.StateDB)

todo RemoveInvalid removed all transactions from the caller for which either: 1. the transaction returns an error when validated through the todo ValidateTransaction function, or 2. the transaction sender's nonce field is >= to the transaction's nonce field.

func (*TxPool) RemoveSet

func (self *TxPool) RemoveSet(txs types.Transactions)

todo RemoveSet takes as an argument a set of transactions _txs_ and removes from the caller's transactions set those that match the ones from _txs_. Looping over the transactions of the caller happens through the todo EachTx function.

func (*TxPool) Size

func (self *TxPool) Size() int

todo Size returns the number of Transactions of the caller.

func (*TxPool) Start

func (pool *TxPool) Start()

Although defined, this function does not contain any executable code in this go-ethereum version.

func (*TxPool) Stop

func (pool *TxPool) Stop()

todo Stop makes a call on todo Flush to empty the caller's transactions list and then sends the message "Stopped" to the todo txplogger channel.

func (*TxPool) ValidateTransaction

func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error

todo ValidateTransaction validates the _tx_ todo Transaction. Returns either an error if _tx_ can not be validated or nil. These are the cases where _tx_ is not validated: 1. For some reason, the currentBlock field of the chainManager field of the caller is nil. (aka the chain is empty) 2. The recipient field (_to_) of _tx_ is is either nil or != 20 bytes. This means that the validation of contract creation transactions, for which the recipient (_to_) is set to nil will always return an error. 3. The _v_ field of _tx_ is neither 28 nor 27. (See todo Transaction object) 4. The sender account of _tx_ does not have enough Ether to send to the recipient of _tx_

type TxPoolHook

type TxPoolHook chan *types.Transaction

Although defined, this type is never used in this go-ethereum version.

type TxPostEvent

type TxPostEvent struct{ Tx *types.Transaction }

TxPostEvent is posted when a transaction has been processed.

type TxPreEvent

type TxPreEvent struct{ Tx *types.Transaction }

TxPreEvent is posted when a transaction enters the transaction pool.

type TxProcessor

type TxProcessor interface {
	ProcessTransaction(tx *types.Transaction)
}

The todo TxProcessor interface, although defined, is not implemented at all in the whole codebase of this go-ethereum version.

type UncleErr

type UncleErr struct {
	Message string
}

Uncle error. This error is thrown only from the function BlockManager.AccumelateRewards defined in the 'core' package (file block_manager.go). See that function for more.

func (*UncleErr) Error

func (err *UncleErr) Error() string

Returns the error message of an UncleErr error.

type VMEnv

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

func NewEnv

func NewEnv(state *state.StateDB, msg Message, block *types.Block) *VMEnv

func (*VMEnv) AddLog

func (self *VMEnv) AddLog(log state.Log)

func (*VMEnv) BlockHash

func (self *VMEnv) BlockHash() []byte

func (*VMEnv) BlockNumber

func (self *VMEnv) BlockNumber() *big.Int

func (*VMEnv) Call

func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)

func (*VMEnv) CallCode

func (self *VMEnv) CallCode(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)

func (*VMEnv) Coinbase

func (self *VMEnv) Coinbase() []byte

func (*VMEnv) Create

func (self *VMEnv) Create(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef)

func (*VMEnv) Depth

func (self *VMEnv) Depth() int

func (*VMEnv) Difficulty

func (self *VMEnv) Difficulty() *big.Int

func (*VMEnv) GasLimit

func (self *VMEnv) GasLimit() *big.Int

func (*VMEnv) Origin

func (self *VMEnv) Origin() []byte

func (*VMEnv) PrevHash

func (self *VMEnv) PrevHash() []byte

func (*VMEnv) SetDepth

func (self *VMEnv) SetDepth(i int)

func (*VMEnv) State

func (self *VMEnv) State() *state.StateDB

func (*VMEnv) Time

func (self *VMEnv) Time() int64

func (*VMEnv) Transfer

func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error

func (*VMEnv) Value

func (self *VMEnv) Value() *big.Int

type ValidationErr

type ValidationErr struct {
	Message string
}

Block validation error. If any validation fails, this error will be thrown

func ValidationError

func ValidationError(format string, v ...interface{}) *ValidationErr

Creates a ValidationErr error by setting it's message and returns it.

func (*ValidationErr) Error

func (err *ValidationErr) Error() string

Returns the error message of a ValidationErr error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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