Merge pull request #3690 from nspcc-dev/drop-compat-0.107.0

Drop deprecated code for 0.107.0
This commit is contained in:
Anna Shaleva 2024-11-20 11:03:46 +03:00 committed by GitHub
commit 57eec71101
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 9 additions and 154 deletions

View file

@ -25,51 +25,6 @@ APIs/commands/configurations will be removed and here is a list of scheduled
breaking changes. Consider changing your code/scripts/configurations if you're breaking changes. Consider changing your code/scripts/configurations if you're
using anything mentioned here. using anything mentioned here.
## GetPeers RPC server response type changes and RPC client support
GetPeers RPC command returns a list of Peers where the port type has changed from
string to uint16 to match C#. The RPC client currently supports unmarshalling both
formats.
Removal of Peer unmarshalling with string based ports is scheduled for Jun-Jul 2024
(~0.107.0 release).
## `NEOBalance` from stack item
We check struct items count before convert LastGasPerVote to let RPC client be compatible with
old versions.
Removal of this compatiblility code is scheduled for Jun-Jul 2024.
## `serv_node_version` Prometheus gauge metric
This metric is replaced by the new `neogo_version` and `server_id` Prometheus gauge
metrics with proper version formatting. `neogo_version` contains NeoGo version
hidden under `version` label and `server_id` contains network server ID hidden
under `server_id` label.
Removal of `serv_node_version` is scheduled for Jun-Jul 2024 (~0.107.0 release).
## RPC error codes returned by old versions and C#-nodes
NeoGo retains certain deprecated error codes: `neorpc.ErrCompatGeneric`,
`neorpc.ErrCompatNoOpenedWallet`. They returned by nodes not compliant with the
neo-project/proposals#156 (NeoGo pre-0.102.0 and all known C# versions).
Removal of the deprecated RPC error codes is planned for Jun-Jul 2024 (~0.107.0
release).
## Block based web-socket waiter transaction awaiting
Web-socket RPC based `waiter.EventWaiter` uses `header_of_added_block` notifications
subscription to manage transaction awaiting. To support old NeoGo RPC servers
(older than 0.105.0) that do not have block headers subscription ability,
event-based waiter fallbacks to the old way of block monitoring with
`block_added` notifications subscription.
Removal of stale RPC server compatibility code from `waiter.EventWaiter` is
scheduled for Jun-Jul 2024 (~0.107.0 release).
## Dump*Slot() methods of `vm.Context` ## Dump*Slot() methods of `vm.Context`
The following new methods have been exposed to give access to VM context slot contents The following new methods have been exposed to give access to VM context slot contents

View file

@ -133,7 +133,7 @@ func (s *NEOBalance) ToStackItem() (stackitem.Item, error) {
// FromStackItem converts stackitem.Item to NEOBalance. // FromStackItem converts stackitem.Item to NEOBalance.
func (s *NEOBalance) FromStackItem(item stackitem.Item) error { func (s *NEOBalance) FromStackItem(item stackitem.Item) error {
structItem, ok := item.Value().([]stackitem.Item) structItem, ok := item.Value().([]stackitem.Item)
if !ok || len(structItem) < 3 { if !ok || len(structItem) < 4 {
return errors.New("invalid stackitem length") return errors.New("invalid stackitem length")
} }
balance, err := structItem[0].TryInteger() balance, err := structItem[0].TryInteger()
@ -159,12 +159,10 @@ func (s *NEOBalance) FromStackItem(item stackitem.Item) error {
} }
s.VoteTo = pub s.VoteTo = pub
} }
if len(structItem) >= 4 { lastGasPerVote, err := structItem[3].TryInteger()
lastGasPerVote, err := structItem[3].TryInteger() if err != nil {
if err != nil { return fmt.Errorf("invalid last vote reward per neo stackitem: %w", err)
return fmt.Errorf("invalid last vote reward per neo stackitem: %w", err)
}
s.LastGasPerVote = *lastGasPerVote
} }
s.LastGasPerVote = *lastGasPerVote
return nil return nil
} }

View file

@ -138,21 +138,6 @@ const (
ErrExecutionFailedCode = -608 ErrExecutionFailedCode = -608
) )
var (
// ErrCompatGeneric is an error returned by nodes not compliant with the neo-project/proposals#156
// (NeoGo pre-0.102.0 and all known C# versions).
// It can be returned for any call and doesn't have any specific meaning.
//
// Deprecated: to be removed after all nodes adopt new error standard.
ErrCompatGeneric = NewErrorWithCode(-100, "RPC error")
// ErrCompatNoOpenedWallet is an error code returned by nodes not compliant with the neo-project/proposals#156
// (all known C# versions, NeoGo never used this code). It can be returned for wallet-related operations.
//
// Deprecated: to be removed after all nodes adopt new error standard.
ErrCompatNoOpenedWallet = NewErrorWithCode(-400, "No opened wallet")
)
var ( var (
// ErrInvalidParams represents a generic "Invalid params" error. // ErrInvalidParams represents a generic "Invalid params" error.
ErrInvalidParams = NewInvalidParamsError("Invalid params") ErrInvalidParams = NewInvalidParamsError("Invalid params")

View file

@ -1,7 +1,6 @@
package result package result
import ( import (
"encoding/json"
"net" "net"
"strconv" "strconv"
@ -86,37 +85,6 @@ func (p *Peers) addConnectedPeers(connectedPeers []network.PeerInfo) {
} }
} }
func (p *Peer) UnmarshalJSON(data []byte) error {
type NewPeer Peer
var np NewPeer
err := json.Unmarshal(data, &np)
if err == nil {
*p = Peer(np)
return nil
}
type OldPeer struct {
Address string `json:"address"`
Port string `json:"port"`
}
var op OldPeer
err = json.Unmarshal(data, &op)
if err == nil {
port, err := strconv.ParseUint(op.Port, 10, 16)
if err != nil {
return err
}
*p = Peer{
Address: op.Address,
Port: uint16(port),
}
}
return err
}
// parseHostPort parses host and port from the given address. // parseHostPort parses host and port from the given address.
// An improperly formatted port string will return zero port. // An improperly formatted port string will return zero port.
func parseHostPort(addr string) (string, uint16, error) { func parseHostPort(addr string) (string, uint16, error) {

View file

@ -37,11 +37,8 @@ func TestGetPeers(t *testing.T) {
require.Equal(t, uint16(20333), gp.Bad[0].Port) require.Equal(t, uint16(20333), gp.Bad[0].Port)
gps := GetPeers{} gps := GetPeers{}
oldPeerFormat := `{"unconnected": [{"address": "20.109.188.128","port": "10333"},{"address": "27.188.182.47","port": "10333"}],"connected": [{"address": "54.227.43.72","port": "10333"},{"address": "157.90.177.38","port": "10333"}],"bad": [{"address": "5.226.142.226","port": "10333"}]}`
err := json.Unmarshal([]byte(oldPeerFormat), &gps)
require.NoError(t, err)
newPeerFormat := `{"unconnected": [{"address": "20.109.188.128","port": 10333},{"address": "27.188.182.47","port": 10333}],"connected": [{"address": "54.227.43.72","port": 10333},{"address": "157.90.177.38","port": 10333}],"bad": [{"address": "5.226.142.226","port": 10333},{"address": "54.208.117.178","port": 10333}]}` newPeerFormat := `{"unconnected": [{"address": "20.109.188.128","port": 10333},{"address": "27.188.182.47","port": 10333}],"connected": [{"address": "54.227.43.72","port": 10333},{"address": "157.90.177.38","port": 10333}],"bad": [{"address": "5.226.142.226","port": 10333},{"address": "54.208.117.178","port": 10333}]}`
err = json.Unmarshal([]byte(newPeerFormat), &gps) err := json.Unmarshal([]byte(newPeerFormat), &gps)
require.NoError(t, err) require.NoError(t, err)
badIntFormat := `{"unconnected": [{"address": "20.109.188.128","port": 65536}],"connected": [],"bad": []}` badIntFormat := `{"unconnected": [{"address": "20.109.188.128","port": 65536}],"connected": [],"bad": []}`
err = json.Unmarshal([]byte(badIntFormat), &gps) err = json.Unmarshal([]byte(badIntFormat), &gps)

View file

@ -25,16 +25,6 @@ var (
}, },
) )
// Deprecated: please, use neogoVersion and serverID instead.
servAndNodeVersion = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Help: "Server and Node versions",
Name: "serv_node_version",
Namespace: "neogo",
},
[]string{"description", "value"},
)
neogoVersion = prometheus.NewGaugeVec( neogoVersion = prometheus.NewGaugeVec(
prometheus.GaugeOpts{ prometheus.GaugeOpts{
Help: "NeoGo version", Help: "NeoGo version",
@ -82,7 +72,6 @@ func init() {
prometheus.MustRegister( prometheus.MustRegister(
estimatedNetworkSize, estimatedNetworkSize,
peersConnected, peersConnected,
servAndNodeVersion,
neogoVersion, neogoVersion,
serverID, serverID,
poolCount, poolCount,
@ -122,12 +111,6 @@ func updatePeersConnectedMetric(pConnected int) {
peersConnected.Set(float64(pConnected)) peersConnected.Set(float64(pConnected))
} }
// Deprecated: please, use setNeoGoVersion and setSeverID instead.
func setServerAndNodeVersions(nodeVer string, serverID string) {
servAndNodeVersion.WithLabelValues("Node version: ", nodeVer).Add(0)
servAndNodeVersion.WithLabelValues("Server id: ", serverID).Add(0)
}
func setNeoGoVersion(nodeVer string) { func setNeoGoVersion(nodeVer string) {
neogoVersion.WithLabelValues(nodeVer).Add(1) neogoVersion.WithLabelValues(nodeVer).Add(1)
} }

View file

@ -318,7 +318,6 @@ func (s *Server) Start() {
for _, tr := range s.transports { for _, tr := range s.transports {
go tr.Accept() go tr.Accept()
} }
setServerAndNodeVersions(s.UserAgent, strconv.FormatUint(uint64(s.id), 10))
setNeoGoVersion(config.Version) setNeoGoVersion(config.Version)
setSeverID(strconv.FormatUint(uint64(s.id), 10)) setSeverID(strconv.FormatUint(uint64(s.id), 10))
go s.run() go s.run()

View file

@ -105,6 +105,7 @@ func TestGetAccountState(t *testing.T) {
stackitem.Make(100500), stackitem.Make(100500),
stackitem.Make(42), stackitem.Make(42),
stackitem.Null{}, stackitem.Null{},
stackitem.Make(0),
}), }),
}, },
} }

View file

@ -74,7 +74,6 @@ type (
RPCPollingBased RPCPollingBased
ReceiveHeadersOfAddedBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Header) (string, error) ReceiveHeadersOfAddedBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Header) (string, error)
ReceiveBlocks(flt *neorpc.BlockFilter, rcvr chan<- *block.Block) (string, error)
ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr chan<- *state.AppExecResult) (string, error) ReceiveExecutions(flt *neorpc.ExecutionFilter, rcvr chan<- *state.AppExecResult) (string, error)
Unsubscribe(id string) error Unsubscribe(id string) error
} }
@ -282,7 +281,6 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
wsWaitErr error wsWaitErr error
waitersActive int waitersActive int
hRcvr = make(chan *block.Header, 2) hRcvr = make(chan *block.Header, 2)
bRcvr = make(chan *block.Block, 2)
aerRcvr = make(chan *state.AppExecResult, len(hashes)) aerRcvr = make(chan *state.AppExecResult, len(hashes))
unsubErrs = make(chan error) unsubErrs = make(chan error)
exit = make(chan struct{}) exit = make(chan struct{})
@ -292,13 +290,7 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
since := vub since := vub
blocksID, err := w.ws.ReceiveHeadersOfAddedBlocks(&neorpc.BlockFilter{Since: &since}, hRcvr) blocksID, err := w.ws.ReceiveHeadersOfAddedBlocks(&neorpc.BlockFilter{Since: &since}, hRcvr)
if err != nil { if err != nil {
// Falling back to block-based subscription. wsWaitErr = fmt.Errorf("failed to subscribe for new headers: %w", err)
if errors.Is(err, neorpc.ErrInvalidParams) {
blocksID, err = w.ws.ReceiveBlocks(&neorpc.BlockFilter{Since: &since}, bRcvr)
}
}
if err != nil {
wsWaitErr = fmt.Errorf("failed to subscribe for new blocks/headers: %w", err)
} else { } else {
waitersActive++ waitersActive++
go func() { go func() {
@ -348,17 +340,6 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
if !ok { if !ok {
// We're toast, retry with non-ws client. // We're toast, retry with non-ws client.
hRcvr = nil hRcvr = nil
bRcvr = nil
aerRcvr = nil
wsWaitErr = ErrMissedEvent
break
}
waitErr = ErrTxNotAccepted
case _, ok := <-bRcvr:
if !ok {
// We're toast, retry with non-ws client.
hRcvr = nil
bRcvr = nil
aerRcvr = nil aerRcvr = nil
wsWaitErr = ErrMissedEvent wsWaitErr = ErrMissedEvent
break break
@ -368,7 +349,6 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
if !ok { if !ok {
// We're toast, retry with non-ws client. // We're toast, retry with non-ws client.
hRcvr = nil hRcvr = nil
bRcvr = nil
aerRcvr = nil aerRcvr = nil
wsWaitErr = ErrMissedEvent wsWaitErr = ErrMissedEvent
break break
@ -390,19 +370,11 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
case _, ok := <-hRcvr: case _, ok := <-hRcvr:
if !ok { // Missed event means both channels are closed. if !ok { // Missed event means both channels are closed.
hRcvr = nil hRcvr = nil
bRcvr = nil
aerRcvr = nil
}
case _, ok := <-bRcvr:
if !ok { // Missed event means both channels are closed.
hRcvr = nil
bRcvr = nil
aerRcvr = nil aerRcvr = nil
} }
case _, ok := <-aerRcvr: case _, ok := <-aerRcvr:
if !ok { // Missed event means both channels are closed. if !ok { // Missed event means both channels are closed.
hRcvr = nil hRcvr = nil
bRcvr = nil
aerRcvr = nil aerRcvr = nil
} }
case unsubErr := <-unsubErrs: case unsubErr := <-unsubErrs:
@ -426,9 +398,6 @@ func (w *EventBased) WaitAny(ctx context.Context, vub uint32, hashes ...util.Uin
if hRcvr != nil { if hRcvr != nil {
close(hRcvr) close(hRcvr)
} }
if bRcvr != nil {
close(bRcvr)
}
if aerRcvr != nil { if aerRcvr != nil {
close(aerRcvr) close(aerRcvr)
} }