-
Notifications
You must be signed in to change notification settings - Fork 198
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
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 |
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.
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), |
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.
Strongly suggest to use slices of pointers for the logs, map[string]*indexer.LogData
for the logsMap on L59
reasons:
for...range
on a slice of structs does not behave as expected, can end up with hard to catch bugs- we are avoiding copying the same data over and over again. Using pointers we will copy only a uint64 value.
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.
refactored
dblookupext/interface.go
Outdated
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 |
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.
same here with the additional ,
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.
done, thanks
# Conflicts: # go.mod # go.sum
logsMap[key] = value | ||
} | ||
logsSlice := make([]*data.LogData, 0, len(tlp.logs)) | ||
logsSlice = append(logsSlice, tlp.logs...) |
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.
is there a particular reason to not just set logsSlice := tlp.logs
?
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.
yes, it's safer to make a clone of the slice
return sp.logsProc.processLogs(blockNonce, logs, false) | ||
logsMap := make(map[string]*data.LogData) | ||
for _, logData := range logs { | ||
logsMap[logData.TxHash] = logData |
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.
nil check here?
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.
added
dblookupext/esdtSupply/logsGetter.go
Outdated
@@ -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 { |
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.
👍
@@ -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 { |
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.
could have been: if logHandler == nil || check.IfNil(logHandler.LogHandler) {
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.
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= |
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.
proper releases
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.
after everything is tested 👍
@@ -98,19 +97,19 @@ func (tlp *txLogProcessor) GetLogFromCache(txHash []byte) (indexer.LogData, bool | |||
|
|||
txLog, err := tlp.GetLog(txHash) |
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.
could have made the logsIndices actually a map of logData and thus, removing the slice indexing on L95
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 would leave it as it is as we want to make sure of the order
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.
Irrelevant: the map could have been used just to avoid double reads: one from a map and one from the slice
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.
System tests passed.
Change logs and events from map to slice -> in order to ensure the order of the events when saving them into outport drivers