Skip to content

Commit 57338b4

Browse files
committed
wip
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
1 parent 79e4ff0 commit 57338b4

19 files changed

Lines changed: 1261 additions & 46 deletions

File tree

cmd/neofs-node/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/nspcc-dev/neofs-node/pkg/services/replicator"
4040
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
4141
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
42+
"github.com/nspcc-dev/neofs-node/pkg/services/sidechain"
4243
"github.com/nspcc-dev/neofs-node/pkg/timers"
4344
"github.com/nspcc-dev/neofs-node/pkg/util"
4445
"github.com/nspcc-dev/neofs-node/pkg/util/state"
@@ -172,6 +173,7 @@ type shared struct {
172173
control *controlSvc.Server
173174

174175
metaService *meta.Meta
176+
sidechain *sidechain.SideChain
175177

176178
containerPayments *paymentChecker
177179
}

cmd/neofs-node/config/meta/meta.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
package metaconfig
22

3+
import (
4+
"time"
5+
6+
"github.com/nspcc-dev/neofs-node/pkg/innerring/config"
7+
)
8+
39
// Meta contains configuration for Meta service.
410
type Meta struct {
5-
Path string `mapstructure:"path"`
11+
// List of nodes' addresses to communicate with over Neo P2P protocol in
12+
// 'host:port' format.
13+
//
14+
// Optional: by default, node runs as standalone.
15+
SeedNodes []string `mapstructure:"seed_nodes"`
16+
17+
// Storage configuration. Must be set using one of constructors like BoltDB.
18+
//
19+
// Required.
20+
Storage config.Storage `mapstructure:"storage"`
21+
22+
// Maximum time period (approximate) between two adjacent blocks,
23+
// if used enables dynamic block time (contrary to TimePerBlock
24+
// targeting for every block).
25+
//
26+
// Optional: not set by default. Must not be negative, must be
27+
// bigger than TimePerBlock.
28+
MaxTimePerBlock time.Duration `mapstructure:"max_time_per_block"`
29+
30+
// Neo RPC service configuration.
31+
//
32+
// Optional: see RPC defaults.
33+
RPC config.RPC `mapstructure:"rpc"`
34+
35+
// P2P settings.
36+
//
37+
// Required.
38+
P2P config.P2P `mapstructure:"p2p"`
639
}

cmd/neofs-node/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func initApp(c *cfg) {
138138
initAndLog(c, "session", initSessionService)
139139
initAndLog(c, "reputation", initReputationService)
140140
initAndLog(c, "meta", initMeta)
141+
initAndLog(c, "meta sidechain", initMeta_new)
141142
initAndLog(c, "object", initObjectService)
142143

143144
initAndLog(c, "morph notifications", listenMorphNotifications)

cmd/neofs-node/meta.go

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,50 @@ import (
1010
"github.com/nspcc-dev/neofs-node/pkg/core/container"
1111
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
1212
cntClient "github.com/nspcc-dev/neofs-node/pkg/morph/client/container"
13-
"github.com/nspcc-dev/neofs-node/pkg/services/meta"
1413
getsvc "github.com/nspcc-dev/neofs-node/pkg/services/object/get"
1514
containerSDK "github.com/nspcc-dev/neofs-sdk-go/container"
1615
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
1716
netmapsdk "github.com/nspcc-dev/neofs-sdk-go/netmap"
1817
"github.com/nspcc-dev/neofs-sdk-go/object"
1918
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
20-
"go.uber.org/zap"
2119
"golang.org/x/sync/errgroup"
2220
)
2321

2422
func initMeta(c *cfg) {
25-
if c.cfgMorph.client == nil {
26-
initMorphComponents(c)
27-
}
28-
29-
c.cfgMeta.network = &neofsNetwork{
30-
key: c.binPublicKey,
31-
cnrClient: c.cCli,
32-
containers: c.cnrSrc,
33-
network: c.netMapSource,
34-
header: c.cfgObject.getSvc,
35-
}
36-
37-
var err error
38-
p := meta.Parameters{
39-
Logger: c.log.With(zap.String("service", "meta data")),
40-
Network: c.cfgMeta.network,
41-
Timeout: c.appCfg.FSChain.DialTimeout,
42-
NeoEnpoints: c.appCfg.FSChain.Endpoints,
43-
ContainerHash: c.containerSH,
44-
NetmapHash: c.netmapSH,
45-
RootPath: c.appCfg.Meta.Path,
46-
}
47-
if p.RootPath == "" {
48-
p.RootPath = "metadata"
49-
}
50-
c.metaService, err = meta.New(p)
51-
fatalOnErr(err)
52-
53-
c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
54-
err = c.metaService.Run(ctx)
55-
if err != nil {
56-
c.internalErr <- fmt.Errorf("meta data service error: %w", err)
57-
}
58-
}))
23+
//if c.cfgMorph.client == nil {
24+
// initMorphComponents(c)
25+
//}
26+
//
27+
//c.cfgMeta.network = &neofsNetwork{
28+
// key: c.binPublicKey,
29+
// cnrClient: c.cCli,
30+
// containers: c.cnrSrc,
31+
// network: c.netMapSource,
32+
// header: c.cfgObject.getSvc,
33+
//}
34+
//
35+
//var err error
36+
//p := meta.Parameters{
37+
// Logger: c.log.With(zap.String("service", "metadata chain")),
38+
// Network: c.cfgMeta.network,
39+
// Timeout: c.appCfg.FSChain.DialTimeout,
40+
// NeoEnpoints: c.appCfg.FSChain.Endpoints,
41+
// ContainerHash: c.containerSH,
42+
// NetmapHash: c.netmapSH,
43+
// RootPath: c.appCfg.Meta.Path,
44+
//}
45+
//if p.RootPath == "" {
46+
// p.RootPath = "metadata"
47+
//}
48+
//c.metaService, err = meta.New(p)
49+
//fatalOnErr(err)
50+
//
51+
//c.workers = append(c.workers, newWorkerFromFunc(func(ctx context.Context) {
52+
// err = c.metaService.Run(ctx)
53+
// if err != nil {
54+
// c.internalErr <- fmt.Errorf("meta data service error: %w", err)
55+
// }
56+
//}))
5957
}
6058

6159
type neofsNetwork struct {

cmd/neofs-node/meta_new.go

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
"github.com/nspcc-dev/neo-go/pkg/config"
9+
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
10+
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
11+
"github.com/nspcc-dev/neofs-node/pkg/services/sidechain"
12+
"go.uber.org/zap"
13+
)
14+
15+
func initMeta_new(c *cfg) {
16+
l := c.log.With(zap.String("component", "metadata chain"))
17+
18+
v, err := c.cfgMorph.client.GetVersion()
19+
fatalOnErr(err)
20+
21+
fsChainProtocol := v.Protocol
22+
standByCommittee := make([]string, 0, len(v.Protocol.StandbyCommittee))
23+
for _, c := range v.Protocol.StandbyCommittee {
24+
standByCommittee = append(standByCommittee, c.StringCompressed())
25+
}
26+
27+
p2pCfg := c.appCfg.Meta.P2P
28+
29+
var chainCfg = config.Config{
30+
ProtocolConfiguration: config.ProtocolConfiguration{
31+
CommitteeHistory: nil,
32+
Genesis: config.Genesis{
33+
MaxTraceableBlocks: fsChainProtocol.MaxTraceableBlocks,
34+
MaxValidUntilBlockIncrement: fsChainProtocol.MaxValidUntilBlockIncrement,
35+
Roles: nil, // not needed?
36+
TimePerBlock: time.Duration(fsChainProtocol.MillisecondsPerBlock) * time.Millisecond,
37+
},
38+
Magic: fsChainProtocol.Network + 1,
39+
InitialGASSupply: fsChainProtocol.InitialGasDistribution,
40+
P2PNotaryRequestPayloadPoolSize: 1000,
41+
MaxTraceableBlocks: fsChainProtocol.MaxTraceableBlocks,
42+
MaxValidUntilBlockIncrement: fsChainProtocol.MaxValidUntilBlockIncrement,
43+
P2PSigExtensions: true,
44+
SeedList: c.appCfg.Meta.SeedNodes,
45+
StandbyCommittee: standByCommittee,
46+
StateRootInHeader: false,
47+
MaxTimePerBlock: c.appCfg.Meta.MaxTimePerBlock,
48+
ValidatorsCount: uint32(len(standByCommittee)),
49+
ValidatorsHistory: nil,
50+
VerifyTransactions: true,
51+
},
52+
ApplicationConfiguration: config.ApplicationConfiguration{
53+
P2P: config.P2P{
54+
Addresses: p2pCfg.Listen,
55+
AttemptConnPeers: int(p2pCfg.Peers.Attempts),
56+
DialTimeout: p2pCfg.DialTimeout,
57+
MaxPeers: int(p2pCfg.Peers.Max),
58+
MinPeers: int(p2pCfg.Peers.Min),
59+
PingInterval: p2pCfg.Ping.Interval,
60+
PingTimeout: p2pCfg.Ping.Timeout,
61+
ProtoTickInterval: p2pCfg.ProtoTickInterval,
62+
},
63+
Oracle: config.OracleConfiguration{},
64+
P2PNotary: config.P2PNotary{},
65+
StateRoot: config.StateRoot{},
66+
NeoFSBlockFetcher: config.NeoFSBlockFetcher{},
67+
NeoFSStateFetcher: config.NeoFSStateFetcher{},
68+
},
69+
}
70+
71+
var cfgDB dbconfig.DBConfiguration
72+
cfgDB.Type = c.appCfg.Meta.Storage.Type
73+
switch c.appCfg.Meta.Storage.Type {
74+
case dbconfig.BoltDB:
75+
cfgDB.BoltDBOptions.FilePath = c.appCfg.Meta.Storage.Path
76+
case dbconfig.LevelDB:
77+
cfgDB.LevelDBOptions.DataDirectoryPath = c.appCfg.Meta.Storage.Path
78+
default:
79+
panic(fmt.Sprintf("unsupported metadata storage type: %s", c.appCfg.Meta.Storage.Type))
80+
}
81+
chainCfg.ApplicationConfiguration.DBConfiguration = cfgDB
82+
83+
if len(c.appCfg.Meta.RPC.Listen) > 0 {
84+
var (
85+
rpcConfig config.RPC
86+
rpcCfgRead = c.appCfg.Meta.RPC
87+
)
88+
89+
rpcConfig.BasicService = config.BasicService{
90+
Enabled: true,
91+
Addresses: c.appCfg.Meta.RPC.Listen,
92+
}
93+
rpcConfig.MaxGasInvoke = fixedn.Fixed8FromInt64(int64(rpcCfgRead.MaxGasInvoke))
94+
rpcConfig.MaxIteratorResultItems = 100
95+
rpcConfig.MaxWebSocketClients = int(rpcCfgRead.MaxWebSocketClients)
96+
rpcConfig.SessionEnabled = true
97+
rpcConfig.SessionExpansionEnabled = true
98+
rpcConfig.SessionPoolSize = int(rpcCfgRead.SessionPoolSize)
99+
rpcConfig.StartWhenSynchronized = true
100+
if tlsCfg := rpcCfgRead.TLS; tlsCfg.Enabled {
101+
rpcConfig.TLSConfig.Enabled = true
102+
rpcConfig.TLSConfig.Addresses = tlsCfg.Listen
103+
rpcConfig.TLSConfig.CertFile = tlsCfg.CertFile
104+
rpcConfig.TLSConfig.KeyFile = tlsCfg.KeyFile
105+
}
106+
107+
chainCfg.ApplicationConfiguration.RPC = rpcConfig
108+
}
109+
110+
applySidechainDefaults(&chainCfg)
111+
112+
err = chainCfg.ProtocolConfiguration.Validate()
113+
fatalOnErr(err)
114+
115+
ch, err := sidechain.New(chainCfg, l, c.internalErr)
116+
fatalOnErr(err)
117+
118+
c.sidechain = ch
119+
120+
c.workers = append(c.workers, &workerFromFunc{
121+
fn: func(ctx context.Context) {
122+
err := ch.Run(ctx)
123+
if err != nil {
124+
c.internalErr <- err
125+
}
126+
},
127+
})
128+
}
129+
130+
func applySidechainDefaults(cfg *config.Config) {
131+
if cfg.ApplicationConfiguration.P2P.MaxPeers == 0 {
132+
cfg.ApplicationConfiguration.P2P.MaxPeers = 100
133+
}
134+
if cfg.ApplicationConfiguration.P2P.AttemptConnPeers == 0 {
135+
cfg.ApplicationConfiguration.P2P.AttemptConnPeers = cfg.ApplicationConfiguration.P2P.MinPeers + 10
136+
}
137+
if cfg.ApplicationConfiguration.P2P.DialTimeout == 0 {
138+
cfg.ApplicationConfiguration.P2P.DialTimeout = time.Minute
139+
}
140+
if cfg.ApplicationConfiguration.P2P.ProtoTickInterval == 0 {
141+
cfg.ApplicationConfiguration.P2P.ProtoTickInterval = 2 * time.Second
142+
}
143+
if cfg.ProtocolConfiguration.MaxTraceableBlocks == 0 {
144+
cfg.ProtocolConfiguration.MaxTraceableBlocks = 17280
145+
}
146+
if cfg.ProtocolConfiguration.MaxValidUntilBlockIncrement == 0 {
147+
cfg.ProtocolConfiguration.MaxValidUntilBlockIncrement = 8640
148+
}
149+
if cfg.ApplicationConfiguration.P2P.PingInterval == 0 {
150+
cfg.ApplicationConfiguration.P2P.PingInterval = 30 * time.Second
151+
}
152+
if cfg.ApplicationConfiguration.P2P.PingTimeout == 0 {
153+
cfg.ApplicationConfiguration.P2P.PingTimeout = time.Minute
154+
}
155+
if cfg.ApplicationConfiguration.RPC.MaxWebSocketClients == 0 {
156+
cfg.ApplicationConfiguration.RPC.MaxWebSocketClients = 64
157+
}
158+
if cfg.ApplicationConfiguration.RPC.SessionPoolSize == 0 {
159+
cfg.ApplicationConfiguration.RPC.SessionPoolSize = 20
160+
}
161+
if cfg.ApplicationConfiguration.RPC.MaxGasInvoke == 0 {
162+
cfg.ApplicationConfiguration.RPC.MaxGasInvoke = 100
163+
}
164+
}

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module github.com/nspcc-dev/neofs-node
22

33
go 1.24.0
44

5+
replace github.com/nspcc-dev/neo-go => ../neo-go
6+
57
require (
68
github.com/cenkalti/backoff/v4 v4.3.0
79
github.com/cheggaaa/pb v1.0.29
@@ -93,7 +95,9 @@ require (
9395
go.yaml.in/yaml/v2 v2.4.2 // indirect
9496
go.yaml.in/yaml/v3 v3.0.4 // indirect
9597
golang.org/x/crypto v0.45.0 // indirect
98+
golang.org/x/mod v0.29.0 // indirect
9699
golang.org/x/text v0.31.0 // indirect
100+
golang.org/x/tools v0.38.0 // indirect
97101
google.golang.org/genproto/googleapis/rpc v0.0.0-20250922171735-9219d122eba9 // indirect
98102
gopkg.in/yaml.v3 v3.0.1 // indirect
99103
lukechampine.com/blake3 v1.2.1 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,6 @@ github.com/nspcc-dev/hrw/v2 v2.0.4 h1:o3Zh/2aF+IgGpvt414f46Ya20WG9u9vWxVd16ErFI8
191191
github.com/nspcc-dev/hrw/v2 v2.0.4/go.mod h1:dUjOx27zTTvoPmT5EG25vSSWL2tKS7ndAa2TPTiZwFo=
192192
github.com/nspcc-dev/locode-db v0.8.1 h1:BadCnDPfIbQXbi+X/m7DRhbiau81QelM/bD4QiiCGsI=
193193
github.com/nspcc-dev/locode-db v0.8.1/go.mod h1:PtAASXSG4D4Oz0js9elzTyTr8GLpOJO20qFL881Nims=
194-
github.com/nspcc-dev/neo-go v0.114.0 h1:JxyLGlQGtzrfWvhdrUa35BGzBaadwPtLdNL5ehfOF2k=
195-
github.com/nspcc-dev/neo-go v0.114.0/go.mod h1:visra3tXvGBgBfhMizRGEB+bUI5a/zoeqr5WQRKXFGQ=
196194
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20251112080609-3c8e29c66609 h1:9jH0IXFw8rjBgBVWSJbWeEHf7XDjANBnmEas49rdAH8=
197195
github.com/nspcc-dev/neo-go/pkg/interop v0.0.0-20251112080609-3c8e29c66609/go.mod h1:X2spkE8hK/l08CYulOF19fpK5n3p2xO0L1GnJFIywQg=
198196
github.com/nspcc-dev/neofs-api-go/v2 v2.14.1-0.20240827150555-5ce597aa14ea h1:mK0EMGLvunXcFyq7fBURS/CsN4MH+4nlYiqn6pTwWAU=

pkg/innerring/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ type Settlement struct {
128128

129129
// Experimental configures experimental features.
130130
type Experimental struct {
131-
ChainMetaData bool `mapstructure:"chain_meta_data"`
132-
AllowEC bool `mapstructure:"allow_ec"`
131+
ChainMetaData MetaChain `mapstructure:"chain_meta_data"`
132+
AllowEC bool `mapstructure:"allow_ec"`
133133
}
134134

135135
// Mainnet configures mainnet chain settings.

pkg/innerring/config/metachain.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package config
2+
3+
import "time"
4+
5+
// TODO
6+
type MetaChain struct {
7+
// Swith experimental meta-on-chain support.
8+
Enabled bool `mapstructure:"enabled"`
9+
10+
// List of nodes' addresses to communicate with over Neo P2P protocol in
11+
// 'host:port' format.
12+
//
13+
// Optional: by default, node runs as standalone.
14+
SeedNodes []string `mapstructure:"seed_nodes"`
15+
16+
// Storage configuration. Must be set using one of constructors like BoltDB.
17+
//
18+
// Required.
19+
Storage Storage `mapstructure:"storage"`
20+
21+
// Maximum time period (approximate) between two adjacent blocks,
22+
// if used enables dynamic block time (contrary to TimePerBlock
23+
// targeting for every block).
24+
//
25+
// Optional: not set by default. Must not be negative, must be
26+
// bigger than TimePerBlock.
27+
MaxTimePerBlock time.Duration `mapstructure:"max_time_per_block"`
28+
29+
// Neo RPC service configuration.
30+
//
31+
// Optional: see RPC defaults.
32+
RPC RPC `mapstructure:"rpc"`
33+
34+
// P2P settings.
35+
//
36+
// Required.
37+
P2P P2P `mapstructure:"p2p"`
38+
}

0 commit comments

Comments
 (0)