vm: fix caller's script hash returned from VM

Regular CALLs don't update it, only Contract.Call does. Fixes the following
mismatch on preview2 testnet:

file BlockStorage_100000/dump-block-49000.json: block 48644, changes number mismatch: 6 vs 4
This commit is contained in:
Roman Khimov 2020-06-23 21:39:26 +03:00
parent d5c9449a43
commit a77357227a
2 changed files with 6 additions and 1 deletions

View file

@ -41,6 +41,9 @@ type Context struct {
// Script hash of the prog. // Script hash of the prog.
scriptHash util.Uint160 scriptHash util.Uint160
// Caller's contract script hash.
callingScriptHash util.Uint160
// Call flags this context was created with. // Call flags this context was created with.
callFlag smartcontract.CallFlag callFlag smartcontract.CallFlag
} }

View file

@ -276,9 +276,11 @@ func (v *VM) LoadScriptWithFlags(b []byte, f smartcontract.CallFlag) {
// given script hash directly into the Context to avoid its recalculations. It's // given script hash directly into the Context to avoid its recalculations. It's
// up to user of this function to make sure the script and hash match each other. // up to user of this function to make sure the script and hash match each other.
func (v *VM) LoadScriptWithHash(b []byte, hash util.Uint160, f smartcontract.CallFlag) { func (v *VM) LoadScriptWithHash(b []byte, hash util.Uint160, f smartcontract.CallFlag) {
shash := v.GetCurrentScriptHash()
v.LoadScriptWithFlags(b, f) v.LoadScriptWithFlags(b, f)
ctx := v.Context() ctx := v.Context()
ctx.scriptHash = hash ctx.scriptHash = hash
ctx.callingScriptHash = shash
} }
// Context returns the current executed context. Nil if there is no context, // Context returns the current executed context. Nil if there is no context,
@ -1607,7 +1609,7 @@ func (v *VM) bytesToPublicKey(b []byte) *keys.PublicKey {
// GetCallingScriptHash implements ScriptHashGetter interface // GetCallingScriptHash implements ScriptHashGetter interface
func (v *VM) GetCallingScriptHash() util.Uint160 { func (v *VM) GetCallingScriptHash() util.Uint160 {
return v.getContextScriptHash(1) return v.Context().callingScriptHash
} }
// GetEntryScriptHash implements ScriptHashGetter interface // GetEntryScriptHash implements ScriptHashGetter interface