[#973] ir/subnet: Remove alphabet re-signature of Delete request

Subnet contract doesn't work with alphabet signatures.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-11-28 12:31:09 +03:00 committed by LeL
parent 41eaa1e246
commit 52fc5bde6e
2 changed files with 7 additions and 62 deletions

View file

@ -135,8 +135,6 @@ func (s *Server) listenSubnet() {
// subnet creation
listenEvent(subnetCreateEvName, subnetevents.ParseNotaryPut, s.onlyAlphabetEventHandler(s.catchSubnetCreation))
// subnet removal
listenEvent(subnetRemoveEvName, subnetevents.ParseNotaryDelete, s.onlyAlphabetEventHandler(s.catchSubnetRemoval))
}
func (s *Server) listenSubnetWithoutNotary() {
@ -303,25 +301,15 @@ func (s *Server) handleSubnetRemoval(e event.Event) {
return
}
notaryMainTx := delEv.NotaryMainTx()
// send new transaction
var prm morphsubnet.DeletePrm
isNotary := notaryMainTx != nil
if isNotary {
// re-sign notary request
err = s.morphClient.NotarySignAndInvokeTX(notaryMainTx)
} else {
// send new transaction
var prm morphsubnet.DeletePrm
prm.SetID(delEv.ID())
prm.SetTxHash(delEv.TxHash())
_, err = s.subnetHandler.morphClient.Delete(prm)
}
prm.SetID(delEv.ID())
prm.SetTxHash(delEv.TxHash())
_, err = s.subnetHandler.morphClient.Delete(prm)
if err != nil {
s.log.Error("approve subnet removal",
zap.Bool("notary", isNotary),
zap.String("error", err.Error()),
)

View file

@ -3,7 +3,6 @@ package subnetevents
import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/network/payload"
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -34,18 +33,6 @@ func (x Delete) TxHash() util.Uint256 {
return x.txHash
}
// NotaryMainTx returns main transaction of the request in the Notary service.
// Returns nil in non-notary environments.
func (x Delete) NotaryMainTx() *transaction.Transaction {
if x.notaryRequest != nil {
return x.notaryRequest.MainTransaction
}
return nil
}
const itemNumDelete = 1
// ParseDelete parses the notification about the removal of a subnet which has been thrown
// by the appropriate method of the Subnet contract.
//
@ -61,6 +48,8 @@ func ParseDelete(e *subscriptions.NotificationEvent) (event.Event, error) {
return nil, fmt.Errorf("parse stack array: %w", err)
}
const itemNumDelete = 1
if ln := len(items); ln != itemNumDelete {
return nil, event.WrongNumberOfParameters(itemNumDelete, ln)
}
@ -75,35 +64,3 @@ func ParseDelete(e *subscriptions.NotificationEvent) (event.Event, error) {
return ev, nil
}
// ParseNotaryDelete parses the notary notification about the removal of a subnet which has been
// thrown by the appropriate method of the Subnet contract.
//
// Resulting event is of Delete type.
func ParseNotaryDelete(e event.NotaryEvent) (event.Event, error) {
var ev Delete
ev.notaryRequest = e.Raw()
if ev.notaryRequest == nil {
panic(fmt.Sprintf("nil %T in notary environment", ev.notaryRequest))
}
var (
err error
prms = e.Params()
)
if ln := len(prms); ln != itemNumDelete {
return nil, event.WrongNumberOfParameters(itemNumDelete, ln)
}
ev.id, err = event.BytesFromOpcode(prms[0])
if err != nil {
return nil, fmt.Errorf("id param: %w", err)
}
ev.notaryRequest = e.Raw()
return ev, nil
}