Skip to content

Commit

Permalink
Merge pull request #3540 from nspcc-dev/rpc-getversion
Browse files Browse the repository at this point in the history
rpcsrv: add seedlist and standbycommittee to `getversion`
  • Loading branch information
AnnaShaleva authored Aug 9, 2024
2 parents f0266a9 + 9fb6d32 commit b27e4f4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
20 changes: 19 additions & 1 deletion pkg/neorpc/result/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand All @@ -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"`
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions pkg/neorpc/result/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/rpcclient/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions pkg/services/rpcsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions pkg/services/rpcsrv/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
},
Expand Down

0 comments on commit b27e4f4

Please sign in to comment.