Skip to content

Commit

Permalink
Remove ForceFetchingTracesForBlocks feature
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciechos committed Jun 24, 2024
1 parent d9e6410 commit bda6e61
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 96 deletions.
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, &cfg.Network, log).WithGateway(gatewayClient).WithFeeder(client)
rpcHandler := rpc.New(chain, syncReader, throttledVM, version, 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
20 changes: 10 additions & 10 deletions rpc/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestBlockNumber(t *testing.T) {
t.Cleanup(mockCtrl.Finish)

mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", utils.Ptr(utils.Mainnet), nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

t.Run("empty blockchain", func(t *testing.T) {
expectedHeight := uint64(0)
Expand All @@ -122,7 +122,7 @@ func TestBlockHashAndNumber(t *testing.T) {

n := utils.Ptr(utils.Mainnet)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

t.Run("empty blockchain", func(t *testing.T) {
mockReader.EXPECT().Head().Return(nil, errors.New("empty blockchain"))
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestBlockTransactionCount(t *testing.T) {

n := utils.Ptr(utils.Sepolia)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

client := feeder.NewTestClient(t, n)
gw := adaptfeeder.New(client)
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestBlockWithTxHashes(t *testing.T) {
log := utils.NewNopZapLogger()
n := utils.Ptr(utils.Mainnet)
chain := blockchain.New(pebble.NewMemTest(t), n)
handler := rpc.New(chain, nil, nil, "", n, log)
handler := rpc.New(chain, nil, nil, "", log)

block, rpcErr := handler.BlockWithTxHashes(id)
assert.Nil(t, block)
Expand All @@ -253,7 +253,7 @@ func TestBlockWithTxHashes(t *testing.T) {

n := utils.Ptr(utils.Sepolia)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

client := feeder.NewTestClient(t, n)
gw := adaptfeeder.New(client)
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestBlockWithTxs(t *testing.T) {
log := utils.NewNopZapLogger()
n := utils.Ptr(utils.Mainnet)
chain := blockchain.New(pebble.NewMemTest(t), n)
handler := rpc.New(chain, nil, nil, "", n, log)
handler := rpc.New(chain, nil, nil, "", log)

block, rpcErr := handler.BlockWithTxs(id)
assert.Nil(t, block)
Expand All @@ -372,7 +372,7 @@ func TestBlockWithTxs(t *testing.T) {

n := utils.Ptr(utils.Mainnet)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

client := feeder.NewTestClient(t, n)
gw := adaptfeeder.New(client)
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestBlockWithTxHashesV013(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

blockNumber := uint64(16350)
gw := adaptfeeder.New(feeder.NewTestClient(t, n))
Expand Down Expand Up @@ -560,7 +560,7 @@ func TestBlockWithReceipts(t *testing.T) {

n := utils.Ptr(utils.Mainnet)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

t.Run("transaction not found", func(t *testing.T) {
blockID := rpc.BlockID{Number: 777}
Expand Down Expand Up @@ -680,7 +680,7 @@ func TestRpcBlockAdaptation(t *testing.T) {

n := utils.Ptr(utils.Sepolia)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

client := feeder.NewTestClient(t, n)
gw := adaptfeeder.New(client)
Expand Down
2 changes: 1 addition & 1 deletion rpc/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestChainId(t *testing.T) {

mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(n)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

cID, err := handler.ChainID()
require.Nil(t, err)
Expand Down
11 changes: 5 additions & 6 deletions rpc/class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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, "", n, utils.NewNopZapLogger())
handler := rpc.New(mockReader, nil, nil, "", utils.NewNopZapLogger())

latest := rpc.BlockID{Latest: true}

Expand Down Expand Up @@ -68,7 +68,7 @@ func TestClass(t *testing.T) {

t.Run("state by id error", func(t *testing.T) {
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, utils.NewNopZapLogger())
handler := rpc.New(mockReader, nil, nil, "", utils.NewNopZapLogger())

mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound)

Expand All @@ -80,7 +80,7 @@ func TestClass(t *testing.T) {
t.Run("class hash not found error", func(t *testing.T) {
mockReader := mocks.NewMockReader(mockCtrl)
mockState := mocks.NewMockStateHistoryReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, utils.NewNopZapLogger())
handler := rpc.New(mockReader, nil, nil, "", utils.NewNopZapLogger())

mockReader.EXPECT().HeadState().Return(mockState, func() error {
return nil
Expand Down Expand Up @@ -120,7 +120,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, "", n, utils.NewNopZapLogger())
handler := rpc.New(mockReader, nil, nil, "", utils.NewNopZapLogger())

latest := rpc.BlockID{Latest: true}

Expand Down Expand Up @@ -150,10 +150,9 @@ func TestClassHashAt(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

n := utils.Ptr(utils.Mainnet)
mockReader := mocks.NewMockReader(mockCtrl)
log := utils.NewNopZapLogger()
handler := rpc.New(mockReader, nil, nil, "", n, log)
handler := rpc.New(mockReader, nil, nil, "", log)

t.Run("empty blockchain", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound)
Expand Down
6 changes: 2 additions & 4 deletions rpc/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ func TestNonce(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

n := utils.Ptr(utils.Mainnet)
mockReader := mocks.NewMockReader(mockCtrl)
log := utils.NewNopZapLogger()
handler := rpc.New(mockReader, nil, nil, "", n, log)
handler := rpc.New(mockReader, nil, nil, "", log)

t.Run("empty blockchain", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound)
Expand Down Expand Up @@ -92,10 +91,9 @@ func TestStorageAt(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

n := utils.Ptr(utils.Mainnet)
mockReader := mocks.NewMockReader(mockCtrl)
log := utils.NewNopZapLogger()
handler := rpc.New(mockReader, nil, nil, "", n, log)
handler := rpc.New(mockReader, nil, nil, "", log)

t.Run("empty blockchain", func(t *testing.T) {
mockReader.EXPECT().HeadState().Return(nil, nil, db.ErrKeyNotFound)
Expand Down
4 changes: 2 additions & 2 deletions rpc/estimate_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestEstimateMessageFee(t *testing.T) {
mockReader.EXPECT().Network().Return(n).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)

handler := rpc.New(mockReader, nil, mockVM, "", n, utils.NewNopZapLogger())
handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger())
msg := rpc.MsgFromL1{
From: common.HexToAddress("0xDEADBEEF"),
To: *new(felt.Felt).SetUint64(1337),
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestEstimateFee(t *testing.T) {
mockReader.EXPECT().Network().Return(n).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)
log := utils.NewNopZapLogger()
handler := rpc.New(mockReader, nil, mockVM, "", n, log)
handler := rpc.New(mockReader, nil, mockVM, "", log)

mockState := mocks.NewMockStateHistoryReader(mockCtrl)
mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil).AnyTimes()
Expand Down
6 changes: 3 additions & 3 deletions rpc/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestEvents(t *testing.T) {
}
}

handler := rpc.New(chain, nil, nil, "", n, utils.NewNopZapLogger())
handler := rpc.New(chain, nil, nil, "", utils.NewNopZapLogger())
from := utils.HexToFelt(t, "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7")
args := rpc.EventsArg{
EventFilter: rpc.EventFilter{
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
t.Cleanup(cancel)
chain := blockchain.New(pebble.NewMemTest(t), n)
syncer := sync.New(chain, gw, log, 0, false)
handler := rpc.New(chain, syncer, nil, "", n, log)
handler := rpc.New(chain, syncer, nil, "", log)

go func() {
require.NoError(t, handler.Run(ctx))
Expand Down Expand Up @@ -322,7 +322,7 @@ func TestMultipleSubscribeNewHeadsAndUnsubscribe(t *testing.T) {
t.Cleanup(cancel)
chain := blockchain.New(pebble.NewMemTest(t), n)
syncer := sync.New(chain, gw, log, 0, false)
handler := rpc.New(chain, syncer, nil, "", n, log)
handler := rpc.New(chain, syncer, nil, "", log)
go func() {
require.NoError(t, handler.Run(ctx))
}()
Expand Down
14 changes: 5 additions & 9 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ 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 @@ -81,9 +80,7 @@ type Handler struct {
vm vm.VM
log utils.Logger

version string
forceFeederTracesForBlocks *set.Set[uint64]

version string
newHeads *feed.Feed[*core.Header]

idgen func() uint64
Expand All @@ -102,7 +99,7 @@ type subscription struct {
conn jsonrpc.Conn
}

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

blockTraceCache: lru.NewCache[traceCacheKey, []TracedBlockTransaction](traceCacheSize),
filterLimit: math.MaxUint,
Expand Down
6 changes: 3 additions & 3 deletions rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ func nopCloser() error { return nil }
func TestVersion(t *testing.T) {
const version = "1.2.3-rc1"

handler := rpc.New(nil, nil, nil, version, utils.Ptr(utils.Mainnet), nil)
handler := rpc.New(nil, nil, nil, version, nil)
ver, err := handler.Version()
require.Nil(t, err)
assert.Equal(t, version, ver)
}

func TestSpecVersion(t *testing.T) {
handler := rpc.New(nil, nil, nil, "", utils.Ptr(utils.Mainnet), nil)
handler := rpc.New(nil, nil, nil, "", nil)
version, rpcErr := handler.SpecVersion()
require.Nil(t, rpcErr)
require.Equal(t, "0.7.1", version)
Expand All @@ -45,7 +45,7 @@ func TestThrottledVMError(t *testing.T) {
mockVM := mocks.NewMockVM(mockCtrl)

throttledVM := node.NewThrottledVM(mockVM, 0, 0)
handler := rpc.New(mockReader, nil, throttledVM, "", utils.Ptr(utils.Mainnet), nil)
handler := rpc.New(mockReader, nil, throttledVM, "", nil)
mockState := mocks.NewMockStateHistoryReader(mockCtrl)

throttledErr := "VM throughput limit reached"
Expand Down
2 changes: 1 addition & 1 deletion rpc/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestSimulateTransactions(t *testing.T) {
mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(n).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)
handler := rpc.New(mockReader, nil, mockVM, "", n, utils.NewNopZapLogger())
handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger())

mockState := mocks.NewMockStateHistoryReader(mockCtrl)
mockReader.EXPECT().HeadState().Return(mockState, nopCloser, nil).AnyTimes()
Expand Down
4 changes: 2 additions & 2 deletions rpc/state_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestStateUpdate(t *testing.T) {
for description, id := range errTests {
t.Run(description, func(t *testing.T) {
chain := blockchain.New(pebble.NewMemTest(t), n)
handler := rpc.New(chain, nil, nil, "", n, nil)
handler := rpc.New(chain, nil, nil, "", nil)

update, rpcErr := handler.StateUpdate(id)
assert.Nil(t, update)
Expand All @@ -40,7 +40,7 @@ func TestStateUpdate(t *testing.T) {

mockCtrl := gomock.NewController(t)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, nil, nil, "", n, nil)
handler := rpc.New(mockReader, nil, nil, "", nil)

client := feeder.NewTestClient(t, n)
mainnetGw := adaptfeeder.New(client)
Expand Down
4 changes: 1 addition & 3 deletions rpc/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/mocks"
"github.com/NethermindEth/juno/rpc"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
"go.uber.org/mock/gomock"
)
Expand All @@ -17,10 +16,9 @@ func TestSyncing(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

n := utils.Ptr(utils.Mainnet)
synchronizer := mocks.NewMockSyncReader(mockCtrl)
mockReader := mocks.NewMockReader(mockCtrl)
handler := rpc.New(mockReader, synchronizer, nil, "", n, nil)
handler := rpc.New(mockReader, synchronizer, nil, "", nil)
defaultSyncState := false

startingBlock := uint64(0)
Expand Down
5 changes: 2 additions & 3 deletions rpc/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,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 && block.ProtocolVersion != excludedVersion) ||
h.forceFeederTracesForBlocks.Contains(block.Number) {
// version <= 0.13.1 and not 0.13.1.1 or forcing fetch some blocks from feeder gateway
} else if blockVer.Compare(traceFallbackVersion) != 1 && block.ProtocolVersion != excludedVersion {
// version <= 0.13.1 and not 0.13.1.1 fetch blocks from feeder gateway
return h.fetchTraces(ctx, block.Hash)
}

Expand Down
Loading

0 comments on commit bda6e61

Please sign in to comment.