Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ethereum/go-ethereum
Browse files Browse the repository at this point in the history
* 'master' of github.com:ethereum/go-ethereum:
  all: make unit tests work with Go 1.13 (ethereum#20053)
  tests: expose internal RunNoVerify method (ethereum#20051)
  eth: remove unused field (ethereum#20049)
  core/state: optimize some internals during encoding
  core, metrics, p2p: switch some invalid counters to gauges
  common, graphql: fix hash/address decoding + UI content type
  README: accounts in alloc field should exist (ethereum#20005)
  • Loading branch information
chadsr committed Sep 11, 2019
2 parents 67bfc93 + 39b0b1a commit d1923c1
Show file tree
Hide file tree
Showing 24 changed files with 296 additions and 173 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.PHONY: geth-darwin geth-darwin-386 geth-darwin-amd64
.PHONY: geth-windows geth-windows-386 geth-windows-amd64

GOBIN = $(shell pwd)/build/bin
GOBIN = ./build/bin
GO ?= latest

geth:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ aware of and agree upon. This consists of a small JSON file (e.g. call it `genes

The above fields should be fine for most purposes, although we'd recommend changing
the `nonce` to some random value so you prevent unknown remote nodes from being able
to connect to you. If you'd like to pre-fund some accounts for easier testing, you can
populate the `alloc` field with account configs:
to connect to you. If you'd like to pre-fund some accounts for easier testing, create
the accounts and populate the `alloc` field with their addresses.

```json
"alloc": {
Expand Down
2 changes: 0 additions & 2 deletions build/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ func doInstall(cmdline []string) {
if flag.NArg() > 0 {
packages = flag.Args()
}
packages = build.ExpandPackagesNoVendor(packages)

if *arch == "" || *arch == runtime.GOARCH {
goinstall := goTool("install", buildFlags(env)...)
Expand Down Expand Up @@ -311,7 +310,6 @@ func doTest(cmdline []string) {
if len(flag.CommandLine.Args()) > 0 {
packages = flag.CommandLine.Args()
}
packages = build.ExpandPackagesNoVendor(packages)

// Run the actual tests.
// Test a single package at a time. CI builders are slow
Expand Down
12 changes: 7 additions & 5 deletions cmd/geth/consolecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestIPCAttachWelcome(t *testing.T) {
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--shh", "--ipcpath", ipc)

time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
waitForEndpoint(t, ipc, 3*time.Second)
testAttachWelcome(t, geth, "ipc:"+ipc, ipcAPIs)

geth.Interrupt()
Expand All @@ -101,8 +101,9 @@ func TestHTTPAttachWelcome(t *testing.T) {
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--rpc", "--rpcport", port)

time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "http://localhost:"+port, httpAPIs)
endpoint := "http://127.0.0.1:" + port
waitForEndpoint(t, endpoint, 3*time.Second)
testAttachWelcome(t, geth, endpoint, httpAPIs)

geth.Interrupt()
geth.ExpectExit()
Expand All @@ -116,8 +117,9 @@ func TestWSAttachWelcome(t *testing.T) {
"--port", "0", "--maxpeers", "0", "--nodiscover", "--nat", "none",
"--etherbase", coinbase, "--ws", "--wsport", port)

time.Sleep(2 * time.Second) // Simple way to wait for the RPC endpoint to open
testAttachWelcome(t, geth, "ws://localhost:"+port, httpAPIs)
endpoint := "ws://127.0.0.1:" + port
waitForEndpoint(t, endpoint, 3*time.Second)
testAttachWelcome(t, geth, endpoint, httpAPIs)

geth.Interrupt()
geth.ExpectExit()
Expand Down
28 changes: 28 additions & 0 deletions cmd/geth/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
package main

import (
"context"
"fmt"
"io/ioutil"
"os"
"testing"
"time"

"github.com/docker/docker/pkg/reexec"
"github.com/ethereum/go-ethereum/internal/cmdtest"
"github.com/ethereum/go-ethereum/rpc"
)

func tmpdir(t *testing.T) string {
Expand Down Expand Up @@ -96,3 +99,28 @@ func runGeth(t *testing.T, args ...string) *testgeth {

return tt
}

// waitForEndpoint attempts to connect to an RPC endpoint until it succeeds.
func waitForEndpoint(t *testing.T, endpoint string, timeout time.Duration) {
probe := func() bool {
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()
c, err := rpc.DialContext(ctx, endpoint)
if c != nil {
_, err = c.SupportedModules()
c.Close()
}
return err == nil
}

start := time.Now()
for {
if probe() {
return
}
if time.Since(start) > timeout {
t.Fatal("endpoint", endpoint, "did not open within", timeout)
}
time.Sleep(200 * time.Millisecond)
}
}
11 changes: 11 additions & 0 deletions common/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,14 @@ func LeftPadBytes(slice []byte, l int) []byte {

return padded
}

// TrimLeftZeroes returns a subslice of s without leading zeroes
func TrimLeftZeroes(s []byte) []byte {
idx := 0
for ; idx < len(s); idx++ {
if s[idx] != 0 {
break
}
}
return s[idx:]
}
4 changes: 2 additions & 2 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (h *Hash) UnmarshalGraphQL(input interface{}) error {
var err error
switch input := input.(type) {
case string:
*h = HexToHash(input)
err = h.UnmarshalText([]byte(input))
default:
err = fmt.Errorf("Unexpected type for Bytes32: %v", input)
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func (a *Address) UnmarshalGraphQL(input interface{}) error {
var err error
switch input := input.(type) {
case string:
*a = HexToAddress(input)
err = a.UnmarshalText([]byte(input))
default:
err = fmt.Errorf("Unexpected type for Address: %v", input)
}
Expand Down
8 changes: 4 additions & 4 deletions core/rawdb/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ type freezer struct {
func newFreezer(datadir string, namespace string) (*freezer, error) {
// Create the initial freezer object
var (
readMeter = metrics.NewRegisteredMeter(namespace+"ancient/read", nil)
writeMeter = metrics.NewRegisteredMeter(namespace+"ancient/write", nil)
sizeCounter = metrics.NewRegisteredCounter(namespace+"ancient/size", nil)
readMeter = metrics.NewRegisteredMeter(namespace+"ancient/read", nil)
writeMeter = metrics.NewRegisteredMeter(namespace+"ancient/write", nil)
sizeGauge = metrics.NewRegisteredGauge(namespace+"ancient/size", nil)
)
// Ensure the datadir is not a symbolic link if it exists.
if info, err := os.Lstat(datadir); !os.IsNotExist(err) {
Expand All @@ -103,7 +103,7 @@ func newFreezer(datadir string, namespace string) (*freezer, error) {
instanceLock: lock,
}
for name, disableSnappy := range freezerNoSnappy {
table, err := newTable(datadir, name, readMeter, writeMeter, sizeCounter, disableSnappy)
table, err := newTable(datadir, name, readMeter, writeMeter, sizeGauge, disableSnappy)
if err != nil {
for _, table := range freezer.tables {
table.Close()
Expand Down
22 changes: 11 additions & 11 deletions core/rawdb/freezer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ type freezerTable struct {
// to count how many historic items have gone missing.
itemOffset uint32 // Offset (number of discarded items)

headBytes uint32 // Number of bytes written to the head file
readMeter metrics.Meter // Meter for measuring the effective amount of data read
writeMeter metrics.Meter // Meter for measuring the effective amount of data written
sizeCounter metrics.Counter // Counter for tracking the combined size of all freezer tables
headBytes uint32 // Number of bytes written to the head file
readMeter metrics.Meter // Meter for measuring the effective amount of data read
writeMeter metrics.Meter // Meter for measuring the effective amount of data written
sizeGauge metrics.Gauge // Gauge for tracking the combined size of all freezer tables

logger log.Logger // Logger with database path and table name ambedded
lock sync.RWMutex // Mutex protecting the data file descriptors
}

// newTable opens a freezer table with default settings - 2G files
func newTable(path string, name string, readMeter metrics.Meter, writeMeter metrics.Meter, sizeCounter metrics.Counter, disableSnappy bool) (*freezerTable, error) {
return newCustomTable(path, name, readMeter, writeMeter, sizeCounter, 2*1000*1000*1000, disableSnappy)
func newTable(path string, name string, readMeter metrics.Meter, writeMeter metrics.Meter, sizeGauge metrics.Gauge, disableSnappy bool) (*freezerTable, error) {
return newCustomTable(path, name, readMeter, writeMeter, sizeGauge, 2*1000*1000*1000, disableSnappy)
}

// openFreezerFileForAppend opens a freezer table file and seeks to the end
Expand Down Expand Up @@ -149,7 +149,7 @@ func truncateFreezerFile(file *os.File, size int64) error {
// newCustomTable opens a freezer table, creating the data and index files if they are
// non existent. Both files are truncated to the shortest common length to ensure
// they don't go out of sync.
func newCustomTable(path string, name string, readMeter metrics.Meter, writeMeter metrics.Meter, sizeCounter metrics.Counter, maxFilesize uint32, noCompression bool) (*freezerTable, error) {
func newCustomTable(path string, name string, readMeter metrics.Meter, writeMeter metrics.Meter, sizeGauge metrics.Gauge, maxFilesize uint32, noCompression bool) (*freezerTable, error) {
// Ensure the containing directory exists and open the indexEntry file
if err := os.MkdirAll(path, 0755); err != nil {
return nil, err
Expand All @@ -172,7 +172,7 @@ func newCustomTable(path string, name string, readMeter metrics.Meter, writeMete
files: make(map[uint32]*os.File),
readMeter: readMeter,
writeMeter: writeMeter,
sizeCounter: sizeCounter,
sizeGauge: sizeGauge,
name: name,
path: path,
logger: log.New("database", path, "table", name),
Expand All @@ -189,7 +189,7 @@ func newCustomTable(path string, name string, readMeter metrics.Meter, writeMete
tab.Close()
return nil, err
}
tab.sizeCounter.Inc(int64(size))
tab.sizeGauge.Inc(int64(size))

return tab, nil
}
Expand Down Expand Up @@ -378,7 +378,7 @@ func (t *freezerTable) truncate(items uint64) error {
if err != nil {
return err
}
t.sizeCounter.Dec(int64(oldSize - newSize))
t.sizeGauge.Dec(int64(oldSize - newSize))

return nil
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func (t *freezerTable) Append(item uint64, blob []byte) error {
t.index.Write(idx.marshallBinary())

t.writeMeter.Mark(int64(bLen + indexEntrySize))
t.sizeCounter.Inc(int64(bLen + indexEntrySize))
t.sizeGauge.Inc(int64(bLen + indexEntrySize))

atomic.AddUint64(&t.items, 1)
return nil
Expand Down
Loading

0 comments on commit d1923c1

Please sign in to comment.