fix(revive-eth-rpc): Update to pezkuwi-subxt with pezsp_runtime support

- Add workspace exclude for vendor/pezkuwi-subxt to prevent
  workspace inheritance conflicts
- Update pezkuwi-subxt codegen to use ::pezsp_runtime::DispatchError
  directly instead of runtime_types path that doesn't exist due to
  substitute_type
- Add From implementations for various pezkuwi_subxt error types
  (EventsError, ExtrinsicError, BlockError, BackendError,
  RuntimeApiError, ConstantError, OnlineClientError)
- Update StorageApi to use StorageClientAt with new try_fetch API
- Fix RuntimeApiError pattern matching for error handling
- Update substitute_type entries to use pezkuwi_subxt paths
- Rename migration table from eth_to_substrate_blocks to
  eth_to_bizinikiwi_blocks for consistency
- Regenerate SQLX query cache for bizinikiwi table names
This commit is contained in:
2025-12-19 19:39:48 +03:00
parent fdd023c499
commit a15cc1d76c
20 changed files with 610 additions and 789 deletions
@@ -23,7 +23,7 @@ use crate::{
use jsonrpsee::core::async_trait;
use pezsp_core::H256;
use std::sync::Arc;
use subxt::{backend::legacy::LegacyRpcMethods, OnlineClient};
use pezkuwi_subxt::{backend::legacy::LegacyRpcMethods, OnlineClient};
use tokio::sync::RwLock;
/// BlockInfoProvider cache and retrieves information about blocks.
@@ -75,7 +75,7 @@ impl SubxtBlockInfoProvider {
api: OnlineClient<SrcChainConfig>,
rpc: LegacyRpcMethods<SrcChainConfig>,
) -> Result<Self, ClientError> {
let latest = Arc::new(api.blocks().at_latest().await?);
let latest = Arc::new(api.blocks().at_latest().await.map_err(pezkuwi_subxt::Error::from)?);
Ok(Self {
api,
rpc,
@@ -127,8 +127,8 @@ impl BlockInfoProvider for SubxtBlockInfoProvider {
match self.api.blocks().at(hash).await {
Ok(block) => Ok(Some(Arc::new(block))),
Err(subxt::Error::Block(subxt::error::BlockError::NotFound(_))) => Ok(None),
Err(err) => Err(err.into()),
Err(pezkuwi_subxt::error::BlockError::BlockNotFound { .. }) => Ok(None),
Err(err) => Err(pezkuwi_subxt::Error::from(err).into()),
}
}
@@ -148,8 +148,8 @@ impl BlockInfoProvider for SubxtBlockInfoProvider {
match self.api.blocks().at(*hash).await {
Ok(block) => Ok(Some(Arc::new(block))),
Err(subxt::Error::Block(subxt::error::BlockError::NotFound(_))) => Ok(None),
Err(err) => Err(err.into()),
Err(pezkuwi_subxt::error::BlockError::BlockNotFound { .. }) => Ok(None),
Err(err) => Err(pezkuwi_subxt::Error::from(err).into()),
}
}
}
+55 -12
View File
@@ -39,7 +39,7 @@ use pezsp_weights::Weight;
use runtime_api::RuntimeApi;
use std::{ops::Range, sync::Arc, time::Duration};
use storage_api::StorageApi;
use subxt::{
use pezkuwi_subxt::{
backend::{
legacy::{rpc_methods::SystemHealth, LegacyRpcMethods},
rpc::{
@@ -48,14 +48,14 @@ use subxt::{
},
},
config::{HashFor, Header},
ext::subxt_rpcs::rpc_params,
ext::pezkuwi_subxt_rpcs::rpc_params,
Config, OnlineClient,
};
use thiserror::Error;
use tokio::sync::Mutex;
/// The bizinikiwi block type.
pub type BizinikiwiBlock = subxt::blocks::Block<SrcChainConfig, OnlineClient<SrcChainConfig>>;
pub type BizinikiwiBlock = pezkuwi_subxt::blocks::Block<SrcChainConfig, OnlineClient<SrcChainConfig>>;
/// The bizinikiwi block header.
pub type BizinikiwiBlockHeader = <SrcChainConfig as Config>::Header;
@@ -84,11 +84,11 @@ pub enum ClientError {
/// A [`jsonrpsee::core::ClientError`] wrapper error.
#[error(transparent)]
Jsonrpsee(#[from] jsonrpsee::core::ClientError),
/// A [`subxt::Error`] wrapper error.
/// A [`pezkuwi_subxt::Error`] wrapper error.
#[error(transparent)]
SubxtError(#[from] subxt::Error),
SubxtError(#[from] pezkuwi_subxt::Error),
#[error(transparent)]
RpcError(#[from] subxt::ext::subxt_rpcs::Error),
RpcError(#[from] pezkuwi_subxt::ext::pezkuwi_subxt_rpcs::Error),
/// A [`sqlx::Error`] wrapper error.
#[error(transparent)]
SqlxError(#[from] sqlx::Error),
@@ -131,6 +131,49 @@ pub enum ClientError {
#[error("Receipt data length mismatch")]
ReceiptDataLengthMismatch,
}
impl From<pezkuwi_subxt::error::EventsError> for ClientError {
fn from(err: pezkuwi_subxt::error::EventsError) -> Self {
ClientError::SubxtError(pezkuwi_subxt::Error::from(err))
}
}
impl From<pezkuwi_subxt::error::ExtrinsicError> for ClientError {
fn from(err: pezkuwi_subxt::error::ExtrinsicError) -> Self {
ClientError::SubxtError(pezkuwi_subxt::Error::from(err))
}
}
impl From<pezkuwi_subxt::error::BlockError> for ClientError {
fn from(err: pezkuwi_subxt::error::BlockError) -> Self {
ClientError::SubxtError(pezkuwi_subxt::Error::from(err))
}
}
impl From<pezkuwi_subxt::error::BackendError> for ClientError {
fn from(err: pezkuwi_subxt::error::BackendError) -> Self {
ClientError::SubxtError(pezkuwi_subxt::Error::from(err))
}
}
impl From<pezkuwi_subxt::error::RuntimeApiError> for ClientError {
fn from(err: pezkuwi_subxt::error::RuntimeApiError) -> Self {
ClientError::SubxtError(pezkuwi_subxt::Error::from(err))
}
}
impl From<pezkuwi_subxt::error::ConstantError> for ClientError {
fn from(err: pezkuwi_subxt::error::ConstantError) -> Self {
ClientError::SubxtError(pezkuwi_subxt::Error::from(err))
}
}
impl From<pezkuwi_subxt::error::OnlineClientError> for ClientError {
fn from(err: pezkuwi_subxt::error::OnlineClientError) -> Self {
ClientError::SubxtError(pezkuwi_subxt::Error::from(err))
}
}
const LOG_TARGET: &str = "eth-rpc::client";
const REVERT_CODE: i32 = 3;
@@ -139,10 +182,10 @@ const NOTIFIER_CAPACITY: usize = 16;
impl From<ClientError> for ErrorObjectOwned {
fn from(err: ClientError) -> Self {
match err {
ClientError::SubxtError(subxt::Error::Rpc(subxt::error::RpcError::ClientError(
subxt::ext::subxt_rpcs::Error::User(err),
))) |
ClientError::RpcError(subxt::ext::subxt_rpcs::Error::User(err)) =>
ClientError::SubxtError(pezkuwi_subxt::Error::OtherRpcClientError(
pezkuwi_subxt::ext::pezkuwi_subxt_rpcs::Error::User(err),
)) |
ClientError::RpcError(pezkuwi_subxt::ext::pezkuwi_subxt_rpcs::Error::User(err)) =>
ErrorObjectOwned::owned::<Vec<u8>>(err.code, err.message, None),
ClientError::TransactError(EthTransactError::Data(data)) => {
let msg = match decode_revert_reason(&data) {
@@ -433,7 +476,7 @@ impl Client {
/// Get the storage API for the given block.
pub fn storage_api(&self, block_hash: H256) -> StorageApi {
StorageApi::new(self.api.storage().at(block_hash))
StorageApi::new(self.api.storage().at(block_hash), block_hash)
}
/// Get the runtime API for the given block.
@@ -454,7 +497,7 @@ impl Client {
/// Expose the transaction API.
pub async fn submit(
&self,
call: subxt::tx::DefaultPayload<EthTransact>,
call: pezkuwi_subxt::tx::DefaultPayload<EthTransact>,
) -> Result<H256, ClientError> {
let ext = self.api.tx().create_unsigned(&call).map_err(ClientError::from)?;
let hash: H256 = self
@@ -30,18 +30,21 @@ use pezpallet_revive::{
};
use pezsp_core::H256;
use pezsp_timestamp::Timestamp;
use subxt::{error::MetadataError, ext::subxt_rpcs::UserError, Error::Metadata, OnlineClient};
use pezkuwi_subxt::{
error::RuntimeApiError,
OnlineClient,
};
const LOG_TARGET: &str = "eth-rpc::runtime_api";
/// A Wrapper around subxt Runtime API
#[derive(Clone)]
pub struct RuntimeApi(subxt::runtime_api::RuntimeApi<SrcChainConfig, OnlineClient<SrcChainConfig>>);
pub struct RuntimeApi(pezkuwi_subxt::runtime_api::RuntimeApi<SrcChainConfig, OnlineClient<SrcChainConfig>>);
impl RuntimeApi {
/// Create a new instance.
pub fn new(
api: subxt::runtime_api::RuntimeApi<SrcChainConfig, OnlineClient<SrcChainConfig>>,
api: pezkuwi_subxt::runtime_api::RuntimeApi<SrcChainConfig, OnlineClient<SrcChainConfig>>,
) -> Self {
Self(api)
}
@@ -93,17 +96,19 @@ impl RuntimeApi {
match err {
// This will be hit if subxt metadata (subxt uses the latest finalized block
// metadata when the eth-rpc starts) does not contain the new method
Metadata(MetadataError::RuntimeMethodNotFound(name)) => {
log::debug!(target: LOG_TARGET, "Method {name:?} not found falling back to eth_transact");
RuntimeApiError::OfflineError(ref inner)
if matches!(inner, pezkuwi_subxt::ext::pezkuwi_subxt_core::error::RuntimeApiError::MethodNotFound { .. }) =>
{
log::debug!(target: LOG_TARGET, "Method not found falling back to eth_transact");
let payload = subxt_client::apis().revive_api().eth_transact(tx.into());
self.0.call(payload).await
},
// This will be hit if we are trying to hit a block where the runtime did not
// have this new runtime `eth_transact_with_config` defined
subxt::Error::Rpc(subxt::error::RpcError::ClientError(
subxt::ext::subxt_rpcs::Error::User(UserError { message, .. }),
)) if message.contains("eth_transact_with_config is not found") => {
log::debug!(target: LOG_TARGET, "{message:?} not found falling back to eth_transact");
RuntimeApiError::CannotCallApi(ref backend_err)
if format!("{backend_err}").contains("eth_transact_with_config is not found") =>
{
log::debug!(target: LOG_TARGET, "eth_transact_with_config not found falling back to eth_transact");
let payload = subxt_client::apis().revive_api().eth_transact(tx.into());
self.0.call(payload).await
},
@@ -23,16 +23,17 @@ use crate::{
},
ClientError, H160,
};
use subxt::{storage::Storage, OnlineClient};
use pezkuwi_subxt::{storage::StorageClientAt, OnlineClient};
use pezsp_core::H256;
/// A wrapper around the Bizinikiwi Storage API.
#[derive(Clone)]
pub struct StorageApi(Storage<SrcChainConfig, OnlineClient<SrcChainConfig>>);
pub struct StorageApi(StorageClientAt<SrcChainConfig, OnlineClient<SrcChainConfig>>, H256);
impl StorageApi {
/// Create a new instance of the StorageApi.
pub fn new(api: Storage<SrcChainConfig, OnlineClient<SrcChainConfig>>) -> Self {
Self(api)
pub fn new(api: StorageClientAt<SrcChainConfig, OnlineClient<SrcChainConfig>>, block_hash: H256) -> Self {
Self(api, block_hash)
}
/// Get the contract info for the given contract address.
@@ -41,12 +42,16 @@ impl StorageApi {
contract_address: &H160,
) -> Result<ContractInfo, ClientError> {
// TODO: remove once subxt is updated
let contract_address: subxt::utils::H160 = contract_address.0.into();
let contract_address: pezkuwi_subxt::utils::H160 = contract_address.0.into();
let query = subxt_client::storage().revive().account_info_of(contract_address);
let Some(info) = self.0.fetch(&query).await? else {
let query = subxt_client::storage().revive().account_info_of();
let Some(storage_value) = self.0.try_fetch(query, (contract_address,)).await
.map_err(|e| ClientError::SubxtError(e.into()))?
else {
return Err(ClientError::ContractNotFound);
};
let info = storage_value.decode()
.map_err(|e| ClientError::SubxtError(pezkuwi_subxt::Error::from(e)))?;
let AccountType::Contract(contract_info) = info.account_type else {
return Err(ClientError::ContractNotFound);
@@ -33,7 +33,7 @@ use pezpallet_revive::{
};
use pezsp_core::keccak_256;
use std::{future::Future, pin::Pin, sync::Arc};
use subxt::{blocks::ExtrinsicDetails, OnlineClient};
use pezkuwi_subxt::{blocks::ExtrinsicDetails, OnlineClient};
type FetchReceiptDataFn = Arc<
dyn Fn(H256) -> Pin<Box<dyn Future<Output = Option<Vec<ReceiptGasInfo>>> + Send>> + Send + Sync,
@@ -147,7 +147,7 @@ impl ReceiptExtractor {
&self,
bizinikiwi_block: &BizinikiwiBlock,
eth_block_hash: H256,
ext: subxt::blocks::ExtrinsicDetails<SrcChainConfig, subxt::OnlineClient<SrcChainConfig>>,
ext: pezkuwi_subxt::blocks::ExtrinsicDetails<SrcChainConfig, pezkuwi_subxt::OnlineClient<SrcChainConfig>>,
call: EthTransact,
receipt_gas_info: ReceiptGasInfo,
transaction_index: usize,
@@ -17,46 +17,46 @@
//! The generated subxt client.
//! Generated against a bizinikiwi chain configured with [`pezpallet_revive`] using:
//! subxt metadata --url ws://localhost:9944 -o rpc/revive_chain.scale
pub use subxt::config::PolkadotConfig as SrcChainConfig;
pub use pezkuwi_subxt::config::PolkadotConfig as SrcChainConfig;
#[subxt::subxt(
#[pezkuwi_subxt::subxt(
runtime_metadata_path = "revive_chain.scale",
// Note: subxt hardcodes sp_runtime paths internally but our metadata uses pezsp_runtime
// This requires either forking subxt or using compatible metadata
// TODO remove once subxt use the same U256 type
substitute_type(
path = "primitive_types::U256",
with = "::subxt::utils::Static<::pezsp_core::U256>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_core::U256>"
),
// pezsp_runtime substitutions (rebranded paths from Pezkuwi SDK)
substitute_type(
path = "pezsp_runtime::DispatchError",
with = "::subxt::utils::Static<::pezsp_runtime::DispatchError>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_runtime::DispatchError>"
),
substitute_type(
path = "pezsp_runtime::ModuleError",
with = "::subxt::utils::Static<::pezsp_runtime::ModuleError>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_runtime::ModuleError>"
),
substitute_type(
path = "pezsp_runtime::TokenError",
with = "::subxt::utils::Static<::pezsp_runtime::TokenError>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_runtime::TokenError>"
),
substitute_type(
path = "pezsp_arithmetic::ArithmeticError",
with = "::subxt::utils::Static<::pezsp_runtime::ArithmeticError>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_runtime::ArithmeticError>"
),
substitute_type(
path = "pezsp_runtime::TransactionalError",
with = "::subxt::utils::Static<::pezsp_runtime::TransactionalError>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_runtime::TransactionalError>"
),
substitute_type(
path = "pezsp_runtime::MultiSignature",
with = "::subxt::utils::Static<::pezsp_runtime::MultiSignature>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_runtime::MultiSignature>"
),
substitute_type(
path = "pezsp_runtime::generic::block::Block<A, B, C, D, E>",
with = "::subxt::utils::Static<::pezsp_runtime::generic::Block<
with = "::pezkuwi_subxt::utils::Static<::pezsp_runtime::generic::Block<
::pezsp_runtime::generic::Header<u32, pezsp_runtime::traits::BlakeTwo256>,
::pezsp_runtime::OpaqueExtrinsic
>>"
@@ -65,45 +65,45 @@ pub use subxt::config::PolkadotConfig as SrcChainConfig;
// pezsp_weights substitutions
substitute_type(
path = "pezsp_weights::weight_v2::Weight",
with = "::subxt::utils::Static<::pezsp_weights::Weight>"
with = "::pezkuwi_subxt::utils::Static<::pezsp_weights::Weight>"
),
// pezpallet_revive substitutions (rebranded paths)
substitute_type(
path = "pezpallet_revive::evm::api::debug_rpc_types::Trace",
with = "::subxt::utils::Static<::pezpallet_revive::evm::Trace>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::evm::Trace>"
),
substitute_type(
path = "pezpallet_revive::evm::api::debug_rpc_types::TracerType",
with = "::subxt::utils::Static<::pezpallet_revive::evm::TracerType>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::evm::TracerType>"
),
substitute_type(
path = "pezpallet_revive::evm::api::rpc_types_gen::GenericTransaction",
with = "::subxt::utils::Static<::pezpallet_revive::evm::GenericTransaction>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::evm::GenericTransaction>"
),
substitute_type(
path = "pezpallet_revive::evm::api::rpc_types::DryRunConfig<M>",
with = "::subxt::utils::Static<::pezpallet_revive::evm::DryRunConfig<M>>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::evm::DryRunConfig<M>>"
),
substitute_type(
path = "pezpallet_revive::primitives::EthTransactInfo<B>",
with = "::subxt::utils::Static<::pezpallet_revive::EthTransactInfo<B>>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::EthTransactInfo<B>>"
),
substitute_type(
path = "pezpallet_revive::primitives::EthTransactError",
with = "::subxt::utils::Static<::pezpallet_revive::EthTransactError>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::EthTransactError>"
),
substitute_type(
path = "pezpallet_revive::primitives::ExecReturnValue",
with = "::subxt::utils::Static<::pezpallet_revive::ExecReturnValue>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::ExecReturnValue>"
),
substitute_type(
path = "pezpallet_revive::evm::api::rpc_types_gen::Block",
with = "::subxt::utils::Static<::pezpallet_revive::evm::Block>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::evm::Block>"
),
substitute_type(
path = "pezpallet_revive::evm::block_hash::ReceiptGasInfo",
with = "::subxt::utils::Static<::pezpallet_revive::evm::ReceiptGasInfo>"
with = "::pezkuwi_subxt::utils::Static<::pezpallet_revive::evm::ReceiptGasInfo>"
),
derive_for_all_types = "codec::Encode, codec::Decode"
)]
+9 -9
View File
@@ -38,9 +38,9 @@ use pezpallet_revive::{
},
};
use std::{sync::Arc, thread};
use subxt::{
use pezkuwi_subxt::{
backend::rpc::RpcClient,
ext::subxt_rpcs::rpc_params,
ext::pezkuwi_subxt_rpcs::rpc_params,
tx::{SubmittableTransaction, TxStatus},
OnlineClient,
};
@@ -155,14 +155,14 @@ async fn prepare_bizinikiwi_transactions(
let mut bizinikiwi_txs = Vec::new();
for i in 0..count {
let remark_data = format!("Hello from test {}", i);
let call = subxt::dynamic::tx(
let call = pezkuwi_subxt::dynamic::tx(
"System",
"remark",
vec![subxt::dynamic::Value::from_bytes(remark_data.as_bytes())],
vec![pezkuwi_subxt::dynamic::Value::from_bytes(remark_data.as_bytes())],
);
// Note: Using polkadot config from subxt (external crate)
let params = subxt::config::polkadot::PolkadotExtrinsicParamsBuilder::new()
let params = pezkuwi_subxt::config::polkadot::PolkadotExtrinsicParamsBuilder::new()
.nonce(nonce)
.build();
@@ -423,7 +423,7 @@ async fn test_runtime_api_dry_run_addr_works(client: Arc<WsClient>) -> anyhow::R
let (bytes, _) = pezpallet_revive_fixtures::compile_module("dummy")?;
let payload = subxt_client::apis().revive_api().instantiate(
subxt::utils::AccountId32(origin),
pezkuwi_subxt::utils::AccountId32(origin),
value,
None,
None,
@@ -747,12 +747,12 @@ async fn test_runtime_pallets_address_upload_code(client: Arc<WsClient>) -> anyh
};
// Step 1: Encode the Bizinikiwi upload_code call
let upload_call = subxt::dynamic::tx(
let upload_call = pezkuwi_subxt::dynamic::tx(
"Revive",
"upload_code",
vec![
subxt::dynamic::Value::from_bytes(&bytecode),
subxt::dynamic::Value::u128(u128::max_value()), // storage_deposit_limit
pezkuwi_subxt::dynamic::Value::from_bytes(&bytecode),
pezkuwi_subxt::dynamic::Value::u128(u128::max_value()), // storage_deposit_limit
],
);
let encoded_call = node_client.tx().call_data(&upload_call)?;