diff --git a/Cargo.lock b/Cargo.lock index a4827929..6b2138a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,9 +101,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.73" +version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0" +checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ "proc-macro2", "quote", @@ -295,9 +295,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "bitvec" @@ -577,9 +577,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" +checksum = "0f32d04922c60427da6f9fef14d042d9edddef64cb9d4ce0d64d0685fbeb1fd3" [[package]] name = "derive_more" @@ -640,9 +640,9 @@ dependencies = [ [[package]] name = "ed25519" -version = "2.2.2" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60f6d271ca33075c88028be6f04d502853d63a5ece419d269c15315d4fc1cf1d" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ "pkcs8", "signature", @@ -1065,7 +1065,7 @@ dependencies = [ [[package]] name = "ibc" version = "0.46.0" -source = "git+https://github.com/cosmos/ibc-rs?rev=87b0bd3#87b0bd349bbd829f3206b295604a51a0a31a1d00" +source = "git+https://github.com/cosmos/ibc-rs?rev=52ea3ef#52ea3ef26d464bf5a917aeb810d56b1e08a61322" dependencies = [ "bytes", "derive_more", @@ -1077,8 +1077,8 @@ dependencies = [ "primitive-types", "prost", "serde", + "serde-json-wasm", "serde_derive", - "serde_json", "sha2 0.10.8", "subtle-encoding", "tendermint", @@ -1092,7 +1092,7 @@ dependencies = [ [[package]] name = "ibc-derive" version = "0.3.0" -source = "git+https://github.com/cosmos/ibc-rs?rev=87b0bd3#87b0bd349bbd829f3206b295604a51a0a31a1d00" +source = "git+https://github.com/cosmos/ibc-rs?rev=52ea3ef#52ea3ef26d464bf5a917aeb810d56b1e08a61322" dependencies = [ "darling", "proc-macro2", @@ -1120,7 +1120,7 @@ dependencies = [ [[package]] name = "ibc-query" version = "0.46.0" -source = "git+https://github.com/cosmos/ibc-rs?rev=87b0bd3#87b0bd349bbd829f3206b295604a51a0a31a1d00" +source = "git+https://github.com/cosmos/ibc-rs?rev=52ea3ef#52ea3ef26d464bf5a917aeb810d56b1e08a61322" dependencies = [ "displaydoc", "ibc", @@ -1303,9 +1303,9 @@ checksum = "da2479e8c062e40bf0066ffa0bc823de0a9368974af99c9f6df941d2c231e03f" [[package]] name = "lock_api" -version = "0.4.10" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -1467,13 +1467,13 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.4.1", "smallvec", "windows-targets", ] @@ -1604,7 +1604,7 @@ checksum = "7c003ac8c77cb07bb74f5f198bce836a689bcd5a42574612bf14d17bfd08c20e" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.4.0", + "bitflags 2.4.1", "lazy_static", "num-traits", "rand", @@ -1717,6 +1717,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "regex-syntax" version = "0.7.5" @@ -1811,11 +1820,11 @@ checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" [[package]] name = "rustix" -version = "0.38.18" +version = "0.38.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c" +checksum = "67ce50cb2e16c2903e30d1cbccfd8387a74b9d4c938b6a4c5ec6cc7556f7a8a0" dependencies = [ - "bitflags 2.4.0", + "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", @@ -1968,13 +1977,22 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] +[[package]] +name = "serde-json-wasm" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83c37d03f3b0f6b5f77c11af1e7c772de1c9af83e50bef7bb6069601900ba67b" +dependencies = [ + "serde", +] + [[package]] name = "serde_bytes" version = "0.11.12" @@ -1986,9 +2004,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", @@ -2247,7 +2265,7 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", + "redox_syscall 0.3.5", "rustix", "windows-sys", ] @@ -2661,9 +2679,9 @@ dependencies = [ [[package]] name = "tower-abci" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "609688a11f3022fd5949a165a4c006f4ce626e3479ba286c0231ce9805ffc35a" +checksum = "0d4826f3df3e9a37083d978cae73f020bcdf6143956b7dfc1bd6050b4e16367c" dependencies = [ "bytes", "futures", @@ -2692,11 +2710,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "log", "pin-project-lite", "tracing-attributes", @@ -2705,9 +2722,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", @@ -2716,9 +2733,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", "valuable", @@ -3050,9 +3067,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.5.16" +version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907" +checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index 71813a80..99efd941 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,10 @@ base64 = { version = "0.21", default-features = false, features = ["alloc"] } displaydoc = { version = "0.2", default-features = false } derive_more = { version = "0.99.17", default-features = false, features = ["from", "into", "display"] } ed25519 = { version = "2.1.0", default-features = false } -ibc = { git ="https://github.com/cosmos/ibc-rs", rev = "56273f6" } -ibc-query = { git ="https://github.com/cosmos/ibc-rs", rev = "56273f6" } +ibc = { git ="https://github.com/cosmos/ibc-rs", rev = "52ea3ef" } +ibc-query = { git ="https://github.com/cosmos/ibc-rs", rev = "52ea3ef" } ibc-proto = { version = "0.37.1", default-features = false } -ics23 = { version = "0.11", default-features = false } +ics23 = { version = "0.11", default-features = false } prost = { version = "0.12", default-features = false } serde = "1.0" serde_json = "1.0" diff --git a/README.md b/README.md index 9d1d5d8f..2ae7dc78 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,16 @@ So far this app has been tested with: * Rust >v1.52.1 * CometBFT v0.37 -## Usage +## How to integrate ibc-rs changes into basecoin +Since basecoin serves as a suite of integration tests against ibc-rs's functionality, each ibc-rs +PR also requires an accompanying basecoin PR. The steps to do this are: +1. In a new branch in basecoin, update ibc [revisions][revs] with the latest commit of the ibc-rs PR. +2. Implement the necessary changes in basecoin in order to get it working with the latest commit revision of ibc-rs. +3. Run `cargo clippy --all-features` and `cargo clippy --no-default-features` and fix any issues that clippy raises. +4. Open a PR in the basecoin-rs repository, making sure to the link to the associated ibc-rs PR. +5. Check to see if the [integration tests][integration-tests] pass. + +## Starting up an instance of basecoin ### Step 1: Reset your local CometBFT node ```shell $ cometbft init @@ -69,3 +78,6 @@ $ cometbft node ![class diagram](docs/images/class-diagram.png) --- ![activity diagram - DeliverTx](docs/images/activity-diagram-deliverTx.png) + +[revs]: https://github.com/informalsystems/basecoin-rs/blob/9610b29067ba122808d1d14354a32e2005b54517/Cargo.toml#L15-L16 +[integration-tests]: https://github.com/informalsystems/basecoin-rs/blob/8f744c8356569d5f87a546f46d1ade247ebe5256/.github/workflows/integration.yml#L1 \ No newline at end of file diff --git a/ci/cometbft-config/config.toml b/ci/cometbft-config/config.toml index 0107c714..b1d28deb 100644 --- a/ci/cometbft-config/config.toml +++ b/ci/cometbft-config/config.toml @@ -327,7 +327,7 @@ enable = false rpc_servers = "" trust_height = 0 trust_hash = "" -trust_period = "168h0m0s" +trust_period = "3m" # Time to spend discovering snapshots before initiating a restore. discovery_time = "15s" diff --git a/ci/hermes-config.toml b/ci/hermes-config.toml index 1edba701..efcd6211 100644 --- a/ci/hermes-config.toml +++ b/ci/hermes-config.toml @@ -12,7 +12,9 @@ key_name = 'testkey' store_prefix = 'ibc' gas_price = { price = 0.001, denom = 'stake' } clock_drift = '5s' -trusting_period = '14days' +# `trusting_period` default value is '14days', but for the purpose of testing +# the consensus state pruning mechanism of Tendermint client it is set to '3m' +trusting_period = '3m' [chains.trust_threshold] numerator = '1' @@ -29,7 +31,7 @@ key_name = 'testkey' store_prefix = 'ibc' gas_price = { price = 0.001, denom = 'basecoin' } clock_drift = '5s' -trusting_period = '14days' +trusting_period = '3m' proof_specs = ''' [ { diff --git a/ci/one-chain b/ci/one-chain index 0914c376..548f9572 100755 --- a/ci/one-chain +++ b/ci/one-chain @@ -126,6 +126,7 @@ if [ $platform = 'linux' ]; then sed -i 's#"localhost:6060"#"localhost:'"$PROF_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml + sed -i 's/trust_period = "168h0m0s"/trust_period = "3m"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml sed -i 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml # sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml else @@ -135,6 +136,7 @@ else sed -i '' 's#"localhost:6060"#"localhost:'"$PROF_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml + sed -i '' 's/trust_period = "168h0m0s"/trust_period = "3m"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml sed -i '' 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml # sed -i '' 's/min-retain-blocks = 0/min-retain-blocks = 100/g' $CHAIN_DIR/$CHAIN_ID/config/app.toml # sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml diff --git a/crates/app/src/modules/ibc/client_contexts.rs b/crates/app/src/modules/ibc/client_contexts.rs index e55a666b..59695068 100644 --- a/crates/app/src/modules/ibc/client_contexts.rs +++ b/crates/app/src/modules/ibc/client_contexts.rs @@ -125,6 +125,34 @@ where .insert((client_id, height), host_height); Ok(()) } + + /// Delete the update time associated with the client at the specified height. + fn delete_update_time( + &mut self, + client_id: ClientId, + height: IbcHeight, + ) -> Result<(), ContextError> { + self.client_processed_times.remove(&(client_id, height)); + Ok(()) + } + + /// Delete the update height associated with the client at the specified height. + fn delete_update_height( + &mut self, + client_id: ClientId, + height: IbcHeight, + ) -> Result<(), ContextError> { + self.client_processed_heights.remove(&(client_id, height)); + Ok(()) + } + + fn delete_consensus_state( + &mut self, + consensus_state_path: ClientConsensusStatePath, + ) -> Result<(), ContextError> { + self.consensus_state_store.delete(consensus_state_path); + Ok(()) + } } impl CommonContext for IbcContext @@ -148,6 +176,33 @@ where ) -> Result { ValidationContext::consensus_state(self, client_cons_state_path) } + + fn consensus_state_heights( + &self, + client_id: &ClientId, + ) -> Result, ContextError> { + let path = format!("clients/{}/consensusStates", client_id) + .try_into() + .map_err(|_| ClientError::Other { + description: "Invalid consensus state path".into(), + })?; + + self.consensus_state_store + .get_keys(&path) + .into_iter() + .flat_map(|path| { + if let Ok(Path::ClientConsensusState(consensus_path)) = path.try_into() { + Some(consensus_path) + } else { + None + } + }) + .map(|consensus_path| { + let height = IbcHeight::new(consensus_path.epoch, consensus_path.height)?; + Ok(height) + }) + .collect() + } } impl TmValidationContext for IbcContext diff --git a/crates/app/src/modules/ibc/impls.rs b/crates/app/src/modules/ibc/impls.rs index 0068a05c..5ccd0cf6 100644 --- a/crates/app/src/modules/ibc/impls.rs +++ b/crates/app/src/modules/ibc/impls.rs @@ -204,7 +204,6 @@ where let ibc_events = self.process_message(message)?; Ok(ibc_events - .clone() .into_iter() .map(|ev| Event::try_from(ev).unwrap()) .collect()) @@ -308,7 +307,7 @@ where /// Tracks the processed height for client updates pub(crate) client_processed_heights: HashMap<(ClientId, IbcHeight), IbcHeight>, /// Map of host consensus states - consensus_states: Arc>>, + pub(crate) consensus_states: Arc>>, /// A typed-store for AnyClientState pub(crate) client_state_store: ProtobufStore, ClientStatePath, TmClientState, Any>, @@ -399,7 +398,7 @@ where } fn decode_client_state(&self, client_state: Any) -> Result { - Ok(TmClientState::try_from(client_state.clone())?) + Ok(TmClientState::try_from(client_state)?) } fn consensus_state(