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 .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ linters:
desc: use github.com/NethermindEth/juno/utils for logging
cbor:
files:
- "!**/encoder/*.go"
- "!**/utils/cbor/*/*.go"
deny:
- pkg: github.com/fxamacker/cbor/v2
desc: use github.com/NethermindEth/juno/encoder, do not import any other CBOR library directly
desc: use github.com/NethermindEth/juno/utils/cbor, do not import any other CBOR library directly
funlen:
lines: 120
statements: 50
Expand Down
2 changes: 1 addition & 1 deletion blockchain/init_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package blockchain_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
)
2 changes: 1 addition & 1 deletion cmd/juno/init_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package main_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
)
2 changes: 1 addition & 1 deletion cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import (
"time"

"github.com/NethermindEth/juno/blockchain/networks"
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/jemalloc"
"github.com/NethermindEth/juno/l1/eth"
"github.com/NethermindEth/juno/node"
"github.com/NethermindEth/juno/utils"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
"github.com/NethermindEth/juno/utils/log"
"github.com/NethermindEth/juno/vm"
"github.com/mitchellh/mapstructure"
Expand Down
2 changes: 1 addition & 1 deletion consensus/p2p/validator/init_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package validator

import (
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
)
2 changes: 1 addition & 1 deletion consensus/proposer/init_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package proposer_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
)
2 changes: 1 addition & 1 deletion consensus/tendermint/init_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package tendermint

import (
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
)
2 changes: 1 addition & 1 deletion consensus/walstore/init_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package walstore_test

import (
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
)
42 changes: 21 additions & 21 deletions core/accessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/encoder"
"github.com/NethermindEth/juno/utils/cbor/v1"
"github.com/bits-and-blooms/bloom/v3"
)

Expand Down Expand Up @@ -56,13 +56,13 @@ func GetClass(r db.KeyValueReader, classHash *felt.Felt) (*DeclaredClassDefiniti
var class *DeclaredClassDefinition

err := r.Get(db.ClassKey(classHash), func(data []byte) error {
return encoder.Unmarshal(data, &class)
return cbor.Unmarshal(data, &class)
})
return class, err
}

func WriteClass(w db.KeyValueWriter, classHash *felt.Felt, class *DeclaredClassDefinition) error {
data, err := encoder.Marshal(class)
data, err := cbor.Marshal(class)
if err != nil {
return err
}
Expand Down Expand Up @@ -94,7 +94,7 @@ func DeleteContractDeploymentHeight(w db.KeyValueWriter, addr *felt.Felt) error
func GetStateUpdateByBlockNum(r db.KeyValueReader, blockNum uint64) (*StateUpdate, error) {
var stateUpdate *StateUpdate
err := r.Get(db.StateUpdateByBlockNumKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &stateUpdate)
return cbor.Unmarshal(data, &stateUpdate)
})
if err != nil {
return nil, err
Expand All @@ -103,7 +103,7 @@ func GetStateUpdateByBlockNum(r db.KeyValueReader, blockNum uint64) (*StateUpdat
}

func WriteStateUpdateByBlockNum(w db.KeyValueWriter, blockNum uint64, stateUpdate *StateUpdate) error {
data, err := encoder.Marshal(stateUpdate)
data, err := cbor.Marshal(stateUpdate)
if err != nil {
return err
}
Expand Down Expand Up @@ -206,13 +206,13 @@ func DeleteDeprecatedContractClassHashHistory(
func GetL1Head(r db.KeyValueReader) (L1Head, error) {
var l1Head L1Head
err := r.Get(db.L1Height.Key(), func(data []byte) error {
return encoder.Unmarshal(data, &l1Head)
return cbor.Unmarshal(data, &l1Head)
})
return l1Head, err
}

func WriteL1Head(w db.KeyValueWriter, l1Head *L1Head) error {
data, err := encoder.Marshal(l1Head)
data, err := cbor.Marshal(l1Head)
if err != nil {
return err
}
Expand All @@ -238,7 +238,7 @@ func DeleteBlockHeaderNumberByHash(w db.KeyValueWriter, hash *felt.Felt) error {
}

func WriteBlockHeaderByNumber(w db.KeyValueWriter, header *Header) error {
data, err := encoder.Marshal(header)
data, err := cbor.Marshal(header)
if err != nil {
return err
}
Expand All @@ -252,13 +252,13 @@ func DeleteBlockHeaderByNumber(w db.KeyValueWriter, number uint64) error {
func GetBlockCommitmentByBlockNum(r db.KeyValueReader, blockNum uint64) (*BlockCommitments, error) {
var commitment *BlockCommitments
err := r.Get(db.BlockCommitmentsKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &commitment)
return cbor.Unmarshal(data, &commitment)
})
return commitment, err
}

func WriteBlockCommitment(w db.KeyValueWriter, blockNum uint64, commitment *BlockCommitments) error {
data, err := encoder.Marshal(commitment)
data, err := cbor.Marshal(commitment)
if err != nil {
return err
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func DeleteChainHeight(w db.KeyValueWriter) error {
func GetBlockHeaderByNumber(r db.KeyValueReader, blockNum uint64) (*Header, error) {
var header *Header
err := r.Get(db.BlockHeaderByNumberKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &header)
return cbor.Unmarshal(data, &header)
})
return header, err
}
Expand All @@ -332,7 +332,7 @@ func GetBlockHeaderByNumber(r db.KeyValueReader, blockNum uint64) (*Header, erro
func GetGlobalStateRootByBlockNumber(r db.KeyValueReader, blockNum uint64) (*felt.Felt, error) {
var header headerGlobalStateRootProjection
err := r.Get(db.BlockHeaderByNumberKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &header)
return cbor.Unmarshal(data, &header)
})
if err != nil {
return nil, err
Expand All @@ -348,7 +348,7 @@ func GetGlobalStateRootByBlockNumber(r db.KeyValueReader, blockNum uint64) (*fel
func GetBlockHeaderHashByNumber(r db.KeyValueReader, blockNum uint64) (*felt.Felt, error) {
var header headerHashProjection
err := r.Get(db.BlockHeaderByNumberKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &header)
return cbor.Unmarshal(data, &header)
})
if err != nil {
return nil, err
Expand All @@ -364,7 +364,7 @@ func GetBlockHeaderHashByNumber(r db.KeyValueReader, blockNum uint64) (*felt.Fel
func GetBlockTransactionCountByNumber(r db.KeyValueReader, blockNum uint64) (uint64, error) {
var header headerTransactionCountProjection
err := r.Get(db.BlockHeaderByNumberKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &header)
return cbor.Unmarshal(data, &header)
})
if err != nil {
return 0, err
Expand All @@ -375,7 +375,7 @@ func GetBlockTransactionCountByNumber(r db.KeyValueReader, blockNum uint64) (uin
func GetBlockHeaderTimestampByNumber(r db.KeyValueReader, blockNum uint64) (uint64, error) {
var header headerTimestampProjection
err := r.Get(db.BlockHeaderByNumberKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &header)
return cbor.Unmarshal(data, &header)
})
if err != nil {
return 0, err
Expand All @@ -392,7 +392,7 @@ func GetBlockHeaderEventsBloomByNumber(
) (*bloom.BloomFilter, error) {
var header headerEventsBloomProjection
err := r.Get(db.BlockHeaderByNumberKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &header)
return cbor.Unmarshal(data, &header)
})
if err != nil {
return nil, err
Expand All @@ -409,7 +409,7 @@ func GetBlockHeaderHashAndStateRootByNumber(
) (hash, stateRoot *felt.Felt, err error) {
var header headerHashAndStateRootProjection
err = r.Get(db.BlockHeaderByNumberKey(blockNum), func(data []byte) error {
return encoder.Unmarshal(data, &header)
return cbor.Unmarshal(data, &header)
})
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -646,7 +646,7 @@ func DeleteTransactionsAndReceipts(
func GetAggregatedBloomFilter(r db.KeyValueReader, fromBlock, toBLock uint64) (AggregatedBloomFilter, error) {
var filter AggregatedBloomFilter
err := r.Get(db.AggregatedBloomFilterKey(fromBlock, toBLock), func(data []byte) error {
err := encoder.Unmarshal(data, &filter)
err := cbor.Unmarshal(data, &filter)
return err
})
if err != nil {
Expand All @@ -657,7 +657,7 @@ func GetAggregatedBloomFilter(r db.KeyValueReader, fromBlock, toBLock uint64) (A
}

func WriteAggregatedBloomFilter(w db.KeyValueWriter, filter *AggregatedBloomFilter) error {
enc, err := encoder.Marshal(filter)
enc, err := cbor.Marshal(filter)
if err != nil {
return err
}
Expand All @@ -671,7 +671,7 @@ func DeleteAggregatedBloomFilter(w db.KeyValueWriter, fromBlock, toBlock uint64)
func GetRunningEventFilter(r db.KeyValueReader) (*RunningEventFilter, error) {
var filter RunningEventFilter
err := r.Get(db.RunningEventFilter.Key(), func(data []byte) error {
err := encoder.Unmarshal(data, &filter)
err := cbor.Unmarshal(data, &filter)
return err
})
if err != nil {
Expand All @@ -682,7 +682,7 @@ func GetRunningEventFilter(r db.KeyValueReader) (*RunningEventFilter, error) {
}

func WriteRunningEventFilter(w db.KeyValueWriter, filter *RunningEventFilter) error {
enc, err := encoder.Marshal(filter)
enc, err := cbor.Marshal(filter)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion core/accessors_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/db/pebblev2"
_ "github.com/NethermindEth/juno/encoder/registry"
"github.com/NethermindEth/juno/starknet"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
"github.com/stretchr/testify/require"
)

Expand Down
14 changes: 7 additions & 7 deletions core/accessors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/db/memory"
"github.com/NethermindEth/juno/encoder"
adaptfeeder "github.com/NethermindEth/juno/starknetdata/feeder"
"github.com/NethermindEth/juno/utils/cbor/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -466,7 +466,7 @@ func TestPartialBlockHeaderAccessorsByNumber(t *testing.T) {
t.Run("missing field returns error", func(t *testing.T) {
t.Parallel()
partialHeaderDB := memory.New()
data, err := encoder.Marshal(tt.headerWithoutField)
data, err := cbor.Marshal(tt.headerWithoutField)
require.NoError(t, err)
require.NoError(t, partialHeaderDB.Put(db.BlockHeaderByNumberKey(block.Number), data))

Expand Down Expand Up @@ -503,7 +503,7 @@ func TestGetBlockTransactionCountByNumber(t *testing.T) {
t.Run("header without transaction count returns zero", func(t *testing.T) {
t.Parallel()
partialHeaderDB := memory.New()
data, err := encoder.Marshal(struct {
data, err := cbor.Marshal(struct {
Hash *felt.Felt
}{Hash: block.Hash})
require.NoError(t, err)
Expand Down Expand Up @@ -537,7 +537,7 @@ func TestGetBlockHeaderTimestampByNumber(t *testing.T) {
t.Run("missing field returns error", func(t *testing.T) {
t.Parallel()
partialHeaderDB := memory.New()
data, err := encoder.Marshal(struct{ Hash *felt.Felt }{Hash: block.Hash})
data, err := cbor.Marshal(struct{ Hash *felt.Felt }{Hash: block.Hash})
require.NoError(t, err)
require.NoError(t, partialHeaderDB.Put(db.BlockHeaderByNumberKey(block.Number), data))

Expand Down Expand Up @@ -568,7 +568,7 @@ func TestGetBlockHeaderEventsBloomByNumber(t *testing.T) {
t.Run("missing field returns error", func(t *testing.T) {
t.Parallel()
partialHeaderDB := memory.New()
data, err := encoder.Marshal(struct{ Hash *felt.Felt }{Hash: block.Hash})
data, err := cbor.Marshal(struct{ Hash *felt.Felt }{Hash: block.Hash})
require.NoError(t, err)
require.NoError(t, partialHeaderDB.Put(db.BlockHeaderByNumberKey(block.Number), data))

Expand Down Expand Up @@ -599,7 +599,7 @@ func TestGetBlockHeaderHashAndStateRootByNumber(t *testing.T) {
t.Run("missing hash returns error", func(t *testing.T) {
t.Parallel()
partialHeaderDB := memory.New()
data, err := encoder.Marshal(
data, err := cbor.Marshal(
struct{ GlobalStateRoot *felt.Felt }{GlobalStateRoot: block.GlobalStateRoot},
)
require.NoError(t, err)
Expand All @@ -612,7 +612,7 @@ func TestGetBlockHeaderHashAndStateRootByNumber(t *testing.T) {
t.Run("missing state root returns error", func(t *testing.T) {
t.Parallel()
partialHeaderDB := memory.New()
data, err := encoder.Marshal(struct{ Hash *felt.Felt }{Hash: block.Hash})
data, err := cbor.Marshal(struct{ Hash *felt.Felt }{Hash: block.Hash})
require.NoError(t, err)
require.NoError(t, partialHeaderDB.Put(db.BlockHeaderByNumberKey(block.Number), data))

Expand Down
6 changes: 3 additions & 3 deletions core/block_transaction_serializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"slices"

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/encoder"
"github.com/NethermindEth/juno/utils/cbor/v1"
)

type BlockTransactionsSerializer struct{}

func (BlockTransactionsSerializer) Marshal(value *BlockTransactions) ([]byte, error) {
indexes, err := encoder.Marshal(value.Indexes)
indexes, err := cbor.Marshal(value.Indexes)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func (blockTransactionsPartialSerializer[E, S, T]) UnmarshalPartial(
value *T,
) error {
var blockTransactions BlockTransactions
remaining, err := encoder.UnmarshalFirst(data, &blockTransactions.Indexes)
remaining, err := cbor.UnmarshalFirst(data, &blockTransactions.Indexes)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions core/block_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/indexed"
"github.com/NethermindEth/juno/db/typed/partial"
"github.com/NethermindEth/juno/encoder"
_ "github.com/NethermindEth/juno/encoder/registry"
_ "github.com/NethermindEth/juno/utils/cbor/registry"
"github.com/NethermindEth/juno/utils/cbor/v1"
"github.com/stretchr/testify/require"
)

const transactionCount = 100

func toCborSeq[T any](items []T) iter.Seq2[encoder.RawMessage, error] {
return func(yield func(encoder.RawMessage, error) bool) {
func toCborSeq[T any](items []T) iter.Seq2[cbor.RawMessage, error] {
return func(yield func(cbor.RawMessage, error) bool) {
for _, item := range items {
cbor, err := encoder.Marshal(item)
cbor, err := cbor.Marshal(item)
if err != nil {
yield(nil, err)
return
Expand Down
2 changes: 1 addition & 1 deletion core/block_transaction_txhash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
_ "github.com/NethermindEth/juno/encoder/registry" // register transaction CBOR tags
_ "github.com/NethermindEth/juno/utils/cbor/registry" // register transaction CBOR tags
"github.com/stretchr/testify/require"
)

Expand Down
Loading
Loading