Skip to content

Commit

Permalink
refactor(gclient): removed filtering static pages while creating memo…
Browse files Browse the repository at this point in the history
…ry dump (#4319)
  • Loading branch information
Lazark0x authored Nov 5, 2024
1 parent 712fc0d commit d43076a
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions gclient/src/api/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
use super::{GearApi, Result};
use crate::{api::storage::account_id::IntoAccountId32, utils, Error};
use anyhow::anyhow;
use gear_core::{
gas::LockId,
ids::*,
memory::PageBuf,
pages::{GearPage, WasmPage},
};
use gear_core::{gas::LockId, ids::*, memory::PageBuf, pages::GearPage};
use gear_utils::{MemoryPageDump, ProgramMemoryDump};
use gsdk::{
config::GearConfig,
Expand Down Expand Up @@ -637,27 +632,18 @@ impl GearApi {
) -> Result {
let program = self.0.api().gprog_at(program_id, block_hash).await?;

assert!(program.static_pages.0 > 0);
// TODO: consider to remove `-1` may be it's a bug #3893
let static_page_count = (program.static_pages.0 - 1) * WasmPage::SIZE / GearPage::SIZE;

let program_pages = self
.0
.api()
.gpages_at(program_id, Some(program.memory_infix.0), block_hash)
.await?
.into_iter()
.filter_map(|(page_number, page_data)| {
if page_number < static_page_count {
None
} else {
Some(MemoryPageDump::new(
GearPage::try_from(page_number).unwrap_or_else(|_| {
panic!("Couldn't decode GearPage from u32: {}", page_number)
}),
PageBuf::decode(&mut &*page_data).expect("Couldn't decode PageBuf"),
))
}
.map(|(page, data)| {
MemoryPageDump::new(
GearPage::try_from(page)
.unwrap_or_else(|_| panic!("Couldn't decode GearPage from u32: {}", page)),
PageBuf::decode(&mut &*data).expect("Couldn't decode PageBuf"),
)
})
.collect();

Expand Down

0 comments on commit d43076a

Please sign in to comment.