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

Commit

Permalink
imp: cache escrow address + update Sovereign SDK dependencies (#90)
Browse files Browse the repository at this point in the history
* imp: caching escrow addresses + updating Sovereign SDK deps revision

* chore: update rpc codebase with latest sovereign changes

* chore: update mocks with latest changes in Sovereign SDK

* fix: BorrowMutError when accessing working_set for obtaining escrow address

* chore: update basecoin rev

* fix: clippy no-default-features
  • Loading branch information
Farhad-Shabani authored Mar 6, 2024
1 parent f49563b commit b5955ab
Show file tree
Hide file tree
Showing 28 changed files with 1,133 additions and 403 deletions.
837 changes: 769 additions & 68 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ tendermint-testgen = { version = "0.34", default-features = false }
tendermint-light-client-verifier = { version = "0.34", default-features = false }

# sovereign dependencies
sov-bank = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
sov-chain-state = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
sov-modules-api = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
sov-state = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
sov-rollup-interface = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
sov-bank = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60" }
sov-chain-state = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60" }
sov-modules-api = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60" }
sov-state = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60" }
sov-rollup-interface = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60" }
34 changes: 18 additions & 16 deletions mocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ tracing = "0.1.36"
typed-builder = "0.18.0"

# internal dependencies
sov-ibc = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "c42dac1" }
sov-ibc-transfer = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "c42dac1" }
sov-celestia-client = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "c42dac1", features = ["test-util"] }
sov-ibc = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "3fe4048" }
sov-ibc-transfer = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "3fe4048" }
sov-celestia-client = { git = "https://github.com/informalsystems/sovereign-ibc.git", rev = "3fe4048", features = ["test-util"] }

# ibc dependencies
ibc-core = { workspace = true }
Expand All @@ -41,8 +41,8 @@ ibc-query = { workspace = true }
ibc-testkit = { git = "https://github.com/cosmos/ibc-rs.git", rev = "552863ec93", default-features = false }

# cosmos dependencies
basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "8c3e924" }
basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "8c3e924" }
basecoin-app = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "e668ec4" }
basecoin-store = { git = "https://github.com/informalsystems/basecoin-rs.git", rev = "e668ec4" }

tendermint = { workspace = true }
tendermint-testgen = { workspace = true }
Expand All @@ -54,12 +54,13 @@ sov-modules-api = { workspace = true }
sov-rollup-interface = { workspace = true }
sov-state = { workspace = true }

sov-celestia-adapter = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8", features = ["native"], optional = true }
sov-mock-da = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8", features = ["native"], optional = true }
sov-modules-stf-blueprint = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
sov-prover-storage-manager = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8", features = ["test-utils"] }
sov-schema-db = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
const-rollup-config = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "a1d9ed8" }
sov-celestia-adapter = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60", features = ["native"], optional = true }
sov-mock-da = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60", features = ["native"], optional = true }
sov-mock-zkvm = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60", features = ["native"], optional = true }
sov-modules-stf-blueprint = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60", features = ["native"], optional = true }
sov-prover-storage-manager = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60", features = ["test-utils"] }
sov-schema-db = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60" }
const-rollup-config = { git = "ssh://[email protected]/informalsystems/sovereign-sdk-wip.git", rev = "5a144d60" }
jmt = { git = "https://github.com/penumbra-zone/jmt.git", rev = "1d007e11cb68aa5ca13e9a5af4a12e6439d5f7b6" }

[dev-dependencies]
Expand All @@ -70,13 +71,14 @@ tracing-subscriber = { version = "0.3", default-features = false, features =
default = ["native"]
native = [
"sov-bank/native",
"sov-celestia-adapter",
"sov-ibc/native",
"sov-ibc-transfer/native",
"sov-chain-state/native",
"sov-modules-api/native",
"sov-modules-stf-blueprint/native",
"sov-state/native",
"sov-mock-da",
"sov-rollup-interface/native",
"sov-ibc/native",
"sov-ibc-transfer/native",
"sov-celestia-adapter",
"sov-mock-da",
"sov-mock-zkvm",
"sov-modules-stf-blueprint",
]
34 changes: 18 additions & 16 deletions mocks/src/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ use serde::de::DeserializeOwned;
use sov_bank::{get_token_address, TokenConfig};
use sov_celestia_adapter::CelestiaService;
use sov_mock_da::MockDaService;
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::{Address, Context};
use sov_modules_api::{Address, Spec};
use sov_modules_stf_blueprint::kernels::basic::BasicKernelGenesisConfig;
use sov_rollup_interface::services::da::DaService;
use typed_builder::TypedBuilder;

pub(crate) type DefaultSpec =
sov_modules_api::default_spec::DefaultSpec<sov_mock_zkvm::MockZkVerifier>;

use crate::sovereign::{celestia_da_service, mock_da_service, GenesisConfig, RollupGenesisConfig};

#[derive(TypedBuilder, Clone, Debug)]
pub struct TestSetupConfig<C: Context, Da: DaService> {
pub struct TestSetupConfig<S: Spec, Da: DaService> {
/// The chain Id of the DA chain.
#[builder(default = ChainId::new("mock-celestia-0").unwrap())]
pub da_chain_id: ChainId,
Expand All @@ -28,21 +30,21 @@ pub struct TestSetupConfig<C: Context, Da: DaService> {
pub rollup_id: ChainId,
/// The runtime configuration.
#[builder(default = RollupGenesisConfig::default())]
pub rollup_genesis_config: RollupGenesisConfig<C>,
pub rollup_genesis_config: RollupGenesisConfig<S>,
/// Sets whether to use manual IBC TAO or not.
#[builder(default = false)]
pub with_manual_tao: bool,
}

impl<C: Context, Da: DaService> TestSetupConfig<C, Da> {
impl<S: Spec, Da: DaService> TestSetupConfig<S, Da> {
/// Returns list of tokens in the bank configuration
pub fn get_tokens(&self) -> &Vec<TokenConfig<C>> {
pub fn get_tokens(&self) -> &Vec<TokenConfig<S>> {
&self.rollup_genesis_config.bank_config.tokens
}

/// Returns the address of the relayer. We use the last address in the list
/// as the relayer address
pub fn get_relayer_address(&self) -> C::Address {
pub fn get_relayer_address(&self) -> S::Address {
self.rollup_genesis_config.bank_config.tokens[0]
.address_and_balances
.last()
Expand All @@ -52,21 +54,21 @@ impl<C: Context, Da: DaService> TestSetupConfig<C, Da> {
}

/// Returns the token address for a given token configuration
pub fn get_token_address(&self, token_cfg: &TokenConfig<C>) -> C::Address {
get_token_address::<C>(
pub fn get_token_address(&self, token_cfg: &TokenConfig<S>) -> S::Address {
get_token_address::<S>(
&token_cfg.token_name,
self.get_relayer_address().as_ref(),
&self.get_relayer_address(),
token_cfg.salt,
)
}

pub fn kernel_genesis_config(&self) -> BasicKernelGenesisConfig<C, Da::Spec> {
pub fn kernel_genesis_config(&self) -> BasicKernelGenesisConfig<S, Da::Spec> {
BasicKernelGenesisConfig {
chain_state: self.rollup_genesis_config.chain_state_config.clone(),
}
}

pub fn runtime_genesis_config(&self) -> GenesisConfig<C, Da::Spec> {
pub fn runtime_genesis_config(&self) -> GenesisConfig<S, Da::Spec> {
GenesisConfig::new(
self.rollup_genesis_config.bank_config.clone(),
self.rollup_genesis_config.ibc_config.clone(),
Expand All @@ -75,14 +77,14 @@ impl<C: Context, Da: DaService> TestSetupConfig<C, Da> {
}
}

pub fn default_config_with_mock_da() -> TestSetupConfig<DefaultContext, MockDaService> {
TestSetupConfig::<DefaultContext, MockDaService>::builder()
pub fn default_config_with_mock_da() -> TestSetupConfig<DefaultSpec, MockDaService> {
TestSetupConfig::<DefaultSpec, MockDaService>::builder()
.da_service(mock_da_service())
.build()
}

pub async fn default_config_with_celestia_da() -> TestSetupConfig<DefaultContext, CelestiaService> {
TestSetupConfig::<DefaultContext, CelestiaService>::builder()
pub async fn default_config_with_celestia_da() -> TestSetupConfig<DefaultSpec, CelestiaService> {
TestSetupConfig::<DefaultSpec, CelestiaService>::builder()
.da_service(celestia_da_service().await)
.build()
}
Expand Down
34 changes: 16 additions & 18 deletions mocks/src/relayer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,47 @@ use ibc_core::host::types::identifiers::Sequence;
use ibc_core::host::ValidationContext;
use sov_celestia_client::types::client_state::sov_client_type;
use sov_mock_da::MockDaService;
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::{Context, WorkingSet};
use sov_modules_api::{Context, Spec, WorkingSet};
use sov_prover_storage_manager::new_orphan_storage;
use sov_rollup_interface::services::da::DaService;
use sov_state::{MerkleProofSpec, ProverStorage};
use tracing::info;

use super::DefaultRelayer;
use crate::configs::{default_config_with_mock_da, TestSetupConfig};
use crate::configs::{default_config_with_mock_da, DefaultSpec, TestSetupConfig};
use crate::cosmos::{dummy_signer, CosmosBuilder, MockTendermint};
use crate::relayer::handle::{Handle, QueryReq, QueryResp};
use crate::relayer::relay::MockRelayer;
use crate::sovereign::{MockRollup, Runtime, DEFAULT_INIT_HEIGHT};

#[derive(Clone)]
pub struct RelayerBuilder<C, Da>
pub struct RelayerBuilder<S, Da>
where
C: Context,
S: Spec,
Da: DaService,
{
setup_cfg: TestSetupConfig<C, Da>,
setup_cfg: TestSetupConfig<S, Da>,
}

impl Default for RelayerBuilder<DefaultContext, MockDaService> {
impl Default for RelayerBuilder<DefaultSpec, MockDaService> {
fn default() -> Self {
Self {
setup_cfg: default_config_with_mock_da(),
}
}
}

impl<C, Da> RelayerBuilder<C, Da>
impl<S, Da> RelayerBuilder<S, Da>
where
C: Context,
S: Spec,
Da: DaService,
{
pub fn new(setup_cfg: TestSetupConfig<C, Da>) -> Self {
pub fn new(setup_cfg: TestSetupConfig<S, Da>) -> Self {
Self { setup_cfg }
}

/// Returns the setup configuration
pub fn setup_cfg(&self) -> &TestSetupConfig<C, Da> {
pub fn setup_cfg(&self) -> &TestSetupConfig<S, Da> {
&self.setup_cfg
}

Expand All @@ -55,20 +54,19 @@ where
}

/// Initializes a mock rollup and a mock Cosmos chain and sets up the relayer between them.
pub async fn setup<S>(self) -> DefaultRelayer<C, Da, S>
pub async fn setup<P>(self) -> DefaultRelayer<S, Da, P>
where
C: Context<Storage = ProverStorage<S>> + Send + Sync,
S: Spec<Storage = ProverStorage<P>> + Send + Sync,
Da: DaService<Error = anyhow::Error> + Clone,
S: MerkleProofSpec + Clone + 'static,
<S as MerkleProofSpec>::Hasher: Send,
MockRollup<C, Da, S>: Handle,
C::GasUnit: Default,
P: MerkleProofSpec + Clone + 'static,
<P as MerkleProofSpec>::Hasher: Send,
MockRollup<S, Da, P>: Handle,
{
let runtime = Runtime::default();

let sender_address = self.setup_cfg.get_relayer_address();

let rollup_ctx = C::new(sender_address.clone(), sender_address, DEFAULT_INIT_HEIGHT);
let rollup_ctx = Context::new(sender_address.clone(), sender_address, DEFAULT_INIT_HEIGHT);

let tmpdir = tempfile::tempdir().unwrap();

Expand Down
13 changes: 6 additions & 7 deletions mocks/src/relayer/handle/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ibc_core::handler::types::events::IbcEvent;
use ibc_core::host::types::path::{ClientConsensusStatePath, Path};
use ibc_core::host::ValidationContext;
use sov_celestia_client::types::client_message::test_util::dummy_sov_header;
use sov_modules_api::{Context, WorkingSet};
use sov_modules_api::{Spec, WorkingSet};
use sov_rollup_interface::services::da::DaService;
use sov_state::{MerkleProofSpec, ProverStorage};
use tracing::info;
Expand All @@ -17,16 +17,15 @@ use crate::sovereign::{MockRollup, RuntimeCall};
use crate::utils::{wait_for_block, MutexUtil};

#[async_trait]
impl<C, Da, S> Handle for MockRollup<C, Da, S>
impl<S, Da, P> Handle for MockRollup<S, Da, P>
where
C: Context<Storage = ProverStorage<S>> + Send + Sync,
S: Spec<Storage = ProverStorage<P>> + Send + Sync,
Da: DaService<Error = anyhow::Error> + Clone,
<Da as DaService>::Spec: Clone,
S: MerkleProofSpec + Clone + 'static,
<S as MerkleProofSpec>::Hasher: Send + Sync,
C::GasUnit: Default,
P: MerkleProofSpec + Clone + 'static,
<P as MerkleProofSpec>::Hasher: Send + Sync,
{
type Message = RuntimeCall<C, Da::Spec>;
type Message = RuntimeCall<S, Da::Spec>;

async fn query(&self, request: QueryReq) -> QueryResp {
info!("rollup: querying app with {:?}", request);
Expand Down
4 changes: 2 additions & 2 deletions mocks/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ mod types {

/// Default concrete type for the relayer between the mock rollup and the
/// mock Cosmos chain.
pub type DefaultRelayer<C, Da, S> =
MockRelayer<MockRollup<C, Da, S>, MockCosmosChain<InMemoryStore>>;
pub type DefaultRelayer<S, Da, P> =
MockRelayer<MockRollup<S, Da, P>, MockCosmosChain<InMemoryStore>>;
}

#[cfg(feature = "native")]
Expand Down
4 changes: 2 additions & 2 deletions mocks/src/relayer/msgs/rollup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ibc_core::primitives::{Signer, Timestamp, ToProto};
use sov_bank::{CallMessage as BankCallMessage, TokenConfig};
use sov_ibc::call::CallMessage;
use sov_ibc::clients::AnyClientState;
use sov_modules_api::Context;
use sov_modules_api::Spec;

use crate::configs::TransferTestConfig;
use crate::cosmos::dummy_tm_client_state;
Expand Down Expand Up @@ -193,7 +193,7 @@ where
}

/// Creates a token with the given configuration
pub fn build_msg_create_token<C: Context>(&self, token: &TokenConfig<C>) -> BankCallMessage<C> {
pub fn build_msg_create_token<S: Spec>(&self, token: &TokenConfig<S>) -> BankCallMessage<S> {
BankCallMessage::CreateToken {
salt: token.salt,
token_name: token.token_name.clone(),
Expand Down
13 changes: 6 additions & 7 deletions mocks/src/sovereign/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@ use ibc_core::host::types::path::{
};
use ibc_core::host::{ExecutionContext, ValidationContext};
use sov_ibc::context::IbcContext;
use sov_modules_api::{Context, WorkingSet};
use sov_modules_api::{Spec, WorkingSet};
use sov_rollup_interface::services::da::DaService;
use sov_state::{MerkleProofSpec, ProverStorage};

use super::MockRollup;
use crate::cosmos::{dummy_tm_client_state, dummy_tm_consensus_state};

impl<C, Da, S> MockRollup<C, Da, S>
impl<S, Da, P> MockRollup<S, Da, P>
where
C: Context<Storage = ProverStorage<S>> + Send + Sync,
S: Spec<Storage = ProverStorage<P>> + Send + Sync,
Da: DaService<Error = anyhow::Error> + Clone,
S: MerkleProofSpec + Clone + 'static,
<S as MerkleProofSpec>::Hasher: Send,
C::GasUnit: Default,
P: MerkleProofSpec + Clone + 'static,
<P as MerkleProofSpec>::Hasher: Send,
{
/// Establishes a tendermint light client on the ibc module
pub async fn setup_client(&mut self, client_chain_id: &ChainId) -> ClientId {
let mut working_set = WorkingSet::new(self.prover_storage());

let mut ibc_ctx: IbcContext<'_, C, <Da as DaService>::Spec> =
let mut ibc_ctx: IbcContext<'_, S, <Da as DaService>::Spec> =
self.ibc_ctx(&mut working_set);

let client_counter = ibc_ctx.client_counter().unwrap();
Expand Down
Loading

0 comments on commit b5955ab

Please sign in to comment.