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 7527 index accounts #2304

Merged
merged 22 commits into from
Oct 6, 2020
Merged

En 7527 index accounts #2304

merged 22 commits into from
Oct 6, 2020

Conversation

bogdan-rosianu
Copy link
Contributor

@bogdan-rosianu bogdan-rosianu commented Sep 18, 2020

This PR adds 2 functionalities:

  1. ability to index only the given indexes. Before this, only for transactions there was the option to index or not. Now, all indexes can be configured.
  2. the accounts index that will contain data about used accounts (from genesis and from transactions).

Testing procedure:

  1. run a testnet with some elastic observers
  2. send some transactions
  3. check the accounts index: GET on elasticURL/accounts/_search where you should see entries for each used account (genesis + from transactions). The format of an account looks like this:
 {
        "_index": "accounts",
        "_type": "_doc",
        "_id": "erd19j8u0kstdgwmgaqm23dh8lj0g5vxm6skg80yrp237rxwjneyz3qqqjmglw",
        "_score": null,
        "_source": {
          "nonce": 0,
          "balance": "2220555555555555555555560",
          "balanceNum": 2220555.5555555555
        }
}
  1. additional testing: check that the shown balance is the same balance returned by /address/ endpoint for a few samples.

@bogdan-rosianu bogdan-rosianu self-assigned this Sep 18, 2020
@bogdan-rosianu bogdan-rosianu marked this pull request as ready for review September 21, 2020 14:22
@bogdan-rosianu bogdan-rosianu changed the title [WIP] En 7527 index accounts En 7527 index accounts Sep 21, 2020
Refresh: "true",
}

return ei.elasticClient.DoRequest(req)
Copy link
Contributor

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.

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

enabledIndexesMap[index] = struct{}{}
}
if len(enabledIndexesMap) == 0 {
return nil, fmt.Errorf("empty elastic search enabled indexes map")
Copy link
Contributor

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

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

@@ -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 {
Copy link
Contributor

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

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 after Iulian's suggestion

core/computers.go Show resolved Hide resolved
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove TODO or code?

core/indexer/elasticClientCommon.go Show resolved Hide resolved
core/indexer/elasticClientCommon.go Outdated Show resolved Hide resolved
core/indexer/elasticProcessor.go Outdated Show resolved Hide resolved
core/indexer/elasticProcessor.go Outdated Show resolved Hide resolved
core/indexer/processTransactions.go Show resolved Hide resolved
core/indexer/processTransactions.go Outdated Show resolved Hide resolved
core/indexer/workItems/workItemAccounts.go Outdated Show resolved Hide resolved
cmd/node/factory/structs.go Outdated Show resolved Hide resolved
@@ -126,3 +126,47 @@ func TestMaxIntShouldReturnB(t *testing.T) {
b := 11
assert.Equal(t, b, core.MaxInt(a, b))
}

func TestMaxFloat64(t *testing.T) {
Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

add empty line

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

@@ -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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

(:+1:)

@@ -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
Copy link
Contributor

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

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

serializedData = append(serializedData, "\n"...)

buffLenWithCurrentAcc := buff.Len() + len(meta) + len(serializedData)
if buffLenWithCurrentAcc > txsBulkSizeThreshold && buff.Len() != 0 {
Copy link
Contributor

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

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

}
_, err = buff.Write(serializedData)
if err != nil {
log.Warn("elastic search: serialize bulk accounts history, write serialized tx", "error", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

`write serialized account hisotory1

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

}
_, err = buff.Write(serializedData)
if err != nil {
log.Warn("elastic search: serialize bulk accounts, write serialized tx", "error", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

write serialized account

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

// append a newline for each element
serializedData = append(serializedData, "\n"...)

buffLenWithCurrentAcc := buff.Len() + len(meta) + len(serializedData)
Copy link
Contributor

Choose a reason for hiding this comment

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

buffLenWithCurrentAccHistory

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

return ei.saveAccountsHistory(accountsMap)
}

func (ei *elasticProcessor) saveAccountsHistory(accountInfoMap map[string]*AccountInfo) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

accountsInfoMap

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

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.

👍

@bogdan-rosianu bogdan-rosianu merged commit f65353b into es-imp-v2 Oct 6, 2020
@bogdan-rosianu bogdan-rosianu deleted the EN-7527-index-accounts branch October 6, 2020 14:03
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.

[FEAT] Introduce REST API about list of all eGLD public addresses
4 participants