Skip to content

Commit

Permalink
rpcsrv: adjust for paid attritbutes in calculatenetworkfee
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
roman-khimov committed Aug 22, 2022
1 parent f3d83c9 commit d356223
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
24 changes: 5 additions & 19 deletions docs/notary.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,25 +355,8 @@ the steps to create a signature request:
`Contract` field. That's needed to skip notary verification during regular
network fee calculation at the next step.

7. Calculate network fee for the transaction (that will be `NetworkFee`
transaction field). Network fee consists of several parts:
- *Notary network fee.* That's the amount of GAS needed to be paid for
`NotaryAssisted` attribute usage and for notary contract witness
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`
6. Fill in the main transaction `Nonce` field.
7. 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
on stack (it may be empty) and empty `Verification` script. If multiple notary
Expand All @@ -393,6 +376,9 @@ the steps to create a signature request:
`Invocation` script either should push on stack signature bytes (one
signature at max per one request) **or** (in case there's no ability to
provide proper signature) **should be empty**.
8. Calculate network fee for the transaction (that will be `NetworkFee`
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.
10. Define lifetime for the fallback transaction. Let the `fallbackValidFor` 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
Expand Down
8 changes: 3 additions & 5 deletions pkg/rpcclient/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,6 @@ func (c *Client) SignAndPushP2PNotaryRequest(mainTx *transaction.Transaction, fa
Value: &transaction.Conflicts{Hash: mainTx.Hash()},
},
}
extraNetFee, err := c.CalculateNotaryFee(0)
if err != nil {
return nil, err
}
fallbackNetFee += extraNetFee

fallbackTx.Scripts = []transaction.Witness{
{
Expand Down Expand Up @@ -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.
// 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) {
baseExecFee, err := c.GetExecFeeFactor()
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions pkg/services/rpcsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,13 @@ func (s *Server) calculateNetworkFee(reqParams params.Params) (interface{}, *neo
netFee += fee
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()
netFee += int64(size) * fee
return result.NetworkFee{Value: netFee}, nil
Expand Down

0 comments on commit d356223

Please sign in to comment.