Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions adapters/sn2core/sn2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func AdaptPreConfirmedBlock(
adaptedBlock,
&stateUpdate,
txStateDiffs,
response.BlockIdentifier,
uint64(response.BlockIdentifier),
)
return preConfirmed, nil
}
Expand All @@ -592,7 +592,7 @@ func AdaptPreConfirmedWithDelta(
current *pending.PreConfirmed,
delta *starknet.PreConfirmedDeltaUpdate,
) (pending.PreConfirmed, error) {
if current.BlockIdentifier != delta.BlockIdentifier {
if current.BlockIdentifier != uint64(delta.BlockIdentifier) {
return pending.PreConfirmed{}, ErrPreConfirmedIdentifierMismatch
}

Expand Down
14 changes: 7 additions & 7 deletions adapters/sn2core/sn2core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func TestAdaptPreConfirmed(t *testing.T) {
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
blockNumberStr := strconv.FormatUint(test.blockNumber, 10)
update, err := client.PreConfirmedBlockWithIdentifier(t.Context(), blockNumberStr, "", 0)
update, err := client.PreConfirmedBlockWithIdentifier(t.Context(), blockNumberStr, 0, 0)
require.NoError(t, err)
responseFull, ok := update.(starknet.PreConfirmedBlock)
require.True(t, ok, "expected PreConfirmedBlock, got %T", update)
Expand Down Expand Up @@ -708,7 +708,7 @@ func assertPreConfirmedBlockBasics(
assert.Equal(t, response.Version, preConfirmed.Block.ProtocolVersion)
assert.Equal(t, response.L1GasPrice.PriceInFri, preConfirmed.Block.L1GasPriceSTRK)
assert.Equal(t, response.L1GasPrice.PriceInWei, preConfirmed.Block.L1GasPriceETH)
assert.Equal(t, response.BlockIdentifier, preConfirmed.BlockIdentifier)
assert.Equal(t, uint64(response.BlockIdentifier), preConfirmed.BlockIdentifier)
}

func assertStateDiffs(
Expand Down Expand Up @@ -816,23 +816,23 @@ func TestAdaptPreConfirmedWithDelta(t *testing.T) {

t.Run("returns ErrPreConfirmedIdentifierMismatch on identifier drift", func(t *testing.T) {
current := &pending.PreConfirmed{
BlockIdentifier: "round-a",
BlockIdentifier: 1,
Block: &core.Block{Header: &core.Header{}},
StateUpdate: &core.StateUpdate{StateDiff: &core.StateDiff{}},
}
delta := &starknet.PreConfirmedDeltaUpdate{BlockIdentifier: "round-b"}
delta := &starknet.PreConfirmedDeltaUpdate{BlockIdentifier: 2}
_, err := sn2core.AdaptPreConfirmedWithDelta(current, delta)
require.ErrorIs(t, err, sn2core.ErrPreConfirmedIdentifierMismatch)
})

t.Run("returns error on mismatched delta lengths", func(t *testing.T) {
current := &pending.PreConfirmed{
BlockIdentifier: "round-a",
BlockIdentifier: 1,
Block: &core.Block{Header: &core.Header{}},
StateUpdate: &core.StateUpdate{StateDiff: &core.StateDiff{}},
}
delta := &starknet.PreConfirmedDeltaUpdate{
BlockIdentifier: "round-a",
BlockIdentifier: 1,
Transactions: []starknet.Transaction{{}},
Receipts: []*starknet.TransactionReceipt{{}, {}},
TransactionStateDiffs: []*starknet.StateDiff{{}},
Expand All @@ -850,7 +850,7 @@ func mustFetchPreConfirmedBlock(
) *starknet.PreConfirmedBlock {
t.Helper()
update, err := client.PreConfirmedBlockWithIdentifier(
t.Context(), strconv.FormatUint(number, 10), "", 0,
t.Context(), strconv.FormatUint(number, 10), 0, 0,
)
require.NoError(t, err)
full, ok := update.(starknet.PreConfirmedBlock)
Expand Down
4 changes: 2 additions & 2 deletions blockchain/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ func TestState(t *testing.T) {
func TestEvents(t *testing.T) {
var pendingB *core.Block
preConfirmedFunc := func() (blockchain.PreConfirmedReader, error) { //nolint:unparam // test stub
preConfirmed := pending.NewPreConfirmed(pendingB, nil, nil, "")
preConfirmed := pending.NewPreConfirmed(pendingB, nil, nil, 0)
chain, err := preconfirmed.NewChain(&preConfirmed)
if err != nil {
return nil, err
Expand Down Expand Up @@ -771,7 +771,7 @@ func TestEventsMultiPreConfirmed(t *testing.T) {
block, err := gw.BlockByNumber(t.Context(), i)
require.NoError(t, err)

preconfirmed := pending.NewPreConfirmed(block, nil, nil, "")
preconfirmed := pending.NewPreConfirmed(block, nil, nil, 0)
pcEntries[i-firstPreConfirmedBlock] = &preconfirmed
}
preconfChain, err := preconfirmed.NewChain(pcEntries...)
Expand Down
18 changes: 8 additions & 10 deletions clients/feeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
classHashArg = "classHash"
trueStr = "true"

PreConfirmedBlankIdentifier = "0x0"
PreConfirmedBlankIdentifier starknet.BlockIdentifier = 0
)

var ErrDeprecatedCompiledClass = errors.New("deprecated compiled class")
Expand Down Expand Up @@ -56,12 +56,12 @@ type Reader interface {
PreConfirmedBlockWithIdentifier(
ctx context.Context,
blockNumber string,
blockIdentifier string,
blockIdentifier starknet.BlockIdentifier,
knownTransactionCount uint64,
) (starknet.PreConfirmedUpdate, error)
PreConfirmedBlockLatest(
ctx context.Context,
blockIdentifier string,
blockIdentifier starknet.BlockIdentifier,
knownTransactionCount uint64,
) (starknet.PreConfirmedUpdate, uint64, error)
PublicKey(ctx context.Context) (felt.Felt, error)
Expand Down Expand Up @@ -367,9 +367,10 @@ func (c *Client) StateUpdateWithBlockAndSignature(
func (c *Client) PreConfirmedBlockWithIdentifier(
ctx context.Context,
blockNumber string,
blockIdentifier string,
blockIdentifier starknet.BlockIdentifier,
knownTransactionCount uint64,
) (starknet.PreConfirmedUpdate, error) {

preConfirmedEnvelope, err := c.fetchPreConfirmedUpdate(
ctx,
blockNumber,
Expand All @@ -388,7 +389,7 @@ func (c *Client) PreConfirmedBlockWithIdentifier(
// Pass an empty identifier and zero txCount for a full reply.
func (c *Client) PreConfirmedBlockLatest(
ctx context.Context,
blockIdentifier string,
blockIdentifier starknet.BlockIdentifier,
knownTransactionCount uint64,
) (starknet.PreConfirmedUpdate, uint64, error) {
preConfirmedEnvelope, err := c.fetchPreConfirmedUpdate(
Expand All @@ -414,15 +415,12 @@ func (c *Client) PreConfirmedBlockLatest(
func (c *Client) fetchPreConfirmedUpdate(
ctx context.Context,
blockNumber string,
blockIdentifier string,
blockIdentifier starknet.BlockIdentifier,
knownTransactionCount uint64,
) (*starknet.PreConfirmedUpdateEnvelope, error) {
if blockIdentifier == "" {
blockIdentifier = PreConfirmedBlankIdentifier
}
queryURL := buildQueryString(c.url, "get_preconfirmed_block", map[string]string{
blockNumberArg: blockNumber,
"blockIdentifier": blockIdentifier,
"blockIdentifier": fmt.Sprintf("0x%x", blockIdentifier),
"knownTransactionCount": strconv.FormatUint(knownTransactionCount, 10),
})

Expand Down
16 changes: 8 additions & 8 deletions clients/feeder/feeder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ func TestFeederValidation(t *testing.T) {
}`
client := clientServingBody(t, body)

update, err := client.PreConfirmedBlockWithIdentifier(t.Context(), "", "", 0)
update, err := client.PreConfirmedBlockWithIdentifier(t.Context(), "", 0, 0)
require.NoError(t, err)
_, ok := update.(starknet.PreConfirmedDeltaUpdate)
require.True(t, ok)
Expand All @@ -1265,7 +1265,7 @@ func TestFeederValidation(t *testing.T) {
}`
client := clientServingBody(t, body)

update, err := client.PreConfirmedBlockWithIdentifier(t.Context(), "", "", 0)
update, err := client.PreConfirmedBlockWithIdentifier(t.Context(), "", 0, 0)
require.Error(t, err)
require.Nil(t, update)
assert.ErrorIs(t, err, feeder.ErrInvalidFeederResponse)
Expand All @@ -1280,37 +1280,37 @@ func TestPreConfirmedBlockLatest(t *testing.T) {
client := feeder.NewTestClient(t, &networks.Sepolia)

t.Run("blank identifier returns the full block for a new round", func(t *testing.T) {
update, blockNumber, err := client.PreConfirmedBlockLatest(t.Context(), "", 0)
update, blockNumber, err := client.PreConfirmedBlockLatest(t.Context(), 0, 0)
require.NoError(t, err)
assert.Equal(t, uint64(10936237), blockNumber)

full, ok := update.(starknet.PreConfirmedBlock)
require.True(t, ok, "expected PreConfirmedBlock, got %T", update)
assert.Equal(t, "0x1cbe25d9", full.BlockIdentifier)
assert.Equal(t, starknet.BlockIdentifier(0x1cbe25d9), full.BlockIdentifier)
assert.Equal(t, "PRE_CONFIRMED", full.Status)
assert.Equal(t, "0.14.2", full.Version)
assert.Len(t, full.Transactions, 3)
})

t.Run("matching identifier and txn count returns the appended delta", func(t *testing.T) {
update, blockNumber, err := client.PreConfirmedBlockLatest(t.Context(), "0x1cbe25d9", 3)
update, blockNumber, err := client.PreConfirmedBlockLatest(t.Context(), 0x1cbe25d9, 3)
require.NoError(t, err)
assert.Equal(t, uint64(10936237), blockNumber)

delta, ok := update.(starknet.PreConfirmedDeltaUpdate)
require.True(t, ok, "expected PreConfirmedDeltaUpdate, got %T", update)
assert.Equal(t, "0x1cbe25d9", delta.BlockIdentifier)
assert.Equal(t, starknet.BlockIdentifier(0x1cbe25d9), delta.BlockIdentifier)
assert.Len(t, delta.Transactions, 1)
})

t.Run("matching identifier with no appended txns returns no change", func(t *testing.T) {
update, _, err := client.PreConfirmedBlockLatest(t.Context(), "0x1cbe25d9", 4)
update, _, err := client.PreConfirmedBlockLatest(t.Context(), 0x1cbe25d9, 4)
require.NoError(t, err)
assert.IsType(t, starknet.PreConfirmedNoChange{}, update)
})

t.Run("full block response without block_number is rejected", func(t *testing.T) {
_, _, err := client.PreConfirmedBlockLatest(t.Context(), "0xbad", 0)
_, _, err := client.PreConfirmedBlockLatest(t.Context(), 0xbad, 0)
require.ErrorContains(t, err, "missing block_number")
})
}
4 changes: 3 additions & 1 deletion clients/feeder/test_feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package feeder

import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -160,7 +161,8 @@ func resolveDirAndQueryArg(t testing.TB, path string, queryMap url.Values) (stri
// any other identifier selects the exact response fixture at
// preconfirmed/<blockNumber>/<identifier>/<knownTransactionCount>.
blockNumber := queryMap.Get(blockNumberArg)
if identifier := queryMap.Get("blockIdentifier"); identifier != PreConfirmedBlankIdentifier {
blankIdentifier := fmt.Sprintf("0x%x", PreConfirmedBlankIdentifier)
if identifier := queryMap.Get("blockIdentifier"); identifier != blankIdentifier {
return filepath.Join("preconfirmed", blockNumber, identifier), "knownTransactionCount", nil
}
queryMap["preconfirmedFile"] = []string{"full"}
Expand Down
4 changes: 2 additions & 2 deletions core/pending/pending.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ type PreConfirmed struct {
// BlockIdentifier is an identifier returned by the feeder gateway
// that uniquely identifies the current round of the pre_confirmed block.
// It is used to negotiate delta-sync responses on subsequent polls.
BlockIdentifier string
BlockIdentifier uint64
}

func NewPreConfirmed(
block *core.Block,
stateUpdate *core.StateUpdate,
transactionStateDiffs []*core.StateDiff,
blockIdentifier string,
blockIdentifier uint64,
) PreConfirmed {
return PreConfirmed{
Block: block,
Expand Down
6 changes: 3 additions & 3 deletions mocks/mock_feeder.go

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

6 changes: 3 additions & 3 deletions mocks/mock_starknetdata.go

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

6 changes: 3 additions & 3 deletions rpc/rpccore/preconfirmed_deduper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package rpccore
// synchronisation.
type PreConfirmedDeduper[K comparable] struct {
blockNum uint64
identifier string
identifier uint64
seen map[K]struct{}
}

Expand All @@ -22,7 +22,7 @@ func NewPreConfirmedDeduper[K comparable]() *PreConfirmedDeduper[K] {
// MarkSent records key for the given pre_confirmed round (blockNum + identifier) and
// reports whether it was newly added — i.e. whether it should be sent. Advancing to a
// different block number or round identifier discards the previous round's keys first.
func (c *PreConfirmedDeduper[K]) MarkSent(blockNum uint64, identifier string, key *K) bool {
func (c *PreConfirmedDeduper[K]) MarkSent(blockNum uint64, identifier uint64, key *K) bool {
if blockNum != c.blockNum || identifier != c.identifier {
clear(c.seen)
c.blockNum = blockNum
Expand All @@ -39,5 +39,5 @@ func (c *PreConfirmedDeduper[K]) MarkSent(blockNum uint64, identifier string, ke
func (c *PreConfirmedDeduper[K]) Clear() {
clear(c.seen)
c.blockNum = 0
c.identifier = ""
c.identifier = 0
}
4 changes: 2 additions & 2 deletions rpc/rpccore/preconfirmed_deduper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestPreConfirmedDeduper(t *testing.T) {
key1 := "key1"
key2 := "key2"
const id1, id2 = "round-1", "round-2"
const id1, id2 = uint64(1), uint64(2)

t.Run("dedups within the same round", func(t *testing.T) {
d := rpccore.NewPreConfirmedDeduper[string]()
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestPreConfirmedDeduper(t *testing.T) {

func BenchmarkPreConfirmedDeduper_MarkSent(b *testing.B) {
d := rpccore.NewPreConfirmedDeduper[string]()
const id = "round"
const id = uint64(1)
b.ReportAllocs()
b.ResetTimer()
for i := range b.N {
Expand Down
4 changes: 2 additions & 2 deletions rpc/v10/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func TestBlockTransactionCount(t *testing.T) {
t.Run("blockID - pre_confirmed", func(t *testing.T) {
latestBlock.Hash = nil
latestBlock.GlobalStateRoot = nil
preConfirmed := pending.NewPreConfirmed(latestBlock, nil, nil, "")
preConfirmed := pending.NewPreConfirmed(latestBlock, nil, nil, 0)
mockSyncReader.EXPECT().PreConfirmedChain().Return(mustNewChain(t, &preConfirmed), nil)

preConfirmedID := rpc.BlockIDPreConfirmed()
Expand All @@ -666,7 +666,7 @@ func TestBlockTransactionCount(t *testing.T) {
t.Run("blockID - pre_confirmed multi-block chain returns tip count", func(t *testing.T) {
latestBlock.Hash = nil
latestBlock.GlobalStateRoot = nil
tipEntry := pending.NewPreConfirmed(latestBlock, nil, nil, "")
tipEntry := pending.NewPreConfirmed(latestBlock, nil, nil, 0)

baseHeader := *latestBlock.Header
baseHeader.Number = latestBlock.Number - 1
Expand Down
2 changes: 1 addition & 1 deletion rpc/v10/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func createEventPreConfirmedFromBlock(
Receipts: block.Receipts,
}

preConfirmed := pending.NewPreConfirmed(preConfirmedBlock, nil, nil, "")
preConfirmed := pending.NewPreConfirmed(preConfirmedBlock, nil, nil, 0)

// Extract events from the block and convert to emitted events
var events []rpc.EmittedEvent
Expand Down
Loading