Skip to content

Commit

Permalink
chore(core): move GasInfo to core (#3130)
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop authored Sep 19, 2023
1 parent 3e3254e commit b386b2a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 5 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ paste = { workspace = true }
enum-iterator.workspace = true
byteorder.workspace = true

# Optional dependencies
serde = { workspace = true, features = [ "derive" ], optional = true }

[dev-dependencies]
wabt.workspace = true
env_logger.workspace = true
proptest.workspace = true

[features]
default = []
strict = []
std = ["serde/std"]
26 changes: 25 additions & 1 deletion core/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
use crate::costs::RuntimeCosts;
use enum_iterator::Sequence;
use scale_info::scale::{Decode, Encode};
use scale_info::{
scale::{Decode, Encode},
TypeInfo,
};

/// The id of the gas lock.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Sequence)]
Expand Down Expand Up @@ -329,6 +332,27 @@ impl From<(i64, i64)> for GasLeft {
}
}

/// The struct contains results of gas calculation required to process
/// a message.
#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct GasInfo {
/// Represents minimum gas limit required for execution.
pub min_limit: u64,
/// Gas amount that we reserve for some other on-chain interactions.
pub reserved: u64,
/// Contains number of gas burned during message processing.
pub burned: u64,
/// The value may be returned if a program happens to be executed
/// the second or next time in a block.
pub may_be_returned: u64,
/// Was the message placed into waitlist at the end of calculating.
///
/// This flag shows, that `min_limit` makes sense and have some guarantees
/// only before insertion into waitlist.
pub waited: bool,
}

#[cfg(test)]
mod tests {
use super::{ChargeResult, GasCounter};
Expand Down
2 changes: 1 addition & 1 deletion gsdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ anyhow.workspace = true
base64.workspace = true
futures-util.workspace = true
futures.workspace = true
gear-core.workspace = true
gear-core = { workspace = true, features = [ "std" ] }
gear-core-errors.workspace = true
hex.workspace = true
jsonrpsee = { workspace = true, features = [ "http-client", "ws-client" ] }
Expand Down
15 changes: 2 additions & 13 deletions gsdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ use crate::{
ActiveProgram,
},
};
pub use gear_core::gas::GasInfo;
use gear_core::ids::{MessageId, ReservationId};
use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
use parity_scale_codec::Decode;
use sp_runtime::AccountId32;
use std::collections::HashMap;
pub use subxt::dynamic::Value;
Expand Down Expand Up @@ -71,17 +71,6 @@ pub mod gp {
/// Block number type
pub type BlockNumber = u32;

/// Information of gas
#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq, Serialize, Deserialize)]
pub struct GasInfo {
/// Represents minimum gas limit required for execution.
pub min_limit: u64,
/// Gas amount that we reserve for some other on-chain interactions.
pub reserved: u64,
/// Contains number of gas burned during message processing.
pub burned: u64,
}

/// Gear gas node id.
pub type GearGasNodeId = GasNodeId<MessageId, ReservationId>;

Expand Down
2 changes: 1 addition & 1 deletion pallets/gear/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sp-rpc.workspace = true
sp-runtime.workspace = true

# Local packages
gear-core.workspace = true
gear-core = { workspace = true, features = ["std"] }
gear-core-errors = { workspace = true, features = ["codec"] }
gear-common.workspace = true
pallet-gear-rpc-runtime-api.workspace = true
22 changes: 1 addition & 21 deletions pallets/gear/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub use crate::{
pallet::*,
schedule::{HostFnWeights, InstructionWeights, Limits, MemoryWeights, Schedule},
};
pub use gear_core::gas::GasInfo;
pub use weights::WeightInfo;

use alloc::{format, string::String};
Expand Down Expand Up @@ -139,27 +140,6 @@ impl DebugInfo for () {
}
}

/// The struct contains results of gas calculation required to process
/// a message.
#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Deserialize, serde::Serialize))]
pub struct GasInfo {
/// Represents minimum gas limit required for execution.
pub min_limit: u64,
/// Gas amount that we reserve for some other on-chain interactions.
pub reserved: u64,
/// Contains number of gas burned during message processing.
pub burned: u64,
/// The value may be returned if a program happens to be executed
/// the second or next time in a block.
pub may_be_returned: u64,
/// Was the message placed into waitlist at the end of calculating.
///
/// This flag shows, that `min_limit` makes sense and have some guarantees
/// only before insertion into waitlist.
pub waited: bool,
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand Down

0 comments on commit b386b2a

Please sign in to comment.