Skip to content

Commit

Permalink
#200 Upgrades Geth to 1.9.2 to fix #199.
Browse files Browse the repository at this point in the history
Fixes bug in cache memory size management.

PS: Missing hardcoded change: "return nil" in validateState() as well in core/block_validator.go
as validateBlock() otherwise the blocks are not compatible.
  • Loading branch information
EnchanterIO committed Sep 3, 2019
1 parent 6175f3e commit 22cc9c5
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 191 deletions.
312 changes: 202 additions & 110 deletions Gopkg.lock

Large diffs are not rendered by default.

35 changes: 13 additions & 22 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

[[constraint]]
name = "github.com/ethereum/go-ethereum"
version = "1.8.27"
version = "1.9.2"

[[constraint]]
branch = "master"
name = "github.com/mitchellh/go-homedir"

[[constraint]]
name = "go.uber.org/zap"
version = "1.8.0"

[[override]]
name = "github.com/tendermint/iavl"
Expand All @@ -21,28 +29,11 @@
[[override]]
name = "github.com/tendermint/go-amino"
version = "~0.14.1"

[[override]]
name = "golang.org/x/crypto"
revision = "ff983b9c42bc9fbf91556e191cc8efb585c16908"

[[constraint]]
branch = "master"
name = "github.com/mitchellh/go-homedir"

[[constraint]]
name = "go.uber.org/zap"
version = "1.8.0"

[prune]
non-go = true
go-tests = true
unused-packages = true
[[prune.project]]
name = "github.com/ethereum/go-ethereum"
non-go = false
unused-packages = false
[[prune.project]]
name = "github.com/karalabe/hid"
non-go = false
unused-packages = false
[[override]]
name = "github.com/russross/blackfriday"
version = "1.5.2"
64 changes: 49 additions & 15 deletions cmd/lightchain/ethereum_cli_ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ var (
RPCListenAddrFlag = ethUtils.RPCListenAddrFlag
RPCPortFlag = ethUtils.RPCPortFlag
RPCApiFlag = ethUtils.RPCApiFlag
RPCCORSDomainFlag = ethUtils.RPCCORSDomainFlag
RPCVirtualHostsFlag = ethUtils.RPCVirtualHostsFlag
RPCInsecureUnlockAllowedFlag = ethUtils.InsecureUnlockAllowedFlag

WSEnabledFlag = ethUtils.WSEnabledFlag
WSListenAddrFlag = ethUtils.WSListenAddrFlag
WSPortFlag = ethUtils.WSPortFlag
WSApiFlag = ethUtils.WSApiFlag
RPCCORSDomainFlag = ethUtils.RPCCORSDomainFlag
RPCVirtualHostsFlag = ethUtils.RPCVirtualHostsFlag
WSAllowedOriginsFlag = ethUtils.WSAllowedOriginsFlag

CacheFlag = ethUtils.CacheFlag
CacheDatabaseFlag = ethUtils.CacheDatabaseFlag
CacheTrieFlag = ethUtils.CacheTrieFlag
CacheGCFlag = ethUtils.CacheGCFlag
)

func addEthNodeFlags(cmd *cobra.Command) {
Expand All @@ -30,62 +37,72 @@ func addEthNodeFlags(cmd *cobra.Command) {
cmd.Flags().String(RPCApiFlag.GetName(), RPCApiFlag.Value, RPCApiFlag.Usage)
cmd.Flags().String(RPCCORSDomainFlag.GetName(), RPCCORSDomainFlag.Value, RPCCORSDomainFlag.Usage)
cmd.Flags().String(RPCVirtualHostsFlag.GetName(), RPCVirtualHostsFlag.Value, RPCVirtualHostsFlag.Usage)

cmd.Flags().Bool(RPCInsecureUnlockAllowedFlag.GetName(), false, RPCInsecureUnlockAllowedFlag.Usage)

// WS Flags
cmd.Flags().Bool(WSEnabledFlag.GetName(), false, WSEnabledFlag.Usage)
cmd.Flags().String(WSListenAddrFlag.GetName(), WSListenAddrFlag.Value, WSListenAddrFlag.Usage)
cmd.Flags().Int(WSPortFlag.GetName(), WSPortFlag.Value, WSPortFlag.Usage)
cmd.Flags().String(WSApiFlag.GetName(), WSApiFlag.Value, WSApiFlag.Usage)
cmd.Flags().String(WSAllowedOriginsFlag.GetName(), WSAllowedOriginsFlag.Usage, WSAllowedOriginsFlag.Usage)

// General
cmd.Flags().Int(CacheFlag.GetName(), CacheFlag.Value, CacheFlag.Usage)
cmd.Flags().Int(CacheDatabaseFlag.GetName(), CacheDatabaseFlag.Value, CacheDatabaseFlag.Usage)
cmd.Flags().Int(CacheTrieFlag.GetName(), CacheTrieFlag.Value, CacheTrieFlag.Usage)
cmd.Flags().Int(CacheGCFlag.GetName(), CacheGCFlag.Value, CacheGCFlag.Usage)
}

func newNodeClientCtx(dataDir string, cmd *cobra.Command) *cli.Context {

app := ethUtils.NewApp("0.0.0", "the lightchain command line interface")
app := ethUtils.NewApp("0.0.0", "0/0/0000", "Lightchain App")
flagSet := flag.NewFlagSet("Ethereum CLI ctx", flag.ExitOnError)

flagSet.String(ethUtils.DataDirFlag.GetName(), dataDir, ethUtils.DataDirFlag.Usage)

rpcEnabledFlagValue, _ := cmd.Flags().GetBool(RPCEnabledFlag.GetName())
flagSet.Bool(RPCEnabledFlag.GetName(), rpcEnabledFlagValue, RPCEnabledFlag.Usage)
flagSet.Set(RPCEnabledFlag.GetName(), strconv.FormatBool(rpcEnabledFlagValue))
flagSet.Set(RPCEnabledFlag.GetName(), strconv.FormatBool(rpcEnabledFlagValue))

rpcListenAddrValue, _ := cmd.Flags().GetString(RPCListenAddrFlag.GetName())
flagSet.String(RPCListenAddrFlag.GetName(), rpcListenAddrValue, RPCListenAddrFlag.Usage)
flagSet.Set(RPCListenAddrFlag.GetName(), rpcListenAddrValue)

rpcPortFlagValue, _ := cmd.Flags().GetInt(RPCPortFlag.GetName())
flagSet.Int(RPCPortFlag.GetName(), rpcPortFlagValue, RPCPortFlag.Usage)
flagSet.Set(RPCPortFlag.GetName(), strconv.Itoa(rpcPortFlagValue))

rpcApiFlagValue, _ := cmd.Flags().GetString(RPCApiFlag.GetName())
flagSet.String(RPCApiFlag.GetName(), rpcApiFlagValue, RPCApiFlag.Usage)
flagSet.Set(RPCApiFlag.GetName(), rpcApiFlagValue)

wsEnabledFlagValue, _ := cmd.Flags().GetBool(WSEnabledFlag.GetName())
flagSet.Bool(WSEnabledFlag.GetName(), wsEnabledFlagValue, WSEnabledFlag.Usage)
flagSet.Set(WSEnabledFlag.GetName(), strconv.FormatBool(wsEnabledFlagValue))

wsListenAddrFlagValue, _ := cmd.Flags().GetString(WSListenAddrFlag.GetName())
flagSet.String(WSListenAddrFlag.GetName(), wsListenAddrFlagValue, WSListenAddrFlag.Usage)
flagSet.Set(WSListenAddrFlag.GetName(), wsListenAddrFlagValue)

wsPortFlagValue, _ := cmd.Flags().GetInt(WSPortFlag.GetName())
flagSet.Int(WSPortFlag.GetName(), wsPortFlagValue, WSPortFlag.Usage)
flagSet.Set(WSPortFlag.GetName(), strconv.Itoa(wsPortFlagValue))

wsApiFlagValue, _ := cmd.Flags().GetString(WSApiFlag.GetName())
flagSet.String(WSApiFlag.GetName(), wsApiFlagValue, WSApiFlag.Usage)
flagSet.Set(WSApiFlag.GetName(), wsApiFlagValue)

rpcCORSDomainFlagValue, _ := cmd.Flags().GetString(RPCCORSDomainFlag.GetName())
flagSet.String(RPCCORSDomainFlag.GetName(), rpcCORSDomainFlagValue, RPCCORSDomainFlag.Usage)
flagSet.Set(RPCCORSDomainFlag.GetName(), rpcCORSDomainFlagValue)

rpcVirtualHostsFlagValue, _ := cmd.Flags().GetString(RPCVirtualHostsFlag.GetName())
flagSet.String(RPCVirtualHostsFlag.GetName(), rpcVirtualHostsFlagValue, RPCVirtualHostsFlag.Usage)
flagSet.Set(RPCVirtualHostsFlag.GetName(), rpcVirtualHostsFlagValue)


rpcInsecureUnlockAllowedFlagValue, _ := cmd.Flags().GetBool(RPCInsecureUnlockAllowedFlag.GetName())
flagSet.Bool(RPCInsecureUnlockAllowedFlag.GetName(), rpcInsecureUnlockAllowedFlagValue, RPCInsecureUnlockAllowedFlag.Usage)
flagSet.Set(RPCInsecureUnlockAllowedFlag.GetName(), strconv.FormatBool(rpcInsecureUnlockAllowedFlagValue))

wsAllowedOriginsFlagValue, _ := cmd.Flags().GetString(WSAllowedOriginsFlag.GetName())
flagSet.String(WSAllowedOriginsFlag.GetName(), wsAllowedOriginsFlagValue, WSAllowedOriginsFlag.Usage)
flagSet.Set(WSAllowedOriginsFlag.GetName(), wsAllowedOriginsFlagValue)
Expand All @@ -94,6 +111,23 @@ func newNodeClientCtx(dataDir string, cmd *cobra.Command) *cli.Context {
flagSet.String(ethUtils.GCModeFlag.GetName(), ethUtils.GCModeFlag.Value, ethUtils.GCModeFlag.Usage)
flagSet.Set(ethUtils.GCModeFlag.GetName(), ethUtils.GCModeFlag.Value)

// General
cacheFlagValue, _ := cmd.Flags().GetInt(CacheFlag.GetName())
flagSet.Int(CacheFlag.GetName(), cacheFlagValue, CacheFlag.Usage)
flagSet.Set(CacheFlag.GetName(), strconv.Itoa(cacheFlagValue))

cacheDatabaseFlagValue, _ := cmd.Flags().GetInt(CacheDatabaseFlag.GetName())
flagSet.Int(CacheDatabaseFlag.GetName(), cacheDatabaseFlagValue, CacheDatabaseFlag.Usage)
flagSet.Set(CacheDatabaseFlag.GetName(), strconv.Itoa(cacheDatabaseFlagValue))

cacheTrieFlagValue, _ := cmd.Flags().GetInt(CacheTrieFlag.GetName())
flagSet.Int(CacheTrieFlag.GetName(), cacheTrieFlagValue, CacheTrieFlag.Usage)
flagSet.Set(CacheTrieFlag.GetName(), strconv.Itoa(cacheTrieFlagValue))

cacheGCFlagValue, _ := cmd.Flags().GetInt(CacheGCFlag.GetName())
flagSet.Int(CacheGCFlag.GetName(), cacheGCFlagValue, CacheGCFlag.Usage)
flagSet.Set(CacheGCFlag.GetName(), strconv.Itoa(cacheGCFlagValue))

ctx := cli.NewContext(app, flagSet, nil)
return ctx
}
6 changes: 3 additions & 3 deletions cmd/lightchain/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
)

const Major = "1"
const Minor = "3"
const Fix = "1"
const Verbal = "Fast && Safe"
const Minor = "4"
const Fix = "0"
const Verbal = "Freezer Performance"

var versionCmd = &cobra.Command{
Use: "version",
Expand Down
12 changes: 9 additions & 3 deletions database/blockvalidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/consensus"
)

// Dummy block validator ignoring PoW, uncles and so on.
type NullBlockValidator struct{}
type NullBlockValidator struct{
config *params.ChainConfig // Chain configuration options
bc *core.BlockChain // Canonical block chain
engine consensus.Engine // Consensus engine used for validating
}

var _ core.Validator = NullBlockValidator{}

Expand All @@ -17,6 +23,6 @@ func (NullBlockValidator) ValidateBody(*ethTypes.Block) error {
}

// ValidateState does not validate anything.
func (NullBlockValidator) ValidateState(block, parent *ethTypes.Block, state *state.StateDB, receipts ethTypes.Receipts, usedGas uint64) error {
func (NullBlockValidator) ValidateState(block *ethTypes.Block, state *state.StateDB, receipts ethTypes.Receipts, usedGas uint64) error {
return nil
}
}
16 changes: 4 additions & 12 deletions database/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package database

import (
"time"
"path/filepath"
"errors"
"gopkg.in/urfave/cli.v1"
Expand Down Expand Up @@ -47,8 +46,8 @@ type GethConfig struct {

func NewConfig(dataDir string, metrics bool, ctx *cli.Context) (Config, error) {
gethCfg := GethConfig{
EthCfg: eth.DefaultConfig,
NodeCfg: DefaultEthNodeConfig(dataDir),
EthCfg: eth.DefaultConfig,
NodeCfg: DefaultEthNodeConfig(dataDir),
}

// Configure ethereum node server
Expand All @@ -57,7 +56,7 @@ func NewConfig(dataDir string, metrics bool, ctx *cli.Context) (Config, error) {
gethCfg.NodeCfg.P2P.NoDiscovery = true
gethCfg.NodeCfg.DataDir = dataDir

// IMPORTANT: If we do not define ".Name" Ethereum lib will automatically set it by the process name which will use
// IMPORTANT: If we do not define ".Name" Ethereum lib will automatically set it by the process name which will use
// to generate every subfolder underneath
gethCfg.NodeCfg.Name = "."

Expand All @@ -71,13 +70,6 @@ func NewConfig(dataDir string, metrics bool, ctx *cli.Context) (Config, error) {
ethUtils.SetEthConfig(ctx, ethereum, &gethCfg.EthCfg)
gethCfg.EthCfg.Ethash.PowMode = ethash.ModeFake

// Due to the low usages of the blockchain we need to reduce cache size to prevent huge number block replies on every restart.
// @TODO once the usage of blockchain is larger we should tune these values again accordingly
gethCfg.EthCfg.DatabaseCache = 256 // MB
gethCfg.EthCfg.TrieCleanCache = 64 // MB
gethCfg.EthCfg.TrieDirtyCache = 0 // MB
gethCfg.EthCfg.TrieTimeout = 10 * time.Minute

// To prevent DDOS TX spam, a min gas price must be defined
//
// 1 PHT = 0.15$
Expand All @@ -87,7 +79,7 @@ func NewConfig(dataDir string, metrics bool, ctx *cli.Context) (Config, error) {
// GPO is responsible for suggesting the right gas price so users don't have to
gethCfg.EthCfg.GPO.Default = big.NewInt(txclient.MinGasPrice)
// We don't use mining but this value is read from miner config anyway and used around the codebase
gethCfg.EthCfg.MinerGasPrice = big.NewInt(txclient.MinGasPrice)
gethCfg.EthCfg.Miner.GasPrice = big.NewInt(txclient.MinGasPrice)
// The TxPool is the most important and ensures TX price validation can happen, also web3 is using it
gethCfg.EthCfg.TxPool.PriceLimit = big.NewInt(txclient.MinGasPrice).Uint64()
gethCfg.EthCfg.TxPool.NoLocals = true
Expand Down
2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewDatabase(ctx *node.ServiceContext, ethCfg *eth.Config, consAPI consensus
currentBlock := ethereum.BlockChain().CurrentBlock()
ethereum.EventMux().Post(core.ChainHeadEvent{currentBlock})

ethereum.BlockChain().SetValidator(NullBlockValidator{})
//ethereum.BlockChain().SetValidator(NullBlockValidator{})

db := &Database{
eth: ethereum,
Expand Down
17 changes: 8 additions & 9 deletions database/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"reflect"
"fmt"
"io/ioutil"
"github.com/ethereum/go-ethereum/ethdb"

ethCore "github.com/ethereum/go-ethereum/core"
tmtLog "github.com/tendermint/tendermint/libs/log"

"github.com/lightstreams-network/lightchain/network"
"github.com/lightstreams-network/lightchain/log"
stdtracer "github.com/lightstreams-network/lightchain/tracer"
"github.com/ethereum/go-ethereum/core/rawdb"
)

func Init(cfg Config, ntw network.Network, trcCfg stdtracer.Config) error {
Expand All @@ -33,12 +32,12 @@ func Init(cfg Config, ntw network.Network, trcCfg stdtracer.Config) error {
if genesisBlob, err = ntw.DatabaseGenesis(); err != nil {
return err
}

if err = writeKeystoreFiles(logger, keystoreDir, keystoreFiles); err != nil {
err = fmt.Errorf("could not write keystore files: %v", err)
return err
}

genesis, err := parseBlobGenesis(genesisBlob)
if err != nil {
err = fmt.Errorf("unable to parse genesis file. err: %v", err)
Expand All @@ -51,7 +50,7 @@ func Init(cfg Config, ntw network.Network, trcCfg stdtracer.Config) error {
}
logger.Info("Generated genesis block", "path", cfg.genesisPath())

chainDb, err := ethdb.NewLDBDatabase(cfg.ChainDbDir(), 0, 0)
chainDb, err := rawdb.NewLevelDBDatabase(cfg.ChainDbDir(), 0, 0, "eth/db/chaindata/")
if err != nil {
err = fmt.Errorf("failed to open LDBD DB: %v", err)
return err
Expand All @@ -68,7 +67,7 @@ func Init(cfg Config, ntw network.Network, trcCfg stdtracer.Config) error {

trc, err := NewTracer(trcCfg, cfg.ChainDbDir())
trc.AssertPersistedGenesisBlock(*genesis)

return nil
}

Expand All @@ -91,7 +90,7 @@ func writeGenesisFile(genesisPath string, genesis *ethCore.Genesis) error {
if err != nil {
return err
}

f, err := os.Create(genesisPath)
if err != nil {
return err
Expand All @@ -100,7 +99,7 @@ func writeGenesisFile(genesisPath string, genesis *ethCore.Genesis) error {
if _, err := f.Write(genesisBlob); err != nil {
return err
}

return nil
}

Expand Down
16 changes: 8 additions & 8 deletions database/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewNode(cfg *Config, consensusAPI conAPI.API, registry *prometheus.Registry
if err != nil {
return nil, err
}

var trackedMetrics metrics.Metrics
if cfg.metrics {
trackedMetrics = metrics.NewMetrics(registry)
Expand Down Expand Up @@ -131,16 +131,14 @@ func registerEventHandlers(n *Node, events chan accounts.WalletEvent) error {
n.logger.Error(fmt.Errorf("failed to attach to self: %v", err).Error())
return err
}
stateReader := ethclient.NewClient(rpcClient)
chainStateReader := ethclient.NewClient(rpcClient)

// Open any wallets already attached
for _, wallet := range n.ethereum.AccountManager().Wallets() {
if err := wallet.Open(""); err != nil {
n.logger.Error("Failed to open wallet", "url", wallet.URL(), "err", err)
} else {
wallet.SelfDerive(accounts.DefaultBaseDerivationPath, stateReader)
}
}

// Listen for wallet event till termination
for event := range events {
switch event.Kind {
Expand All @@ -152,11 +150,13 @@ func registerEventHandlers(n *Node, events chan accounts.WalletEvent) error {
status, _ := event.Wallet.Status()
n.logger.Info("New wallet appeared", "url", event.Wallet.URL(), "status", status)

var derivationPaths []accounts.DerivationPath
if event.Wallet.URL().Scheme == "ledger" {
event.Wallet.SelfDerive(accounts.DefaultLedgerBaseDerivationPath, stateReader)
} else {
event.Wallet.SelfDerive(accounts.DefaultBaseDerivationPath, stateReader)
derivationPaths = append(derivationPaths, accounts.LegacyLedgerBaseDerivationPath)
}
derivationPaths = append(derivationPaths, accounts.DefaultBaseDerivationPath)

event.Wallet.SelfDerive(derivationPaths, chainStateReader)

case accounts.WalletDropped:
n.logger.Info("Old wallet dropped", "url", event.Wallet.URL())
Expand Down
Loading

0 comments on commit 22cc9c5

Please sign in to comment.