Skip to content

Commit

Permalink
go-ethereum v1.14.7 update
Browse files Browse the repository at this point in the history
Vendored go-ethereum is now:

v1.14.7
  • Loading branch information
attente committed Jul 15, 2024
1 parent 2877284 commit 1a49db7
Show file tree
Hide file tree
Showing 15 changed files with 599 additions and 528 deletions.
492 changes: 492 additions & 0 deletions go-ethereum/accounts/abi/bind/source.go.tpl

Large diffs are not rendered by default.

503 changes: 8 additions & 495 deletions go-ethereum/accounts/abi/bind/template.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions go-ethereum/accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ type Type struct {
var (
// typeRegex parses the abi sub types
typeRegex = regexp.MustCompile("([a-zA-Z]+)(([0-9]+)(x([0-9]+))?)?")

// sliceSizeRegex grab the slice size
sliceSizeRegex = regexp.MustCompile("[0-9]+")
)

// NewType creates a new reflection type of abi type given in t.
Expand Down Expand Up @@ -91,8 +94,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
// grab the last cell and create a type from there
sliced := t[i:]
// grab the slice size with regexp
re := regexp.MustCompile("[0-9]+")
intz := re.FindAllString(sliced, -1)
intz := sliceSizeRegex.FindAllString(sliced, -1)

if len(intz) == 0 {
// is a slice
Expand Down
6 changes: 1 addition & 5 deletions go-ethereum/accounts/keystore/account_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,7 @@ func TestUpdatedKeyfileContents(t *testing.T) {
t.Parallel()

// Create a temporary keystore to test with
dir := filepath.Join(os.TempDir(), fmt.Sprintf("eth-keystore-updatedkeyfilecontents-test-%d-%d", os.Getpid(), rand.Int()))

// Create the directory
os.MkdirAll(dir, 0700)
defer os.RemoveAll(dir)
dir := t.TempDir()

ks := NewKeyStore(dir, LightScryptN, LightScryptP)

Expand Down
2 changes: 1 addition & 1 deletion go-ethereum/common/math/big.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewHexOrDecimal256(x int64) *HexOrDecimal256 {
// It is similar to UnmarshalText, but allows parsing real decimals too, not just
// quoted decimal strings.
func (i *HexOrDecimal256) UnmarshalJSON(input []byte) error {
if len(input) > 0 && input[0] == '"' {
if len(input) > 1 && input[0] == '"' {
input = input[1 : len(input)-1]
}
return i.UnmarshalText(input)
Expand Down
2 changes: 1 addition & 1 deletion go-ethereum/common/math/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type HexOrDecimal64 uint64
// It is similar to UnmarshalText, but allows parsing real decimals too, not just
// quoted decimal strings.
func (i *HexOrDecimal64) UnmarshalJSON(input []byte) error {
if len(input) > 0 && input[0] == '"' {
if len(input) > 1 && input[0] == '"' {
input = input[1 : len(input)-1]
}
return i.UnmarshalText(input)
Expand Down
2 changes: 1 addition & 1 deletion go-ethereum/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ func (d *Decimal) UnmarshalJSON(input []byte) error {
if !isString(input) {
return &json.UnmarshalTypeError{Value: "non-string", Type: reflect.TypeOf(uint64(0))}
}
if i, err := strconv.ParseInt(string(input[1:len(input)-1]), 10, 64); err == nil {
if i, err := strconv.ParseUint(string(input[1:len(input)-1]), 10, 64); err == nil {
*d = Decimal(i)
return nil
} else {
Expand Down
27 changes: 27 additions & 0 deletions go-ethereum/common/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"database/sql/driver"
"encoding/json"
"fmt"
"math"
"math/big"
"reflect"
"strings"
Expand Down Expand Up @@ -595,3 +596,29 @@ func BenchmarkPrettyDuration(b *testing.B) {
}
b.Logf("Post %s", a)
}

func TestDecimalUnmarshalJSON(t *testing.T) {
// These should error
for _, tc := range []string{``, `"`, `""`, `"-1"`} {
if err := new(Decimal).UnmarshalJSON([]byte(tc)); err == nil {
t.Errorf("input %s should cause error", tc)
}
}
// These should succeed
for _, tc := range []struct {
input string
want uint64
}{
{`"0"`, 0},
{`"9223372036854775807"`, math.MaxInt64},
{`"18446744073709551615"`, math.MaxUint64},
} {
have := new(Decimal)
if err := have.UnmarshalJSON([]byte(tc.input)); err != nil {
t.Errorf("input %q triggered error: %v", tc.input, err)
}
if uint64(*have) != tc.want {
t.Errorf("input %q, have %d want %d", tc.input, *have, tc.want)
}
}
}
12 changes: 6 additions & 6 deletions go-ethereum/core/types/transaction_signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,11 @@ func (s EIP155Signer) Hash(tx *Transaction) common.Hash {
// homestead rules.
type HomesteadSigner struct{ FrontierSigner }

func (s HomesteadSigner) ChainID() *big.Int {
func (hs HomesteadSigner) ChainID() *big.Int {
return nil
}

func (s HomesteadSigner) Equal(s2 Signer) bool {
func (hs HomesteadSigner) Equal(s2 Signer) bool {
_, ok := s2.(HomesteadSigner)
return ok
}
Expand All @@ -486,11 +486,11 @@ func (hs HomesteadSigner) Sender(tx *Transaction) (common.Address, error) {
// frontier rules.
type FrontierSigner struct{}

func (s FrontierSigner) ChainID() *big.Int {
func (fs FrontierSigner) ChainID() *big.Int {
return nil
}

func (s FrontierSigner) Equal(s2 Signer) bool {
func (fs FrontierSigner) Equal(s2 Signer) bool {
_, ok := s2.(FrontierSigner)
return ok
}
Expand Down Expand Up @@ -572,6 +572,6 @@ func deriveChainId(v *big.Int) *big.Int {
}
return new(big.Int).SetUint64((v - 35) / 2)
}
v = new(big.Int).Sub(v, big.NewInt(35))
return v.Div(v, big.NewInt(2))
v.Sub(v, big.NewInt(35))
return v.Rsh(v, 1)
}
2 changes: 1 addition & 1 deletion go-ethereum/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const RecoveryIDOffset = 64
const DigestLength = 32

var (
secp256k1N, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16)
secp256k1N = S256().Params().N
secp256k1halfN = new(big.Int).Div(secp256k1N, big.NewInt(2))
)

Expand Down
8 changes: 4 additions & 4 deletions go-ethereum/log/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
}

// ResetFieldPadding zeroes the field-padding for all attribute pairs.
func (t *TerminalHandler) ResetFieldPadding() {
t.mu.Lock()
t.fieldPadding = make(map[string]int)
t.mu.Unlock()
func (h *TerminalHandler) ResetFieldPadding() {
h.mu.Lock()
h.fieldPadding = make(map[string]int)
h.mu.Unlock()
}

type leveler struct{ minLevel slog.Level }
Expand Down
12 changes: 10 additions & 2 deletions go-ethereum/log/handler_glog.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,15 @@ func (h *GlogHandler) Vmodule(ruleset string) error {
return nil
}

// Enabled implements slog.Handler, reporting whether the handler handles records
// at the given level.
func (h *GlogHandler) Enabled(ctx context.Context, lvl slog.Level) bool {
// fast-track skipping logging if override not enabled and the provided verbosity is above configured
return h.override.Load() || slog.Level(h.level.Load()) <= lvl
}

// WithAttrs implements slog.Handler, returning a new Handler whose attributes
// consist of both the receiver's attributes and the arguments.
func (h *GlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
h.lock.RLock()
siteCache := maps.Clone(h.siteCache)
Expand All @@ -164,12 +168,16 @@ func (h *GlogHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
return &res
}

// WithGroup implements slog.Handler, returning a new Handler with the given
// group appended to the receiver's existing groups.
//
// Note, this function is not implemented.
func (h *GlogHandler) WithGroup(name string) slog.Handler {
panic("not implemented")
}

// Log implements Handler.Log, filtering a log record through the global, local
// and backtrace filters, finally emitting it if either allow it through.
// Handle implements slog.Handler, filtering a log record through the global,
// local and backtrace filters, finally emitting it if either allow it through.
func (h *GlogHandler) Handle(_ context.Context, r slog.Record) error {
// If the global log level allows, fast track logging
if slog.Level(h.level.Load()) <= r.Level {
Expand Down
6 changes: 3 additions & 3 deletions go-ethereum/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
LvlDebug = LevelDebug
)

// convert from old Geth verbosity level constants
// FromLegacyLevel converts from old Geth verbosity level constants
// to levels defined by slog
func FromLegacyLevel(lvl int) slog.Level {
switch lvl {
Expand Down Expand Up @@ -107,7 +107,7 @@ type Logger interface {
// With returns a new Logger that has this logger's attributes plus the given attributes
With(ctx ...interface{}) Logger

// With returns a new Logger that has this logger's attributes plus the given attributes. Identical to 'With'.
// New returns a new Logger that has this logger's attributes plus the given attributes. Identical to 'With'.
New(ctx ...interface{}) Logger

// Log logs a message at the specified level with context key/value pairs
Expand Down Expand Up @@ -156,7 +156,7 @@ func (l *logger) Handler() slog.Handler {
return l.inner.Handler()
}

// Write logs a message at the specified level:
// Write logs a message at the specified level.
func (l *logger) Write(level slog.Level, msg string, attrs ...any) {
if !l.inner.Enabled(context.Background(), level) {
return
Expand Down
2 changes: 1 addition & 1 deletion go-ethereum/params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
const (
VersionMajor = 1 // Major version component of the current release
VersionMinor = 14 // Minor version component of the current release
VersionPatch = 5 // Patch version component of the current release
VersionPatch = 7 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string
)

Expand Down
45 changes: 39 additions & 6 deletions go-ethereum/rpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
package rpc

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -468,16 +471,16 @@ func (h *handler) handleCallMsg(ctx *callProc, msg *jsonrpcMessage) *jsonrpcMess

case msg.isCall():
resp := h.handleCall(ctx, msg)
var ctx []interface{}
ctx = append(ctx, "reqid", idForLog{msg.ID}, "duration", time.Since(start))
var logctx []any
logctx = append(logctx, "reqid", idForLog{msg.ID}, "duration", time.Since(start))
if resp.Error != nil {
ctx = append(ctx, "err", resp.Error.Message)
logctx = append(logctx, "err", resp.Error.Message)
if resp.Error.Data != nil {
ctx = append(ctx, "errdata", resp.Error.Data)
logctx = append(logctx, "errdata", formatErrorData(resp.Error.Data))
}
h.log.Warn("Served "+msg.Method, ctx...)
h.log.Warn("Served "+msg.Method, logctx...)
} else {
h.log.Debug("Served "+msg.Method, ctx...)
h.log.Debug("Served "+msg.Method, logctx...)
}
return resp

Expand Down Expand Up @@ -576,3 +579,33 @@ func (id idForLog) String() string {
}
return string(id.RawMessage)
}

var errTruncatedOutput = errors.New("truncated output")

type limitedBuffer struct {
output []byte
limit int
}

func (buf *limitedBuffer) Write(data []byte) (int, error) {
avail := max(buf.limit, len(buf.output))
if len(data) < avail {
buf.output = append(buf.output, data...)
return len(data), nil
}
buf.output = append(buf.output, data[:avail]...)
return avail, errTruncatedOutput
}

func formatErrorData(v any) string {
buf := limitedBuffer{limit: 1024}
err := json.NewEncoder(&buf).Encode(v)
switch {
case err == nil:
return string(bytes.TrimRight(buf.output, "\n"))
case errors.Is(err, errTruncatedOutput):
return fmt.Sprintf("%s... (truncated)", buf.output)
default:
return fmt.Sprintf("bad error data (err=%v)", err)
}
}

0 comments on commit 1a49db7

Please sign in to comment.