Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
feat: L1 gas price/fix (#1625)
Browse files Browse the repository at this point in the history
Co-authored-by: Arun Jangra <[email protected]>
Co-authored-by: apoorvsadana <[email protected]>
  • Loading branch information
3 people authored and Gerson2102 committed Jun 2, 2024
1 parent 0f9f63b commit 78a7fe7
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 74 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- test: Deleting tests for wallets
- test: Adding txv3 tests

- feat: L1 gas price/fix

## v0.8.0

- feat: add `TransactionFilter<TxType>` to pallet-starknet `Config`
Expand Down
2 changes: 1 addition & 1 deletion crates/client/l1-gas-price/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct FeeHistory {
/// of the returned range, because this value can be derived from the newest block. Zeroes
/// are returned for pre-EIP-4844 blocks.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub base_fee_per_blob_gas: Vec<u128>,
pub base_fee_per_blob_gas: Vec<String>,
/// An array of block blob gas used ratios. These are calculated as the ratio of gasUsed and
/// gasLimit.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
Expand Down
12 changes: 8 additions & 4 deletions crates/client/l1-gas-price/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ async fn update_gas_price(
// The RPC responds with 301 elements for some reason. It's also just safer to manually
// take the last 300. We choose 300 to get average gas caprice for last one hour (300 * 12 sec block
// time).
let (_, blob_fee_history_one_hour) =
fee_history.result.base_fee_per_blob_gas.split_at(fee_history.result.base_fee_per_blob_gas.len() - 300);

let avg_blob_base_fee = blob_fee_history_one_hour.iter().sum::<u128>() / blob_fee_history_one_hour.len() as u128;
let (_, blob_fee_history_one_hour) = fee_history
.result
.base_fee_per_blob_gas
.split_at(fee_history.result.base_fee_per_blob_gas.len().max(300) - 300);

let avg_blob_base_fee =
blob_fee_history_one_hour.iter().map(|hex_str| u128::from_str_radix(&hex_str[2..], 16).unwrap()).sum::<u128>()
/ blob_fee_history_one_hour.len() as u128;

let eth_gas_price = u128::from_str_radix(
fee_history
Expand Down
32 changes: 20 additions & 12 deletions crates/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use mp_starknet_inherent::{
InherentDataProvider as StarknetInherentDataProvider, InherentError as StarknetInherentError, L1GasPrices,
StarknetInherentData, DEFAULT_SEQUENCER_ADDRESS, SEQ_ADDR_STORAGE_KEY,
};
use pallet_starknet_runtime_api::StarknetRuntimeApi;
use prometheus_endpoint::Registry;
use sc_basic_authorship::ProposerFactory;
use sc_client_api::{Backend, BlockBackend, BlockchainEvents, HeaderBackend};
Expand All @@ -33,7 +34,7 @@ use sc_telemetry::{Telemetry, TelemetryWorker};
use sc_transaction_pool::FullPool;
use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_api::offchain::OffchainStorage;
use sp_api::ConstructRuntimeApi;
use sp_api::{ConstructRuntimeApi, ProvideRuntimeApi};
use sp_consensus_aura::sr25519::AuthorityPair as AuraPair;
use sp_offchain::STORAGE_PREFIX;

Expand Down Expand Up @@ -346,18 +347,25 @@ pub fn new_full(
),
);

// Ensuring we've fetched the latest price before we start the node
futures::executor::block_on(mc_l1_gas_price::worker::run_worker(
ethereum_conf.clone(),
l1_gas_price.clone(),
false,
));
let fees_disabled = client
.runtime_api()
.is_transaction_fee_disabled(client.chain_info().best_hash)
.expect("Failed to get fee status");

task_manager.spawn_handle().spawn(
"l1-gas-prices-worker",
Some(MADARA_TASK_GROUP),
mc_l1_gas_price::worker::run_worker(ethereum_conf.clone(), l1_gas_price.clone(), true),
);
if !fees_disabled {
// Ensuring we've fetched the latest price before we start the node
futures::executor::block_on(mc_l1_gas_price::worker::run_worker(
ethereum_conf.clone(),
l1_gas_price.clone(),
false,
));

task_manager.spawn_handle().spawn(
"l1-gas-prices-worker",
Some(MADARA_TASK_GROUP),
mc_l1_gas_price::worker::run_worker(ethereum_conf.clone(), l1_gas_price.clone(), true),
);
}
}
}

Expand Down
71 changes: 39 additions & 32 deletions docs/content/articles/cn/madara-beast-article.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,32 @@

试想一下,为你的应用程序的特殊需求来量身定制一条区块链——这正是应用链可以提供的
功<!--
-->能。应用链是面向特定应用程序的区块链,开发人员可以灵活调整链的各个方面,从而满
<!--
-->能。应用链是面向特定应用程序的区块链,开发人员可以灵活调整链的各个方面,从而
满足<!--
-->其应用的需求,例如选择不同的哈希函数或自定义共识算法。最棒的是,由于应用链建
立在<!--
-->L1 或 L2 区块链之上,可以继承其强大的安全性,为开发人员提供了两全其美的解决方案。
-->L1 或 L2 区块链之上,可以继承其强大的安全性,为开发人员提供了两全其美的解决方
案。

介绍下 Madara,这是一个将灵活性和极速性能相结合的划时代的排序器。排序器这一组件
负<!--
-->责执行交易并将它们分组到批次中。作为通往属于你的 Starknet 应用链的入口,Madara
为在<!--
-->责执行交易并将它们分组到批次中。作为通往属于你的 Starknet 应用链的入
口,Madara 为在<!--
-->Starknet 生态系统中进行前所未有的实验开辟了广阔的可能性。

在我们深入探讨 Madara 如何为 Starknet 应用链带来强大的能力前,有必要解决一个问
题:为<!--
-->什么开发人员会选择在 Starknet 上构建应用链,而不是直接使<!--
-->用[Starknet 有效性 Rollups](https://starkware.co/resource/scaling-ethereum-navigating-the-blockchain-trilemma/#:~:text=top%20of%20them.-,Validity%20Rollups,-Validity%20rollups%2C%20also)
有人可能会想,Starknet 是否已经足以应对大多数情况。
-->用[Starknet 有效性 Rollups](https://starkware.co/resource/scaling-ethereum-navigating-the-blockchain-trilemma/#:~:text=top%20of%20them.-,Validity%20Rollups,-Validity%20rollups%2C%20also)
人可能会想,Starknet 是否已经足以应对大多数情况。

首先让我们了解下为什么应用链是 Starknet 生态系统中引人注目的扩展方式。

## 为什么选择应用链

Madara 是由 StarkWare 探索团队,也称<!--
-->为[Keep Starknet Strange](https://github.com/keep-starknet-strange)开发的,专门<!--
-->为[Keep Starknet Strange](https://github.com/keep-starknet-strange)开发的,专
门<!--
-->设计用于实现 StarkWare<!--
-->的[分形缩放](https://medium.com/starkware/fractal-scaling-from-l2-to-l3-7fe238ecfb4f)愿<!--
-->景。有许多令人信服的原因让开发人员选择创建一个 Starknet 应用链或 L3,而不是直
Expand All @@ -68,22 +70,23 @@ Madara 是由 StarkWare 探索团队,也称<!--
到 L3<!--
-->的整体成本,最高可达一百万倍。由于应用程序建立在其专用区块链上,从而无需与其
他<!--
-->应用竞争链上资源,吞吐量不受第三方应用活动的影响,这确保了持续平稳的流畅体验。
-->应用竞争链上资源,吞吐量不受第三方应用活动的影响,这确保了持续平稳的流畅体
验。

### 定制化

像 Starknet 和 Ethereum 等通用链采取了多项措施来确保网络对所有人可用,但这导致了
一种<!--
-->受限的环境。通过应用链,开发人员可以微调其应用和基础设施的各个方面,创建量身定
<!--
-->受限的环境。通过应用链,开发人员可以微调其应用和基础设施的各个方面,创建量身
定制<!--
-->的解决方案。不喜欢 Cairo VM 的某个特性?可以在你的应用链中将其排除掉。

### 创新

应用链的可定制性还允许开发人员可以使用目前在 Starknet 中不可用或存在风险的功能。
应<!--
-->用链赋予每个团队自主权,允许他们编写和授权任何所需的代码 hints。这使得应用链能
<!--
-->用链赋予每个团队自主权,允许他们编写和授权任何所需的代码 hints。这使得应用链
能够<!--
-->解锁许多用例,譬如可以在不泄露个人隐私的情况下执行链上 KYC。

## Madara 对应用链堆栈的影响
Expand All @@ -92,57 +95,61 @@ Madara 是由 StarkWare 探索团队,也称<!--

1. **执行:** 执行层定义了区块的执行和状态差异的生成。Madara 提供了在两种执行工
具<!--
-->包(StarkWare 的 [blockifier](https://github.com/starkware-libs/blockifier)<!--
-->包(StarkWare 的
[blockifier](https://github.com/starkware-libs/blockifier)<!--
-->和 LambdaClass 的<!--
-->[starknet_in_rust](https://github.com/lambdaclass/starknet_in_rust)之间切
换的灵活性。无论选择了哪个执行工具包,底层框架都使用 Cairo VM。Cairo 语言有助于
创建可证明的程序,这样就能证明计算被正确执行。
-->[starknet_in_rust](https://github.com/lambdaclass/starknet_in_rust)之间
切换的灵活性。无论选择了哪个执行工具包,底层框架都使用 Cairo VM。Cairo 语言有
助于创建可证明的程序,这样就能证明计算被正确执行。
2. **结算:** 作为有效性 Rollup,Madara 应用链的状态可以仅通过检查其结算层来重
建。通过在 Starknet L2 上更频繁的结算,L3 应用链可以实现更快的硬最终性,而去
中心化的<!--
-->排序层实现更强大的软最终性,因此,在这两方面(硬和软终结性),结算都得到了增<!--
-->排序层实现更强大的软最终性,因此,在这两方面(硬和软终结性),结算都得到了
增<!--
-->强。
3. **排序:** Madara 负责排序过程,可以根据应用的需求进行调整,无论是简单的 FCFS
或<!--
-->PGA,还是像 Narwhall 和 Bullshark 这类更复杂的方案。一些应用链可以选择部署加
密内<!--
-->PGA,还是像 Narwhall 和 Bullshark 这类更复杂的方案。一些应用链可以选择部署
加密内<!--
-->存池,以确保公平排序并减轻 MEV 的影响。
4. **数据可用性:** 数据可用性保证始终可访问完整的状态树,借此向用户提供信心,
即<!--
-->使 Madara 发生故障的情况下,他们也能证明自己拥有资产的所有权。Madara 将为开
发者<!--
-->使 Madara 发生故障的情况下,他们也能证明自己拥有资产的所有权。Madara 将为
开发者<!--
-->提供多种可供选择的数据可用性方案。
5. **治理:** 每个 Madara 应用链可以选择其治理模
型。[Snapshot X](https://twitter.com/SnapshotLabs)提供了一个依赖于存储证明
并<!--
-->完全基于链上的治理系统。其他治理机制也在探索中,譬如原生的 Substrate 治理面
。链上治理是 Madara 的核心价值所在。
-->完全基于链上的治理系统。其他治理机制也在探索中,譬如原生的 Substrate 治理
面板。链上治理是 Madara 的核心价值所在。

![come come](https://lh4.googleusercontent.com/i7bXi2IPV-LTLzEgueA2SPHGULUFDj1OX4IznOQr5BeZe0hcey-VXA5TOV6q9XaVqBGAcYiie7u7uxw7q1ByZxjkPQKHERqKJTxhdDdTSgBQy8smyNO3jEHiNJv7Eqh8BMxjj4fFlQAW6gm-hQMzyIU)

## 进入: Madara

在 Madara 中,通过利用 Substrate 框架并整合 Cairo VM 来执行 Cairo 程序和
Starknet 智能合<!--
-->约,从而增强了 Cairo VM。Substrate 是一个开源 Rust 框架,以其灵活性而闻名,并用
于构<!--
-->约,从而增强了 Cairo VM。Substrate 是一个开源 Rust 框架,以其灵活性而闻名,
用于构<!--
-->建可定制的区块链。与此同时,Cairo VM 专门设计用于高效生成程序执行的有效性证
明。通<!--
-->过在 L2 上使用状态跟踪和智能合约来验证这些证明,应用链确保集成了 Starknet 的安
全性。这样,Madara 利用 Cairo 的强大功能实现了程序执行的可证明性。
-->过在 L2 上使用状态跟踪和智能合约来验证这些证明,应用链确保集成了 Starknet
安全性。这样,Madara 利用 Cairo 的强大功能实现了程序执行的可证明性。

Substrate 框架固有的模块化特性使开发者可以轻松地定制应用链。没有任何强加的假设,
允许你自行整合共识协议、哈希函数、签名方案、存储布局 - 无论你的应用需要什么,
都<!--
-->可以利用 Cairo 来生成证明。无论是 Starknet 还是 Ethereum 上,开发者都可以在继承
底层链<!--
-->可以利用 Cairo 来生成证明。无论是 Starknet 还是 Ethereum 上,开发者都可以在继
承底层链<!--
-->安全性的同时,不受限制的操作,并可被证明。

起初,Madara 将与 Starknet 非常相似,使智能合约可以在 Starknet 生态系统内进行组
合。未<!--
-->来将有更宏伟的计划,因为 Starknet 将与[Herodotus](https://www.herodotus.dev/)集<!--
-->来将有更宏伟的计划,因为 Starknet 将
[Herodotus](https://www.herodotus.dev/)集<!--
-->成,利用 [存储证明](https://book.starknet.io/chapter_8/storage_proofs.html)
现<!--
-->互操作性。存储证明的整合还将使 Madara 应用链能够考虑来自其他链的状态和流动性。
-->互操作性。存储证明的整合还将使 Madara 应用链能够考虑来自其他链的状态和流动
性。

准备好见证由 Madara 开启的 Starknet 新纪元吧。
53 changes: 29 additions & 24 deletions docs/contributor-starter-pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,26 @@ are some key aspects of the mindset that can help you navigate your contribution
journey:

- _Openness to Learning_\
Embrace a mindset of continuous learning and be open to acquiring new knowledge
and skills. Starknet is a recent ecosystem and does have its own unique concepts
and principles. Stay curious, ask questions (there are no dumb questions), and
be willing to explore and understand new concepts.
Embrace a mindset of continuous learning and be open to acquiring new
knowledge and skills. Starknet is a recent ecosystem and does have its own
unique concepts and principles. Stay curious, ask questions (there are no dumb
questions), and be willing to explore and understand new concepts.

- _Patience and Perseverance_\
Contributing to a complex or quickly evolving project takes time and effort. Be
patient with yourself and the learning process. Expect challenges along the way,
but persevere through them. Building expertise and making meaningful contributions
often requires persistence and determination.
Contributing to a complex or quickly evolving project takes time and effort.
Be patient with yourself and the learning process. Expect challenges along the
way, but persevere through them. Building expertise and making meaningful
contributions often requires persistence and determination.

- _Collaboration and Communication_\
Engage with the community, ask for guidance when needed, and seek feedback on your
contributions. Actively participate in GitHub discussions, issues or chat channels.
Be respectful and constructive with other builders.
Engage with the community, ask for guidance when needed, and seek feedback on
your contributions. Actively participate in GitHub discussions, issues or chat
channels. Be respectful and constructive with other builders.

- _Respect for Existing Contributors_\
Recognize and respect the work of existing contributors and maintainers. Appreciate
the efforts of others and collaborate with them in a respectful and inclusive manner.
Recognize and respect the work of existing contributors and maintainers.
Appreciate the efforts of others and collaborate with them in a respectful and
inclusive manner.

With this mindset, you'll participate to Madara and Starknet projects in a
collaborative and productive atmosphere. It's not everything about code but also
Expand All @@ -82,7 +83,8 @@ some valuable and helpful resources.

[The Rust Programming Language Book](https://doc.rust-lang.org/book/): read this
first\
[Rust by Example](https://doc.rust-lang.org/rust-by-example/): practical approach\
[Rust by Example](https://doc.rust-lang.org/rust-by-example/): practical
approach\
[Rustlings](https://github.com/rust-lang/rustlings): Educative and interactive
learning

Expand Down Expand Up @@ -146,17 +148,19 @@ build.
Some key features of Substrate are:

- _Modular Framework_\
Substrate provides a modular framework that allows developers to easily customize
and configure various components of a blockchain network.
Substrate provides a modular framework that allows developers to easily
customize and configure various components of a blockchain network.

- _Efficiency and Scalability_\
Substrate leverages advanced techniques such as in its transaction queue management
to ensure high performance and the ability to handle a large number of transactions.
Substrate leverages advanced techniques such as in its transaction queue
management to ensure high performance and the ability to handle a large number
of transactions.

- _Runtime Upgradability_\
Substrate allows for seamless runtime upgrades, enabling the introduction of new
features or bug fixes in a live blockchain network without requiring a hard fork.
This feature enhances the upgradability and maintainability of the blockchain system.
Substrate allows for seamless runtime upgrades, enabling the introduction of
new features or bug fixes in a live blockchain network without requiring a
hard fork. This feature enhances the upgradability and maintainability of the
blockchain system.

Substrate achieves its modularity through three key components: the **client**,
the **runtime**, and the **primitives**. Those are key concepts of Substrate
Expand Down Expand Up @@ -283,7 +287,8 @@ organized and executed in a secure and deterministic manner.

You can find Madara documentation (work in progress)
[here](https://docs.madara.wtf/).\
You can contribute to this documentation [here](https://github.com/keep-starknet-strange/madara-docs).
You can contribute to this documentation
[here](https://github.com/keep-starknet-strange/madara-docs).

How to contribute?

Expand All @@ -310,8 +315,8 @@ future of Ethereum scaling!
guide](https://docs.github.com/en/get-started/quickstart/hello-world)\
[Madara GitHub repository](https://github.com/keep-starknet-strange/madara)\
[Madara Telegram](https://t.me/MadaraStarknet)\
[Starknet Discord](https://discord.gg/qypnmzkhbc) (Or search for Starknet in discord's
servers browser)
[Starknet Discord](https://discord.gg/qypnmzkhbc) (Or search for Starknet in
discord's servers browser)

## Contribution rewards on OnlyDust <a name="onlydust"/>

Expand Down
2 changes: 1 addition & 1 deletion examples/messaging/eth-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"provider": {
"rpc_endpoint": "https://eth.merkle.io",
"rpc_endpoint": "http://127.0.0.1:8545",
"gas_price_poll_ms": 10000
},
"contracts": {
Expand Down

0 comments on commit 78a7fe7

Please sign in to comment.