Skip to content

Commit

Permalink
linter & formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pnowosie committed Oct 10, 2024
1 parent a33464e commit b936107
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 64 deletions.
24 changes: 14 additions & 10 deletions blockchain/pending.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blockchain

import (
"errors"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/core/trie"
Expand Down Expand Up @@ -69,20 +70,23 @@ func (p *PendingState) Class(classHash *felt.Felt) (*core.DeclaredClass, error)
}

// Note[pnowosie]: Maybe extending StateReader with the following methods was not a good idea?
func (s *PendingState) ClassTrie() (*trie.Trie, func() error, error) {
return nil, nopCloser, featureNotImplemented
func (p *PendingState) ClassTrie() (*trie.Trie, func() error, error) {
return nil, nopCloser, errFeatureNotImplemented
}
func (s *PendingState) StorageTrie() (*trie.Trie, func() error, error) {
return nil, nopCloser, featureNotImplemented

func (p *PendingState) StorageTrie() (*trie.Trie, func() error, error) {
return nil, nopCloser, errFeatureNotImplemented
}
func (s *PendingState) StorageTrieForAddr(*felt.Felt) (*trie.Trie, error) {
return nil, featureNotImplemented

func (p *PendingState) StorageTrieForAddr(*felt.Felt) (*trie.Trie, error) {
return nil, errFeatureNotImplemented
}
func (s *PendingState) StateAndClassRoot() (*felt.Felt, *felt.Felt, error) {
return nil, nil, featureNotImplemented

func (p *PendingState) StateAndClassRoot() (*felt.Felt, *felt.Felt, error) {
return nil, nil, errFeatureNotImplemented
}

var (
featureNotImplemented = errors.New("feature not implemented for a historical state")
nopCloser = func() error { return nil }
errFeatureNotImplemented = errors.New("feature not implemented for a historical state")
nopCloser = func() error { return nil }
)
17 changes: 10 additions & 7 deletions core/state_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package core

import (
"errors"
"github.com/NethermindEth/juno/core/trie"

"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/core/trie"
"github.com/NethermindEth/juno/db"
)

Expand Down Expand Up @@ -91,19 +91,22 @@ func (s *stateSnapshot) Class(classHash *felt.Felt) (*DeclaredClass, error) {

// Note[pnowosie]: Maybe extending StateReader with the following methods was not a good idea?
func (s *stateSnapshot) ClassTrie() (*trie.Trie, func() error, error) {
return nil, nopCloser, featureNotImplemented
return nil, nopCloser, errFeatureNotImplemented
}

func (s *stateSnapshot) StorageTrie() (*trie.Trie, func() error, error) {
return nil, nopCloser, featureNotImplemented
return nil, nopCloser, errFeatureNotImplemented
}

func (s *stateSnapshot) StorageTrieForAddr(*felt.Felt) (*trie.Trie, error) {
return nil, featureNotImplemented
return nil, errFeatureNotImplemented
}

func (s *stateSnapshot) StateAndClassRoot() (*felt.Felt, *felt.Felt, error) {
return nil, nil, featureNotImplemented
return nil, nil, errFeatureNotImplemented
}

var (
featureNotImplemented = errors.New("feature not implemented for a historical state")
nopCloser = func() error { return nil }
errFeatureNotImplemented = errors.New("feature not implemented for a historical state")
nopCloser = func() error { return nil }
)
5 changes: 0 additions & 5 deletions rpc/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package rpc

import (
"errors"
"fmt"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
Expand Down Expand Up @@ -237,10 +236,6 @@ func getProof(t *trie.Trie, elt *felt.Felt) ([]*HashToNode, error) {
feltBytes := elt.Bytes()
key := trie.NewKey(core.ContractStorageTrieHeight, feltBytes[:])
nodes, err := trie.GetProof(&key, t)
for i, n := range nodes {
fmt.Printf("[%d]", i)
n.PrettyPrint()
}
if err != nil {
return nil, err
}
Expand Down
42 changes: 0 additions & 42 deletions rpc/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,6 @@ func TestStorageProof(t *testing.T) {
require.NoError(t, err)
require.NoError(t, tempTrie.Commit())

// TODO[pnowosie]: There is smth wrong with proof verification, see `Trie proofs sanity check` test
//verifyIf := func(proof []*rpc.HashToNode, key *felt.Felt, value *felt.Felt) bool {
// root, err := tempTrie.Root()
// require.NoError(t, err)
// fmt.Println("root", root)
//
// pnodes := []trie.ProofNode{}
// for _, hn := range proof {
// pnodes = append(pnodes, NodeToProofNode(hn))
// }
//
// kbs := key.Bytes()
// kkey := trie.NewKey(251, kbs[:])
// result := trie.VerifyProof(root, &kkey, value, pnodes, tempTrie.HashFunc())
// fmt.Println("result", result)
//
// return result
//}

mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

Expand Down Expand Up @@ -312,26 +293,3 @@ func emptyTrie(t *testing.T) *trie.Trie {
require.NoError(t, err)
return tempTrie
}

func NodeToProofNode(hn *rpc.HashToNode) trie.ProofNode {
var proofNode trie.ProofNode

switch pnode := hn.Node.(type) {
case *rpc.MerkleEdgeNode:
pbs := pnode.Path.Bytes()
path := trie.NewKey(uint8(pnode.Length), pbs[:])
proofNode = &trie.Edge{
Path: &path,
Child: pnode.Child,
}
case *rpc.MerkleBinaryNode:
proofNode = &trie.Binary{
LeftHash: pnode.Left,
RightHash: pnode.Right,
}
default:
panic(fmt.Errorf("unsupported node type %T", pnode))
}

return proofNode
}

0 comments on commit b936107

Please sign in to comment.