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

Rianhughes/sequencer #1863

Closed
wants to merge 85 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
dd87d7c
Add a persistent mempool implementation
omerfirmak Dec 6, 2023
28fe471
Define Genesis state
rianhughes Dec 8, 2023
7d54eb9
Add barebones builder with mempool validation facilities
omerfirmak Dec 8, 2023
f7b3017
++
omerfirmak Jan 15, 2024
b288c28
Add and implement the StateReadWriter interface
joshklop Dec 11, 2023
6a8201a
Enable the `JunoStateReader` to write (#1541)
joshklop Dec 14, 2023
d9479e8
Combine the blockbuilder and builder packages
joshklop Dec 14, 2023
03f6999
Allow user of pending state to obtain underlying state diff
joshklop Dec 15, 2023
69486fa
build Genesis state
rianhughes Dec 21, 2023
e1d9ada
Move state root verification to blockchain
omerfirmak Dec 27, 2023
19db715
Implement blockchain.Finalize
omerfirmak Dec 27, 2023
c1167b1
fix tests and make state writeable
May 14, 2024
b7ba978
Builder signs blocks (#1608)
joshklop Dec 28, 2023
0699cba
Add Cairo1 support in Genesis state
omerfirmak Dec 29, 2023
b4c2cee
Add mempool.Wait
joshklop Dec 29, 2023
0348d74
Allow Juno to start in sequencer mode
omerfirmak Dec 28, 2023
c732588
fix test
May 14, 2024
e384744
Add blockchain.InitGenesisState
omerfirmak Jan 1, 2024
d3c8825
Initialize genesis state at node startup
omerfirmak Jan 1, 2024
f143041
Add transactions to mempool
omerfirmak Jan 1, 2024
c0eccbc
Convert traces to receipts
joshklop Dec 22, 2023
3f9a0cf
Add test to ensure genesis state is immutable
joshklop Jan 2, 2024
5b0effb
Build genesis state with 0 timestamp
omerfirmak Jan 3, 2024
d35fe83
fix small breaks
May 14, 2024
0b287d3
Allow access to updated declared class set as well
omerfirmak Jan 3, 2024
620e779
Use a genesis block in addition to genesis state
joshklop Jan 4, 2024
4cdf059
Permit sequencer mode without a genesis file
joshklop Jan 9, 2024
77e20d3
Remove unused ChainID field from genesis config (#1652)
joshklop Jan 12, 2024
0948cb9
Fix lints
joshklop Jan 15, 2024
ceada76
Build empty blocks
joshklop Jan 9, 2024
29d3cb1
Add txns to blocks
omerfirmak Jan 3, 2024
dc943cb
Allow felts to be used as map keys in genesis file
omerfirmak Jan 4, 2024
7faaaf0
Separate PendingStateWriter
omerfirmak Jan 16, 2024
ab75ca4
Allow contracts to be deployed on genesis without a constructor call
omerfirmak Jan 16, 2024
55f12b9
Implement L1->L2 messaging (#1596)
joshklop Jan 17, 2024
8c3a6b2
fix lint
May 14, 2024
65dd866
addTransction relays to sequencer
May 15, 2024
f97b848
add flag for blocktime
May 15, 2024
1633071
bootstrap
May 15, 2024
856a438
??
Jun 5, 2024
59c1558
genesis test update, impl add_visited_pcs - wip
rianhughes Jun 28, 2024
7360530
wip
rianhughes Jun 28, 2024
26dbb4f
deploy strk token and transfer an account some tokens - working!
rianhughes Jun 28, 2024
1e27167
fund multiple accounts
rianhughes Jun 30, 2024
ced5980
refactor - deploy+prefund accounts
rianhughes Jun 30, 2024
1045a5b
add flag to run sequencer using prefunded accounts
rianhughes Jun 30, 2024
b3f75dd
Merge branch 'main' into rianhughes/seq2
Jul 1, 2024
c4f2bda
test builder - account has no balance?
Jul 1, 2024
c5697c3
test wip - problem with add_visited_pcs?
Jul 2, 2024
d223d06
predployed acconts have tokens! - add max steps to seq
Jul 2, 2024
431dde7
test - invoke transactions now pass, but no state updates??. Also, re…
Jul 2, 2024
bd0d133
invoke transactions / state changes now work!
Jul 2, 2024
c15a8bc
Merge branch 'main' into rianhughes/seq2
Jul 3, 2024
6ada93a
implement builder test for prefunded accounts
Jul 4, 2024
69c7b0b
fix lint
Jul 4, 2024
648c15c
add test for two txns in same lbokc
Jul 4, 2024
b2e041c
fix errors - default seq now runs
Jul 4, 2024
80ef4e4
add sequencer network - still not sure where 0x1 state change is comi…
Jul 4, 2024
eeba462
Merge branch 'main' into rianhughes/seq2
rianhughes Jul 5, 2024
a2c3d33
fix default config test
Jul 5, 2024
4656c31
fix panic from rerunning sequencer
Jul 5, 2024
7c951aa
fix ci/cd err?
Jul 5, 2024
04c4084
add another make command for sequencer
Jul 5, 2024
4014579
fix cicd err?
Jul 5, 2024
580708a
push prefunding and redploying to genesis file
Jul 15, 2024
5fd6812
Merge branch 'main' into rianhughes/seq2
Jul 15, 2024
8aea86c
Merge branch 'main' into rianhughes/seq2
rianhughes Jul 15, 2024
b761656
Merge branch 'main' into rianhughes/seq2
rianhughes Jul 15, 2024
7264688
fix TestPrefundedAccounts
Jul 15, 2024
c3e5cb9
fix make file
Jul 15, 2024
2f30bce
fix seq test - trace return
Jul 15, 2024
8a98424
remove redundant test
Jul 16, 2024
a259f42
Merge branch 'main' into rianhughes/seq2
rianhughes Jul 16, 2024
678ad79
fix lint
Jul 16, 2024
4231f6c
merge state diffs + test with 2 txns in same block
Jul 16, 2024
4e150fa
merge state proofs + update test (2 txns single block)
Jul 16, 2024
3c60513
remove assertions on strk mint
Jul 17, 2024
9cfcb4d
remove caller address from vm
Jul 17, 2024
0fd409a
Merge branch 'main' into rianhughes/seq2
Jul 17, 2024
2158138
Merge branch 'main' into rianhughes/seq2
rianhughes Jul 17, 2024
29cc144
remove unneeded test
Jul 17, 2024
6cb470a
format
Jul 17, 2024
5d1ebb7
remove unneeded flag
Jul 17, 2024
7b32c01
tidy test
Jul 17, 2024
758f30b
change test blocktime - only fails on cicd
Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ courtney/
__pycache__/
config/
.envrc
seq-db/

# pyenv
.python-version
Expand Down
39 changes: 32 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,37 @@ node3:
--p2p-private-key="54a695e2a5d5717d5ba8730efcafe6f17251a1955733cffc55a4085fbf7f5d2c1b4009314092069ef7ca9b364ce3eb3072531c64dfb2799c6bad76720a5bdff0" \
--metrics-port=9093

sequencer:
./build/juno \
--http \
--http-port=6060 \
--http-host=0.0.0.0 \
--db-path=./seq-db \
--log-level=debug \
--seq-enable \
--seq-block-time=1 \
--network sequencer \
--rpc-call-max-steps=4123000

sequencer-with-accounts:
./build/juno \
--http \
--http-port=6060 \
--http-host=0.0.0.0 \
--db-path=./seq-db \
--log-level=debug \
--seq-enable \
--seq-block-time=1 \
--network sequencer \
--genesis-file "./genesis/genesis_prefund_accounts.json" \
--rpc-call-max-steps=4123000

pathfinder: juno-cached
./build/juno \
--network=sepolia \
--log-level=debug \
--db-path=./p2p-dbs/node-pathfinder \
--p2p \
--p2p-peers=/ip4/127.0.0.1/tcp/8888/p2p/12D3KooWF1JrZWQoBiBSjsFSuLbDiDvqcmJQRLaFQLmpVkHA9duk \
--p2p-private-key="54a695e2a5d5717d5ba8730efcafe6f17251a1955733cffc55a4085fbf7f5d2c1b4009314092069ef7ca9b364ce3eb3072531c64dfb2799c6bad76720a5bdff0" \
--metrics-port=9094
--network=sepolia \
--log-level=debug \
--db-path=./p2p-dbs/node-pathfinder \
--p2p \
--p2p-peers=/ip4/127.0.0.1/tcp/8888/p2p/12D3KooWF1JrZWQoBiBSjsFSuLbDiDvqcmJQRLaFQLmpVkHA9duk \
--p2p-private-key="54a695e2a5d5717d5ba8730efcafe6f17251a1955733cffc55a4085fbf7f5d2c1b4009314092069ef7ca9b364ce3eb3072531c64dfb2799c6bad76720a5bdff0" \
--metrics-port=9094
159 changes: 130 additions & 29 deletions blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,40 +337,51 @@
stateUpdate *core.StateUpdate, newClasses map[felt.Felt]core.Class,
) error {
return b.database.Update(func(txn db.Transaction) error {
if err := verifyBlock(txn, block); err != nil {
if err := b.storeBlock(txn, block, blockCommitments); err != nil {
return err
}
if err := core.NewState(txn).Update(block.Number, stateUpdate, newClasses); err != nil {

state := core.NewState(txn)
if err := state.Update(block.Number, stateUpdate.StateDiff, newClasses); err != nil {
return err
}
if err := StoreBlockHeader(txn, block.Header); err != nil {

if err := b.verifyStateUpdateRoot(state, stateUpdate.NewRoot); err != nil {
return err
}

for i, tx := range block.Transactions {
if err := storeTransactionAndReceipt(txn, block.Number, uint64(i), tx,
block.Receipts[i]); err != nil {
return err
}
}
return storeStateUpdate(txn, block.Number, stateUpdate)
})
}

if err := storeStateUpdate(txn, block.Number, stateUpdate); err != nil {
return err
}
func (b *Blockchain) storeBlock(txn db.Transaction, block *core.Block, blockCommitments *core.BlockCommitments) error {
if err := verifyBlock(txn, block); err != nil {
return err
}

if err := StoreBlockCommitments(txn, block.Number, blockCommitments); err != nil {
return err
}
if err := StoreBlockHeader(txn, block.Header); err != nil {
return err

Check warning on line 363 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L363

Added line #L363 was not covered by tests
}

if err := b.storeEmptyPending(txn, block.Header); err != nil {
for i, tx := range block.Transactions {
if err := storeTransactionAndReceipt(txn, block.Number, uint64(i), tx,
block.Receipts[i]); err != nil {
return err
}
}

// Head of the blockchain is maintained as follows:
// [db.ChainHeight]() -> (BlockNumber)
heightBin := core.MarshalBlockNumber(block.Number)
return txn.Set(db.ChainHeight.Key(), heightBin)
})
if err := StoreBlockCommitments(txn, block.Number, blockCommitments); err != nil {
return err

Check warning on line 374 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L374

Added line #L374 was not covered by tests
}

if err := b.storeEmptyPending(txn, block.Header); err != nil {
return err

Check warning on line 378 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L378

Added line #L378 was not covered by tests
}

// Head of the blockchain is maintained as follows:
// [db.ChainHeight]() -> (BlockNumber)
heightBin := core.MarshalBlockNumber(block.Number)
return txn.Set(db.ChainHeight.Key(), heightBin)
}

// VerifyBlock assumes the block has already been sanity-checked.
Expand Down Expand Up @@ -514,7 +525,7 @@
return nil, err
}

var txs []core.Transaction
txs := []core.Transaction{}
numBytes := core.MarshalBlockNumber(number)

prefix := db.TransactionsByBlockNumberAndIndex.Key(numBytes)
Expand Down Expand Up @@ -549,7 +560,7 @@
return nil, err
}

var receipts []*core.TransactionReceipt
receipts := []*core.TransactionReceipt{}
numBytes := core.MarshalBlockNumber(number)

prefix := db.ReceiptsByBlockNumberAndIndex.Key(numBytes)
Expand Down Expand Up @@ -760,11 +771,6 @@
return nil, nil, err
}

_, err = chainHeight(txn)
if err != nil {
return nil, nil, utils.RunAndWrapOnError(txn.Discard, err)
}

return core.NewState(txn), txn.Discard, nil
}

Expand Down Expand Up @@ -841,7 +847,11 @@

state := core.NewState(txn)
// revert state
if err = state.Revert(blockNumber, stateUpdate); err != nil {
if err = state.Revert(blockNumber, stateUpdate.StateDiff); err != nil {
return err

Check warning on line 851 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L851

Added line #L851 was not covered by tests
}

if err = b.verifyStateUpdateRoot(state, stateUpdate.OldRoot); err != nil {
return err
}

Expand Down Expand Up @@ -1072,3 +1082,94 @@
}
return stateDiff, nil
}

func (b *Blockchain) verifyStateUpdateRoot(s *core.State, root *felt.Felt) error {
currentRoot, err := s.Root()
if err != nil {
return err

Check warning on line 1089 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1089

Added line #L1089 was not covered by tests
}

if !root.Equal(currentRoot) {
return fmt.Errorf("state's current root: %s does not match the expected root: %s", currentRoot, root)
}
return nil
}

type BlockSignFunc func(blockHash, stateDiffCommitment *felt.Felt) ([]*felt.Felt, error)

// Finalise will calculate the state commitment and block hash for the given pending block and append it to the
// blockchain
func (b *Blockchain) Finalise(pending *Pending, sign BlockSignFunc) error {
return b.database.Update(func(txn db.Transaction) error {
var err error

state := core.NewState(txn)
pending.StateUpdate.OldRoot, err = state.Root()
if err != nil {
return err

Check warning on line 1109 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1109

Added line #L1109 was not covered by tests
}

if h, hErr := chainHeight(txn); hErr == nil {
pending.Block.Number = h + 1
}

if err = state.Update(pending.Block.Number, pending.StateUpdate.StateDiff, pending.NewClasses); err != nil {
return err

Check warning on line 1117 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1117

Added line #L1117 was not covered by tests
}

pending.Block.GlobalStateRoot, err = state.Root()
if err != nil {
return err

Check warning on line 1122 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1122

Added line #L1122 was not covered by tests
}
pending.StateUpdate.NewRoot = pending.Block.GlobalStateRoot

var commitments *core.BlockCommitments
pending.Block.Hash, commitments, err = core.BlockHash(pending.Block)
if err != nil {
return err

Check warning on line 1129 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1129

Added line #L1129 was not covered by tests
}
pending.StateUpdate.BlockHash = pending.Block.Hash

pending.Block.Signatures = [][]*felt.Felt{}
var sig []*felt.Felt
sig, err = sign(pending.Block.Hash, pending.StateUpdate.StateDiff.Commitment())
if err != nil {
return err

Check warning on line 1137 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1137

Added line #L1137 was not covered by tests
}
if sig != nil {
pending.Block.Signatures = append(pending.Block.Signatures, sig)
}

if err = b.storeBlock(txn, pending.Block, commitments); err != nil {
return err

Check warning on line 1144 in blockchain/blockchain.go

View check run for this annotation

Codecov / codecov/patch

blockchain/blockchain.go#L1144

Added line #L1144 was not covered by tests
}

return storeStateUpdate(txn, pending.Block.Number, pending.StateUpdate)
})
}

func (b *Blockchain) StoreGenesis(diff *core.StateDiff, classes map[felt.Felt]core.Class) error {
receipts := make([]*core.TransactionReceipt, 0)
pendingGenesis := Pending{
Block: &core.Block{
Header: &core.Header{
ParentHash: &felt.Zero,
Number: 0,
SequencerAddress: &felt.Zero,
EventsBloom: core.EventsBloom(receipts),
GasPrice: &felt.Zero,
GasPriceSTRK: &felt.Zero,
},
Transactions: make([]core.Transaction, 0),
Receipts: receipts,
},
StateUpdate: &core.StateUpdate{
OldRoot: &felt.Zero,
StateDiff: diff,
},
NewClasses: classes,
}
return b.Finalise(&pendingGenesis, func(_, _ *felt.Felt) ([]*felt.Felt, error) {
return nil, nil
})
}
Loading
Loading