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

Change logs from map to slice #3655

Merged
merged 15 commits into from
Dec 27, 2021
Merged

Conversation

bogdan-rosianu
Copy link
Contributor

Change logs and events from map to slice -> in order to ensure the order of the events when saving them into outport drivers

@bogdan-rosianu bogdan-rosianu self-assigned this Dec 21, 2021
@codecov
Copy link

codecov bot commented Dec 21, 2021

Codecov Report

Merging #3655 (046d0e2) into development (9899a97) will increase coverage by 0.00%.
The diff coverage is 89.36%.

Impacted file tree graph

@@             Coverage Diff              @@
##           development    #3655   +/-   ##
============================================
  Coverage        73.68%   73.69%           
============================================
  Files              587      587           
  Lines            76031    76040    +9     
============================================
+ Hits             56027    56035    +8     
- Misses           15561    15563    +2     
+ Partials          4443     4442    -1     
Impacted Files Coverage Δ
process/transactionLog/process.go 86.02% <77.27%> (-2.22%) ⬇️
dblookupext/esdtSupply/esdtSuppliesProcessor.go 73.52% <100.00%> (+3.52%) ⬆️
dblookupext/esdtSupply/logsGetter.go 77.77% <100.00%> (-1.39%) ⬇️
dblookupext/esdtSupply/logsProcessor.go 72.80% <100.00%> (ø)
dblookupext/historyRepository.go 76.09% <100.00%> (ø)
process/coordinator/process.go 76.60% <100.00%> (ø)
process/transactionLog/printTxLogProcessor.go 100.00% <100.00%> (ø)
p2p/libp2p/netMessenger.go 75.00% <0.00%> (ø)
process/block/baseProcess.go 67.77% <0.00%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 957a2ff...046d0e2. Read the comment docs.

@bogdan-rosianu bogdan-rosianu marked this pull request as ready for review December 21, 2021 15:36
@ssd04 ssd04 self-requested a review December 21, 2021 16:07
dblookupext/esdtSupply/logsGetter.go Outdated Show resolved Hide resolved
dblookupext/esdtSupply/logsGetter.go Outdated Show resolved Hide resolved
dblookupext/esdtSupply/logsGetter.go Outdated Show resolved Hide resolved
go.mod Outdated
github.com/ElrondNetwork/covalent-indexer-go v1.0.4
github.com/ElrondNetwork/elastic-indexer-go v1.1.28
github.com/ElrondNetwork/elrond-go-core v1.1.5
github.com/ElrondNetwork/covalent-indexer-go v1.0.5-0.20211221133537-5f9e7df77444
Copy link
Contributor

Choose a reason for hiding this comment

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

proper relases

@@ -53,7 +55,8 @@ func NewTxLogProcessor(args ArgTxLogProcessor) (*txLogProcessor, error) {
return &txLogProcessor{
storer: storer,
marshalizer: args.Marshalizer,
logs: make(map[string]data.LogHandler),
logs: make([]indexer.LogData, 0),
logsIndices: make(map[string]int),
Copy link
Contributor

Choose a reason for hiding this comment

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

Strongly suggest to use slices of pointers for the logs, map[string]*indexer.LogData for the logsMap on L59
reasons:

  1. for...range on a slice of structs does not behave as expected, can end up with hard to catch bugs
  2. we are avoiding copying the same data over and over again. Using pointers we will copy only a uint64 value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored

process/transactionLog/process.go Outdated Show resolved Hide resolved
logs map[string]data.LogHandler,
) error

RecordBlock(blockHeaderHash []byte, blockHeader data.HeaderHandler, blockBody data.BodyHandler, scrResultsFromPool map[string]data.TransactionHandler, receiptsFromPool map[string]data.TransactionHandler, logs []*data.LogData, ) error
Copy link
Contributor

Choose a reason for hiding this comment

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

same here with the additional ,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thanks

logsMap[key] = value
}
logsSlice := make([]*data.LogData, 0, len(tlp.logs))
logsSlice = append(logsSlice, tlp.logs...)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a particular reason to not just set logsSlice := tlp.logs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it's safer to make a clone of the slice

ssd04
ssd04 previously approved these changes Dec 22, 2021
return sp.logsProc.processLogs(blockNonce, logs, false)
logsMap := make(map[string]*data.LogData)
for _, logData := range logs {
logsMap[logData.TxHash] = logData
Copy link
Contributor

Choose a reason for hiding this comment

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

nil check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

@@ -90,22 +91,3 @@ func (lg *logsGetter) getTxLog(txHash []byte) (data.LogHandler, bool, error) {

return logFromDB, true, nil
}

func mergeLogsSlices(m1, m2 []indexer.LogData) []indexer.LogData {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -55,6 +54,9 @@ func (lp *logsProcessor) processLogs(blockNonce uint64, logs []indexer.LogData,

supplies := make(map[string]*SupplyESDT)
for _, logHandler := range logs {
if logHandler == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

could have been: if logHandler == nil || check.IfNil(logHandler.LogHandler) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

go.sum Outdated
github.com/ElrondNetwork/covalent-indexer-go v1.0.5-0.20211221133537-5f9e7df77444/go.mod h1:dZGbdYuMcIx+E4N/FRT+k+fs0G/+OV4V6bhB58QpUEc=
github.com/ElrondNetwork/elastic-indexer-go v1.1.29-0.20211221131443-f8a5ee61cac4 h1:59JdRRT4Ydx97Og6iLe79xmwuVBD4P9IVGK9VVl8OFQ=
github.com/ElrondNetwork/elastic-indexer-go v1.1.29-0.20211221131443-f8a5ee61cac4/go.mod h1:nkcuucWvT9D+iEihxXLXGiK/Cach1tFm3TAj9gFIUcQ=
github.com/ElrondNetwork/covalent-indexer-go v1.0.5-0.20211222142224-033f6d346e44 h1:jNeBuGfjiqNN+zFOroUiP0D+fIYfhpVk+jSHEBaYkeQ=
Copy link
Contributor

Choose a reason for hiding this comment

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

proper releases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after everything is tested 👍

@@ -98,19 +97,19 @@ func (tlp *txLogProcessor) GetLogFromCache(txHash []byte) (indexer.LogData, bool

txLog, err := tlp.GetLog(txHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

could have made the logsIndices actually a map of logData and thus, removing the slice indexing on L95

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would leave it as it is as we want to make sure of the order

Copy link
Contributor

Choose a reason for hiding this comment

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

Irrelevant: the map could have been used just to avoid double reads: one from a map and one from the slice

ssd04
ssd04 previously approved these changes Dec 24, 2021
Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

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

System tests passed.

@iulianpascalau iulianpascalau merged commit e6ef82a into development Dec 27, 2021
@iulianpascalau iulianpascalau deleted the change-logs-map-to-slice branch December 27, 2021 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants