Skip to content
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

[EN] Fix uploader missing events in block data uploaded to GCP #4562

Merged
merged 2 commits into from
Jul 14, 2023

Conversation

fxamacker
Copy link
Member

@fxamacker fxamacker commented Jul 14, 2023

Closes #4558

Problem

The uploader in engine/execution/ingestion/uploader/ is only uploading the last event instead of all events.

The problem is caused by reusing variable returned by range which is a per-loop variable (it is not a per-iteration variable). Each iteration was just appending the same variable's address to events.

events := make([]*flow.Event, 0)
for _, e := range computationResult.AllEvents() {
	events = append(events, &e)  // BUG: same address appended each iteration.
}

When loop finishes, all elements of events is the same address of the same e.

Solution

This PR:

  • Fixes the problem by replacing range loop with an index-based loop.
  • Updates unit test to check for this problem.

2023-07-17 EDIT: Added more details about the problem and fix because there was a question about it.

Previously, only last event is included in block data (repeated n times).

This commit fixes the bug and includes all events.
@fxamacker fxamacker requested a review from koko1123 July 14, 2023 20:40
@fxamacker fxamacker requested a review from ramtinms as a code owner July 14, 2023 20:40
@fxamacker fxamacker self-assigned this Jul 14, 2023
eventsList := computationResult.AllEvents()
events := make([]*flow.Event, len(eventsList))
for i := 0; i < len(eventsList); i++ {
events[i] = &eventsList[i]
}

trieUpdates := make(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this be affected as well?

Copy link
Member Author

@fxamacker fxamacker Jul 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that code block avoids the problem and is unaffected by the bug. Also the unit test improved by this PR checks for the problem so tests won't pass anymore if that code is affected by the bug.

The bug in the old code is caused by reusing variable returned by range which is a per-loop variable (it is not a per-iteration variable). So &variable would point to same variable each iteration. Each iteration was just appending the same variable's address to events.

events := make([]*flow.Event, 0)
for _, e := range computationResult.AllEvents() {
	events = append(events, &e)  // BUG: same address appended each iteration.
}

All elements of events is the same address of the same e when loop finishes.

@github-actions
Copy link
Contributor

github-actions bot commented Jul 14, 2023

FVM Benchstat comparison

This branch with compared with the base branch onflow:master commit 72b4db9

The command (for i in {1..7}; do go test ./fvm ./engine/execution/computation --bench . --tags relic -shuffle=on --benchmem --run ^$; done) was used.

Collapsed results for better readability

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/reference_tx-243.7ms ± 5%44.1ms ± 6%~(p=0.534 n=6+7)
RuntimeTransaction/convert_int_to_string-249.6ms ±18%46.4ms ± 2%~(p=0.366 n=7+6)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-247.0ms ± 4%47.9ms ± 5%~(p=0.240 n=6+6)
RuntimeTransaction/get_signer_address-244.2ms ± 2%46.5ms ±15%~(p=0.318 n=7+7)
RuntimeTransaction/get_public_account-250.0ms ±22%47.4ms ± 4%~(p=0.535 n=7+7)
RuntimeTransaction/get_account_and_get_balance-2364ms ± 4%370ms ± 5%~(p=0.366 n=7+6)
RuntimeTransaction/get_account_and_get_available_balance-2369ms ± 2%369ms ± 6%~(p=0.945 n=6+7)
RuntimeTransaction/get_account_and_get_storage_used-250.1ms ± 2%50.9ms ± 3%~(p=0.234 n=6+7)
RuntimeTransaction/get_account_and_get_storage_capacity-2335ms ± 4%332ms ± 4%~(p=0.620 n=7+7)
RuntimeTransaction/get_signer_vault-253.8ms ± 2%53.4ms ± 2%~(p=0.394 n=6+6)
RuntimeTransaction/get_signer_receiver-268.9ms ± 7%69.6ms ± 4%~(p=0.902 n=7+7)
RuntimeTransaction/transfer_tokens-2278ms ± 3%277ms ± 2%~(p=0.456 n=7+7)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-254.5ms ± 6%52.8ms ± 4%~(p=0.073 n=7+7)
RuntimeTransaction/load_and_save_long_string_on_signers_address-2106ms ± 2%106ms ± 1%~(p=0.628 n=6+7)
RuntimeTransaction/create_new_account-21.04s ± 5%1.03s ± 3%~(p=0.902 n=7+7)
RuntimeTransaction/call_empty_contract_function-248.5ms ± 5%48.5ms ± 5%~(p=1.000 n=7+7)
RuntimeTransaction/emit_event-263.7ms ± 5%66.1ms ± 6%~(p=0.165 n=7+7)
RuntimeTransaction/borrow_array_from_storage-2167ms ± 1%172ms ± 7%~(p=0.165 n=7+7)
RuntimeTransaction/copy_array_from_storage-2165ms ± 2%167ms ± 6%~(p=0.710 n=7+7)
RuntimeNFTBatchTransfer-2144ms ± 3%148ms ± 4%~(p=0.295 n=6+7)
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes/1/max-concurrency-26.00s ± 2%5.97s ± 3%~(p=0.445 n=7+6)
ComputeBlock/16/cols/128/txes/2/max-concurrency-26.49s ± 3%6.35s ± 1%−2.17%(p=0.022 n=7+6)
 
computationdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/reference_tx-2202 ± 0%202 ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-2502 ± 0%502 ± 0%~(all equal)
RuntimeTransaction/get_signer_address-2302 ± 0%302 ± 0%~(all equal)
RuntimeTransaction/get_public_account-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_balance-21.00k ± 0%1.00k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_available_balance-23.10k ± 0%3.10k ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_used-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_account_and_get_storage_capacity-21.70k ± 0%1.70k ± 0%~(all equal)
RuntimeTransaction/get_signer_vault-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/get_signer_receiver-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/transfer_tokens-23.50k ± 0%3.50k ± 0%~(all equal)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/load_and_save_long_string_on_signers_address-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/create_new_account-2202 ± 0%202 ± 0%~(all equal)
RuntimeTransaction/call_empty_contract_function-2402 ± 0%402 ± 0%~(all equal)
RuntimeTransaction/emit_event-2602 ± 0%602 ± 0%~(all equal)
RuntimeTransaction/borrow_array_from_storage-22.60k ± 0%2.60k ± 0%~(all equal)
RuntimeTransaction/copy_array_from_storage-22.60k ± 0%2.60k ± 0%~(all equal)
 
interactionsdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/get_signer_receiver-238.2k ± 0%38.2k ± 0%+0.01%(p=0.021 n=6+7)
RuntimeTransaction/call_empty_contract_function-238.4k ± 0%38.4k ± 0%+0.01%(p=0.034 n=7+7)
RuntimeTransaction/reference_tx-238.2k ± 0%38.2k ± 0%~(p=0.316 n=6+7)
RuntimeTransaction/convert_int_to_string-238.2k ± 0%38.2k ± 0%~(p=0.131 n=7+7)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-238.2k ± 0%38.2k ± 0%~(p=0.783 n=7+7)
RuntimeTransaction/get_signer_address-238.2k ± 0%38.2k ± 0%~(p=0.784 n=7+7)
RuntimeTransaction/get_public_account-238.2k ± 0%38.2k ± 0%~(p=0.922 n=7+7)
RuntimeTransaction/get_account_and_get_balance-246.4k ± 0%46.4k ± 0%~(p=0.108 n=6+7)
RuntimeTransaction/get_account_and_get_available_balance-238.1k ± 0%38.1k ± 0%~(p=0.372 n=6+6)
RuntimeTransaction/get_account_and_get_storage_used-238.2k ± 0%38.2k ± 0%~(p=0.819 n=7+7)
RuntimeTransaction/get_account_and_get_storage_capacity-238.1k ± 0%38.1k ± 0%~(p=0.449 n=7+7)
RuntimeTransaction/get_signer_vault-238.2k ± 0%38.2k ± 0%~(p=0.590 n=7+7)
RuntimeTransaction/transfer_tokens-238.1k ± 0%38.1k ± 0%~(p=0.200 n=6+7)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-238.3k ± 0%38.3k ± 0%~(p=0.923 n=7+7)
RuntimeTransaction/load_and_save_long_string_on_signers_address-242.1k ± 0%42.1k ± 0%~(p=0.620 n=7+7)
RuntimeTransaction/create_new_account-284.6k ± 0%84.6k ± 0%~(p=0.592 n=7+7)
RuntimeTransaction/borrow_array_from_storage-243.4k ± 0%43.4k ± 0%~(p=0.078 n=7+6)
RuntimeTransaction/copy_array_from_storage-243.4k ± 0%43.4k ± 0%~(p=0.129 n=7+6)
RuntimeTransaction/emit_event-238.4k ± 0%38.4k ± 0%−0.02%(p=0.001 n=7+6)
 
alloc/opdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/get_account_and_get_available_balance-2109MB ± 4%111MB ± 2%+2.33%(p=0.026 n=7+7)
RuntimeTransaction/reference_tx-236.1MB ± 4%35.6MB ± 5%~(p=0.456 n=7+7)
RuntimeTransaction/convert_int_to_string-236.8MB ± 3%36.8MB ± 2%~(p=1.000 n=7+7)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-236.4MB ± 6%36.9MB ± 2%~(p=0.731 n=7+6)
RuntimeTransaction/get_signer_address-236.2MB ± 3%36.5MB ± 4%~(p=0.620 n=7+7)
RuntimeTransaction/get_public_account-237.3MB ± 4%36.8MB ± 5%~(p=0.318 n=7+7)
RuntimeTransaction/get_account_and_get_balance-2123MB ± 0%123MB ± 2%~(p=0.181 n=6+7)
RuntimeTransaction/get_account_and_get_storage_used-237.3MB ± 4%37.7MB ± 5%~(p=0.535 n=7+7)
RuntimeTransaction/get_account_and_get_storage_capacity-2105MB ± 5%104MB ± 4%~(p=0.128 n=7+7)
RuntimeTransaction/get_signer_vault-238.4MB ± 3%37.5MB ± 4%~(p=0.097 n=7+7)
RuntimeTransaction/get_signer_receiver-242.1MB ± 7%42.5MB ± 3%~(p=1.000 n=7+7)
RuntimeTransaction/transfer_tokens-282.2MB ± 5%81.5MB ± 2%~(p=0.383 n=7+7)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-237.9MB ± 4%37.5MB ± 4%~(p=0.535 n=7+7)
RuntimeTransaction/load_and_save_long_string_on_signers_address-254.6MB ± 4%54.2MB ± 6%~(p=0.805 n=7+7)
RuntimeTransaction/create_new_account-2184MB ± 3%183MB ± 4%~(p=0.710 n=7+7)
RuntimeTransaction/call_empty_contract_function-237.1MB ± 5%37.0MB ± 2%~(p=0.456 n=7+7)
RuntimeTransaction/emit_event-241.6MB ± 7%42.1MB ± 6%~(p=0.710 n=7+7)
RuntimeTransaction/borrow_array_from_storage-271.8MB ± 3%72.4MB ± 1%~(p=0.530 n=7+5)
RuntimeTransaction/copy_array_from_storage-282.0MB ± 3%83.2MB ± 3%~(p=0.209 n=7+7)
RuntimeNFTBatchTransfer-254.5MB ± 5%53.5MB ± 6%~(p=0.456 n=7+7)
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes/1/max-concurrency-21.24GB ± 1%1.24GB ± 0%~(p=0.628 n=6+7)
ComputeBlock/16/cols/128/txes/2/max-concurrency-21.29GB ± 0%1.29GB ± 1%~(p=0.051 n=6+7)
 
allocs/opdelta
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/reference_tx-292.4k ± 0%92.4k ± 0%~(p=0.727 n=7+7)
RuntimeTransaction/convert_int_to_string-2105k ± 0%105k ± 0%~(p=0.558 n=7+7)
RuntimeTransaction/convert_int_to_string_and_concatenate_it-2116k ± 0%116k ± 0%~(p=0.874 n=7+7)
RuntimeTransaction/get_signer_address-296.5k ± 0%96.5k ± 0%~(p=0.433 n=7+7)
RuntimeTransaction/get_account_and_get_balance-21.33M ± 0%1.33M ± 0%~(p=0.234 n=6+7)
RuntimeTransaction/get_account_and_get_available_balance-21.29M ± 0%1.29M ± 0%~(p=0.119 n=7+7)
RuntimeTransaction/get_account_and_get_storage_used-2132k ± 0%132k ± 0%~(p=0.314 n=6+7)
RuntimeTransaction/get_account_and_get_storage_capacity-21.16M ± 0%1.16M ± 0%~(p=0.535 n=7+7)
RuntimeTransaction/get_signer_receiver-2223k ± 0%223k ± 0%~(p=0.967 n=7+6)
RuntimeTransaction/transfer_tokens-2863k ± 0%863k ± 0%~(p=0.805 n=7+7)
RuntimeTransaction/load_and_save_empty_string_on_signers_address-2143k ± 0%143k ± 0%~(p=0.176 n=7+7)
RuntimeTransaction/load_and_save_long_string_on_signers_address-2226k ± 0%226k ± 0%~(p=0.318 n=7+7)
RuntimeTransaction/create_new_account-22.36M ± 0%2.36M ± 0%~(p=0.781 n=6+6)
RuntimeTransaction/call_empty_contract_function-2110k ± 0%110k ± 0%~(p=0.062 n=6+7)
RuntimeTransaction/emit_event-2151k ± 0%151k ± 0%~(p=0.165 n=7+7)
RuntimeTransaction/borrow_array_from_storage-2372k ± 0%372k ± 0%~(p=0.383 n=7+7)
RuntimeTransaction/copy_array_from_storage-2304k ± 0%304k ± 0%~(p=0.928 n=7+7)
RuntimeNFTBatchTransfer-2280k ± 0%280k ± 1%~(p=1.000 n=7+7)
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes/1/max-concurrency-217.8M ± 0%17.8M ± 0%~(p=0.710 n=7+7)
ComputeBlock/16/cols/128/txes/2/max-concurrency-218.4M ± 0%18.4M ± 0%~(p=0.535 n=7+7)
pkg:github.com/onflow/flow-go/fvm goos:linux goarch:amd64
RuntimeTransaction/get_signer_vault-2137k ± 0%137k ± 0%−0.01%(p=0.041 n=7+7)
RuntimeTransaction/get_public_account-2121k ± 0%121k ± 0%−0.01%(p=0.004 n=7+7)
 
us/txdelta
pkg:github.com/onflow/flow-go/engine/execution/computation goos:linux goarch:amd64
ComputeBlock/16/cols/128/txes/1/max-concurrency-22.93k ± 2%2.92k ± 3%~(p=0.445 n=7+6)
ComputeBlock/16/cols/128/txes/2/max-concurrency-23.17k ± 3%3.10k ± 1%−2.16%(p=0.020 n=7+6)
 

@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2023

Codecov Report

Merging #4562 (6fe26d1) into master (2528190) will decrease coverage by 1.81%.
The diff coverage is 47.38%.

@@            Coverage Diff             @@
##           master    #4562      +/-   ##
==========================================
- Coverage   56.25%   54.45%   -1.81%     
==========================================
  Files         653      914     +261     
  Lines       64699    85200   +20501     
==========================================
+ Hits        36396    46392    +9996     
- Misses      25362    35219    +9857     
- Partials     2941     3589     +648     
Flag Coverage Δ
unittests 54.45% <47.38%> (-1.81%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cmd/scaffold.go 14.83% <0.00%> (+0.06%) ⬆️
engine/access/rpc/backend/backend_transactions.go 49.01% <0.00%> (+2.86%) ⬆️
model/flow/identifierList.go 22.36% <0.00%> (+0.84%) ⬆️
model/verification/chunkDataPackRequest.go 43.75% <0.00%> (-6.25%) ⬇️
module/metrics/herocache.go 0.00% <0.00%> (ø)
module/metrics/network.go 0.00% <0.00%> (ø)
module/metrics/noop.go 0.00% <0.00%> (ø)
network/p2p/inspector/internal/cache/cache.go 64.70% <ø> (ø)
network/p2p/middleware/middleware.go 1.71% <0.00%> (ø)
network/p2p/p2pbuilder/libp2pNodeBuilder.go 0.00% <0.00%> (ø)
... and 27 more

... and 246 files with indirect coverage changes

@fxamacker fxamacker changed the title Fix missing events in uploaded block data uploaded to GCP Fix missing events in block data uploaded to GCP Jul 14, 2023
@fxamacker fxamacker added the Execution Cadence Execution Team label Jul 14, 2023
Copy link
Member

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this

@fxamacker fxamacker merged commit f1d5a06 into master Jul 14, 2023
34 checks passed
@fxamacker fxamacker deleted the fxamacker/fix-incomplete-events-in-gcp-uploader branch July 14, 2023 22:38
@fxamacker fxamacker changed the title Fix missing events in block data uploaded to GCP [EN] Fix uploader missing events in block data uploaded to GCP Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Execution Cadence Execution Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Execution node uploader only uploads last event instead of all events.
4 participants