forked from TrueCloudLab/frostfs-node
[#1966] neofs-adm: Set VerifyBlocks: true
and fix NetworkFee calculation
Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
parent
41f93dcc1d
commit
2dcf8d51be
2 changed files with 20 additions and 31 deletions
|
@ -101,6 +101,7 @@ func generateTestData(t *testing.T, dir string, size int) {
|
||||||
cfg.ProtocolConfiguration.StandbyCommittee = pubs // sorted by glagolic letters
|
cfg.ProtocolConfiguration.StandbyCommittee = pubs // sorted by glagolic letters
|
||||||
cfg.ProtocolConfiguration.P2PSigExtensions = true
|
cfg.ProtocolConfiguration.P2PSigExtensions = true
|
||||||
cfg.ProtocolConfiguration.VerifyTransactions = true
|
cfg.ProtocolConfiguration.VerifyTransactions = true
|
||||||
|
cfg.ProtocolConfiguration.VerifyBlocks = true
|
||||||
data, err := yaml.Marshal(cfg)
|
data, err := yaml.Marshal(cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
@ -29,10 +30,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/unwrap"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
@ -248,41 +247,30 @@ func (l *localClient) CalculateNetworkFee(tx *transaction.Transaction) (int64, e
|
||||||
}
|
}
|
||||||
|
|
||||||
size := len(hashablePart) + io.GetVarSize(len(tx.Signers))
|
size := len(hashablePart) + io.GetVarSize(len(tx.Signers))
|
||||||
|
ef := l.bc.GetBaseExecFee()
|
||||||
|
|
||||||
var netFee int64
|
var netFee int64
|
||||||
for i, signer := range tx.Signers {
|
for i, signer := range tx.Signers {
|
||||||
w := tx.Scripts[i]
|
var verificationScript []byte
|
||||||
if len(w.InvocationScript) == 0 { // No invocation provided, try to infer one.
|
for _, w := range tx.Scripts {
|
||||||
var paramz []manifest.Parameter
|
if w.VerificationScript != nil && hash.Hash160(w.VerificationScript).Equals(signer.Account) {
|
||||||
|
verificationScript = w.VerificationScript
|
||||||
if vm.IsSignatureContract(w.VerificationScript) {
|
break
|
||||||
paramz = []manifest.Parameter{{Type: smartcontract.SignatureType}}
|
|
||||||
} else if nSigs, _, ok := vm.ParseMultiSigContract(w.VerificationScript); ok {
|
|
||||||
paramz = make([]manifest.Parameter, nSigs)
|
|
||||||
for j := 0; j < nSigs; j++ {
|
|
||||||
paramz[j] = manifest.Parameter{Type: smartcontract.SignatureType}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if verificationScript == nil {
|
||||||
inv := io.NewBufBinWriter()
|
gasConsumed, err := l.bc.VerifyWitness(signer.Account, tx, &tx.Scripts[i], l.maxGasInvoke)
|
||||||
for _, p := range paramz {
|
if err != nil {
|
||||||
p.Type.EncodeBinary(inv.BinWriter)
|
return 0, fmt.Errorf("invalid signature: %w", err)
|
||||||
}
|
}
|
||||||
if inv.Err != nil {
|
|
||||||
return 0, fmt.Errorf("failed to create dummy invocation script (signer %d): %w", i, inv.Err)
|
|
||||||
}
|
|
||||||
w.InvocationScript = inv.Bytes()
|
|
||||||
}
|
|
||||||
gasConsumed, _ := l.bc.VerifyWitness(signer.Account, tx, &w, l.maxGasInvoke)
|
|
||||||
netFee += gasConsumed
|
netFee += gasConsumed
|
||||||
size += io.GetVarSize(w.VerificationScript) + io.GetVarSize(w.InvocationScript)
|
size += io.GetVarSize([]byte{}) + io.GetVarSize(tx.Scripts[i].InvocationScript)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// notary service is expected to be enabled
|
fee, sizeDelta := fee.Calculate(ef, verificationScript)
|
||||||
attrs := tx.GetAttributes(transaction.NotaryAssistedT)
|
netFee += fee
|
||||||
if len(attrs) != 0 {
|
size += sizeDelta
|
||||||
na := attrs[0].Value.(*transaction.NotaryAssisted)
|
|
||||||
netFee += (int64(na.NKeys) + 1) * l.bc.GetNotaryServiceFeePerKey()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fee := l.bc.FeePerByte()
|
fee := l.bc.FeePerByte()
|
||||||
|
|
Loading…
Reference in a new issue