2015-07-07 00:54:22 +00:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-07-22 16:48:40 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 00:54:22 +00:00
|
|
|
//
|
2015-07-23 16:35:11 +00:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 00:54:22 +00:00
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2015-07-22 16:48:40 +00:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 00:54:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 16:48:40 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 00:54:22 +00:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 16:48:40 +00:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 00:54:22 +00:00
|
|
|
|
2015-07-07 03:08:16 +00:00
|
|
|
// Package eth implements the Ethereum protocol.
|
2014-12-14 18:03:24 +00:00
|
|
|
package eth
|
|
|
|
|
|
|
|
import (
|
2020-11-13 16:16:47 +00:00
|
|
|
"context"
|
2020-09-19 14:16:04 +00:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
2017-04-12 14:27:23 +00:00
|
|
|
"errors"
|
2015-01-04 13:20:16 +00:00
|
|
|
"fmt"
|
2020-09-19 14:16:04 +00:00
|
|
|
"io/ioutil"
|
2017-05-16 19:07:27 +00:00
|
|
|
"math/big"
|
2020-07-15 12:26:59 +00:00
|
|
|
"os"
|
2020-10-23 11:18:45 +00:00
|
|
|
"path"
|
2020-02-13 14:45:02 +00:00
|
|
|
"reflect"
|
2017-04-12 14:27:23 +00:00
|
|
|
"runtime"
|
2016-05-12 17:32:04 +00:00
|
|
|
"sync"
|
2017-04-10 08:43:01 +00:00
|
|
|
"sync/atomic"
|
2020-11-13 16:16:47 +00:00
|
|
|
"time"
|
2020-10-13 12:56:16 +00:00
|
|
|
|
2021-03-05 20:34:23 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/turbo/snapshotsync"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/turbo/snapshotsync/bittorrent"
|
|
|
|
|
|
|
|
ethereum "github.com/ledgerwatch/turbo-geth"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/etl"
|
2020-10-10 06:06:54 +00:00
|
|
|
"google.golang.org/grpc"
|
2020-09-11 20:17:37 +00:00
|
|
|
"google.golang.org/grpc/credentials"
|
2020-09-02 11:24:27 +00:00
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/accounts"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/hexutil"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/consensus"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/consensus/clique"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/consensus/ethash"
|
|
|
|
"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/types"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/core/vm"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth/downloader"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth/filters"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/eth/gasprice"
|
2020-11-17 19:13:41 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/eth/stagedsync"
|
2019-05-27 13:51:49 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb"
|
2020-03-20 10:06:14 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/ethdb/remote/remotedbserver"
|
2019-05-27 13:51:49 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/event"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/internal/ethapi"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/log"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/miner"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/node"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/p2p"
|
2020-02-13 13:38:30 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/p2p/enode"
|
2019-05-27 13:51:49 +00:00
|
|
|
"github.com/ledgerwatch/turbo-geth/p2p/enr"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/params"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/rlp"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/rpc"
|
2014-12-14 18:03:24 +00:00
|
|
|
)
|
|
|
|
|
2016-06-30 10:03:26 +00:00
|
|
|
// Ethereum implements the Ethereum full node service.
|
|
|
|
type Ethereum struct {
|
2019-03-27 11:23:08 +00:00
|
|
|
config *Config
|
2017-09-05 16:18:28 +00:00
|
|
|
|
2015-10-19 14:08:17 +00:00
|
|
|
// Handlers
|
2015-04-18 00:21:07 +00:00
|
|
|
txPool *core.TxPool
|
2015-08-31 15:09:50 +00:00
|
|
|
blockchain *core.BlockChain
|
2015-04-18 00:21:07 +00:00
|
|
|
protocolManager *ProtocolManager
|
2020-05-22 11:46:34 +00:00
|
|
|
dialCandidates enode.Iterator
|
2017-09-05 16:18:28 +00:00
|
|
|
|
2015-12-16 03:26:23 +00:00
|
|
|
// DB interfaces
|
2021-03-01 04:02:22 +00:00
|
|
|
chainDb ethdb.Database // Block chain database
|
|
|
|
chainKV ethdb.KV // Same as chainDb, but different interface
|
2020-10-10 06:06:54 +00:00
|
|
|
privateAPI *grpc.Server
|
2014-12-14 18:03:24 +00:00
|
|
|
|
2015-12-16 03:26:23 +00:00
|
|
|
eventMux *event.TypeMux
|
2021-03-05 20:34:23 +00:00
|
|
|
engine consensus.Engine
|
2015-12-16 03:26:23 +00:00
|
|
|
accountManager *accounts.Manager
|
2015-05-26 12:17:43 +00:00
|
|
|
|
2020-10-12 08:39:04 +00:00
|
|
|
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
|
2017-08-18 19:52:20 +00:00
|
|
|
|
2018-05-09 07:59:00 +00:00
|
|
|
APIBackend *EthAPIBackend
|
2015-10-26 21:24:09 +00:00
|
|
|
|
2017-05-29 07:21:34 +00:00
|
|
|
miner *miner.Miner
|
|
|
|
gasPrice *big.Int
|
|
|
|
etherbase common.Address
|
2014-12-14 18:03:24 +00:00
|
|
|
|
2018-06-14 10:14:52 +00:00
|
|
|
networkID uint64
|
2015-12-16 03:26:23 +00:00
|
|
|
netRPCService *ethapi.PublicNetAPI
|
2017-05-29 07:21:34 +00:00
|
|
|
|
2020-08-15 17:32:05 +00:00
|
|
|
p2pServer *p2p.Server
|
2020-07-15 05:10:17 +00:00
|
|
|
txPoolStarted bool
|
2014-12-14 18:03:24 +00:00
|
|
|
|
2020-11-13 16:16:47 +00:00
|
|
|
torrentClient *bittorrent.Client
|
2020-10-13 12:56:16 +00:00
|
|
|
|
2020-08-03 17:40:46 +00:00
|
|
|
lock sync.RWMutex // Protects the variadic fields (e.g. gas price and etherbase)
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 10:03:26 +00:00
|
|
|
// New creates a new Ethereum object (including the
|
2015-12-16 03:26:23 +00:00
|
|
|
// initialisation of the common Ethereum object)
|
2020-08-03 17:40:46 +00:00
|
|
|
func New(stack *node.Node, config *Config) (*Ethereum, error) {
|
2018-08-23 10:02:36 +00:00
|
|
|
// Ensure configuration values are compatible and sane
|
2017-04-12 14:27:23 +00:00
|
|
|
if config.SyncMode == downloader.LightSync {
|
|
|
|
return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
|
|
|
|
}
|
|
|
|
if !config.SyncMode.IsValid() {
|
|
|
|
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
|
|
|
|
}
|
2019-04-23 07:08:51 +00:00
|
|
|
if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 {
|
|
|
|
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", DefaultConfig.Miner.GasPrice)
|
|
|
|
config.Miner.GasPrice = new(big.Int).Set(DefaultConfig.Miner.GasPrice)
|
2018-08-23 10:02:36 +00:00
|
|
|
}
|
2020-05-07 13:31:14 +00:00
|
|
|
if !config.Pruning && config.TrieDirtyCache > 0 {
|
2020-05-06 10:01:01 +00:00
|
|
|
if config.SnapshotCache > 0 {
|
|
|
|
config.TrieCleanCache += config.TrieDirtyCache * 3 / 5
|
|
|
|
config.SnapshotCache += config.TrieDirtyCache * 2 / 5
|
|
|
|
} else {
|
|
|
|
config.TrieCleanCache += config.TrieDirtyCache
|
|
|
|
}
|
2019-02-05 10:49:59 +00:00
|
|
|
config.TrieDirtyCache = 0
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:52:15 +00:00
|
|
|
tmpdir := path.Join(stack.Config().DataDir, etl.TmpDirName)
|
|
|
|
|
2018-08-23 10:02:36 +00:00
|
|
|
// Assemble the Ethereum object
|
2021-03-01 04:02:22 +00:00
|
|
|
var chainDb ethdb.Database
|
2020-07-15 06:15:48 +00:00
|
|
|
var err error
|
|
|
|
if config.EnableDebugProtocol {
|
2020-07-19 08:11:53 +00:00
|
|
|
if err = os.RemoveAll("simulator"); err != nil {
|
|
|
|
return nil, fmt.Errorf("removing simulator db: %w", err)
|
|
|
|
}
|
2020-07-15 12:26:59 +00:00
|
|
|
chainDb = ethdb.MustOpen("simulator")
|
2020-05-27 16:24:34 +00:00
|
|
|
} else {
|
2021-03-01 04:02:22 +00:00
|
|
|
chainDb, err = stack.OpenDatabaseWithFreezer("chaindata", tmpdir)
|
2020-08-15 17:32:05 +00:00
|
|
|
if err != nil {
|
2020-07-15 06:15:48 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-27 16:24:34 +00:00
|
|
|
}
|
2020-03-20 10:06:14 +00:00
|
|
|
|
2020-07-15 06:15:48 +00:00
|
|
|
chainConfig, genesisHash, _, genesisErr := core.SetupGenesisBlock(chainDb, config.Genesis, config.StorageMode.History, false /* overwrite */)
|
2020-05-19 10:28:20 +00:00
|
|
|
|
2017-03-02 13:03:33 +00:00
|
|
|
if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok {
|
|
|
|
return nil, genesisErr
|
2015-10-12 15:58:51 +00:00
|
|
|
}
|
2017-03-02 13:03:33 +00:00
|
|
|
log.Info("Initialised chain configuration", "config", chainConfig)
|
|
|
|
|
2020-11-13 16:16:47 +00:00
|
|
|
var torrentClient *bittorrent.Client
|
|
|
|
if config.SyncMode == downloader.StagedSync && config.SnapshotMode != (snapshotsync.SnapshotMode{}) && config.NetworkID == params.MainnetChainConfig.ChainID.Uint64() {
|
|
|
|
if config.ExternalSnapshotDownloaderAddr != "" {
|
|
|
|
cli, cl, innerErr := snapshotsync.NewClient(config.ExternalSnapshotDownloaderAddr)
|
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
|
|
|
}
|
|
|
|
defer cl() //nolint
|
2020-10-13 12:56:16 +00:00
|
|
|
|
2020-11-13 16:16:47 +00:00
|
|
|
_, innerErr = cli.Download(context.Background(), &snapshotsync.DownloadSnapshotRequest{
|
|
|
|
NetworkId: config.NetworkID,
|
|
|
|
Type: config.SnapshotMode.ToSnapshotTypes(),
|
|
|
|
})
|
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
|
|
|
}
|
|
|
|
|
|
|
|
waitDownload := func() (map[snapshotsync.SnapshotType]*snapshotsync.SnapshotsInfo, error) {
|
|
|
|
snapshotReadinessCheck := func(mp map[snapshotsync.SnapshotType]*snapshotsync.SnapshotsInfo, tp snapshotsync.SnapshotType) bool {
|
|
|
|
if mp[tp].Readiness != int32(100) {
|
|
|
|
log.Info("Downloading", "snapshot", tp, "%", mp[tp].Readiness)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
mp := make(map[snapshotsync.SnapshotType]*snapshotsync.SnapshotsInfo)
|
|
|
|
snapshots, err1 := cli.Snapshots(context.Background(), &snapshotsync.SnapshotsRequest{NetworkId: config.NetworkID})
|
|
|
|
if err1 != nil {
|
|
|
|
return nil, err1
|
|
|
|
}
|
|
|
|
for i := range snapshots.Info {
|
|
|
|
if mp[snapshots.Info[i].Type].SnapshotBlock < snapshots.Info[i].SnapshotBlock && snapshots.Info[i] != nil {
|
|
|
|
mp[snapshots.Info[i].Type] = snapshots.Info[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
downloaded := true
|
|
|
|
if config.SnapshotMode.Headers {
|
|
|
|
if !snapshotReadinessCheck(mp, snapshotsync.SnapshotType_headers) {
|
|
|
|
downloaded = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if config.SnapshotMode.Bodies {
|
|
|
|
if !snapshotReadinessCheck(mp, snapshotsync.SnapshotType_bodies) {
|
|
|
|
downloaded = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if config.SnapshotMode.State {
|
|
|
|
if !snapshotReadinessCheck(mp, snapshotsync.SnapshotType_state) {
|
|
|
|
downloaded = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if config.SnapshotMode.Receipts {
|
|
|
|
if !snapshotReadinessCheck(mp, snapshotsync.SnapshotType_receipts) {
|
|
|
|
downloaded = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if downloaded {
|
|
|
|
return mp, nil
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
downloadedSnapshots, innerErr := waitDownload()
|
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
|
|
|
}
|
2021-03-01 04:02:22 +00:00
|
|
|
snapshotKV := chainDb.(ethdb.HasKV).KV()
|
2020-11-13 16:16:47 +00:00
|
|
|
|
2021-01-02 19:28:37 +00:00
|
|
|
snapshotKV, innerErr = snapshotsync.WrapBySnapshotsFromDownloader(snapshotKV, downloadedSnapshots)
|
2020-11-13 16:16:47 +00:00
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
|
|
|
}
|
2021-03-01 04:02:22 +00:00
|
|
|
chainDb.(ethdb.HasKV).SetKV(snapshotKV)
|
2021-01-02 19:28:37 +00:00
|
|
|
innerErr = snapshotsync.PostProcessing(chainDb, config.SnapshotMode, downloadedSnapshots)
|
2020-11-13 16:16:47 +00:00
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
var dbPath string
|
|
|
|
dbPath, err = stack.Config().ResolvePath("snapshots")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
torrentClient, err = bittorrent.New(dbPath, config.SnapshotSeeding)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-01-02 19:28:37 +00:00
|
|
|
|
2020-11-13 16:16:47 +00:00
|
|
|
err = torrentClient.Load(chainDb)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = torrentClient.AddSnapshotsTorrents(context.Background(), chainDb, config.NetworkID, config.SnapshotMode)
|
|
|
|
if err == nil {
|
|
|
|
torrentClient.Download()
|
2021-03-01 04:02:22 +00:00
|
|
|
snapshotKV := chainDb.(ethdb.HasKV).KV()
|
2021-01-02 19:28:37 +00:00
|
|
|
mp, innerErr := torrentClient.GetSnapshots(chainDb, config.NetworkID)
|
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshotKV, innerErr = snapshotsync.WrapBySnapshotsFromDownloader(snapshotKV, mp)
|
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
2020-11-13 16:16:47 +00:00
|
|
|
}
|
2021-03-01 04:02:22 +00:00
|
|
|
chainDb.(ethdb.HasKV).SetKV(snapshotKV)
|
2021-01-02 19:28:37 +00:00
|
|
|
innerErr = snapshotsync.PostProcessing(chainDb, config.SnapshotMode, mp)
|
|
|
|
if innerErr != nil {
|
|
|
|
return nil, innerErr
|
2020-11-13 16:16:47 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log.Error("There was an error in snapshot init. Swithing to regular sync", "err", err)
|
|
|
|
}
|
2020-10-13 12:56:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 10:03:26 +00:00
|
|
|
eth := &Ethereum{
|
2020-10-12 08:39:04 +00:00
|
|
|
config: config,
|
|
|
|
chainDb: chainDb,
|
2021-03-01 04:02:22 +00:00
|
|
|
chainKV: chainDb.(ethdb.HasKV).KV(),
|
2020-10-12 08:39:04 +00:00
|
|
|
eventMux: stack.EventMux(),
|
|
|
|
accountManager: stack.AccountManager(),
|
2021-03-05 20:34:23 +00:00
|
|
|
engine: CreateConsensusEngine(stack, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb),
|
2020-10-12 08:39:04 +00:00
|
|
|
networkID: config.NetworkID,
|
|
|
|
gasPrice: config.Miner.GasPrice,
|
|
|
|
etherbase: config.Miner.Etherbase,
|
|
|
|
bloomRequests: make(chan chan *bloombits.Retrieval),
|
|
|
|
p2pServer: stack.Server(),
|
2020-10-13 12:56:16 +00:00
|
|
|
torrentClient: torrentClient,
|
2015-07-10 12:29:40 +00:00
|
|
|
}
|
2016-03-01 22:32:43 +00:00
|
|
|
|
2019-05-27 13:51:49 +00:00
|
|
|
log.Info("Initialising Ethereum protocol", "versions", ProtocolVersions, "network", config.NetworkID)
|
|
|
|
|
2019-02-21 13:14:35 +00:00
|
|
|
bcVersion := rawdb.ReadDatabaseVersion(chainDb)
|
|
|
|
var dbVer = "<nil>"
|
|
|
|
if bcVersion != nil {
|
|
|
|
dbVer = fmt.Sprintf("%d", *bcVersion)
|
|
|
|
}
|
2015-12-16 03:26:23 +00:00
|
|
|
|
2015-04-13 08:13:52 +00:00
|
|
|
if !config.SkipBcVersionCheck {
|
2019-01-11 11:49:12 +00:00
|
|
|
if bcVersion != nil && *bcVersion > core.BlockChainVersion {
|
|
|
|
return nil, fmt.Errorf("database version is v%d, Geth %s only supports v%d", *bcVersion, params.VersionWithMeta, core.BlockChainVersion)
|
2019-02-21 13:14:35 +00:00
|
|
|
} else if bcVersion == nil || *bcVersion < core.BlockChainVersion {
|
|
|
|
log.Warn("Upgrade blockchain database version", "from", dbVer, "to", core.BlockChainVersion)
|
2020-10-24 06:57:09 +00:00
|
|
|
if err2 := rawdb.WriteDatabaseVersion(chainDb, core.BlockChainVersion); err2 != nil {
|
|
|
|
return nil, err2
|
|
|
|
}
|
2015-04-13 08:13:52 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-13 14:45:02 +00:00
|
|
|
|
2020-06-09 13:11:09 +00:00
|
|
|
err = ethdb.SetStorageModeIfNotExist(chainDb, config.StorageMode)
|
2020-02-13 14:45:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-06-09 13:11:09 +00:00
|
|
|
sm, err := ethdb.GetStorageModeFromDB(chainDb)
|
2020-02-13 14:45:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(sm, config.StorageMode) {
|
|
|
|
return nil, errors.New("mode is " + config.StorageMode.ToString() + " original mode is " + sm.ToString())
|
|
|
|
}
|
|
|
|
|
2020-08-01 16:56:57 +00:00
|
|
|
vmConfig, cacheConfig := BlockchainRuntimeConfig(config)
|
2020-07-16 13:27:24 +00:00
|
|
|
txCacher := core.NewTxSenderCacher(runtime.NumCPU())
|
2020-08-01 16:56:57 +00:00
|
|
|
eth.blockchain, err = core.NewBlockChain(chainDb, cacheConfig, chainConfig, eth.engine, vmConfig, eth.shouldPreserve, txCacher)
|
2015-06-08 10:12:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-04-24 16:57:43 +00:00
|
|
|
if config.SyncMode != downloader.StagedSync {
|
|
|
|
_, err = eth.blockchain.GetTrieDbState()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-02-10 17:05:32 +00:00
|
|
|
}
|
2019-12-06 11:19:00 +00:00
|
|
|
|
|
|
|
eth.blockchain.EnableReceipts(config.StorageMode.Receipts)
|
|
|
|
eth.blockchain.EnableTxLookupIndex(config.StorageMode.TxIndex)
|
|
|
|
|
2017-03-02 13:03:33 +00:00
|
|
|
// Rewind the chain in case of an incompatible config upgrade.
|
|
|
|
if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
|
|
|
|
log.Warn("Rewinding chain to upgrade configuration", "err", compat)
|
|
|
|
eth.blockchain.SetHead(compat.RewindTo)
|
2020-10-24 06:57:09 +00:00
|
|
|
err = rawdb.WriteChainConfig(chainDb, genesisHash, chainConfig)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-02 13:03:33 +00:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:09:39 +00:00
|
|
|
if config.TxPool.Journal != "" {
|
2020-10-28 09:52:15 +00:00
|
|
|
config.TxPool.Journal, err = stack.ResolvePath(config.TxPool.Journal)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-07-28 13:09:39 +00:00
|
|
|
}
|
2020-07-09 12:53:35 +00:00
|
|
|
|
2020-07-23 20:52:41 +00:00
|
|
|
eth.txPool = core.NewTxPool(config.TxPool, chainConfig, chainDb, txCacher)
|
2015-06-15 09:33:08 +00:00
|
|
|
|
2020-11-17 19:13:41 +00:00
|
|
|
stagedSync := config.StagedSync
|
|
|
|
|
|
|
|
// setting notifier to support streaming events to rpc daemon
|
|
|
|
remoteEvents := remotedbserver.NewEvents()
|
|
|
|
if stagedSync == nil {
|
|
|
|
// if there is not stagedsync, we create one with the custom notifier
|
|
|
|
stagedSync = stagedsync.New(stagedsync.DefaultStages(), stagedsync.DefaultUnwindOrder(), stagedsync.OptionalParameters{Notifier: remoteEvents})
|
|
|
|
} else {
|
|
|
|
// otherwise we add one if needed
|
|
|
|
if stagedSync.Notifier == nil {
|
|
|
|
stagedSync.Notifier = remoteEvents
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 17:32:05 +00:00
|
|
|
if stack.Config().PrivateApiAddr != "" {
|
2020-09-11 20:17:37 +00:00
|
|
|
if stack.Config().TLSConnection {
|
2020-09-19 14:16:04 +00:00
|
|
|
// load peer cert/key, ca cert
|
2020-09-11 20:17:37 +00:00
|
|
|
var creds credentials.TransportCredentials
|
2020-09-19 14:16:04 +00:00
|
|
|
|
|
|
|
if stack.Config().TLSCACert != "" {
|
|
|
|
var peerCert tls.Certificate
|
|
|
|
var caCert []byte
|
|
|
|
peerCert, err = tls.LoadX509KeyPair(stack.Config().TLSCertFile, stack.Config().TLSKeyFile)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("load peer cert/key error:%v", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
caCert, err = ioutil.ReadFile(stack.Config().TLSCACert)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("read ca cert file error:%v", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
caCertPool := x509.NewCertPool()
|
|
|
|
caCertPool.AppendCertsFromPEM(caCert)
|
|
|
|
creds = credentials.NewTLS(&tls.Config{
|
|
|
|
Certificates: []tls.Certificate{peerCert},
|
|
|
|
ClientCAs: caCertPool,
|
|
|
|
ClientAuth: tls.RequireAndVerifyClientCert,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
creds, err = credentials.NewServerTLSFromFile(stack.Config().TLSCertFile, stack.Config().TLSKeyFile)
|
|
|
|
}
|
|
|
|
|
2020-09-11 20:17:37 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-03-01 04:02:22 +00:00
|
|
|
eth.privateAPI, err = remotedbserver.StartGrpc(chainDb.(ethdb.HasKV).KV(), eth, stack.Config().PrivateApiAddr, &creds, remoteEvents)
|
2020-10-10 06:06:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-11 20:17:37 +00:00
|
|
|
} else {
|
2021-03-01 04:02:22 +00:00
|
|
|
eth.privateAPI, err = remotedbserver.StartGrpc(chainDb.(ethdb.HasKV).KV(), eth, stack.Config().PrivateApiAddr, nil, remoteEvents)
|
2020-10-10 06:06:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-11 20:17:37 +00:00
|
|
|
}
|
2020-08-11 21:09:30 +00:00
|
|
|
}
|
|
|
|
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
checkpoint := config.Checkpoint
|
|
|
|
if checkpoint == nil {
|
2020-03-04 22:25:40 +00:00
|
|
|
//checkpoint = params.TrustedCheckpoints[genesisHash]
|
all: on-chain oracle checkpoint syncing (#19543)
* all: implement simple checkpoint syncing
cmd, les, node: remove callback mechanism
cmd, node: remove callback definition
les: simplify the registrar
les: expose checkpoint rpc services in the light client
les, light: don't store untrusted receipt
cmd, contracts, les: discard stale checkpoint
cmd, contracts/registrar: loose restriction of registeration
cmd, contracts: add replay-protection
all: off-chain multi-signature contract
params: deploy checkpoint contract for rinkeby
cmd/registrar: add raw signing mode for registrar
cmd/registrar, contracts/registrar, les: fixed messages
* cmd/registrar, contracts/registrar: fix lints
* accounts/abi/bind, les: address comments
* cmd, contracts, les, light, params: minor checkpoint sync cleanups
* cmd, eth, les, light: move checkpoint config to config file
* cmd, eth, les, params: address comments
* eth, les, params: address comments
* cmd: polish up the checkpoint admin CLI
* cmd, contracts, params: deploy new version contract
* cmd/checkpoint-admin: add another flag for clef mode signing
* cmd, contracts, les: rename and regen checkpoint oracle with abigen
2019-06-28 07:34:02 +00:00
|
|
|
}
|
2020-11-17 19:13:41 +00:00
|
|
|
|
|
|
|
if eth.protocolManager, err = NewProtocolManager(chainConfig, checkpoint, config.SyncMode, config.NetworkID, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb, config.Whitelist, stagedSync); err != nil {
|
2015-09-01 14:35:14 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2020-08-03 17:40:46 +00:00
|
|
|
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
|
2020-10-23 11:18:45 +00:00
|
|
|
eth.protocolManager.SetTmpDir(tmpdir)
|
2021-02-21 18:41:59 +00:00
|
|
|
eth.protocolManager.SetBatchSize(config.CacheSize, config.BatchSize)
|
2020-05-24 14:48:15 +00:00
|
|
|
|
2020-07-09 12:53:35 +00:00
|
|
|
if config.SyncMode != downloader.StagedSync {
|
|
|
|
if err = eth.StartTxPool(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-08-15 17:32:05 +00:00
|
|
|
}
|
2020-08-03 17:40:46 +00:00
|
|
|
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), eth, nil}
|
|
|
|
gpoParams := config.GPO
|
|
|
|
if gpoParams.Default == nil {
|
|
|
|
gpoParams.Default = config.Miner.GasPrice
|
2020-07-09 12:53:35 +00:00
|
|
|
}
|
2020-08-03 17:40:46 +00:00
|
|
|
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
|
2020-07-09 12:53:35 +00:00
|
|
|
|
2020-04-24 16:57:43 +00:00
|
|
|
if config.SyncMode != downloader.StagedSync {
|
2020-08-01 16:56:57 +00:00
|
|
|
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
|
2020-04-24 16:57:43 +00:00
|
|
|
_ = eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
|
|
|
|
}
|
2015-07-25 15:33:56 +00:00
|
|
|
|
2020-04-24 16:57:43 +00:00
|
|
|
if config.SyncMode != downloader.StagedSync {
|
2020-08-15 17:32:05 +00:00
|
|
|
eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), eth, nil}
|
2020-04-24 16:57:43 +00:00
|
|
|
gpoParams := config.GPO
|
|
|
|
if gpoParams.Default == nil {
|
|
|
|
gpoParams.Default = config.Miner.GasPrice
|
|
|
|
}
|
|
|
|
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
|
2015-12-16 03:26:23 +00:00
|
|
|
}
|
|
|
|
|
2020-08-03 17:40:46 +00:00
|
|
|
eth.dialCandidates, err = eth.setupDiscovery(&stack.Config().P2P)
|
2020-02-13 13:38:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-08-03 17:40:46 +00:00
|
|
|
// Start the RPC service
|
2020-08-15 17:32:05 +00:00
|
|
|
if config.SyncMode != downloader.StagedSync {
|
2020-08-18 17:22:49 +00:00
|
|
|
id, err := eth.NetVersion()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
eth.netRPCService = ethapi.NewPublicNetAPI(eth.p2pServer, id)
|
2020-08-15 17:32:05 +00:00
|
|
|
}
|
2020-02-13 13:38:30 +00:00
|
|
|
|
2020-08-03 17:40:46 +00:00
|
|
|
// Register the backend on the node
|
|
|
|
stack.RegisterAPIs(eth.APIs())
|
|
|
|
stack.RegisterProtocols(eth.Protocols())
|
|
|
|
stack.RegisterLifecycle(eth)
|
2014-12-14 18:03:24 +00:00
|
|
|
return eth, nil
|
|
|
|
}
|
|
|
|
|
2020-08-01 16:56:57 +00:00
|
|
|
func BlockchainRuntimeConfig(config *Config) (vm.Config, *core.CacheConfig) {
|
2020-07-09 12:54:10 +00:00
|
|
|
var (
|
|
|
|
vmConfig = vm.Config{
|
|
|
|
EnablePreimageRecording: config.EnablePreimageRecording,
|
|
|
|
EWASMInterpreter: config.EWASMInterpreter,
|
|
|
|
EVMInterpreter: config.EVMInterpreter,
|
2020-11-28 14:26:28 +00:00
|
|
|
NoReceipts: !config.StorageMode.Receipts,
|
2020-07-09 12:54:10 +00:00
|
|
|
}
|
|
|
|
cacheConfig = &core.CacheConfig{
|
|
|
|
Pruning: config.Pruning,
|
|
|
|
BlocksBeforePruning: config.BlocksBeforePruning,
|
|
|
|
BlocksToPrune: config.BlocksToPrune,
|
|
|
|
PruneTimeout: config.PruningTimeout,
|
|
|
|
TrieCleanLimit: config.TrieCleanCache,
|
|
|
|
TrieCleanNoPrefetch: config.NoPrefetch,
|
|
|
|
TrieDirtyLimit: config.TrieDirtyCache,
|
|
|
|
TrieTimeLimit: config.TrieTimeout,
|
|
|
|
DownloadOnly: config.DownloadOnly,
|
|
|
|
NoHistory: !config.StorageMode.History,
|
|
|
|
ArchiveSyncInterval: uint64(config.ArchiveSyncInterval),
|
|
|
|
}
|
|
|
|
)
|
2020-08-01 16:56:57 +00:00
|
|
|
return vmConfig, cacheConfig
|
2020-07-09 12:54:10 +00:00
|
|
|
}
|
|
|
|
|
2017-04-12 14:27:23 +00:00
|
|
|
func makeExtraData(extra []byte) []byte {
|
|
|
|
if len(extra) == 0 {
|
|
|
|
// create default extradata
|
|
|
|
extra, _ = rlp.EncodeToBytes([]interface{}{
|
2020-07-27 12:18:26 +00:00
|
|
|
uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionMicro),
|
2019-05-27 13:51:49 +00:00
|
|
|
"turbo-geth",
|
2017-04-12 14:27:23 +00:00
|
|
|
runtime.Version(),
|
|
|
|
runtime.GOOS,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if uint64(len(extra)) > params.MaximumExtraDataSize {
|
|
|
|
log.Warn("Miner extra data exceed limit", "extra", hexutil.Bytes(extra), "limit", params.MaximumExtraDataSize)
|
|
|
|
extra = nil
|
|
|
|
}
|
|
|
|
return extra
|
|
|
|
}
|
|
|
|
|
2017-04-04 22:16:29 +00:00
|
|
|
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
|
2021-03-05 20:34:23 +00:00
|
|
|
func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
|
|
|
|
// If proof-of-authority is requested, set it up
|
|
|
|
if chainConfig.Clique != nil {
|
|
|
|
return clique.New(chainConfig.Clique, db)
|
2015-12-16 03:26:23 +00:00
|
|
|
}
|
2021-03-05 20:34:23 +00:00
|
|
|
// Otherwise assume proof-of-work
|
|
|
|
switch config.PowMode {
|
|
|
|
case ethash.ModeFake:
|
|
|
|
log.Warn("Ethash used in fake mode")
|
|
|
|
return ethash.NewFaker()
|
|
|
|
case ethash.ModeTest:
|
|
|
|
log.Warn("Ethash used in test mode")
|
|
|
|
return ethash.NewTester(nil, noverify)
|
|
|
|
case ethash.ModeShared:
|
|
|
|
log.Warn("Ethash used in shared mode")
|
|
|
|
return ethash.NewShared()
|
|
|
|
default:
|
|
|
|
engine := ethash.New(ethash.Config{
|
|
|
|
CachesInMem: config.CachesInMem,
|
|
|
|
CachesLockMmap: config.CachesLockMmap,
|
|
|
|
DatasetDir: config.DatasetDir,
|
|
|
|
DatasetsInMem: config.DatasetsInMem,
|
|
|
|
DatasetsOnDisk: config.DatasetsOnDisk,
|
|
|
|
DatasetsLockMmap: config.DatasetsLockMmap,
|
|
|
|
}, notify, noverify)
|
|
|
|
engine.SetThreads(-1) // Disable CPU mining
|
|
|
|
return engine
|
2021-02-25 19:40:45 +00:00
|
|
|
}
|
2015-12-16 03:26:23 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 12:55:20 +00:00
|
|
|
// APIs return the collection of RPC services the ethereum package offers.
|
2015-10-15 14:07:19 +00:00
|
|
|
// NOTE, some of these services probably need to be moved to somewhere else.
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) APIs() []rpc.API {
|
2020-04-24 16:57:43 +00:00
|
|
|
if s.APIBackend == nil {
|
|
|
|
return []rpc.API{}
|
|
|
|
}
|
2018-05-09 07:59:00 +00:00
|
|
|
apis := ethapi.GetAPIs(s.APIBackend)
|
2017-04-04 22:16:29 +00:00
|
|
|
|
|
|
|
// Append any APIs exposed explicitly by the consensus engine
|
|
|
|
apis = append(apis, s.engine.APIs(s.BlockChain())...)
|
|
|
|
|
|
|
|
// Append all the local APIs and return
|
|
|
|
return append(apis, []rpc.API{
|
2020-08-19 11:46:20 +00:00
|
|
|
//{
|
|
|
|
// Namespace: "eth",
|
|
|
|
// Version: "1.0",
|
|
|
|
// Service: NewPublicEthereumAPI(s),
|
|
|
|
// Public: true,
|
|
|
|
//},
|
|
|
|
//{
|
|
|
|
// Namespace: "eth",
|
|
|
|
// Version: "1.0",
|
|
|
|
// Service: NewPublicMinerAPI(s),
|
|
|
|
// Public: true,
|
|
|
|
//},
|
2015-10-15 14:07:19 +00:00
|
|
|
{
|
|
|
|
Namespace: "eth",
|
|
|
|
Version: "1.0",
|
2016-04-28 09:00:11 +00:00
|
|
|
Service: downloader.NewPublicDownloaderAPI(s.protocolManager.downloader, s.eventMux),
|
2015-10-15 14:07:19 +00:00
|
|
|
Public: true,
|
2020-08-19 11:46:20 +00:00
|
|
|
},
|
|
|
|
//{
|
|
|
|
// Namespace: "miner",
|
|
|
|
// Version: "1.0",
|
|
|
|
// Service: NewPrivateMinerAPI(s),
|
|
|
|
// Public: false,
|
|
|
|
//},
|
|
|
|
{
|
2015-10-15 14:07:19 +00:00
|
|
|
Namespace: "eth",
|
|
|
|
Version: "1.0",
|
2018-05-09 07:59:00 +00:00
|
|
|
Service: filters.NewPublicFilterAPI(s.APIBackend, false),
|
2015-10-15 14:07:19 +00:00
|
|
|
Public: true,
|
2020-08-19 11:46:20 +00:00
|
|
|
},
|
|
|
|
//{
|
|
|
|
// Namespace: "admin",
|
|
|
|
// Version: "1.0",
|
|
|
|
// Service: NewPrivateAdminAPI(s),
|
|
|
|
//},
|
|
|
|
//{
|
|
|
|
// Namespace: "debug",
|
|
|
|
// Version: "1.0",
|
|
|
|
// Service: NewPublicDebugAPI(s),
|
|
|
|
// Public: true,
|
|
|
|
//}, {
|
|
|
|
// Namespace: "debug",
|
|
|
|
// Version: "1.0",
|
|
|
|
// Service: NewPrivateDebugAPI(s),
|
|
|
|
//},
|
|
|
|
{
|
2015-12-16 09:58:01 +00:00
|
|
|
Namespace: "net",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: s.netRPCService,
|
|
|
|
Public: true,
|
2015-10-15 14:07:19 +00:00
|
|
|
},
|
2015-12-16 03:26:23 +00:00
|
|
|
}...)
|
2015-10-15 14:07:19 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
|
2015-08-31 15:09:50 +00:00
|
|
|
s.blockchain.ResetWithGenesisBlock(gb)
|
2015-03-13 17:34:43 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) Etherbase() (eb common.Address, err error) {
|
2017-05-29 07:21:34 +00:00
|
|
|
s.lock.RLock()
|
|
|
|
etherbase := s.etherbase
|
|
|
|
s.lock.RUnlock()
|
|
|
|
|
|
|
|
if etherbase != (common.Address{}) {
|
|
|
|
return etherbase, nil
|
2017-01-24 09:49:20 +00:00
|
|
|
}
|
2017-02-07 10:47:34 +00:00
|
|
|
if wallets := s.AccountManager().Wallets(); len(wallets) > 0 {
|
|
|
|
if accounts := wallets[0].Accounts(); len(accounts) > 0 {
|
2017-12-09 22:42:23 +00:00
|
|
|
etherbase := accounts[0].Address
|
|
|
|
|
|
|
|
s.lock.Lock()
|
|
|
|
s.etherbase = etherbase
|
|
|
|
s.lock.Unlock()
|
|
|
|
|
|
|
|
log.Info("Etherbase automatically configured", "address", etherbase)
|
|
|
|
return etherbase, nil
|
2017-02-07 10:47:34 +00:00
|
|
|
}
|
2015-03-26 21:49:22 +00:00
|
|
|
}
|
2017-12-09 22:42:23 +00:00
|
|
|
return common.Address{}, fmt.Errorf("etherbase must be explicitly specified")
|
2015-03-26 21:49:22 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 17:02:15 +00:00
|
|
|
// isLocalBlock checks whether the specified block is mined
|
|
|
|
// by local miner accounts.
|
2018-09-20 12:09:30 +00:00
|
|
|
//
|
2018-09-20 17:02:15 +00:00
|
|
|
// We regard two types of accounts as local miner account: etherbase
|
|
|
|
// and accounts specified via `txpool.locals` flag.
|
|
|
|
func (s *Ethereum) isLocalBlock(block *types.Block) bool {
|
|
|
|
author, err := s.engine.Author(block.Header())
|
|
|
|
if err != nil {
|
|
|
|
log.Warn("Failed to retrieve block author", "number", block.NumberU64(), "hash", block.Hash(), "err", err)
|
|
|
|
return false
|
|
|
|
}
|
2018-09-20 12:09:30 +00:00
|
|
|
// Check whether the given address is etherbase.
|
|
|
|
s.lock.RLock()
|
|
|
|
etherbase := s.etherbase
|
|
|
|
s.lock.RUnlock()
|
2018-09-20 17:02:15 +00:00
|
|
|
if author == etherbase {
|
2018-09-20 12:09:30 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
// Check whether the given address is specified by `txpool.local`
|
|
|
|
// CLI flag.
|
|
|
|
for _, account := range s.config.TxPool.Locals {
|
2018-09-20 17:02:15 +00:00
|
|
|
if account == author {
|
2018-09-20 12:09:30 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-20 17:02:15 +00:00
|
|
|
// shouldPreserve checks whether we should preserve the given block
|
|
|
|
// during the chain reorg depending on whether the author of block
|
|
|
|
// is a local account.
|
|
|
|
func (s *Ethereum) shouldPreserve(block *types.Block) bool {
|
|
|
|
// The reason we need to disable the self-reorg preserving for clique
|
|
|
|
// is it can be probable to introduce a deadlock.
|
|
|
|
//
|
|
|
|
// e.g. If there are 7 available signers
|
|
|
|
//
|
|
|
|
// r1 A
|
|
|
|
// r2 B
|
|
|
|
// r3 C
|
|
|
|
// r4 D
|
|
|
|
// r5 A [X] F G
|
|
|
|
// r6 [X]
|
|
|
|
//
|
|
|
|
// In the round5, the inturn signer E is offline, so the worst case
|
|
|
|
// is A, F and G sign the block of round5 and reject the block of opponents
|
|
|
|
// and in the round6, the last available signer B is offline, the whole
|
|
|
|
// network is stuck.
|
2021-03-05 20:34:23 +00:00
|
|
|
if _, ok := s.engine.(*clique.Clique); ok {
|
2018-09-20 17:02:15 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return s.isLocalBlock(block)
|
|
|
|
}
|
|
|
|
|
2018-05-03 12:15:33 +00:00
|
|
|
// SetEtherbase sets the mining reward address.
|
|
|
|
func (s *Ethereum) SetEtherbase(etherbase common.Address) {
|
|
|
|
s.lock.Lock()
|
|
|
|
s.etherbase = etherbase
|
|
|
|
s.lock.Unlock()
|
2017-05-29 07:21:34 +00:00
|
|
|
|
2019-12-10 13:12:21 +00:00
|
|
|
s.miner.SetEtherbase(etherbase)
|
2015-07-07 08:32:05 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 10:02:36 +00:00
|
|
|
// StartMining starts the miner with the given number of CPU threads. If mining
|
|
|
|
// is already running, this method adjust the number of threads allowed to use
|
|
|
|
// and updates the minimum price required by the transaction pool.
|
2020-08-01 16:56:57 +00:00
|
|
|
func (s *Ethereum) StartMining(threads int) error {
|
2018-08-23 10:02:36 +00:00
|
|
|
// Update the thread count within the consensus engine
|
|
|
|
type threaded interface {
|
|
|
|
SetThreads(threads int)
|
2016-10-28 17:05:01 +00:00
|
|
|
}
|
2021-03-05 20:34:23 +00:00
|
|
|
if th, ok := s.engine.(threaded); ok {
|
2018-08-23 10:02:36 +00:00
|
|
|
log.Info("Updated mining threads", "threads", threads)
|
|
|
|
if threads == 0 {
|
|
|
|
threads = -1 // Disable the miner from within
|
2017-04-10 10:24:12 +00:00
|
|
|
}
|
2018-08-23 10:02:36 +00:00
|
|
|
th.SetThreads(threads)
|
2017-04-10 10:24:12 +00:00
|
|
|
}
|
2018-08-23 10:02:36 +00:00
|
|
|
// If the miner was not running, initialize it
|
|
|
|
if !s.IsMining() {
|
|
|
|
// Propagate the initial price point to the transaction pool
|
|
|
|
s.lock.RLock()
|
|
|
|
price := s.gasPrice
|
|
|
|
s.lock.RUnlock()
|
|
|
|
s.txPool.SetGasPrice(price)
|
|
|
|
|
2018-09-20 12:09:30 +00:00
|
|
|
// Configure the local mining address
|
2018-08-23 10:02:36 +00:00
|
|
|
eb, err := s.Etherbase()
|
|
|
|
if err != nil {
|
|
|
|
log.Error("Cannot start mining without etherbase", "err", err)
|
|
|
|
return fmt.Errorf("etherbase missing: %v", err)
|
|
|
|
}
|
2021-03-05 20:34:23 +00:00
|
|
|
if clique, ok := s.engine.(*clique.Clique); ok {
|
2018-08-23 10:02:36 +00:00
|
|
|
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
|
|
|
|
if wallet == nil || err != nil {
|
|
|
|
log.Error("Etherbase account unavailable locally", "err", err)
|
|
|
|
return fmt.Errorf("signer missing: %v", err)
|
|
|
|
}
|
accounts, eth, clique, signer: support for external signer API (#18079)
* accounts, eth, clique: implement external backend + move sighash calc to backend
* signer: implement account_Version on external API
* accounts/external: enable ipc, add copyright
* accounts, internal, signer: formatting
* node: go fmt
* flags: disallow --dev in combo with --externalsigner
* accounts: remove clique-specific signing method, replace with more generic
* accounts, consensus: formatting + fix error in tests
* signer/core: remove (test-) import cycle
* clique: remove unused import
* accounts: remove CliqueHash and avoid dependency on package crypto
* consensus/clique: unduplicate header encoding
2019-02-05 10:23:57 +00:00
|
|
|
clique.Authorize(eb, wallet.SignData)
|
2018-08-23 10:02:36 +00:00
|
|
|
}
|
|
|
|
// If mining is started, we can disable the transaction rejection mechanism
|
|
|
|
// introduced to speed sync times.
|
2017-04-10 08:43:01 +00:00
|
|
|
atomic.StoreUint32(&s.protocolManager.acceptTxs, 1)
|
2018-08-23 10:02:36 +00:00
|
|
|
|
2020-08-01 16:56:57 +00:00
|
|
|
go s.miner.Start(eb)
|
2017-04-10 08:43:01 +00:00
|
|
|
}
|
2016-10-28 17:05:01 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-23 10:02:36 +00:00
|
|
|
// StopMining terminates the miner, both at the consensus engine level as well as
|
|
|
|
// at the block creation level.
|
|
|
|
func (s *Ethereum) StopMining() {
|
|
|
|
// Update the thread count within the consensus engine
|
|
|
|
type threaded interface {
|
|
|
|
SetThreads(threads int)
|
|
|
|
}
|
2021-03-05 20:34:23 +00:00
|
|
|
if th, ok := s.engine.(threaded); ok {
|
2018-08-23 10:02:36 +00:00
|
|
|
th.SetThreads(-1)
|
|
|
|
}
|
|
|
|
// Stop the block creating itself
|
2019-12-10 13:12:21 +00:00
|
|
|
s.miner.Stop()
|
2018-08-23 10:02:36 +00:00
|
|
|
}
|
|
|
|
|
2019-12-10 13:12:21 +00:00
|
|
|
func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
|
|
|
|
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
|
2016-06-30 10:03:26 +00:00
|
|
|
|
|
|
|
func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
|
|
|
|
func (s *Ethereum) BlockChain() *core.BlockChain { return s.blockchain }
|
|
|
|
func (s *Ethereum) TxPool() *core.TxPool { return s.txPool }
|
|
|
|
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
|
2017-04-04 22:16:29 +00:00
|
|
|
func (s *Ethereum) Engine() consensus.Engine { return s.engine }
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) ChainDb() ethdb.Database { return s.chainDb }
|
2020-05-27 16:24:34 +00:00
|
|
|
func (s *Ethereum) ChainKV() ethdb.KV { return s.chainKV }
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) IsListening() bool { return true } // Always listening
|
2019-07-08 15:53:47 +00:00
|
|
|
func (s *Ethereum) EthVersion() int { return int(ProtocolVersions[0]) }
|
2020-08-18 17:22:49 +00:00
|
|
|
func (s *Ethereum) NetVersion() (uint64, error) { return s.networkID, nil }
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader }
|
2020-08-29 07:24:50 +00:00
|
|
|
func (s *Ethereum) SyncProgress() ethereum.SyncProgress {
|
|
|
|
return s.protocolManager.downloader.Progress()
|
|
|
|
}
|
2020-10-12 08:39:04 +00:00
|
|
|
func (s *Ethereum) Synced() bool { return atomic.LoadUint32(&s.protocolManager.acceptTxs) == 1 }
|
|
|
|
func (s *Ethereum) ArchiveMode() bool { return !s.config.Pruning }
|
2015-01-28 17:14:28 +00:00
|
|
|
|
2020-08-03 17:40:46 +00:00
|
|
|
// Protocols returns all the currently configured
|
2015-11-17 16:33:25 +00:00
|
|
|
// network protocols to start.
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) Protocols() []p2p.Protocol {
|
2019-07-08 15:53:47 +00:00
|
|
|
protos := make([]p2p.Protocol, len(ProtocolVersions))
|
|
|
|
for i, vsn := range ProtocolVersions {
|
|
|
|
protos[i] = s.protocolManager.makeProtocol(vsn)
|
|
|
|
protos[i].Attributes = []enr.Entry{s.currentEthEntry()}
|
2020-05-22 11:46:34 +00:00
|
|
|
protos[i].DialCandidates = s.dialCandidates
|
2019-07-08 15:53:47 +00:00
|
|
|
}
|
2019-05-27 13:51:49 +00:00
|
|
|
|
2020-05-28 17:58:08 +00:00
|
|
|
if s.config.EnableDebugProtocol {
|
|
|
|
// Debug
|
|
|
|
protos = append(protos, s.protocolManager.makeDebugProtocol())
|
|
|
|
}
|
2020-03-15 16:10:07 +00:00
|
|
|
|
2019-07-08 15:53:47 +00:00
|
|
|
return protos
|
2015-11-17 16:33:25 +00:00
|
|
|
}
|
2015-04-22 10:46:41 +00:00
|
|
|
|
2020-08-03 17:40:46 +00:00
|
|
|
// Start implements node.Lifecycle, starting all internal goroutines needed by the
|
2016-06-30 10:03:26 +00:00
|
|
|
// Ethereum protocol implementation.
|
2020-08-03 17:40:46 +00:00
|
|
|
func (s *Ethereum) Start() error {
|
|
|
|
s.startEthEntryUpdate(s.p2pServer.LocalNode())
|
2019-07-08 15:53:47 +00:00
|
|
|
|
2017-09-05 16:18:28 +00:00
|
|
|
// Figure out a max peers count based on the server limits
|
2020-08-03 17:40:46 +00:00
|
|
|
maxPeers := s.p2pServer.MaxPeers
|
2020-07-09 12:53:35 +00:00
|
|
|
withTxPool := s.config.SyncMode != downloader.StagedSync
|
2017-08-29 11:13:11 +00:00
|
|
|
// Start the networking layer and the light server if requested
|
2020-08-15 17:32:05 +00:00
|
|
|
return s.protocolManager.Start(maxPeers, withTxPool)
|
2014-12-14 18:03:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 12:53:35 +00:00
|
|
|
func (s *Ethereum) StartTxPool() error {
|
2020-07-15 05:10:17 +00:00
|
|
|
if s.txPoolStarted {
|
|
|
|
return errors.New("transaction pool is already started")
|
|
|
|
}
|
2020-07-23 20:52:41 +00:00
|
|
|
headHash := rawdb.ReadHeadHeaderHash(s.chainDb)
|
|
|
|
headNumber := rawdb.ReadHeaderNumber(s.chainDb, headHash)
|
|
|
|
head := rawdb.ReadHeader(s.chainDb, headHash, *headNumber)
|
|
|
|
if err := s.txPool.Start(head.GasLimit, *headNumber); err != nil {
|
2020-07-09 12:53:35 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-07-15 05:10:17 +00:00
|
|
|
if err := s.protocolManager.StartTxPool(); err != nil {
|
|
|
|
s.txPool.Stop()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
s.txPoolStarted = true
|
|
|
|
return nil
|
2020-07-09 12:53:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Ethereum) StopTxPool() error {
|
2020-07-15 05:10:17 +00:00
|
|
|
if !s.txPoolStarted {
|
|
|
|
return errors.New("transaction pool is already stopped")
|
|
|
|
}
|
2020-07-09 12:53:35 +00:00
|
|
|
s.protocolManager.StopTxPool()
|
|
|
|
s.txPool.Stop()
|
2020-07-15 05:10:17 +00:00
|
|
|
|
|
|
|
s.txPoolStarted = false
|
2020-07-09 12:53:35 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-11-17 16:33:25 +00:00
|
|
|
// Stop implements node.Service, terminating all internal goroutines used by the
|
|
|
|
// Ethereum protocol.
|
2016-06-30 10:03:26 +00:00
|
|
|
func (s *Ethereum) Stop() error {
|
geth 1.9.13 (#469)
* core: initial version of state snapshots
* core/state: lazy sorting, snapshot invalidation
* core/state/snapshot: extract and split cap method, cover corners
* snapshot: iteration and buffering optimizations
* core/state/snapshot: unlink snapshots from blocks, quad->linear cleanup
* 123
* core/rawdb, core/state/snapshot: runtime snapshot generation
* core/state/snapshot: fix difflayer origin-initalization after flatten
* add "to merge"
* core/state/snapshot: implement snapshot layer iteration
* core/state/snapshot: node behavioural difference on bloom content
* core: journal the snapshot inside leveldb, not a flat file
* core/state/snapshot: bloom, metrics and prefetcher fixes
* core/state/snapshot: move iterator out into its own files
* core/state/snapshot: implement iterator priority for fast direct data lookup
* core/state/snapshot: full featured account iteration
* core/state/snapshot: faster account iteration, CLI integration
* core: fix broken tests due to API changes + linter
* core/state: fix an account resurrection issue
* core/tests: test for destroy+recreate contract with storage
* squashme
* core/state/snapshot, tests: sync snap gen + snaps in consensus tests
* core/state: extend snapshotter to handle account resurrections
* core/state: fix account root hash update point
* core/state: fix resurrection state clearing and access
* core/state/snapshot: handle deleted accounts in fast iterator
* core: more blockchain tests
* core/state/snapshot: fix various iteration issues due to destruct set
* core: fix two snapshot iterator flaws, decollide snap storage prefix
* core/state/snapshot/iterator: fix two disk iterator flaws
* core/rawdb: change SnapshotStoragePrefix to avoid prefix collision with preimagePrefix
* params: begin v1.9.13 release cycle
* cmd/checkpoint-admin: add some documentation (#20697)
* go.mod: update duktape to fix sprintf warnings (#20777)
This revision of go-duktype fixes the following warning
```
duk_logging.c: In function ‘duk__logger_prototype_log_shared’:
duk_logging.c:184:64: warning: ‘Z’ directive writing 1 byte into a region of size between 0 and 9 [-Wformat-overflow=]
184 | sprintf((char *) date_buf, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
| ^
In file included from /usr/include/stdio.h:867,
from duk_logging.c:5:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 25 and 85 bytes into a destination of size 32
36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
* core/rawdb: fix freezer table test error check
Fixes: Condition is always 'false' because 'err' is always 'nil'
* core/rawdb: improve table database (#20703)
This PR fixes issues in TableDatabase.
TableDatabase is a wrapper of underlying ethdb.Database with an additional prefix.
The prefix is applied to all entries it maintains. However when we try to retrieve entries
from it we don't handle the key properly. In theory the prefix should be truncated and
only user key is returned. But we don't do it in some cases, e.g. the iterator and batch
replayer created from it. So this PR is the fix to these issues.
* eth: when triggering a sync, check the head header TD, not block
* internal/web3ext: fix clique console apis to work on missing arguments
* rpc: dont log an error if user configures --rpcapi=rpc... (#20776)
This just prevents a false negative ERROR warning when, for some unknown
reason, a user attempts to turn on the module rpc even though it's already going
to be on.
* node, cmd/clef: report actual port used for http rpc (#20789)
* internal/ethapi: don't set sender-balance to maxuint, fixes #16999 (#20783)
Prior to this change, eth_call changed the balance of the sender account in the
EVM environment to 2^256 wei to cover the gas cost of the call execution.
We've had this behavior for a long time even though it's super confusing.
This commit sets the default call gasprice to zero instead of updating the balance,
which is better because it makes eth_call semantics less surprising. Removing
the built-in balance assignment also makes balance overrides work as expected.
* metrics: disable CPU stats (gosigar) on iOS
* cmd/devp2p: tweak DNS TTLs (#20801)
* cmd/devp2p: tweak DNS TTLs
* cmd/devp2p: bump treeNodeTTL to four weeks
* cmd/devp2p: lower route53 change limit again (#20819)
* cmd/devp2p: be very correct about route53 change splitting (#20820)
Turns out the way RDATA limits work is documented after all,
I just didn't search right. The trick to make it work is to
count UPSERTs twice.
This also adds an additional check to ensure TTL changes are
applied on existing records.
* graphql, node, rpc: fix typos in comments (#20824)
* eth: improve shutdown synchronization (#20695)
* eth: improve shutdown synchronization
Most goroutines started by eth.Ethereum didn't have any shutdown sync at
all, which lead to weird error messages when quitting the client.
This change improves the clean shutdown path by stopping all internal
components in dependency order and waiting for them to actually be
stopped before shutdown is considered done. In particular, we now stop
everything related to peers before stopping 'resident' parts such as
core.BlockChain.
* eth: rewrite sync controller
* eth: remove sync start debug message
* eth: notify chainSyncer about new peers after handshake
* eth: move downloader.Cancel call into chainSyncer
* eth: make post-sync block broadcast synchronous
* eth: add comments
* core: change blockchain stop message
* eth: change closeBloomHandler channel type
* eth/filters: fix typo on unindexedLogs function's comment (#20827)
* core: bump txpool tx max size to 128KB
* snapshotter/tests: verify snapdb post-state against trie (#20812)
* core/state/snapshot: basic trie-to-hash implementation
* tests: validate snapshot after test
* core/state/snapshot: fix review concerns
* cmd, consensus: add option to disable mmap for DAG caches/datasets (#20484)
* cmd, consensus: add option to disable mmap for DAG caches/datasets
* consensus: add benchmarks for mmap with/with lock
* cmd/clef: add newaccount command (#20782)
* cmd/clef: add newaccount command
* cmd/clef: document clef_New, update API versioning
* Update cmd/clef/intapi_changelog.md
Co-Authored-By: ligi <ligi@ligi.de>
* Update signer/core/uiapi.go
Co-Authored-By: ligi <ligi@ligi.de>
Co-authored-by: ligi <ligi@ligi.de>
* eth: add debug_accountRange API (#19645)
This new API allows reading accounts and their content by address range.
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
* travis: allow cocoapods deploy to fail (#20833)
* metrics: improve TestTimerFunc (#20818)
The test failed due to what appears to be fluctuations in time.Sleep, which is
not the actual method under test. This change modifies it so we compare the
metered Max to the actual time instead of the desired time.
* README: update private network genesis spec with istanbul (#20841)
* add istanbul and muirGlacier to genesis states in README
* remove muirGlacier, relocate istanbul
* cmd/evm: Rework execution stats (#20792)
- Dump stats also for --bench flag.
- From memory stats only show number and size of allocations. This is what `test -bench` shows. I doubt others like number of GC runs are any useful, but can be added if requested.
- Now the mem stats are for single execution in case of --bench.
* cmd/devp2p, cmd/wnode, whisper: add missing calls to Timer.Stop (#20843)
* p2p/server: add UDP port mapping goroutine to wait group (#20846)
* accounts/abi faster unpacking of int256 (#20850)
* p2p/discv5: add missing Timer.Stop calls (#20853)
* miner/worker: add missing timer.Stop call (#20857)
* cmd/geth: fix bad genesis test (#20860)
* eth/filters: add missing Ticker.Stop call (#20862)
* eth/fetcher: add missing timer.Stop calls (#20861)
* event: add missing timer.Stop call in TestFeed (#20868)
* metrics: add missing calls to Ticker.Stop in tests (#20866)
* ethstats: add missing Ticker.Stop call (#20867)
* p2p/discv5, p2p/testing: add missing Timer.Stop calls in tests (#20869)
* core: add missing Timer.Stop call in TestLogReorgs (#20870)
* rpc: add missing timer.Stop calls in websocket tests (#20863)
* crypto/ecies: improve concatKDF (#20836)
This removes a bunch of weird code around the counter overflow check in
concatKDF and makes it actually work for different hash output sizes.
The overflow check worked as follows: concatKDF applies the hash function N
times, where N is roundup(kdLen, hashsize) / hashsize. N should not
overflow 32 bits because that would lead to a repetition in the KDF output.
A couple issues with the overflow check:
- It used the hash.BlockSize, which is wrong because the
block size is about the input of the hash function. Luckily, all standard
hash functions have a block size that's greater than the output size, so
concatKDF didn't crash, it just generated too much key material.
- The check used big.Int to compare against 2^32-1.
- The calculation could still overflow before reaching the check.
The new code in concatKDF doesn't check for overflow. Instead, there is a
new check on ECIESParams which ensures that params.KeyLen is < 512. This
removes any possibility of overflow.
There are a couple of miscellaneous improvements bundled in with this
change:
- The key buffer is pre-allocated instead of appending the hash output
to an initially empty slice.
- The code that uses concatKDF to derive keys is now shared between Encrypt
and Decrypt.
- There was a redundant invocation of IsOnCurve in Decrypt. This is now removed
because elliptic.Unmarshal already checks whether the input is a valid curve
point since Go 1.5.
Co-authored-by: Felix Lange <fjl@twurst.com>
* rpc: metrics for JSON-RPC method calls (#20847)
This adds a couple of metrics for tracking the timing
and frequency of method calls:
- rpc/requests gauge counts all requests
- rpc/success gauge counts requests which return err == nil
- rpc/failure gauge counts requests which return err != nil
- rpc/duration/all timer tracks timing of all requests
- rpc/duration/<method>/<success/failure> tracks per-method timing
* mobile: use bind.NewKeyedTransactor instead of duplicating (#20888)
It's better to reuse the existing code to create a keyed transactor
than to rewrite the logic again.
* internal/ethapi: add CallArgs.ToMessage method (#20854)
ToMessage is used to convert between ethapi.CallArgs and types.Message.
It reduces the length of the DoCall method by about half by abstracting out
the conversion between the CallArgs and the Message. This should improve the
code's maintainability and reusability.
* eth, les: fix flaky tests (#20897)
* les: fix flaky test
* eth: fix flaky test
* cmd/geth: enable metrics for geth import command (#20738)
* cmd/geth: enable metrics for geth import command
* cmd/geth: enable metrics-flags for import command
* core/vm: use a callcontext struct (#20761)
* core/vm: use a callcontext struct
* core/vm: fix tests
* core/vm/runtime: benchmark
* core/vm: make intpool push inlineable, unexpose callcontext
* docs/audits: add discv5 protocol audits from LA and C53 (#20898)
* .github: change gitter reference to discord link in issue template (#20896)
* couple of fixes to docs in clef (#20900)
* p2p/discover: add initial discovery v5 implementation (#20750)This adds an implementation of the current discovery v5 spec.There is full integration with cmd/devp2p and enode.Iterator in thisversion. In theory we could enable the new protocol as a replacement ofdiscovery v4 at any time. In practice, there will likely be a few morechanges to the spec and implementation before this can happen.
* build: upgrade to golangci-lint 1.24.0 (#20901)
* accounts/scwallet: remove unnecessary uses of fmt.Sprintf
* cmd/puppeth: remove unnecessary uses of fmt.Sprintf
* p2p/discv5: remove unnecessary use of fmt.Sprintf
* whisper/mailserver: remove unnecessary uses of fmt.Sprintf
* core: goimports -w tx_pool_test.go
* eth/downloader: goimports -w downloader_test.go
* build: upgrade to golangci-lint 1.24.0
* accounts/abi/bind: Refactored topics (#20851)
* accounts/abi/bind: refactored topics
* accounts/abi/bind: use store function to remove code duplication
* accounts/abi/bind: removed unused type defs
* accounts/abi/bind: error on tuples in topics
* Cosmetic changes to restart travis build
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
* node: allow websocket and HTTP on the same port (#20810)
This change makes it possible to run geth with JSON-RPC over HTTP and
WebSocket on the same TCP port. The default port for WebSocket
is still 8546.
geth --rpc --rpcport 8545 --ws --wsport 8545
This also removes a lot of deprecated API surface from package rpc.
The rpc package is now purely about serving JSON-RPC and no longer
provides a way to start an HTTP server.
* crypto: improve error messages in LoadECDSA (#20718)
This improves error messages when the file is too short or too long.
Also rewrite the test for SaveECDSA because LoadECDSA has its own
test now.
Co-authored-by: Felix Lange <fjl@twurst.com>
* changed date of rpcstack.go since new file (#20904)
* accounts/abi/bind: fixed erroneous filtering of negative ints (#20865)
* accounts/abi/bind: fixed erroneous packing of negative ints
* accounts/abi/bind: added test cases for negative ints in topics
* accounts/abi/bind: fixed genIntType for go 1.12
* accounts/abi: minor nitpick
* cmd: deprecate --testnet, use named networks instead (#20852)
* cmd/utils: make goerli the default testnet
* cmd/geth: explicitly rename testnet to ropsten
* core: explicitly rename testnet to ropsten
* params: explicitly rename testnet to ropsten
* cmd: explicitly rename testnet to ropsten
* miner: explicitly rename testnet to ropsten
* mobile: allow for returning the goerli spec
* tests: explicitly rename testnet to ropsten
* docs: update readme to reflect changes to the default testnet
* mobile: allow for configuring goerli and rinkeby nodes
* cmd/geth: revert --testnet back to ropsten and mark as legacy
* cmd/util: mark --testnet flag as deprecated
* docs: update readme to properly reflect the 3 testnets
* cmd/utils: add an explicit deprecation warning on startup
* cmd/utils: swap goerli and ropsten in usage
* cmd/geth: swap goerli and ropsten in usage
* cmd/geth: if running a known preset, log it for convenience
* docs: improve readme on usage of ropsten's testnet datadir
* cmd/utils: check if legacy `testnet` datadir exists for ropsten
* cmd/geth: check for legacy testnet path in console command
* cmd/geth: use switch statement for complex conditions in main
* cmd/geth: move known preset log statement to the very top
* cmd/utils: create new ropsten configurations in the ropsten datadir
* cmd/utils: makedatadir should check for existing testnet dir
* cmd/geth: add legacy testnet flag to the copy db command
* cmd/geth: add legacy testnet flag to the inspect command
* les, les/lespay/client: add service value statistics and API (#20837)
This PR adds service value measurement statistics to the light client. It
also adds a private API that makes these statistics accessible. A follow-up
PR will add the new server pool which uses these statistics to select
servers with good performance.
This document describes the function of the new components:
https://gist.github.com/zsfelfoldi/3c7ace895234b7b345ab4f71dab102d4
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
* README: update min go version to 1.13 (#20911)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2 (#20913)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2
* travis, appveyor: force GO111MODULE=on for every build
* core/rawdb: fix data race between Retrieve and Close (#20919)
* core/rawdb: fixed data race between retrieve and close
closes https://github.com/ethereum/go-ethereum/issues/20420
* core/rawdb: use non-atomic load while holding mutex
* all: simplify and fix database iteration with prefix/start (#20808)
* core/state/snapshot: start fixing disk iterator seek
* ethdb, rawdb, leveldb, memorydb: implement iterators with prefix and start
* les, core/state/snapshot: iterator fixes
* all: remove two iterator methods
* all: rename Iteratee.NewIteratorWith -> NewIterator
* ethdb: fix review concerns
* params: update CHTs for the 1.9.13 release
* params: release Geth v1.9.13
* added some missing files
* post-rebase fixups
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: gary rong <garyrong0905@gmail.com>
Co-authored-by: Alex Willmer <alex@moreati.org.uk>
Co-authored-by: meowsbits <45600330+meowsbits@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
Co-authored-by: Ha ĐANG <dvietha@gmail.com>
Co-authored-by: Hanjiang Yu <42531996+de1acr0ix@users.noreply.github.com>
Co-authored-by: ligi <ligi@ligi.de>
Co-authored-by: Wenbiao Zheng <delweng@gmail.com>
Co-authored-by: Adam Schmideg <adamschmideg@users.noreply.github.com>
Co-authored-by: Jeff Wentworth <jeff@curvegrid.com>
Co-authored-by: Paweł Bylica <chfast@gmail.com>
Co-authored-by: ucwong <ucwong@126.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Luke Champine <luke.champine@gmail.com>
Co-authored-by: Boqin Qin <Bobbqqin@gmail.com>
Co-authored-by: William Morriss <wjmelements@gmail.com>
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
Co-authored-by: Raw Pong Ghmoa <58883403+q9f@users.noreply.github.com>
Co-authored-by: Felföldi Zsolt <zsfelfoldi@gmail.com>
2020-04-19 17:31:47 +00:00
|
|
|
// Stop all the peer-related stuff first.
|
2015-06-12 11:36:38 +00:00
|
|
|
s.protocolManager.Stop()
|
2020-10-10 06:06:54 +00:00
|
|
|
if s.privateAPI != nil {
|
2020-12-16 13:14:31 +00:00
|
|
|
shutdownDone := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
defer close(shutdownDone)
|
|
|
|
s.privateAPI.GracefulStop()
|
|
|
|
}()
|
|
|
|
select {
|
|
|
|
case <-time.After(1 * time.Second): // shutdown deadline
|
|
|
|
s.privateAPI.Stop()
|
|
|
|
case <-shutdownDone:
|
|
|
|
}
|
2020-10-10 06:06:54 +00:00
|
|
|
}
|
geth 1.9.13 (#469)
* core: initial version of state snapshots
* core/state: lazy sorting, snapshot invalidation
* core/state/snapshot: extract and split cap method, cover corners
* snapshot: iteration and buffering optimizations
* core/state/snapshot: unlink snapshots from blocks, quad->linear cleanup
* 123
* core/rawdb, core/state/snapshot: runtime snapshot generation
* core/state/snapshot: fix difflayer origin-initalization after flatten
* add "to merge"
* core/state/snapshot: implement snapshot layer iteration
* core/state/snapshot: node behavioural difference on bloom content
* core: journal the snapshot inside leveldb, not a flat file
* core/state/snapshot: bloom, metrics and prefetcher fixes
* core/state/snapshot: move iterator out into its own files
* core/state/snapshot: implement iterator priority for fast direct data lookup
* core/state/snapshot: full featured account iteration
* core/state/snapshot: faster account iteration, CLI integration
* core: fix broken tests due to API changes + linter
* core/state: fix an account resurrection issue
* core/tests: test for destroy+recreate contract with storage
* squashme
* core/state/snapshot, tests: sync snap gen + snaps in consensus tests
* core/state: extend snapshotter to handle account resurrections
* core/state: fix account root hash update point
* core/state: fix resurrection state clearing and access
* core/state/snapshot: handle deleted accounts in fast iterator
* core: more blockchain tests
* core/state/snapshot: fix various iteration issues due to destruct set
* core: fix two snapshot iterator flaws, decollide snap storage prefix
* core/state/snapshot/iterator: fix two disk iterator flaws
* core/rawdb: change SnapshotStoragePrefix to avoid prefix collision with preimagePrefix
* params: begin v1.9.13 release cycle
* cmd/checkpoint-admin: add some documentation (#20697)
* go.mod: update duktape to fix sprintf warnings (#20777)
This revision of go-duktype fixes the following warning
```
duk_logging.c: In function ‘duk__logger_prototype_log_shared’:
duk_logging.c:184:64: warning: ‘Z’ directive writing 1 byte into a region of size between 0 and 9 [-Wformat-overflow=]
184 | sprintf((char *) date_buf, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
| ^
In file included from /usr/include/stdio.h:867,
from duk_logging.c:5:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 25 and 85 bytes into a destination of size 32
36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
* core/rawdb: fix freezer table test error check
Fixes: Condition is always 'false' because 'err' is always 'nil'
* core/rawdb: improve table database (#20703)
This PR fixes issues in TableDatabase.
TableDatabase is a wrapper of underlying ethdb.Database with an additional prefix.
The prefix is applied to all entries it maintains. However when we try to retrieve entries
from it we don't handle the key properly. In theory the prefix should be truncated and
only user key is returned. But we don't do it in some cases, e.g. the iterator and batch
replayer created from it. So this PR is the fix to these issues.
* eth: when triggering a sync, check the head header TD, not block
* internal/web3ext: fix clique console apis to work on missing arguments
* rpc: dont log an error if user configures --rpcapi=rpc... (#20776)
This just prevents a false negative ERROR warning when, for some unknown
reason, a user attempts to turn on the module rpc even though it's already going
to be on.
* node, cmd/clef: report actual port used for http rpc (#20789)
* internal/ethapi: don't set sender-balance to maxuint, fixes #16999 (#20783)
Prior to this change, eth_call changed the balance of the sender account in the
EVM environment to 2^256 wei to cover the gas cost of the call execution.
We've had this behavior for a long time even though it's super confusing.
This commit sets the default call gasprice to zero instead of updating the balance,
which is better because it makes eth_call semantics less surprising. Removing
the built-in balance assignment also makes balance overrides work as expected.
* metrics: disable CPU stats (gosigar) on iOS
* cmd/devp2p: tweak DNS TTLs (#20801)
* cmd/devp2p: tweak DNS TTLs
* cmd/devp2p: bump treeNodeTTL to four weeks
* cmd/devp2p: lower route53 change limit again (#20819)
* cmd/devp2p: be very correct about route53 change splitting (#20820)
Turns out the way RDATA limits work is documented after all,
I just didn't search right. The trick to make it work is to
count UPSERTs twice.
This also adds an additional check to ensure TTL changes are
applied on existing records.
* graphql, node, rpc: fix typos in comments (#20824)
* eth: improve shutdown synchronization (#20695)
* eth: improve shutdown synchronization
Most goroutines started by eth.Ethereum didn't have any shutdown sync at
all, which lead to weird error messages when quitting the client.
This change improves the clean shutdown path by stopping all internal
components in dependency order and waiting for them to actually be
stopped before shutdown is considered done. In particular, we now stop
everything related to peers before stopping 'resident' parts such as
core.BlockChain.
* eth: rewrite sync controller
* eth: remove sync start debug message
* eth: notify chainSyncer about new peers after handshake
* eth: move downloader.Cancel call into chainSyncer
* eth: make post-sync block broadcast synchronous
* eth: add comments
* core: change blockchain stop message
* eth: change closeBloomHandler channel type
* eth/filters: fix typo on unindexedLogs function's comment (#20827)
* core: bump txpool tx max size to 128KB
* snapshotter/tests: verify snapdb post-state against trie (#20812)
* core/state/snapshot: basic trie-to-hash implementation
* tests: validate snapshot after test
* core/state/snapshot: fix review concerns
* cmd, consensus: add option to disable mmap for DAG caches/datasets (#20484)
* cmd, consensus: add option to disable mmap for DAG caches/datasets
* consensus: add benchmarks for mmap with/with lock
* cmd/clef: add newaccount command (#20782)
* cmd/clef: add newaccount command
* cmd/clef: document clef_New, update API versioning
* Update cmd/clef/intapi_changelog.md
Co-Authored-By: ligi <ligi@ligi.de>
* Update signer/core/uiapi.go
Co-Authored-By: ligi <ligi@ligi.de>
Co-authored-by: ligi <ligi@ligi.de>
* eth: add debug_accountRange API (#19645)
This new API allows reading accounts and their content by address range.
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
* travis: allow cocoapods deploy to fail (#20833)
* metrics: improve TestTimerFunc (#20818)
The test failed due to what appears to be fluctuations in time.Sleep, which is
not the actual method under test. This change modifies it so we compare the
metered Max to the actual time instead of the desired time.
* README: update private network genesis spec with istanbul (#20841)
* add istanbul and muirGlacier to genesis states in README
* remove muirGlacier, relocate istanbul
* cmd/evm: Rework execution stats (#20792)
- Dump stats also for --bench flag.
- From memory stats only show number and size of allocations. This is what `test -bench` shows. I doubt others like number of GC runs are any useful, but can be added if requested.
- Now the mem stats are for single execution in case of --bench.
* cmd/devp2p, cmd/wnode, whisper: add missing calls to Timer.Stop (#20843)
* p2p/server: add UDP port mapping goroutine to wait group (#20846)
* accounts/abi faster unpacking of int256 (#20850)
* p2p/discv5: add missing Timer.Stop calls (#20853)
* miner/worker: add missing timer.Stop call (#20857)
* cmd/geth: fix bad genesis test (#20860)
* eth/filters: add missing Ticker.Stop call (#20862)
* eth/fetcher: add missing timer.Stop calls (#20861)
* event: add missing timer.Stop call in TestFeed (#20868)
* metrics: add missing calls to Ticker.Stop in tests (#20866)
* ethstats: add missing Ticker.Stop call (#20867)
* p2p/discv5, p2p/testing: add missing Timer.Stop calls in tests (#20869)
* core: add missing Timer.Stop call in TestLogReorgs (#20870)
* rpc: add missing timer.Stop calls in websocket tests (#20863)
* crypto/ecies: improve concatKDF (#20836)
This removes a bunch of weird code around the counter overflow check in
concatKDF and makes it actually work for different hash output sizes.
The overflow check worked as follows: concatKDF applies the hash function N
times, where N is roundup(kdLen, hashsize) / hashsize. N should not
overflow 32 bits because that would lead to a repetition in the KDF output.
A couple issues with the overflow check:
- It used the hash.BlockSize, which is wrong because the
block size is about the input of the hash function. Luckily, all standard
hash functions have a block size that's greater than the output size, so
concatKDF didn't crash, it just generated too much key material.
- The check used big.Int to compare against 2^32-1.
- The calculation could still overflow before reaching the check.
The new code in concatKDF doesn't check for overflow. Instead, there is a
new check on ECIESParams which ensures that params.KeyLen is < 512. This
removes any possibility of overflow.
There are a couple of miscellaneous improvements bundled in with this
change:
- The key buffer is pre-allocated instead of appending the hash output
to an initially empty slice.
- The code that uses concatKDF to derive keys is now shared between Encrypt
and Decrypt.
- There was a redundant invocation of IsOnCurve in Decrypt. This is now removed
because elliptic.Unmarshal already checks whether the input is a valid curve
point since Go 1.5.
Co-authored-by: Felix Lange <fjl@twurst.com>
* rpc: metrics for JSON-RPC method calls (#20847)
This adds a couple of metrics for tracking the timing
and frequency of method calls:
- rpc/requests gauge counts all requests
- rpc/success gauge counts requests which return err == nil
- rpc/failure gauge counts requests which return err != nil
- rpc/duration/all timer tracks timing of all requests
- rpc/duration/<method>/<success/failure> tracks per-method timing
* mobile: use bind.NewKeyedTransactor instead of duplicating (#20888)
It's better to reuse the existing code to create a keyed transactor
than to rewrite the logic again.
* internal/ethapi: add CallArgs.ToMessage method (#20854)
ToMessage is used to convert between ethapi.CallArgs and types.Message.
It reduces the length of the DoCall method by about half by abstracting out
the conversion between the CallArgs and the Message. This should improve the
code's maintainability and reusability.
* eth, les: fix flaky tests (#20897)
* les: fix flaky test
* eth: fix flaky test
* cmd/geth: enable metrics for geth import command (#20738)
* cmd/geth: enable metrics for geth import command
* cmd/geth: enable metrics-flags for import command
* core/vm: use a callcontext struct (#20761)
* core/vm: use a callcontext struct
* core/vm: fix tests
* core/vm/runtime: benchmark
* core/vm: make intpool push inlineable, unexpose callcontext
* docs/audits: add discv5 protocol audits from LA and C53 (#20898)
* .github: change gitter reference to discord link in issue template (#20896)
* couple of fixes to docs in clef (#20900)
* p2p/discover: add initial discovery v5 implementation (#20750)This adds an implementation of the current discovery v5 spec.There is full integration with cmd/devp2p and enode.Iterator in thisversion. In theory we could enable the new protocol as a replacement ofdiscovery v4 at any time. In practice, there will likely be a few morechanges to the spec and implementation before this can happen.
* build: upgrade to golangci-lint 1.24.0 (#20901)
* accounts/scwallet: remove unnecessary uses of fmt.Sprintf
* cmd/puppeth: remove unnecessary uses of fmt.Sprintf
* p2p/discv5: remove unnecessary use of fmt.Sprintf
* whisper/mailserver: remove unnecessary uses of fmt.Sprintf
* core: goimports -w tx_pool_test.go
* eth/downloader: goimports -w downloader_test.go
* build: upgrade to golangci-lint 1.24.0
* accounts/abi/bind: Refactored topics (#20851)
* accounts/abi/bind: refactored topics
* accounts/abi/bind: use store function to remove code duplication
* accounts/abi/bind: removed unused type defs
* accounts/abi/bind: error on tuples in topics
* Cosmetic changes to restart travis build
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
* node: allow websocket and HTTP on the same port (#20810)
This change makes it possible to run geth with JSON-RPC over HTTP and
WebSocket on the same TCP port. The default port for WebSocket
is still 8546.
geth --rpc --rpcport 8545 --ws --wsport 8545
This also removes a lot of deprecated API surface from package rpc.
The rpc package is now purely about serving JSON-RPC and no longer
provides a way to start an HTTP server.
* crypto: improve error messages in LoadECDSA (#20718)
This improves error messages when the file is too short or too long.
Also rewrite the test for SaveECDSA because LoadECDSA has its own
test now.
Co-authored-by: Felix Lange <fjl@twurst.com>
* changed date of rpcstack.go since new file (#20904)
* accounts/abi/bind: fixed erroneous filtering of negative ints (#20865)
* accounts/abi/bind: fixed erroneous packing of negative ints
* accounts/abi/bind: added test cases for negative ints in topics
* accounts/abi/bind: fixed genIntType for go 1.12
* accounts/abi: minor nitpick
* cmd: deprecate --testnet, use named networks instead (#20852)
* cmd/utils: make goerli the default testnet
* cmd/geth: explicitly rename testnet to ropsten
* core: explicitly rename testnet to ropsten
* params: explicitly rename testnet to ropsten
* cmd: explicitly rename testnet to ropsten
* miner: explicitly rename testnet to ropsten
* mobile: allow for returning the goerli spec
* tests: explicitly rename testnet to ropsten
* docs: update readme to reflect changes to the default testnet
* mobile: allow for configuring goerli and rinkeby nodes
* cmd/geth: revert --testnet back to ropsten and mark as legacy
* cmd/util: mark --testnet flag as deprecated
* docs: update readme to properly reflect the 3 testnets
* cmd/utils: add an explicit deprecation warning on startup
* cmd/utils: swap goerli and ropsten in usage
* cmd/geth: swap goerli and ropsten in usage
* cmd/geth: if running a known preset, log it for convenience
* docs: improve readme on usage of ropsten's testnet datadir
* cmd/utils: check if legacy `testnet` datadir exists for ropsten
* cmd/geth: check for legacy testnet path in console command
* cmd/geth: use switch statement for complex conditions in main
* cmd/geth: move known preset log statement to the very top
* cmd/utils: create new ropsten configurations in the ropsten datadir
* cmd/utils: makedatadir should check for existing testnet dir
* cmd/geth: add legacy testnet flag to the copy db command
* cmd/geth: add legacy testnet flag to the inspect command
* les, les/lespay/client: add service value statistics and API (#20837)
This PR adds service value measurement statistics to the light client. It
also adds a private API that makes these statistics accessible. A follow-up
PR will add the new server pool which uses these statistics to select
servers with good performance.
This document describes the function of the new components:
https://gist.github.com/zsfelfoldi/3c7ace895234b7b345ab4f71dab102d4
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
* README: update min go version to 1.13 (#20911)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2 (#20913)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2
* travis, appveyor: force GO111MODULE=on for every build
* core/rawdb: fix data race between Retrieve and Close (#20919)
* core/rawdb: fixed data race between retrieve and close
closes https://github.com/ethereum/go-ethereum/issues/20420
* core/rawdb: use non-atomic load while holding mutex
* all: simplify and fix database iteration with prefix/start (#20808)
* core/state/snapshot: start fixing disk iterator seek
* ethdb, rawdb, leveldb, memorydb: implement iterators with prefix and start
* les, core/state/snapshot: iterator fixes
* all: remove two iterator methods
* all: rename Iteratee.NewIteratorWith -> NewIterator
* ethdb: fix review concerns
* params: update CHTs for the 1.9.13 release
* params: release Geth v1.9.13
* added some missing files
* post-rebase fixups
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: gary rong <garyrong0905@gmail.com>
Co-authored-by: Alex Willmer <alex@moreati.org.uk>
Co-authored-by: meowsbits <45600330+meowsbits@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
Co-authored-by: Ha ĐANG <dvietha@gmail.com>
Co-authored-by: Hanjiang Yu <42531996+de1acr0ix@users.noreply.github.com>
Co-authored-by: ligi <ligi@ligi.de>
Co-authored-by: Wenbiao Zheng <delweng@gmail.com>
Co-authored-by: Adam Schmideg <adamschmideg@users.noreply.github.com>
Co-authored-by: Jeff Wentworth <jeff@curvegrid.com>
Co-authored-by: Paweł Bylica <chfast@gmail.com>
Co-authored-by: ucwong <ucwong@126.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Luke Champine <luke.champine@gmail.com>
Co-authored-by: Boqin Qin <Bobbqqin@gmail.com>
Co-authored-by: William Morriss <wjmelements@gmail.com>
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
Co-authored-by: Raw Pong Ghmoa <58883403+q9f@users.noreply.github.com>
Co-authored-by: Felföldi Zsolt <zsfelfoldi@gmail.com>
2020-04-19 17:31:47 +00:00
|
|
|
|
|
|
|
// Then stop everything else.
|
2020-07-09 12:53:35 +00:00
|
|
|
if err := s.StopTxPool(); err != nil {
|
|
|
|
log.Warn("error while stopping transaction pool", "err", err)
|
|
|
|
}
|
2019-12-10 13:12:21 +00:00
|
|
|
s.miner.Stop()
|
geth 1.9.13 (#469)
* core: initial version of state snapshots
* core/state: lazy sorting, snapshot invalidation
* core/state/snapshot: extract and split cap method, cover corners
* snapshot: iteration and buffering optimizations
* core/state/snapshot: unlink snapshots from blocks, quad->linear cleanup
* 123
* core/rawdb, core/state/snapshot: runtime snapshot generation
* core/state/snapshot: fix difflayer origin-initalization after flatten
* add "to merge"
* core/state/snapshot: implement snapshot layer iteration
* core/state/snapshot: node behavioural difference on bloom content
* core: journal the snapshot inside leveldb, not a flat file
* core/state/snapshot: bloom, metrics and prefetcher fixes
* core/state/snapshot: move iterator out into its own files
* core/state/snapshot: implement iterator priority for fast direct data lookup
* core/state/snapshot: full featured account iteration
* core/state/snapshot: faster account iteration, CLI integration
* core: fix broken tests due to API changes + linter
* core/state: fix an account resurrection issue
* core/tests: test for destroy+recreate contract with storage
* squashme
* core/state/snapshot, tests: sync snap gen + snaps in consensus tests
* core/state: extend snapshotter to handle account resurrections
* core/state: fix account root hash update point
* core/state: fix resurrection state clearing and access
* core/state/snapshot: handle deleted accounts in fast iterator
* core: more blockchain tests
* core/state/snapshot: fix various iteration issues due to destruct set
* core: fix two snapshot iterator flaws, decollide snap storage prefix
* core/state/snapshot/iterator: fix two disk iterator flaws
* core/rawdb: change SnapshotStoragePrefix to avoid prefix collision with preimagePrefix
* params: begin v1.9.13 release cycle
* cmd/checkpoint-admin: add some documentation (#20697)
* go.mod: update duktape to fix sprintf warnings (#20777)
This revision of go-duktype fixes the following warning
```
duk_logging.c: In function ‘duk__logger_prototype_log_shared’:
duk_logging.c:184:64: warning: ‘Z’ directive writing 1 byte into a region of size between 0 and 9 [-Wformat-overflow=]
184 | sprintf((char *) date_buf, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
| ^
In file included from /usr/include/stdio.h:867,
from duk_logging.c:5:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 25 and 85 bytes into a destination of size 32
36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
* core/rawdb: fix freezer table test error check
Fixes: Condition is always 'false' because 'err' is always 'nil'
* core/rawdb: improve table database (#20703)
This PR fixes issues in TableDatabase.
TableDatabase is a wrapper of underlying ethdb.Database with an additional prefix.
The prefix is applied to all entries it maintains. However when we try to retrieve entries
from it we don't handle the key properly. In theory the prefix should be truncated and
only user key is returned. But we don't do it in some cases, e.g. the iterator and batch
replayer created from it. So this PR is the fix to these issues.
* eth: when triggering a sync, check the head header TD, not block
* internal/web3ext: fix clique console apis to work on missing arguments
* rpc: dont log an error if user configures --rpcapi=rpc... (#20776)
This just prevents a false negative ERROR warning when, for some unknown
reason, a user attempts to turn on the module rpc even though it's already going
to be on.
* node, cmd/clef: report actual port used for http rpc (#20789)
* internal/ethapi: don't set sender-balance to maxuint, fixes #16999 (#20783)
Prior to this change, eth_call changed the balance of the sender account in the
EVM environment to 2^256 wei to cover the gas cost of the call execution.
We've had this behavior for a long time even though it's super confusing.
This commit sets the default call gasprice to zero instead of updating the balance,
which is better because it makes eth_call semantics less surprising. Removing
the built-in balance assignment also makes balance overrides work as expected.
* metrics: disable CPU stats (gosigar) on iOS
* cmd/devp2p: tweak DNS TTLs (#20801)
* cmd/devp2p: tweak DNS TTLs
* cmd/devp2p: bump treeNodeTTL to four weeks
* cmd/devp2p: lower route53 change limit again (#20819)
* cmd/devp2p: be very correct about route53 change splitting (#20820)
Turns out the way RDATA limits work is documented after all,
I just didn't search right. The trick to make it work is to
count UPSERTs twice.
This also adds an additional check to ensure TTL changes are
applied on existing records.
* graphql, node, rpc: fix typos in comments (#20824)
* eth: improve shutdown synchronization (#20695)
* eth: improve shutdown synchronization
Most goroutines started by eth.Ethereum didn't have any shutdown sync at
all, which lead to weird error messages when quitting the client.
This change improves the clean shutdown path by stopping all internal
components in dependency order and waiting for them to actually be
stopped before shutdown is considered done. In particular, we now stop
everything related to peers before stopping 'resident' parts such as
core.BlockChain.
* eth: rewrite sync controller
* eth: remove sync start debug message
* eth: notify chainSyncer about new peers after handshake
* eth: move downloader.Cancel call into chainSyncer
* eth: make post-sync block broadcast synchronous
* eth: add comments
* core: change blockchain stop message
* eth: change closeBloomHandler channel type
* eth/filters: fix typo on unindexedLogs function's comment (#20827)
* core: bump txpool tx max size to 128KB
* snapshotter/tests: verify snapdb post-state against trie (#20812)
* core/state/snapshot: basic trie-to-hash implementation
* tests: validate snapshot after test
* core/state/snapshot: fix review concerns
* cmd, consensus: add option to disable mmap for DAG caches/datasets (#20484)
* cmd, consensus: add option to disable mmap for DAG caches/datasets
* consensus: add benchmarks for mmap with/with lock
* cmd/clef: add newaccount command (#20782)
* cmd/clef: add newaccount command
* cmd/clef: document clef_New, update API versioning
* Update cmd/clef/intapi_changelog.md
Co-Authored-By: ligi <ligi@ligi.de>
* Update signer/core/uiapi.go
Co-Authored-By: ligi <ligi@ligi.de>
Co-authored-by: ligi <ligi@ligi.de>
* eth: add debug_accountRange API (#19645)
This new API allows reading accounts and their content by address range.
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
* travis: allow cocoapods deploy to fail (#20833)
* metrics: improve TestTimerFunc (#20818)
The test failed due to what appears to be fluctuations in time.Sleep, which is
not the actual method under test. This change modifies it so we compare the
metered Max to the actual time instead of the desired time.
* README: update private network genesis spec with istanbul (#20841)
* add istanbul and muirGlacier to genesis states in README
* remove muirGlacier, relocate istanbul
* cmd/evm: Rework execution stats (#20792)
- Dump stats also for --bench flag.
- From memory stats only show number and size of allocations. This is what `test -bench` shows. I doubt others like number of GC runs are any useful, but can be added if requested.
- Now the mem stats are for single execution in case of --bench.
* cmd/devp2p, cmd/wnode, whisper: add missing calls to Timer.Stop (#20843)
* p2p/server: add UDP port mapping goroutine to wait group (#20846)
* accounts/abi faster unpacking of int256 (#20850)
* p2p/discv5: add missing Timer.Stop calls (#20853)
* miner/worker: add missing timer.Stop call (#20857)
* cmd/geth: fix bad genesis test (#20860)
* eth/filters: add missing Ticker.Stop call (#20862)
* eth/fetcher: add missing timer.Stop calls (#20861)
* event: add missing timer.Stop call in TestFeed (#20868)
* metrics: add missing calls to Ticker.Stop in tests (#20866)
* ethstats: add missing Ticker.Stop call (#20867)
* p2p/discv5, p2p/testing: add missing Timer.Stop calls in tests (#20869)
* core: add missing Timer.Stop call in TestLogReorgs (#20870)
* rpc: add missing timer.Stop calls in websocket tests (#20863)
* crypto/ecies: improve concatKDF (#20836)
This removes a bunch of weird code around the counter overflow check in
concatKDF and makes it actually work for different hash output sizes.
The overflow check worked as follows: concatKDF applies the hash function N
times, where N is roundup(kdLen, hashsize) / hashsize. N should not
overflow 32 bits because that would lead to a repetition in the KDF output.
A couple issues with the overflow check:
- It used the hash.BlockSize, which is wrong because the
block size is about the input of the hash function. Luckily, all standard
hash functions have a block size that's greater than the output size, so
concatKDF didn't crash, it just generated too much key material.
- The check used big.Int to compare against 2^32-1.
- The calculation could still overflow before reaching the check.
The new code in concatKDF doesn't check for overflow. Instead, there is a
new check on ECIESParams which ensures that params.KeyLen is < 512. This
removes any possibility of overflow.
There are a couple of miscellaneous improvements bundled in with this
change:
- The key buffer is pre-allocated instead of appending the hash output
to an initially empty slice.
- The code that uses concatKDF to derive keys is now shared between Encrypt
and Decrypt.
- There was a redundant invocation of IsOnCurve in Decrypt. This is now removed
because elliptic.Unmarshal already checks whether the input is a valid curve
point since Go 1.5.
Co-authored-by: Felix Lange <fjl@twurst.com>
* rpc: metrics for JSON-RPC method calls (#20847)
This adds a couple of metrics for tracking the timing
and frequency of method calls:
- rpc/requests gauge counts all requests
- rpc/success gauge counts requests which return err == nil
- rpc/failure gauge counts requests which return err != nil
- rpc/duration/all timer tracks timing of all requests
- rpc/duration/<method>/<success/failure> tracks per-method timing
* mobile: use bind.NewKeyedTransactor instead of duplicating (#20888)
It's better to reuse the existing code to create a keyed transactor
than to rewrite the logic again.
* internal/ethapi: add CallArgs.ToMessage method (#20854)
ToMessage is used to convert between ethapi.CallArgs and types.Message.
It reduces the length of the DoCall method by about half by abstracting out
the conversion between the CallArgs and the Message. This should improve the
code's maintainability and reusability.
* eth, les: fix flaky tests (#20897)
* les: fix flaky test
* eth: fix flaky test
* cmd/geth: enable metrics for geth import command (#20738)
* cmd/geth: enable metrics for geth import command
* cmd/geth: enable metrics-flags for import command
* core/vm: use a callcontext struct (#20761)
* core/vm: use a callcontext struct
* core/vm: fix tests
* core/vm/runtime: benchmark
* core/vm: make intpool push inlineable, unexpose callcontext
* docs/audits: add discv5 protocol audits from LA and C53 (#20898)
* .github: change gitter reference to discord link in issue template (#20896)
* couple of fixes to docs in clef (#20900)
* p2p/discover: add initial discovery v5 implementation (#20750)This adds an implementation of the current discovery v5 spec.There is full integration with cmd/devp2p and enode.Iterator in thisversion. In theory we could enable the new protocol as a replacement ofdiscovery v4 at any time. In practice, there will likely be a few morechanges to the spec and implementation before this can happen.
* build: upgrade to golangci-lint 1.24.0 (#20901)
* accounts/scwallet: remove unnecessary uses of fmt.Sprintf
* cmd/puppeth: remove unnecessary uses of fmt.Sprintf
* p2p/discv5: remove unnecessary use of fmt.Sprintf
* whisper/mailserver: remove unnecessary uses of fmt.Sprintf
* core: goimports -w tx_pool_test.go
* eth/downloader: goimports -w downloader_test.go
* build: upgrade to golangci-lint 1.24.0
* accounts/abi/bind: Refactored topics (#20851)
* accounts/abi/bind: refactored topics
* accounts/abi/bind: use store function to remove code duplication
* accounts/abi/bind: removed unused type defs
* accounts/abi/bind: error on tuples in topics
* Cosmetic changes to restart travis build
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
* node: allow websocket and HTTP on the same port (#20810)
This change makes it possible to run geth with JSON-RPC over HTTP and
WebSocket on the same TCP port. The default port for WebSocket
is still 8546.
geth --rpc --rpcport 8545 --ws --wsport 8545
This also removes a lot of deprecated API surface from package rpc.
The rpc package is now purely about serving JSON-RPC and no longer
provides a way to start an HTTP server.
* crypto: improve error messages in LoadECDSA (#20718)
This improves error messages when the file is too short or too long.
Also rewrite the test for SaveECDSA because LoadECDSA has its own
test now.
Co-authored-by: Felix Lange <fjl@twurst.com>
* changed date of rpcstack.go since new file (#20904)
* accounts/abi/bind: fixed erroneous filtering of negative ints (#20865)
* accounts/abi/bind: fixed erroneous packing of negative ints
* accounts/abi/bind: added test cases for negative ints in topics
* accounts/abi/bind: fixed genIntType for go 1.12
* accounts/abi: minor nitpick
* cmd: deprecate --testnet, use named networks instead (#20852)
* cmd/utils: make goerli the default testnet
* cmd/geth: explicitly rename testnet to ropsten
* core: explicitly rename testnet to ropsten
* params: explicitly rename testnet to ropsten
* cmd: explicitly rename testnet to ropsten
* miner: explicitly rename testnet to ropsten
* mobile: allow for returning the goerli spec
* tests: explicitly rename testnet to ropsten
* docs: update readme to reflect changes to the default testnet
* mobile: allow for configuring goerli and rinkeby nodes
* cmd/geth: revert --testnet back to ropsten and mark as legacy
* cmd/util: mark --testnet flag as deprecated
* docs: update readme to properly reflect the 3 testnets
* cmd/utils: add an explicit deprecation warning on startup
* cmd/utils: swap goerli and ropsten in usage
* cmd/geth: swap goerli and ropsten in usage
* cmd/geth: if running a known preset, log it for convenience
* docs: improve readme on usage of ropsten's testnet datadir
* cmd/utils: check if legacy `testnet` datadir exists for ropsten
* cmd/geth: check for legacy testnet path in console command
* cmd/geth: use switch statement for complex conditions in main
* cmd/geth: move known preset log statement to the very top
* cmd/utils: create new ropsten configurations in the ropsten datadir
* cmd/utils: makedatadir should check for existing testnet dir
* cmd/geth: add legacy testnet flag to the copy db command
* cmd/geth: add legacy testnet flag to the inspect command
* les, les/lespay/client: add service value statistics and API (#20837)
This PR adds service value measurement statistics to the light client. It
also adds a private API that makes these statistics accessible. A follow-up
PR will add the new server pool which uses these statistics to select
servers with good performance.
This document describes the function of the new components:
https://gist.github.com/zsfelfoldi/3c7ace895234b7b345ab4f71dab102d4
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
* README: update min go version to 1.13 (#20911)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2 (#20913)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2
* travis, appveyor: force GO111MODULE=on for every build
* core/rawdb: fix data race between Retrieve and Close (#20919)
* core/rawdb: fixed data race between retrieve and close
closes https://github.com/ethereum/go-ethereum/issues/20420
* core/rawdb: use non-atomic load while holding mutex
* all: simplify and fix database iteration with prefix/start (#20808)
* core/state/snapshot: start fixing disk iterator seek
* ethdb, rawdb, leveldb, memorydb: implement iterators with prefix and start
* les, core/state/snapshot: iterator fixes
* all: remove two iterator methods
* all: rename Iteratee.NewIteratorWith -> NewIterator
* ethdb: fix review concerns
* params: update CHTs for the 1.9.13 release
* params: release Geth v1.9.13
* added some missing files
* post-rebase fixups
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: gary rong <garyrong0905@gmail.com>
Co-authored-by: Alex Willmer <alex@moreati.org.uk>
Co-authored-by: meowsbits <45600330+meowsbits@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
Co-authored-by: Ha ĐANG <dvietha@gmail.com>
Co-authored-by: Hanjiang Yu <42531996+de1acr0ix@users.noreply.github.com>
Co-authored-by: ligi <ligi@ligi.de>
Co-authored-by: Wenbiao Zheng <delweng@gmail.com>
Co-authored-by: Adam Schmideg <adamschmideg@users.noreply.github.com>
Co-authored-by: Jeff Wentworth <jeff@curvegrid.com>
Co-authored-by: Paweł Bylica <chfast@gmail.com>
Co-authored-by: ucwong <ucwong@126.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Luke Champine <luke.champine@gmail.com>
Co-authored-by: Boqin Qin <Bobbqqin@gmail.com>
Co-authored-by: William Morriss <wjmelements@gmail.com>
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
Co-authored-by: Raw Pong Ghmoa <58883403+q9f@users.noreply.github.com>
Co-authored-by: Felföldi Zsolt <zsfelfoldi@gmail.com>
2020-04-19 17:31:47 +00:00
|
|
|
s.blockchain.Stop()
|
|
|
|
s.engine.Close()
|
|
|
|
s.eventMux.Stop()
|
2020-07-23 20:52:41 +00:00
|
|
|
if s.txPool != nil {
|
|
|
|
s.txPool.Stop()
|
|
|
|
}
|
2015-11-17 16:33:25 +00:00
|
|
|
return nil
|
2014-12-14 18:03:24 +00:00
|
|
|
}
|