Merge pull request #3540 from nspcc-dev/rpc-getversion

rpcsrv: add seedlist and standbycommittee to `getversion`
This commit is contained in:
Anna Shaleva 2024-08-09 15:18:12 +03:00 committed by GitHub
commit b27e4f4309
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 50 additions and 5 deletions

View file

@ -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 {

View file

@ -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) {

View file

@ -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,

View file

@ -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,

View file

@ -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)
},
},
},