@@ -41,7 +41,7 @@ use client::ExecutionStrategies;
4141use parity_codec:: { Decode , Encode } ;
4242use hash_db:: Hasher ;
4343use kvdb:: { KeyValueDB , DBTransaction } ;
44- use trie:: { MemoryDB , PrefixedMemoryDB , prefixed_key } ;
44+ use trie:: MemoryDB ;
4545use parking_lot:: RwLock ;
4646use primitives:: { H256 , Blake2Hasher , ChangesTrieConfiguration , convert_hash} ;
4747use primitives:: storage:: well_known_keys;
@@ -267,7 +267,7 @@ impl<Block: BlockT> client::blockchain::ProvideCache<Block> for BlockchainDb<Blo
267267/// Database transaction
268268pub struct BlockImportOperation < Block : BlockT , H : Hasher > {
269269 old_state : CachingState < Blake2Hasher , DbState , Block > ,
270- db_updates : PrefixedMemoryDB < H > ,
270+ db_updates : MemoryDB < H > ,
271271 storage_updates : Vec < ( Vec < u8 > , Option < Vec < u8 > > ) > ,
272272 changes_trie_updates : MemoryDB < H > ,
273273 pending_block : Option < PendingBlock < Block > > ,
@@ -318,7 +318,7 @@ where Block: BlockT<Hash=H256>,
318318 // Currently cache isn't implemented on full nodes.
319319 }
320320
321- fn update_db_storage ( & mut self , update : PrefixedMemoryDB < Blake2Hasher > ) -> Result < ( ) , client:: error:: Error > {
321+ fn update_db_storage ( & mut self , update : MemoryDB < Blake2Hasher > ) -> Result < ( ) , client:: error:: Error > {
322322 self . db_updates = update;
323323 Ok ( ( ) )
324324 }
@@ -329,7 +329,7 @@ where Block: BlockT<Hash=H256>,
329329 return Err ( client:: error:: ErrorKind :: GenesisInvalid . into ( ) ) ;
330330 }
331331
332- let mut transaction: PrefixedMemoryDB < Blake2Hasher > = Default :: default ( ) ;
332+ let mut transaction: MemoryDB < Blake2Hasher > = Default :: default ( ) ;
333333
334334 for ( child_key, child_map) in children {
335335 if !well_known_keys:: is_child_storage_key ( & child_key) {
@@ -382,23 +382,22 @@ where Block: BlockT<Hash=H256>,
382382
383383struct StorageDb < Block : BlockT > {
384384 pub db : Arc < KeyValueDB > ,
385- pub state_db : StateDb < Block :: Hash , Vec < u8 > > ,
385+ pub state_db : StateDb < Block :: Hash , H256 > ,
386386}
387387
388388impl < Block : BlockT > state_machine:: Storage < Blake2Hasher > for StorageDb < Block > {
389- fn get ( & self , key : & H256 , prefix : & [ u8 ] ) -> Result < Option < DBValue > , String > {
390- let key = prefixed_key :: < Blake2Hasher > ( key, prefix) ;
391- self . state_db . get ( & key, self ) . map ( |r| r. map ( |v| DBValue :: from_slice ( & v) ) )
389+ fn get ( & self , key : & H256 ) -> Result < Option < DBValue > , String > {
390+ self . state_db . get ( key, self ) . map ( |r| r. map ( |v| DBValue :: from_slice ( & v) ) )
392391 . map_err ( |e| format ! ( "Database backend error: {:?}" , e) )
393392 }
394393}
395394
396- impl < Block : BlockT > state_db:: NodeDb for StorageDb < Block > {
395+ impl < Block : BlockT > state_db:: HashDb for StorageDb < Block > {
397396 type Error = io:: Error ;
398- type Key = [ u8 ] ;
397+ type Hash = H256 ;
399398
400- fn get ( & self , key : & [ u8 ] ) -> Result < Option < Vec < u8 > > , Self :: Error > {
401- self . db . get ( columns:: STATE , key) . map ( |r| r. map ( |v| v. to_vec ( ) ) )
399+ fn get ( & self , key : & H256 ) -> Result < Option < Vec < u8 > > , Self :: Error > {
400+ self . db . get ( columns:: STATE , key. as_bytes ( ) ) . map ( |r| r. map ( |v| v. to_vec ( ) ) )
402401 }
403402}
404403
@@ -414,7 +413,7 @@ impl DbGenesisStorage {
414413}
415414
416415impl state_machine:: Storage < Blake2Hasher > for DbGenesisStorage {
417- fn get ( & self , _key : & H256 , _prefix : & [ u8 ] ) -> Result < Option < DBValue > , String > {
416+ fn get ( & self , _key : & H256 ) -> Result < Option < DBValue > , String > {
418417 Ok ( None )
419418 }
420419}
@@ -524,7 +523,7 @@ impl<Block: BlockT> state_machine::ChangesTrieRootsStorage<Blake2Hasher> for DbC
524523}
525524
526525impl < Block : BlockT > state_machine:: ChangesTrieStorage < Blake2Hasher > for DbChangesTrieStorage < Block > {
527- fn get ( & self , key : & H256 , _prefix : & [ u8 ] ) -> Result < Option < DBValue > , String > {
526+ fn get ( & self , key : & H256 ) -> Result < Option < DBValue > , String > {
528527 self . db . get ( columns:: CHANGES_TRIE , & key[ ..] )
529528 . map_err ( |err| format ! ( "{}" , err) )
530529 }
@@ -568,7 +567,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
568567 let blockchain = BlockchainDb :: new ( db. clone ( ) ) ?;
569568 let meta = blockchain. meta . clone ( ) ;
570569 let map_e = |e : state_db:: Error < io:: Error > | :: client:: error:: Error :: from ( format ! ( "State database error: {:?}" , e) ) ;
571- let state_db: StateDb < _ , _ > = StateDb :: new ( pruning, & StateMetaDb ( & * db) ) . map_err ( map_e) ?;
570+ let state_db: StateDb < Block :: Hash , H256 > = StateDb :: new ( pruning, & StateMetaDb ( & * db) ) . map_err ( map_e) ?;
572571 let storage_db = StorageDb {
573572 db : db. clone ( ) ,
574573 state_db,
@@ -841,7 +840,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
841840 transaction. put ( columns:: META , meta_keys:: GENESIS_HASH , hash. as_ref ( ) ) ;
842841 }
843842
844- let mut changeset: state_db:: ChangeSet < Vec < u8 > > = state_db:: ChangeSet :: default ( ) ;
843+ let mut changeset: state_db:: ChangeSet < H256 > = state_db:: ChangeSet :: default ( ) ;
845844 for ( key, ( val, rc) ) in operation. db_updates . drain ( ) {
846845 if rc > 0 {
847846 changeset. inserted . push ( ( key, val. to_vec ( ) ) ) ;
@@ -990,7 +989,7 @@ impl<Block: BlockT<Hash=H256>> Backend<Block> {
990989 }
991990}
992991
993- fn apply_state_commit ( transaction : & mut DBTransaction , commit : state_db:: CommitSet < Vec < u8 > > ) {
992+ fn apply_state_commit ( transaction : & mut DBTransaction , commit : state_db:: CommitSet < H256 > ) {
994993 for ( key, val) in commit. data . inserted . into_iter ( ) {
995994 transaction. put ( columns:: STATE , & key[ ..] , & val) ;
996995 }
@@ -1040,7 +1039,7 @@ impl<Block> client::backend::Backend<Block, Blake2Hasher> for Backend<Block> whe
10401039 Ok ( BlockImportOperation {
10411040 pending_block : None ,
10421041 old_state,
1043- db_updates : PrefixedMemoryDB :: default ( ) ,
1042+ db_updates : MemoryDB :: default ( ) ,
10441043 storage_updates : Default :: default ( ) ,
10451044 changes_trie_updates : MemoryDB :: default ( ) ,
10461045 aux_ops : Vec :: new ( ) ,
@@ -1423,7 +1422,7 @@ mod tests {
14231422
14241423 op. reset_storage ( storage. iter ( ) . cloned ( ) . collect ( ) , Default :: default ( ) ) . unwrap ( ) ;
14251424
1426- key = op. db_updates . insert ( & [ ] , b"hello" ) ;
1425+ key = op. db_updates . insert ( b"hello" ) ;
14271426 op. set_block_data (
14281427 header,
14291428 Some ( vec ! [ ] ) ,
@@ -1457,8 +1456,8 @@ mod tests {
14571456 ) . 0 . into ( ) ;
14581457 let hash = header. hash ( ) ;
14591458
1460- op. db_updates . insert ( & [ ] , b"hello" ) ;
1461- op. db_updates . remove ( & key, & [ ] ) ;
1459+ op. db_updates . insert ( b"hello" ) ;
1460+ op. db_updates . remove ( & key) ;
14621461 op. set_block_data (
14631462 header,
14641463 Some ( vec ! [ ] ) ,
@@ -1492,7 +1491,7 @@ mod tests {
14921491 ) . 0 . into ( ) ;
14931492 let hash = header. hash ( ) ;
14941493
1495- op. db_updates . remove ( & key, & [ ] ) ;
1494+ op. db_updates . remove ( & key) ;
14961495 op. set_block_data (
14971496 header,
14981497 Some ( vec ! [ ] ) ,
@@ -1558,7 +1557,7 @@ mod tests {
15581557 assert_eq ! ( backend. changes_tries_storage. root( & anchor, block) , Ok ( Some ( changes_root) ) ) ;
15591558
15601559 for ( key, ( val, _) ) in changes_trie_update. drain ( ) {
1561- assert_eq ! ( backend. changes_trie_storage( ) . unwrap( ) . get( & key, & [ ] ) , Ok ( Some ( val) ) ) ;
1560+ assert_eq ! ( backend. changes_trie_storage( ) . unwrap( ) . get( & key) , Ok ( Some ( val) ) ) ;
15621561 }
15631562 } ;
15641563
@@ -1684,34 +1683,34 @@ mod tests {
16841683 let mut tx = DBTransaction :: new ( ) ;
16851684 backend. changes_tries_storage . prune ( Some ( config. clone ( ) ) , & mut tx, Default :: default ( ) , 12 ) ;
16861685 backend. storage . db . write ( tx) . unwrap ( ) ;
1687- assert ! ( backend. changes_tries_storage. get( & root1, & [ ] ) . unwrap( ) . is_none( ) ) ;
1688- assert ! ( backend. changes_tries_storage. get( & root2, & [ ] ) . unwrap( ) . is_none( ) ) ;
1689- assert ! ( backend. changes_tries_storage. get( & root3, & [ ] ) . unwrap( ) . is_none( ) ) ;
1690- assert ! ( backend. changes_tries_storage. get( & root4, & [ ] ) . unwrap( ) . is_none( ) ) ;
1691- assert ! ( backend. changes_tries_storage. get( & root5, & [ ] ) . unwrap( ) . is_some( ) ) ;
1692- assert ! ( backend. changes_tries_storage. get( & root6, & [ ] ) . unwrap( ) . is_some( ) ) ;
1693- assert ! ( backend. changes_tries_storage. get( & root7, & [ ] ) . unwrap( ) . is_some( ) ) ;
1694- assert ! ( backend. changes_tries_storage. get( & root8, & [ ] ) . unwrap( ) . is_some( ) ) ;
1686+ assert ! ( backend. changes_tries_storage. get( & root1) . unwrap( ) . is_none( ) ) ;
1687+ assert ! ( backend. changes_tries_storage. get( & root2) . unwrap( ) . is_none( ) ) ;
1688+ assert ! ( backend. changes_tries_storage. get( & root3) . unwrap( ) . is_none( ) ) ;
1689+ assert ! ( backend. changes_tries_storage. get( & root4) . unwrap( ) . is_none( ) ) ;
1690+ assert ! ( backend. changes_tries_storage. get( & root5) . unwrap( ) . is_some( ) ) ;
1691+ assert ! ( backend. changes_tries_storage. get( & root6) . unwrap( ) . is_some( ) ) ;
1692+ assert ! ( backend. changes_tries_storage. get( & root7) . unwrap( ) . is_some( ) ) ;
1693+ assert ! ( backend. changes_tries_storage. get( & root8) . unwrap( ) . is_some( ) ) ;
16951694
16961695 // now simulate finalization of block#16, causing prune of tries at #5..#8
16971696 let mut tx = DBTransaction :: new ( ) ;
16981697 backend. changes_tries_storage . prune ( Some ( config. clone ( ) ) , & mut tx, Default :: default ( ) , 16 ) ;
16991698 backend. storage . db . write ( tx) . unwrap ( ) ;
1700- assert ! ( backend. changes_tries_storage. get( & root5, & [ ] ) . unwrap( ) . is_none( ) ) ;
1701- assert ! ( backend. changes_tries_storage. get( & root6, & [ ] ) . unwrap( ) . is_none( ) ) ;
1702- assert ! ( backend. changes_tries_storage. get( & root7, & [ ] ) . unwrap( ) . is_none( ) ) ;
1703- assert ! ( backend. changes_tries_storage. get( & root8, & [ ] ) . unwrap( ) . is_none( ) ) ;
1699+ assert ! ( backend. changes_tries_storage. get( & root5) . unwrap( ) . is_none( ) ) ;
1700+ assert ! ( backend. changes_tries_storage. get( & root6) . unwrap( ) . is_none( ) ) ;
1701+ assert ! ( backend. changes_tries_storage. get( & root7) . unwrap( ) . is_none( ) ) ;
1702+ assert ! ( backend. changes_tries_storage. get( & root8) . unwrap( ) . is_none( ) ) ;
17041703
17051704 // now "change" pruning mode to archive && simulate finalization of block#20
17061705 // => no changes tries are pruned, because we never prune in archive mode
17071706 backend. changes_tries_storage . min_blocks_to_keep = None ;
17081707 let mut tx = DBTransaction :: new ( ) ;
17091708 backend. changes_tries_storage . prune ( Some ( config) , & mut tx, Default :: default ( ) , 20 ) ;
17101709 backend. storage . db . write ( tx) . unwrap ( ) ;
1711- assert ! ( backend. changes_tries_storage. get( & root9, & [ ] ) . unwrap( ) . is_some( ) ) ;
1712- assert ! ( backend. changes_tries_storage. get( & root10, & [ ] ) . unwrap( ) . is_some( ) ) ;
1713- assert ! ( backend. changes_tries_storage. get( & root11, & [ ] ) . unwrap( ) . is_some( ) ) ;
1714- assert ! ( backend. changes_tries_storage. get( & root12, & [ ] ) . unwrap( ) . is_some( ) ) ;
1710+ assert ! ( backend. changes_tries_storage. get( & root9) . unwrap( ) . is_some( ) ) ;
1711+ assert ! ( backend. changes_tries_storage. get( & root10) . unwrap( ) . is_some( ) ) ;
1712+ assert ! ( backend. changes_tries_storage. get( & root11) . unwrap( ) . is_some( ) ) ;
1713+ assert ! ( backend. changes_tries_storage. get( & root12) . unwrap( ) . is_some( ) ) ;
17151714 }
17161715
17171716 #[ test]
@@ -1750,15 +1749,15 @@ mod tests {
17501749 let mut tx = DBTransaction :: new ( ) ;
17511750 backend. changes_tries_storage . prune ( Some ( config. clone ( ) ) , & mut tx, block5, 5 ) ;
17521751 backend. storage . db . write ( tx) . unwrap ( ) ;
1753- assert ! ( backend. changes_tries_storage. get( & root1, & [ ] ) . unwrap( ) . is_none( ) ) ;
1754- assert ! ( backend. changes_tries_storage. get( & root2, & [ ] ) . unwrap( ) . is_some( ) ) ;
1752+ assert ! ( backend. changes_tries_storage. get( & root1) . unwrap( ) . is_none( ) ) ;
1753+ assert ! ( backend. changes_tries_storage. get( & root2) . unwrap( ) . is_some( ) ) ;
17551754
17561755 // now simulate finalization of block#6, causing prune of tries at #2
17571756 let mut tx = DBTransaction :: new ( ) ;
17581757 backend. changes_tries_storage . prune ( Some ( config. clone ( ) ) , & mut tx, block6, 6 ) ;
17591758 backend. storage . db . write ( tx) . unwrap ( ) ;
1760- assert ! ( backend. changes_tries_storage. get( & root2, & [ ] ) . unwrap( ) . is_none( ) ) ;
1761- assert ! ( backend. changes_tries_storage. get( & root3, & [ ] ) . unwrap( ) . is_some( ) ) ;
1759+ assert ! ( backend. changes_tries_storage. get( & root2) . unwrap( ) . is_none( ) ) ;
1760+ assert ! ( backend. changes_tries_storage. get( & root3) . unwrap( ) . is_some( ) ) ;
17621761 }
17631762
17641763 #[ test]
0 commit comments