mirror of
https://github.com/pezkuwichain/pezkuwi-fellows.git
synced 2026-05-30 15:01:01 +00:00
deploy: 7f673a4f6a
This commit is contained in:
+44
-57
@@ -598,29 +598,23 @@ Client-side developers can encode their desired custom computation logic into th
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>#[extension_decl]
|
||||
mod extension_core {
|
||||
#[extension_decl::config]
|
||||
pub trait Config {
|
||||
type ExtensionId: Codec;
|
||||
}
|
||||
#[extension_decl::view_fns]
|
||||
pub trait ExtensionCore<T: Config> {
|
||||
fn has_extension(id: T::ExtensionId) -> bool;
|
||||
pub mod extension_core {
|
||||
#[extension_decl::extension]
|
||||
pub trait ExtensionCore {
|
||||
type ExtensionId;
|
||||
fn has_extension(id: Self::ExtensionId) -> bool;
|
||||
}
|
||||
}
|
||||
#[extension_decl]
|
||||
mod extension_fungibles {
|
||||
#[extension_decl::config]
|
||||
pub trait Config {
|
||||
type AssetId: Codec;
|
||||
type AccountId: Codec;
|
||||
type Balance: Codec;
|
||||
}
|
||||
|
||||
#[extension_decl::view_fns]
|
||||
pub trait ExtensionFungibles<T: Config> {
|
||||
fn total_supply(asset: T::AssetId) -> T::Balance;
|
||||
fn balance(asset: T::AssetId, who: T::AccountId) -> T::Balance;
|
||||
#[extension_decl]
|
||||
pub mod extension_fungibles {
|
||||
#[extension_decl::extension]
|
||||
pub trait ExtensionFungibles {
|
||||
type AssetId;
|
||||
type Balance;
|
||||
type AccountId;
|
||||
fn total_supply(asset: Self::AssetId) -> Self::Balance;
|
||||
fn balance(asset: Self::AssetId, who: Self::AccountId) -> Self::Balance;
|
||||
}
|
||||
}
|
||||
<span class="boring">}</span></code></pre></pre>
|
||||
@@ -628,38 +622,27 @@ mod extension_fungibles {
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>#[extensions_impl]
|
||||
mod extensions_impl {
|
||||
pub mod extensions {
|
||||
#[extensions_impl::impl_struct]
|
||||
pub struct ExtensionsImpl;
|
||||
|
||||
#[extensions_impl::extensions_config]
|
||||
pub struct ExtensionsConfig;
|
||||
#[extensions_impl::extensions_struct]
|
||||
pub struct Extensions;
|
||||
|
||||
#[extensions_impl::extensions_config_impl]
|
||||
impl extension_core::Config for ExtensionsConfig {
|
||||
#[extensions_impl::extension]
|
||||
impl pvq_extension_core::extension::ExtensionCore for ExtensionsImpl {
|
||||
type ExtensionId = u64;
|
||||
}
|
||||
|
||||
#[extensions_impl::extensions_config_impl]
|
||||
impl extension_fungibles::Config for ExtensionsConfig {
|
||||
type AssetId = u32;
|
||||
type AccountId = [u8; 32];
|
||||
type Balance = u64;
|
||||
}
|
||||
|
||||
#[extensions_impl::extension_struct_impl]
|
||||
impl extension_core::ExtensionCore<ExtensionsConfig> for Extensions {
|
||||
fn has_extension(id: u64) -> bool {
|
||||
fn has_extension(id: Self::ExtensionId) -> bool {
|
||||
matches!(id, 0 | 1)
|
||||
}
|
||||
}
|
||||
|
||||
#[extensions_impl::extension_struct_impl]
|
||||
impl extension_fungibles::ExtensionFungibles<ExtensionsConfig> for Extensions {
|
||||
fn total_supply(asset: u32) -> u64 {
|
||||
200
|
||||
#[extensions_impl::extension]
|
||||
impl pvq_extension_fungibles::extension::ExtensionFungibles for ExtensionsImpl {
|
||||
type AssetId = u32;
|
||||
type AccountId = [u8; 32];
|
||||
type Balance = u64;
|
||||
fn total_supply(_asset: Self::AssetId) -> Self::Balance {
|
||||
100
|
||||
}
|
||||
fn balance(asset: u32, who: [u8; 32]) -> u64 {
|
||||
fn balance(_asset: Self::AssetId, _who: Self::AccountId) -> Self::Balance {
|
||||
100
|
||||
}
|
||||
}
|
||||
@@ -739,7 +722,7 @@ extern "C" {
|
||||
<ul>
|
||||
<li><code>program</code>: PVQ main binary.</li>
|
||||
<li><code>args</code>: PVQ query data.</li>
|
||||
<li><code>gas_limit</code>: Maximum PVM gas limit for the query.</li>
|
||||
<li><code>gas_limit</code>: Maximum PVM gas limit for the query. If not provided, the executor works at no gas metering mode.</li>
|
||||
</ul>
|
||||
<p><strong>Example Rust Implementation</strong>:</p>
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
@@ -748,13 +731,17 @@ extern "C" {
|
||||
&mut self,
|
||||
program: &[u8],
|
||||
args: &[u8],
|
||||
gas_limit: u64,
|
||||
gas_limit: Option<i64>,
|
||||
) -> Result<Vec<u8>, PvqExecutorError> {...}
|
||||
enum PvqExecutorError {
|
||||
|
||||
pub enum PvqExecutorError<UserError> {
|
||||
InvalidProgramFormat,
|
||||
OutOfGas,
|
||||
// Implementors can define additional error variants to differentiate specific panic reasons for debugging purposes
|
||||
Panic,
|
||||
MemoryAccessError(polkavm::MemoryAccessError),
|
||||
Trap,
|
||||
NotEnoughGas,
|
||||
User(UserError),
|
||||
OtherPvmError(polkavm::Error),
|
||||
// Implementors can define additional error variants to differentiate specific panic reasons for internal debugging purposes.
|
||||
}
|
||||
<span class="boring">}</span></code></pre></pre>
|
||||
<p>Additionally, it provides an initialization method that sets up the PVM execution environment and external interfaces by pre-registering the required host functions:</p>
|
||||
@@ -771,7 +758,7 @@ enum PvqExecutorError {
|
||||
<ul>
|
||||
<li><code>program</code>: PVQ binary.</li>
|
||||
<li><code>args</code>: Query arguments that is SCALE-encoded.</li>
|
||||
<li><code>ref_time_limit</code>: Maximum allowed execution time for a single query, measured in reference time units. The conversion between the PVM gas and reference time is a rather important implementation detail.</li>
|
||||
<li><code>gas_limit</code>: Optional gas limit. If not provided, we have the gas limit which corresponds to 2 seconds as maximum execution time the query.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
@@ -783,7 +770,7 @@ enum PvqExecutorError {
|
||||
</span><span class="boring">fn main() {
|
||||
</span>decl_runtime_apis! {
|
||||
pub trait PvqApi {
|
||||
fn execute_query(program: Vec<u8>, args: Vec<u8>, ref_time_limit: u64) -> PvqResult;
|
||||
fn execute_query(program: Vec<u8>, args: Vec<u8>, gas_limit: Option<i64>) -> PvqResult;
|
||||
fn metadata() -> Vec<u8>;
|
||||
}
|
||||
}
|
||||
@@ -811,7 +798,7 @@ enum PvqError {
|
||||
<p>Operands:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>query: BoundedVec<u8, MAX_QUERY_SIZE></code>: Encoded bytes of the tuple <code>(program, args)</code>. <code>MAX_QUERY_SIZE</code> is the generic parameter type size limit (i.e. 2MB).</p>
|
||||
<p><code>query: BoundedVec<u8, MaxPvqSize></code>: Encoded bytes of the tuple <code>(program, args)</code>. <code>MaxPvqSize</code> is the generic parameter type size limit (i.e. 2MB).</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>max_weight: Weight</code>: Maximum weight that the query should take.</p>
|
||||
@@ -823,7 +810,7 @@ enum PvqError {
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>ReportQuery {
|
||||
query: BoundedVec<u8, MAX_QUERY_SIZE>,
|
||||
query: BoundedVec<u8, MaxPvqSize>,
|
||||
max_weight: Weight,
|
||||
info: QueryResponseInfo,
|
||||
}
|
||||
@@ -838,7 +825,7 @@ enum PvqError {
|
||||
<p><code>PvqResult</code> is a variant type:</p>
|
||||
<ul>
|
||||
<li><code>Ok(Vec<u8>)</code>: Successful query result</li>
|
||||
<li><code>Err(PanicReason)</code>: The query panics, the specific panic reason is encoded in the bytes.</li>
|
||||
<li><code>Err(PvqError)</code>: The query panics, the specific panic reason is encoded in the bytes.</li>
|
||||
</ul>
|
||||
<h4 id="errors"><a class="header" href="#errors">Errors</a></h4>
|
||||
<ul>
|
||||
@@ -913,7 +900,7 @@ PVQ does not conflict with them, and it can take advantage of these Pallet View
|
||||
</ul>
|
||||
<h2 id="unresolved-questions-2"><a class="header" href="#unresolved-questions-2">Unresolved Questions</a></h2>
|
||||
<ul>
|
||||
<li>The metadata of PVQ extensions can be integrated into <code>frame-metadata</code>'s <code>CustomMetadata</code> field, but the trade-offs (i.e., compatibility between versions) need examination.</li>
|
||||
<li>The specific conversion between gas and weight has not been finalized and will likely require development of a suitable benchmarking methodology.</li>
|
||||
</ul>
|
||||
<h2 id="future-directions-and-related-material-2"><a class="header" href="#future-directions-and-related-material-2">Future Directions and Related Material</a></h2>
|
||||
<p>Once PVQ and the aforementioned Facade Project are ready, there are opportunities to consolidate overlapping functionality between the two systems. For example, the metadata APIs could potentially be unified to provide a more cohesive interface for runtime information. This would help reduce duplication and improve maintainability while preserving the distinct benefits of each approach.</p>
|
||||
|
||||
@@ -283,29 +283,23 @@ Client-side developers can encode their desired custom computation logic into th
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>#[extension_decl]
|
||||
mod extension_core {
|
||||
#[extension_decl::config]
|
||||
pub trait Config {
|
||||
type ExtensionId: Codec;
|
||||
}
|
||||
#[extension_decl::view_fns]
|
||||
pub trait ExtensionCore<T: Config> {
|
||||
fn has_extension(id: T::ExtensionId) -> bool;
|
||||
pub mod extension_core {
|
||||
#[extension_decl::extension]
|
||||
pub trait ExtensionCore {
|
||||
type ExtensionId;
|
||||
fn has_extension(id: Self::ExtensionId) -> bool;
|
||||
}
|
||||
}
|
||||
#[extension_decl]
|
||||
mod extension_fungibles {
|
||||
#[extension_decl::config]
|
||||
pub trait Config {
|
||||
type AssetId: Codec;
|
||||
type AccountId: Codec;
|
||||
type Balance: Codec;
|
||||
}
|
||||
|
||||
#[extension_decl::view_fns]
|
||||
pub trait ExtensionFungibles<T: Config> {
|
||||
fn total_supply(asset: T::AssetId) -> T::Balance;
|
||||
fn balance(asset: T::AssetId, who: T::AccountId) -> T::Balance;
|
||||
#[extension_decl]
|
||||
pub mod extension_fungibles {
|
||||
#[extension_decl::extension]
|
||||
pub trait ExtensionFungibles {
|
||||
type AssetId;
|
||||
type Balance;
|
||||
type AccountId;
|
||||
fn total_supply(asset: Self::AssetId) -> Self::Balance;
|
||||
fn balance(asset: Self::AssetId, who: Self::AccountId) -> Self::Balance;
|
||||
}
|
||||
}
|
||||
<span class="boring">}</span></code></pre></pre>
|
||||
@@ -313,38 +307,27 @@ mod extension_fungibles {
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>#[extensions_impl]
|
||||
mod extensions_impl {
|
||||
pub mod extensions {
|
||||
#[extensions_impl::impl_struct]
|
||||
pub struct ExtensionsImpl;
|
||||
|
||||
#[extensions_impl::extensions_config]
|
||||
pub struct ExtensionsConfig;
|
||||
#[extensions_impl::extensions_struct]
|
||||
pub struct Extensions;
|
||||
|
||||
#[extensions_impl::extensions_config_impl]
|
||||
impl extension_core::Config for ExtensionsConfig {
|
||||
#[extensions_impl::extension]
|
||||
impl pvq_extension_core::extension::ExtensionCore for ExtensionsImpl {
|
||||
type ExtensionId = u64;
|
||||
}
|
||||
|
||||
#[extensions_impl::extensions_config_impl]
|
||||
impl extension_fungibles::Config for ExtensionsConfig {
|
||||
type AssetId = u32;
|
||||
type AccountId = [u8; 32];
|
||||
type Balance = u64;
|
||||
}
|
||||
|
||||
#[extensions_impl::extension_struct_impl]
|
||||
impl extension_core::ExtensionCore<ExtensionsConfig> for Extensions {
|
||||
fn has_extension(id: u64) -> bool {
|
||||
fn has_extension(id: Self::ExtensionId) -> bool {
|
||||
matches!(id, 0 | 1)
|
||||
}
|
||||
}
|
||||
|
||||
#[extensions_impl::extension_struct_impl]
|
||||
impl extension_fungibles::ExtensionFungibles<ExtensionsConfig> for Extensions {
|
||||
fn total_supply(asset: u32) -> u64 {
|
||||
200
|
||||
#[extensions_impl::extension]
|
||||
impl pvq_extension_fungibles::extension::ExtensionFungibles for ExtensionsImpl {
|
||||
type AssetId = u32;
|
||||
type AccountId = [u8; 32];
|
||||
type Balance = u64;
|
||||
fn total_supply(_asset: Self::AssetId) -> Self::Balance {
|
||||
100
|
||||
}
|
||||
fn balance(asset: u32, who: [u8; 32]) -> u64 {
|
||||
fn balance(_asset: Self::AssetId, _who: Self::AccountId) -> Self::Balance {
|
||||
100
|
||||
}
|
||||
}
|
||||
@@ -424,7 +407,7 @@ extern "C" {
|
||||
<ul>
|
||||
<li><code>program</code>: PVQ main binary.</li>
|
||||
<li><code>args</code>: PVQ query data.</li>
|
||||
<li><code>gas_limit</code>: Maximum PVM gas limit for the query.</li>
|
||||
<li><code>gas_limit</code>: Maximum PVM gas limit for the query. If not provided, the executor works at no gas metering mode.</li>
|
||||
</ul>
|
||||
<p><strong>Example Rust Implementation</strong>:</p>
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
@@ -433,13 +416,17 @@ extern "C" {
|
||||
&mut self,
|
||||
program: &[u8],
|
||||
args: &[u8],
|
||||
gas_limit: u64,
|
||||
gas_limit: Option<i64>,
|
||||
) -> Result<Vec<u8>, PvqExecutorError> {...}
|
||||
enum PvqExecutorError {
|
||||
|
||||
pub enum PvqExecutorError<UserError> {
|
||||
InvalidProgramFormat,
|
||||
OutOfGas,
|
||||
// Implementors can define additional error variants to differentiate specific panic reasons for debugging purposes
|
||||
Panic,
|
||||
MemoryAccessError(polkavm::MemoryAccessError),
|
||||
Trap,
|
||||
NotEnoughGas,
|
||||
User(UserError),
|
||||
OtherPvmError(polkavm::Error),
|
||||
// Implementors can define additional error variants to differentiate specific panic reasons for internal debugging purposes.
|
||||
}
|
||||
<span class="boring">}</span></code></pre></pre>
|
||||
<p>Additionally, it provides an initialization method that sets up the PVM execution environment and external interfaces by pre-registering the required host functions:</p>
|
||||
@@ -456,7 +443,7 @@ enum PvqExecutorError {
|
||||
<ul>
|
||||
<li><code>program</code>: PVQ binary.</li>
|
||||
<li><code>args</code>: Query arguments that is SCALE-encoded.</li>
|
||||
<li><code>ref_time_limit</code>: Maximum allowed execution time for a single query, measured in reference time units. The conversion between the PVM gas and reference time is a rather important implementation detail.</li>
|
||||
<li><code>gas_limit</code>: Optional gas limit. If not provided, we have the gas limit which corresponds to 2 seconds as maximum execution time the query.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
@@ -468,7 +455,7 @@ enum PvqExecutorError {
|
||||
</span><span class="boring">fn main() {
|
||||
</span>decl_runtime_apis! {
|
||||
pub trait PvqApi {
|
||||
fn execute_query(program: Vec<u8>, args: Vec<u8>, ref_time_limit: u64) -> PvqResult;
|
||||
fn execute_query(program: Vec<u8>, args: Vec<u8>, gas_limit: Option<i64>) -> PvqResult;
|
||||
fn metadata() -> Vec<u8>;
|
||||
}
|
||||
}
|
||||
@@ -496,7 +483,7 @@ enum PvqError {
|
||||
<p>Operands:</p>
|
||||
<ul>
|
||||
<li>
|
||||
<p><code>query: BoundedVec<u8, MAX_QUERY_SIZE></code>: Encoded bytes of the tuple <code>(program, args)</code>. <code>MAX_QUERY_SIZE</code> is the generic parameter type size limit (i.e. 2MB).</p>
|
||||
<p><code>query: BoundedVec<u8, MaxPvqSize></code>: Encoded bytes of the tuple <code>(program, args)</code>. <code>MaxPvqSize</code> is the generic parameter type size limit (i.e. 2MB).</p>
|
||||
</li>
|
||||
<li>
|
||||
<p><code>max_weight: Weight</code>: Maximum weight that the query should take.</p>
|
||||
@@ -508,7 +495,7 @@ enum PvqError {
|
||||
<pre><pre class="playground"><code class="language-rust"><span class="boring">#![allow(unused)]
|
||||
</span><span class="boring">fn main() {
|
||||
</span>ReportQuery {
|
||||
query: BoundedVec<u8, MAX_QUERY_SIZE>,
|
||||
query: BoundedVec<u8, MaxPvqSize>,
|
||||
max_weight: Weight,
|
||||
info: QueryResponseInfo,
|
||||
}
|
||||
@@ -523,7 +510,7 @@ enum PvqError {
|
||||
<p><code>PvqResult</code> is a variant type:</p>
|
||||
<ul>
|
||||
<li><code>Ok(Vec<u8>)</code>: Successful query result</li>
|
||||
<li><code>Err(PanicReason)</code>: The query panics, the specific panic reason is encoded in the bytes.</li>
|
||||
<li><code>Err(PvqError)</code>: The query panics, the specific panic reason is encoded in the bytes.</li>
|
||||
</ul>
|
||||
<h4 id="errors"><a class="header" href="#errors">Errors</a></h4>
|
||||
<ul>
|
||||
@@ -598,7 +585,7 @@ PVQ does not conflict with them, and it can take advantage of these Pallet View
|
||||
</ul>
|
||||
<h2 id="unresolved-questions"><a class="header" href="#unresolved-questions">Unresolved Questions</a></h2>
|
||||
<ul>
|
||||
<li>The metadata of PVQ extensions can be integrated into <code>frame-metadata</code>'s <code>CustomMetadata</code> field, but the trade-offs (i.e., compatibility between versions) need examination.</li>
|
||||
<li>The specific conversion between gas and weight has not been finalized and will likely require development of a suitable benchmarking methodology.</li>
|
||||
</ul>
|
||||
<h2 id="future-directions-and-related-material"><a class="header" href="#future-directions-and-related-material">Future Directions and Related Material</a></h2>
|
||||
<p>Once PVQ and the aforementioned Facade Project are ready, there are opportunities to consolidate overlapping functionality between the two systems. For example, the metadata APIs could potentially be unified to provide a more cohesive interface for runtime information. This would help reduce duplication and improve maintainability while preserving the distinct benefits of each approach.</p>
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user