Skip to content

Commit

Permalink
rpcsrv: add seedlist and standbycommittee to getversion
Browse files Browse the repository at this point in the history
Port neo-project/neo#3443.

Close #3538

Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
  • Loading branch information
AliceInHunterland committed Jul 31, 2024
1 parent d8e3e57 commit 77b1212
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
31 changes: 20 additions & 11 deletions pkg/neorpc/result/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package result

import (
"crypto"
"encoding/json"
"fmt"
"strings"
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 []crypto.PublicKey
SeedList []string

// Below are NeoGo-specific extensions to the protocol that are
// returned by the server in case they're enabled.
Expand All @@ -57,16 +60,18 @@ type (

// protocolMarshallerAux is an auxiliary struct used for Protocol JSON marshalling.
protocolMarshallerAux struct {
AddressVersion byte `json:"addressversion"`
Network netmode.Magic `json:"network"`
MillisecondsPerBlock int `json:"msperblock"`
MaxTraceableBlocks uint32 `json:"maxtraceableblocks"`
MaxValidUntilBlockIncrement uint32 `json:"maxvaliduntilblockincrement"`
MaxTransactionsPerBlock uint16 `json:"maxtransactionsperblock"`
MemoryPoolMaxTransactions int `json:"memorypoolmaxtransactions"`
ValidatorsCount byte `json:"validatorscount"`
InitialGasDistribution int64 `json:"initialgasdistribution"`
Hardforks []hardforkAux `json:"hardforks"`
AddressVersion byte `json:"addressversion"`
Network netmode.Magic `json:"network"`
MillisecondsPerBlock int `json:"msperblock"`
MaxTraceableBlocks uint32 `json:"maxtraceableblocks"`
MaxValidUntilBlockIncrement uint32 `json:"maxvaliduntilblockincrement"`
MaxTransactionsPerBlock uint16 `json:"maxtransactionsperblock"`
MemoryPoolMaxTransactions int `json:"memorypoolmaxtransactions"`
ValidatorsCount byte `json:"validatorscount"`
InitialGasDistribution int64 `json:"initialgasdistribution"`
Hardforks []hardforkAux `json:"hardforks"`
StandbyCommittee []crypto.PublicKey `json:"standbycommittee"`
SeedList []string `json:"seedlist"`

CommitteeHistory map[uint32]uint32 `json:"committeehistory,omitempty"`
P2PSigExtensions bool `json:"p2psigextensions,omitempty"`
Expand Down Expand Up @@ -107,6 +112,8 @@ func (p Protocol) MarshalJSON() ([]byte, error) {
ValidatorsCount: p.ValidatorsCount,
InitialGasDistribution: int64(p.InitialGasDistribution),
Hardforks: hfs,
StandbyCommittee: p.StandbyCommittee,
SeedList: p.SeedList,

CommitteeHistory: p.CommitteeHistory,
P2PSigExtensions: p.P2PSigExtensions,
Expand Down Expand Up @@ -136,6 +143,8 @@ func (p *Protocol) UnmarshalJSON(data []byte) error {
p.StateRootInHeader = aux.StateRootInHeader
p.ValidatorsHistory = aux.ValidatorsHistory
p.InitialGasDistribution = fixedn.Fixed8(aux.InitialGasDistribution)
p.StandbyCommittee = aux.StandbyCommittee
p.SeedList = aux.SeedList

// Filter out unknown hardforks.
for i := range aux.Hardforks {
Expand Down
18 changes: 16 additions & 2 deletions pkg/neorpc/result/version_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package result

import (
"crypto"
"encoding/json"
"testing"

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 Down Expand Up @@ -94,6 +99,15 @@ func TestVersion_MarshalUnmarshalJSON(t *testing.T) {
InitialGasDistribution: fixedn.Fixed8FromInt64(52000000),
StateRootInHeader: false,
Hardforks: map[config.Hardfork]uint32{config.HFAspidochelone: 123, config.HFBasilisk: 1234},
StandbyCommittee: []crypto.PublicKey{
"03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c",
"02df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e895093",
"03b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a",
},
SeedList: []string{
"seed1.neo.org:10333",
"seed2.neo.org:10333",
},
},
}
t.Run("MarshalJSON", func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/services/rpcsrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpcsrv
import (
"bytes"
"context"
"crypto"
"crypto/elliptic"
"encoding/binary"
"encoding/hex"
Expand Down Expand Up @@ -886,6 +887,8 @@ func (s *Server) getVersion(_ params.Params) (any, *neorpc.Error) {
ValidatorsCount: byte(cfg.GetNumOfCNs(s.chain.BlockHeight())),
InitialGasDistribution: cfg.InitialGASSupply,
Hardforks: hfs,
StandbyCommittee: []crypto.PublicKey{cfg.StandbyCommittee},
SeedList: cfg.SeedList,

CommitteeHistory: cfg.CommitteeHistory,
P2PSigExtensions: cfg.P2PSigExtensions,
Expand Down

0 comments on commit 77b1212

Please sign in to comment.