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

Feat/pubkeyconverter_refactor #4716

Merged
merged 59 commits into from
Mar 20, 2023
Merged

Conversation

schimih
Copy link
Contributor

@schimih schimih commented Nov 18, 2022

Reasoning behind the pull request

The original implementation of the pidPubkeyConverter.Encode method did not propagate the error to its caller. Instead, it logged the error and returned an empty string. This behavior can be problematic as it might hide potential issues and security threats. Furthermore, the logger's presence in the PubKeyConverter constructor became unnecessary, therefore the hrp was given as input, especially considering our vision for sovereign shards where each shard could have its unique human-readable part (hrp).

Proposed changes

  • refactor the pidPubkeyConverter.Encode method by returning both a string and an error.
  • remove the log statement, which was previously used to log the error;
  • return the error so that the caller should decide what to do with the error (handle or log);
  • provide hrp as input parameter for the PubKeyConverter constructor;
  • treat the error everywhere the NewPubKeyConverter constructor is used;
  • Legacy refactor:

Testing procedure

  • standard system test
  • run a blockchain with half of the nodes using the previous node version and the other half with this branch

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

@schimih schimih self-assigned this Nov 18, 2022
@schimih schimih marked this pull request as draft November 18, 2022 16:38
@schimih schimih changed the base branch from master to rc/v1.5.0 December 9, 2022 08:58
@codecov-commenter
Copy link

codecov-commenter commented Dec 9, 2022

Codecov Report

❗ No coverage uploaded for pull request base (rc/v1.6.0@89b54e7). Click here to learn what that means.
Patch has no changes to coverable lines.

❗ Current head 2182749 differs from pull request most recent head 58c40b0. Consider uploading reports for the commit 58c40b0 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@             Coverage Diff              @@
##             rc/v1.6.0    #4716   +/-   ##
============================================
  Coverage             ?   70.89%           
============================================
  Files                ?      675           
  Lines                ?    87614           
  Branches             ?        0           
============================================
  Hits                 ?    62118           
  Misses               ?    20827           
  Partials             ?     4669           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@andreibancioiu andreibancioiu changed the base branch from rc/v1.6.0 to master March 9, 2023 13:38
@andreibancioiu andreibancioiu changed the base branch from master to rc/v1.4.0 March 9, 2023 13:39
@andreibancioiu andreibancioiu changed the base branch from rc/v1.4.0 to rc/v1.5.0 March 9, 2023 13:39
@andreibancioiu andreibancioiu changed the base branch from rc/v1.5.0 to rc/v1.6.0 March 9, 2023 13:39
iulianpascalau and others added 3 commits March 10, 2023 13:42
…3.10

# Conflicts:
#	cmd/keygenerator/converter/errors.go
#	cmd/keygenerator/converter/pidPubkeyConverter.go
#	cmd/keygenerator/converter/pidPubkeyConverter_test.go
#	cmd/keygenerator/main.go
#	common/enablers/enableEpochsHandler.go
#	common/factory/pubkeyConverterFactory.go
#	config/tomlConfig_test.go
#	examples/construction_test.go
#	factory/addressDecoder_test.go
#	factory/crypto/cryptoComponents.go
#	genesis/checking/nodesSetupChecker.go
#	genesis/checking/nodesSetupChecker_test.go
#	genesis/parsing/accountsParser.go
#	genesis/parsing/accountsParser_test.go
#	go.mod
#	go.sum
#	integrationTests/consensus/consensus_test.go
#	integrationTests/frontend/wallet/dataField_test.go
#	integrationTests/multiShard/txScenarios/moveBalance_test.go
#	integrationTests/testConsensusNode.go
#	integrationTests/vm/txsFee/scCalls_test.go
#	node/external/nodeApiResolver.go
#	node/external/transactionAPI/apiTransactionProcessor.go
#	node/external/transactionAPI/apiTransactionProcessor_test.go
#	node/external/transactionAPI/apiTransactionResults.go
#	node/external/transactionAPI/gasUsedAndFeeProcessor_test.go
#	node/external/transactionAPI/unmarshaller.go
#	node/external/transactionAPI/unmarshaller_test.go
#	node/trieIterators/delegatedListProcessor_test.go
#	node/trieIterators/directStakedListProcessor.go
#	node/trieIterators/directStakedListProcessor_test.go
#	node/trieIterators/factory/delegatedListHandlerFactory_test.go
#	node/trieIterators/factory/directStakedListHandlerFactory_test.go
#	node/trieIterators/factory/stakeValuesHandlerFactory_test.go
#	node/trieIterators/stakeValuesProcessor_test.go
#	outport/factory/outportFactory_test.go
#	outport/process/alteredaccounts/alteredAccountsProvider.go
#	outport/process/transactionsfee/transactionsFeeProcessor.go
#	outport/process/transactionsfee/transactionsFeeProcessor_test.go
#	process/block/postprocess/intermediateResults_test.go
#	process/block/preprocess/transactions_test.go
#	process/dataValidators/txValidator.go
#	process/factory/metachain/intermediateProcessorsContainerFactory_test.go
#	process/peer/validatorsProvider_test.go
#	process/rewardTransaction/interceptedRewardTransaction_test.go
#	process/smartContract/process.go
#	process/txsimulator/txSimulator.go
#	process/unsigned/interceptedUnsignedTransaction_test.go
#	testscommon/addresses.go
#	testscommon/integrationtests/stringers.go
#	testscommon/integrationtests/stringers_test.go
#	update/genesis/export_test.go
#	vm/systemSmartContracts/esdt_test.go
…conv-2023.03.10

Merge rc v1.6.0 feat pubkey conv 2023.03.10
@iulianpascalau iulianpascalau self-requested a review March 13, 2023 07:45
cmd/keygenerator/converter/pidPubkeyConverter.go Outdated Show resolved Hide resolved
config/tomlConfig_test.go Outdated Show resolved Hide resolved
go.mod Outdated
@@ -13,13 +13,13 @@ require (
github.com/google/gops v0.3.18
github.com/gorilla/websocket v1.5.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.1.35
github.com/multiversx/mx-chain-core-go v1.1.36-0.20230308081722-5262fb09cb9a
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 before merging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

immediately after review and system test 👍

integrationTests/consensus/consensus_test.go Outdated Show resolved Hide resolved
node/external/transactionAPI/apiTransactionProcessor.go Outdated Show resolved Hide resolved
outport/process/alteredaccounts/alteredAccountsProvider.go Outdated Show resolved Hide resolved
state/accountsDB.go Outdated Show resolved Hide resolved
state/accountsDB.go Outdated Show resolved Hide resolved
@@ -41,6 +41,7 @@ const minedWalletPrefixKeys = "mined-wallet"
const nopattern = "nopattern"
const desiredpattern = "[0-f]+"
const noshard = -1
const pubkeyHrp = "erd"
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the future, this can be received as a command line parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

noted

Copy link
Contributor

Choose a reason for hiding this comment

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

...or a config defined in config.toml file

@@ -288,9 +288,9 @@ func (u *userAccountsSyncer) printDataTrieStatistics() {
})

for _, trieStat := range u.largeTries {
address := u.pubkeyCoverter.Encode(trieStat.address)
trieStatAddress := u.pubkeyCoverter.SilentEncode(trieStat.address, log)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Previous name is better (address).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@@ -1800,11 +1800,15 @@ func (sc *scProcessor) printScDeployed(vmOutput *vmcommon.VMOutput, tx data.Tran
continue
}

scGenerated = append(scGenerated, sc.pubkeyConv.Encode(addr))
scAddress := sc.pubkeyConv.SilentEncode(addr, log)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty line is not necessary 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.

deleted

log.Debug("SmartContract deployed",
"owner", sc.pubkeyConv.Encode(tx.GetSndAddr()),
"owner", encodedSndAddr,
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the log on line 432, the encoding is "in-lined". Perhaps do the same here, we well?

Or, instead, perhaps rename variable to ownerAddress?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

@@ -875,7 +876,7 @@ func TestNode_GetAllESDTTokensShouldReturnEsdtAndFormattedNft(t *testing.T) {
tokens, _, err := n.GetAllESDTTokens(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background())
assert.Nil(t, err)
assert.Equal(t, 2, len(tokens))
assert.Equal(t, esdtData, tokens[esdtToken])
assert.Equal(t, esdtData, tokens["TKKR-7q8w9e-"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure what happened here.

Copy link
Contributor

Choose a reason for hiding this comment

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

reverted in the next PR :D

converter, _ := pubkeyConverter.NewBech32PubkeyConverter(32, "erd")

receiverAddress, _ := converter.Encode(tx.RcvAddr)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty lines not strictly necessary here.

Events: events,
}
}

func (converter *logsConverter) encodeAddress(pubkey []byte) string {
return converter.pubKeyConverter.Encode(pubkey)
return converter.pubKeyConverter.SilentEncode(pubkey, log)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

leaderPK := core.GetTrimmedPk(vs.pubkeyConv.Encode(consensusGroup[0].PubKey()))

encodedLeaderPk := vs.pubkeyConv.SilentEncode(consensusGroup[0].PubKey(), log)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty line is not necessary, I think.

return nil, nil
}

metaDataCreatorAddr, err := aap.addressConverter.Encode(metaData.Creator)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure this should not be a silent encode? CC: @bogdan-rosianu.

@@ -96,8 +96,13 @@ func (dlp *delegatedListProcessor) getDelegatorsInfo(delegationSC []byte, delega

delegatorInfo, ok := delegatorsMap[string(delegatorAddress)]
if !ok {
encodedDelegatorAddress, err := dlp.publicKeyConverter.Encode(delegatorAddress)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we sure we don't need silent encode in this file, instead?

@schimih schimih marked this pull request as ready for review March 20, 2023 11:38
Copy link
Contributor

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

System test passed

Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

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

go.mod looks ok 👌

@schimih schimih merged commit e272723 into rc/v1.6.0 Mar 20, 2023
@schimih schimih deleted the feat/pubkeyconverter-refactor branch March 20, 2023 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants