Skip to content

Commit

Permalink
Replace remaining value utils.Network types to pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
omerfirmak committed Jan 18, 2024
1 parent b08c0ea commit 12bad37
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
10 changes: 5 additions & 5 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type Reader interface {

Pending() (Pending, error)

Network() utils.Network
Network() *utils.Network
}

var (
Expand All @@ -71,7 +71,7 @@ var _ Reader = (*Blockchain)(nil)

// Blockchain is responsible for keeping track of all things related to the Starknet blockchain
type Blockchain struct {
network utils.Network
network *utils.Network
database db.DB

listener EventListener
Expand All @@ -83,7 +83,7 @@ func New(database db.DB, network *utils.Network) *Blockchain {
RegisterCoreTypesToEncoder()
return &Blockchain{
database: database,
network: *network,
network: network,
listener: &SelectiveListener{},
}
}
Expand All @@ -93,7 +93,7 @@ func (b *Blockchain) WithListener(listener EventListener) *Blockchain {
return b
}

func (b *Blockchain) Network() utils.Network {
func (b *Blockchain) Network() *utils.Network {
return b.network
}

Expand Down Expand Up @@ -640,7 +640,7 @@ func (b *Blockchain) SanityCheckNewHeight(block *core.Block, stateUpdate *core.S
return nil, err
}

return core.VerifyBlockHash(block, &b.network)
return core.VerifyBlockHash(block, b.network)
}

type txAndReceiptDBKey struct {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestNew(t *testing.T) {
gw := adaptfeeder.New(client)
t.Run("empty blockchain's head is nil", func(t *testing.T) {
chain := blockchain.New(pebble.NewMemTest(t), &utils.Mainnet)
assert.Equal(t, utils.Mainnet, chain.Network())
assert.Equal(t, &utils.Mainnet, chain.Network())
b, err := chain.Head()
assert.Nil(t, b)
assert.EqualError(t, err, db.ErrKeyNotFound.Error())
Expand Down
2 changes: 1 addition & 1 deletion l1/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Client struct {
l1 Subscriber
l2Chain *blockchain.Blockchain
log utils.SimpleLogger
network utils.Network
network *utils.Network
resubscribeDelay time.Duration
pollFinalisedInterval time.Duration
nonFinalisedLogs map[uint64]*contract.StarknetLogStateUpdate
Expand Down
4 changes: 2 additions & 2 deletions mocks/mock_blockchain.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 7 additions & 10 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func (h *Handler) Run(ctx context.Context) error {
// It follows the specification defined here:
// https://github.com/starkware-libs/starknet-specs/blob/a789ccc3432c57777beceaa53a34a7ae2f25fda0/api/starknet_api_openrpc.json#L542
func (h *Handler) ChainID() (*felt.Felt, *jsonrpc.Error) {
network := h.bcReader.Network()
return network.L2ChainIDFelt(), nil
return h.bcReader.Network().L2ChainIDFelt(), nil
}

// BlockNumber returns the latest synced block number.
Expand Down Expand Up @@ -1253,9 +1252,8 @@ func (h *Handler) Call(call FunctionCall, id BlockID) ([]*felt.Felt, *jsonrpc.Er
return nil, ErrContractNotFound
}

network := h.bcReader.Network()
res, err := h.vm.Call(&call.ContractAddress, classHash, &call.EntryPointSelector,
call.Calldata, header.Number, header.Timestamp, state, &network)
call.Calldata, header.Number, header.Timestamp, state, h.bcReader.Network())
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
return nil, ErrInternal.CloneWithData(err.Error())
Expand Down Expand Up @@ -1479,8 +1477,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra

paidFeesOnL1 := make([]*felt.Felt, 0)
for idx := range transactions {
network := h.bcReader.Network()
txn, declaredClass, paidFeeOnL1, aErr := adaptBroadcastedTransaction(&transactions[idx], &network)
txn, declaredClass, paidFeeOnL1, aErr := adaptBroadcastedTransaction(&transactions[idx], h.bcReader.Network())
if aErr != nil {
return nil, jsonrpc.Err(jsonrpc.InvalidParams, aErr.Error())
}
Expand All @@ -1494,13 +1491,13 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
classes = append(classes, declaredClass)
}
}
network := h.bcReader.Network()

sequencerAddress := header.SequencerAddress
if sequencerAddress == nil {
sequencerAddress = network.BlockHashMetaInfo.FallBackSequencerAddress
sequencerAddress = h.bcReader.Network().BlockHashMetaInfo.FallBackSequencerAddress
}
overallFees, traces, err := h.vm.Execute(txns, classes, header.Number, header.Timestamp, sequencerAddress,
state, &network, paidFeesOnL1, skipFeeCharge, skipValidate, errOnRevert, header.GasPrice,
state, h.bcReader.Network(), paidFeesOnL1, skipFeeCharge, skipValidate, errOnRevert, header.GasPrice,
header.GasPriceSTRK, legacyTraceJSON)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
Expand Down Expand Up @@ -1643,7 +1640,7 @@ func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block,
}

_, traces, err := h.vm.Execute(block.Transactions, classes, block.Number, block.Header.Timestamp,
sequencerAddress, state, &network, paidFeesOnL1, false, false, false, block.Header.GasPrice,
sequencerAddress, state, network, paidFeesOnL1, false, false, false, block.Header.GasPrice,
block.Header.GasPriceSTRK, legacyJSON)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
Expand Down
16 changes: 8 additions & 8 deletions rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestChainId(t *testing.T) {
t.Cleanup(mockCtrl.Finish)

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

cID, err := handler.ChainID()
Expand Down Expand Up @@ -3017,7 +3017,7 @@ func TestEstimateMessageFee(t *testing.T) {
t.Cleanup(mockCtrl.Finish)

mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(utils.Mainnet).AnyTimes()
mockReader.EXPECT().Network().Return(&utils.Mainnet).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)

handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger())
Expand Down Expand Up @@ -3091,7 +3091,7 @@ func TestLegacyEstimateMessageFee(t *testing.T) {
t.Cleanup(mockCtrl.Finish)

mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(utils.Mainnet).AnyTimes()
mockReader.EXPECT().Network().Return(&utils.Mainnet).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)

handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger())
Expand Down Expand Up @@ -3147,7 +3147,7 @@ func TestTraceTransaction(t *testing.T) {
t.Cleanup(mockCtrl.Finish)

mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(utils.Mainnet).AnyTimes()
mockReader.EXPECT().Network().Return(&utils.Mainnet).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)
handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger())

Expand Down Expand Up @@ -3222,7 +3222,7 @@ func TestSimulateTransactions(t *testing.T) {
network := utils.Mainnet

mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(network).AnyTimes()
mockReader.EXPECT().Network().Return(&network).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)
handler := rpc.New(mockReader, nil, mockVM, "", utils.NewNopZapLogger())

Expand Down Expand Up @@ -3299,7 +3299,7 @@ func TestTraceBlockTransactions(t *testing.T) {
network := utils.Mainnet

mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(network).AnyTimes()
mockReader.EXPECT().Network().Return(&network).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)
log := utils.NewNopZapLogger()

Expand Down Expand Up @@ -3699,7 +3699,7 @@ func TestThrottledVMError(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(utils.Mainnet).AnyTimes()
mockReader.EXPECT().Network().Return(&utils.Mainnet).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)

throttledVM := node.NewThrottledVM(mockVM, 0, 0)
Expand Down Expand Up @@ -3775,7 +3775,7 @@ func TestEstimateFee(t *testing.T) {
network := utils.Mainnet

mockReader := mocks.NewMockReader(mockCtrl)
mockReader.EXPECT().Network().Return(network).AnyTimes()
mockReader.EXPECT().Network().Return(&network).AnyTimes()
mockVM := mocks.NewMockVM(mockCtrl)
log := utils.NewNopZapLogger()
handler := rpc.New(mockReader, nil, mockVM, "", log)
Expand Down

0 comments on commit 12bad37

Please sign in to comment.