Skip to content

Commit beef1df

Browse files
Merge pull request #76 from ElrondNetwork/multisig-fix-7
Multisig - clean up storage before performing async_call
2 parents 823bf47 + ef0486e commit beef1df

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

contracts/examples/multisig/mandos/deployAdder_then_call.scen.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,48 @@
259259
"refund": "*"
260260
}
261261
},
262+
{
263+
"step": "scCall",
264+
"comment": "check that account data got cleaned up",
265+
"txId": "check-cleanup-1",
266+
"tx": {
267+
"from": "address:paul",
268+
"to": "address:multisig",
269+
"value": "0",
270+
"function": "getActionData",
271+
"arguments": ["4"],
272+
"gasLimit": "1,000,000",
273+
"gasPrice": "0"
274+
},
275+
"expect": {
276+
"out": [ "" ],
277+
"status": "",
278+
"logs": [],
279+
"gas": "*",
280+
"refund": "*"
281+
}
282+
},
283+
{
284+
"step": "scCall",
285+
"comment": "check that account data got cleaned up",
286+
"txId": "check-cleanup-2",
287+
"tx": {
288+
"from": "address:paul",
289+
"to": "address:multisig",
290+
"value": "0",
291+
"function": "getActionSigners",
292+
"arguments": ["4"],
293+
"gasLimit": "1,000,000",
294+
"gasPrice": "0"
295+
},
296+
"expect": {
297+
"out": [ "" ],
298+
"status": "",
299+
"logs": [],
300+
"gas": "*",
301+
"refund": "*"
302+
}
303+
},
262304
{
263305
"step": "checkState",
264306
"accounts": {

contracts/examples/multisig/src/lib.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ pub trait Multisig {
350350

351351
fn perform_action(&self, action_id: usize) -> SCResult<MultiResultVec<BoxedBytes>> {
352352
let action = self.get_action_data(action_id);
353+
354+
// clean up storage
355+
// happens before actual execution, because the async_call kills contract execution,
356+
// so cleanup cannot happen afterwards
357+
self.set_action_data(action_id, &Action::Nothing);
358+
self.set_action_signer_ids(action_id, &[][..]);
359+
self.set_pending_action_count(self.get_pending_action_count() - 1);
360+
353361
let mut result = Vec::<BoxedBytes>::new();
354362
match action {
355363
Action::Nothing => {},
@@ -411,10 +419,6 @@ pub trait Multisig {
411419
},
412420
}
413421

414-
// clean up storage
415-
self.set_action_data(action_id, &Action::Nothing);
416-
self.set_action_signer_ids(action_id, &[][..]);
417-
self.set_pending_action_count(self.get_pending_action_count() - 1);
418422
Ok(result.into())
419423
}
420424
}

0 commit comments

Comments
 (0)