forked from TrueCloudLab/neoneo-go
rpcsrv: adjust for paid attritbutes in calculatenetworkfee
calculatenetworkfee MUST calculate complete proper network fee, if we have some extensions enabled and some attributes should be paid for that they're a part of the equation too.
This commit is contained in:
parent
f3d83c90b1
commit
a2c4a7f611
4 changed files with 26 additions and 33 deletions
|
@ -355,26 +355,10 @@ the steps to create a signature request:
|
||||||
`Contract` field. That's needed to skip notary verification during regular
|
`Contract` field. That's needed to skip notary verification during regular
|
||||||
network fee calculation at the next step.
|
network fee calculation at the next step.
|
||||||
|
|
||||||
7. Calculate network fee for the transaction (that will be `NetworkFee`
|
6. Fill in the main transaction `Nonce` field.
|
||||||
transaction field). Network fee consists of several parts:
|
7. Construct a list of main transactions witnesses (that will be `Scripts`
|
||||||
- *Notary network fee.* That's the amount of GAS needed to be paid for
|
transaction field). Uses standard rules for witnesses of not yet signed
|
||||||
`NotaryAssisted` attribute usage and for notary contract witness
|
transaction (it can't be signed at this stage because network fee is missing):
|
||||||
verification (that is to be added by the notary node in the end of
|
|
||||||
signature collection process). Use
|
|
||||||
[func (*Client) CalculateNotaryFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.CalculateNotaryFee)
|
|
||||||
to calculate notary network fee. Use `NKeys` estimated at step 4 as an
|
|
||||||
argument.
|
|
||||||
- *Regular network fee.* That's the amount of GAS to be paid for other witnesses
|
|
||||||
verification. Use
|
|
||||||
[func (*Client) AddNetworkFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.AddNetworkFee)
|
|
||||||
to calculate regular network fee and add it to the transaction. Use
|
|
||||||
partially-filled main transaction from the previous steps as `tx` argument.
|
|
||||||
Use notary network fee calculated at the previous substep as `extraFee`
|
|
||||||
argument. Use the list of accounts constructed at step 5 as `accs`
|
|
||||||
argument.
|
|
||||||
8. Fill in the main transaction `Nonce` field.
|
|
||||||
9. Construct a list of main transactions witnesses (that will be `Scripts`
|
|
||||||
transaction field). Use the following rules:
|
|
||||||
- A contract-based witness should have `Invocation` script that pushes arguments
|
- A contract-based witness should have `Invocation` script that pushes arguments
|
||||||
on stack (it may be empty) and empty `Verification` script. If multiple notary
|
on stack (it may be empty) and empty `Verification` script. If multiple notary
|
||||||
requests provide different `Invocation` scripts, the first one will be used
|
requests provide different `Invocation` scripts, the first one will be used
|
||||||
|
@ -386,13 +370,17 @@ the steps to create a signature request:
|
||||||
- A standard signature witness must have regular `Verification` script filled
|
- A standard signature witness must have regular `Verification` script filled
|
||||||
even if the `Invocation` script is to be collected from other notary
|
even if the `Invocation` script is to be collected from other notary
|
||||||
requests.
|
requests.
|
||||||
`Invocation` script either should push signature bytes on stack **or** (in
|
`Invocation` script **should be empty**.
|
||||||
case the signature is to be collected) **should be empty**.
|
|
||||||
- A multisignature witness must have regular `Verification` script filled even
|
- A multisignature witness must have regular `Verification` script filled even
|
||||||
if `Invocation` script is to be collected from other notary requests.
|
if `Invocation` script is to be collected from other notary requests.
|
||||||
`Invocation` script either should push on stack signature bytes (one
|
`Invocation` script either **should be empty**.
|
||||||
signature at max per one request) **or** (in case there's no ability to
|
8. Calculate network fee for the transaction (that will be `NetworkFee`
|
||||||
provide proper signature) **should be empty**.
|
transaction field). Use [func (*Client) CalculateNetworkFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.99.2/pkg/rpcclient#Client.CalculateNetworkFee)
|
||||||
|
method with the main transaction given to it.
|
||||||
|
9. Fill in all signatures that can be provded by the client creating request,
|
||||||
|
that includes simple-signature accounts and multisignature accounts where
|
||||||
|
the client has one of the keys (in which case an invocation script is
|
||||||
|
created that pushes just one signature onto the stack).
|
||||||
10. Define lifetime for the fallback transaction. Let the `fallbackValidFor` be
|
10. Define lifetime for the fallback transaction. Let the `fallbackValidFor` be
|
||||||
the lifetime. Let `N` be the current chain's height and `VUB` be
|
the lifetime. Let `N` be the current chain's height and `VUB` be
|
||||||
`ValidUntilBlock` value estimated at step 3. Then, the notary node is trying to
|
`ValidUntilBlock` value estimated at step 3. Then, the notary node is trying to
|
||||||
|
@ -409,7 +397,7 @@ the steps to create a signature request:
|
||||||
special on fallback invocation, you can use simple `opcode.RET` script.
|
special on fallback invocation, you can use simple `opcode.RET` script.
|
||||||
12. Sign and submit P2P notary request. Use
|
12. Sign and submit P2P notary request. Use
|
||||||
[func (*Client) SignAndPushP2PNotaryRequest](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.SignAndPushP2PNotaryRequest) for it.
|
[func (*Client) SignAndPushP2PNotaryRequest](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.SignAndPushP2PNotaryRequest) for it.
|
||||||
- Use the signed main transaction from step 8 as `mainTx` argument.
|
- Use the signed main transaction from step 9 as `mainTx` argument.
|
||||||
- Use the fallback script from step 10 as `fallbackScript` argument.
|
- Use the fallback script from step 10 as `fallbackScript` argument.
|
||||||
- Use `-1` as `fallbackSysFee` argument to define system fee by test
|
- Use `-1` as `fallbackSysFee` argument to define system fee by test
|
||||||
invocation or provide any custom value.
|
invocation or provide any custom value.
|
||||||
|
|
|
@ -912,11 +912,6 @@ func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fa
|
||||||
Value: &transaction.Conflicts{Hash: mainTx.Hash()},
|
Value: &transaction.Conflicts{Hash: mainTx.Hash()},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
extraNetFee, err := c.CalculateNotaryFee(0)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
fallbackNetFee += extraNetFee
|
|
||||||
|
|
||||||
fallbackTx.Scripts = []transaction.Witness{
|
fallbackTx.Scripts = []transaction.Witness{
|
||||||
{
|
{
|
||||||
|
@ -961,6 +956,9 @@ func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fa
|
||||||
|
|
||||||
// CalculateNotaryFee calculates network fee for one dummy Notary witness and NotaryAssisted attribute with NKeys specified.
|
// CalculateNotaryFee calculates network fee for one dummy Notary witness and NotaryAssisted attribute with NKeys specified.
|
||||||
// The result should be added to the transaction's net fee for successful verification.
|
// The result should be added to the transaction's net fee for successful verification.
|
||||||
|
//
|
||||||
|
// Deprecated: NeoGo calculatenetworkfee method handles notary fees as well since 0.99.3, so
|
||||||
|
// this method is just no longer needed and will be removed in future versions.
|
||||||
func (c *Client) CalculateNotaryFee(nKeys uint8) (int64, error) {
|
func (c *Client) CalculateNotaryFee(nKeys uint8) (int64, error) {
|
||||||
baseExecFee, err := c.GetExecFeeFactor()
|
baseExecFee, err := c.GetExecFeeFactor()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -998,7 +998,7 @@ func TestCalculateNotaryFee(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("client not initialized", func(t *testing.T) {
|
t.Run("client not initialized", func(t *testing.T) {
|
||||||
_, err := c.CalculateNotaryFee(0)
|
_, err := c.CalculateNotaryFee(0) //nolint:staticcheck // SA1019: c.CalculateNotaryFee is deprecated
|
||||||
require.NoError(t, err) // Do not require client initialisation for this.
|
require.NoError(t, err) // Do not require client initialisation for this.
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -779,6 +779,13 @@ func (s *Server) calculateNetworkFee(reqParams params.Params) (interface{}, *neo
|
||||||
netFee += fee
|
netFee += fee
|
||||||
size += sizeDelta
|
size += sizeDelta
|
||||||
}
|
}
|
||||||
|
if s.chain.P2PSigExtensionsEnabled() {
|
||||||
|
attrs := tx.GetAttributes(transaction.NotaryAssistedT)
|
||||||
|
if len(attrs) != 0 {
|
||||||
|
na := attrs[0].Value.(*transaction.NotaryAssisted)
|
||||||
|
netFee += (int64(na.NKeys) + 1) * s.chain.GetNotaryServiceFeePerKey()
|
||||||
|
}
|
||||||
|
}
|
||||||
fee := s.chain.FeePerByte()
|
fee := s.chain.FeePerByte()
|
||||||
netFee += int64(size) * fee
|
netFee += int64(size) * fee
|
||||||
return result.NetworkFee{Value: netFee}, nil
|
return result.NetworkFee{Value: netFee}, nil
|
||||||
|
|
Loading…
Reference in a new issue