Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

feat: change rlp in executor to fixed-codec #29

Merged
merged 4 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion core/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ cita_trie = "2.0"
bytes = "0.4"
lazy_static = "1.4"
derive_more = "0.15"
rlp = "0.4"
rocksdb = "0.12"
hex = "0.3"
16 changes: 9 additions & 7 deletions core/executor/src/adapter/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use std::rc::Rc;
use bytes::Bytes;
use derive_more::{Display, From};

use protocol::fixed_codec::ProtocolFixedCodec;
use protocol::traits::executor::contract::ContractStateAdapter;
use protocol::traits::executor::{ContractSchema, ContractSer, TrieDB};
use protocol::traits::executor::{ContractSchema, TrieDB};
use protocol::types::MerkleRoot;
use protocol::{ProtocolError, ProtocolErrorKind, ProtocolResult};

Expand Down Expand Up @@ -40,20 +41,20 @@ impl<DB: TrieDB> ContractStateAdapter for GeneralContractStateAdapter<DB> {
&self,
key: &<Schema as ContractSchema>::Key,
) -> ProtocolResult<Option<<Schema as ContractSchema>::Value>> {
let encoded_key = key.encode()?;
let encoded_key = key.encode_fixed()?;

if let Some(value_bytes) = self.cache_map.get(&encoded_key) {
let inst = <_>::decode(value_bytes.clone())?;
let inst = <_>::decode_fixed(value_bytes.clone())?;
return Ok(Some(inst));
}

if let Some(value_bytes) = self.stash_map.get(&encoded_key) {
let inst = <_>::decode(value_bytes.clone())?;
let inst = <_>::decode_fixed(value_bytes.clone())?;
return Ok(Some(inst));
}

if let Some(value_bytes) = self.trie.get(&encoded_key)? {
return Ok(Some(Schema::Value::decode(value_bytes)?));
return Ok(Some(Schema::Value::decode_fixed(value_bytes)?));
}

Ok(None)
Expand All @@ -63,7 +64,7 @@ impl<DB: TrieDB> ContractStateAdapter for GeneralContractStateAdapter<DB> {
&self,
key: &<Schema as ContractSchema>::Key,
) -> ProtocolResult<bool> {
let encoded_key = key.encode()?;
let encoded_key = key.encode_fixed()?;

if self.cache_map.contains_key(&encoded_key) {
return Ok(true);
Expand All @@ -81,7 +82,8 @@ impl<DB: TrieDB> ContractStateAdapter for GeneralContractStateAdapter<DB> {
key: <Schema as ContractSchema>::Key,
value: <Schema as ContractSchema>::Value,
) -> ProtocolResult<()> {
self.cache_map.insert(key.encode()?, value.encode()?);
self.cache_map
.insert(key.encode_fixed()?, value.encode_fixed()?);
Ok(())
}

Expand Down
Loading