Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 13 additions & 1 deletion contracts/linear/src/epoch_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,25 @@ impl LiquidStakingContract {
pub fn validator_get_balance_callback(
&mut self,
validator_id: AccountId,
#[callback] total_balance: U128,
#[callback_result] result: Result<U128, PromiseError>,
Comment thread
linguists marked this conversation as resolved.
Resolved
) {
let mut validator = self
.validator_pool
.get_validator(&validator_id)
.expect(ERR_VALIDATOR_NOT_EXIST);

let total_balance = match result {
Ok(total_balance) => total_balance,
Err(_) => {
validator.on_refresh_total_balance_failed(&mut self.validator_pool);
log!(
"Failed to refresh total balance from validator {}",
validator_id
);
return;
}
};

let new_balance = total_balance.0;
let rewards = new_balance - validator.total_balance();
Event::EpochUpdateRewards {
Expand Down
4 changes: 4 additions & 0 deletions contracts/linear/src/validator_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,10 @@ impl Validator {
pool.save_validator(self);
}

pub fn on_refresh_total_balance_failed(&mut self, pool: &mut ValidatorPool) {
self.post_execution(pool);
}

/// Due to shares calculation and rounding of staking pool contract,
/// the amount of staked and unstaked balance might be a little bit
/// different than we requested.
Expand Down
18 changes: 18 additions & 0 deletions tests/__tests__/linear/epoch-action-failure.ava.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,22 @@ test('get balance failure', async (t) => {

// balance should not change
await assertValidator(v1, '60', '0');

await v1.call(v1, 'set_panic', {
panic: false,
});

// update reward should be retryable after the failed callback releases executing
await owner.call(
contract,
'epoch_update_rewards',
{
validator_id: v1.accountId,
},
{
gas: Gas.parse('200 Tgas'),
},
);

await assertValidator(v1, '61', '0');
});
Loading