From 06c1726ab93aba4e872e96cad9d8757b99732b98 Mon Sep 17 00:00:00 2001 From: HonzaDajc Date: Thu, 11 Jul 2024 09:50:04 +0200 Subject: [PATCH 1/2] Patch for message to referene --- ethapi/api.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/ethapi/api.go b/ethapi/api.go index 3149c6700..c0be58f20 100644 --- a/ethapi/api.go +++ b/ethapi/api.go @@ -2129,7 +2129,15 @@ func (api *PublicDebugAPI) TraceTransaction(ctx context.Context, hash common.Has // traceTx configures a new tracer according to the provided configuration, and // executes the given message in the provided environment. The return value will // be tracer dependent. -func (api *PublicDebugAPI) traceTx(ctx context.Context, message evmcore.Message, txctx *tracers.Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { +func (api *PublicDebugAPI) traceTx(ctx context.Context, message evmcore.Message, txctx *tracers.Context, vmctx vm.BlockContext, statedb *state.StateDB, config *TraceConfig) (ret interface{}, reterr error) { + + defer func() { + if r := recover(); r != nil { + log.Error("debug trace transaction failed with panic:", r) + reterr = fmt.Errorf("debug trace transaction failed with panic: %v", r) + } + }() + // Assemble the structured logger or the JavaScript tracer var ( tracer vm.Tracer @@ -2202,17 +2210,27 @@ func (api *PublicDebugAPI) traceTx(ctx context.Context, message evmcore.Message, if config.Tracer != nil && strings.Compare(*config.Tracer, "callTracer") == 0 { if strings.Contains(err.Error(), "cannot read property 'toString' of undefined") { log.Debug("error when debug with callTracer", "err", err.Error()) - callTracer, _ := tracers.New(*config.Tracer, txctx) - callTracer.CaptureStart(vmenv, message.From(), *message.To(), false, message.Data(), message.Gas(), message.Value()) + callTracer, errTracer := tracers.New(*config.Tracer, txctx) + if errTracer != nil { + return nil, errTracer + } + if message == nil || vmenv == nil { + return nil, err + } + to := message.To() + if to == nil { + to = &common.Address{} + } + callTracer.CaptureStart(vmenv, message.From(), *to, false, message.Data(), message.Gas(), message.Value()) callTracer.CaptureEnd([]byte{}, message.Gas(), time.Duration(0), fmt.Errorf("execution reverted")) - result, err = callTracer.GetResult() + return callTracer.GetResult() } } } return result, err default: - panic(fmt.Sprintf("bad tracer type %T", tracer)) + return nil, fmt.Errorf("bad tracer type %T", tracer) } } From 7548273cd55fe259c9967ece38862e80e511e096 Mon Sep 17 00:00:00 2001 From: HonzaDajc Date: Thu, 11 Jul 2024 09:50:50 +0200 Subject: [PATCH 2/2] Possibility to connect to Sonic nodes --- gossip/handler.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gossip/handler.go b/gossip/handler.go index 1d5a48a18..fcb134bd3 100644 --- a/gossip/handler.go +++ b/gossip/handler.go @@ -3,6 +3,7 @@ package gossip import ( "errors" "fmt" + "github.com/ethereum/go-ethereum/p2p/enode" "math" "math/rand" "strings" @@ -773,6 +774,17 @@ func (h *handler) highestPeerProgress() PeerProgress { return max } +// isUseless checks if the peer is banned from discovery and ban it if it should be +func isUseless(node *enode.Node, name string) bool { + useless := discfilter.Banned(node.ID(), node.Record()) + lowerName := strings.ToLower(name) + if !useless && !strings.Contains(lowerName, "opera") && !strings.Contains(lowerName, "sonic") { + useless = true + discfilter.Ban(node.ID()) + } + return useless +} + // handle is the callback invoked to manage the life cycle of a peer. When // this function terminates, the peer is disconnected. func (h *handler) handle(p *peer) error { @@ -783,11 +795,7 @@ func (h *handler) handle(p *peer) error { p.Log().Error("Snapshot extension barrier failed", "err", err) return err } - useless := discfilter.Banned(p.Node().ID(), p.Node().Record()) - if !useless && (!eligibleForSnap(p.Peer) || !strings.Contains(strings.ToLower(p.Name()), "opera")) { - useless = true - discfilter.Ban(p.ID()) - } + useless := isUseless(p.Node(), p.Name()) if !p.Peer.Info().Network.Trusted && useless { if h.peers.UselessNum() >= h.maxPeers/10 { // don't allow more than 10% of useless peers