[FIX] Double swap events wrong
When we do a swap involving a double swap, events are wrong in Thorchain thus balances are wrong in Midgard.
Example smoke test TX 29 Transaction USER-1 ==> VAULT | [<Coin 5000000000BNB.LOK-3C0>] | SWAP:BNB.BNB
We trigger a double swap:
- 5000000000 LOK ----> 4854247129 RUNE
- 4854247129 RUNE ---> 10405499 BNB
We get these events in thorchain, see down.
Issue: we get for both events the same TxIns and TxOuts but on different pool with different trade_slip, liquidity_fee on the swap events. Both events have the transaction for the "second" swap of the double swap.
The swap events have the correct pool asset, but the first event should have TxIn and TxOut of the first double swap, TxIn being LOK and TxOut being RUNE.
{
"id": "51",
"height": "963",
"type": "swap",
"in_tx": {
"id": "5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN",
"chain": "BNB",
"from_address": "tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff",
"to_address": "tbnb12p63ydy54k80cl8dezep0xhcexrtqqg5atcd6v",
"coins": [
{
"asset": "BNB.RUNE-A1F",
"amount": "4854247129"
}
],
"gas": [
{
"asset": "BNB.BNB",
"amount": "37500"
}
],
"memo": "SWAP:BNB.BNB"
},
"out_txs": [
{
"id": "VC9NZUC184K8O98ZX5K8VMMWSKF2UBEEDCMYXA4DHAKFMVYEQM1GZTU6YQ08OJFH",
"chain": "BNB",
"from_address": "tbnb12p63ydy54k80cl8dezep0xhcexrtqqg5atcd6v",
"to_address": "tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff",
"coins": [
{
"asset": "BNB.BNB",
"amount": "10405499"
}
],
"gas": [
{
"asset": "BNB.BNB",
"amount": "37500"
}
],
"memo": "OUTBOUND:5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN"
}
],
"gas": null,
"event": {
"pool": "BNB.LOK-3C0",
"price_target": "0",
"trade_slip": "2591",
"liquidity_fee": "592639915"
},
"status": "Success"
},
{
"id": "52",
"height": "963",
"type": "swap",
"in_tx": {
"id": "5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN",
"chain": "BNB",
"from_address": "tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff",
"to_address": "tbnb12p63ydy54k80cl8dezep0xhcexrtqqg5atcd6v",
"coins": [
{
"asset": "BNB.RUNE-A1F",
"amount": "4854247129"
}
],
"gas": [
{
"asset": "BNB.BNB",
"amount": "37500"
}
],
"memo": "SWAP:BNB.BNB"
},
"out_txs": [
{
"id": "VC9NZUC184K8O98ZX5K8VMMWSKF2UBEEDCMYXA4DHAKFMVYEQM1GZTU6YQ08OJFH",
"chain": "BNB",
"from_address": "tbnb12p63ydy54k80cl8dezep0xhcexrtqqg5atcd6v",
"to_address": "tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff",
"coins": [
{
"asset": "BNB.BNB",
"amount": "10405499"
}
],
"gas": [
{
"asset": "BNB.BNB",
"amount": "37500"
}
],
"memo": "OUTBOUND:5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN"
}
],
"gas": null,
"event": {
"pool": "BNB.BNB",
"price_target": "0",
"trade_slip": "890",
"liquidity_fee": "194184588"
},
"status": "Success"
},
Logs in thorchain daemon container:
I[2020-02-14|08:42:49.792] is_active_observer module=main key=active_observer/1/THOR12P63YDY54K80CL8DEZEP0XHCEXRTQQG5HAH7WV
I[2020-02-14|08:42:49.792] handleMsgObservedTxIn request module=main Tx:="5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN: tbnb157dxmw9jz5emuf0apj4d6p3ee42ck
0uwksxfff ==> tbnb12p63ydy54k80cl8dezep0xhcexrtqqg5atcd6v (Memo: SWAP:BNB.BNB) BNB.LOK-3C05000000000"
I[2020-02-14|08:42:49.794] is_active_observer module=main key=active_observer/1/THOR12P63YDY54K80CL8DEZEP0XHCEXRTQQG5HAH7WV
I[2020-02-14|08:42:49.794] receive MsgSwap module=main requesttxhash=5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN sourceasset=BNB.LOK-3C0 ta
rgetasset=BNB.BNB signer=thor12p63ydy54k80cl8dezep0xhcexrtqqg5hah7wv
I[2020-02-14|08:42:49.795] tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff Swapping BNB.LOK-3C0(5000000000) -> BNB.RUNE-A1F to tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff module=main
I[2020-02-14|08:42:49.796] Pre-Pool: 50061728396Rune 40954439649Asset module=main
I[2020-02-14|08:42:49.796] Post-swap: 45207481267Rune 45954439649Asset , user get:4854247129 module=main
I[2020-02-14|08:42:49.796] tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff Swapping BNB.RUNE-A1F(4854247129) -> BNB.BNB to tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff module=main
I[2020-02-14|08:42:49.797] Pre-Pool: 111426881623Rune 260117493Asset module=main
I[2020-02-14|08:42:49.797] Post-swap: 116281128752Rune 249711994Asset , user get:10405499 module=main
I[2020-02-14|08:42:49.798] event id(51): 5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN module=main
I[2020-02-14|08:42:49.799] event id(52): 5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN module=main
E[2020-02-14|08:42:49.801] Unable to get all pending events module=main error="fail to unmarshal event id: unmarshal to int64 didn't read all bytes. Expected to read 2, only rea
d 1: 3334"
E[2020-02-14|08:42:49.801] Unable to slash for lack of signing: module=main error="fail to unmarshal event id: unmarshal to int64 didn't read all bytes. Expected to read 2, only rea
d 1: 3334"
I[2020-02-14|08:42:49.802] Executed block module=state height=963 validTxs=1 invalidTxs=0
I[2020-02-14|08:42:49.826] Committed state module=state height=963 txs=1 appHash=E6A30A53A6826D9A8AF770F9553E5F3F6A2A61026C0BD2D3386B2E91E365594D
E[2020-02-14|08:42:54.808] Unable to get all pending events module=main error="fail to unmarshal event id: unmarshal to int64 didn't read all bytes. Expected to read 2, only rea
d 1: 3334"
E[2020-02-14|08:42:54.808] Unable to slash for lack of signing: module=main error="fail to unmarshal event id: unmarshal to int64 didn't read all bytes. Expected to read 2, only rea
d 1: 3334"
I[2020-02-14|08:42:54.809] Executed block module=state height=964 validTxs=0 invalidTxs=0
I[2020-02-14|08:42:54.836] Committed state module=state height=964 txs=0 appHash=E6A30A53A6826D9A8AF770F9553E5F3F6A2A61026C0BD2D3386B2E91E365594D
E[2020-02-14|08:42:59.830] Unable to get all pending events module=main error="fail to unmarshal event id: unmarshal to int64 didn't read all bytes. Expected to read 2, only rea
d 1: 3334"
E[2020-02-14|08:42:59.830] Unable to slash for lack of signing: module=main error="fail to unmarshal event id: unmarshal to int64 didn't read all bytes. Expected to read 2, only rea
d 1: 3334"
I[2020-02-14|08:42:59.832] Executed block module=state height=965 validTxs=0 invalidTxs=0
I[2020-02-14|08:42:59.858] Committed state module=state height=965 txs=0 appHash=E6A30A53A6826D9A8AF770F9553E5F3F6A2A61026C0BD2D3386B2E91E365594D
I[2020-02-14|08:43:04.856] is_active_observer module=main key=active_observer/1/THOR12P63YDY54K80CL8DEZEP0XHCEXRTQQG5HAH7WV
I[2020-02-14|08:43:04.857] handleMsgObservedTxOut request module=main Tx:="VC9NZUC184K8O98ZX5K8VMMWSKF2UBEEDCMYXA4DHAKFMVYEQM1GZTU6YQ08OJFH: tbnb12p63ydy54k80cl8dezep0xhcexrtq
qg5atcd6v ==> tbnb157dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff (Memo: OUTBOUND:5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN) BNB.BNB10405499"
I[2020-02-14|08:43:04.859] is_active_observer module=main key=active_observer/1/THOR12P63YDY54K80CL8DEZEP0XHCEXRTQQG5HAH7WV
I[2020-02-14|08:43:04.859] receive MsgOutboundTx module=main requestoutboundtxhash=VC9NZUC184K8O98ZX5K8VMMWSKF2UBEEDCMYXA4DHAKFMVYEQM1GZTU6YQ08OJFH
I[2020-02-14|08:43:04.859] txid(5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN) module=main
I[2020-02-14|08:43:04.859] set event to Success,eventID (51) , txs:[VC9NZUC184K8O98ZX5K8VMMWSKF2UBEEDCMYXA4DHAKFMVYEQM1GZTU6YQ08OJFH: tbnb12p63ydy54k80cl8dezep0xhcexrtqqg5atcd6v ==> tbnb157
dxmw9jz5emuf0apj4d6p3ee42ck0uwksxfff (Memo: OUTBOUND:5VHEYCB44TYL1MJV1LYW79SJ7TQ47GPH5UINBTUJ04LOJ36DN1VIRNBDA06GFTTN) BNB.BNB10405499] module=main