-
Notifications
You must be signed in to change notification settings - Fork 198
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
implement logic to build genesis state for the sequencer #2371
base: main
Are you sure you want to change the base?
Conversation
wip - fix test fix stuff
fb11e07
to
459db5d
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2371 +/- ##
==========================================
- Coverage 75.20% 75.08% -0.13%
==========================================
Files 140 141 +1
Lines 16862 17174 +312
==========================================
+ Hits 12681 12895 +214
- Misses 3353 3426 +73
- Partials 828 853 +25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have finished reviewing everything except vm logic. Everything is good, just small changes and questions. I'll continue reviewing vm logic.
Even though the PR is approved, I'm adding the |
Relevant blockifier PR #2397 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just putting a blocking comment here to make sure it doesn't get merged by accident during this release process.
I would also like to give a final review before moving ahead with the PR.
vm/state.go
Outdated
addrFelt := makeFeltFromPtr(addr) | ||
keyFelt := makeFeltFromPtr(key) | ||
valueFelt := makeFeltFromPtr(value) | ||
state := context.state.(StateReadWriter) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a good design. The issues are:
- Runtime Type Checking: The code relies on runtime type assertions (
context.state.(StateReadWriter)
) which can panic if the assertion fails. - Implicit Behavior: The code's behavior changes based on whether the state implements write methods, but this isn't immediately obvious from function signatures.
I'd suggest changing state core.StateReader
to an interface defined directly in the vm
package. It's usually a good practice to define interfaces in the consumer package (in this case, vm
) rather than the implementor package (in this case, core
).
so something like:
package vm
type State interface {
StateReader
StateWriter
}
type StateReader interface {
ContractClassHash(addr *felt.Felt) (*felt.Felt, error)
ContractNonce(addr *felt.Felt) (*felt.Felt, error)
ContractStorage(addr, key *felt.Felt) (*felt.Felt, error)
Class(classHash *felt.Felt) (*DeclaredClass, error)
}
type StateWriter interface {
SetStorage(contractAddress, storageKey, value *felt.Felt) error
IncrementNonce(contractAddress *felt.Felt) error
SetClassHash(contractAddress, classHash *felt.Felt) error
SetContractClass(classHash *felt.Felt, contractClass core.Class) error
SetCompiledClassHash(classHash *felt.Felt, compiledClassHash *felt.Felt) error
}
type callContext struct {
// state that the call is running on
state State
...other fields
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, you're right! After thinking about it a little more, I think we can completely remove the setter functions, and just extract the required state changes by returning the state-diff
from blockifier. This simplifies a lot of the code, and saves blockifier having to call Go-code whenever something is set. Also, since vm.Call()
is primarily executed when handling RPC requests, I added a flag (returnStateDiff
) to indicate that the blockifier should only return the state-diff when requested (ie when we call genesis.GenesisStateDiff()
, which is only done when running Juno as a sequencer)
This PR implements the
genesis
pkg that builds astate diff
from declaring classes, deploying contracts and invoking functions. The sequencer can then commit thisstate diff
to state, so that upon startup, a set of account contracts have already been deployed and funded (it is not possible to achieve this from an empty state by submitting transactions, since Starknet requires accounts to be funded to perform any actions on the state - originally this wasn't a requirement in Starknet). This is particularly useful as it allows users to start the sequencer with any number of accounts pre-deployed, and pre-funded, etc, and opens up the possibility of using Juno as a devnetIn essence: