Skip to main content
deleted 126 characters in body
Source Link

So, as it turns out, I found what my problem is: I was trying to close a set of accounts in a loop that contained other instructions, and a last instruction outside of it, which messed things up.

If instead of doing that, I get the sum of the rents, and apply it at the very end, instead of updating the payer account at each step of the loop it works. So it looks something like this:

let rents = 0;
for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? = 0;
    rents += lamports;
}
another_instruction()?;
**payer.try_borrow_mut_lamports()? += rents;

So, as it turns out, I found what my problem is: I was trying to close a set of accounts in a loop that contained other instructions, and a last instruction outside of it, which messed things up.

If instead of doing that, I get the sum of the rents, and apply it at the very end, it works. So it looks something like this:

let rents = 0;
for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? = 0;
    rents += lamports;
}
another_instruction()?;
**payer.try_borrow_mut_lamports()? += rents;

So, I found what my problem is.

If I get the sum of the rents and apply it at the very end instead of updating the payer account at each step of the loop it works. So it looks something like this:

let rents = 0;
for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? = 0;
    rents += lamports;
}
another_instruction()?;
**payer.try_borrow_mut_lamports()? += rents;
Edited to put the problem code in the question
Source Link

So, as it turns out, I found what my problem is: I was trying to close a set of accounts in a loop that contained other instructions, and a last instruction outside of it, which messed things up.

Basically something like this:

for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? -= lamports;
    **payer.try_borrow_mut_lamports()? += lamports;
}
another_instruction()?;

If instead of doing, that, I get the sum of the rents, and apply thatit at the very end, it works. So it looks something like this:

let rents = 0;
for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? = 0;
    rents += lamports;
}
another_instruction()?;
**payer.try_borrow_mut_lamports()? += rents;

So, as it turns out, I found what my problem is: I was trying to close a set of accounts in a loop that contained other instructions, and a last instruction outside of it, which messed things up.

Basically something like this:

for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? -= lamports;
    **payer.try_borrow_mut_lamports()? += lamports;
}
another_instruction()?;

If instead of doing, that, I get the sum of the rents, and apply that at the very end, it works. So it looks something like this:

let rents = 0;
for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? = 0;
    rents += lamports;
}
another_instruction()?;
**payer.try_borrow_mut_lamports()? += rents;

So, as it turns out, I found what my problem is: I was trying to close a set of accounts in a loop that contained other instructions, and a last instruction outside of it, which messed things up.

If instead of doing that, I get the sum of the rents, and apply it at the very end, it works. So it looks something like this:

let rents = 0;
for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? = 0;
    rents += lamports;
}
another_instruction()?;
**payer.try_borrow_mut_lamports()? += rents;
Source Link

So, as it turns out, I found what my problem is: I was trying to close a set of accounts in a loop that contained other instructions, and a last instruction outside of it, which messed things up.

Basically something like this:

for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? -= lamports;
    **payer.try_borrow_mut_lamports()? += lamports;
}
another_instruction()?;

If instead of doing, that, I get the sum of the rents, and apply that at the very end, it works. So it looks something like this:

let rents = 0;
for account in accounts {
    instruction_whatever(account)?;
    let lamports = account.lamports();
    **account.try_borrow_mut_lamports()? = 0;
    rents += lamports;
}
another_instruction()?;
**payer.try_borrow_mut_lamports()? += rents;