From 95b72db7077161c89efc98ac743ddaf7f6462b70 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 8 Aug 2022 16:10:02 +0300 Subject: [PATCH] rpcsrv: return more configuration data to the client These are extensions, but they're important for the client to make various decisions. --- docs/rpc.md | 9 +++++++++ pkg/neorpc/result/version.go | 31 +++++++++++++++++++++++++++--- pkg/services/rpcsrv/server.go | 6 +++++- pkg/services/rpcsrv/server_test.go | 6 +++++- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/docs/rpc.md b/docs/rpc.md index 1872ccfa3..a894a93f9 100644 --- a/docs/rpc.md +++ b/docs/rpc.md @@ -162,6 +162,15 @@ latest state synchronization point P the node working against, `LastUpdatedBlock` equals P. For NEP-11 NFTs `LastUpdatedBlock` is equal for all tokens of the same asset. +##### `getversion` + +NeoGo can return additional fields in the `protocol` object depending on the +extensions enabled. Specifically that's `p2psigextensions` and +`staterootinheader` booleans and `committeehistory` and `validatorshistory` +objects (that are effectively maps from stringified integers to other +integers. These fields are only returned when corresponding settings are +enabled in the server's protocol configuration. + ##### `getnep11transfers` and `getnep17transfers` `transfernotifyindex` is not tracked by NeoGo, thus this field is always zero. diff --git a/pkg/neorpc/result/version.go b/pkg/neorpc/result/version.go index e1f3b49e6..9f9102949 100644 --- a/pkg/neorpc/result/version.go +++ b/pkg/neorpc/result/version.go @@ -39,8 +39,18 @@ type ( MemoryPoolMaxTransactions int ValidatorsCount byte InitialGasDistribution fixedn.Fixed8 + + // Below are NeoGo-specific extensions to the protocol that are + // returned by the server in case they're enabled. + + // CommitteeHistory stores height:size map of the committee size. + CommitteeHistory map[uint32]int + // P2PSigExtensions is true when Notary subsystem is enabled on the network. + P2PSigExtensions bool // StateRootInHeader is true if state root is contained in block header. StateRootInHeader bool + // ValidatorsHistory stores height:size map of the validators count. + ValidatorsHistory map[uint32]int } ) @@ -67,7 +77,11 @@ type ( MemoryPoolMaxTransactions int `json:"memorypoolmaxtransactions"` ValidatorsCount byte `json:"validatorscount"` InitialGasDistribution int64 `json:"initialgasdistribution"` - StateRootInHeader bool `json:"staterootinheader,omitempty"` + + CommitteeHistory map[uint32]int `json:"committeehistory,omitempty"` + P2PSigExtensions bool `json:"p2psigextensions,omitempty"` + StateRootInHeader bool `json:"staterootinheader,omitempty"` + ValidatorsHistory map[uint32]int `json:"validatorshistory,omitempty"` } // versionUnmarshallerAux is an auxiliary struct used for Version JSON unmarshalling. @@ -92,7 +106,11 @@ type ( MemoryPoolMaxTransactions int `json:"memorypoolmaxtransactions"` ValidatorsCount byte `json:"validatorscount"` InitialGasDistribution json.RawMessage `json:"initialgasdistribution"` - StateRootInHeader bool `json:"staterootinheader,omitempty"` + + CommitteeHistory map[uint32]int `json:"committeehistory,omitempty"` + P2PSigExtensions bool `json:"p2psigextensions,omitempty"` + StateRootInHeader bool `json:"staterootinheader,omitempty"` + ValidatorsHistory map[uint32]int `json:"validatorshistory,omitempty"` } ) @@ -118,7 +136,11 @@ func (v *Version) MarshalJSON() ([]byte, error) { MemoryPoolMaxTransactions: v.Protocol.MemoryPoolMaxTransactions, ValidatorsCount: v.Protocol.ValidatorsCount, InitialGasDistribution: int64(v.Protocol.InitialGasDistribution), - StateRootInHeader: v.Protocol.StateRootInHeader, + + CommitteeHistory: v.Protocol.CommitteeHistory, + P2PSigExtensions: v.Protocol.P2PSigExtensions, + StateRootInHeader: v.Protocol.StateRootInHeader, + ValidatorsHistory: v.Protocol.ValidatorsHistory, }, StateRootInHeader: v.StateRootInHeader, } @@ -145,7 +167,10 @@ func (v *Version) UnmarshalJSON(data []byte) error { v.Protocol.MaxTransactionsPerBlock = aux.Protocol.MaxTransactionsPerBlock v.Protocol.MemoryPoolMaxTransactions = aux.Protocol.MemoryPoolMaxTransactions v.Protocol.ValidatorsCount = aux.Protocol.ValidatorsCount + v.Protocol.CommitteeHistory = aux.Protocol.CommitteeHistory + v.Protocol.P2PSigExtensions = aux.Protocol.P2PSigExtensions v.Protocol.StateRootInHeader = aux.Protocol.StateRootInHeader + v.Protocol.ValidatorsHistory = aux.Protocol.ValidatorsHistory v.StateRootInHeader = aux.StateRootInHeader if len(aux.Protocol.InitialGasDistribution) == 0 { return nil diff --git a/pkg/services/rpcsrv/server.go b/pkg/services/rpcsrv/server.go index b7534c13b..e67c801a0 100644 --- a/pkg/services/rpcsrv/server.go +++ b/pkg/services/rpcsrv/server.go @@ -694,7 +694,11 @@ func (s *Server) getVersion(_ params.Params) (interface{}, *neorpc.Error) { MemoryPoolMaxTransactions: cfg.MemPoolSize, ValidatorsCount: byte(cfg.GetNumOfCNs(s.chain.BlockHeight())), InitialGasDistribution: cfg.InitialGASSupply, - StateRootInHeader: cfg.StateRootInHeader, + + CommitteeHistory: cfg.CommitteeHistory, + P2PSigExtensions: cfg.P2PSigExtensions, + StateRootInHeader: cfg.StateRootInHeader, + ValidatorsHistory: cfg.ValidatorsHistory, }, }, nil } diff --git a/pkg/services/rpcsrv/server_test.go b/pkg/services/rpcsrv/server_test.go index 3f7fe8971..51a7f3556 100644 --- a/pkg/services/rpcsrv/server_test.go +++ b/pkg/services/rpcsrv/server_test.go @@ -875,7 +875,11 @@ 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, false, resp.Protocol.StateRootInHeader) + + 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)) }, }, },