-
Notifications
You must be signed in to change notification settings - Fork 50
Feat/native meta contract #3742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,39 @@ | ||
| package metaconfig | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/nspcc-dev/neofs-node/pkg/innerring/config" | ||
| ) | ||
|
|
||
| // Meta contains configuration for Meta service. | ||
| type Meta struct { | ||
| Path string `mapstructure:"path"` | ||
| // List of nodes' addresses to communicate with over Neo P2P protocol in | ||
| // 'host:port' format. | ||
| // | ||
| // Optional: by default, node runs as standalone. | ||
| SeedNodes []string `mapstructure:"seed_nodes"` | ||
|
|
||
| // Storage configuration. Must be set using one of constructors like BoltDB. | ||
| // | ||
| // Required. | ||
| Storage config.Storage `mapstructure:"storage"` | ||
|
|
||
| // Maximum time period (approximate) between two adjacent blocks, | ||
| // if used enables dynamic block time (contrary to TimePerBlock | ||
| // targeting for every block). | ||
| // | ||
| // Optional: not set by default. Must not be negative, must be | ||
| // bigger than TimePerBlock. | ||
| MaxTimePerBlock time.Duration `mapstructure:"max_time_per_block"` | ||
|
|
||
| // Neo RPC service configuration. | ||
| // | ||
| // Optional: see RPC defaults. | ||
| RPC config.RPC `mapstructure:"rpc"` | ||
|
|
||
| // P2P settings. | ||
| // | ||
| // Required. | ||
| P2P config.P2P `mapstructure:"p2p"` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/nspcc-dev/neo-go/pkg/config" | ||
| "github.com/nspcc-dev/neo-go/pkg/core/native/noderoles" | ||
| "github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig" | ||
| "github.com/nspcc-dev/neo-go/pkg/crypto/keys" | ||
| "github.com/nspcc-dev/neo-go/pkg/encoding/fixedn" | ||
| "github.com/nspcc-dev/neofs-node/pkg/services/sidechain" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| func initMeta_new(c *cfg) { | ||
| l := c.log.With(zap.String("component", "metadata chain")) | ||
|
|
||
| v, err := c.cfgMorph.client.GetVersion() | ||
| fatalOnErr(err) | ||
|
|
||
| fsChainProtocol := v.Protocol | ||
| standByCommittee := make([]string, 0, len(v.Protocol.StandbyCommittee)) | ||
| for _, c := range v.Protocol.StandbyCommittee { | ||
| standByCommittee = append(standByCommittee, c.StringCompressed()) | ||
| } | ||
|
|
||
| p2pCfg := c.appCfg.Meta.P2P | ||
|
|
||
| var chainCfg = config.Config{ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would like to be validated on what exact minimum config is enough for an RPC node to start. see
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the reviewcomments below. |
||
| ProtocolConfiguration: config.ProtocolConfiguration{ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for the record: I don't see However, NeoGo is continuously adding more hardforks, so if some new hardfork is added, then it may affect states after subsequent NeoGo dependency update in meta chain. So to me, it's better to explicitly set all desired hardfork heights to 0 here. |
||
| CommitteeHistory: nil, | ||
| Genesis: config.Genesis{ | ||
| MaxTraceableBlocks: fsChainProtocol.MaxTraceableBlocks, | ||
| MaxValidUntilBlockIncrement: fsChainProtocol.MaxValidUntilBlockIncrement, | ||
| Roles: map[noderoles.Role]keys.PublicKeys{ | ||
| noderoles.P2PNotary: v.Protocol.StandbyCommittee, | ||
| noderoles.NeoFSAlphabet: v.Protocol.StandbyCommittee, | ||
| }, | ||
| TimePerBlock: time.Duration(fsChainProtocol.MillisecondsPerBlock) * time.Millisecond, | ||
| }, | ||
| Magic: fsChainProtocol.Network + 1, | ||
| InitialGASSupply: fsChainProtocol.InitialGasDistribution, | ||
| P2PNotaryRequestPayloadPoolSize: 1000, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be removed, will be set to default by https://github.com/nspcc-dev/neo-go/blob/993eaaeaf6faef5d66647212bfa4ba9618ee7b2f/pkg/core/blockchain.go#L291. |
||
| MaxTraceableBlocks: fsChainProtocol.MaxTraceableBlocks, | ||
| MaxValidUntilBlockIncrement: fsChainProtocol.MaxValidUntilBlockIncrement, | ||
| P2PSigExtensions: true, | ||
| SeedList: c.appCfg.Meta.SeedNodes, | ||
| StandbyCommittee: standByCommittee, | ||
| StateRootInHeader: false, | ||
| MaxTimePerBlock: c.appCfg.Meta.MaxTimePerBlock, | ||
| ValidatorsCount: uint32(len(standByCommittee)), | ||
| ValidatorsHistory: nil, | ||
| VerifyTransactions: true, | ||
| }, | ||
| ApplicationConfiguration: config.ApplicationConfiguration{ | ||
| P2P: config.P2P{ | ||
| Addresses: p2pCfg.Listen, | ||
| AttemptConnPeers: int(p2pCfg.Peers.Attempts), | ||
| DialTimeout: p2pCfg.DialTimeout, | ||
| MaxPeers: int(p2pCfg.Peers.Max), | ||
| MinPeers: int(p2pCfg.Peers.Min), | ||
| PingInterval: p2pCfg.Ping.Interval, | ||
| PingTimeout: p2pCfg.Ping.Timeout, | ||
| ProtoTickInterval: p2pCfg.ProtoTickInterval, | ||
| }, | ||
| Oracle: config.OracleConfiguration{}, | ||
| P2PNotary: config.P2PNotary{}, | ||
| StateRoot: config.StateRoot{}, | ||
| NeoFSBlockFetcher: config.NeoFSBlockFetcher{}, | ||
| NeoFSStateFetcher: config.NeoFSStateFetcher{}, | ||
| }, | ||
| } | ||
|
|
||
| var cfgDB dbconfig.DBConfiguration | ||
| cfgDB.Type = c.appCfg.Meta.Storage.Type | ||
| switch c.appCfg.Meta.Storage.Type { | ||
| case dbconfig.BoltDB: | ||
| cfgDB.BoltDBOptions.FilePath = c.appCfg.Meta.Storage.Path | ||
| case dbconfig.LevelDB: | ||
| cfgDB.LevelDBOptions.DataDirectoryPath = c.appCfg.Meta.Storage.Path | ||
| default: | ||
| panic(fmt.Sprintf("unsupported metadata storage type: %s", c.appCfg.Meta.Storage.Type)) | ||
| } | ||
| chainCfg.ApplicationConfiguration.DBConfiguration = cfgDB | ||
|
|
||
| if len(c.appCfg.Meta.RPC.Listen) > 0 { | ||
| var ( | ||
| rpcConfig config.RPC | ||
| rpcCfgRead = c.appCfg.Meta.RPC | ||
| ) | ||
|
|
||
| rpcConfig.BasicService = config.BasicService{ | ||
| Enabled: true, | ||
| Addresses: c.appCfg.Meta.RPC.Listen, | ||
| } | ||
| rpcConfig.MaxGasInvoke = fixedn.Fixed8FromInt64(int64(rpcCfgRead.MaxGasInvoke)) | ||
| rpcConfig.MaxIteratorResultItems = 100 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use https://github.com/nspcc-dev/neo-go/blob/2aef3337eed2994ec756bcd145502ce82eb7e7c1/pkg/config/config.go#L28 if you need to set the default. Keep it empty in case if you're OK with server defaults, the config will be sanitized on RPC server construction, ref. https://github.com/nspcc-dev/neo-go/blob/2aef3337eed2994ec756bcd145502ce82eb7e7c1/pkg/services/rpcsrv/server.go#L286.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose it's the answer to https://github.com/nspcc-dev/neofs-node/pull/3742/changes#r2628944024. |
||
| rpcConfig.MaxWebSocketClients = int(rpcCfgRead.MaxWebSocketClients) | ||
| rpcConfig.SessionEnabled = true | ||
| rpcConfig.SessionExpansionEnabled = true | ||
| rpcConfig.SessionPoolSize = int(rpcCfgRead.SessionPoolSize) | ||
| rpcConfig.StartWhenSynchronized = true | ||
AnnaShaleva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if tlsCfg := rpcCfgRead.TLS; tlsCfg.Enabled { | ||
| rpcConfig.TLSConfig.Enabled = true | ||
| rpcConfig.TLSConfig.Addresses = tlsCfg.Listen | ||
| rpcConfig.TLSConfig.CertFile = tlsCfg.CertFile | ||
| rpcConfig.TLSConfig.KeyFile = tlsCfg.KeyFile | ||
| } | ||
|
|
||
| chainCfg.ApplicationConfiguration.RPC = rpcConfig | ||
| } | ||
|
|
||
| applySidechainDefaults(&chainCfg) | ||
|
|
||
| err = chainCfg.ProtocolConfiguration.Validate() | ||
| fatalOnErr(err) | ||
|
|
||
| ch, err := sidechain.New(chainCfg, l, c.internalErr) | ||
| fatalOnErr(err) | ||
|
|
||
| c.sidechain = ch | ||
|
|
||
| c.workers = append(c.workers, &workerFromFunc{ | ||
| fn: func(ctx context.Context) { | ||
| err := ch.Run(ctx) | ||
| if err != nil { | ||
| c.internalErr <- err | ||
| } | ||
| }, | ||
| }) | ||
| } | ||
|
|
||
| func applySidechainDefaults(cfg *config.Config) { | ||
| if cfg.ApplicationConfiguration.P2P.MaxPeers == 0 { | ||
| cfg.ApplicationConfiguration.P2P.MaxPeers = 100 | ||
| } | ||
| if cfg.ApplicationConfiguration.P2P.AttemptConnPeers == 0 { | ||
| cfg.ApplicationConfiguration.P2P.AttemptConnPeers = cfg.ApplicationConfiguration.P2P.MinPeers + 10 | ||
| } | ||
|
Comment on lines
+139
to
+141
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sanitized by the server constructor, ref. https://github.com/nspcc-dev/neo-go/blob/2aef3337eed2994ec756bcd145502ce82eb7e7c1/pkg/network/server.go#L295.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As far as some other fields mentioned in |
||
| if cfg.ApplicationConfiguration.P2P.DialTimeout == 0 { | ||
| cfg.ApplicationConfiguration.P2P.DialTimeout = time.Minute | ||
| } | ||
| if cfg.ApplicationConfiguration.P2P.ProtoTickInterval == 0 { | ||
| cfg.ApplicationConfiguration.P2P.ProtoTickInterval = 2 * time.Second | ||
| } | ||
| if cfg.ProtocolConfiguration.MaxTraceableBlocks == 0 { | ||
| cfg.ProtocolConfiguration.MaxTraceableBlocks = 17280 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use magic numbers, please. Move it to a constant, add an appropriate comment: it's 3 days of 15-seconds blocks in its essence, ref. nspcc-dev/neo-go#3518. Also, meta chains will likely have shorter |
||
| } | ||
| if cfg.ProtocolConfiguration.MaxValidUntilBlockIncrement == 0 { | ||
| cfg.ProtocolConfiguration.MaxValidUntilBlockIncrement = 8640 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's set to a day of 15-seconds blocks for FS chains, so https://github.com/nspcc-dev/neofs-node/pull/3742/changes#r2630334320 is relevant for this setting as far. And just for the record: it can't exceed MTB setting. |
||
| } | ||
| if cfg.ApplicationConfiguration.P2P.PingInterval == 0 { | ||
| cfg.ApplicationConfiguration.P2P.PingInterval = 30 * time.Second | ||
| } | ||
| if cfg.ApplicationConfiguration.P2P.PingTimeout == 0 { | ||
| cfg.ApplicationConfiguration.P2P.PingTimeout = time.Minute | ||
| } | ||
| if cfg.ApplicationConfiguration.RPC.MaxWebSocketClients == 0 { | ||
| cfg.ApplicationConfiguration.RPC.MaxWebSocketClients = 64 | ||
| } | ||
| if cfg.ApplicationConfiguration.RPC.SessionPoolSize == 0 { | ||
| cfg.ApplicationConfiguration.RPC.SessionPoolSize = 20 | ||
| } | ||
| if cfg.ApplicationConfiguration.RPC.MaxGasInvoke == 0 { | ||
| cfg.ApplicationConfiguration.RPC.MaxGasInvoke = 100 | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,8 +106,8 @@ type Settlement struct { | |
|
|
||
| // Experimental configures experimental features. | ||
| type Experimental struct { | ||
| ChainMetaData bool `mapstructure:"chain_meta_data"` | ||
| AllowEC bool `mapstructure:"allow_ec"` | ||
| ChainMetaData MetaChain `mapstructure:"chain_meta_data"` | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since it is experimental, i dont care if it is changed, but i may be wrong |
||
| AllowEC bool `mapstructure:"allow_ec"` | ||
| } | ||
|
|
||
| // Mainnet configures mainnet chain settings. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it supposed to be commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not, it is a temporary migration/merging of old and new meta services for SNs