Add context to fee and outbound events to enable them to be handled without cross-referencing

Background

As events are processed by Midgard it uses them to update the depths. For example:

Gas event:

attrs: map[string]string{"asset":"BNB.BNB", "asset_amt":"37500", "rune_amt":"0", "transaction_count":"1"}

The rune_amt is added to the RUNE depth of the BNB.BNB pool, and the asset_amt is deducted from the asset depth of the BNB.BNB pool. This can be done without any further information other than what is contained in the event and makes for very simple handling. However if we consider this event:

Fee event:

attrs: map[string]string{"coins":"100000000 BNB.RUNE-B1A", "pool_deduct":"0", "tx_id":"8241CC03D8EFD4B75E6A84C7B707841AC5581529FAF919D8AA4D1880B266CD38"}

Here the RUNE amount should be deducted from a pool, unless the fee is associated with either a refund or a swap event. To process this we need to find out which kind of event is the fee is associated with and which pool that event is for. So we can't process this as we see it, we have to wait until the end of the block and then do some cross-referencing of other events.

Outbound event:

attrs: map[string]string{"chain":"BNB", "coin":"900000000 BNB.RUNE-B1A", "from":"bnb13l3j9zj25kdpafuah2c5r6yp57udm7nftwmf4y", "id":"C7F5FD60DA98503D76FE57FF44852E575DB28A4A02EBCF3FCEC1255B9600F3CA", "in_tx_id":"8241CC03D8EFD4B75E6A84C7B707841AC5581529FAF919D8AA4D1880B266CD38", "memo":"REFUND:8241CC03D8EFD4B75E6A84C7B707841AC5581529FAF919D8AA4D1880B266CD38", "to":"bnb1tgn9ug8sm8kpqmfcul835rxrg835shp3sdcj47"}

Similarly here, we need to cross-reference the outbound with its associated event in order to discover whether it should be deducted from a pool and which pool that should be.

Why this is bad

This cross referencing of events during syncing results in huge complexity in Midgard, both the old version and the in-development version and makes arriving at an accurate depth complex and fragile which has led to inefficient development and bugs. Carrying this complexity going forwards will have ongoing cost as new developers and community members try to understand the code and make changes.

Proposed solution

Given the upcoming move to a multichain net, we have the opportunity to change events.

Events should be sufficiently self-contained that they can for the most part be processed without cross-referencing to other events. Two simple changes would mostly enable this:

Fee event: add the following fields pool (e.g. BNB.BNB) and event type (refund/swap/unstake, etc)

Outbound event: add the following fields: pool (e.g. BNB.BNB) and event type (refund/swap/unstake, etc)

This would allow fee events and outbound events to be interpreted without further context.

It would also be an option to make swap, refund, unstake etc events entirely self contained and also contain the network fee and outbound amount, though this seems a bigger change from the thornode side.

Chain bloat

Adding the fields proposed above would result in some chain bloat but given the positives I think it's worth it.