Skip to content

Commit

Permalink
Merge branch 'main' into vm-ctx-revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Exca-DK committed Nov 15, 2023
2 parents 0f32c4b + c2877e4 commit 99dd4e1
Show file tree
Hide file tree
Showing 88 changed files with 3,744 additions and 733 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ jobs:
env:
EVENT_NAME: juno-prod
IMAGE_TAG: ${{ needs.docker_build_and_publish.outputs.IMAGE_TAG }}
GOERLI: apps/juno-prod/overlays/prod_goerli-1/config.yaml
INTEGRATION: apps/juno-prod/overlays/prod_integration/config.yaml
MAINNET: apps/juno-prod/overlays/prod_mainnet/config.yaml
GOERLI: apps/juno-prod/overlays/prod-goerli-1/config.yaml
INTEGRATION: apps/juno-prod/overlays/prod-integration/config.yaml
MAINNET: apps/juno-prod/overlays/prod-mainnet/config.yaml
run: |
curl -L \
-X POST \
Expand All @@ -153,4 +153,4 @@ jobs:
secrets:
TEST_RPC_URL: ${{ secrets.PROD_GOERLI_URL }}/v0_4
TEST_ACCOUNT_ADDRESS: ${{ secrets.GOERLI_TEST_ACCOUNT_ADDRESS }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_TEST_ACCOUNT_PRIVATE_KEY }}
TEST_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOERLI_TEST_ACCOUNT_PRIVATE_KEY }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Use the provided snapshots to quickly sync your Juno node with the current state
nethermind/juno \
--http \
--http-port 6060 \
--http-host 0.0.0.0 \
--db-path /var/lib/juno \
--eth-node <YOUR-ETH-NODE>
```
Expand Down
65 changes: 65 additions & 0 deletions adapters/core2p2p/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package core2p2p

import (
"time"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
"google.golang.org/protobuf/types/known/timestamppb"
)

func AdaptBlockID(header *core.Header) *spec.BlockID {
if header == nil {
return nil
}

return &spec.BlockID{
Number: header.Number,
Header: AdaptHash(header.Hash),
}
}

func AdaptSignature(sig []*felt.Felt) *spec.ConsensusSignature {
return &spec.ConsensusSignature{
R: AdaptFelt(sig[0]),
S: AdaptFelt(sig[1]),
}
}

func AdaptHeader(header *core.Header, commitments *core.BlockCommitments) *spec.BlockHeader {
return &spec.BlockHeader{
ParentHeader: AdaptHash(header.ParentHash),
Number: header.Number,
Time: timestamppb.New(time.Unix(int64(header.Timestamp), 0)),
SequencerAddress: AdaptAddress(header.SequencerAddress),
ProofFact: nil, // not defined yet
Receipts: nil, // not defined yet
StateDiffs: nil, // not defined yet
State: &spec.Patricia{
Height: 251, // fixed
Root: AdaptHash(header.GlobalStateRoot),
},
Transactions: &spec.Merkle{
NLeaves: uint32(header.TransactionCount),
Root: AdaptHash(commitments.TransactionCommitment),
},
Events: &spec.Merkle{
NLeaves: uint32(header.EventCount),
Root: AdaptHash(commitments.EventCommitment),
},
}
}

func AdaptEvent(e *core.Event) *spec.Event {
if e == nil {
return nil
}

return &spec.Event{
FromAddress: AdaptFelt(e.From),
Keys: utils.Map(e.Keys, AdaptFelt),
Data: utils.Map(e.Data, AdaptFelt),
}
}
30 changes: 30 additions & 0 deletions adapters/core2p2p/class.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package core2p2p

import (
"fmt"

"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/p2p/starknet/spec"
)

func AdaptClass(class core.Class, compiledHash *felt.Felt) *spec.Class {
if class == nil {
return nil
}

switch v := class.(type) {
case *core.Cairo0Class:
return &spec.Class{
CompiledHash: AdaptHash(compiledHash),
Definition: []byte(v.Program),
}
case *core.Cairo1Class:
return &spec.Class{
CompiledHash: AdaptHash(compiledHash),
Definition: v.Compiled,
}
default:
panic(fmt.Errorf("unsupported cairo class %T (version=%d)", v, class.Version()))
}
}
21 changes: 21 additions & 0 deletions adapters/core2p2p/felt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core2p2p
import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
)

func AdaptHash(f *felt.Felt) *spec.Hash {
Expand All @@ -15,6 +16,12 @@ func AdaptHash(f *felt.Felt) *spec.Hash {
}
}

func AdaptAccountSignature(signature []*felt.Felt) *spec.AccountSignature {
return &spec.AccountSignature{
Parts: utils.Map(signature, AdaptFelt),
}
}

func AdaptFelt(f *felt.Felt) *spec.Felt252 {
if f == nil {
return nil
Expand All @@ -24,3 +31,17 @@ func AdaptFelt(f *felt.Felt) *spec.Felt252 {
Elements: f.Marshal(),
}
}

func AdaptFeltSlice(sl []*felt.Felt) []*spec.Felt252 {
return utils.Map(sl, AdaptFelt)
}

func AdaptAddress(f *felt.Felt) *spec.Address {
if f == nil {
return nil
}

return &spec.Address{
Elements: f.Marshal(),
}
}
96 changes: 96 additions & 0 deletions adapters/core2p2p/receipt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package core2p2p

import (
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
)

// Core Transaction receipt does not contain all the information required to create p2p spec Receipt, therefore,
// we have to pass the transaction as well.
func AdaptReceipt(r *core.TransactionReceipt, txn core.Transaction) *spec.Receipt {
if r == nil || txn == nil {
return nil
}
switch t := txn.(type) {
case *core.InvokeTransaction:
return &spec.Receipt{
Receipt: &spec.Receipt_Invoke_{
Invoke: &spec.Receipt_Invoke{
Common: receiptCommon(r),
},
},
}
case *core.L1HandlerTransaction:
return &spec.Receipt{
Receipt: &spec.Receipt_L1Handler_{
L1Handler: &spec.Receipt_L1Handler{
Common: receiptCommon(r),
MsgHash: &spec.Hash{Elements: t.MessageHash()},
},
},
}
case *core.DeclareTransaction:
return &spec.Receipt{
Receipt: &spec.Receipt_Declare_{
Declare: &spec.Receipt_Declare{
Common: receiptCommon(r),
},
},
}
case *core.DeployTransaction:
return &spec.Receipt{
Receipt: &spec.Receipt_DeprecatedDeploy{
DeprecatedDeploy: &spec.Receipt_Deploy{
Common: receiptCommon(r),
ContractAddress: AdaptFelt(t.ContractAddress),
},
},
}
case *core.DeployAccountTransaction:
return &spec.Receipt{
Receipt: &spec.Receipt_DeployAccount_{
DeployAccount: &spec.Receipt_DeployAccount{
Common: receiptCommon(r),
ContractAddress: AdaptFelt(t.ContractAddress),
},
},
}
default:
return nil
}
}

func receiptCommon(r *core.TransactionReceipt) *spec.Receipt_Common {
return &spec.Receipt_Common{
TransactionHash: AdaptHash(r.TransactionHash),
ActualFee: AdaptFelt(r.Fee),
MessagesSent: utils.Map(r.L2ToL1Message, AdaptMessageToL1),
ExecutionResources: AdaptExecutionResources(r.ExecutionResources),
RevertReason: r.RevertReason,
}
}

func AdaptMessageToL1(mL1 *core.L2ToL1Message) *spec.MessageToL1 {
return &spec.MessageToL1{
FromAddress: AdaptFelt(mL1.From),
Payload: utils.Map(mL1.Payload, AdaptFelt),
ToAddress: &spec.EthereumAddress{Elements: mL1.To.Bytes()},
}
}

func AdaptExecutionResources(er *core.ExecutionResources) *spec.Receipt_ExecutionResources {
return &spec.Receipt_ExecutionResources{
Builtins: &spec.Receipt_ExecutionResources_BuiltinCounter{
Bitwise: uint32(er.BuiltinInstanceCounter.Bitwise),
Ecdsa: uint32(er.BuiltinInstanceCounter.Ecsda),
EcOp: uint32(er.BuiltinInstanceCounter.EcOp),
Pedersen: uint32(er.BuiltinInstanceCounter.Pedersen),
RangeCheck: uint32(er.BuiltinInstanceCounter.RangeCheck),
Poseidon: uint32(er.BuiltinInstanceCounter.Poseidon),
Keccak: uint32(er.BuiltinInstanceCounter.Keccak),
},
Steps: uint32(er.Steps),
MemoryHoles: uint32(er.MemoryHoles),
}
}
26 changes: 26 additions & 0 deletions adapters/core2p2p/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package core2p2p

import (
"github.com/NethermindEth/juno/core"
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/utils"
)

func AdaptStateDiff(addr, classHash, nonce *felt.Felt, diff []core.StorageDiff) *spec.StateDiff_ContractDiff {
return &spec.StateDiff_ContractDiff{
Address: AdaptAddress(addr),
Nonce: AdaptFelt(nonce),
ClassHash: AdaptFelt(classHash),
Values: AdaptStorageDiff(diff),
}
}

func AdaptStorageDiff(diff []core.StorageDiff) []*spec.ContractStoredValue {
return utils.Map(diff, func(item core.StorageDiff) *spec.ContractStoredValue {
return &spec.ContractStoredValue{
Key: AdaptFelt(item.Key),
Value: AdaptFelt(item.Value),
}
})
}
Loading

0 comments on commit 99dd4e1

Please sign in to comment.