Skip to content

Commit 4bf1dec

Browse files
rianhugheswojciechos
authored andcommitted
Bug fix: set the pending header correctly (#2696)
* bug fix: correctly set pending header
1 parent f342758 commit 4bf1dec

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

adapters/sn2core/sn2core.go

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func AdaptBlock(response *starknet.Block, sig *starknet.Signature) (*core.Block,
3838
if sig != nil {
3939
sigs = append(sigs, sig.Signature)
4040
}
41+
4142
return &core.Block{
4243
Header: &core.Header{
4344
Hash: response.Hash,

rpc/v7/simulation.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
5252
if rpcErr != nil {
5353
return nil, httpHeader, rpcErr
5454
}
55+
5556
defer h.callAndLogErr(closer, "Failed to close state in starknet_estimateFee")
5657

5758
header, rpcErr := h.blockHeaderByID(&id)
@@ -60,6 +61,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
6061
}
6162

6263
network := h.bcReader.Network()
64+
6365
txns, classes, paidFeesOnL1, rpcErr := prepareTransactions(transactions, network)
6466
if rpcErr != nil {
6567
return nil, httpHeader, rpcErr
@@ -69,6 +71,7 @@ func (h *Handler) simulateTransactions(id BlockID, transactions []BroadcastedTra
6971
if err != nil {
7072
return nil, httpHeader, rpccore.ErrInternal.CloneWithData(err)
7173
}
74+
7275
blockInfo := vm.BlockInfo{
7376
Header: header,
7477
BlockHashToBeRevealed: blockHashToBeRevealed,
@@ -171,7 +174,6 @@ func createSimulatedTransactions(
171174
l1GasPrice = l1GasPriceStrk
172175
l1DataGasPrice = l1DataGasPriceStrk
173176
}
174-
175177
simulatedTransactions[i] = SimulatedTransaction{
176178
TransactionTrace: trace,
177179
FeeEstimation: FeeEstimate{

sync/sync.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,11 @@ func (s *Synchronizer) fetchAndStorePending(ctx context.Context) error {
565565
return err
566566
}
567567

568+
pendingBlock.Number = head.Number + 1
568569
newClasses, err := s.fetchUnknownClasses(ctx, pendingStateUpdate)
569570
if err != nil {
570571
return err
571572
}
572-
573573
s.log.Debugw("Found pending block", "txns", pendingBlock.TransactionCount)
574574
return s.StorePending(&Pending{
575575
Block: pendingBlock,
@@ -688,6 +688,8 @@ func (s *Synchronizer) storeEmptyPending(latestHeader *core.Header) error {
688688
L1GasPriceETH: latestHeader.L1GasPriceETH,
689689
L1GasPriceSTRK: latestHeader.L1GasPriceSTRK,
690690
L2GasPrice: latestHeader.L2GasPrice,
691+
L1DataGasPrice: latestHeader.L1DataGasPrice,
692+
L1DAMode: latestHeader.L1DAMode,
691693
},
692694
Transactions: make([]core.Transaction, 0),
693695
Receipts: receipts,

vm/rust/src/lib.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ use execution::process_transaction;
1111
use serde::Deserialize;
1212
use serde_json::json;
1313
use std::{
14-
ffi::{c_char, c_longlong, c_uchar, c_ulonglong, c_void, CStr, CString},
15-
slice,
16-
sync::Arc,
1714
collections::BTreeMap,
15+
ffi::{c_char, c_longlong, c_uchar, c_ulonglong, c_void, CStr, CString},
1816
fs::File,
1917
io::Read,
2018
path::Path,
19+
slice,
20+
sync::Arc,
2121
};
2222

2323
use anyhow::Result;
@@ -67,8 +67,8 @@ use starknet_api::{
6767
use starknet_types_core::felt::Felt;
6868
use std::str::FromStr;
6969
type StarkFelt = Felt;
70-
use once_cell::sync::Lazy;
7170
use anyhow::Context;
71+
use once_cell::sync::Lazy;
7272

7373
// Allow users to call CONSTRUCTOR entry point type which has fixed entry_point_felt "0x28ffe4ff0f226a9107253e17a904099aa4f63a02a5621de0576e5aa71bc5194"
7474
pub static CONSTRUCTOR_ENTRY_POINT_FELT: Lazy<StarkFelt> = Lazy::new(|| {
@@ -707,11 +707,14 @@ fn build_block_context(
707707

708708
#[allow(static_mut_refs)]
709709
fn get_versioned_constants(version: *const c_char) -> VersionedConstants {
710-
let starknet_version = unsafe { CStr::from_ptr(version) }.to_str()
710+
let starknet_version = unsafe { CStr::from_ptr(version) }
711+
.to_str()
711712
.ok()
712713
.and_then(|version_str| StarknetVersion::try_from(version_str).ok());
713714

714-
if let (Some(custom_constants), Some(version)) = (unsafe { &CUSTOM_VERSIONED_CONSTANTS }, starknet_version) {
715+
if let (Some(custom_constants), Some(version)) =
716+
(unsafe { &CUSTOM_VERSIONED_CONSTANTS }, starknet_version)
717+
{
715718
if let Some(constants) = custom_constants.0.get(&version) {
716719
return constants.clone();
717720
}
@@ -731,15 +734,18 @@ impl VersionedConstantsMap {
731734
let mut result = BTreeMap::new();
732735

733736
for (version, path) in version_with_path {
734-
let mut file = File::open(Path::new(&path)).with_context(|| format!("Failed to open file: {}", path))?;
737+
let mut file = File::open(Path::new(&path))
738+
.with_context(|| format!("Failed to open file: {}", path))?;
735739

736740
let mut contents = String::new();
737-
file.read_to_string(&mut contents).with_context(|| format!("Failed to read contents of file: {}", path))?;
741+
file.read_to_string(&mut contents)
742+
.with_context(|| format!("Failed to read contents of file: {}", path))?;
738743

739-
let constants: VersionedConstants =
740-
serde_json::from_str(&contents).with_context(|| format!("Failed to parse JSON in file: {}", path))?;
744+
let constants: VersionedConstants = serde_json::from_str(&contents)
745+
.with_context(|| format!("Failed to parse JSON in file: {}", path))?;
741746

742-
let parsed_version = StarknetVersion::try_from(version.as_str()).with_context(|| format!("Failed to parse version string: {}", version))?;
747+
let parsed_version = StarknetVersion::try_from(version.as_str())
748+
.with_context(|| format!("Failed to parse version string: {}", version))?;
743749

744750
result.insert(parsed_version, constants);
745751
}
@@ -764,19 +770,21 @@ pub extern "C" fn setVersionedConstants(json_bytes: *const c_char) -> *const c_c
764770
}
765771
};
766772

767-
let versioned_constants_files_paths: Result<BTreeMap<String, String>, _> = serde_json::from_str(json_str);
773+
let versioned_constants_files_paths: Result<BTreeMap<String, String>, _> =
774+
serde_json::from_str(json_str);
768775
if let Ok(paths) = versioned_constants_files_paths {
769776
match VersionedConstantsMap::from_file(paths) {
770-
Ok(custom_constants) => {
771-
unsafe {
772-
CUSTOM_VERSIONED_CONSTANTS = Some(custom_constants);
773-
return CString::new("").unwrap().into_raw();
774-
}
777+
Ok(custom_constants) => unsafe {
778+
CUSTOM_VERSIONED_CONSTANTS = Some(custom_constants);
779+
return CString::new("").unwrap().into_raw();
775780
},
776781
Err(e) => {
777-
return CString::new(format!("Failed to load versioned constants from paths: {}", e))
778-
.unwrap()
779-
.into_raw();
782+
return CString::new(format!(
783+
"Failed to load versioned constants from paths: {}",
784+
e
785+
))
786+
.unwrap()
787+
.into_raw();
780788
}
781789
}
782790
} else {

0 commit comments

Comments
 (0)