Alpha: don't fail when burning previously burned bond/fees/rewards.

Just in a case a baker double-bakes and doesn't reveal its nonce.
This commit is contained in:
Grégoire Henry 2018-03-15 14:20:59 +01:00 committed by Benjamin Canou
parent 0cf6f8fff2
commit a95e601284

View File

@ -190,8 +190,17 @@ let freeze_bond ctxt delegate amount =
let burn_bond ctxt delegate cycle amount = let burn_bond ctxt delegate cycle amount =
let contract = Contract_repr.implicit_contract delegate in let contract = Contract_repr.implicit_contract delegate in
get_frozen_bond ctxt contract cycle >>=? fun old_amount -> get_frozen_bond ctxt contract cycle >>=? fun old_amount ->
Roll_storage.Delegate.remove_amount ctxt delegate amount >>=? fun ctxt -> begin
Lwt.return Tez_repr.(old_amount -? amount) >>=? fun new_amount -> match Tez_repr.(old_amount -? amount) with
| Ok new_amount ->
Roll_storage.Delegate.remove_amount
ctxt delegate amount >>=? fun ctxt ->
return (new_amount, ctxt)
| Error _ ->
Roll_storage.Delegate.remove_amount
ctxt delegate old_amount >>=? fun ctxt ->
return (Tez_repr.zero, ctxt)
end >>=? fun (new_amount, ctxt) ->
Storage.Contract.Frozen_bonds.set (ctxt, contract) cycle new_amount Storage.Contract.Frozen_bonds.set (ctxt, contract) cycle new_amount
@ -217,8 +226,17 @@ let freeze_fees ctxt delegate amount =
let burn_fees ctxt delegate cycle amount = let burn_fees ctxt delegate cycle amount =
let contract = Contract_repr.implicit_contract delegate in let contract = Contract_repr.implicit_contract delegate in
get_frozen_fees ctxt contract cycle >>=? fun old_amount -> get_frozen_fees ctxt contract cycle >>=? fun old_amount ->
Roll_storage.Delegate.remove_amount ctxt delegate amount >>=? fun ctxt -> begin
Lwt.return Tez_repr.(old_amount -? amount) >>=? fun new_amount -> match Tez_repr.(old_amount -? amount) with
| Ok new_amount ->
Roll_storage.Delegate.remove_amount
ctxt delegate amount >>=? fun ctxt ->
return (new_amount, ctxt)
| Error _ ->
Roll_storage.Delegate.remove_amount
ctxt delegate old_amount >>=? fun ctxt ->
return (Tez_repr.zero, ctxt)
end >>=? fun (new_amount, ctxt) ->
Storage.Contract.Frozen_fees.set (ctxt, contract) cycle new_amount Storage.Contract.Frozen_fees.set (ctxt, contract) cycle new_amount
@ -242,7 +260,10 @@ let freeze_rewards ctxt delegate amount =
let burn_rewards ctxt delegate cycle amount = let burn_rewards ctxt delegate cycle amount =
let contract = Contract_repr.implicit_contract delegate in let contract = Contract_repr.implicit_contract delegate in
get_frozen_rewards ctxt contract cycle >>=? fun old_amount -> get_frozen_rewards ctxt contract cycle >>=? fun old_amount ->
Lwt.return Tez_repr.(old_amount -? amount) >>=? fun new_amount -> let new_amount =
match Tez_repr.(old_amount -? amount) with
| Error _ -> Tez_repr.zero
| Ok new_amount -> new_amount in
Storage.Contract.Frozen_rewards.set (ctxt, contract) cycle new_amount Storage.Contract.Frozen_rewards.set (ctxt, contract) cycle new_amount