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

Optimize LoadAccount #2693

Merged
merged 26 commits into from Jan 14, 2021
Merged

Optimize LoadAccount #2693

merged 26 commits into from Jan 14, 2021

Conversation

BeniaminDrasovean
Copy link
Contributor

@BeniaminDrasovean BeniaminDrasovean commented Jan 13, 2021

Separated getCode from loadAccount - code is only got from trie when it is needed.
Added fixes on esdt callbacks and return of values
Integrated new arwen

@BeniaminDrasovean BeniaminDrasovean changed the title add getCode to accountsDb Optimize LoadAccount Jan 13, 2021
@sasurobert sasurobert self-requested a review January 13, 2021 16:01
}

if len(baseAcc.GetCode()) != 0 {
return baseAcc.GetCode()
Copy link
Contributor

Choose a reason for hiding this comment

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

assuming the base account has a code inside and returning it in that case might lead to this scenario:
I have an account, I've put by mistake something in its code field and then I call AccountsDB.GetCode assuming I will get the "real" contract code. Instead I get the existing byte slice from the user 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.

Should I retrieve the code from the trie each time?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is better without this sort of cache (we can do it in other parts of the code). In this way this function express the intent in a more straight forward way.

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 get it - as we have extra gas cost for it now.

data/state/accountsDB.go Outdated Show resolved Hide resolved
data/state/accountsDB.go Outdated Show resolved Hide resolved
data/state/baseAccount.go Show resolved Hide resolved
@@ -22,6 +23,7 @@ func (ba *baseAccount) GetCode() []byte {

// SetCode sets the actual code that needs to be run in the VM
func (ba *baseAccount) SetCode(code []byte) {
ba.hasNewCode = true
Copy link
Contributor

Choose a reason for hiding this comment

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

ba.hasNewCode = !bytes.Equal(code, ba.code) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the code is nil, and the old code was not loaded from the trie (ba.code == nil), this will set false, and the code would not be removed.

epochStart/bootstrap/disabled/disabledAccountsAdapter.go Outdated Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
node/txsimulator/wrappedAccountsDB.go Outdated Show resolved Hide resolved
iulianpascalau
iulianpascalau previously approved these changes Jan 13, 2021
Copy link
Contributor

@sasurobert sasurobert left a comment

Choose a reason for hiding this comment

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

I think you should delete GetCode from the UserAccountsHandler interface

sasurobert
sasurobert previously approved these changes Jan 13, 2021
@sasurobert sasurobert marked this pull request as ready for review January 14, 2021 11:31
@@ -246,8 +246,8 @@ func TestMultipleTimesERC20BigIntInBatches(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}
gasSchedule, _ := core.LoadGasScheduleConfig("../../../../cmd/node/config/gasSchedules/gasScheduleV2.toml")
deployAndExecuteERC20WithBigInt(t, 3, 1000, gasSchedule, "../testdata/erc20-c-03/wrc20_arwen.wasm", "transferToken", false)
//gasSchedule, _ := core.LoadGasScheduleConfig("../../../../cmd/node/config/gasSchedules/gasScheduleV2.toml")
Copy link
Contributor

Choose a reason for hiding this comment

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

remove commented code

Copy link
Contributor

Choose a reason for hiding this comment

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

done

node/node.go Outdated
@@ -1124,7 +1124,8 @@ func (n *Node) GetAccount(address string) (state.UserAccountHandler, error) {
accWrp, err := n.accounts.GetExistingAccount(addr)
if err != nil {
if err == state.ErrAccNotFound {
return state.NewUserAccount(addr)
newAcc, err := state.NewUserAccount(addr)
Copy link
Contributor

Choose a reason for hiding this comment

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

return directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

done

@@ -25,6 +25,10 @@ func (adb *AccountsDB) GetObsoleteHashes() map[string][][]byte {
return adb.obsoleteDataTrieHashes
}

func GetCode(account baseAccountHandler) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

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

GetCodeHash?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is an export function only. some stuff is mocked for tests only.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it is, but it returns a code hash and not the code, the name is misleading also for tests :)

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.

@LucianMincu LucianMincu merged commit d726d38 into development Jan 14, 2021
@LucianMincu LucianMincu deleted the optimize-LoadAccount branch January 14, 2021 16:24
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

5 participants