Skip to content

Commit

Permalink
implement sequecning
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Dec 17, 2024
1 parent a9d11d4 commit be21143
Show file tree
Hide file tree
Showing 57 changed files with 31,969 additions and 274 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ build/
coverage/*
config/
.envrc
.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
63 changes: 61 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
.PHONY: vm juno

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 @@ -160,6 +160,65 @@ node3: juno-cached ## Run a node №3. P2P usage only
--metrics-port=9093 \
--disable-l1-verification

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 \
--disable-l1-verification \
--rpc-call-max-steps=4123000

sequencer-plugin-w-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 \
--plugin-path="myplugin.so" \
--seq-disable-fees \
--seq-genesis-file "./genesis/genesis_prefund_accounts.json" \
--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 \
--disable-l1-verification \
--seq-genesis-file "./genesis/genesis_prefund_accounts.json" \
--rpc-call-max-steps=4123000


sequencer-shadow-sepolia: # Only works for 0.12.3 Sepolia blocks
./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-block=0 \
--seq-rpc-endpoint="" \
--network sepolia \
--disable-l1-verification \
--rpc-call-max-steps=4123000

pathfinder: juno-cached ## Run a node to sync from pathfinder feedernode. P2P usage only
./build/juno \
--network=sepolia \
Expand Down
134 changes: 134 additions & 0 deletions adapters/vm2core/vm2core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,35 @@ import (
"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, totalGas *vm.GasConsumed) *core.ExecutionResources {
return &core.ExecutionResources{
BuiltinInstanceCounter: core.BuiltinInstanceCounter{
Pedersen: resources.Pedersen,
RangeCheck: resources.RangeCheck,
Bitwise: resources.Bitwise,
Ecsda: resources.Ecdsa,
EcOp: resources.EcOp,
Keccak: resources.Keccak,
Poseidon: resources.Poseidon,
SegmentArena: resources.SegmentArena,
Output: resources.Output,
AddMod: resources.AddMod,
MulMod: resources.MulMod,
RangeCheck96: resources.RangeCheck96,
},
MemoryHoles: resources.MemoryHoles,
Steps: resources.Steps,
DataAvailability: adaptDA(resources.DataAvailability),
TotalGasConsumed: &core.GasConsumed{L1Gas: totalGas.L1Gas, L1DataGas: totalGas.L1DataGas},
}
}

func AdaptOrderedEvent(event vm.OrderedEvent) *core.Event {
return &core.Event{
From: event.From,
Expand Down Expand Up @@ -39,3 +63,113 @@ func AdaptOrderedEvents(events []vm.OrderedEvent) []*core.Event {
})
return utils.Map(events, AdaptOrderedEvent)
}

func adaptDA(da *vm.DataAvailability) *core.DataAvailability {
if da == nil {
return nil
}

return &core.DataAvailability{
L1Gas: da.L1Gas,
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),
}
if sd == nil {
return &result
}
for _, entries := range sd.StorageDiffs {
KeyVals := map[felt.Felt]*felt.Felt{}
for _, entry := range entries.StorageEntries {
KeyVals[entry.Key] = &entry.Value
}
result.StorageDiffs[entries.Address] = KeyVals
}
for _, addrNonce := range sd.Nonces {
result.Nonces[addrNonce.ContractAddress] = &addrNonce.Nonce
}
for _, addrClassHash := range sd.DeployedContracts {
result.Nonces[addrClassHash.Address] = &addrClassHash.ClassHash
}
for _, hashes := range sd.DeclaredClasses {
result.DeclaredV1Classes[hashes.ClassHash] = &hashes.CompiledClassHash
}
for _, addrClassHash := range sd.ReplacedClasses {
result.ReplacedClasses[addrClassHash.ClassHash] = &addrClassHash.ClassHash
}
result.DeclaredV0Classes = append(result.DeclaredV0Classes, sd.DeprecatedDeclaredClasses...)
return &result
}

func StateDiff(trace *vm.TransactionTrace) *core.StateDiff {
if trace.StateDiff == nil {
return nil
}
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{ //nolint: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(),
}
}
Loading

0 comments on commit be21143

Please sign in to comment.