Skip to content

Commit 86f48fe

Browse files
Seulgi Kimmajecty
authored andcommitted
Distinguish TxHash from H256
1 parent 2e45da3 commit 86f48fe

File tree

38 files changed

+374
-253
lines changed

38 files changed

+374
-253
lines changed

core/src/block.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use cstate::{FindActionHandler, StateDB, StateError, StateWithCache, TopLevelSta
2323
use ctypes::errors::HistoryError;
2424
use ctypes::header::{Header, Seal};
2525
use ctypes::util::unexpected::Mismatch;
26-
use ctypes::{BlockNumber, CommonParams};
26+
use ctypes::{BlockNumber, CommonParams, TxHash};
2727
use cvm::ChainTimeInfo;
2828
use primitives::{Bytes, H256};
2929
use rlp::{Decodable, DecoderError, Encodable, RlpStream, UntrustedRlp};
@@ -90,7 +90,7 @@ pub struct ExecutedBlock {
9090
state: TopLevelState,
9191
transactions: Vec<SignedTransaction>,
9292
invoices: Vec<Invoice>,
93-
transactions_set: HashSet<H256>,
93+
transactions_set: HashSet<TxHash>,
9494
}
9595

9696
impl ExecutedBlock {
@@ -153,7 +153,7 @@ impl<'x> OpenBlock<'x> {
153153
pub fn push_transaction<C: ChainTimeInfo + FindActionHandler>(
154154
&mut self,
155155
tx: SignedTransaction,
156-
h: Option<H256>,
156+
h: Option<TxHash>,
157157
client: &C,
158158
parent_block_number: BlockNumber,
159159
parent_block_timestamp: u64,

core/src/blockchain/blockchain.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use std::sync::Arc;
1818

19-
use ctypes::{BlockHash, BlockNumber, Tracker};
19+
use ctypes::{BlockHash, BlockNumber, Tracker, TxHash};
2020
use kvdb::{DBTransaction, KeyValueDB};
2121
use parking_lot::RwLock;
2222
use primitives::H256;
@@ -411,7 +411,7 @@ impl BodyProvider for BlockChain {
411411
self.body_db.is_known_body(hash)
412412
}
413413

414-
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress> {
414+
fn transaction_address(&self, hash: &TxHash) -> Option<TransactionAddress> {
415415
self.body_db.transaction_address(hash)
416416
}
417417

@@ -426,15 +426,15 @@ impl BodyProvider for BlockChain {
426426

427427
impl InvoiceProvider for BlockChain {
428428
/// Returns true if invoices for given hash is known
429-
fn is_known_error_hint(&self, hash: &H256) -> bool {
429+
fn is_known_error_hint(&self, hash: &TxHash) -> bool {
430430
self.invoice_db.is_known_error_hint(hash)
431431
}
432432

433-
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(H256, Option<String>)> {
433+
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(TxHash, Option<String>)> {
434434
self.invoice_db.error_hints_by_tracker(tracker)
435435
}
436436

437-
fn error_hint(&self, hash: &H256) -> Option<String> {
437+
fn error_hint(&self, hash: &TxHash) -> Option<String> {
438438
self.invoice_db.error_hint(hash)
439439
}
440440
}

core/src/blockchain/body_db.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use std::collections::{HashMap, HashSet};
1818
use std::mem;
1919
use std::sync::Arc;
2020

21-
use ctypes::{BlockHash, Tracker};
21+
use ctypes::{BlockHash, Tracker, TxHash};
2222
use kvdb::{DBTransaction, KeyValueDB};
2323
use lru_cache::LruCache;
2424
use parking_lot::{Mutex, RwLock};
25-
use primitives::{Bytes, H256};
25+
use primitives::Bytes;
2626
use rlp::RlpStream;
2727
use rlp_compress::{blocks_swapper, compress, decompress};
2828

@@ -37,8 +37,8 @@ const BODY_CACHE_SIZE: usize = 1000;
3737
pub struct BodyDB {
3838
// block cache
3939
body_cache: Mutex<LruCache<BlockHash, Bytes>>,
40-
parcel_address_cache: RwLock<HashMap<H256, TransactionAddress>>,
41-
pending_parcel_addresses: RwLock<HashMap<H256, Option<TransactionAddress>>>,
40+
parcel_address_cache: RwLock<HashMap<TxHash, TransactionAddress>>,
41+
pending_parcel_addresses: RwLock<HashMap<TxHash, Option<TransactionAddress>>>,
4242

4343
transaction_address_cache: Mutex<HashMap<Tracker, TransactionAddresses>>,
4444
pending_transaction_addresses: Mutex<HashMap<Tracker, Option<TransactionAddresses>>>,
@@ -141,7 +141,7 @@ impl BodyDB {
141141
fn new_parcel_address_entries(
142142
&self,
143143
best_block_changed: &BestBlockChanged,
144-
) -> HashMap<H256, Option<TransactionAddress>> {
144+
) -> HashMap<TxHash, Option<TransactionAddress>> {
145145
let block_hash = if let Some(best_block_hash) = best_block_changed.new_best_hash() {
146146
best_block_hash
147147
} else {
@@ -284,7 +284,7 @@ pub trait BodyProvider {
284284
fn is_known_body(&self, hash: &BlockHash) -> bool;
285285

286286
/// Get the address of parcel with given hash.
287-
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress>;
287+
fn transaction_address(&self, hash: &TxHash) -> Option<TransactionAddress>;
288288

289289
fn transaction_address_by_tracker(&self, tracker: &Tracker) -> Option<TransactionAddress>;
290290

@@ -298,7 +298,7 @@ impl BodyProvider for BodyDB {
298298
}
299299

300300
/// Get the address of parcel with given hash.
301-
fn transaction_address(&self, hash: &H256) -> Option<TransactionAddress> {
301+
fn transaction_address(&self, hash: &TxHash) -> Option<TransactionAddress> {
302302
let result = self.db.read_with_cache(db::COL_EXTRA, &mut *self.parcel_address_cache.write(), hash)?;
303303
Some(result)
304304
}
@@ -332,11 +332,11 @@ impl BodyProvider for BodyDB {
332332

333333
fn parcel_address_entries(
334334
block_hash: BlockHash,
335-
parcel_hashes: impl IntoIterator<Item = H256>,
336-
) -> impl Iterator<Item = (H256, Option<TransactionAddress>)> {
337-
parcel_hashes.into_iter().enumerate().map(move |(index, parcel_hash)| {
335+
tx_hashes: impl IntoIterator<Item = TxHash>,
336+
) -> impl Iterator<Item = (TxHash, Option<TransactionAddress>)> {
337+
tx_hashes.into_iter().enumerate().map(move |(index, tx_hash)| {
338338
(
339-
parcel_hash,
339+
tx_hash,
340340
Some(TransactionAddress {
341341
block_hash,
342342
index,

core/src/blockchain/extras.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use std::ops::{Add, AddAssign, Deref, Sub, SubAssign};
1818

19-
use ctypes::{BlockHash, BlockNumber, Tracker};
19+
use ctypes::{BlockHash, BlockNumber, Tracker, TxHash};
2020
use primitives::{H256, H264, U256};
2121

2222
use crate::db::Key;
@@ -29,8 +29,8 @@ enum ExtrasIndex {
2929
BlockDetails = 0,
3030
/// Block hash index
3131
BlockHash = 1,
32-
/// Parcel address index
33-
ParcelAddress = 2,
32+
/// Transaction address index
33+
TransactionAddress = 2,
3434
/// Transaction addresses index
3535
TransactionAddresses = 3,
3636
// (Reserved) = 4,
@@ -77,11 +77,11 @@ impl Key<BlockDetails> for BlockHash {
7777
}
7878
}
7979

80-
impl Key<TransactionAddress> for H256 {
80+
impl Key<TransactionAddress> for TxHash {
8181
type Target = H264;
8282

8383
fn key(&self) -> H264 {
84-
with_index(self, ExtrasIndex::ParcelAddress)
84+
with_index(self, ExtrasIndex::TransactionAddress)
8585
}
8686
}
8787

core/src/blockchain/invoice_db.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::collections::HashMap;
1818
use std::ops::{Deref, DerefMut};
1919
use std::sync::Arc;
2020

21-
use ctypes::Tracker;
21+
use ctypes::{Tracker, TxHash};
2222
use kvdb::{DBTransaction, KeyValueDB};
2323
use parking_lot::RwLock;
2424
use primitives::{H256, H264};
@@ -33,7 +33,7 @@ pub struct InvoiceDB {
3333
// tracker -> transaction hashe + error hint
3434
tracker_cache: RwLock<HashMap<Tracker, TrackerInvoices>>,
3535
// transaction hash -> error hint
36-
hash_cache: RwLock<HashMap<H256, Option<String>>>,
36+
hash_cache: RwLock<HashMap<TxHash, Option<String>>>,
3737

3838
db: Arc<dyn KeyValueDB>,
3939
}
@@ -55,7 +55,7 @@ impl InvoiceDB {
5555
pub fn insert_invoice(
5656
&self,
5757
batch: &mut DBTransaction,
58-
hash: H256,
58+
hash: TxHash,
5959
tracker: Option<Tracker>,
6060
error_hint: Option<String>,
6161
) {
@@ -80,34 +80,34 @@ impl InvoiceDB {
8080
/// Interface for querying invoices.
8181
pub trait InvoiceProvider {
8282
/// Returns true if invoices for given hash is known
83-
fn is_known_error_hint(&self, hash: &H256) -> bool;
83+
fn is_known_error_hint(&self, hash: &TxHash) -> bool;
8484

8585
/// Get error hints
86-
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(H256, Option<String>)>;
86+
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(TxHash, Option<String>)>;
8787

8888
/// Get error hint
89-
fn error_hint(&self, hash: &H256) -> Option<String>;
89+
fn error_hint(&self, hash: &TxHash) -> Option<String>;
9090
}
9191

9292
impl InvoiceProvider for InvoiceDB {
93-
fn is_known_error_hint(&self, hash: &H256) -> bool {
93+
fn is_known_error_hint(&self, hash: &TxHash) -> bool {
9494
self.db.exists_with_cache(db::COL_ERROR_HINT, &self.hash_cache, hash)
9595
}
9696

97-
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(H256, Option<String>)> {
97+
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(TxHash, Option<String>)> {
9898
self.db
9999
.read_with_cache(db::COL_ERROR_HINT, &mut *self.tracker_cache.write(), tracker)
100100
.map(|hashes| (*hashes).clone())
101101
.unwrap_or_default()
102102
}
103103

104-
fn error_hint(&self, hash: &H256) -> Option<String> {
104+
fn error_hint(&self, hash: &TxHash) -> Option<String> {
105105
self.db.read_with_cache(db::COL_ERROR_HINT, &mut *self.hash_cache.write(), hash)?
106106
}
107107
}
108108

109109
#[derive(Clone, Default)]
110-
pub struct TrackerInvoices(Vec<(H256, Option<String>)>);
110+
pub struct TrackerInvoices(Vec<(TxHash, Option<String>)>);
111111

112112
impl Encodable for TrackerInvoices {
113113
fn rlp_append(&self, s: &mut RlpStream) {
@@ -137,14 +137,14 @@ impl Decodable for TrackerInvoices {
137137
}
138138
}
139139

140-
impl From<Vec<(H256, Option<String>)>> for TrackerInvoices {
141-
fn from(f: Vec<(H256, Option<String>)>) -> Self {
140+
impl From<Vec<(TxHash, Option<String>)>> for TrackerInvoices {
141+
fn from(f: Vec<(TxHash, Option<String>)>) -> Self {
142142
TrackerInvoices(f)
143143
}
144144
}
145145

146146
impl Deref for TrackerInvoices {
147-
type Target = Vec<(H256, Option<String>)>;
147+
type Target = Vec<(TxHash, Option<String>)>;
148148

149149
fn deref(&self) -> &Self::Target {
150150
&self.0
@@ -168,7 +168,7 @@ impl From<ErrorHintIndex> for u8 {
168168
}
169169
}
170170

171-
impl Key<Option<String>> for H256 {
171+
impl Key<Option<String>> for TxHash {
172172
type Target = H264;
173173

174174
fn key(&self) -> H264 {

core/src/client/chain_notify.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use cnetwork::NodeId;
18-
use ctypes::BlockHash;
19-
use primitives::H256;
18+
use ctypes::{BlockHash, TxHash};
2019

2120
/// Represents what has to be handled by actor listening to chain events
2221
pub trait ChainNotify: Send + Sync {
@@ -48,7 +47,7 @@ pub trait ChainNotify: Send + Sync {
4847
}
4948

5049
/// fires when new transactions are received from a peer
51-
fn transactions_received(&self, _hashes: Vec<H256>, _peer_id: NodeId) {
50+
fn transactions_received(&self, _hashes: Vec<TxHash>, _peer_id: NodeId) {
5251
// does nothing by default
5352
}
5453
}

core/src/client/client.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use cstate::{
2828
};
2929
use ctimer::{TimeoutHandler, TimerApi, TimerScheduleError, TimerToken};
3030
use ctypes::transaction::{AssetTransferInput, PartialHashing, ShardTransaction};
31-
use ctypes::{BlockHash, BlockNumber, CommonParams, ShardId, Tracker};
31+
use ctypes::{BlockHash, BlockNumber, CommonParams, ShardId, Tracker, TxHash};
3232
use cvm::{decode, execute, ChainTimeInfo, ScriptResult, VMConfig};
3333
use hashdb::AsHashDB;
3434
use journaldb;
@@ -142,7 +142,7 @@ impl Client {
142142
self.notify.write().push(target);
143143
}
144144

145-
pub fn transactions_received(&self, hashes: &[H256], peer_id: NodeId) {
145+
pub fn transactions_received(&self, hashes: &[TxHash], peer_id: NodeId) {
146146
self.notify(|notify| {
147147
notify.transactions_received(hashes.to_vec(), peer_id);
148148
});
@@ -422,7 +422,7 @@ impl AssetClient for Client {
422422
}
423423

424424
impl TextClient for Client {
425-
fn get_text(&self, tx_hash: H256, id: BlockId) -> TrieResult<Option<Text>> {
425+
fn get_text(&self, tx_hash: TxHash, id: BlockId) -> TrieResult<Option<Text>> {
426426
if let Some(state) = Client::state_at(&self, id) {
427427
Ok(state.text(&tx_hash)?)
428428
} else {
@@ -797,7 +797,7 @@ impl BlockChainClient for Client {
797797
self.transaction_address(id).and_then(|address| chain.transaction(&address))
798798
}
799799

800-
fn error_hint(&self, hash: &H256) -> Option<String> {
800+
fn error_hint(&self, hash: &TxHash) -> Option<String> {
801801
let chain = self.block_chain();
802802
chain.error_hint(hash)
803803
}
@@ -808,7 +808,7 @@ impl BlockChainClient for Client {
808808
address.and_then(|address| chain.transaction(&address))
809809
}
810810

811-
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(H256, Option<String>)> {
811+
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(TxHash, Option<String>)> {
812812
let chain = self.block_chain();
813813
chain.error_hints_by_tracker(tracker)
814814
}
@@ -855,7 +855,7 @@ impl Shard for Client {
855855
state.number_of_shards().ok()
856856
}
857857

858-
fn shard_id_by_hash(&self, create_shard_tx_hash: &H256, state: StateOrBlock) -> Option<u16> {
858+
fn shard_id_by_hash(&self, create_shard_tx_hash: &TxHash, state: StateOrBlock) -> Option<u16> {
859859
let state = self.state_info(state)?;
860860
state.shard_id_by_hash(&create_shard_tx_hash).ok()?
861861
}

core/src/client/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use cmerkle::Result as TrieResult;
3737
use cnetwork::NodeId;
3838
use cstate::{AssetScheme, FindActionHandler, OwnedAsset, StateResult, Text, TopLevelState, TopStateView};
3939
use ctypes::transaction::{AssetTransferInput, PartialHashing, ShardTransaction};
40-
use ctypes::{BlockHash, BlockNumber, CommonParams, ShardId, Tracker};
40+
use ctypes::{BlockHash, BlockNumber, CommonParams, ShardId, Tracker, TxHash};
4141
use cvm::ChainTimeInfo;
4242
use kvdb::KeyValueDB;
4343
use primitives::{Bytes, H160, H256, U256};
@@ -185,7 +185,7 @@ impl From<BlockId> for StateOrBlock {
185185
pub trait Shard {
186186
fn number_of_shards(&self, state: StateOrBlock) -> Option<ShardId>;
187187

188-
fn shard_id_by_hash(&self, create_shard_tx_hash: &H256, state: StateOrBlock) -> Option<ShardId>;
188+
fn shard_id_by_hash(&self, create_shard_tx_hash: &TxHash, state: StateOrBlock) -> Option<ShardId>;
189189
fn shard_root(&self, shard_id: ShardId, state: StateOrBlock) -> Option<H256>;
190190

191191
fn shard_owners(&self, shard_id: ShardId, state: StateOrBlock) -> Option<Vec<Address>>;
@@ -250,12 +250,12 @@ pub trait BlockChainClient: Sync + Send + AccountData + BlockChainTrait + Import
250250
fn transaction(&self, id: &TransactionId) -> Option<LocalizedTransaction>;
251251

252252
/// Get invoice with given hash.
253-
fn error_hint(&self, hash: &H256) -> Option<String>;
253+
fn error_hint(&self, hash: &TxHash) -> Option<String>;
254254

255255
/// Get the transaction with given tracker.
256256
fn transaction_by_tracker(&self, tracker: &Tracker) -> Option<LocalizedTransaction>;
257257

258-
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(H256, Option<String>)>;
258+
fn error_hints_by_tracker(&self, tracker: &Tracker) -> Vec<(TxHash, Option<String>)>;
259259
}
260260

261261
/// Result of import block operation.
@@ -319,7 +319,7 @@ pub trait AssetClient {
319319

320320
/// Provides methods to texts
321321
pub trait TextClient {
322-
fn get_text(&self, tx_hash: H256, id: BlockId) -> TrieResult<Option<Text>>;
322+
fn get_text(&self, tx_hash: TxHash, id: BlockId) -> TrieResult<Option<Text>>;
323323
}
324324

325325
pub trait ExecuteClient: ChainTimeInfo {

0 commit comments

Comments
 (0)