Skip to content

Commit

Permalink
Force some traces to be fetched from feeder gateway (#1823)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan committed Apr 16, 2024
1 parent bde35d8 commit a570b6b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 55 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/ethereum/go-ethereum v1.13.10
github.com/fxamacker/cbor/v2 v2.5.0
github.com/go-playground/validator/v10 v10.17.0
github.com/hashicorp/go-set/v2 v2.1.0
github.com/jinzhu/copier v0.4.0
github.com/libp2p/go-libp2p v0.32.2
github.com/libp2p/go-libp2p-kad-dht v0.25.2
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpx
github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/hashicorp/go-set/v2 v2.1.0 h1:iERPCQWks+I+4bTgy0CT2myZsCqNgBg79ZHqwniohXo=
github.com/hashicorp/go-set/v2 v2.1.0/go.mod h1:6q4nh8UCVZODn2tJ5RbJi8+ki7pjZBsAEYGt6yaGeTo=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
Expand Down Expand Up @@ -464,6 +466,8 @@ github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWR
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shoenig/test v0.6.7 h1:k92ohN9VyRfZn0ezNfwamtIBT/5byyfLVktRmL/Jmek=
github.com/shoenig/test v0.6.7/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k=
github.com/shurcooL/component v0.0.0-20170202220835-f88ec8f54cc4/go.mod h1:XhFIlyj5a1fBNx5aJTbKoIq0mNaPvOagO+HjB3EtxrY=
github.com/shurcooL/events v0.0.0-20181021180414-410e4ca65f48/go.mod h1:5u70Mqkb5O5cxEA8nxTsgrgLehJeAw6Oc4Ab1c/P1HM=
github.com/shurcooL/github_flavored_markdown v0.0.0-20181002035957-2122de532470/go.mod h1:2dOwnU2uBioM+SGy2aZoq1f/Sd1l9OkAeAUvjSyvgU0=
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func New(cfg *Config, version string) (*Node, error) { //nolint:gocyclo,funlen
syncReader = synchronizer
}

rpcHandler := rpc.New(chain, syncReader, throttledVM, version, log).WithGateway(gatewayClient).WithFeeder(client)
rpcHandler := rpc.New(chain, syncReader, throttledVM, version, &cfg.Network, log).WithGateway(gatewayClient).WithFeeder(client)
rpcHandler = rpcHandler.WithFilterLimit(cfg.RPCMaxBlockScan).WithCallMaxSteps(uint64(cfg.RPCCallMaxSteps))
services = append(services, rpcHandler)
// to improve RPC throughput we double GOMAXPROCS
Expand Down
21 changes: 14 additions & 7 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/NethermindEth/juno/utils"
"github.com/NethermindEth/juno/vm"
"github.com/ethereum/go-ethereum/common/lru"
"github.com/hashicorp/go-set/v2"
"github.com/sourcegraph/conc"
)

Expand Down Expand Up @@ -87,7 +88,9 @@ type Handler struct {
feederClient *feeder.Client
vm vm.VM
log utils.Logger
version string

version string
forceFeederTracesForBlocks *set.Set[uint64]

newHeads *feed.Feed[*core.Header]

Expand All @@ -107,7 +110,9 @@ type subscription struct {
conn jsonrpc.Conn
}

func New(bcReader blockchain.Reader, syncReader sync.Reader, virtualMachine vm.VM, version string, logger utils.Logger) *Handler {
func New(bcReader blockchain.Reader, syncReader sync.Reader, virtualMachine vm.VM, version string, network *utils.Network,
logger utils.Logger,
) *Handler {
return &Handler{
bcReader: bcReader,
syncReader: syncReader,
Expand All @@ -119,9 +124,10 @@ func New(bcReader blockchain.Reader, syncReader sync.Reader, virtualMachine vm.V
}
return n
},
version: version,
newHeads: feed.New[*core.Header](),
subscriptions: make(map[uint64]*subscription),
version: version,
forceFeederTracesForBlocks: set.From(network.BlockHashMetaInfo.ForceFetchingTracesForBlocks),
newHeads: feed.New[*core.Header](),
subscriptions: make(map[uint64]*subscription),

blockTraceCache: lru.NewCache[traceCacheKey, []TracedBlockTransaction](traceCacheSize),
filterLimit: math.MaxUint,
Expand Down Expand Up @@ -1162,6 +1168,7 @@ func (h *Handler) Events(args EventsArg) (*EventsChunk, *jsonrpc.Error) {
}

func setEventFilterRange(filter *blockchain.EventFilter, fromID, toID *BlockID, latestHeight uint64) error {
//nolint:gocritic
set := func(filterRange blockchain.EventFilterRange, id *BlockID) error {
if id == nil {
return nil
Expand Down Expand Up @@ -1691,8 +1698,8 @@ func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block,
if !isPending {
if blockVer, err := core.ParseBlockVersion(block.ProtocolVersion); err != nil {
return nil, ErrUnexpectedError.CloneWithData(err.Error())
} else if blockVer.Compare(traceFallbackVersion) != 1 {
// version <= 0.12.3
} else if blockVer.Compare(traceFallbackVersion) != 1 || h.forceFeederTracesForBlocks.Contains(block.Number) {
// version <= 0.12.3 or forcing fetch some blocks from feeder gateway
return h.fetchTraces(ctx, block.Hash)
}

Expand Down
Loading

0 comments on commit a570b6b

Please sign in to comment.