diff --git a/pallets/vtoken-voting/src/lib.rs b/pallets/vtoken-voting/src/lib.rs index d130ca18d..bb9ba028c 100644 --- a/pallets/vtoken-voting/src/lib.rs +++ b/pallets/vtoken-voting/src/lib.rs @@ -335,8 +335,9 @@ pub mod pallet { T::RelaychainBlockNumberProvider::current_block_number(); weight += T::DbWeight::get().reads(1); - ReferendumTimeout::::take(relay_current_block_number).iter().for_each( - |(vtoken, poll_index)| { + let timeout = ReferendumTimeout::::get(relay_current_block_number); + if !timeout.is_empty() { + timeout.iter().for_each(|(vtoken, poll_index)| { ReferendumInfoFor::::mutate( vtoken, poll_index, @@ -351,8 +352,10 @@ pub mod pallet { }, ); weight += T::DbWeight::get().reads_writes(1, 1); - }, - ); + }); + weight += T::DbWeight::get().reads_writes(1, 1); + ReferendumTimeout::::remove(relay_current_block_number); + } weight } @@ -619,7 +622,7 @@ pub mod pallet { let success = Response::DispatchResult(MaybeErrorCode::Success) == response; if let Some((vtoken, poll_index, derivative_index, who, vote)) = - PendingVotingInfo::::take(query_id) + PendingVotingInfo::::get(query_id) { if !success { // rollback vote @@ -638,10 +641,11 @@ pub mod pallet { }, )?; } + PendingVotingInfo::::remove(query_id); Self::deposit_event(Event::::VoteNotified { vtoken, poll_index, success }); } - if let Some((vtoken, poll_index)) = PendingReferendumInfo::::take(query_id) { + if let Some((vtoken, poll_index)) = PendingReferendumInfo::::get(query_id) { if success { ReferendumInfoFor::::try_mutate_exists( vtoken, @@ -676,6 +680,7 @@ pub mod pallet { } else { ReferendumInfoFor::::remove(vtoken, poll_index); } + PendingReferendumInfo::::remove(query_id); } Self::deposit_event(Event::::ResponseReceived { responder, query_id, response }); @@ -692,7 +697,7 @@ pub mod pallet { ) -> DispatchResult { let responder = Self::ensure_xcm_response_or_governance(origin)?; if let Some((vtoken, poll_index, derivative_index)) = - PendingRemoveDelegatorVote::::take(query_id) + PendingRemoveDelegatorVote::::get(query_id) { let success = Response::DispatchResult(MaybeErrorCode::Success) == response; if success { @@ -711,6 +716,7 @@ pub mod pallet { }, )?; } + PendingRemoveDelegatorVote::::remove(query_id); Self::deposit_event(Event::::DelegatorVoteRemovedNotified { vtoken, poll_index,