From fe0bb007c95e4f30966232c3e98e7b9200f56186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Mon, 6 Dec 2021 16:20:41 +0000 Subject: [PATCH] Don't reset total delegation on mixnode rebond (#940) --- contracts/mixnet/src/mixnodes/transactions.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/contracts/mixnet/src/mixnodes/transactions.rs b/contracts/mixnet/src/mixnodes/transactions.rs index c83d4518fe..e3f82ce7ee 100644 --- a/contracts/mixnet/src/mixnodes/transactions.rs +++ b/contracts/mixnet/src/mixnodes/transactions.rs @@ -88,7 +88,15 @@ fn _try_add_mixnode( // in different places that we can guarantee that if node exists, so does the data behind the total delegation let identity = stored_bond.identity(); storage::mixnodes().save(deps.storage, identity, &stored_bond)?; - storage::TOTAL_DELEGATION.save(deps.storage, identity, &Uint128::zero())?; + + // if this is a fresh mixnode - write 0 total delegation, otherwise, don't touch it since the node has just rebonded + if storage::TOTAL_DELEGATION + .may_load(deps.storage, identity)? + .is_none() + { + storage::TOTAL_DELEGATION.save(deps.storage, identity, &Uint128::zero())?; + } + mixnet_params_storage::increment_layer_count(deps.storage, stored_bond.layer)?; Ok(Response::new())