-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix events treatments for txs endpoint #177
Conversation
In the presensence of orphans, we can have multiple executions of the same transaction yielding different events every time. This commit makes sure that each execution gets associated with its own events only.
At the moment the following transaction details page displays incoherent information: https://explorer.chainweb.com/mainnet/txdetail/vRoAnAGoQx290TqhTJ0EVJM9PxWNh3u5q_ZsY3f1Rog It looks as if a failed transaction has emitted non-gas events. This discrepancy is caused by the fact that this transaction appeared on an orphan block and ended up failing there while it succeeded on mainline. The bug fixed by this PR causes the curl localhost:1849/txs/txs?requestkey=vRoAnAGoQx290TqhTJ0EVJM9PxWNh3u5q_ZsY3f1Rog | jq -C Full Response[
{
"signers": [
{
"clist": [
{
"args": [],
"name": "coin.GAS"
},
{
"args": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
77.767619761037
],
"name": "coin.TRANSFER"
}
],
"pubKey": "faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
}
],
"height": 4001193,
"creationTime": "2023-08-19T19:02:13Z",
"nonce": "\"2023-08-19T19:02:22.528Z\"",
"result": [
{
"amount": 77.303796979163,
"token": "coin"
},
{
"amount": 21400.70376134421,
"token": "mok.token"
}
],
"sender": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"pactId": null,
"initialCode": null,
"gasLimit": 9000,
"gasPrice": 5.10018e-07,
"data": {
"d": {
"pred": "keys-all",
"keys": [
"faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
]
},
"c": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"b": 77.767619761037,
"a": 21400.70376134421
},
"metadata": null,
"code": "(kaddex.exchange.swap-exact-out (read-decimal 'a) (read-decimal 'b) [coin mok.token] (read-string 'c) (read-string 'c) (read-keyset 'd))",
"gas": 3605,
"logs": "yGwCAu-ZyFLMF9GA_vXcVkWUqiUo52aQJEPIW4ONbQI",
"events": [
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"99cb7008d7d70c94f138cc366a825f0d9c83a8a2f4ba82c86c666e0ab6fecf3a",
0.00183861489
]
},
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
77.303796979163
]
},
{
"name": "mok.token.TRANSFER",
"params": [
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
21400.70376134421
]
},
{
"name": "kaddex.exchange.UPDATE",
"params": [
"coin:mok.token",
{
"decimal": "13971.384193728172"
},
{
"decimal": "3857996.938024219913"
}
]
},
{
"name": "kaddex.exchange.SWAP",
"params": [
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
77.303796979163,
{
"refSpec": [
{
"name": "fungible-xchain-v1",
"namespace": null
},
{
"name": "fungible-v2",
"namespace": null
}
],
"refName": {
"name": "coin",
"namespace": null
}
},
21400.70376134421,
{
"refSpec": [
{
"name": "fungible-xchain-v1",
"namespace": null
},
{
"name": "fungible-v2",
"namespace": null
}
],
"refName": {
"name": "token",
"namespace": "mok"
}
}
]
},
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"6d87fd6e5e47185cb421459d2888bddba7a6c0f2c4ae5246d5f38f993818bb89",
0.004590162
]
}
],
"ttl": 600,
"blockTime": "2023-08-19T19:02:46.496395Z",
"proof": null,
"txid": 8067192,
"continuation": null,
"requestKey": "vRoAnAGoQx290TqhTJ0EVJM9PxWNh3u5q_ZsY3f1Rog",
"rollback": null,
"sigs": [
{
"sig": "a7062ee2fbd51ede80858c46278982db21c2e8957af94a89dafd8549e6c2a81027337202996f165e63ba12e0882e4d4e57247a0f1440f6eb7d35ddbf4492480f"
}
],
"success": true,
"blockHash": "NtoNvmxcendQTcZr_cOe8kayH5AGYsOzZrgwGQcVjv0",
"previousSteps": null,
"chain": 2,
"step": null
},
{
"signers": [
{
"clist": [
{
"args": [],
"name": "coin.GAS"
},
{
"args": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
77.767619761037
],
"name": "coin.TRANSFER"
}
],
"pubKey": "faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
}
],
"height": 4001193,
"creationTime": "2023-08-19T19:02:13Z",
"nonce": "\"2023-08-19T19:02:22.528Z\"",
"result": {
"info": "",
"message": "swap-exact-out: excessive input amount 78.167502492123",
"callStack": [],
"type": "TxFailure"
},
"sender": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"pactId": null,
"initialCode": null,
"gasLimit": 9000,
"gasPrice": 5.10018e-07,
"data": {
"d": {
"pred": "keys-all",
"keys": [
"faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
]
},
"c": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"b": 77.767619761037,
"a": 21400.70376134421
},
"metadata": null,
"code": "(kaddex.exchange.swap-exact-out (read-decimal 'a) (read-decimal 'b) [coin mok.token] (read-string 'c) (read-string 'c) (read-keyset 'd))",
"gas": 9000,
"logs": "JzDLfF0SsIasZPrftjWb_R66KuZ5VPMFdxCNwZ0PRtw",
"events": [
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"99cb7008d7d70c94f138cc366a825f0d9c83a8a2f4ba82c86c666e0ab6fecf3a",
0.00183861489
]
},
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
77.303796979163
]
},
{
"name": "mok.token.TRANSFER",
"params": [
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
21400.70376134421
]
},
{
"name": "kaddex.exchange.UPDATE",
"params": [
"coin:mok.token",
{
"decimal": "13971.384193728172"
},
{
"decimal": "3857996.938024219913"
}
]
},
{
"name": "kaddex.exchange.SWAP",
"params": [
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
77.303796979163,
{
"refSpec": [
{
"name": "fungible-xchain-v1",
"namespace": null
},
{
"name": "fungible-v2",
"namespace": null
}
],
"refName": {
"name": "coin",
"namespace": null
}
},
21400.70376134421,
{
"refSpec": [
{
"name": "fungible-xchain-v1",
"namespace": null
},
{
"name": "fungible-v2",
"namespace": null
}
],
"refName": {
"name": "token",
"namespace": "mok"
}
}
]
},
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"6d87fd6e5e47185cb421459d2888bddba7a6c0f2c4ae5246d5f38f993818bb89",
0.004590162
]
}
],
"ttl": 600,
"blockTime": "2023-08-19T19:02:48.103501Z",
"proof": null,
"txid": 0,
"continuation": null,
"requestKey": "vRoAnAGoQx290TqhTJ0EVJM9PxWNh3u5q_ZsY3f1Rog",
"rollback": null,
"sigs": [
{
"sig": "a7062ee2fbd51ede80858c46278982db21c2e8957af94a89dafd8549e6c2a81027337202996f165e63ba12e0882e4d4e57247a0f1440f6eb7d35ddbf4492480f"
}
],
"success": false,
"blockHash": "DUXA-li2N6XP1ptP5Pb0texgS2nDbYNnVkIkuirHz6s",
"previousSteps": null,
"chain": 2,
"step": null
}
] Notice the following transaction in particular: {
"height": 4001193,
"result": {
"type": "TxFailure"
...
},
"events": [
{
"name": "coin.TRANSFER",
...
},
{
"name": "coin.TRANSFER",
...
},
{
"name": "mok.token.TRANSFER",
...
},
... many more
],
"blockHash": "DUXA-li2N6XP1ptP5Pb0texgS2nDbYNnVkIkuirHz6s",
...
} After this PR: curl localhost:1849/txs/txs?requestkey=vRoAnAGoQx290TqhTJ0EVJM9PxWNh3u5q_ZsY3f1Rog | jq -C Full Response[
{
"blockHash": "NtoNvmxcendQTcZr_cOe8kayH5AGYsOzZrgwGQcVjv0",
"blockTime": "2023-08-19T19:02:46.496395Z",
"chain": 2,
"code": "(kaddex.exchange.swap-exact-out (read-decimal 'a) (read-decimal 'b) [coin mok.token] (read-string 'c) (read-string 'c) (read-keyset 'd))",
"continuation": null,
"creationTime": "2023-08-19T19:02:13Z",
"data": {
"a": 21400.70376134421,
"b": 77.767619761037,
"c": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"d": {
"keys": [
"faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
],
"pred": "keys-all"
}
},
"events": [
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"99cb7008d7d70c94f138cc366a825f0d9c83a8a2f4ba82c86c666e0ab6fecf3a",
0.00183861489
]
},
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
77.303796979163
]
},
{
"name": "mok.token.TRANSFER",
"params": [
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
21400.70376134421
]
},
{
"name": "kaddex.exchange.UPDATE",
"params": [
"coin:mok.token",
{
"decimal": "13971.384193728172"
},
{
"decimal": "3857996.938024219913"
}
]
},
{
"name": "kaddex.exchange.SWAP",
"params": [
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
77.303796979163,
{
"refName": {
"name": "coin",
"namespace": null
},
"refSpec": [
{
"name": "fungible-xchain-v1",
"namespace": null
},
{
"name": "fungible-v2",
"namespace": null
}
]
},
21400.70376134421,
{
"refName": {
"name": "token",
"namespace": "mok"
},
"refSpec": [
{
"name": "fungible-xchain-v1",
"namespace": null
},
{
"name": "fungible-v2",
"namespace": null
}
]
}
]
}
],
"gas": 3605,
"gasLimit": 9000,
"gasPrice": 5.10018e-07,
"height": 4001193,
"initialCode": null,
"logs": "yGwCAu-ZyFLMF9GA_vXcVkWUqiUo52aQJEPIW4ONbQI",
"metadata": null,
"nonce": "\"2023-08-19T19:02:22.528Z\"",
"pactId": null,
"previousSteps": null,
"proof": null,
"requestKey": "vRoAnAGoQx290TqhTJ0EVJM9PxWNh3u5q_ZsY3f1Rog",
"result": [
{
"amount": 77.303796979163,
"token": "coin"
},
{
"amount": 21400.70376134421,
"token": "mok.token"
}
],
"rollback": null,
"sender": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"signers": [
{
"clist": [
{
"args": [],
"name": "coin.GAS"
},
{
"args": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
77.767619761037
],
"name": "coin.TRANSFER"
}
],
"pubKey": "faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
}
],
"sigs": [
{
"sig": "a7062ee2fbd51ede80858c46278982db21c2e8957af94a89dafd8549e6c2a81027337202996f165e63ba12e0882e4d4e57247a0f1440f6eb7d35ddbf4492480f"
}
],
"step": null,
"success": true,
"ttl": 600,
"txid": 8067192
},
{
"blockHash": "DUXA-li2N6XP1ptP5Pb0texgS2nDbYNnVkIkuirHz6s",
"blockTime": "2023-08-19T19:02:48.103501Z",
"chain": 2,
"code": "(kaddex.exchange.swap-exact-out (read-decimal 'a) (read-decimal 'b) [coin mok.token] (read-string 'c) (read-string 'c) (read-keyset 'd))",
"continuation": null,
"creationTime": "2023-08-19T19:02:13Z",
"data": {
"a": 21400.70376134421,
"b": 77.767619761037,
"c": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"d": {
"keys": [
"faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
],
"pred": "keys-all"
}
},
"events": [
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"6d87fd6e5e47185cb421459d2888bddba7a6c0f2c4ae5246d5f38f993818bb89",
0.004590162
]
}
],
"gas": 9000,
"gasLimit": 9000,
"gasPrice": 5.10018e-07,
"height": 4001193,
"initialCode": null,
"logs": "JzDLfF0SsIasZPrftjWb_R66KuZ5VPMFdxCNwZ0PRtw",
"metadata": null,
"nonce": "\"2023-08-19T19:02:22.528Z\"",
"pactId": null,
"previousSteps": null,
"proof": null,
"requestKey": "vRoAnAGoQx290TqhTJ0EVJM9PxWNh3u5q_ZsY3f1Rog",
"result": {
"callStack": [],
"info": "",
"message": "swap-exact-out: excessive input amount 78.167502492123",
"type": "TxFailure"
},
"rollback": null,
"sender": "k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"signers": [
{
"clist": [
{
"args": [],
"name": "coin.GAS"
},
{
"args": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"Jmv7qp5izDnejTSE6fSctjC6Ndm9ZWjQsyuGELPmggg",
77.767619761037
],
"name": "coin.TRANSFER"
}
],
"pubKey": "faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81"
}
],
"sigs": [
{
"sig": "a7062ee2fbd51ede80858c46278982db21c2e8957af94a89dafd8549e6c2a81027337202996f165e63ba12e0882e4d4e57247a0f1440f6eb7d35ddbf4492480f"
}
],
"step": null,
"success": false,
"ttl": 600,
"txid": 0
}
] The failed transaction doesn't have the non-gas events anymore: {
"blockHash": "DUXA-li2N6XP1ptP5Pb0texgS2nDbYNnVkIkuirHz6s",
"height": 4001193,
"result": {
"type": "TxFailure"
...
},
"events": [
{
"name": "coin.TRANSFER",
"params": [
"k:faca5ae889fcbd144c908ba4757df4ee496aa849c52d6f30b5bf9e8a51ee3d81",
"6d87fd6e5e47185cb421459d2888bddba7a6c0f2c4ae5246d5f38f993818bb89",
0.004590162
]
}
],
"gas": 9000,
"gasLimit": 9000,
"gasPrice": 5.10018e-07,
...
} |
@@ -433,9 +433,10 @@ queryTxsByKey logger rk c = | |||
, Api._signer_capList = caps | |||
} | |||
let sigs = Api.Sig . unSignature . _signer_sig <$> dbSigners | |||
sameBlock tx ev = (unBlockId $ _tx_block tx) == (unBlockId $ _ev_block ev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you should put the wanted events in the let binding. Like this:
evsInTxBlock = filter (sameBlock tx) evs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, that toApiTxDetail
call was indeed busy enough already so I've applied your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change....not absolutely required.
In the presence of orphans, we can have multiple executions of the same transaction yielding different events every time. This PR makes sure that each execution gets associated with its own events only.