diff --git a/client/api/src/client.rs b/client/api/src/client.rs index d0053afeba97b..a07198abfe8d6 100644 --- a/client/api/src/client.rs +++ b/client/api/src/client.rs @@ -118,10 +118,8 @@ pub trait BlockBackend { /// /// Note that this will only fetch transactions /// that are indexed by the runtime with `storage_index_transaction`. - fn block_indexed_body( - &self, - id: &BlockId, - ) -> sp_blockchain::Result>>>; + fn block_indexed_body(&self, hash: &Block::Hash) + -> sp_blockchain::Result>>>; /// Get full block by id. fn block(&self, id: &BlockId) -> sp_blockchain::Result>>; diff --git a/client/api/src/in_mem.rs b/client/api/src/in_mem.rs index 6f33695fe4bf4..26364f28acca2 100644 --- a/client/api/src/in_mem.rs +++ b/client/api/src/in_mem.rs @@ -451,7 +451,7 @@ impl blockchain::Backend for Blockchain { fn block_indexed_body( &self, - _id: BlockId, + _hash: &Block::Hash, ) -> sp_blockchain::Result>>> { unimplemented!("Not supported by the in-mem backend.") } diff --git a/client/db/src/lib.rs b/client/db/src/lib.rs index af45e7c961fd3..0138df36a38fb 100644 --- a/client/db/src/lib.rs +++ b/client/db/src/lib.rs @@ -694,8 +694,13 @@ impl sc_client_api::blockchain::Backend for BlockchainDb) -> ClientResult>>> { - let body = match read_db(&*self.db, columns::KEY_LOOKUP, columns::BODY_INDEX, id)? { + fn block_indexed_body(&self, hash: &Block::Hash) -> ClientResult>>> { + let body = match read_db( + &*self.db, + columns::KEY_LOOKUP, + columns::BODY_INDEX, + BlockId::::Hash(*hash), + )? { Some(body) => body, None => return Ok(None), }; diff --git a/client/network/sync/src/block_request_handler.rs b/client/network/sync/src/block_request_handler.rs index 08b8cffa38714..5eba1d52dc68c 100644 --- a/client/network/sync/src/block_request_handler.rs +++ b/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/client/service/src/client/client.rs b/client/service/src/client/client.rs index 6d463f337aabc..a4890f2fcf06f 100644 --- a/client/service/src/client/client.rs +++ b/client/service/src/client/client.rs @@ -1980,9 +1980,9 @@ where fn block_indexed_body( &self, - id: &BlockId, + hash: &Block::Hash, ) -> sp_blockchain::Result>>> { - 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, ) -> Result>>, 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/primitives/blockchain/src/backend.rs b/primitives/blockchain/src/backend.rs index e5764354e90f3..fdb56020661b4 100644 --- a/primitives/blockchain/src/backend.rs +++ b/primitives/blockchain/src/backend.rs @@ -238,7 +238,7 @@ pub trait Backend: Ok(self.indexed_transaction(hash)?.is_some()) } - fn block_indexed_body(&self, id: BlockId) -> Result>>>; + fn block_indexed_body(&self, hash: &Block::Hash) -> Result>>>; } /// Blockchain info