Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix bug that account counter wasn't properly persited
  • Loading branch information
athei committed Oct 28, 2021
commit a7201f29f23abac0515f8235a0a20f9c870ad803
25 changes: 14 additions & 11 deletions frame/contracts/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,15 @@ where
value: BalanceOf<T>,
debug_message: Option<&'a mut Vec<u8>>,
) -> Result<(Self, E), ExecError> {
let (first_frame, executable) = Self::new_frame(args, value, gas_meter, 0, &schedule)?;
let (first_frame, executable, account_counter) =
Self::new_frame(args, value, gas_meter, 0, &schedule)?;
let stack = Self {
origin,
schedule,
gas_meter,
timestamp: T::Time::now(),
block_number: <frame_system::Pallet<T>>::block_number(),
account_counter: None,
account_counter,
first_frame,
frames: Default::default(),
debug_message,
Expand All @@ -565,8 +566,9 @@ where
gas_meter: &mut GasMeter<T>,
gas_limit: Weight,
schedule: &Schedule<T>,
) -> Result<(Frame<T>, E), ExecError> {
let (account_id, contract_info, executable, entry_point) = match frame_args {
) -> Result<(Frame<T>, E, Option<u64>), ExecError> {
let (account_id, contract_info, executable, entry_point, account_counter) = match frame_args
{
FrameArgs::Call { dest, cached_info } => {
let contract = if let Some(contract) = cached_info {
contract
Expand All @@ -576,7 +578,7 @@ where

let executable = E::from_storage(contract.code_hash, schedule, gas_meter)?;

(dest, contract, executable, ExportedFunction::Call)
(dest, contract, executable, ExportedFunction::Call, None)
},
FrameArgs::Instantiate { sender, trie_seed, executable, salt } => {
let account_id =
Expand All @@ -587,7 +589,7 @@ where
trie_id,
executable.code_hash().clone(),
)?;
(account_id, contract, executable, ExportedFunction::Constructor)
(account_id, contract, executable, ExportedFunction::Constructor, Some(trie_seed))
},
};

Expand All @@ -600,7 +602,7 @@ where
allows_reentry: true,
};

Ok((frame, executable))
Ok((frame, executable, account_counter))
}

/// Create a subsequent nested frame.
Expand Down Expand Up @@ -629,7 +631,7 @@ where

let nested_meter =
&mut self.frames.last_mut().unwrap_or(&mut self.first_frame).nested_meter;
let (frame, executable) =
let (frame, executable, _) =
Self::new_frame(frame_args, value_transferred, nested_meter, gas_limit, self.schedule)?;
self.frames.push(frame);
Ok(executable)
Expand Down Expand Up @@ -842,7 +844,7 @@ where
/// Increments the cached account id and returns the value to be used for the trie_id.
fn next_trie_seed(&mut self) -> u64 {
let next = if let Some(current) = self.account_counter {
current + 1
current.wrapping_add(1)
} else {
Self::initial_trie_seed()
};
Expand Down Expand Up @@ -2173,7 +2175,7 @@ mod tests {
let succ_fail_code = MockLoader::insert(Constructor, move |ctx, _| {
ctx.ext
.instantiate(0, fail_code, ctx.ext.minimum_balance() * 100, vec![], &[])
.unwrap();
.ok();
exec_success()
});
let succ_succ_code = MockLoader::insert(Constructor, move |ctx, _| {
Expand Down Expand Up @@ -2211,7 +2213,8 @@ mod tests {
vec![],
&[],
None,
);
)
.ok();
assert_eq!(<AccountCounter<Test>>::get(), 0);

assert_ok!(MockStack::run_instantiate(
Expand Down