Skip to content

Commit

Permalink
Merge branch 'main' into wojciechos/e2e_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kirugan authored Nov 24, 2023
2 parents 6908200 + b7c7f69 commit 4eb7c2a
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 73 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ After following these steps, Juno should be up and running on your machine, util

## 🛣 Roadmap

### Phase 1
### Phase 1: Permissionless access to Starknet ✅

<details>
<summary></summary>
Expand Down Expand Up @@ -232,7 +232,7 @@ After following these steps, Juno should be up and running on your machine, util

</details>

### Phase 2
### Phase 2: Full JSON RPC Support ✅

<details>
<summary></summary>
Expand Down Expand Up @@ -262,6 +262,35 @@ The focus of Phase 2 will be to Verify the state from layer 1 and implement the

</details>

### Phase 3: Starknet decentralization begins 🚧

<details>
<summary></summary>

Juno can synchronize Starknet state from other full nodes with the aim of decentralizing Starknet by removing the dependency from the centralized sequencer.


Snap sync is implemented, significantly reducing sync times.

</details>

### Phase 4: Juno becomes a Starknet Sequencer 🔜

<details>
<summary></summary>

The decentralization of Starknet is complete! Juno becomes a sequencer and participates in L2 consensus to secure the network. Juno has multiple modes of operation:

• Light client: provides fast permissionless access to Starknet with minimal verification.

• Full Node: complete verification of Starknet state along with transaction execution.

• Sequencer: secure the network by taking part in the L2 consensus mechanism.

</details>


## 👍 Contribute

We welcome PRs from external contributors and would love to help you get up to speed.
Expand Down
8 changes: 4 additions & 4 deletions mocks/mock_vm.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions node/throttled_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func (tvm *ThrottledVM) Call(contractAddr, classHash, selector *felt.Felt, calld

func (tvm *ThrottledVM) Execute(txns []core.Transaction, declaredClasses []core.Class, blockNumber, blockTimestamp uint64,
sequencerAddress *felt.Felt, state core.StateReader, network utils.Network, paidFeesOnL1 []*felt.Felt,
skipChargeFee, skipValidate bool, gasPrice *felt.Felt, legacyTraceJSON bool,
skipChargeFee, skipValidate bool, gasPriceWEI *felt.Felt, gasPriceSTRK *felt.Felt, legacyTraceJSON bool,
) ([]*felt.Felt, []json.RawMessage, error) {
var ret []*felt.Felt
var traces []json.RawMessage
throttler := (*utils.Throttler[vm.VM])(tvm)
return ret, traces, throttler.Do(func(vm *vm.VM) error {
var err error
ret, traces, err = (*vm).Execute(txns, declaredClasses, blockNumber, blockTimestamp, sequencerAddress,
state, network, paidFeesOnL1, skipChargeFee, skipValidate, gasPrice, legacyTraceJSON)
state, network, paidFeesOnL1, skipChargeFee, skipValidate, gasPriceWEI, gasPriceSTRK, legacyTraceJSON)
return err
})
}
4 changes: 2 additions & 2 deletions rpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
sequencerAddress = core.NetworkBlockHashMetaInfo(h.network).FallBackSequencerAddress
}
overallFees, traces, err := h.vm.Execute(txns, classes, blockNumber, header.Timestamp, sequencerAddress,
state, h.network, paidFeesOnL1, skipFeeCharge, skipValidate, header.GasPrice, legacyTraceJSON)
state, h.network, paidFeesOnL1, skipFeeCharge, skipValidate, header.GasPrice, header.GasPriceSTRK, legacyTraceJSON)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
return nil, ErrUnexpectedError.CloneWithData(err.Error())
Expand Down Expand Up @@ -1482,7 +1482,7 @@ func (h *Handler) traceBlockTransactions(ctx context.Context, block *core.Block,
}

_, traces, err := h.vm.Execute(block.Transactions, classes, blockNumber, block.Header.Timestamp,
sequencerAddress, state, h.network, paidFeesOnL1, false, false, block.Header.GasPrice, legacyJSON)
sequencerAddress, state, h.network, paidFeesOnL1, false, false, block.Header.GasPrice, block.Header.GasPriceSTRK, legacyJSON)
if err != nil {
if errors.Is(err, utils.ErrResourceBusy) {
return nil, ErrUnexpectedError.CloneWithData(err.Error())
Expand Down
16 changes: 8 additions & 8 deletions rpc/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2055,10 +2055,10 @@ func TestEstimateMessageFee(t *testing.T) {

expectedGasConsumed := new(felt.Felt).SetUint64(37)
mockVM.EXPECT().Execute(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(),
gomock.Any(), utils.Mainnet, gomock.Any(), gomock.Any(), gomock.Any(), latestHeader.GasPrice, gomock.Any()).DoAndReturn(
gomock.Any(), utils.Mainnet, gomock.Any(), gomock.Any(), gomock.Any(), latestHeader.GasPrice, latestHeader.GasPriceSTRK, gomock.Any()).DoAndReturn(
func(txns []core.Transaction, declaredClasses []core.Class, blockNumber, blockTimestamp uint64,
sequencerAddress *felt.Felt, state core.StateReader, network utils.Network, paidFeesOnL1 []*felt.Felt,
skipChargeFee, skipValidate bool, gasPrice *felt.Felt, legacyTraceJson bool,
skipChargeFee, skipValidate bool, gasPriceWei, gasPriceSTRK *felt.Felt, legacyTraceJson bool,
) ([]*felt.Felt, []json.RawMessage, error) {
require.Len(t, txns, 1)
assert.NotNil(t, txns[0].(*core.L1HandlerTransaction))
Expand All @@ -2069,7 +2069,7 @@ func TestEstimateMessageFee(t *testing.T) {
assert.NotNil(t, sequencerAddress)
assert.Len(t, paidFeesOnL1, 1)

actualFee := new(felt.Felt).Mul(expectedGasConsumed, gasPrice)
actualFee := new(felt.Felt).Mul(expectedGasConsumed, gasPriceWei)
return []*felt.Felt{actualFee}, []json.RawMessage{{}}, nil
},
)
Expand Down Expand Up @@ -2138,7 +2138,7 @@ func TestTraceTransaction(t *testing.T) {
"fee_transfer_invocation": {"contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", "calldata": ["0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", "0x2cb6", "0x0"], "caller_address": "0xd747220b2744d8d8d48c8a52bd3869fb98aea915665ab2485d5eadb49def6a", "class_hash": "0xd0e183745e9dae3e4e78a8ffedcce0903fc4900beace4e0abf192d4c202da3", "entry_point_type": "EXTERNAL", "call_type": "CALL", "result": ["0x1"], "calls": [{"contract_address": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", "entry_point_selector": "0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e", "calldata": ["0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", "0x2cb6", "0x0"], "caller_address": "0xd747220b2744d8d8d48c8a52bd3869fb98aea915665ab2485d5eadb49def6a", "class_hash": "0x2760f25d5a4fb2bdde5f561fd0b44a3dee78c28903577d37d669939d97036a0", "entry_point_type": "EXTERNAL", "call_type": "DELEGATE", "result": ["0x1"], "calls": [], "events": [{"keys": ["0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"], "data": ["0xd747220b2744d8d8d48c8a52bd3869fb98aea915665ab2485d5eadb49def6a", "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8", "0x2cb6", "0x0"]}], "messages": []}], "events": [], "messages": []}
}`)
mockVM.EXPECT().Execute([]core.Transaction{tx}, []core.Class{declaredClass.Class}, header.Number, header.Timestamp, header.SequencerAddress,
gomock.Any(), utils.Mainnet, []*felt.Felt{}, false, false, gomock.Any(), false).Return(nil, []json.RawMessage{vmTrace}, nil)
gomock.Any(), utils.Mainnet, []*felt.Felt{}, false, false, gomock.Any(), gomock.Any(), false).Return(nil, []json.RawMessage{vmTrace}, nil)

trace, err := handler.TraceTransaction(context.Background(), *hash)
require.Nil(t, err)
Expand All @@ -2165,7 +2165,7 @@ func TestSimulateTransactions(t *testing.T) {
mockReader.EXPECT().HeadsHeader().Return(&core.Header{}, nil)

sequencerAddress := core.NetworkBlockHashMetaInfo(network).FallBackSequencerAddress
mockVM.EXPECT().Execute(nil, nil, uint64(0), uint64(0), sequencerAddress, mockState, network, []*felt.Felt{}, true, false, nil, false).
mockVM.EXPECT().Execute(nil, nil, uint64(0), uint64(0), sequencerAddress, mockState, network, []*felt.Felt{}, true, false, nil, nil, false).
Return([]*felt.Felt{}, []json.RawMessage{}, nil)

_, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipFeeChargeFlag})
Expand All @@ -2180,7 +2180,7 @@ func TestSimulateTransactions(t *testing.T) {
mockReader.EXPECT().HeadsHeader().Return(&core.Header{}, nil)

sequencerAddress := core.NetworkBlockHashMetaInfo(network).FallBackSequencerAddress
mockVM.EXPECT().Execute(nil, nil, uint64(0), uint64(0), sequencerAddress, mockState, network, []*felt.Felt{}, false, true, nil, false).
mockVM.EXPECT().Execute(nil, nil, uint64(0), uint64(0), sequencerAddress, mockState, network, []*felt.Felt{}, false, true, nil, nil, false).
Return([]*felt.Felt{}, []json.RawMessage{}, nil)

_, err := handler.SimulateTransactions(rpc.BlockID{Latest: true}, []rpc.BroadcastedTransaction{}, []rpc.SimulationFlag{rpc.SkipValidateFlag})
Expand Down Expand Up @@ -2249,7 +2249,7 @@ func TestTraceBlockTransactions(t *testing.T) {
"fee_transfer_invocation": {}
}`)
mockVM.EXPECT().Execute(block.Transactions, []core.Class{declaredClass.Class}, height+1, header.Timestamp, sequencerAddress,
gomock.Any(), network, paidL1Fees, false, false, header.GasPrice, false).Return(nil, []json.RawMessage{vmTrace, vmTrace}, nil)
gomock.Any(), network, paidL1Fees, false, false, header.GasPrice, header.GasPriceSTRK, false).Return(nil, []json.RawMessage{vmTrace, vmTrace}, nil)

result, err := handler.TraceBlockTransactions(context.Background(), rpc.BlockID{Hash: blockHash})
require.Nil(t, err)
Expand Down Expand Up @@ -2293,7 +2293,7 @@ func TestTraceBlockTransactions(t *testing.T) {
"fee_transfer_invocation":{"entry_point_selector":"0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e","calldata":["0x5dcd266a80b8a5f29f04d779c6b166b80150c24f2180a75e82427242dab20a9","0x15be","0x0"],"caller_address":"0xdac9bcffb3d967f19a7fe21002c98c984d5a9458a88e6fc5d1c478a97ed412","class_hash":"0xd0e183745e9dae3e4e78a8ffedcce0903fc4900beace4e0abf192d4c202da3","entry_point_type":"EXTERNAL","call_type":"CALL","result":["0x1"],"calls":[{"entry_point_selector":"0x83afd3f4caedc6eebf44246fe54e38c95e3179a5ec9ea81740eca5b482d12e","calldata":["0x5dcd266a80b8a5f29f04d779c6b166b80150c24f2180a75e82427242dab20a9","0x15be","0x0"],"caller_address":"0xdac9bcffb3d967f19a7fe21002c98c984d5a9458a88e6fc5d1c478a97ed412","class_hash":"0x2760f25d5a4fb2bdde5f561fd0b44a3dee78c28903577d37d669939d97036a0","entry_point_type":"EXTERNAL","call_type":"DELEGATE","result":["0x1"],"calls":[],"events":[{"keys":["0x99cd8bde557814842a3121e8ddfd433a539b8c9f14bf31ebf108d12e6196e9"],"data":["0xdac9bcffb3d967f19a7fe21002c98c984d5a9458a88e6fc5d1c478a97ed412","0x5dcd266a80b8a5f29f04d779c6b166b80150c24f2180a75e82427242dab20a9","0x15be","0x0"]}],"messages":[]}],"events":[],"messages":[]}}
}`)
mockVM.EXPECT().Execute([]core.Transaction{tx}, []core.Class{declaredClass.Class}, header.Number, header.Timestamp, header.SequencerAddress,
gomock.Any(), network, []*felt.Felt{}, false, false, header.GasPrice, false).Return(nil, []json.RawMessage{vmTrace}, nil)
gomock.Any(), network, []*felt.Felt{}, false, false, header.GasPrice, header.GasPriceSTRK, false).Return(nil, []json.RawMessage{vmTrace}, nil)

expectedResult := []rpc.TracedBlockTransaction{
{
Expand Down
8 changes: 4 additions & 4 deletions vm/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ edition = "2021"
[dependencies]
serde = "1.0.171"
serde_json = { version = "1.0.96", features = ["raw_value"] }
blockifier = {git = "https://github.com/starkware-libs/blockifier", rev = "v0.3.0-rc1"}
starknet_api = { git = "https://github.com/starkware-libs/starknet-api", rev = "8f620bc" }
blockifier = "0.4.0-rc8"
starknet_api = "0.6.0-rc2"
cairo-vm = "0.8.2"
cairo-lang-casm = "2.1.0"
cairo-lang-starknet = "2.1.0"
cairo-lang-casm = "2.4.0-rc2"
cairo-lang-starknet = "2.4.0-rc2"
indexmap = "1.9.2"
starknet = { rev = "starknet-core/v0.4.0", git = "https://github.com/xJonathanLEI/starknet-rs" }
cached = "0.44.0"
Expand Down
13 changes: 7 additions & 6 deletions vm/rust/src/jsonrpc.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use blockifier;
use blockifier::execution::entry_point::{CallType, OrderedL2ToL1Message};
use blockifier::execution::entry_point::CallType;
use blockifier::execution::call_info::OrderedL2ToL1Message;
use blockifier::state::cached_state::TransactionalState;
use blockifier::state::errors::StateError;
use blockifier::state::state_api::{State, StateReader};
use serde::Serialize;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, PatriciaKey};
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, PatriciaKey, EthAddress};
use starknet_api::deprecated_contract_class::EntryPointType;
use starknet_api::hash::StarkFelt;
use starknet_api::transaction::{Calldata, EthAddress, EventContent, L2ToL1Payload};
use starknet_api::transaction::{Calldata, EventContent, L2ToL1Payload};
use starknet_api::transaction::{DeclareTransaction, Transaction as StarknetApiTransaction};

use crate::juno_state_reader::JunoStateReader;
Expand Down Expand Up @@ -156,7 +157,7 @@ pub fn new_transaction_trace(
match declare_txn {
DeclareTransaction::V0(_) => Some(declare_txn.class_hash()),
DeclareTransaction::V1(_) => Some(declare_txn.class_hash()),
DeclareTransaction::V2(_) => None,
_ => None,
}
} else {
None
Expand All @@ -180,7 +181,7 @@ pub struct OrderedEvent {
pub event: EventContent,
}

type BlockifierOrderedEvent = blockifier::execution::entry_point::OrderedEvent;
use blockifier::execution::call_info::OrderedEvent as BlockifierOrderedEvent;
impl From<BlockifierOrderedEvent> for OrderedEvent {
fn from(val: BlockifierOrderedEvent) -> Self {
OrderedEvent {
Expand Down Expand Up @@ -218,7 +219,7 @@ impl FunctionInvocation {
}
}

type BlockifierCallInfo = blockifier::execution::entry_point::CallInfo;
use blockifier::execution::call_info::CallInfo as BlockifierCallInfo;
impl From<BlockifierCallInfo> for FunctionInvocation {
fn from(val: BlockifierCallInfo) -> Self {
FunctionInvocation {
Expand Down
Loading

0 comments on commit 4eb7c2a

Please sign in to comment.