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
Optimize LoadAccount #2693
Conversation
data/state/accountsDB.go
Outdated
} | ||
|
||
if len(baseAcc.GetCode()) != 0 { | ||
return baseAcc.GetCode() |
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.
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.
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.
Should I retrieve the code from the trie each time?
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 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.
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 get it - as we have extra gas cost for it now.
@@ -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 |
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.
ba.hasNewCode = !bytes.Equal(code, ba.code) ?
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.
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.
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 think you should delete GetCode from the UserAccountsHandler interface
# Conflicts: # data/state/export_test.go
…ize-LoadAccount # Conflicts: # go.mod # go.sum
# Conflicts: # go.mod # go.sum
…vert Fix esdt cross sc fail revert
@@ -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") |
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 commented code
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
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) |
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.
return directly?
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
@@ -25,6 +25,10 @@ func (adb *AccountsDB) GetObsoleteHashes() map[string][][]byte { | |||
return adb.obsoleteDataTrieHashes | |||
} | |||
|
|||
func GetCode(account baseAccountHandler) []byte { |
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.
GetCodeHash?
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 is an export function only. some stuff is mocked for tests only.
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 is, but it returns a code hash and not the code, the name is misleading also for tests :)
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.
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