Merge pull request #2113 from nspcc-dev/optimize-witness-hashing

core: don't recalculate witness script hash
This commit is contained in:
Roman Khimov 2021-08-06 11:57:54 +03:00 committed by GitHub
commit 95e1f5f77b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

24
pkg/core/bench_test.go Normal file
View file

@ -0,0 +1,24 @@
package core
import (
"testing"
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/stretchr/testify/require"
)
func BenchmarkVerifyWitness(t *testing.B) {
bc := newTestChain(t)
acc, err := wallet.NewAccount()
require.NoError(t, err)
tx := bc.newTestTx(acc.Contract.ScriptHash(), []byte{byte(opcode.PUSH1)})
require.NoError(t, acc.SignTx(netmode.UnitTestNet, tx))
t.ResetTimer()
for n := 0; n < t.N; n++ {
_ = bc.VerifyWitness(tx.Signers[0].Account, tx, &tx.Scripts[0], 100000000)
}
}

View file

@ -1837,7 +1837,7 @@ func (bc *Blockchain) InitVerificationVM(v *vm.VM, getContract func(util.Uint160
if err != nil {
return fmt.Errorf("%w: %v", ErrInvalidVerification, err)
}
v.LoadScriptWithFlags(witness.VerificationScript, callflag.ReadOnly)
v.LoadScriptWithHash(witness.VerificationScript, hash, callflag.ReadOnly)
} else {
cs, err := getContract(hash)
if err != nil {