diff --git a/substrate/client/api/src/client.rs b/substrate/client/api/src/client.rs index d0053afeba97bb7c90e4919f9cd03001f55cb276..a07198abfe8d65d59f49d609c79dc927441f1861 100644 --- a/substrate/client/api/src/client.rs +++ b/substrate/client/api/src/client.rs @@ -118,10 +118,8 @@ pub trait BlockBackend<Block: BlockT> { /// /// Note that this will only fetch transactions /// that are indexed by the runtime with `storage_index_transaction`. - fn block_indexed_body( - &self, - id: &BlockId<Block>, - ) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>>; + fn block_indexed_body(&self, hash: &Block::Hash) + -> sp_blockchain::Result<Option<Vec<Vec<u8>>>>; /// Get full block by id. fn block(&self, id: &BlockId<Block>) -> sp_blockchain::Result<Option<SignedBlock<Block>>>; diff --git a/substrate/client/api/src/in_mem.rs b/substrate/client/api/src/in_mem.rs index 6f33695fe4bf4c40ff1479be435b3269889b52c0..26364f28acca28264658627f974a5cb42189ea67 100644 --- a/substrate/client/api/src/in_mem.rs +++ b/substrate/client/api/src/in_mem.rs @@ -451,7 +451,7 @@ impl<Block: BlockT> blockchain::Backend<Block> for Blockchain<Block> { fn block_indexed_body( &self, - _id: BlockId<Block>, + _hash: &Block::Hash, ) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>> { unimplemented!("Not supported by the in-mem backend.") } diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs index af45e7c961fd3bc8298b7fbf9925878033160b78..0138df36a38fb45be91ded6fac163f9f7ed17f80 100644 --- a/substrate/client/db/src/lib.rs +++ b/substrate/client/db/src/lib.rs @@ -694,8 +694,13 @@ impl<Block: BlockT> sc_client_api::blockchain::Backend<Block> for BlockchainDb<B Ok(self.db.contains(columns::TRANSACTION, hash.as_ref())) } - fn block_indexed_body(&self, id: BlockId<Block>) -> ClientResult<Option<Vec<Vec<u8>>>> { - let body = match read_db(&*self.db, columns::KEY_LOOKUP, columns::BODY_INDEX, id)? { + fn block_indexed_body(&self, hash: &Block::Hash) -> ClientResult<Option<Vec<Vec<u8>>>> { + let body = match read_db( + &*self.db, + columns::KEY_LOOKUP, + columns::BODY_INDEX, + BlockId::<Block>::Hash(*hash), + )? { Some(body) => body, None => return Ok(None), }; diff --git a/substrate/client/network/sync/src/block_request_handler.rs b/substrate/client/network/sync/src/block_request_handler.rs index 08b8cffa38714e120cf206b00ec467f34fe129bf..5eba1d52dc68c1174f2467226cb44f78130a3ae2 100644 --- a/substrate/client/network/sync/src/block_request_handler.rs +++ b/substrate/client/network/sync/src/block_request_handler.rs @@ -374,7 +374,7 @@ where }; let indexed_body = if get_indexed_body { - match self.client.block_indexed_body(&BlockId::Hash(hash))? { + match self.client.block_indexed_body(&hash)? { Some(transactions) => transactions, None => { log::trace!( diff --git a/substrate/client/service/src/client/client.rs b/substrate/client/service/src/client/client.rs index 6d463f337aabc43e86bddb3b9373405ebbd1e328..a4890f2fcf06f21eb5068bdd73efbdeb3f7f66d7 100644 --- a/substrate/client/service/src/client/client.rs +++ b/substrate/client/service/src/client/client.rs @@ -1980,9 +1980,9 @@ where fn block_indexed_body( &self, - id: &BlockId<Block>, + hash: &Block::Hash, ) -> sp_blockchain::Result<Option<Vec<Vec<u8>>>> { - self.backend.blockchain().block_indexed_body(*id) + self.backend.blockchain().block_indexed_body(hash) } fn requires_full_sync(&self) -> bool { @@ -2073,9 +2073,19 @@ where &self, number: NumberFor<B>, ) -> Result<Option<Vec<Vec<u8>>>, sp_transaction_storage_proof::Error> { + let hash = match self + .backend + .blockchain() + .block_hash_from_id(&BlockId::Number(number)) + .map_err(|e| sp_transaction_storage_proof::Error::Application(Box::new(e)))? + { + Some(hash) => hash, + None => return Ok(None), + }; + self.backend .blockchain() - .block_indexed_body(BlockId::number(number)) + .block_indexed_body(&hash) .map_err(|e| sp_transaction_storage_proof::Error::Application(Box::new(e))) } diff --git a/substrate/primitives/blockchain/src/backend.rs b/substrate/primitives/blockchain/src/backend.rs index e5764354e90f3dc9a1581858740ab1bc55037ed9..fdb56020661b44219df8076e84fc8ad86443ab69 100644 --- a/substrate/primitives/blockchain/src/backend.rs +++ b/substrate/primitives/blockchain/src/backend.rs @@ -238,7 +238,7 @@ pub trait Backend<Block: BlockT>: Ok(self.indexed_transaction(hash)?.is_some()) } - fn block_indexed_body(&self, id: BlockId<Block>) -> Result<Option<Vec<Vec<u8>>>>; + fn block_indexed_body(&self, hash: &Block::Hash) -> Result<Option<Vec<Vec<u8>>>>; } /// Blockchain info