|
| 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 | +} |
0 commit comments