Skip to content

Commit

Permalink
removed filtering static pages while creating memory dump
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazark0x committed Oct 24, 2024
1 parent 73929e3 commit ded0d27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 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
15 changes: 5 additions & 10 deletions gclient/tests/memory_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,27 @@ async fn memory_dump() -> Result<()> {
.await?;
assert!(listener.message_processed(message_id).await?.succeed());

assert_eq!(
charge_10(&api, program_id, &mut listener).await.unwrap(),
""
);
assert_eq!(charge_10(&api, program_id, &mut listener).await?, "");

let cleanup = CleanupFolderOnDrop {
path: "./296c6962726".to_string(),
};

api.save_program_memory_dump_at(program_id, None, "./296c6962726/demo_custom.dump")
.await
.unwrap();
.await?;

assert_eq!(
charge_10(&api, program_id, &mut listener).await.unwrap(),
charge_10(&api, program_id, &mut listener).await?,
"Discharged: 20"
);

api.replace_program_memory(program_id, "./296c6962726/demo_custom.dump")
.await
.unwrap();
.await?;

drop(cleanup);

assert_eq!(
charge_10(&api, program_id, &mut listener).await.unwrap(),
charge_10(&api, program_id, &mut listener).await?,
"Discharged: 20"
);

Expand Down

0 comments on commit ded0d27

Please sign in to comment.