Skip to content

Commit

Permalink
Latest fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan committed Jun 4, 2024
1 parent 0d4e20f commit 1ddbb84
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func (b *Blockchain) Store(block *core.Block, blockCommitments *core.BlockCommit
if err := verifyBlock(txn, block); err != nil {
return err
}
spew.Dump("DUMP", block.Number, stateUpdate)
// spew.Dump("DUMP", block.Number, stateUpdate)

Check failure on line 345 in blockchain/blockchain.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
if err := core.NewState(txn).Update(block.Number, stateUpdate, newClasses); err != nil {
return err
}
Expand Down
30 changes: 15 additions & 15 deletions core/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"fmt"

"github.com/davecgh/go-spew/spew"

"github.com/NethermindEth/juno/core/crypto"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/utils"
Expand Down Expand Up @@ -195,19 +193,21 @@ func post07Hash(b *Block, overrideSeqAddr *felt.Felt) (*felt.Felt, *BlockCommitm
return nil, nil, eErr
}

spew.Dump("HASH VALUES:",
b.Number, // block number
b.GlobalStateRoot, // global state root
seqAddr, // sequencer address
b.Timestamp, // block timestamp
b.TransactionCount, // number of transactions
txCommitment, // transaction commitment
b.EventCount, // number of events
eCommitment, // event commitment
&felt.Zero, // reserved: protocol version
&felt.Zero, // reserved: extra data
b.ParentHash, // parent block hash
&BlockCommitments{TransactionCommitment: txCommitment, EventCommitment: eCommitment})
/*

Check failure on line 196 in core/block.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
spew.Dump("HASH VALUES:",
b.Number, // block number
b.GlobalStateRoot, // global state root
seqAddr, // sequencer address
b.Timestamp, // block timestamp
b.TransactionCount, // number of transactions
txCommitment, // transaction commitment
b.EventCount, // number of events
eCommitment, // event commitment
&felt.Zero, // reserved: protocol version
&felt.Zero, // reserved: extra data
b.ParentHash, // parent block hash
&BlockCommitments{TransactionCommitment: txCommitment, EventCommitment: eCommitment})
*/
// Unlike the pre07Hash computation, we exclude the chain
// id and replace the zero felt with the actual values for:
// - sequencer address
Expand Down
13 changes: 11 additions & 2 deletions p2p/starknet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"io"
"time"

"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
Expand All @@ -14,7 +15,10 @@ import (
"google.golang.org/protobuf/proto"
)

const unmarshalMaxSize = 15 * utils.Megabyte
const (
unmarshalMaxSize = 15 * utils.Megabyte
readTimeout = 5 * time.Second
)

type NewStreamFunc func(ctx context.Context, pids ...protocol.ID) (network.Stream, error)

Expand Down Expand Up @@ -59,6 +63,11 @@ func requestAndReceiveStream[ReqT proto.Message, ResT proto.Message](ctx context
return nil, err
}

err = stream.SetReadDeadline(time.Now().Add(readTimeout))
if err != nil {
return nil, err
}

id := stream.ID()
if err := sendAndCloseWrite(stream, req); err != nil {
log.Errorw("sendAndCloseWrite (stream is not closed)", "err", err, "streamID", id)
Expand All @@ -77,7 +86,7 @@ func requestAndReceiveStream[ReqT proto.Message, ResT proto.Message](ctx context
var zero ResT
res := zero.ProtoReflect().New().Interface()
if err := receiveInto(stream, res); err != nil {
if true || !errors.Is(err, io.EOF) {
if !errors.Is(err, io.EOF) {
log.Debugw("Error while reading from stream", "err", err)
}

Expand Down
31 changes: 20 additions & 11 deletions p2p/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func (s *syncService) start(ctx context.Context) {
break
}

s.log.Infow("Stored Block", "number", b.block.Number, "hash", b.block.Hash.ShortString(), "root",
b.block.GlobalStateRoot.ShortString())
s.log.Infow("Stored Block", "number", b.block.Number, "hash", b.block.Hash.ShortString(),
"root", b.block.GlobalStateRoot.ShortString())
s.listener.OnSyncStepDone(junoSync.OpStore, b.block.Number, time.Since(storeTimer))
}
cancelIteration()
Expand Down Expand Up @@ -253,12 +253,12 @@ func (s *syncService) processSpecBlockParts(
default:
switch p := part.(type) {
case specBlockHeaderAndSigs:
s.log.Debugw("Received Block Header and Signatures", "blockNumber", p.blockNumber())
s.log.Debugw("Received Block Header with signatures", "blockNumber", p.blockNumber())
if _, ok := specBlockHeadersAndSigsM[part.blockNumber()]; !ok {
specBlockHeadersAndSigsM[part.blockNumber()] = p
}
case specTxWithReceipts:
s.log.Debugw("Received Transactions", "blockNumber", p.blockNumber())
s.log.Debugw("Received Transactions with receipts", "blockNumber", p.blockNumber(), "txLen", len(p.txs))
if _, ok := specTransactionsM[part.blockNumber()]; !ok {
specTransactionsM[part.blockNumber()] = p
}
Expand Down Expand Up @@ -370,12 +370,24 @@ func (s *syncService) adaptAndSanityCheckBlock(ctx context.Context, header *spec
coreBlock.EventsBloom = core.EventsBloom(coreBlock.Receipts)

if int(coreBlock.TransactionCount) != len(coreBlock.Transactions) {
spew.Dump("Number of transactions != count", coreBlock)
os.Exit(1)
s.log.Errorw(
"Number of transactions != count",
"transactionCount",
coreBlock.TransactionCount,
"len(transactions)",
len(coreBlock.Transactions),
)
return
}
if int(coreBlock.EventCount) != len(events) {
spew.Dump("Number of events != count", coreBlock, events)
os.Exit(1)
s.log.Errorw(
"Number of events != count",
"eventCount",
coreBlock.EventCount,
"len(events)",
len(events),
)
return
}

h, err := core.BlockHash(coreBlock)
Expand Down Expand Up @@ -405,8 +417,6 @@ func (s *syncService) adaptAndSanityCheckBlock(ctx context.Context, header *spec
// Note: Parts of the State Update are created from Blockchain object as the Store and SanityCheck functions require a State
// Update but there is no such message in P2P.

spew.Dump("Classes", coreBlock.Number, len(classes))

stateReader, stateCloser, err := s.blockchain.StateAtBlockNumber(coreBlock.Number - 1)
if err != nil {
panic(err)
Expand Down Expand Up @@ -668,7 +678,6 @@ func (s *syncService) genEvents(ctx context.Context, blockNumber uint64) (<-chan
number: blockNumber,
events: events,
}:
spew.Dump("Received events from client", len(events), blockNumber)
}
}()
return eventsCh, nil
Expand Down

0 comments on commit 1ddbb84

Please sign in to comment.