Add chronological event insertion for different application phases - #459
Conversation
|
Meta feedback about the PR (not specific to any file) 1/ Dont these need to be captured in the ChangeLog as well. 2/ Ditto for the |
The type should also be possible to be "system". Is that right? |
not anymore with this most recent change from George. |
|
Hmm, but in protocol 22 system events are not diagnostic events, they show up in the non-diagnostic event list. For example, in transaction {"v1":{"ext":"v0","ledger_header":{"hash":"97fd77288b59b4decde667d1c1a16b80ae07232361784ef4e3232a4cd452ac89","header":{"ledger_version":22,"previous_ledger_hash":"6f9fa8589a936b90810413da0542e03cb8d2f2655d029adc0ac5a2c967509c18","scp_value":{"tx_set_hash":"964b94104cab5dda7f901c38fb056210373bbdf2fe85593f96ebe80a67d83f80","close_time":1750133351,"upgrades":[],"ext":{"signed":{"node_id":"GCUCJTIYXSOXKBSNFGNFWW5MUQ54HKRPGJUTQFJ5RQXZXNOLNXYDHRAP","signature":"ca1967048a3114d29855f563274c337aa139554b291c945b92d73dec381ca339e464d9153d46c9c322e48c48c84e77bab4e10cbe07dedd0564509f710391a80b"}}},"tx_set_result_hash":"7d14f31c8791447f2dc51cc54dc3a6490ebe403ad926f1b5050bb6aadb6591f8","bucket_list_hash":"424c1bc5b3900559bd0ebafd26846cb03d53ea98b6467f0f7bce8163ea796b6d","ledger_seq":1544215,"total_coins":1000000000000000000,"fee_pool":1147371827130,"inflation_seq":0,"id_pool":32429,"base_fee":100,"base_reserve":5000000,"max_tx_set_size":200,"skip_list":["88409f229233e7ee2c1637bb31f61c0ac598fb636ffc1e1ad05d625c590b4c9a","eb60c2cc4083afd0f5f77d1ea54a0a0ff6a2272d3cba58842ea21949f72a935b","b4744b374f44323a1d3bd5319f4ae311cbe558243d6b29afbb2504d83700032e","14697d36f8d8f4e34738770a137d85b4d0203ae19eeeca9d997e70f0df951e1e"],"ext":"v0"},"ext":"v0"},"tx_set":{"v1":{"previous_ledger_hash":"6f9fa8589a936b90810413da0542e03cb8d2f2655d029adc0ac5a2c967509c18","phases":[{"v0":[]},{"v0":[{"txset_comp_txs_maybe_discounted_fee":{"base_fee":100,"txs":[{"tx":{"tx":{"source_account":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL","fee":100207,"seq_num":5095695228862537,"cond":"none","memo":"none","operations":[{"source_account":null,"body":{"invoke_host_function":{"host_function":{"invoke_contract":{"contract_address":"CCWFZSNOO4PJGDX563OEIQNOADGUUUWZM44AULJZKLEAXP6PSJN64CQX","function_name":"upgrade","args":[{"bytes":"010cbf093498c3f8582505bd0f383c6ad196f51d00d764fa3a7f28f90f6c49d6"}]}},"auth":[{"credentials":"source_account","root_invocation":{"function":{"contract_fn":{"contract_address":"CCWFZSNOO4PJGDX563OEIQNOADGUUUWZM44AULJZKLEAXP6PSJN64CQX","function_name":"upgrade","args":[{"bytes":"010cbf093498c3f8582505bd0f383c6ad196f51d00d764fa3a7f28f90f6c49d6"}]}},"sub_invocations":[]}}]}}}],"ext":{"v1":{"ext":"v0","resources":{"footprint":{"read_only":[{"contract_code":{"hash":"010cbf093498c3f8582505bd0f383c6ad196f51d00d764fa3a7f28f90f6c49d6"}},{"contract_code":{"hash":"1d6f290f62afa4bfdb04435da1b335242566dae02f7e25c2ec491764c89eea46"}}],"read_write":[{"contract_data":{"contract":"CCWFZSNOO4PJGDX563OEIQNOADGUUUWZM44AULJZKLEAXP6PSJN64CQX","key":"ledger_key_contract_instance","durability":"persistent"}}]},"instructions":1180826,"read_bytes":3032,"write_bytes":180},"resource_fee":100107}}},"signatures":[{"hint":"1e193d9c","signature":"93fe5de9b29ad99fa6bff703c192aec91ee620f5f6092825ad7f6ac851a13866d5df802dd49eebfca8a13cf74f977d5be38c57cd925b41c6b5d9a5b56365f907"}]}}]}}]}]}},"tx_processing":[{"result":{"transaction_hash":"a130817e905f2102a01bd02874cd21dda236e7a79637865549f018430293e416","result":{"fee_charged":54981,"result":{"tx_success":[{"op_inner":{"invoke_host_function":{"success":"5a4330705560a94d339db17f1cdc680aab541e2b015b4e26f37418d894cf92e9"}}}]},"ext":"v0"}},"fee_processing":[{"state":{"last_modified_ledger_seq":1544202,"data":{"account":{"account_id":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL","balance":99616111584,"seq_num":5095695228862536,"num_sub_entries":0,"inflation_dest":null,"flags":0,"home_domain":"","thresholds":"01000000","signers":[],"ext":{"v1":{"liabilities":{"buying":0,"selling":0},"ext":{"v2":{"num_sponsored":0,"num_sponsoring":0,"signer_sponsoring_i_ds":[],"ext":{"v3":{"ext":"v0","seq_ledger":1544202,"seq_time":1750133286}}}}}}}},"ext":"v0"}},{"updated":{"last_modified_ledger_seq":1544215,"data":{"account":{"account_id":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL","balance":99616011377,"seq_num":5095695228862536,"num_sub_entries":0,"inflation_dest":null,"flags":0,"home_domain":"","thresholds":"01000000","signers":[],"ext":{"v1":{"liabilities":{"buying":0,"selling":0},"ext":{"v2":{"num_sponsored":0,"num_sponsoring":0,"signer_sponsoring_i_ds":[],"ext":{"v3":{"ext":"v0","seq_ledger":1544202,"seq_time":1750133286}}}}}}}},"ext":"v0"}}],"tx_apply_processing":{"v3":{"ext":"v0","tx_changes_before":[{"state":{"last_modified_ledger_seq":1544215,"data":{"account":{"account_id":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL","balance":99616011377,"seq_num":5095695228862536,"num_sub_entries":0,"inflation_dest":null,"flags":0,"home_domain":"","thresholds":"01000000","signers":[],"ext":{"v1":{"liabilities":{"buying":0,"selling":0},"ext":{"v2":{"num_sponsored":0,"num_sponsoring":0,"signer_sponsoring_i_ds":[],"ext":{"v3":{"ext":"v0","seq_ledger":1544202,"seq_time":1750133286}}}}}}}},"ext":"v0"}},{"updated":{"last_modified_ledger_seq":1544215,"data":{"account":{"account_id":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL","balance":99616011377,"seq_num":5095695228862537,"num_sub_entries":0,"inflation_dest":null,"flags":0,"home_domain":"","thresholds":"01000000","signers":[],"ext":{"v1":{"liabilities":{"buying":0,"selling":0},"ext":{"v2":{"num_sponsored":0,"num_sponsoring":0,"signer_sponsoring_i_ds":[],"ext":{"v3":{"ext":"v0","seq_ledger":1544215,"seq_time":1750133351}}}}}}}},"ext":"v0"}}],"operations":[{"changes":[{"state":{"last_modified_ledger_seq":1544185,"data":{"contract_data":{"ext":"v0","contract":"CCWFZSNOO4PJGDX563OEIQNOADGUUUWZM44AULJZKLEAXP6PSJN64CQX","key":"ledger_key_contract_instance","durability":"persistent","val":{"contract_instance":{"executable":{"wasm":"1d6f290f62afa4bfdb04435da1b335242566dae02f7e25c2ec491764c89eea46"},"storage":[{"key":{"vec":[{"symbol":"Admin"}]},"val":{"address":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL"}}]}}}},"ext":"v0"}},{"updated":{"last_modified_ledger_seq":1544215,"data":{"contract_data":{"ext":"v0","contract":"CCWFZSNOO4PJGDX563OEIQNOADGUUUWZM44AULJZKLEAXP6PSJN64CQX","key":"ledger_key_contract_instance","durability":"persistent","val":{"contract_instance":{"executable":{"wasm":"010cbf093498c3f8582505bd0f383c6ad196f51d00d764fa3a7f28f90f6c49d6"},"storage":[{"key":{"vec":[{"symbol":"Admin"}]},"val":{"address":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL"}}]}}}},"ext":"v0"}}]}],"tx_changes_after":[{"state":{"last_modified_ledger_seq":1544215,"data":{"account":{"account_id":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL","balance":99616011377,"seq_num":5095695228862537,"num_sub_entries":0,"inflation_dest":null,"flags":0,"home_domain":"","thresholds":"01000000","signers":[],"ext":{"v1":{"liabilities":{"buying":0,"selling":0},"ext":{"v2":{"num_sponsored":0,"num_sponsoring":0,"signer_sponsoring_i_ds":[],"ext":{"v3":{"ext":"v0","seq_ledger":1544215,"seq_time":1750133351}}}}}}}},"ext":"v0"}},{"updated":{"last_modified_ledger_seq":1544215,"data":{"account":{"account_id":"GAZMNKR7VTGSTW4NBTDYD5FL7ZFG5ANYTSA2FJJC7X7L7RA6DE6ZZDYL","balance":99616056603,"seq_num":5095695228862537,"num_sub_entries":0,"inflation_dest":null,"flags":0,"home_domain":"","thresholds":"01000000","signers":[],"ext":{"v1":{"liabilities":{"buying":0,"selling":0},"ext":{"v2":{"num_sponsored":0,"num_sponsoring":0,"signer_sponsoring_i_ds":[],"ext":{"v3":{"ext":"v0","seq_ledger":1544215,"seq_time":1750133351}}}}}}}},"ext":"v0"}}],"soroban_meta":{"ext":"v0","events":[{"ext":"v0","contract_id":"ac5cc9ae771e930efdf6dc4441ae00cd4a52d967380a2d3952c80bbfcf925bee","type_":"system","body":{"v0":{"topics":[{"symbol":"executable_update"},{"vec":[{"symbol":"Wasm"},{"bytes":"1d6f290f62afa4bfdb04435da1b335242566dae02f7e25c2ec491764c89eea46"}]},{"vec":[{"symbol":"Wasm"},{"bytes":"010cbf093498c3f8582505bd0f383c6ad196f51d00d764fa3a7f28f90f6c49d6"}]}],"data":{"vec":[]}}}}],"return_value":"void","diagnostic_events":[]}}}}],"upgrades_processing":[],"scp_info":[],"total_byte_size_of_bucket_list":265396726,"evicted_temporary_ledger_keys":[],"evicted_persistent_ledger_entries":[]}}Looking at the transactions
@sisuresh Will system events still show up in the non-diagnostic events, and show up in the events stored in the operation and transaction-level events? |
Yeah system events will still show up in non-diagnostic operation events. System events are just events emitted by the system during an invocation, and get hashed into the ledger. |
This is totally my bad, I was under the incorrect impression that @sisuresh : one more clarification. |
Yeah system events can show up in |
|
So long story short, if I understand the discussion correctly:
|
b408ae0 to
cc84484
Compare
tamirms
left a comment
There was a problem hiding this comment.
nice job coming up with a cursor that handles chronological ordering and preserves the pre-existing events!
sreuland
left a comment
There was a problem hiding this comment.
lgtm, nice design up front to wrangle complexity of raw events in such a small code footprint!


What
TL;DR: This accomplishes three goals for
getEvents:With Protocol 23, the chronological order of event generation is as follows:
We need to gather these out of the meta in the right order. We also need to maintain two important properties of events stored in the database:
To accomplish this, we leverage/abuse the 1-indexed semantics of the transaction index in a TOID to maintain the following properties for the IDs in the format
<TOID>-<event index>:{ ledger seq, 0, 0 }<{ ledger seq, tx index, op index }<{ ledger seq, tx index, op max }<{ ledger seq, tx max, 0 }Here,
tx maxandop maxreflect the respective mask specified by the TOID spec.Note that this means operation-level events, the only types of events that existed before, still have their same ID as they did beforehand (as evidenced by the lack of changes to the unit tests in that domain).
Why
So that
getEventsreturns events in the same chronological order that Core generated them in, see #414.Known limitations
n/a