database

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DataDirPath = "database"
	NodeName    = "lightchain"
	// IMPORTANT: Following three values needs to correspond to the internal values used by go-ethereum
	KeystorePath = "keystore"
	ChainDbPath  = "chaindata" // it needs to match to the value passed at go-ethereum/eth/backend.go:CreateDB()
	GenesisPath  = "genesis.json"
	GethIpcFile  = "geth.ipc"
)

Functions

func DefaultEthNodeConfig

func DefaultEthNodeConfig(dataDir string) ethNode.Config

DefaultEthNodeConfig returns the default configuration for a go-ethereum ethereum

func Init

func Init(cfg Config, ntw network.Network, trcCfg stdtracer.Config) error

Types

type Config

type Config struct {
	DataDir string
	GethCfg GethConfig
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig(dataDir string, metrics bool, ctx *cli.Context) (Config, error)

func (Config) ChainDbDir added in v0.10.0

func (c Config) ChainDbDir() string

func (Config) GethIpcPath added in v0.10.0

func (c Config) GethIpcPath() string

func (Config) KeystoreDir added in v0.12.0

func (c Config) KeystoreDir() string

type Database

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

Database handles the chain database and VM.

func NewDatabase

func NewDatabase(ctx *node.ServiceContext, ethCfg *eth.Config, consAPI consensusAPI.API, logger tmtLog.Logger, metrics metrics.Metrics) (*Database, error)

func (*Database) APIs

func (db *Database) APIs() []rpc.API

APIs returns the collection of Ethereum RPC services.

Overwrites go-ethereum/eth/backend.go::APIs().

Some of the API methods must be re-implemented to support Ethereum web3 features due to dependency on Tendermint, e.g Syncing().

func (*Database) Config

func (db *Database) Config() *eth.Config

func (*Database) Ethereum

func (db *Database) Ethereum() *eth.Ethereum

func (*Database) ExecuteTx added in v0.10.0

func (db *Database) ExecuteTx(tx *ethTypes.Transaction) error

ExecuteTx appends a transaction to the current block.

func (*Database) GasLimit

func (db *Database) GasLimit() uint64

GasLimit returns the maximum gas per block.

func (*Database) GetBlockStateHeader added in v1.3.0

func (db *Database) GetBlockStateHeader() ethTypes.Header

func (*Database) Persist added in v0.10.0

func (db *Database) Persist(receiver common.Address) (ethTypes.Block, error)

Persist finalises the current block and writes it to disk.

Returns the persisted Block.

func (*Database) Protocols

func (db *Database) Protocols() []p2p.Protocol

func (*Database) ResetBlockState added in v0.10.0

func (db *Database) ResetBlockState(receiver common.Address) error

ResetBlockState resets the in-memory block's processing state.

func (*Database) Start

func (db *Database) Start(_ *p2p.Server) error

func (*Database) Stop

func (db *Database) Stop() error

func (*Database) UpdateBlockState added in v0.10.0

func (db *Database) UpdateBlockState(tmHeader tmtAbciTypes.Header)

UpdateBlockState uses the tendermint header to update the eth header.

type EthDBTracer added in v0.12.0

type EthDBTracer struct {
	stdtracer.Tracer
	// contains filtered or unexported fields
}

func (EthDBTracer) AssertPersistedGenesisBlock added in v0.12.0

func (t EthDBTracer) AssertPersistedGenesisBlock(genesis core.Genesis)

func (EthDBTracer) AssertPostTxSimulationState added in v0.12.0

func (t EthDBTracer) AssertPostTxSimulationState(from common.Address, tx *types.Transaction)

type EthState

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

---------------------------------------------------------------------- EthState manages concurrent access to the intermediate blockState object The eth tx pool fires TxPreEvent in a go-routine, and the miner subscribes to this in another go-routine and processes the tx onto an intermediate ethState. We used to use `unsafe` to overwrite the miner, but this didn't work because it didn't affect the already launched go-routines. So instead we introduce the Pending API in a small persist in go-eth so we don't even start the miner there, and instead manage the intermediate ethState from here. In the same persist we also fire the TxPreEvent synchronously so the order is preserved, instead of using a go-routine.

TODO: Rewrite this description, it doesn't make sense and this "EthState" Struct is even more suspicious.

func NewEthState

func NewEthState(ethereum *eth.Ethereum, ethCfg *eth.Config, logger tmtLog.Logger) *EthState

func (*EthState) ExecuteTx added in v0.10.0

func (es *EthState) ExecuteTx(tx *ethTypes.Transaction) error

Executes TX against the eth blockchain state.

The changes happen only inside of the Eth state, not disk!

func (*EthState) GasLimit

func (es *EthState) GasLimit() *core.GasPool

func (*EthState) Pending

func (es *EthState) Pending() (*ethTypes.Block, *state.StateDB)

Implements: miner.Pending API (our custom patch to go-eth).

Return a new block and a copy of the ethState from the latest blockState.

func (*EthState) Persist added in v0.10.0

func (es *EthState) Persist(receiver common.Address) (ethTypes.Block, error)

Persist the application state to disk.

Persist is called after all TXs are executed against the application state. Triggered by ABCI::Commit(), to persist changes introduced in latest block.

Returns the persisted Block.

func (*EthState) ResetBlockState added in v0.10.0

func (es *EthState) ResetBlockState(receiver common.Address) error

func (*EthState) UpdateBlockState added in v0.10.0

func (es *EthState) UpdateBlockState(config params.ChainConfig, blockTime uint64, numTx uint64)

type GethConfig

type GethConfig struct {
	EthCfg   eth.Config
	NodeCfg  ethNode.Config
	Ethstats ethstatsConfig
}

type Node

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

Node is the main object.

func NewNode

func NewNode(cfg *Config, consensusAPI conAPI.API, registry *prometheus.Registry) (*Node, error)

NewNode creates a new node.

func (*Node) Database

func (n *Node) Database() *Database

func (*Node) RpcClient

func (n *Node) RpcClient() *ethRpc.Client

func (*Node) Start

func (n *Node) Start() error

Start starts base node and stops p2p server

func (*Node) Stop

func (n *Node) Stop() error

type NullBlockValidator added in v0.10.0

type NullBlockValidator struct{}

Dummy block validator ignoring PoW, uncles and so on.

func (NullBlockValidator) ValidateBody added in v0.10.0

func (NullBlockValidator) ValidateBody(*ethTypes.Block) error

ValidateBody does not validate anything.

func (NullBlockValidator) ValidateState added in v0.10.0

func (NullBlockValidator) ValidateState(block, parent *ethTypes.Block, state *state.StateDB, receipts ethTypes.Receipts, usedGas uint64) error

ValidateState does not validate anything.

type Tracer added in v0.12.0

type Tracer interface {
	// AssertPersistedGenesisBlock validates if the GenesisBlock was properly saved in disk.
	//
	// Verifies whenever it's possible to re-construct the eth state from disk and
	// asserts accounts balances, nonces, gas settings as defined in Genesis config.
	AssertPersistedGenesisBlock(genesis core.Genesis)

	// AssertPostTxSimulationState validates if the state saved in disk after TX simulation is correct.
	AssertPostTxSimulationState(from common.Address, tx *types.Transaction)
}

Tracer is used to trace and assert behaviour of lightchain `database` pkg.

func NewTracer added in v0.12.0

func NewTracer(cfg stdtracer.Config, chainDataDir string) (Tracer, error)

NewTracer creates a new Tracer instance.

If tracing is disabled, it will return a nullable Tracer that doesn't do anything.

DANGER: Tracing is not recommended in production due decrease in performance!

Use tracing only to debug bugs and for testing purposes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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