Skip to content

Commit

Permalink
runtime-sdk: Fix consensus_accounts undelegation queue state
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jul 14, 2023
1 parent 2143d0f commit 39cc9b2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions runtime-sdk/src/modules/consensus_accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,11 @@ impl<Accounts: modules::accounts::API, Consensus: modules::consensus::API> modul
return;
}

let logger = ctx.get_logger("consensus_accounts");
slog::debug!(logger, "epoch changed, processing queued undelegations";
"epoch" => ctx.epoch(),
);

let mut reclaims: lru::LruCache<(EpochTime, Address), (u128, u128)> =
lru::LruCache::new(NonZeroUsize::new(128).unwrap());

Expand All @@ -737,6 +742,10 @@ impl<Accounts: modules::accounts::API, Consensus: modules::consensus::API> modul
for ud in qd {
let udi = state::take_undelegation(&ud).unwrap();

slog::debug!(logger, "processing undelegation";
"shares" => udi.shares,
);

// Determine total amount the runtime got during the reclaim operation.
let (total_amount, total_shares) =
if let Some(totals) = reclaims.get(&(ud.epoch, ud.from)) {
Expand Down
5 changes: 4 additions & 1 deletion runtime-sdk/src/modules/consensus_accounts/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ pub fn add_undelegation(
// Add to undelegation queue (if existing item is there, this will have no effect).
let store = storage::PrefixStore::new(root_store, &MODULE_NAME);
let mut queue = storage::PrefixStore::new(store, &UNDELEGATION_QUEUE);
queue.insert(&queue_entry_key(from, to, epoch), &[]);
queue.insert(
&queue_entry_key(from, to, epoch),
&[0xF6], /* CBOR NULL */
);

Ok(())
})
Expand Down

0 comments on commit 39cc9b2

Please sign in to comment.