Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/improve-state-updates' into avoi…
Browse files Browse the repository at this point in the history
…d-unnecessary-updates

# Conflicts:
#	crates/core/src/client_events.rs
#	crates/core/src/contract.rs
#	crates/core/src/contract/executor.rs
  • Loading branch information
netsirius committed Jan 10, 2025
2 parents 969b94a + 25d3333 commit e418e77
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
41 changes: 25 additions & 16 deletions crates/core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ mod handler;
pub mod storages;

pub(crate) use executor::{
executor_channel, mock_runtime::MockRuntime, Callback, ExecutorToEventLoopChannel, UpsertResult,
NetworkEventListenerHalve,
executor_channel, mock_runtime::MockRuntime, Callback, ExecutorToEventLoopChannel,
NetworkEventListenerHalve, UpsertResult,
};
pub(crate) use handler::{
client_responses_channel, contract_handler_channel, in_memory::MemoryContractHandler,
Expand Down Expand Up @@ -87,22 +87,30 @@ where
} => {
let put_result = contract_handler
.executor()
.upsert_contract_state(key, Either::Left(state.clone()), related_contracts, contract)
.upsert_contract_state(
key,
Either::Left(state.clone()),
related_contracts,
contract,
)
.instrument(tracing::info_span!("upsert_contract_state", %key))
.await;

let event_result = match put_result {
Ok(UpsertResult::NoChange) => ContractHandlerEvent::PutResponse {new_value: Ok(state)},
Ok(UpsertResult::Updated(state)) => ContractHandlerEvent::PutResponse {new_value: Ok(state)},
Err(err) => ContractHandlerEvent::PutResponse {new_value: Err(err)},
Ok(UpsertResult::NoChange) => ContractHandlerEvent::PutResponse {
new_value: Ok(state),
},
Ok(UpsertResult::Updated(state)) => ContractHandlerEvent::PutResponse {
new_value: Ok(state),
},
Err(err) => ContractHandlerEvent::PutResponse {
new_value: Err(err),
},
};

contract_handler
.channel()
.send_to_sender(
id,
event_result,
)
.send_to_sender(id, event_result)
.await
.map_err(|error| {
tracing::debug!(%error, "shutting down contract handler");
Expand All @@ -129,16 +137,17 @@ where

let event_result = match update_result {
Ok(UpsertResult::NoChange) => ContractHandlerEvent::UpdateNoChange { key },
Ok(UpsertResult::Updated(state)) => ContractHandlerEvent::UpdateResponse {new_value: Ok(state)},
Err(err) => ContractHandlerEvent::UpdateResponse {new_value: Err(err)},
Ok(UpsertResult::Updated(state)) => ContractHandlerEvent::UpdateResponse {
new_value: Ok(state),
},
Err(err) => ContractHandlerEvent::UpdateResponse {
new_value: Err(err),
},
};

contract_handler
.channel()
.send_to_sender(
id,
event_result,
)
.send_to_sender(id, event_result)
.await
.map_err(|error| {
tracing::debug!(%error, "shutting down contract handler");
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/contract/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use freenet_stdlib::prelude::*;
use serde::{Deserialize, Serialize};
use tokio::sync::mpsc::{self};

use super::storages::Storage;
use crate::config::Config;
use crate::message::Transaction;
use crate::node::OpManager;
Expand All @@ -32,7 +33,6 @@ use crate::{
client_events::{ClientId, HostResult},
operations::{self, Operation},
};
use super::storages::Storage;

pub(super) mod mock_runtime;
pub(super) mod runtime;
Expand Down

0 comments on commit e418e77

Please sign in to comment.