Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec update #1858

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Spec update #1858

wants to merge 20 commits into from

Conversation

kirugan
Copy link
Contributor

@kirugan kirugan commented May 6, 2024

Issue #1688

Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.40%. Comparing base (4e6dcd7) to head (8670ea7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1858      +/-   ##
==========================================
- Coverage   75.43%   75.40%   -0.03%     
==========================================
  Files          97       97              
  Lines        8342     8340       -2     
==========================================
- Hits         6293     6289       -4     
- Misses       1519     1520       +1     
- Partials      530      531       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kirugan kirugan marked this pull request as ready for review June 5, 2024 11:55

s.log.Infow("Start Pipeline", "Random node height", randHeight, "Current height", nextHeight-1, "Start", nextHeight, "End",
nextHeight+min(blockBehind, maxBlocks))
s.log.Infow("Start Pipeline", "Random node height", randHeight, "Current height", nextHeight-1, "Start", nextHeight)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

randHeight will no longer be used, so it will always be 0. Do we need to remove it?

Would like to ask, if we no longer choose a random peer and sync with it, how does the current implementation choose its peers?

I would also recommend adding some sort of check such that if no peers are available, then don't bother trying to sync at all, perhaps retry every certain interval. This is because I've been getting a lot of these messages while attempting to sync when there are no peers:

23:53:22.370 14/06/2024 +08:00	ERROR	p2p/sync.go:79	Failed to get block headers parts{"err": "no peers available"}
github.com/NethermindEth/juno/p2p.(*syncService).start
	/Users/han/Documents/Codes/juno/p2p/sync.go:79
github.com/NethermindEth/juno/p2p.(*Service).Run
	/Users/han/Documents/Codes/juno/p2p/p2p.go:212
github.com/NethermindEth/juno/node.(*Node).Run.func3
	/Users/han/Documents/Codes/juno/node/node.go:353
github.com/sourcegraph/conc/panics.(*Catcher).Try
	/Users/han/go/1.22.4/pkg/mod/github.com/sourcegraph/conc@v0.3.0/panics/panics.go:23
github.com/sourcegraph/conc.(*WaitGroup).Go.func1
	/Users/han/go/1.22.4/pkg/mod/github.com/sourcegraph/conc@v0.3.0/waitgroup.go:32

Copy link
Contributor

@IronGauntlets IronGauntlets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some todo I think we can work but we can complete them in a separate PR. Also, there is some unused code which should be removed (such as randHeight and onBlockBodiesRequest.

In general, the PR looks good, I have left some questions and suggestions.

Here are some of my thoughts on the sync process:

  • Good first step towards using the new conventions.
  • To fully utilise the Stream convention we should request more than 1 block parts, however, this would complicate the sync process a lot.
  • We should try to benchmark the current sync process so that it can be compared to any new ones in the future. It may be the case that the simple one is more efficient.

GasPrice: AdaptFelt(header.GasPrice),
GasPriceFri: AdaptUint128(header.GasPrice),
Signatures: utils.Map(header.Signatures, AdaptSignature),
// todo(kirill) set these fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming these fields will have to be set after 0.13.2 update, right?

Comment on lines +66 to +67
default:
panic(fmt.Errorf("unknown L1DAMode %v", da))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: given the data is coming from our db I think we can assume it will be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I can change it to panic("unreachable") but without it won't work because switch must have default case that either panic or return smth.

Comment on lines +49 to +58
func AdaptUint128(f *felt.Felt) *spec.Uint128 {
// bits represents value in little endian byte order
// i.e. first is least significant byte
bits := f.Bits()
// todo what should we do with the rest of bytes?
return &spec.Uint128{
Low: bits[0],
High: bits[1],
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think they are not using felt to reduce the size of the message?.

Having 128 bits to represent a number seems a bit weird, not sure why uint64 is not enough.

// todo what should we do with the rest of bytes?
I don't think the rest of the words would be used as this is only used for Gas/DataGas prices

func adaptDeployTransaction(tx *core.DeployTransaction) *spec.Transaction_Deploy_ {
return &spec.Transaction_Deploy_{
Deploy: &spec.Transaction_Deploy{
ClassHash: AdaptHash(tx.ClassHash),
AddressSalt: AdaptFelt(tx.ContractAddressSalt),
Calldata: AdaptFeltSlice(tx.ConstructorCallData),
Version: 0, // todo(kirill) remove field from spec? tx is deprecated so no future versions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a good idea

Comment on lines +23 to +24
adaptEP := func(points []*spec.EntryPoint) []core.EntryPoint {
// usage of NonNilSlice is essential because relevant core class fields are non nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So can EntryPoints be empty or do you think there is a bug in Pathfinder?

Comment on lines +66 to +70
err = stream.SetReadDeadline(time.Now().Add(readTimeout))
if err != nil {
return nil, err
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which issue caused you to introduce a timeout?

Comment on lines +336 to +340
if !coreBlock.Hash.Equal(h) {
spew.Dump("Receipts number:", coreBlock.Receipts, events)
spew.Dump("Hash mismtach", coreBlock)
os.Exit(1)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider removing this debug code?

Comment on lines +161 to +164
fin := newFin(&spec.BlockBodiesResponse{
BodyMessage: &spec.BlockBodiesResponse_Fin{},
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why we need to keep this function. let's delete it.

log utils.SimpleLogger

ctx context.Context
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have always read that storing a context is not a good idea.

I can see that it is used in different protocol handlers protocol handlers when creating a stream. However, we could pass context from the setProtocolHanderls() and avoid this storage. The cancel function can be set when HeadersHandler() or any other handler function is called.

(I would be happy if this change could be made in a separate PR)

Comment on lines +499 to +506
for _, msg := range messages {
// push generated msg to caller
if !yield(msg) {
// if caller is not interested in remaining data (example: connection to a peer is closed) exit
// note that in this case we won't send finMsg
return
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, this is the only part which is different from processIterationRequest. Do you think we could pass this as a function and reduce the duplication?

@kirugan
Copy link
Contributor Author

kirugan commented Jun 17, 2024

There is some todo I think we can work but we can complete them in a separate PR. Also, there is some unused code which should be removed (such as randHeight and onBlockBodiesRequest.

In general, the PR looks good, I have left some questions and suggestions.

Here are some of my thoughts on the sync process:

* Good first step towards using the new conventions.

* To fully utilise the Stream convention we should request more than 1 block parts, however, this would complicate the sync process a lot.

* We should try to benchmark the current sync process so that it can be compared to any new ones in the future. It may be the case that the simple one is more efficient.

Totally agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants