Commit b6e2ecba authored by Heimdall's avatar Heimdall
Browse files

add some comments

parent 74052928
Pipeline #265112623 failed with stages
in 3 minutes and 29 seconds
......@@ -211,7 +211,7 @@ func (h ErrataTxHandler) processErrataOutboundTx(ctx cosmos.Context, msg MsgErra
return nil, fmt.Errorf("tx out voter is not finalised")
}
tx := txOutVoter.Tx.Tx
if !tx.Chain.Equals(msg.Chain) {
if !tx.Chain.Equals(msg.Chain) || tx.Coins.IsEmpty() {
return &cosmos.Result{}, nil
}
// parse the outbound tx memo, so we can figure out which inbound tx triggered the outbound
......@@ -222,33 +222,71 @@ func (h ErrataTxHandler) processErrataOutboundTx(ctx cosmos.Context, msg MsgErra
if !m.IsOutbound() {
return nil, fmt.Errorf("%s is not outbound tx", m)
}
if m.IsInternal() {
ctx.Logger().Info("%s is internal tx , don't do anything", tx.Memo)
return &cosmos.Result{}, nil
}
vaultPubKey := txOutVoter.Tx.ObservedPubKey
if !vaultPubKey.IsEmpty() {
v, err := h.keeper.GetVault(ctx, vaultPubKey)
if err != nil {
return nil, fmt.Errorf("fail to get vault with pubkey %s: %w", vaultPubKey, err)
}
if v.IsAsgard() && (v.Status == RetiringVault || v.Status == ActiveVault) {
v.AddFunds(tx.Coins)
compensate := true
if v.IsAsgard() {
if v.Status == RetiringVault || v.Status == ActiveVault {
v.AddFunds(tx.Coins)
compensate = false
}
}
if v.IsYggdrasil() {
node, err := h.keeper.GetNodeAccountByPubKey(ctx, v.PubKey)
if err != nil {
return nil, fmt.Errorf("fail to get node account with pubkey: %s,err: %w", v.PubKey, err)
}
if !node.IsEmpty() && node.Status != NodeDisabled {
if !node.IsEmpty() && !node.Bond.IsZero() {
// as long as the node still has bond , we can just credit it back to it's yggdrasil vault.
// if the node request to leave , but has not refund it's bond yet , then they will be slashed,
// if the node stay in the network , then they can still hold the fund until they leave
// if the node already left , but only has little bond left , the slash logic will take it all , and then
// subsidise pool with reserve
v.AddFunds(tx.Coins)
compensate = false
}
}
if !v.IsEmpty() {
if err := h.keeper.SetVault(ctx, v); err != nil {
return nil, fmt.Errorf("fail to save vault: %w", err)
}
}
if err := h.keeper.SetVault(ctx, v); err != nil {
return nil, fmt.Errorf("fail to save vault: %w", err)
if compensate {
coin := tx.Coins[0]
p, err := h.keeper.GetPool(ctx, coin.GetAsset())
if err != nil {
return nil, fmt.Errorf("fail to get pool(%s): %w", coin.GetAsset(), err)
}
runeValue := p.AssetValueInRune(coin.Amount)
p.BalanceRune = p.BalanceRune.Add(runeValue)
p.BalanceAsset = common.SafeSub(p.BalanceAsset, coin.Amount)
h.keeper.SendFromModuleToModule(ctx, ReserveName, AsgardName, common.Coins{
common.NewCoin(common.RuneAsset(), runeValue),
})
if err := h.keeper.SetPool(ctx, p); err != nil {
return nil, fmt.Errorf("fail to save pool (%s) : %w", p.Asset, err)
}
// send errata event
mods := PoolMods{
NewPoolMod(p.Asset, runeValue, true, coin.Amount, false),
}
eventErrata := NewEventErrata(msg.TxID, mods)
if err := h.mgr.EventMgr().EmitEvent(ctx, eventErrata); err != nil {
return nil, ErrInternal(err, "fail to emit errata event")
}
}
}
if m.IsInternal() {
ctx.Logger().Info("%s is internal tx , don't do anything", tx.Memo)
return &cosmos.Result{}, nil
}
txInVoter, err := h.keeper.GetObservedTxInVoter(ctx, m.GetTxID())
if err != nil {
return nil, fmt.Errorf("fail to get tx in voter for tx (%s): %w", m.GetTxID(), err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment