From 9fb6d3266e5125cb4e6ec0ee2dbb548943bb4ef3 Mon Sep 17 00:00:00 2001 From: Ekaterina Pavlova Date: Fri, 9 Aug 2024 12:53:31 +0300 Subject: [PATCH] rpcsrv: add seedlist and standbycommittee to getversion Port neo-project/neo#3443. Close #3538 Signed-off-by: Ekaterina Pavlova --- pkg/neorpc/result/version.go | 20 +++++++++++++++++++- pkg/neorpc/result/version_test.go | 19 +++++++++++++++++-- pkg/rpcclient/rpc_test.go | 5 +++-- pkg/services/rpcsrv/server.go | 6 ++++++ pkg/services/rpcsrv/server_test.go | 5 +++++ 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/pkg/neorpc/result/version.go b/pkg/neorpc/result/version.go index 4dff198f6..cb33f1c40 100644 --- a/pkg/neorpc/result/version.go +++ b/pkg/neorpc/result/version.go @@ -7,6 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/config" "github.com/nspcc-dev/neo-go/pkg/config/netmode" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" ) @@ -40,7 +41,9 @@ type ( ValidatorsCount byte InitialGasDistribution fixedn.Fixed8 // Hardforks is the map of network hardforks with the enabling height. - Hardforks map[config.Hardfork]uint32 + Hardforks map[config.Hardfork]uint32 + StandbyCommittee keys.PublicKeys + SeedList []string // Below are NeoGo-specific extensions to the protocol that are // returned by the server in case they're enabled. @@ -67,6 +70,8 @@ type ( ValidatorsCount byte `json:"validatorscount"` InitialGasDistribution int64 `json:"initialgasdistribution"` Hardforks []hardforkAux `json:"hardforks"` + StandbyCommittee []string `json:"standbycommittee"` + SeedList []string `json:"seedlist"` CommitteeHistory map[uint32]uint32 `json:"committeehistory,omitempty"` P2PSigExtensions bool `json:"p2psigextensions,omitempty"` @@ -96,6 +101,11 @@ func (p Protocol) MarshalJSON() ([]byte, error) { }) } } + standbyCommittee := make([]string, len(p.StandbyCommittee)) + for i, key := range p.StandbyCommittee { + standbyCommittee[i] = key.StringCompressed() + } + aux := protocolMarshallerAux{ AddressVersion: p.AddressVersion, Network: p.Network, @@ -107,6 +117,8 @@ func (p Protocol) MarshalJSON() ([]byte, error) { ValidatorsCount: p.ValidatorsCount, InitialGasDistribution: int64(p.InitialGasDistribution), Hardforks: hfs, + StandbyCommittee: standbyCommittee, + SeedList: p.SeedList, CommitteeHistory: p.CommitteeHistory, P2PSigExtensions: p.P2PSigExtensions, @@ -123,6 +135,10 @@ func (p *Protocol) UnmarshalJSON(data []byte) error { if err != nil { return err } + standbyCommittee, err := keys.NewPublicKeysFromStrings(aux.StandbyCommittee) + if err != nil { + return err + } p.AddressVersion = aux.AddressVersion p.Network = aux.Network p.MillisecondsPerBlock = aux.MillisecondsPerBlock @@ -136,6 +152,8 @@ func (p *Protocol) UnmarshalJSON(data []byte) error { p.StateRootInHeader = aux.StateRootInHeader p.ValidatorsHistory = aux.ValidatorsHistory p.InitialGasDistribution = fixedn.Fixed8(aux.InitialGasDistribution) + p.StandbyCommittee = standbyCommittee + p.SeedList = aux.SeedList // Filter out unknown hardforks. for i := range aux.Hardforks { diff --git a/pkg/neorpc/result/version_test.go b/pkg/neorpc/result/version_test.go index d0480fbe2..162f92919 100644 --- a/pkg/neorpc/result/version_test.go +++ b/pkg/neorpc/result/version_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/nspcc-dev/neo-go/pkg/config" + "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" "github.com/stretchr/testify/require" ) @@ -40,7 +41,9 @@ func TestVersion_MarshalUnmarshalJSON(t *testing.T) { "msperblock": 15000, "network": 860833102, "validatorscount": 7, - "hardforks": [{"name": "Aspidochelone", "blockheight": 123}, {"name": "Basilisk", "blockheight": 1234}] + "hardforks": [{"name": "Aspidochelone", "blockheight": 123}, {"name": "Basilisk", "blockheight": 1234}], + "seedlist": ["seed1.neo.org:10333", "seed2.neo.org:10333"], + "standbycommittee": ["03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", "02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", "03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a"] }, "rpc": { "maxiteratorresultitems": 100, @@ -62,7 +65,9 @@ func TestVersion_MarshalUnmarshalJSON(t *testing.T) { "msperblock": 15000, "network": 860833102, "validatorscount": 7, - "hardforks": [{"name": "HF_Aspidochelone", "blockheight": 123}, {"name": "HF_Basilisk", "blockheight": 1234}] + "hardforks": [{"name": "HF_Aspidochelone", "blockheight": 123}, {"name": "HF_Basilisk", "blockheight": 1234}], + "seedlist": ["seed1.neo.org:10333", "seed2.neo.org:10333"], + "standbycommittee": ["03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", "02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", "03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a"] }, "rpc": { "maxiteratorresultitems": 100, @@ -72,6 +77,11 @@ func TestVersion_MarshalUnmarshalJSON(t *testing.T) { "useragent": "/Neo:3.1.0/", "wsport": 10334 }` + standbyCommittee, _ := keys.NewPublicKeysFromStrings([]string{ + "03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c", + "02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093", + "03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a", + }) v := &Version{ TCPPort: 10333, WSPort: 10334, @@ -94,6 +104,11 @@ func TestVersion_MarshalUnmarshalJSON(t *testing.T) { InitialGasDistribution: fixedn.Fixed8FromInt64(52000000), StateRootInHeader: false, Hardforks: map[config.Hardfork]uint32{config.HFAspidochelone: 123, config.HFBasilisk: 1234}, + StandbyCommittee: standbyCommittee, + SeedList: []string{ + "seed1.neo.org:10333", + "seed2.neo.org:10333", + }, }, } t.Run("MarshalJSON", func(t *testing.T) { diff --git a/pkg/rpcclient/rpc_test.go b/pkg/rpcclient/rpc_test.go index 9856a5e0a..26fb68ad3 100644 --- a/pkg/rpcclient/rpc_test.go +++ b/pkg/rpcclient/rpc_test.go @@ -1034,8 +1034,9 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ Nonce: 2153672787, UserAgent: "/NEO-GO:0.73.1-pre-273-ge381358/", Protocol: result.Protocol{ - Network: netmode.UnitTestNet, - Hardforks: map[config.Hardfork]uint32{}, + Network: netmode.UnitTestNet, + Hardforks: map[config.Hardfork]uint32{}, + StandbyCommittee: keys.PublicKeys{}, }, RPC: result.RPC{ MaxIteratorResultItems: 100, diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index 7269fe219..24fcf5201 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -867,6 +867,10 @@ func (s *Server) getVersion(_ params.Params) (any, *neorpc.Error) { } hfs[cfgHf] = height } + standbyCommittee, err := keys.NewPublicKeysFromStrings(cfg.StandbyCommittee) + if err != nil { + return nil, neorpc.NewInternalServerError(fmt.Sprintf("cannot fetch standbyCommittee: %s", err)) + } return &result.Version{ TCPPort: port, Nonce: s.coreServer.ID(), @@ -886,6 +890,8 @@ func (s *Server) getVersion(_ params.Params) (any, *neorpc.Error) { ValidatorsCount: byte(cfg.GetNumOfCNs(s.chain.BlockHeight())), InitialGasDistribution: cfg.InitialGASSupply, Hardforks: hfs, + StandbyCommittee: standbyCommittee, + SeedList: cfg.SeedList, CommitteeHistory: cfg.CommitteeHistory, P2PSigExtensions: cfg.P2PSigExtensions, diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index e6223d602..03e493f33 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -1352,11 +1352,16 @@ var rpcTestCases = map[string][]rpcTestCase{ require.EqualValues(t, cfg.MemPoolSize, resp.Protocol.MemoryPoolMaxTransactions) require.EqualValues(t, cfg.ValidatorsCount, resp.Protocol.ValidatorsCount) require.EqualValues(t, cfg.InitialGASSupply, resp.Protocol.InitialGasDistribution) + require.EqualValues(t, cfg.SeedList, resp.Protocol.SeedList) require.Equal(t, 0, len(resp.Protocol.CommitteeHistory)) require.True(t, resp.Protocol.P2PSigExtensions) // Yeah, notary is enabled. require.False(t, resp.Protocol.StateRootInHeader) require.Equal(t, 0, len(resp.Protocol.ValidatorsHistory)) + + standbyCommittee, err := keys.NewPublicKeysFromStrings(cfg.StandbyCommittee) + require.NoError(t, err) + require.EqualValues(t, standbyCommittee, resp.Protocol.StandbyCommittee) }, }, },