Skip to content

Commit

Permalink
formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
pnowosie committed Aug 1, 2024
1 parent f6e7266 commit b2321f6
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 67 deletions.
1 change: 0 additions & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
heightBin := core.MarshalBlockNumber(block.Number)
return txn.Set(db.ChainHeight.Key(), heightBin)
})

if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions blockchain/snap_server_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package blockchain
import (
"errors"
"fmt"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
Expand All @@ -23,7 +24,6 @@ func (b *Blockchain) GetStateForStateRoot(stateRoot *felt.Felt) (*core.State, er
snapshot, err := b.findSnapshotMatching(func(record *snapshotRecord) bool {
return record.stateRoot.Equal(stateRoot)
})

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -66,7 +66,6 @@ func (b *Blockchain) GetClasses(felts []*felt.Felt) ([]core.Class, error) {

return nil
})

if err != nil {
return nil, err
}
Expand All @@ -91,7 +90,6 @@ func (b *Blockchain) GetDClasses(felts []*felt.Felt) ([]*core.DeclaredClass, err

return nil
})

if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions core/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"errors"

"github.com/NethermindEth/juno/core/crypto"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/core/trie"
Expand Down
15 changes: 9 additions & 6 deletions core/crypto/poseidon_hash.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package crypto

import (
"sync"

Check failure on line 5 in core/crypto/poseidon_hash.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
lru "github.com/hashicorp/golang-lru"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"sync"

Check failure on line 9 in core/crypto/poseidon_hash.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"github.com/NethermindEth/juno/core/felt"
)
Expand Down Expand Up @@ -56,11 +57,13 @@ func HadesPermutation(state []felt.Felt) {

var two = new(felt.Felt).SetUint64(2)

var lruPoseidon, _ = lru.New(10000000)
var poseidonCache = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "juno_poseidon",
Help: "pederson",
}, []string{"hit"})
var (
lruPoseidon, _ = lru.New(10000000)
poseidonCache = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "juno_poseidon",
Help: "pederson",
}, []string{"hit"})
)

type lruKey struct {
x felt.Felt
Expand Down
5 changes: 3 additions & 2 deletions core/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"encoding/binary"
"errors"
"fmt"
"runtime"
"sort"

"github.com/NethermindEth/juno/core/crypto"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/core/trie"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/encoder"
"github.com/sourcegraph/conc/pool"
"runtime"
"sort"
)

const globalTrieHeight = 251
Expand Down
5 changes: 3 additions & 2 deletions core/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ package trie
import (
"errors"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"math/big"
"strings"
"sync"

"github.com/prometheus/client_golang/prometheus"

Check failure on line 11 in core/trie/trie.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default (gci)
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/NethermindEth/juno/core/crypto"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
Expand Down
34 changes: 5 additions & 29 deletions sync/snap_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package sync
import (
"context"
"errors"
"math/big"

"github.com/NethermindEth/juno/adapters/core2p2p"
"github.com/NethermindEth/juno/adapters/p2p2core"
"github.com/NethermindEth/juno/blockchain"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/NethermindEth/juno/core/trie"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils/iter"
"math/big"
)

type ContractRangeStreamingResult struct {
Expand Down Expand Up @@ -58,9 +59,7 @@ type snapServer struct {
blockchain SnapServerBlockchain
}

var (
_ SnapServerBlockchain = &blockchain.Blockchain{}
)
var _ SnapServerBlockchain = &blockchain.Blockchain{}

const maxNodePerRequest = 1024 * 1024 // I just want it to process faster
func determineMaxNodes(specifiedMaxNodes uint64) uint64 {
Expand Down Expand Up @@ -97,16 +96,6 @@ func (b *snapServer) GetClassRange(ctx context.Context, request *spec.ClassRange
}
defer classCloser()

Check failure on line 97 in sync/snap_server.go

View workflow job for this annotation

GitHub Actions / lint

Error return value is not checked (errcheck)

actualRoot, err := ctrie.Root()
if err != nil {
yield(nil, err)
return
}
if !actualRoot.Equal(classRoot) {
yield(nil, errors.New("class trie root is not equal to the one in state root"))
return
}

startAddr := p2p2core.AdaptHash(request.Start)
limitAddr := p2p2core.AdaptHash(request.End)
if limitAddr.IsZero() {
Expand Down Expand Up @@ -184,16 +173,6 @@ func (b *snapServer) GetContractRange(ctx context.Context, request *spec.Contrac
}
defer scloser()

actualRoot, err := strie.Root()
if err != nil {
yield(nil, err)
return
}
if !actualRoot.Equal(contractRoot) {
yield(nil, errors.New("contract trie root is not equal to the one in state root"))
return
}

startAddr := p2p2core.AdaptAddress(request.Start)
limitAddr := p2p2core.AdaptAddress(request.End)
states := []*spec.ContractState{}
Expand Down Expand Up @@ -229,7 +208,6 @@ func (b *snapServer) GetContractRange(ctx context.Context, request *spec.Contrac
})
return nil
})

if err != nil {
yield(nil, err)
return
Expand Down Expand Up @@ -291,7 +269,6 @@ func (b *snapServer) GetStorageRange(ctx context.Context, request *StorageRangeR
RangeProof: Core2P2pProof(proofs),
}, nil)
})

if err != nil {
yield(nil, err)
return
Expand Down Expand Up @@ -326,8 +303,8 @@ func (b *snapServer) handleStorageRangeRequest(
request *spec.StorageRangeQuery,
maxChunkPerProof uint64,
nodeLimit uint64,
yield func([]*spec.ContractStoredValue, []trie.ProofNode)) (int64, error) {

yield func([]*spec.ContractStoredValue, []trie.ProofNode),
) (int64, error) {
totalSent := int64(0)
finished := false
startAddr := p2p2core.AdaptFelt(request.Start.Key)
Expand Down Expand Up @@ -415,7 +392,6 @@ func iterateWithLimit(
}
return true, nil
})

if err != nil {
return nil, finished, err
}
Expand Down
16 changes: 9 additions & 7 deletions sync/snap_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package sync
import (
"context"
"fmt"
"testing"

"github.com/NethermindEth/juno/adapters/core2p2p"
"github.com/NethermindEth/juno/adapters/p2p2core"
"github.com/NethermindEth/juno/blockchain"
Expand All @@ -12,7 +14,6 @@ import (
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
"testing"
)

func TestClassRange(t *testing.T) {
Expand Down Expand Up @@ -130,7 +131,8 @@ func TestContractStorageRange(t *testing.T) {
{
address: feltFromString("0x3deecdb26a60e4c062d5bd98ab37f72ea2acc37f28dae6923359627ebde9"),
storageRoot: feltFromString("0x276edbc91a945d11645ba0b8298c7d657e554d06ab2bb765cbc44d61fa01fd5"),
expectedLeaves: 1},
expectedLeaves: 1,
},
{
address: feltFromString("0x5de00d3720421ab00fdbc47d33d253605c1ac226ab1a0d267f7d57e23305"),
storageRoot: feltFromString("0x5eebb2c6722d321469cb662260c5171c9f6f67b9a625c9c9ab56b0a4631b0fe"),
Expand All @@ -141,7 +143,7 @@ func TestContractStorageRange(t *testing.T) {
storageRoot: feltFromString("0x60dccd54f4956147c6a499b71579820d181e22d5e9c430fd5953f861ca7727e"),
expectedLeaves: 4,
},
//TODO: long root calc - comment when root is verified
// TODO: long root calc - comment when root is verified
{
address: feltFromString("0x000000000000000000000000000000000000000000000000000000000001"),
storageRoot: feltFromString("0x241ce4b3da62e79caf008c66ca5f3232e9628af90ba3fcb70974d0b8b30cd8b"),
Expand Down Expand Up @@ -176,7 +178,7 @@ func TestContractStorageRange(t *testing.T) {
StateRoot: stateRoot,
ChunkPerProof: 100,
Queries: []*spec.StorageRangeQuery{
&spec.StorageRangeQuery{
{
Address: core2p2p.AdaptAddress(test.address),
Start: &spec.StorageLeafQuery{
ContractStorageRoot: core2p2p.AdaptHash(test.storageRoot),
Expand Down Expand Up @@ -208,9 +210,9 @@ func TestContractStorageRange(t *testing.T) {
fmt.Println("Address:", test.address, "storage length:", len(keys))
assert.Equal(t, test.expectedLeaves, len(keys))

//hasMore, err := VerifyTrie(test.storageRoot, keys, vals, nil, ClassTrieHeight, crypto.Poseidon)
//assert.NoError(t, err)
//assert.False(t, hasMore)
// hasMore, err := VerifyTrie(test.storageRoot, keys, vals, nil, ClassTrieHeight, crypto.Poseidon)
// assert.NoError(t, err)
// assert.False(t, hasMore)
})
}
}
16 changes: 9 additions & 7 deletions sync/snapsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"context"
"errors"
"fmt"
big "math/big"
"sync"
"sync/atomic"
"time"

"github.com/NethermindEth/juno/adapters/core2p2p"
"github.com/NethermindEth/juno/adapters/p2p2core"
"github.com/NethermindEth/juno/core/crypto"
Expand All @@ -14,10 +19,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"golang.org/x/sync/errgroup"
big "math/big"
"sync"
"sync/atomic"
"time"

"github.com/NethermindEth/juno/blockchain"
"github.com/NethermindEth/juno/core"
Expand Down Expand Up @@ -547,8 +548,10 @@ func VerifyGlobalStateRoot(globalStateRoot *felt.Felt, classRoot *felt.Felt, sto
return nil
}

const ClassTrieHeight = 251
const ContractTrieDepth = 251
const (
ClassTrieHeight = 251
ContractTrieDepth = 251
)

func CalculateClassHash(cls core.Class) *felt.Felt {
hash, err := cls.Hash()
Expand Down Expand Up @@ -939,7 +942,6 @@ func (s *SnapSyncher) ApplyStateUpdate(blockNumber uint64) error {
}

func (s *SnapSyncher) runFetchClassJob(ctx context.Context) error {

keyBatches := make([]*felt.Felt, 0)
for {

Expand Down
20 changes: 10 additions & 10 deletions sync/snapsyncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"encoding/hex"
"errors"
"github.com/NethermindEth/juno/encoder"
"github.com/prometheus/client_golang/prometheus/promhttp"
"math/big"
"net/http"
"os"
"testing"
"time"

"github.com/NethermindEth/juno/encoder"
"github.com/prometheus/client_golang/prometheus/promhttp"

"github.com/NethermindEth/juno/blockchain"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
Expand Down Expand Up @@ -74,7 +75,6 @@ func V1ClassFromString(key, bytes string) (*felt.Felt, *felt.Felt, core.Class, e
}

func TestSnapOfflineCopy(t *testing.T) {

scenarios := []struct {
name string
scenario func(t *testing.T, bc *blockchain.Blockchain) error
Expand Down Expand Up @@ -343,37 +343,37 @@ func (l localStarknetData) BlockLatest(ctx context.Context) (*core.Block, error)
}

func (l localStarknetData) BlockPending(ctx context.Context) (*core.Block, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (l localStarknetData) Transaction(ctx context.Context, transactionHash *felt.Felt) (core.Transaction, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (l localStarknetData) Class(ctx context.Context, classHash *felt.Felt) (core.Class, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (l localStarknetData) StateUpdate(ctx context.Context, blockNumber uint64) (*core.StateUpdate, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (l localStarknetData) StateUpdatePending(ctx context.Context) (*core.StateUpdate, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (l localStarknetData) StateUpdateWithBlock(ctx context.Context, blockNumber uint64) (*core.StateUpdate, *core.Block, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

func (l localStarknetData) StateUpdatePendingWithBlock(ctx context.Context) (*core.StateUpdate, *core.Block, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}

Expand Down

0 comments on commit b2321f6

Please sign in to comment.