Skip to content

Commit

Permalink
Minimize changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Oct 17, 2023
1 parent ae36669 commit e618d64
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
17 changes: 5 additions & 12 deletions crates/services/executor/src/refs/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,40 +114,33 @@ pub trait ContractStorageTrait:
+ MerkleRootStorage<ContractId, ContractsState, Error = Self::InnerError>
+ MerkleRootStorage<ContractId, ContractsAssets, Error = Self::InnerError>
{
type InnerError: Into<anyhow::Error>
+ fmt::Debug
+ fmt::Display
+ Send
+ Sync
+ 'static;
type InnerError: fmt::Debug + fmt::Display + Send + Sync + 'static;
}

impl<'a, Database> GenesisCommitment for ContractRef<&'a mut Database>
where
Database: ContractStorageTrait,
anyhow::Error: From<Database::InnerError>,
{
fn root(&self) -> anyhow::Result<MerkleRoot> {
let contract_id = *self.contract_id();
let utxo = self
.database()
.storage::<ContractsLatestUtxo>()
.get(&contract_id)
.map_err(Into::into)?
.get(&contract_id)?
.ok_or(not_found!(ContractsLatestUtxo))?
.into_owned()
.utxo_id;

let state_root = self
.database()
.storage::<ContractsState>()
.root(&contract_id)
.map_err(Into::into)?;
.root(&contract_id)?;

let balance_root = self
.database()
.storage::<ContractsAssets>()
.root(&contract_id)
.map_err(Into::into)?;
.root(&contract_id)?;

let contract_hash = *Hasher::default()
// `ContractId` already is based on contract's code and salt so we don't need it.
Expand Down
4 changes: 2 additions & 2 deletions crates/services/p2p/src/codecs/postcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl PostcardCodec {
}

fn serialize<D: Serialize>(&self, data: &D) -> Result<Vec<u8>, io::Error> {
postcard::to_allocvec(&data)
postcard::to_stdvec(&data)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@ impl RequestResponseCodec for PostcardCodec {
where
T: futures::AsyncWrite + Unpin + Send,
{
match postcard::to_allocvec(&req) {
match postcard::to_stdvec(&req) {
Ok(encoded_data) => {
write_length_prefixed(socket, encoded_data).await?;
socket.close().await?;
Expand Down
4 changes: 2 additions & 2 deletions crates/services/relayer/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<D> SharedState<D> {
pub async fn await_synced(&self) -> anyhow::Result<()> {
let mut rx = self.synced.clone();
if rx.borrow_and_update().deref().is_none() {
rx.changed().await.map_err(anyhow::Error::msg)?;
rx.changed().await?;
}
Ok(())
}
Expand All @@ -275,7 +275,7 @@ impl<D> SharedState<D> {
) -> anyhow::Result<()> {
let mut rx = self.synced.clone();
while rx.borrow_and_update().deref().map_or(true, |h| h < *height) {
rx.changed().await.map_err(anyhow::Error::msg)?;
rx.changed().await?;
}
Ok(())
}
Expand Down
4 changes: 1 addition & 3 deletions crates/services/relayer/src/service/get_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ where
S: futures::Stream<Item = Result<(u64, Vec<Log>), ProviderError>>,
{
tokio::pin!(logs);
while let Some((height, events)) =
logs.try_next().await.map_err(anyhow::Error::msg)?
{
while let Some((height, events)) = logs.try_next().await? {
let messages = events
.into_iter()
.filter_map(|event| match EthEventLog::try_from(&event) {
Expand Down
7 changes: 4 additions & 3 deletions crates/services/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ where
if !state.starting() {
return Ok(state)
}
start.changed().await.map_err(anyhow::Error::msg)?;
start.changed().await?;
}
}

Expand All @@ -177,7 +177,7 @@ where
if state.stopped() {
return Ok(state)
}
stop.changed().await.map_err(anyhow::Error::msg)?;
stop.changed().await?;
}
}
}
Expand Down Expand Up @@ -369,7 +369,8 @@ async fn run<S>(
tracing::debug!("run loop");
}
Err(e) => {
tracing::error!("{:?}", e);
let e: &dyn std::error::Error = &*e;
tracing::error!(e);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/services/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl StateWatcher {
return Ok(state)
}

self.changed().await.map_err(anyhow::Error::msg)?;
self.changed().await?;
}
}
}
Expand Down

0 comments on commit e618d64

Please sign in to comment.