Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
weiihann committed Oct 25, 2024
1 parent 3fcef80 commit d0b83e2
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 82 deletions.
15 changes: 8 additions & 7 deletions blockchain/snap_server_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
Expand Down Expand Up @@ -165,22 +166,22 @@ func (b *Blockchain) Close() {
}
}

type Blockchain_Closer struct {
type BlockchainCloser struct {
log utils.SimpleLogger
bc *Blockchain
}

var _ service.Service = (*Blockchain_Closer)(nil)
var _ service.Service = (*BlockchainCloser)(nil)

func NewBlockchainCloser(bc *Blockchain, log utils.SimpleLogger) *Blockchain_Closer {
return &Blockchain_Closer{log, bc}
func NewBlockchainCloser(bc *Blockchain, log utils.SimpleLogger) *BlockchainCloser {
return &BlockchainCloser{log, bc}
}

func (b *Blockchain_Closer) Run(ctx context.Context) error {
b.log.Infow("Blockchain_Closer has started")
func (b *BlockchainCloser) Run(ctx context.Context) error {
b.log.Infow("BlockchainCloser has started")

<-ctx.Done()
b.bc.Close()
b.log.Infow("Blockchain_Closer has stopped")
b.log.Infow("BlockchainCloser has stopped")
return nil
}
2 changes: 1 addition & 1 deletion cmd/juno/juno.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const (
p2pFeederNodeUsage = "EXPERIMENTAL: Run juno as a feeder node which will only sync from feeder gateway and gossip the new" +
" blocks to the network."
p2pPrivateKeyUsage = "EXPERIMENTAL: Hexadecimal representation of a private key on the Ed25519 elliptic curve."
p2pSyncModeUsage = "EXPERIMENTAL: Synchronization mode: 'full' (default), 'snap'"
p2pSyncModeUsage = "EXPERIMENTAL: Synchronisation mode: 'full' (default), 'snap'"
metricsUsage = "Enables the Prometheus metrics endpoint on the default port."
metricsHostUsage = "The interface on which the Prometheus endpoint will listen for requests."
metricsPortUsage = "The port on which the Prometheus endpoint will listen for requests."
Expand Down
6 changes: 3 additions & 3 deletions core/trie/snap_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package trie_test

import (
"fmt"
"github.com/NethermindEth/juno/db/pebble"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/require"
"math"
"testing"

"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/db/pebble"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const trieHeight = 251
Expand Down
18 changes: 12 additions & 6 deletions p2p/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ type Downloader struct {
log utils.SimpleLogger
}

func NewDownloader(isFeeder bool, syncMode SyncMode, p2pHost host.Host, network *utils.Network, bc *blockchain.Blockchain, log utils.SimpleLogger) *Downloader {
func NewDownloader(
isFeeder bool,
syncMode SyncMode,
p2pHost host.Host,
network *utils.Network,
bc *blockchain.Blockchain,
log utils.SimpleLogger,
) *Downloader {
dl := &Downloader{
isFeeder: isFeeder,
log: log,
Expand All @@ -40,10 +47,10 @@ func NewDownloader(isFeeder bool, syncMode SyncMode, p2pHost host.Host, network
return dl
}

func (d *Downloader) Start(ctx context.Context) error {
func (d *Downloader) Start(ctx context.Context) {
// Feeder node doesn't sync using P2P
if d.isFeeder {
return nil
return
}

d.log.Infow("Downloader start", "mode", d.getMode())
Expand All @@ -53,16 +60,15 @@ func (d *Downloader) Start(ctx context.Context) error {
err := d.snapSyncer.Run(ctx)
if err != nil {
d.log.Errorw("Snapsyncer failed to start")
return err
return
}
} else {
d.log.Infow("Syncing is disabled")
return nil
return
}
}

d.baseSyncer.Start(ctx)
return nil
}

func (d *Downloader) getMode() SyncMode {
Expand Down
2 changes: 1 addition & 1 deletion p2p/modes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
type SyncMode uint32

const (
FullSync SyncMode = iota // Synchronize by downloading blocks and applying them to the chain sequentially
FullSync SyncMode = iota // Synchronise by downloading blocks and applying them to the chain sequentially
SnapSync // Download the chain and the state via snap protocol
)

Expand Down
15 changes: 10 additions & 5 deletions p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,17 @@ type Service struct {
synchroniser *SyncService
gossipTracer *gossipTracer

feederNode bool
database db.DB
database db.DB
}

func New(addr, publicAddr, version, peers, privKeyStr string, feederNode bool, syncMode SyncMode, bc *blockchain.Blockchain, snNetwork *utils.Network,
log utils.SimpleLogger, database db.DB,
func New(
addr, publicAddr, version, peers, privKeyStr string,
feederNode bool,
syncMode SyncMode,
bc *blockchain.Blockchain,
snNetwork *utils.Network,
log utils.SimpleLogger,
database db.DB,
) (*Service, error) {
if addr == "" {
// 0.0.0.0/tcp/0 will listen on any interface device and assing a free port.
Expand Down Expand Up @@ -150,7 +155,7 @@ func NewWithHost(p2phost host.Host, peers string, feederNode bool, syncMode Sync

downloader := NewDownloader(feederNode, syncMode, p2phost, snNetwork, bc, log)
handler := starknet.NewHandler(bc, log)
handler.WithSnapsyncSupport(NewSnapServer(bc, log)) // TODO: initialize the snap server in the starknet handler
handler.WithSnapsyncSupport(NewSnapServer(bc, log)) // TODO: initialise the snap server in the starknet handler

s := &Service{
downloader: downloader,
Expand Down
15 changes: 7 additions & 8 deletions p2p/snap_server.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package p2p

import (
"iter"
"math/big"

"github.com/NethermindEth/juno/utils"
"google.golang.org/protobuf/proto"

"github.com/NethermindEth/juno/adapters/core2p2p"
"github.com/NethermindEth/juno/adapters/p2p2core"
"github.com/NethermindEth/juno/blockchain"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/core/trie"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
"github.com/ethereum/go-ethereum/log"
"google.golang.org/protobuf/proto"
"iter"
)

type ContractRangeStreamingResult struct {
Expand Down Expand Up @@ -54,10 +53,10 @@ type yieldFunc = func(proto.Message) bool

var _ SnapServerBlockchain = (*blockchain.Blockchain)(nil)

func NewSnapServer(blockchain SnapServerBlockchain, log utils.SimpleLogger) *snapServer {
func NewSnapServer(bc SnapServerBlockchain, logger utils.SimpleLogger) *snapServer {
return &snapServer{
log: log,
blockchain: blockchain,
log: logger,
blockchain: bc,
}
}

Expand Down Expand Up @@ -285,7 +284,7 @@ func (b *snapServer) GetStorageRange(request *spec.ContractStorageRequest) (iter
var curNodeLimit uint32 = 1000000

// shouldContinue is a return value from the yield function which specify whether the iteration should continue
var shouldContinue bool = true
shouldContinue := true
for _, query := range request.Query {
contractLimit := curNodeLimit

Expand Down
21 changes: 11 additions & 10 deletions p2p/snap_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package p2p
import (
"context"
"fmt"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/crypto"
"github.com/stretchr/testify/require"
"maps"
"testing"

"github.com/NethermindEth/juno/adapters/core2p2p"
"github.com/NethermindEth/juno/adapters/p2p2core"
"github.com/NethermindEth/juno/blockchain"
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/crypto"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/db"
"github.com/NethermindEth/juno/db/pebble"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestClassRange(t *testing.T) {
Expand Down Expand Up @@ -257,8 +257,8 @@ func TestContractRangeByOneContract(t *testing.T) {
storageRoot := p2p2core.AdaptHash(crct.Storage)
assert.Equal(t, test.expectedStorageRoot, storageRoot)

//classHash := p2p2core.AdaptHash(crct.Class)
//assert.Equal(t, test.expectedClassHash, classHash, "classHash", classHash)
//nolint:nolintlint // classHash := p2p2core.AdaptHash(crct.Class)
//nolint:nolintlint // assert.Equal(t, test.expectedClassHash, classHash, "classHash", classHash)

assert.Equal(t, test.expectedNonce, crct.Nonce)

Expand All @@ -280,7 +280,7 @@ func TestContractRangeByOneContract(t *testing.T) {
func TestContractRange_FinMsg_Received(t *testing.T) {
// TODO: Fix the test so it demonstrated FinMsg is returned at the iteration end
t.Skip("Fix me")
var d db.DB = pebble.NewMemTest(t)
d := pebble.NewMemTest(t)
bc := blockchain.New(d, &utils.Sepolia)
defer bc.Close()
server := &snapServer{blockchain: bc}
Expand Down Expand Up @@ -472,6 +472,7 @@ func TestGetClassesByHash(t *testing.T) {
assert.True(t, finMsgReceived)
}

//nolint:gocyclo
func Test__Finding_Storage_Heavy_Contract(t *testing.T) {
var d db.DB
t.Skip("DB snapshot is needed for this test")
Expand All @@ -496,7 +497,7 @@ func Test__Finding_Storage_Heavy_Contract(t *testing.T) {
request := &spec.ContractRangeRequest{
ChunksPerProof: 100,
Start: core2p2p.AdaptAddress(felt.Zero.Clone()),
End: nil, //core2p2p.AdaptAddress(test.address),
End: nil, // core2p2p.AdaptAddress(test.address),
StateRoot: core2p2p.AdaptHash(stateRoot),
}

Expand All @@ -515,8 +516,8 @@ func Test__Finding_Storage_Heavy_Contract(t *testing.T) {
for _, contract := range v.Range.State {
addr := p2p2core.AdaptAddress(contract.Address)
strt := p2p2core.AdaptHash(contract.Storage)
//assert.Equal(t, test.address, addr)
//assert.Equal(t, test.storageRoot, strt)
//nolint:nolintlint // assert.Equal(t, test.address, addr)
//nolint:nolintlint // assert.Equal(t, test.storageRoot, strt)
if !(strt.IsZero() || addr.IsOne()) {
ctso[*addr] = strt
contracts++
Expand Down Expand Up @@ -575,7 +576,7 @@ func Test__Finding_Storage_Heavy_Contract(t *testing.T) {
switch v := resT.GetResponses().(type) {
case *spec.ContractStorageResponse_Storage:
vl := stoCnt[*addr]
//if !ok { stoCnt[*addr] = 0 }
//nolint:nolintlint // if !ok { stoCnt[*addr] = 0 }
stoCnt[*addr] = vl + len(v.Storage.KeyValue)
case *spec.ContractStorageResponse_Fin:
// we expect just one fin message at the iteration end
Expand Down
Loading

0 comments on commit d0b83e2

Please sign in to comment.