Skip to content

Commit

Permalink
nit: Rename system_balance in callbacks and chain info queries (liner…
Browse files Browse the repository at this point in the history
…a-io#1574)

* rename request_system_balance into request_owner_balance

* rename system_balance into chain_balance

* rename comments as well

* fix expected fuel in test
  • Loading branch information
ma2bd authored Jan 29, 2024
1 parent 672028a commit 3ffeed1
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 94 deletions.
10 changes: 5 additions & 5 deletions linera-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,8 +1612,8 @@ where
.await
{
Ok((_, response)) => Ok((
response.info.system_balance,
response.info.requested_system_balance,
response.info.chain_balance,
response.info.requested_owner_balance,
)),
Err(ChainClientError::LocalNodeError(LocalNodeError::WorkerError(
WorkerError::ChainError(error),
Expand Down Expand Up @@ -1663,11 +1663,11 @@ where
ChainClientError::WalletSynchronizationError
);
let mut query = ChainInfoQuery::new(self.chain_id);
query.request_system_balance = owner;
query.request_owner_balance = owner;
let response = self.node_client.handle_chain_info_query(query).await?;
Ok((
response.info.system_balance,
response.info.requested_system_balance,
response.info.chain_balance,
response.info.requested_owner_balance,
))
}

Expand Down
20 changes: 10 additions & 10 deletions linera-core/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub struct ChainInfoQuery {
pub chain_id: ChainId,
/// Optionally test that the block height is the one expected.
pub test_next_block_height: Option<BlockHeight>,
/// Request the system balance of a given `Owner`.
pub request_system_balance: Option<Owner>,
/// Request the balance of a given `Owner`.
pub request_owner_balance: Option<Owner>,
/// Query the current committees.
pub request_committees: bool,
/// Query the received messages that are waiting be picked in the next block.
Expand All @@ -79,7 +79,7 @@ impl ChainInfoQuery {
chain_id,
test_next_block_height: None,
request_committees: false,
request_system_balance: None,
request_owner_balance: None,
request_pending_messages: false,
request_sent_certificates_in_range: None,
request_received_log_excluding_first_nth: None,
Expand All @@ -99,8 +99,8 @@ impl ChainInfoQuery {
self
}

pub fn with_system_balance(mut self, owner: Owner) -> Self {
self.request_system_balance = Some(owner);
pub fn with_owner_balance(mut self, owner: Owner) -> Self {
self.request_owner_balance = Some(owner);
self
}

Expand Down Expand Up @@ -147,7 +147,7 @@ pub struct ChainInfo {
/// The state of the chain authentication.
pub manager: Box<ChainManagerInfo>,
/// The current balance.
pub system_balance: Amount,
pub chain_balance: Amount,
/// The last block hash, if any.
pub block_hash: Option<CryptoHash>,
/// The earliest possible timestamp for the next block.
Expand All @@ -156,8 +156,8 @@ pub struct ChainInfo {
pub next_block_height: BlockHeight,
/// The hash of the current execution state.
pub state_hash: Option<CryptoHash>,
/// The requested system balance, if any.
pub requested_system_balance: Option<Amount>,
/// The requested owner balance, if any.
pub requested_owner_balance: Option<Amount>,
/// The current committees.
pub requested_committees: Option<BTreeMap<Epoch, Committee>>,
/// The received messages that are waiting be picked in the next block (if requested).
Expand Down Expand Up @@ -237,13 +237,13 @@ where
epoch: *system_state.epoch.get(),
description: *system_state.description.get(),
manager: Box::new(ChainManagerInfo::from(view.manager.get())),
system_balance: *system_state.balance.get(),
chain_balance: *system_state.balance.get(),
block_hash: tip_state.block_hash,
next_block_height: tip_state.next_block_height,
timestamp: *view.execution_state.system.timestamp.get(),
state_hash: *view.execution_state_hash.get(),
requested_committees: None,
requested_system_balance: None,
requested_owner_balance: None,
requested_pending_messages: Vec::new(),
requested_sent_certificates: Vec::new(),
count_received_log: view.received_log.count(),
Expand Down
12 changes: 6 additions & 6 deletions linera-core/src/unit_tests/wasm_worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::from(publisher_chain), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(1), info.next_block_height);
assert_eq!(Timestamp::from(1), info.timestamp);
assert_eq!(Some(publish_certificate.hash()), info.block_hash);
Expand Down Expand Up @@ -216,7 +216,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::from(publisher_chain), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(2), info.next_block_height);
assert_eq!(Timestamp::from(1), info.timestamp);
assert_eq!(Some(broadcast_certificate.hash()), info.block_hash);
Expand Down Expand Up @@ -270,7 +270,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::from(creator_chain), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(1), info.next_block_height);
assert_eq!(Timestamp::from(2), info.timestamp);
assert_eq!(Some(subscribe_certificate.hash()), info.block_hash);
Expand Down Expand Up @@ -316,7 +316,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::from(publisher_chain), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(3), info.next_block_height);
assert_eq!(Timestamp::from(3), info.timestamp);
assert_eq!(Some(accept_certificate.hash()), info.block_hash);
Expand Down Expand Up @@ -407,7 +407,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::root(2), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(2), info.next_block_height);
assert_eq!(Timestamp::from(4), info.timestamp);
assert_eq!(Some(create_certificate.hash()), info.block_hash);
Expand Down Expand Up @@ -455,7 +455,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::root(2), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(3), info.next_block_height);
assert_eq!(Some(run_certificate.hash()), info.block_hash);
assert_eq!(Timestamp::from(5), info.timestamp);
Expand Down
4 changes: 2 additions & 2 deletions linera-core/src/unit_tests/worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::root(1), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(1), info.next_block_height);
assert_eq!(Some(certificate.hash()), info.block_hash);
assert!(info.manager.pending.is_none());
Expand Down Expand Up @@ -2434,7 +2434,7 @@ where
.unwrap()
.info;
assert_eq!(ChainId::root(1), info.chain_id);
assert_eq!(Amount::ZERO, info.system_balance);
assert_eq!(Amount::ZERO, info.chain_balance);
assert_eq!(BlockHeight::from(1), info.next_block_height);
assert_eq!(Some(certificate.hash()), info.block_hash);
assert!(info.manager.pending.is_none());
Expand Down
6 changes: 3 additions & 3 deletions linera-core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ where
let executed_block = chain.execute_block(&block, local_time).await?.with(block);
let mut response = ChainInfoResponse::new(&chain, None);
if let Some(signer) = signer {
response.info.requested_system_balance =
response.info.requested_owner_balance =
chain.execution_state.system.balances.get(&signer).await?;
}
// Do not save the new state.
Expand Down Expand Up @@ -1209,8 +1209,8 @@ where
if query.request_committees {
info.requested_committees = Some(chain.execution_state.system.committees.get().clone());
}
if let Some(owner) = query.request_system_balance {
info.requested_system_balance =
if let Some(owner) = query.request_owner_balance {
info.requested_owner_balance =
chain.execution_state.system.balances.get(&owner).await?;
}
if let Some(next_block_height) = query.test_next_block_height {
Expand Down
8 changes: 4 additions & 4 deletions linera-execution/src/execution_state_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ where
callback.respond((code, description));
}

SystemBalance { callback } => {
ChainBalance { callback } => {
let balance = *self.system.balance.get();
callback.respond(balance);
}
Expand Down Expand Up @@ -159,7 +159,7 @@ pub enum Request {
callback: Sender<(UserServiceCode, UserApplicationDescription)>,
},

SystemBalance {
ChainBalance {
callback: Sender<Amount>,
},

Expand Down Expand Up @@ -217,8 +217,8 @@ impl Debug for Request {
.field("id", id)
.finish_non_exhaustive(),

Request::SystemBalance { .. } => formatter
.debug_struct("Request::SystemBalance")
Request::ChainBalance { .. } => formatter
.debug_struct("Request::ChainBalance")
.finish_non_exhaustive(),

Request::SystemTimestamp { .. } => formatter
Expand Down
4 changes: 2 additions & 2 deletions linera-execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ pub trait BaseRuntime {
/// The current application parameters.
fn application_parameters(&mut self) -> Result<Vec<u8>, ExecutionError>;

/// Reads the system balance.
fn read_system_balance(&mut self) -> Result<Amount, ExecutionError>;
/// Reads the balance of the chain.
fn read_chain_balance(&mut self) -> Result<Amount, ExecutionError>;

/// Reads the system timestamp.
fn read_system_timestamp(&mut self) -> Result<Timestamp, ExecutionError>;
Expand Down
8 changes: 4 additions & 4 deletions linera-execution/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ impl<UserInstance> BaseRuntime for SyncRuntime<UserInstance> {
self.inner().application_parameters()
}

fn read_system_balance(&mut self) -> Result<Amount, ExecutionError> {
self.inner().read_system_balance()
fn read_chain_balance(&mut self) -> Result<Amount, ExecutionError> {
self.inner().read_chain_balance()
}

fn read_system_timestamp(&mut self) -> Result<Timestamp, ExecutionError> {
Expand Down Expand Up @@ -684,9 +684,9 @@ impl<UserInstance> BaseRuntime for SyncRuntimeInternal<UserInstance> {
Ok(self.current_application().parameters.clone())
}

fn read_system_balance(&mut self) -> Result<Amount, ExecutionError> {
fn read_chain_balance(&mut self) -> Result<Amount, ExecutionError> {
self.execution_state_sender
.send_request(|callback| Request::SystemBalance { callback })?
.send_request(|callback| Request::ChainBalance { callback })?
.recv_response()
}

Expand Down
5 changes: 2 additions & 3 deletions linera-execution/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ impl Display for SystemChannel {
pub enum Recipient {
/// This is mainly a placeholder for future extensions.
Burn,
/// Transfers to the system balance of the given owner (or any owner) at the given
/// chain.
/// Transfers to the balance of the given account.
Account(Account),
}

Expand All @@ -345,7 +344,7 @@ impl Recipient {
pub struct Account {
/// The chain of the account.
pub chain_id: ChainId,
/// The owner of the account.
/// The owner of the account, or `None` for the chain balance.
pub owner: Option<Owner>,
}

Expand Down
8 changes: 4 additions & 4 deletions linera-execution/src/wasm/system_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ macro_rules! impl_contract_system_api {
BaseRuntime::application_parameters(self)
}

fn read_system_balance(&mut self) -> Result<contract_system_api::Amount, Self::Error> {
BaseRuntime::read_system_balance(self).map(|balance| balance.into())
fn read_chain_balance(&mut self) -> Result<contract_system_api::Amount, Self::Error> {
BaseRuntime::read_chain_balance(self).map(|balance| balance.into())
}

fn read_system_timestamp(
Expand Down Expand Up @@ -129,8 +129,8 @@ macro_rules! impl_service_system_api {
BaseRuntime::application_parameters(self)
}

fn read_system_balance(&mut self) -> Result<service_system_api::Amount, Self::Error> {
BaseRuntime::read_system_balance(self).map(|balance| balance.into())
fn read_chain_balance(&mut self) -> Result<service_system_api::Amount, Self::Error> {
BaseRuntime::read_chain_balance(self).map(|balance| balance.into())
}

fn read_system_timestamp(
Expand Down
Binary file modified linera-execution/tests/fixtures/counter_contract.wasm
Binary file not shown.
Binary file modified linera-execution/tests/fixtures/counter_service.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions linera-execution/tests/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use test_case::test_case;
/// called correctly and consume the expected amount of fuel.
///
/// To update the bytecode files, run `linera-execution/update_wasm_fixtures.sh`.
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::Wasmer, 36_458, ExecutionRuntimeConfig::Synchronous; "wasmer"))]
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::WasmerWithSanitizer, 36_876, ExecutionRuntimeConfig::Synchronous; "wasmer_with_sanitizer"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::Wasmtime, 36_876, ExecutionRuntimeConfig::Synchronous; "wasmtime"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::WasmtimeWithSanitizer, 36_876, ExecutionRuntimeConfig::Synchronous; "wasmtime_with_sanitizer"))]
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::Wasmer, 37_228, ExecutionRuntimeConfig::Synchronous; "wasmer"))]
#[cfg_attr(feature = "wasmer", test_case(WasmRuntime::WasmerWithSanitizer, 37_655, ExecutionRuntimeConfig::Synchronous; "wasmer_with_sanitizer"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::Wasmtime, 37_655, ExecutionRuntimeConfig::Synchronous; "wasmtime"))]
#[cfg_attr(feature = "wasmtime", test_case(WasmRuntime::WasmtimeWithSanitizer, 37_655, ExecutionRuntimeConfig::Synchronous; "wasmtime_with_sanitizer"))]
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn test_fuel_for_counter_wasm_application(
wasm_runtime: WasmRuntime,
Expand Down
4 changes: 2 additions & 2 deletions linera-rpc/proto/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ message ChainInfoQuery {
// Query a value that contains a binary blob (e.g. bytecode) required by this chain.
optional bytes request_blob = 9;

// Query the system balance of a given owner.
optional Owner request_system_balance = 10;
// Query the balance of a given owner.
optional Owner request_owner_balance = 10;
}

// An authenticated proposal for a new block.
Expand Down
12 changes: 6 additions & 6 deletions linera-rpc/src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ impl TryFrom<grpc::ChainInfoQuery> for ChainInfoQuery {

Ok(Self {
request_committees: chain_info_query.request_committees,
request_system_balance: chain_info_query
.request_system_balance
request_owner_balance: chain_info_query
.request_owner_balance
.map(TryInto::try_into)
.transpose()?,
request_pending_messages: chain_info_query.request_pending_messages,
Expand Down Expand Up @@ -337,7 +337,7 @@ impl TryFrom<ChainInfoQuery> for grpc::ChainInfoQuery {
Ok(Self {
chain_id: Some(chain_info_query.chain_id.into()),
request_committees: chain_info_query.request_committees,
request_system_balance: chain_info_query.request_system_balance.map(Into::into),
request_owner_balance: chain_info_query.request_owner_balance.map(Into::into),
request_pending_messages: chain_info_query.request_pending_messages,
test_next_block_height: chain_info_query.test_next_block_height.map(Into::into),
request_sent_certificates_in_range,
Expand Down Expand Up @@ -554,13 +554,13 @@ pub mod tests {
epoch: None,
description: None,
manager: Box::default(),
system_balance: Amount::ZERO,
chain_balance: Amount::ZERO,
block_hash: None,
timestamp: Timestamp::default(),
next_block_height: BlockHeight::ZERO,
state_hash: None,
requested_committees: None,
requested_system_balance: None,
requested_owner_balance: None,
requested_pending_messages: vec![],
requested_sent_certificates: vec![],
count_received_log: 0,
Expand Down Expand Up @@ -592,7 +592,7 @@ pub mod tests {
chain_id: ChainId::root(0),
test_next_block_height: Some(BlockHeight::from(10)),
request_committees: false,
request_system_balance: None,
request_owner_balance: None,
request_pending_messages: false,
request_sent_certificates_in_range: Some(linera_core::data_types::BlockHeightRange {
start: BlockHeight::from(3),
Expand Down
6 changes: 3 additions & 3 deletions linera-rpc/tests/staged/formats.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ChainInfo:
TYPENAME: ChainDescription
- manager:
TYPENAME: ChainManagerInfo
- system_balance:
- chain_balance:
TYPENAME: Amount
- block_hash:
OPTION:
Expand All @@ -164,7 +164,7 @@ ChainInfo:
- state_hash:
OPTION:
TYPENAME: CryptoHash
- requested_system_balance:
- requested_owner_balance:
OPTION:
TYPENAME: Amount
- requested_committees:
Expand Down Expand Up @@ -194,7 +194,7 @@ ChainInfoQuery:
- test_next_block_height:
OPTION:
TYPENAME: BlockHeight
- request_system_balance:
- request_owner_balance:
OPTION:
TYPENAME: Owner
- request_committees: BOOL
Expand Down
2 changes: 1 addition & 1 deletion linera-sdk/contract_system_api.wit
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
chain-id: func() -> chain-id
application-id: func() -> application-id
application-parameters: func() -> list<u8>
read-system-balance: func() -> amount
read-chain-balance: func() -> amount
read-system-timestamp: func() -> timestamp

log: func(message: string, level: log-level)
Expand Down
Loading

0 comments on commit 3ffeed1

Please sign in to comment.