remove database field from Ethereum object (#1750)

This commit is contained in:
Alex Sharov 2021-04-19 14:56:44 +07:00 committed by GitHub
parent 00f700675b
commit 5019610cfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 70 deletions

View File

@ -16,28 +16,7 @@
package eth package eth
import ( /*
"context"
"errors"
"fmt"
"math/big"
"github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/consensus"
"github.com/ledgerwatch/turbo-geth/core"
"github.com/ledgerwatch/turbo-geth/core/bloombits"
"github.com/ledgerwatch/turbo-geth/core/rawdb"
"github.com/ledgerwatch/turbo-geth/core/state"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/core/vm"
"github.com/ledgerwatch/turbo-geth/eth/downloader"
"github.com/ledgerwatch/turbo-geth/eth/gasprice"
"github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/event"
"github.com/ledgerwatch/turbo-geth/params"
"github.com/ledgerwatch/turbo-geth/rpc"
)
// EthAPIBackend implements ethapi.Backend for full nodes // EthAPIBackend implements ethapi.Backend for full nodes
type EthAPIBackend struct { type EthAPIBackend struct {
extRPCEnabled bool extRPCEnabled bool
@ -362,3 +341,4 @@ func (b *EthAPIBackend) StatesInRange(ctx context.Context, fromBlock *types.Bloc
func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.IntraBlockState, func(), error) { func (b *EthAPIBackend) StateAtTransaction(ctx context.Context, block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.IntraBlockState, func(), error) {
return b.eth.stateAtTransaction(block, txIndex, reexec) return b.eth.stateAtTransaction(block, txIndex, reexec)
} }
*/

View File

@ -50,13 +50,11 @@ import (
"github.com/ledgerwatch/turbo-geth/eth/downloader" "github.com/ledgerwatch/turbo-geth/eth/downloader"
"github.com/ledgerwatch/turbo-geth/eth/ethconfig" "github.com/ledgerwatch/turbo-geth/eth/ethconfig"
"github.com/ledgerwatch/turbo-geth/eth/ethutils" "github.com/ledgerwatch/turbo-geth/eth/ethutils"
"github.com/ledgerwatch/turbo-geth/eth/gasprice"
"github.com/ledgerwatch/turbo-geth/eth/protocols/eth" "github.com/ledgerwatch/turbo-geth/eth/protocols/eth"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync" "github.com/ledgerwatch/turbo-geth/eth/stagedsync"
"github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages" "github.com/ledgerwatch/turbo-geth/eth/stagedsync/stages"
"github.com/ledgerwatch/turbo-geth/ethdb" "github.com/ledgerwatch/turbo-geth/ethdb"
"github.com/ledgerwatch/turbo-geth/ethdb/remote/remotedbserver" "github.com/ledgerwatch/turbo-geth/ethdb/remote/remotedbserver"
"github.com/ledgerwatch/turbo-geth/internal/ethapi"
"github.com/ledgerwatch/turbo-geth/log" "github.com/ledgerwatch/turbo-geth/log"
"github.com/ledgerwatch/turbo-geth/node" "github.com/ledgerwatch/turbo-geth/node"
"github.com/ledgerwatch/turbo-geth/p2p" "github.com/ledgerwatch/turbo-geth/p2p"
@ -85,22 +83,21 @@ type Ethereum struct {
snapDialCandidates enode.Iterator snapDialCandidates enode.Iterator
// DB interfaces // DB interfaces
chainDb ethdb.Database // Block chain database chainKV ethdb.RwKV // Same as chainDb, but different interface
chainKV ethdb.RwKV // Same as chainDb, but different interface
privateAPI *grpc.Server privateAPI *grpc.Server
engine consensus.Engine engine consensus.Engine
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
APIBackend *EthAPIBackend //APIBackend *EthAPIBackend
gasPrice *uint256.Int gasPrice *uint256.Int
etherbase common.Address etherbase common.Address
signer *ecdsa.PrivateKey signer *ecdsa.PrivateKey
networkID uint64 networkID uint64
netRPCService *ethapi.PublicNetAPI //netRPCService *ethapi.PublicNetAPI
p2pServer *p2p.Server p2pServer *p2p.Server
@ -273,7 +270,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth := &Ethereum{ eth := &Ethereum{
config: config, config: config,
chainDb: chainDb,
chainKV: chainDb.(ethdb.HasRwKV).RwKV(), chainKV: chainDb.(ethdb.HasRwKV).RwKV(),
engine: ethconfig.CreateConsensusEngine(chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb), engine: ethconfig.CreateConsensusEngine(chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb),
networkID: config.NetworkID, networkID: config.NetworkID,
@ -439,12 +435,12 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
eth.handler.SetStagedSync(stagedSync) eth.handler.SetStagedSync(stagedSync)
eth.handler.SetMining(mining) eth.handler.SetMining(mining)
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil} //eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
gpoParams := config.GPO gpoParams := config.GPO
if gpoParams.Default == nil { if gpoParams.Default == nil {
gpoParams.Default = config.Miner.GasPrice gpoParams.Default = config.Miner.GasPrice
} }
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams) //eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
eth.ethDialCandidates, err = setupDiscovery(eth.config.EthDiscoveryURLs) eth.ethDialCandidates, err = setupDiscovery(eth.config.EthDiscoveryURLs)
if err != nil { if err != nil {
return nil, err return nil, err
@ -498,6 +494,11 @@ func BlockchainRuntimeConfig(config *ethconfig.Config) (vm.Config, *core.CacheCo
// return extra // return extra
// } // }
func (s *Ethereum) APIs() []rpc.API {
return []rpc.API{}
}
/*
// APIs return the collection of RPC services the ethereum package offers. // APIs return the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else. // NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API { func (s *Ethereum) APIs() []rpc.API {
@ -564,6 +565,7 @@ func (s *Ethereum) APIs() []rpc.API {
}, },
}...) }...)
} }
*/
func (s *Ethereum) Etherbase() (eb common.Address, err error) { func (s *Ethereum) Etherbase() (eb common.Address, err error) {
s.lock.RLock() s.lock.RLock()
@ -684,7 +686,6 @@ func (s *Ethereum) IsMining() bool { return s.config.Miner.Enabled }
func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain } func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool } func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
func (s *Ethereum) Engine() consensus.Engine { return s.engine } func (s *Ethereum) Engine() consensus.Engine { return s.engine }
func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb }
func (s *Ethereum) ChainKV() ethdb.RwKV { return s.chainKV } func (s *Ethereum) ChainKV() ethdb.RwKV { return s.chainKV }
func (s *Ethereum) IsListening() bool { return true } // Always listening func (s *Ethereum) IsListening() bool { return true } // Always listening
func (s *Ethereum) Downloader() *downloader.Downloader { return s.handler.downloader } func (s *Ethereum) Downloader() *downloader.Downloader { return s.handler.downloader }
@ -698,7 +699,11 @@ func (s *Ethereum) ArchiveMode() bool { return !s.config.Pruning }
// Protocols returns all the currently configured // Protocols returns all the currently configured
// network protocols to start. // network protocols to start.
func (s *Ethereum) Protocols() []p2p.Protocol { func (s *Ethereum) Protocols() []p2p.Protocol {
headHeight, _ := stages.GetStageProgress(s.chainDb, stages.Finish) var headHeight uint64
_ = s.chainKV.View(context.Background(), func(tx ethdb.Tx) error {
headHeight, _ = stages.GetStageProgress(tx, stages.Finish)
return nil
})
protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.ethDialCandidates, s.chainConfig, s.genesisHash, headHeight) protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.ethDialCandidates, s.chainConfig, s.genesisHash, headHeight)
return protos return protos
} }

View File

@ -16,6 +16,7 @@
package eth package eth
/*
import ( import (
"time" "time"
) )
@ -33,3 +34,4 @@ const (
// to accumulate request an entire batch (avoiding hysteresis). // to accumulate request an entire batch (avoiding hysteresis).
bloomRetrievalWait = time.Duration(0) bloomRetrievalWait = time.Duration(0)
) )
*/

View File

@ -121,6 +121,8 @@ type Config struct {
Pruning bool // Whether to disable pruning and flush everything to disk Pruning bool // Whether to disable pruning and flush everything to disk
TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved. TxLookupLimit uint64 `toml:",omitempty"` // The maximum number of blocks from head whose tx indices are reserved.
EnableDownloaderV2 bool
StorageMode ethdb.StorageMode StorageMode ethdb.StorageMode
CacheSize datasize.ByteSize // Cache size for execution stage CacheSize datasize.ByteSize // Cache size for execution stage
BatchSize datasize.ByteSize // Batch size for execution stage BatchSize datasize.ByteSize // Batch size for execution stage

View File

@ -15,30 +15,3 @@
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package eth package eth
import (
"github.com/ledgerwatch/turbo-geth/core"
"github.com/ledgerwatch/turbo-geth/core/state"
"github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/core/vm"
)
// stateAtBlock retrieves the state database associated with a certain block.
// If no state is locally available for the given block, a number of blocks are
// attempted to be reexecuted to generate the desired state.
func (eth *Ethereum) stateAtBlock(block *types.Block, reexec uint64) (statedb *state.IntraBlockState, release func(), err error) {
return nil, nil, nil
}
// statesInRange retrieves a batch of state databases associated with the specific
// block ranges. If no state is locally available for the given range, a number of
// blocks are attempted to be reexecuted to generate the ancestor state.
func (eth *Ethereum) statesInRange(fromBlock, toBlock *types.Block, reexec uint64) (states []*state.IntraBlockState, release func(), err error) {
return nil, nil, nil
}
// stateAtTransaction returns the execution environment of a certain transaction.
func (eth *Ethereum) stateAtTransaction(block *types.Block, txIndex int, reexec uint64) (core.Message, vm.BlockContext, *state.IntraBlockState, func(), error) {
return nil, vm.BlockContext{}, nil, nil, nil
}

View File

@ -17,32 +17,25 @@
package ethapi package ethapi
import ( import (
"bytes"
"context" "context"
"errors" "errors"
"fmt" "fmt"
"math/big" "math/big"
"time" "time"
"github.com/davecgh/go-spew/spew"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"github.com/ledgerwatch/turbo-geth/accounts/abi" "github.com/ledgerwatch/turbo-geth/accounts/abi"
"github.com/ledgerwatch/turbo-geth/common" "github.com/ledgerwatch/turbo-geth/common"
"github.com/ledgerwatch/turbo-geth/common/hexutil" "github.com/ledgerwatch/turbo-geth/common/hexutil"
"github.com/ledgerwatch/turbo-geth/common/math" "github.com/ledgerwatch/turbo-geth/common/math"
"github.com/ledgerwatch/turbo-geth/consensus/ethash"
"github.com/ledgerwatch/turbo-geth/core" "github.com/ledgerwatch/turbo-geth/core"
"github.com/ledgerwatch/turbo-geth/core/types" "github.com/ledgerwatch/turbo-geth/core/types"
"github.com/ledgerwatch/turbo-geth/core/vm" "github.com/ledgerwatch/turbo-geth/core/vm"
"github.com/ledgerwatch/turbo-geth/crypto"
"github.com/ledgerwatch/turbo-geth/log" "github.com/ledgerwatch/turbo-geth/log"
"github.com/ledgerwatch/turbo-geth/p2p"
"github.com/ledgerwatch/turbo-geth/params"
"github.com/ledgerwatch/turbo-geth/rlp"
"github.com/ledgerwatch/turbo-geth/rpc" "github.com/ledgerwatch/turbo-geth/rpc"
) )
/*
// PublicEthereumAPI provides an API to access Ethereum related information. // PublicEthereumAPI provides an API to access Ethereum related information.
// It offers only methods that operate on public data that is freely available to anyone. // It offers only methods that operate on public data that is freely available to anyone.
type PublicEthereumAPI struct { type PublicEthereumAPI struct {
@ -328,6 +321,7 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A
state.GetState(address, &keyHash, &res) state.GetState(address, &keyHash, &res)
return res.Bytes(), state.Error() return res.Bytes(), state.Error()
} }
*/
// CallArgs represents the arguments for a call. // CallArgs represents the arguments for a call.
type CallArgs struct { type CallArgs struct {
@ -459,7 +453,7 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
// Execute the message. // Execute the message.
gp := new(core.GasPool).AddGas(math.MaxUint64) gp := new(core.GasPool).AddGas(math.MaxUint64)
result, err := core.ApplyMessage(evm, msg, gp, true /* refunds */, false /* gasBailout */) result, err := core.ApplyMessage(evm, msg, gp, true, false)
if err := vmError(); err != nil { if err := vmError(); err != nil {
return nil, err return nil, err
} }
@ -504,6 +498,7 @@ func (e *RevertError) ErrorData() interface{} {
return e.reason return e.reason
} }
/*
// Call executes the given transaction on the state for the given block number. // Call executes the given transaction on the state for the given block number.
// //
// Additionally, the caller can specify a batch of contract for fields overriding. // Additionally, the caller can specify a batch of contract for fields overriding.
@ -644,6 +639,7 @@ func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs, bl
} }
return DoEstimateGas(ctx, s.b, args, bNrOrHash, s.b.RPCGasCap()) return DoEstimateGas(ctx, s.b, args, bNrOrHash, s.b.RPCGasCap())
} }
*/
// ExecutionResult groups all structured logs emitted by the EVM // ExecutionResult groups all structured logs emitted by the EVM
// while replaying a transaction in debug mode as well as transaction // while replaying a transaction in debug mode as well as transaction
@ -765,6 +761,8 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool) (map[string]i
return fields, nil return fields, nil
} }
/*
// rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires // rpcMarshalHeader uses the generalized output filler, then adds the total difficulty field, which requires
// a `PublicBlockchainAPI`. // a `PublicBlockchainAPI`.
func (s *PublicBlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Header) map[string]interface{} { func (s *PublicBlockChainAPI) rpcMarshalHeader(ctx context.Context, header *types.Header) map[string]interface{} {
@ -785,6 +783,7 @@ func (s *PublicBlockChainAPI) rpcMarshalBlock(ctx context.Context, b *types.Bloc
} }
return fields, err return fields, err
} }
*/
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction // RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
type RPCTransaction struct { type RPCTransaction struct {
@ -850,10 +849,12 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
return result return result
} }
/*
// newRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation // newRPCPendingTransaction returns a pending transaction that will serialize to the RPC representation
func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction { func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction {
return newRPCTransaction(tx, common.Hash{}, 0, 0) return newRPCTransaction(tx, common.Hash{}, 0, 0)
} }
*/
// newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation. // newRPCTransactionFromBlockIndex returns a transaction that will serialize to the RPC representation.
func newRPCTransactionFromBlockIndex(b *types.Block, index uint64) *RPCTransaction { func newRPCTransactionFromBlockIndex(b *types.Block, index uint64) *RPCTransaction {
@ -864,6 +865,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, index uint64) *RPCTransacti
return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index) return newRPCTransaction(txs[index], b.Hash(), b.NumberU64(), index)
} }
/*
// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index. // newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.Bytes { func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.Bytes {
txs := b.Transactions() txs := b.Transactions()
@ -873,6 +875,7 @@ func newRPCRawTransactionFromBlockIndex(b *types.Block, index uint64) hexutil.By
blob, _ := txs[index].MarshalBinary() blob, _ := txs[index].MarshalBinary()
return blob return blob
} }
*/
// newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation. // newRPCTransactionFromBlockHash returns a transaction that will serialize to the RPC representation.
func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash) *RPCTransaction { func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash) *RPCTransaction {
@ -884,6 +887,7 @@ func newRPCTransactionFromBlockHash(b *types.Block, hash common.Hash) *RPCTransa
return nil return nil
} }
/*
// PublicTransactionPoolAPI exposes methods for the RPC interface // PublicTransactionPoolAPI exposes methods for the RPC interface
type PublicTransactionPoolAPI struct { type PublicTransactionPoolAPI struct {
b Backend b Backend
@ -1351,3 +1355,4 @@ func checkTxFee(gasPrice *big.Int, gas uint64, cap float64) error {
} }
return nil return nil
} }
*/

View File

@ -88,6 +88,11 @@ type Backend interface {
Engine() consensus.Engine Engine() consensus.Engine
} }
func GetAPIs(apiBackend Backend) []rpc.API {
return []rpc.API{}
}
/*
func GetAPIs(apiBackend Backend) []rpc.API { func GetAPIs(apiBackend Backend) []rpc.API {
nonceLock := new(AddrLocker) nonceLock := new(AddrLocker)
return []rpc.API{ return []rpc.API{
@ -123,3 +128,4 @@ func GetAPIs(apiBackend Backend) []rpc.API {
}, },
} }
} }
*/

View File

@ -50,6 +50,11 @@ var (
Value: 500, Value: 500,
} }
DownloaderV2Flag = cli.BoolFlag{
Name: "downloader.v2",
Usage: "enable experimental downloader v2",
}
StorageModeFlag = cli.StringFlag{ StorageModeFlag = cli.StringFlag{
Name: "storage-mode", Name: "storage-mode",
Usage: `Configures the storage mode of the app: Usage: `Configures the storage mode of the app:
@ -113,6 +118,7 @@ var (
) )
func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config) { func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config) {
cfg.EnableDownloaderV2 = ctx.GlobalBool(DownloaderV2Flag.Name)
mode, err := ethdb.StorageModeFromString(ctx.GlobalString(StorageModeFlag.Name)) mode, err := ethdb.StorageModeFromString(ctx.GlobalString(StorageModeFlag.Name))
if err != nil { if err != nil {
utils.Fatalf(fmt.Sprintf("error while parsing mode: %v", err)) utils.Fatalf(fmt.Sprintf("error while parsing mode: %v", err))