mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 06:06:44 +00:00
Merge branch 'master' of https://github.com/juga1980/go-ethereum
This commit is contained in:
commit
0f137b8db7
5 changed files with 282 additions and 23 deletions
|
|
@ -765,15 +765,8 @@ func downloadEra(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseRange(s string) (start uint64, end uint64, ok bool) {
|
func parseRange(s string) (start uint64, end uint64, ok bool) {
|
||||||
if m, _ := regexp.MatchString("[0-9]+", s); m {
|
log.Info("Parsing block range", "input", s)
|
||||||
start, err := strconv.ParseUint(s, 10, 64)
|
if m, _ := regexp.MatchString("^[0-9]+-[0-9]+$", s); m {
|
||||||
if err != nil {
|
|
||||||
return 0, 0, false
|
|
||||||
}
|
|
||||||
end = start
|
|
||||||
return start, end, true
|
|
||||||
}
|
|
||||||
if m, _ := regexp.MatchString("[0-9]+-[0-9]+", s); m {
|
|
||||||
s1, s2, _ := strings.Cut(s, "-")
|
s1, s2, _ := strings.Cut(s, "-")
|
||||||
start, err := strconv.ParseUint(s1, 10, 64)
|
start, err := strconv.ParseUint(s1, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -783,6 +776,19 @@ func parseRange(s string) (start uint64, end uint64, ok bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
}
|
||||||
|
if start > end {
|
||||||
|
return 0, 0, false
|
||||||
|
}
|
||||||
|
log.Info("Parsing block range", "start", start, "end", end)
|
||||||
|
return start, end, true
|
||||||
|
}
|
||||||
|
if m, _ := regexp.MatchString("^[0-9]+$", s); m {
|
||||||
|
start, err := strconv.ParseUint(s, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, false
|
||||||
|
}
|
||||||
|
end = start
|
||||||
|
log.Info("Parsing single block range", "block", start)
|
||||||
return start, end, true
|
return start, end, true
|
||||||
}
|
}
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
|
|
|
||||||
98
cmd/geth/chaincmd_test.go
Normal file
98
cmd/geth/chaincmd_test.go
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
// Copyright 2025 The go-ethereum Authors
|
||||||
|
// This file is part of go-ethereum.
|
||||||
|
//
|
||||||
|
// go-ethereum is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// go-ethereum is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestParseRange(t *testing.T) {
|
||||||
|
var cases = []struct {
|
||||||
|
input string
|
||||||
|
valid bool
|
||||||
|
expStart uint64
|
||||||
|
expEnd uint64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
input: "0",
|
||||||
|
valid: true,
|
||||||
|
expStart: 0,
|
||||||
|
expEnd: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "500",
|
||||||
|
valid: true,
|
||||||
|
expStart: 500,
|
||||||
|
expEnd: 500,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "-1",
|
||||||
|
valid: false,
|
||||||
|
expStart: 0,
|
||||||
|
expEnd: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "1-1",
|
||||||
|
valid: true,
|
||||||
|
expStart: 1,
|
||||||
|
expEnd: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "0-1",
|
||||||
|
valid: true,
|
||||||
|
expStart: 0,
|
||||||
|
expEnd: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "1-0",
|
||||||
|
valid: false,
|
||||||
|
expStart: 0,
|
||||||
|
expEnd: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "1-1000",
|
||||||
|
valid: true,
|
||||||
|
expStart: 1,
|
||||||
|
expEnd: 1000,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "1-1-",
|
||||||
|
valid: false,
|
||||||
|
expStart: 0,
|
||||||
|
expEnd: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "-1-1",
|
||||||
|
valid: false,
|
||||||
|
expStart: 0,
|
||||||
|
expEnd: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
start, end, valid := parseRange(c.input)
|
||||||
|
if valid != c.valid {
|
||||||
|
t.Errorf("Unexpected result, want: %t, got: %t", c.valid, valid)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if valid {
|
||||||
|
if c.expStart != start {
|
||||||
|
t.Errorf("Unexpected start, want: %d, got: %d", c.expStart, start)
|
||||||
|
}
|
||||||
|
if c.expEnd != end {
|
||||||
|
t.Errorf("Unexpected end, want: %d, got: %d", c.expEnd, end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
135
eth/tracers/internal/tracetest/testdata/prestate_tracer/7702_delegate.json
vendored
Normal file
135
eth/tracers/internal/tracetest/testdata/prestate_tracer/7702_delegate.json
vendored
Normal file
File diff suppressed because one or more lines are too long
|
|
@ -81,6 +81,10 @@
|
||||||
"0x0000000000000000000000000000000000000000": {
|
"0x0000000000000000000000000000000000000000": {
|
||||||
"balance": "0x272e0528"
|
"balance": "0x272e0528"
|
||||||
},
|
},
|
||||||
|
"0x000000000000000000000000000000000000bbbb": {
|
||||||
|
"balance": "0x0",
|
||||||
|
"code": "0x6042604255"
|
||||||
|
},
|
||||||
"0x703c4b2bd70c169f5717101caee543299fc946c7": {
|
"0x703c4b2bd70c169f5717101caee543299fc946c7": {
|
||||||
"balance": "0xde0b6b3a7640000",
|
"balance": "0xde0b6b3a7640000",
|
||||||
"storage": {
|
"storage": {
|
||||||
|
|
|
||||||
|
|
@ -61,15 +61,16 @@ type accountMarshaling struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type prestateTracer struct {
|
type prestateTracer struct {
|
||||||
env *tracing.VMContext
|
env *tracing.VMContext
|
||||||
pre stateMap
|
pre stateMap
|
||||||
post stateMap
|
post stateMap
|
||||||
to common.Address
|
to common.Address
|
||||||
config prestateTracerConfig
|
config prestateTracerConfig
|
||||||
interrupt atomic.Bool // Atomic flag to signal execution interruption
|
chainConfig *params.ChainConfig
|
||||||
reason error // Textual reason for the interruption
|
interrupt atomic.Bool // Atomic flag to signal execution interruption
|
||||||
created map[common.Address]bool
|
reason error // Textual reason for the interruption
|
||||||
deleted map[common.Address]bool
|
created map[common.Address]bool
|
||||||
|
deleted map[common.Address]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type prestateTracerConfig struct {
|
type prestateTracerConfig struct {
|
||||||
|
|
@ -90,11 +91,12 @@ func newPrestateTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *p
|
||||||
return nil, errors.New("cannot use diffMode with includeEmpty")
|
return nil, errors.New("cannot use diffMode with includeEmpty")
|
||||||
}
|
}
|
||||||
t := &prestateTracer{
|
t := &prestateTracer{
|
||||||
pre: stateMap{},
|
pre: stateMap{},
|
||||||
post: stateMap{},
|
post: stateMap{},
|
||||||
config: config,
|
config: config,
|
||||||
created: make(map[common.Address]bool),
|
chainConfig: chainConfig,
|
||||||
deleted: make(map[common.Address]bool),
|
created: make(map[common.Address]bool),
|
||||||
|
deleted: make(map[common.Address]bool),
|
||||||
}
|
}
|
||||||
return &tracers.Tracer{
|
return &tracers.Tracer{
|
||||||
Hooks: &tracing.Hooks{
|
Hooks: &tracing.Hooks{
|
||||||
|
|
@ -133,6 +135,13 @@ func (t *prestateTracer) OnOpcode(pc uint64, opcode byte, gas, cost uint64, scop
|
||||||
case stackLen >= 5 && (op == vm.DELEGATECALL || op == vm.CALL || op == vm.STATICCALL || op == vm.CALLCODE):
|
case stackLen >= 5 && (op == vm.DELEGATECALL || op == vm.CALL || op == vm.STATICCALL || op == vm.CALLCODE):
|
||||||
addr := common.Address(stackData[stackLen-2].Bytes20())
|
addr := common.Address(stackData[stackLen-2].Bytes20())
|
||||||
t.lookupAccount(addr)
|
t.lookupAccount(addr)
|
||||||
|
// Lookup the delegation target
|
||||||
|
if t.chainConfig.IsPrague(t.env.BlockNumber, t.env.Time) {
|
||||||
|
code := t.env.StateDB.GetCode(addr)
|
||||||
|
if target, ok := types.ParseDelegation(code); ok {
|
||||||
|
t.lookupAccount(target)
|
||||||
|
}
|
||||||
|
}
|
||||||
case op == vm.CREATE:
|
case op == vm.CREATE:
|
||||||
nonce := t.env.StateDB.GetNonce(caller)
|
nonce := t.env.StateDB.GetNonce(caller)
|
||||||
addr := crypto.CreateAddress(caller, nonce)
|
addr := crypto.CreateAddress(caller, nonce)
|
||||||
|
|
@ -161,6 +170,13 @@ func (t *prestateTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction
|
||||||
t.created[t.to] = true
|
t.created[t.to] = true
|
||||||
} else {
|
} else {
|
||||||
t.to = *tx.To()
|
t.to = *tx.To()
|
||||||
|
// Lookup the delegation target
|
||||||
|
if t.chainConfig.IsPrague(t.env.BlockNumber, t.env.Time) {
|
||||||
|
code := t.env.StateDB.GetCode(t.to)
|
||||||
|
if target, ok := types.ParseDelegation(code); ok {
|
||||||
|
t.lookupAccount(target)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
t.lookupAccount(from)
|
t.lookupAccount(from)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue