diff --git a/go.mod b/go.mod index 4882927edf..34730f40c2 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 6b18de7e7a..2ba0cb9e38 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/node/node.go b/node/node.go index 98b63750bb..de880617cf 100644 --- a/node/node.go +++ b/node/node.go @@ -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 diff --git a/rpc/handlers.go b/rpc/handlers.go index ad0fa3ba0b..234c33dafb 100644 --- a/rpc/handlers.go +++ b/rpc/handlers.go @@ -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" ) @@ -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] @@ -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, @@ -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, @@ -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 @@ -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) } diff --git a/rpc/handlers_test.go b/rpc/handlers_test.go index bbbaba0d0b..e00faf5831 100644 --- a/rpc/handlers_test.go +++ b/rpc/handlers_test.go @@ -44,7 +44,7 @@ func TestChainId(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) mockReader.EXPECT().Network().Return(&n) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", &n, nil) cID, err := handler.ChainID() require.Nil(t, err) @@ -58,7 +58,7 @@ func TestBlockNumber(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) t.Run("empty blockchain", func(t *testing.T) { expectedHeight := uint64(0) @@ -84,7 +84,7 @@ func TestBlockHashAndNumber(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) t.Run("empty blockchain", func(t *testing.T) { mockReader.EXPECT().Head().Return(nil, errors.New("empty blockchain")) @@ -116,7 +116,7 @@ func TestBlockTransactionCount(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) client := feeder.NewTestClient(t, &utils.Sepolia) gw := adaptfeeder.New(client) @@ -201,7 +201,7 @@ func TestBlockWithTxHashes(t *testing.T) { log := utils.NewNopZapLogger() network := utils.Mainnet chain := blockchain.New(pebble.NewMemTest(t), &network) - handler := rpc.New(chain, nil, nil, "", log) + handler := rpc.New(chain, nil, nil, "", &network, log) block, rpcErr := handler.BlockWithTxHashes(id) assert.Nil(t, block) @@ -213,7 +213,7 @@ func TestBlockWithTxHashes(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) client := feeder.NewTestClient(t, &utils.Goerli) gw := adaptfeeder.New(client) @@ -319,7 +319,7 @@ func TestBlockWithTxs(t *testing.T) { log := utils.NewNopZapLogger() network := utils.Mainnet chain := blockchain.New(pebble.NewMemTest(t), &network) - handler := rpc.New(chain, nil, nil, "", log) + handler := rpc.New(chain, nil, nil, "", &network, log) block, rpcErr := handler.BlockWithTxs(id) assert.Nil(t, block) @@ -331,7 +331,7 @@ func TestBlockWithTxs(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) client := feeder.NewTestClient(t, &utils.Mainnet) gw := adaptfeeder.New(client) @@ -451,7 +451,7 @@ func TestBlockWithTxHashesV013(t *testing.T) { mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", &network, nil) blockNumber := uint64(319132) gw := adaptfeeder.New(feeder.NewTestClient(t, &network)) @@ -521,7 +521,7 @@ func TestTransactionByHashNotFound(t *testing.T) { txHash := new(felt.Felt).SetBytes([]byte("random hash")) mockReader.EXPECT().TransactionByHash(txHash).Return(nil, errors.New("tx not found")) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) tx, rpcErr := handler.TransactionByHash(*txHash) assert.Nil(t, tx) @@ -813,7 +813,7 @@ func TestTransactionByHash(t *testing.T) { mockReader.EXPECT().TransactionByHash(gomock.Any()).DoAndReturn(func(hash *felt.Felt) (core.Transaction, error) { return gw.Transaction(context.Background(), hash) }).Times(1) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", &test.network, nil) hash, err := new(felt.Felt).SetString(test.hash) require.NoError(t, err) @@ -847,7 +847,7 @@ func TestTransactionByBlockIdAndIndex(t *testing.T) { require.NoError(t, err) latestBlockHash := latestBlock.Hash - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) t.Run("empty blockchain", func(t *testing.T) { mockReader.EXPECT().HeadsHeader().Return(nil, db.ErrKeyNotFound) @@ -981,13 +981,11 @@ func TestTransactionByBlockIdAndIndex(t *testing.T) { //nolint:dupl func TestTransactionReceiptByHash(t *testing.T) { - t.Skip() - mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) t.Run("transaction not found", func(t *testing.T) { txHash := new(felt.Felt).SetBytes([]byte("random hash")) @@ -1239,13 +1237,11 @@ func TestTransactionReceiptByHash(t *testing.T) { } func TestBlockWithReceipts(t *testing.T) { - t.Skip() - mockCtrl := gomock.NewController(t) t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) t.Run("transaction not found", func(t *testing.T) { blockID := rpc.BlockID{Number: 777} @@ -1275,6 +1271,7 @@ func TestBlockWithReceipts(t *testing.T) { mainnetGw := adaptfeeder.New(client) t.Run("pending block", func(t *testing.T) { + t.Skip() block0, err := mainnetGw.BlockByNumber(context.Background(), 0) require.NoError(t, err) @@ -1315,6 +1312,7 @@ func TestBlockWithReceipts(t *testing.T) { }) t.Run("accepted L1 block", func(t *testing.T) { + t.Skip() block1, err := mainnetGw.BlockByNumber(context.Background(), 1) require.NoError(t, err) @@ -1364,7 +1362,7 @@ func TestLegacyTransactionReceiptByHash(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) t.Run("transaction not found", func(t *testing.T) { txHash := new(felt.Felt).SetBytes([]byte("random hash")) @@ -1620,7 +1618,7 @@ func TestStateUpdate(t *testing.T) { for description, id := range errTests { t.Run(description, func(t *testing.T) { chain := blockchain.New(pebble.NewMemTest(t), &utils.Mainnet) - handler := rpc.New(chain, nil, nil, "", nil) + handler := rpc.New(chain, nil, nil, "", utils.Ptr(utils.Mainnet), nil) update, rpcErr := handler.StateUpdate(id) assert.Nil(t, update) @@ -1630,7 +1628,7 @@ func TestStateUpdate(t *testing.T) { mockCtrl := gomock.NewController(t) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) client := feeder.NewTestClient(t, &utils.Mainnet) mainnetGw := adaptfeeder.New(client) @@ -1745,7 +1743,7 @@ func TestSyncing(t *testing.T) { synchronizer := mocks.NewMockSyncReader(mockCtrl) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, synchronizer, nil, "", nil) + handler := rpc.New(mockReader, synchronizer, nil, "", utils.Ptr(utils.Mainnet), nil) defaultSyncState := false startingBlock := uint64(0) @@ -1818,7 +1816,7 @@ func TestNonce(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) log := utils.NewNopZapLogger() - handler := rpc.New(mockReader, nil, nil, "", log) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), log) t.Run("empty blockchain", func(t *testing.T) { mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound) @@ -1891,7 +1889,7 @@ func TestStorageAt(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) log := utils.NewNopZapLogger() - handler := rpc.New(mockReader, nil, nil, "", log) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), log) t.Run("empty blockchain", func(t *testing.T) { mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound) @@ -1973,7 +1971,7 @@ func TestClassHashAt(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) log := utils.NewNopZapLogger() - handler := rpc.New(mockReader, nil, nil, "", log) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), log) t.Run("empty blockchain", func(t *testing.T) { mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound) @@ -2111,7 +2109,7 @@ func TestClass(t *testing.T) { return nil }, nil).AnyTimes() mockReader.EXPECT().HeadsHeader().Return(new(core.Header), nil).AnyTimes() - handler := rpc.New(mockReader, nil, nil, "", utils.NewNopZapLogger()) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), utils.NewNopZapLogger()) latest := rpc.BlockID{Latest: true} @@ -2167,7 +2165,7 @@ func TestClassAt(t *testing.T) { return nil }, nil).AnyTimes() mockReader.EXPECT().HeadsHeader().Return(new(core.Header), nil).AnyTimes() - handler := rpc.New(mockReader, nil, nil, "", utils.NewNopZapLogger()) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), utils.NewNopZapLogger()) latest := rpc.BlockID{Latest: true} @@ -2218,7 +2216,7 @@ func TestEvents(t *testing.T) { } } - handler := rpc.New(chain, nil, nil, "", utils.NewNopZapLogger()) + handler := rpc.New(chain, nil, nil, "", utils.Ptr(utils.Mainnet), utils.NewNopZapLogger()) from := utils.HexToFelt(t, "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7") args := rpc.EventsArg{ EventFilter: rpc.EventFilter{ @@ -2686,7 +2684,7 @@ func TestAddTransaction(t *testing.T) { }`), nil). Times(1) - handler := rpc.New(nil, nil, nil, "", utils.NewNopZapLogger()) + handler := rpc.New(nil, nil, nil, "", &network, utils.NewNopZapLogger()) _, rpcErr := handler.AddTransaction(context.Background(), test.txn) require.Equal(t, rpcErr.Code, rpc.ErrInternal.Code) @@ -2705,7 +2703,7 @@ func TestAddTransaction(t *testing.T) { func TestVersion(t *testing.T) { const version = "1.2.3-rc1" - handler := rpc.New(nil, nil, nil, version, nil) + handler := rpc.New(nil, nil, nil, version, utils.Ptr(utils.Mainnet), nil) ver, err := handler.Version() require.Nil(t, err) assert.Equal(t, version, ver) @@ -2758,7 +2756,7 @@ func TestTransactionStatus(t *testing.T) { mockReader.EXPECT().Receipt(tx.Hash()).Return(block.Receipts[0], block.Hash, block.Number, nil) mockReader.EXPECT().L1Head().Return(nil, nil) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", &test.network, nil) want := &rpc.TransactionStatus{ Finality: rpc.TxnStatusAcceptedOnL2, @@ -2776,7 +2774,7 @@ func TestTransactionStatus(t *testing.T) { BlockNumber: block.Number + 1, }, nil) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", &test.network, nil) want := &rpc.TransactionStatus{ Finality: rpc.TxnStatusAcceptedOnL1, @@ -2806,7 +2804,7 @@ func TestTransactionStatus(t *testing.T) { t.Run(description, func(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) mockReader.EXPECT().TransactionByHash(notFoundTest.hash).Return(nil, db.ErrKeyNotFound).Times(2) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", &test.network, nil) _, err := handler.TransactionStatus(ctx, *notFoundTest.hash) require.Equal(t, rpc.ErrTxnHashNotFound.Code, err.Code) @@ -2823,7 +2821,7 @@ func TestTransactionStatus(t *testing.T) { t.Run("transaction not found in db and feeder ", func(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) mockReader.EXPECT().TransactionByHash(test.notFoundTxHash).Return(nil, db.ErrKeyNotFound) - handler := rpc.New(mockReader, nil, nil, "", nil).WithFeeder(client) + handler := rpc.New(mockReader, nil, nil, "", &test.network, nil).WithFeeder(client) _, err := handler.TransactionStatus(ctx, *test.notFoundTxHash) require.NotNil(t, err) @@ -2839,7 +2837,7 @@ func TestCall(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) mockVM := mocks.NewMockVM(mockCtrl) - handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger()) + handler := rpc.New(mockReader, nil, mockVM, "", utils.Ptr(utils.Mainnet), utils.NewNopZapLogger()) t.Run("empty blockchain", func(t *testing.T) { mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound) @@ -2926,7 +2924,7 @@ func TestEstimateMessageFee(t *testing.T) { mockReader.EXPECT().Network().Return(&utils.Mainnet).AnyTimes() mockVM := mocks.NewMockVM(mockCtrl) - handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger()) + handler := rpc.New(mockReader, nil, mockVM, "", utils.Ptr(utils.Mainnet), utils.NewNopZapLogger()) msg := rpc.MsgFromL1{ From: common.HexToAddress("0xDEADBEEF"), To: *new(felt.Felt).SetUint64(1337), @@ -2997,7 +2995,7 @@ func TestTraceTransaction(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) mockReader.EXPECT().Network().Return(&utils.Mainnet).AnyTimes() mockVM := mocks.NewMockVM(mockCtrl) - handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger()) + handler := rpc.New(mockReader, nil, mockVM, "", utils.Ptr(utils.Mainnet), utils.NewNopZapLogger()) t.Run("not found", func(t *testing.T) { hash := utils.HexToFelt(t, "0xBBBB") @@ -3073,7 +3071,7 @@ func TestSimulateTransactions(t *testing.T) { mockReader := mocks.NewMockReader(mockCtrl) mockReader.EXPECT().Network().Return(&network).AnyTimes() mockVM := mocks.NewMockVM(mockCtrl) - handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger()) + handler := rpc.New(mockReader, nil, mockVM, "", &network, utils.NewNopZapLogger()) mockState := mocks.NewMockStateHistoryReader(mockCtrl) mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil).AnyTimes() @@ -3147,7 +3145,7 @@ func TestTraceBlockTransactions(t *testing.T) { log := utils.NewNopZapLogger() network := utils.Mainnet chain := blockchain.New(pebble.NewMemTest(t), &network) - handler := rpc.New(chain, nil, nil, "", log) + handler := rpc.New(chain, nil, nil, "", &network, log) update, rpcErr := handler.TraceBlockTransactions(context.Background(), id) assert.Nil(t, update) @@ -3164,7 +3162,7 @@ func TestTraceBlockTransactions(t *testing.T) { mockVM := mocks.NewMockVM(mockCtrl) log := utils.NewNopZapLogger() - handler := rpc.New(mockReader, nil, mockVM, "", log) + handler := rpc.New(mockReader, nil, mockVM, "", &network, log) t.Run("pending block", func(t *testing.T) { blockHash := utils.HexToFelt(t, "0x0001") @@ -3300,7 +3298,7 @@ func TestRpcBlockAdaptation(t *testing.T) { t.Cleanup(mockCtrl.Finish) mockReader := mocks.NewMockReader(mockCtrl) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil) client := feeder.NewTestClient(t, &utils.Goerli) gw := adaptfeeder.New(client) @@ -3350,7 +3348,7 @@ func TestSubscribeNewHeadsAndUnsubscribe(t *testing.T) { t.Cleanup(cancel) chain := blockchain.New(pebble.NewMemTest(t), &network) syncer := sync.New(chain, gw, log, 0, false) - handler := rpc.New(chain, syncer, nil, "", log) + handler := rpc.New(chain, syncer, nil, "", &network, log) go func() { require.NoError(t, handler.Run(ctx)) @@ -3432,7 +3430,7 @@ func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) { t.Cleanup(cancel) chain := blockchain.New(pebble.NewMemTest(t), &network) syncer := sync.New(chain, gw, log, 0, false) - handler := rpc.New(chain, syncer, nil, "", log) + handler := rpc.New(chain, syncer, nil, "", &network, log) go func() { require.NoError(t, handler.Run(ctx)) }() @@ -3543,7 +3541,7 @@ func TestTraceFallback(t *testing.T) { mockReader.EXPECT().BlockByHash(utils.HexToFelt(t, test.hash)).DoAndReturn(func(_ *felt.Felt) (block *core.Block, err error) { return mockReader.BlockByNumber(test.blockNumber) }).Times(2) - handler := rpc.New(mockReader, nil, nil, "", nil) + handler := rpc.New(mockReader, nil, nil, "", &network, nil) _, jErr := handler.TraceBlockTransactions(context.Background(), rpc.BlockID{Number: test.blockNumber}) require.Equal(t, rpc.ErrInternal.Code, jErr.Code) @@ -3565,7 +3563,7 @@ func TestThrottledVMError(t *testing.T) { mockVM := mocks.NewMockVM(mockCtrl) throttledVM := node.NewThrottledVM(mockVM, 0, 0) - handler := rpc.New(mockReader, nil, throttledVM, "", nil) + handler := rpc.New(mockReader, nil, throttledVM, "", utils.Ptr(utils.Mainnet), nil) mockState := mocks.NewMockStateHistoryReader(mockCtrl) throttledErr := "VM throughput limit reached" @@ -3621,7 +3619,7 @@ func TestThrottledVMError(t *testing.T) { } func TestSpecVersion(t *testing.T) { - handler := rpc.New(nil, nil, nil, "", nil) + handler := rpc.New(nil, nil, nil, "", utils.Ptr(utils.Mainnet), nil) version, rpcErr := handler.SpecVersion() require.Nil(t, rpcErr) require.Equal(t, "0.7.1", version) @@ -3643,7 +3641,7 @@ func TestEstimateFee(t *testing.T) { mockReader.EXPECT().Network().Return(&network).AnyTimes() mockVM := mocks.NewMockVM(mockCtrl) log := utils.NewNopZapLogger() - handler := rpc.New(mockReader, nil, mockVM, "", log) + handler := rpc.New(mockReader, nil, mockVM, "", &network, log) mockState := mocks.NewMockStateHistoryReader(mockCtrl) mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil).AnyTimes() diff --git a/utils/network.go b/utils/network.go index 3b67162e4c..8cbe6a5cf3 100644 --- a/utils/network.go +++ b/utils/network.go @@ -33,6 +33,8 @@ type BlockHashMetaInfo struct { First07Block uint64 `json:"first_07_block" validate:"required"` // Range of blocks that are not verifiable UnverifiableRange []uint64 `json:"unverifiable_range" validate:"required"` + // Block ids for which we fetch traces from feeder gateway instead of getting them from blockifier + ForceFetchingTracesForBlocks []uint64 `json:"force_fetching_traces_for_blocks"` } var ( @@ -53,6 +55,13 @@ var ( BlockHashMetaInfo: &BlockHashMetaInfo{ First07Block: 833, FallBackSequencerAddress: fallBackSequencerAddressMainnet, + ForceFetchingTracesForBlocks: []uint64{ + 631040, 631041, 631091, 631136, 631142, 631144, 631149, 631155, + 631204, 631269, 631368, 631602, 631685, 631739, 631741, 631760, + 631811, 631861, 631927, 632072, 632073, 632074, 632075, 632076, + 632077, 632078, 632079, 632081, 632202, 632206, 632237, 632241, + 632271, 632845, + }, }, } Goerli = Network{