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

Implement sequencer "shadow" feature #2015

Closed
wants to merge 89 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
6f8e272
implement juno sequencer
Jul 17, 2024
ca76d85
Update hashing functions for 0.13.2 (#1964)
kirugan Jul 30, 2024
be4fe92
support declaring classes
Aug 1, 2024
9fb7f93
fix deploy_contract and replace_class_hashes in state diff
Aug 1, 2024
f863c76
merge main - wip - vm.call mutRefState broke
Aug 2, 2024
e244aad
merge mainqip - call execute no longer accepst MutRefState
Aug 2, 2024
7a63520
Merge branch 'main' into rianhughes/merge-sequencer
Aug 2, 2024
9f14fff
cairoVMCAll now modifies state
Aug 2, 2024
3a5ce53
allow vm.Call to modify state if ReaderWriter interface is satisfied
Aug 3, 2024
6571a1c
lint
Aug 3, 2024
fe14d54
implement logic to let sequencer shadow the sepolia network
Aug 3, 2024
f7e606f
add state root check
Aug 3, 2024
3531d68
verification - wip
Aug 5, 2024
b6eb966
add support for snapshot - wip
Aug 5, 2024
9ce554b
Merge branch 'main' into rianhughes/seq-shadow-mode-2
Aug 6, 2024
80f5db3
fix hang on Finalise
Aug 19, 2024
eb9e439
transaction level debug using traces - wip
Aug 19, 2024
a40cae0
more debug friendly trac verification
Aug 20, 2024
157dce3
debug print update
rianhughes Aug 22, 2024
6201f84
use shadowblock timestamp
rianhughes Aug 22, 2024
bca58bd
fix sync issues for block 122510
rianhughes Aug 22, 2024
a3ad411
1. block hash issue at 122520, 2. reloading seq - fails to verify block
rianhughes Aug 22, 2024
a8d435e
Merge branch 'main' into rianhughes/seq-shadow-mode-2
rianhughes Aug 23, 2024
cc57384
fix verfyHash on load - wip, compute all commitments
rianhughes Aug 23, 2024
5c2e994
can now re-load the sequencer in shadow mode (ie block verif passes)
rianhughes Aug 23, 2024
29fe625
block hash check on Finalise(currnetly failing)
rianhughes Aug 23, 2024
b1973a3
receipts 122510, state diff 122511
rianhughes Aug 23, 2024
3af9ba8
add validation logic
rianhughes Aug 26, 2024
b6eeedc
return receipts from blockifier (total gas)
rianhughes Aug 27, 2024
687b96c
Merge branch 'main' into rianhughes/seq-shadow-mode-2
rianhughes Aug 27, 2024
243b46d
Merge branch 'rianhughes/totalgasconsumed' into rianhughes/seq-shadow…
rianhughes Aug 27, 2024
93d32b8
use total gas consumed returned from blockifier
rianhughes Aug 27, 2024
ae41a15
validate events
rianhughes Aug 27, 2024
9201c7d
Events - blockifier seems to give two distinct events the same order …
rianhughes Aug 27, 2024
ea6cd5e
event order err - wip - checking if blockifier is to blame
rianhughes Aug 27, 2024
0232f83
correct events ordering
rianhughes Aug 28, 2024
4eac97c
less verbose
rianhughes Aug 28, 2024
5bd604b
remove storage updates that dont actually update the state
rianhughes Aug 29, 2024
247cc55
account for deployAccount in event ordering
rianhughes Aug 29, 2024
40936a5
remove empty storage diffs
rianhughes Aug 29, 2024
70a68e3
don't throw error in revert - seems to sync fine
rianhughes Aug 29, 2024
0fe9e32
don't override L1 handler fee
rianhughes Aug 29, 2024
ba55e8b
ugly toggle verif using juno endpoint
rianhughes Aug 29, 2024
b49e733
start tidy
rianhughes Aug 29, 2024
c5741b5
small wip
rianhughes Sep 2, 2024
1570cf8
wip - fee problem seems to be resolved
rianhughes Sep 4, 2024
f17b19b
return data gas from blickifier, set abi-len to zero for v0 classes
rianhughes Sep 5, 2024
5f41e82
readd cairov1 to newclasses
rianhughes Sep 5, 2024
c978406
syncs up to block 129752
rianhughes Sep 5, 2024
2d504c8
synced up to 133371 (skipped 129751 tho)
rianhughes Sep 6, 2024
fb41fb0
todo: hack, if revert reason if different, use that from the sepolia …
rianhughes Sep 8, 2024
5d04994
wip - l1 handler fee can be any non-zero value
rianhughes Sep 9, 2024
02e3a77
wip - l1 handler fee can be any non-zero value
rianhughes Sep 9, 2024
9117891
fix - move replaced class to deployed if has same affect
rianhughes Sep 10, 2024
de63db5
just add a new flag to set block number we should sync to
rianhughes Sep 10, 2024
f280451
remove duplicates
rianhughes Sep 10, 2024
be9dc7c
Merge branch 'main' into rianhughes/seq-shadow-mode-2
rianhughes Sep 12, 2024
38957b4
merge main
rianhughes Sep 12, 2024
c2fc2a7
solved problematic txn - set blockhash to be revealed
rianhughes Sep 13, 2024
e7bff7c
duplication fix
rianhughes Sep 13, 2024
8eb7e69
modify compareSlices (order should be irrelevant)
rianhughes Sep 13, 2024
b9479fa
reason for revert-reason differences
rianhughes Sep 13, 2024
286d2ec
use receipts revert reason even if no access to another juno node
rianhughes Sep 13, 2024
ddb3cd7
Dfix block0 sync + tidy
rianhughes Sep 18, 2024
a774d3e
tidying - wip
rianhughes Sep 18, 2024
f796b7c
wip
rianhughes Sep 18, 2024
6c1f714
lint - wip
rianhughes Sep 18, 2024
64c77a5
lint wip + refactor
rianhughes Sep 19, 2024
5a5e544
lint wip
rianhughes Sep 19, 2024
129af4a
gofmy
rianhughes Sep 19, 2024
0025d39
fix TestAllEvents
rianhughes Sep 19, 2024
5890c48
lint
rianhughes Sep 19, 2024
b383c50
fix tests
rianhughes Sep 20, 2024
a402526
Merge branch 'main' into rianhughes/seq-shadow-mode-2
rianhughes Sep 20, 2024
3bd5589
Dlint
rianhughes Sep 20, 2024
bad0f86
0.12.3 fixes
rianhughes Sep 20, 2024
9b7a357
0.13.2 fixes
rianhughes Sep 20, 2024
440c808
fmting
rianhughes Sep 20, 2024
c88e865
fix: sleep for 5s when at chain head
rianhughes Sep 20, 2024
422c104
fix test, remove chanFinalised from runSeq
rianhughes Sep 21, 2024
3512493
lint
rianhughes Sep 21, 2024
93c9b15
fix TestBuildBlocks
rianhughes Sep 21, 2024
4a6da0d
add classes for [200~TestShadowSepolia~
rianhughes Sep 21, 2024
74079c3
fix TestShadowSepolia
rianhughes Sep 23, 2024
63737c9
move StateDiff() to adapter
rianhughes Sep 23, 2024
1266dae
move Receipt() to adapters + add test
rianhughes Sep 23, 2024
36d1415
push printers to new file and remove from code cov
rianhughes Sep 23, 2024
311356e
tiny tidys
rianhughes Sep 23, 2024
4fc301f
Merge branch 'main' into rianhughes/seq-shadow-mode-2
rianhughes Sep 23, 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ build/
coverage/*
config/
.envrc
seq-db/

# pyenv
.python-version

# Default path for Juno DB files. It will get created if you follow the
# README and/or run `./build/juno` command.
juno/
Expand Down
59 changes: 50 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
.PHONY: vm

ifeq ($(VM_DEBUG),true)
GO_TAGS = -tags vm_debug
GO_TAGS = -tags 'vm_debug,no_coverage'
VM_TARGET = debug
else
GO_TAGS =
GO_TAGS = -tags 'no_coverage'
VM_TARGET = all
endif

Expand Down Expand Up @@ -151,12 +151,53 @@ 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 \
--seq-genesis-file "./genesis/genesis_prefund_accounts.json" \
--rpc-call-max-steps=4123000


sequencer-shadow-sepolia:
./build/juno \
--http \
--http-port=6066 \
--http-host=0.0.0.0 \
--db-path=../seq-db\
--log-level=info \
--seq-enable \
--seq-shadow-mode \
--seq-block-time=5 \
--seq-shadow-mode-sync-to=0 \
--seq-rpc-endpoint="" \
--network sepolia \
--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
104 changes: 102 additions & 2 deletions adapters/vm2core/vm2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"slices"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/utils"
"github.com/NethermindEth/juno/vm"
"github.com/ethereum/go-ethereum/common"
)

func AdaptExecutionResources(resources *vm.ExecutionResources) *core.ExecutionResources {
func AdaptExecutionResources(resources *vm.ExecutionResources, totalGas *vm.GasConsumed) *core.ExecutionResources {
return &core.ExecutionResources{
BuiltinInstanceCounter: core.BuiltinInstanceCounter{
Pedersen: resources.Pedersen,
Expand All @@ -29,7 +30,7 @@
MemoryHoles: resources.MemoryHoles,
Steps: resources.Steps,
DataAvailability: adaptDA(resources.DataAvailability),
TotalGasConsumed: nil, // todo: fill after 0.13.2
TotalGasConsumed: &core.GasConsumed{L1Gas: totalGas.L1Gas, L1DataGas: totalGas.L1DataGas},
}
}

Expand Down Expand Up @@ -73,3 +74,102 @@
L1DataGas: da.L1DataGas,
}
}

func AdaptStateDiff(sd *vm.StateDiff) *core.StateDiff {
result := core.StateDiff{
StorageDiffs: make(map[felt.Felt]map[felt.Felt]*felt.Felt),
Nonces: make(map[felt.Felt]*felt.Felt),
DeployedContracts: make(map[felt.Felt]*felt.Felt),
DeclaredV0Classes: []*felt.Felt{},
DeclaredV1Classes: make(map[felt.Felt]*felt.Felt),
ReplacedClasses: make(map[felt.Felt]*felt.Felt),

Check warning on line 85 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L78-L85

Added lines #L78 - L85 were not covered by tests
}
if sd == nil {
return &result

Check warning on line 88 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L87-L88

Added lines #L87 - L88 were not covered by tests
}
for _, entries := range sd.StorageDiffs {
KeyVals := map[felt.Felt]*felt.Felt{}
for _, entry := range entries.StorageEntries {
KeyVals[entry.Key] = &entry.Value

Check warning on line 93 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L90-L93

Added lines #L90 - L93 were not covered by tests
}
result.StorageDiffs[entries.Address] = KeyVals

Check warning on line 95 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L95

Added line #L95 was not covered by tests
}
for _, addrNonce := range sd.Nonces {
result.Nonces[addrNonce.ContractAddress] = &addrNonce.Nonce

Check warning on line 98 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L97-L98

Added lines #L97 - L98 were not covered by tests
}
for _, addrClassHash := range sd.DeployedContracts {
result.Nonces[addrClassHash.Address] = &addrClassHash.ClassHash

Check warning on line 101 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L100-L101

Added lines #L100 - L101 were not covered by tests
}
for _, hashes := range sd.DeclaredClasses {
result.DeclaredV1Classes[hashes.ClassHash] = &hashes.CompiledClassHash

Check warning on line 104 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L103-L104

Added lines #L103 - L104 were not covered by tests
}
for _, addrClassHash := range sd.ReplacedClasses {
result.ReplacedClasses[addrClassHash.ClassHash] = &addrClassHash.ClassHash

Check warning on line 107 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L106-L107

Added lines #L106 - L107 were not covered by tests
}
result.DeclaredV0Classes = append(result.DeclaredV0Classes, sd.DeprecatedDeclaredClasses...)
return &result

Check warning on line 110 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L109-L110

Added lines #L109 - L110 were not covered by tests
}

func StateDiff(trace *vm.TransactionTrace) *core.StateDiff {
if trace.StateDiff == nil {
return nil

Check warning on line 115 in adapters/vm2core/vm2core.go

View check run for this annotation

Codecov / codecov/patch

adapters/vm2core/vm2core.go#L115

Added line #L115 was not covered by tests
}
stateDiff := trace.StateDiff
newStorageDiffs := make(map[felt.Felt]map[felt.Felt]*felt.Felt)
for _, sd := range stateDiff.StorageDiffs {
entries := make(map[felt.Felt]*felt.Felt)
for _, entry := range sd.StorageEntries {
val := entry.Value
entries[entry.Key] = &val
}
newStorageDiffs[sd.Address] = entries
}

newNonces := make(map[felt.Felt]*felt.Felt)
for _, nonce := range stateDiff.Nonces {
nonc := nonce.Nonce
newNonces[nonce.ContractAddress] = &nonc
}

newDeployedContracts := make(map[felt.Felt]*felt.Felt)
for _, dc := range stateDiff.DeployedContracts {
ch := dc.ClassHash
newDeployedContracts[dc.Address] = &ch
}

newDeclaredV1Classes := make(map[felt.Felt]*felt.Felt)
for _, dc := range stateDiff.DeclaredClasses {
cch := dc.CompiledClassHash
newDeclaredV1Classes[dc.ClassHash] = &cch
}

newReplacedClasses := make(map[felt.Felt]*felt.Felt)
for _, rc := range stateDiff.ReplacedClasses {
ch := rc.ClassHash
newReplacedClasses[rc.ContractAddress] = &ch
}

return &core.StateDiff{
StorageDiffs: newStorageDiffs,
Nonces: newNonces,
DeployedContracts: newDeployedContracts,
DeclaredV0Classes: stateDiff.DeprecatedDeclaredClasses,
DeclaredV1Classes: newDeclaredV1Classes,
ReplacedClasses: newReplacedClasses,
}
}

func Receipt(fee *felt.Felt, feeUnit core.FeeUnit, txHash *felt.Felt,
trace *vm.TransactionTrace, txnReceipt *vm.TransactionReceipt,
) *core.TransactionReceipt {
return &core.TransactionReceipt{

Check failure on line 165 in adapters/vm2core/vm2core.go

View workflow job for this annotation

GitHub Actions / lint

core.TransactionReceipt is missing field L1ToL2Message (exhaustruct)
Fee: fee,
FeeUnit: feeUnit,
Events: AdaptOrderedEvents(trace.AllEvents()),
ExecutionResources: AdaptExecutionResources(trace.TotalExecutionResources(), &txnReceipt.Gas),
L2ToL1Message: AdaptOrderedMessagesToL1(trace.AllMessages()),
TransactionHash: txHash,
Reverted: trace.IsReverted(),
RevertReason: trace.RevertReason(),
}
}
77 changes: 74 additions & 3 deletions adapters/vm2core/vm2core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ func TestAdaptExecutionResources(t *testing.T) {
SegmentArena: 8,
Output: 11,
},
MemoryHoles: 9,
Steps: 10,
MemoryHoles: 9,
Steps: 10,
TotalGasConsumed: &core.GasConsumed{L1Gas: 1, L1DataGas: 2},
}, vm2core.AdaptExecutionResources(&vm.ExecutionResources{
ComputationResources: vm.ComputationResources{
Pedersen: 1,
Expand All @@ -98,5 +99,75 @@ func TestAdaptExecutionResources(t *testing.T) {
Steps: 10,
Output: 11,
},
}))
}, &vm.GasConsumed{L1Gas: 1, L1DataGas: 2}))
}

func TestStateDiff(t *testing.T) {
address1 := *new(felt.Felt).SetUint64(1)
key1 := *new(felt.Felt).SetUint64(2)
value1 := *new(felt.Felt).SetUint64(3)
nonce1 := *new(felt.Felt).SetUint64(4)
classHash1 := *new(felt.Felt).SetUint64(5)
compiledClassHash1 := *new(felt.Felt).SetUint64(6)
trace := &vm.TransactionTrace{
StateDiff: &vm.StateDiff{
StorageDiffs: []vm.StorageDiff{
{
Address: address1,
StorageEntries: []vm.Entry{
{Key: key1, Value: value1},
},
},
},
Nonces: []vm.Nonce{{ContractAddress: address1, Nonce: nonce1}},
DeployedContracts: []vm.DeployedContract{{Address: address1, ClassHash: classHash1}},
DeclaredClasses: []vm.DeclaredClass{{ClassHash: classHash1, CompiledClassHash: compiledClassHash1}},
ReplacedClasses: []vm.ReplacedClass{{ContractAddress: address1, ClassHash: classHash1}},
DeprecatedDeclaredClasses: []*felt.Felt{&classHash1},
},
}

expected := &core.StateDiff{
StorageDiffs: map[felt.Felt]map[felt.Felt]*felt.Felt{
address1: {key1: &value1},
},
Nonces: map[felt.Felt]*felt.Felt{address1: &nonce1},
DeployedContracts: map[felt.Felt]*felt.Felt{address1: &classHash1},
DeclaredV0Classes: []*felt.Felt{&classHash1},
DeclaredV1Classes: map[felt.Felt]*felt.Felt{classHash1: &compiledClassHash1},
ReplacedClasses: map[felt.Felt]*felt.Felt{address1: &classHash1},
}
require.Equal(t, expected, vm2core.StateDiff(trace))
}

func TestReceipt(t *testing.T) {
fee := new(felt.Felt).SetUint64(1)
feeUnit := core.WEI
txHash := new(felt.Felt).SetUint64(2)
trace := &vm.TransactionTrace{
Type: vm.TxnInvoke,
ValidateInvocation: &vm.FunctionInvocation{},
ExecuteInvocation: &vm.ExecuteInvocation{},
FeeTransferInvocation: &vm.FunctionInvocation{},
ConstructorInvocation: &vm.FunctionInvocation{},
FunctionInvocation: &vm.FunctionInvocation{},
StateDiff: &vm.StateDiff{},
ExecutionResources: &vm.ExecutionResources{},
}
txnReceipt := &vm.TransactionReceipt{
Fee: fee,
Gas: vm.GasConsumed{L1Gas: 1, L1DataGas: 2},
DAGas: vm.DataAvailability{L1Gas: 1, L1DataGas: 2},
}
expectedReceipt := &core.TransactionReceipt{
Fee: fee,
FeeUnit: feeUnit,
Events: vm2core.AdaptOrderedEvents(trace.AllEvents()),
ExecutionResources: vm2core.AdaptExecutionResources(trace.TotalExecutionResources(), &txnReceipt.Gas),
L2ToL1Message: vm2core.AdaptOrderedMessagesToL1(trace.AllMessages()),
TransactionHash: txHash,
Reverted: trace.IsReverted(),
RevertReason: trace.RevertReason(),
}
require.Equal(t, expectedReceipt, vm2core.Receipt(fee, feeUnit, txHash, trace, txnReceipt))
}
Loading
Loading