Skip to content

Commit 843bb2d

Browse files
authored
Strict gas consumption on the high end usage (#14172)
## Description Make the gas charging harsher on the high end. This should affect nobody and make charging and running out of gas faster on the high end. ## Test Plan Existing tests --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] protocol change - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
1 parent 9495123 commit 843bb2d

File tree

1 file changed

+103
-5
lines changed

1 file changed

+103
-5
lines changed

move-vm/types/src/views.rs

Lines changed: 103 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ pub trait ValueView {
2424

2525
/// Returns the abstract memory size of the value.
2626
///
27-
/// The concept of abstract memory size is not well-defined and is only kept for backward compatibility.
28-
/// New applications should avoid using this.
29-
///
30-
/// TODO(Gas): Encourage clients to replicate this in their own repo and get this removed once
31-
/// they are done.
27+
/// This version of abstract memory size is not well-defined and is only kept for backward
28+
/// compatibility. New applications should avoid using this.
3229
fn legacy_abstract_memory_size(&self) -> AbstractMemorySize {
3330
use crate::values::{LEGACY_CONST_SIZE, LEGACY_REFERENCE_SIZE, LEGACY_STRUCT_SIZE};
3431

@@ -120,6 +117,107 @@ pub trait ValueView {
120117

121118
acc.0
122119
}
120+
121+
/// Returns the abstract memory size of the value.
122+
fn abstract_memory_size(&self) -> AbstractMemorySize {
123+
use crate::values::{LEGACY_CONST_SIZE, LEGACY_REFERENCE_SIZE, LEGACY_STRUCT_SIZE};
124+
125+
struct Acc(AbstractMemorySize);
126+
127+
impl ValueVisitor for Acc {
128+
fn visit_u8(&mut self, _depth: usize, _val: u8) {
129+
self.0 += LEGACY_CONST_SIZE;
130+
}
131+
132+
fn visit_u16(&mut self, _depth: usize, _val: u16) {
133+
self.0 += LEGACY_CONST_SIZE;
134+
}
135+
136+
fn visit_u32(&mut self, _depth: usize, _val: u32) {
137+
self.0 += LEGACY_CONST_SIZE;
138+
}
139+
140+
fn visit_u64(&mut self, _depth: usize, _val: u64) {
141+
self.0 += LEGACY_CONST_SIZE;
142+
}
143+
144+
fn visit_u128(&mut self, _depth: usize, _val: u128) {
145+
self.0 += LEGACY_CONST_SIZE;
146+
}
147+
148+
fn visit_u256(&mut self, _depth: usize, _val: move_core_types::u256::U256) {
149+
self.0 += LEGACY_CONST_SIZE;
150+
}
151+
152+
fn visit_bool(&mut self, _depth: usize, _val: bool) {
153+
self.0 += LEGACY_CONST_SIZE;
154+
}
155+
156+
fn visit_address(&mut self, _depth: usize, _val: AccountAddress) {
157+
self.0 += AbstractMemorySize::new(AccountAddress::LENGTH as u64);
158+
}
159+
160+
fn visit_struct(&mut self, _depth: usize, _len: usize) -> bool {
161+
self.0 += LEGACY_STRUCT_SIZE;
162+
true
163+
}
164+
165+
fn visit_vec(&mut self, _depth: usize, _len: usize) -> bool {
166+
self.0 += LEGACY_STRUCT_SIZE;
167+
true
168+
}
169+
170+
fn visit_vec_u8(&mut self, _depth: usize, vals: &[u8]) {
171+
self.0 += LEGACY_STRUCT_SIZE;
172+
self.0 += ((size_of::<u8>() * vals.len()) as u64).into();
173+
}
174+
175+
fn visit_vec_u16(&mut self, _depth: usize, vals: &[u16]) {
176+
self.0 += LEGACY_STRUCT_SIZE;
177+
self.0 += ((size_of::<u16>() * vals.len()) as u64).into();
178+
}
179+
180+
fn visit_vec_u32(&mut self, _depth: usize, vals: &[u32]) {
181+
self.0 += LEGACY_STRUCT_SIZE;
182+
self.0 += ((size_of::<u32>() * vals.len()) as u64).into();
183+
}
184+
185+
fn visit_vec_u64(&mut self, _depth: usize, vals: &[u64]) {
186+
self.0 += LEGACY_STRUCT_SIZE;
187+
self.0 += ((size_of::<u64>() * vals.len()) as u64).into();
188+
}
189+
190+
fn visit_vec_u128(&mut self, _depth: usize, vals: &[u128]) {
191+
self.0 += LEGACY_STRUCT_SIZE;
192+
self.0 += ((size_of::<u128>() * vals.len()) as u64).into();
193+
}
194+
195+
fn visit_vec_u256(&mut self, _depth: usize, vals: &[move_core_types::u256::U256]) {
196+
self.0 += LEGACY_STRUCT_SIZE;
197+
self.0 += ((size_of::<move_core_types::u256::U256>() * vals.len()) as u64).into();
198+
}
199+
200+
fn visit_vec_bool(&mut self, _depth: usize, vals: &[bool]) {
201+
self.0 += LEGACY_STRUCT_SIZE;
202+
self.0 += ((size_of::<bool>() * vals.len()) as u64).into();
203+
}
204+
205+
fn visit_vec_address(&mut self, _depth: usize, vals: &[AccountAddress]) {
206+
self.0 += LEGACY_STRUCT_SIZE;
207+
self.0 += ((size_of::<AccountAddress>() * vals.len()) as u64).into();
208+
}
209+
210+
fn visit_ref(&mut self, _depth: usize, _is_global: bool) -> bool {
211+
self.0 += LEGACY_REFERENCE_SIZE;
212+
false
213+
}
214+
}
215+
216+
let mut acc = Acc(0.into());
217+
self.visit(&mut acc);
218+
219+
acc.0
220+
}
123221
}
124222

125223
/// Trait that defines a visitor that could be used to traverse a value recursively.

0 commit comments

Comments
 (0)