-
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
En 7527 index accounts #2304
En 7527 index accounts #2304
Conversation
# Conflicts: # core/indexer/elasticProcessor_test.go
core/indexer/elasticProcessor.go
Outdated
Refresh: "true", | ||
} | ||
|
||
return ei.elasticClient.DoRequest(req) |
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.
instead of DoRequest you have to use DoBulkRequest to save more than one account per request. You should create a request with size smaller than 1MB and send it.
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
enabledIndexesMap[index] = struct{}{} | ||
} | ||
if len(enabledIndexesMap) == 0 { | ||
return nil, fmt.Errorf("empty elastic search enabled indexes map") |
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.
define an error for this
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
core/indexer/processTransactions.go
Outdated
@@ -259,6 +264,19 @@ func (tdp *txDatabaseProcessor) setTransactionSearchOrder(transactions map[strin | |||
return transactions | |||
} | |||
|
|||
func addToAlteredAddresses(tx *Transaction, alteredAddresses map[string]struct{}, miniBlock *block.MiniBlock, selfShardID uint32) { | |||
if selfShardID == miniBlock.SenderShardID { |
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.
you can refactor here to be more clear.
isIntraShard ---> save sender and receiver address
isCrossShardDstMe ---> save receiver
else if isNotRewardMB --> save sender
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 after Iulian's suggestion
core/indexer/common.go
Outdated
@@ -391,7 +392,21 @@ func GetElasticTemplatesAndPolicies() (map[string]*bytes.Buffer, map[string]*byt | |||
|
|||
func getTemplateByIndex(index string) *bytes.Buffer { | |||
indexTemplate := &bytes.Buffer{} | |||
_ = core.LoadJsonFile(&indexTemplate, "./config/elasticIndexTemplates/"+index+".json") | |||
|
|||
// TODO: (maybe) un-do this code before merging. for some reason, in local tests, the older version did not work |
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.
@miiu96 ?
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.
Remove TODO or code?
@@ -126,3 +126,47 @@ func TestMaxIntShouldReturnB(t *testing.T) { | |||
b := 11 | |||
assert.Equal(t, b, core.MaxInt(a, b)) | |||
} | |||
|
|||
func TestMaxFloat64(t *testing.T) { |
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.
👍
selfShardID uint32, | ||
isRewardTx bool, | ||
) { | ||
if selfShardID == miniBlock.SenderShardID && !isRewardTx { |
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.
👍
} | ||
} | ||
} | ||
} |
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.
add empty line
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
@@ -641,8 +689,10 @@ func indexGenesisBlocks(args *processComponentsFactoryArgs, genesisBlocks map[ui | |||
return err | |||
} | |||
|
|||
log.Info("indexGenesisBlocks(): indexer.SaveBlock", "hash", genesisBlockHash) | |||
args.indexer.SaveBlock(&dataBlock.Body{}, genesisBlockHeader, nil, nil, nil) | |||
if !args.indexer.IsNilIndexer() { |
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.
(:+1:)
core/indexer/errors.go
Outdated
@@ -30,3 +30,9 @@ var ErrNilOptions = errors.New("nil options") | |||
|
|||
// ErrNegativeCacheSize signals that a invalid cache size has been provided | |||
var ErrNegativeCacheSize = errors.New("negative cache size") | |||
|
|||
// ErrNilAccountsDB signals that a nil accounts db has been provided |
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.
dont use shortcuts in comments
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
core/indexer/common.go
Outdated
serializedData = append(serializedData, "\n"...) | ||
|
||
buffLenWithCurrentAcc := buff.Len() + len(meta) + len(serializedData) | ||
if buffLenWithCurrentAcc > txsBulkSizeThreshold && buff.Len() != 0 { |
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.
maybe you can rename this const txsBulkSizeThreshold
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
core/indexer/common.go
Outdated
} | ||
_, err = buff.Write(serializedData) | ||
if err != nil { | ||
log.Warn("elastic search: serialize bulk accounts history, write serialized tx", "error", err.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.
`write serialized account hisotory1
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
core/indexer/common.go
Outdated
} | ||
_, err = buff.Write(serializedData) | ||
if err != nil { | ||
log.Warn("elastic search: serialize bulk accounts, write serialized tx", "error", err.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.
write serialized account
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
core/indexer/common.go
Outdated
// append a newline for each element | ||
serializedData = append(serializedData, "\n"...) | ||
|
||
buffLenWithCurrentAcc := buff.Len() + len(meta) + len(serializedData) |
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.
buffLenWithCurrentAccHistory
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
core/indexer/elasticProcessor.go
Outdated
return ei.saveAccountsHistory(accountsMap) | ||
} | ||
|
||
func (ei *elasticProcessor) saveAccountsHistory(accountInfoMap map[string]*AccountInfo) 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.
accountsInfoMap
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
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.
👍
This PR adds 2 functionalities:
transactions
there was the option to index or not. Now, all indexes can be configured.accounts
index that will contain data about used accounts (from genesis and from transactions).Testing procedure:
elasticURL/accounts/_search
where you should see entries for each used account (genesis + from transactions). The format of an account looks like this:/address/
endpoint for a few samples.