-
Notifications
You must be signed in to change notification settings - Fork 199
/
nodeFacade.go
190 lines (164 loc) · 8.32 KB
/
nodeFacade.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package components
import (
"errors"
"fmt"
"strconv"
"time"
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/api/gin"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/forking"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/facade"
apiComp "github.com/multiversx/mx-chain-go/factory/api"
nodePack "github.com/multiversx/mx-chain-go/node"
"github.com/multiversx/mx-chain-go/node/metrics"
"github.com/multiversx/mx-chain-go/process/mock"
)
func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInterface APIConfigurator) error {
log.Debug("creating api resolver structure")
err := node.createMetrics(configs)
if err != nil {
return err
}
argsGasScheduleNotifier := forking.ArgsNewGasScheduleNotifier{
GasScheduleConfig: configs.EpochConfig.GasSchedule,
ConfigDir: configs.ConfigurationPathsHolder.GasScheduleDirectoryName,
EpochNotifier: node.CoreComponentsHolder.EpochNotifier(),
WasmVMChangeLocker: node.CoreComponentsHolder.WasmVMChangeLocker(),
}
gasScheduleNotifier, err := forking.NewGasScheduleNotifier(argsGasScheduleNotifier)
if err != nil {
return err
}
allowVMQueriesChan := make(chan struct{})
go func() {
time.Sleep(time.Second)
close(allowVMQueriesChan)
node.StatusCoreComponents.AppStatusHandler().SetStringValue(common.MetricAreVMQueriesReady, strconv.FormatBool(true))
}()
apiResolverArgs := &apiComp.ApiResolverArgs{
Configs: &configs,
CoreComponents: node.CoreComponentsHolder,
DataComponents: node.DataComponentsHolder,
StateComponents: node.StateComponentsHolder,
BootstrapComponents: node.BootstrapComponentsHolder,
CryptoComponents: node.CryptoComponentsHolder,
ProcessComponents: node.ProcessComponentsHolder,
StatusCoreComponents: node.StatusCoreComponents,
GasScheduleNotifier: gasScheduleNotifier,
Bootstrapper: &mock.BootstrapperStub{
GetNodeStateCalled: func() common.NodeState {
return common.NsSynchronized
},
},
AllowVMQueriesChan: allowVMQueriesChan,
StatusComponents: node.StatusComponentsHolder,
ProcessingMode: common.GetNodeProcessingMode(configs.ImportDbConfig),
}
apiResolver, err := apiComp.CreateApiResolver(apiResolverArgs)
if err != nil {
return err
}
log.Debug("creating multiversx node facade")
flagsConfig := configs.FlagsConfig
nd, err := nodePack.NewNode(
nodePack.WithStatusCoreComponents(node.StatusCoreComponents),
nodePack.WithCoreComponents(node.CoreComponentsHolder),
nodePack.WithCryptoComponents(node.CryptoComponentsHolder),
nodePack.WithBootstrapComponents(node.BootstrapComponentsHolder),
nodePack.WithStateComponents(node.StateComponentsHolder),
nodePack.WithDataComponents(node.DataComponentsHolder),
nodePack.WithStatusComponents(node.StatusComponentsHolder),
nodePack.WithProcessComponents(node.ProcessComponentsHolder),
nodePack.WithNetworkComponents(node.NetworkComponentsHolder),
nodePack.WithInitialNodesPubKeys(node.CoreComponentsHolder.GenesisNodesSetup().InitialNodesPubKeys()),
nodePack.WithRoundDuration(node.CoreComponentsHolder.GenesisNodesSetup().GetRoundDuration()),
nodePack.WithConsensusGroupSize(int(node.CoreComponentsHolder.GenesisNodesSetup().GetShardConsensusGroupSize())),
nodePack.WithGenesisTime(node.CoreComponentsHolder.GenesisTime()),
nodePack.WithConsensusType(configs.GeneralConfig.Consensus.Type),
nodePack.WithRequestedItemsHandler(node.ProcessComponentsHolder.RequestedItemsHandler()),
nodePack.WithAddressSignatureSize(configs.GeneralConfig.AddressPubkeyConverter.SignatureLength),
nodePack.WithValidatorSignatureSize(configs.GeneralConfig.ValidatorPubkeyConverter.SignatureLength),
nodePack.WithPublicKeySize(configs.GeneralConfig.ValidatorPubkeyConverter.Length),
nodePack.WithNodeStopChannel(node.CoreComponentsHolder.ChanStopNodeProcess()),
nodePack.WithImportMode(configs.ImportDbConfig.IsImportDBMode),
nodePack.WithESDTNFTStorageHandler(node.ProcessComponentsHolder.ESDTDataStorageHandlerForAPI()),
)
if err != nil {
return errors.New("error creating node: " + err.Error())
}
shardID := node.GetShardCoordinator().SelfId()
restApiInterface := apiInterface.RestApiInterface(shardID)
argNodeFacade := facade.ArgNodeFacade{
Node: nd,
ApiResolver: apiResolver,
RestAPIServerDebugMode: flagsConfig.EnableRestAPIServerDebugMode,
WsAntifloodConfig: configs.GeneralConfig.WebServerAntiflood,
FacadeConfig: config.FacadeConfig{
RestApiInterface: restApiInterface,
PprofEnabled: flagsConfig.EnablePprof,
},
ApiRoutesConfig: *configs.ApiRoutesConfig,
AccountsState: node.StateComponentsHolder.AccountsAdapter(),
PeerState: node.StateComponentsHolder.PeerAccounts(),
Blockchain: node.DataComponentsHolder.Blockchain(),
}
ef, err := facade.NewNodeFacade(argNodeFacade)
if err != nil {
return fmt.Errorf("%w while creating NodeFacade", err)
}
ef.SetSyncer(node.CoreComponentsHolder.SyncTimer())
node.facadeHandler = ef
return nil
}
func (node *testOnlyProcessingNode) createHttpServer(configs config.Configs) error {
httpServerArgs := gin.ArgsNewWebServer{
Facade: node.facadeHandler,
ApiConfig: *configs.ApiRoutesConfig,
AntiFloodConfig: configs.GeneralConfig.WebServerAntiflood,
}
httpServerWrapper, err := gin.NewGinWebServerHandler(httpServerArgs)
if err != nil {
return err
}
err = httpServerWrapper.StartHttpServer()
if err != nil {
return err
}
node.httpServer = httpServerWrapper
return nil
}
func (node *testOnlyProcessingNode) createMetrics(configs config.Configs) error {
err := metrics.InitMetrics(
node.StatusCoreComponents.AppStatusHandler(),
node.CryptoComponentsHolder.PublicKeyString(),
node.BootstrapComponentsHolder.NodeType(),
node.BootstrapComponentsHolder.ShardCoordinator(),
node.CoreComponentsHolder.GenesisNodesSetup(),
configs.FlagsConfig.Version,
configs.EconomicsConfig,
configs.GeneralConfig.EpochStartConfig.RoundsPerEpoch,
node.CoreComponentsHolder.MinTransactionVersion(),
)
if err != nil {
return err
}
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricNodeDisplayName, configs.PreferencesConfig.Preferences.NodeDisplayName)
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricRedundancyLevel, fmt.Sprintf("%d", configs.PreferencesConfig.Preferences.RedundancyLevel))
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricRedundancyIsMainActive, common.MetricValueNA)
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricChainId, node.CoreComponentsHolder.ChainID())
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricGasPerDataByte, node.CoreComponentsHolder.EconomicsData().GasPerDataByte())
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricMinGasPrice, node.CoreComponentsHolder.EconomicsData().MinGasPrice())
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricMinGasLimit, node.CoreComponentsHolder.EconomicsData().MinGasLimit())
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricExtraGasLimitGuardedTx, node.CoreComponentsHolder.EconomicsData().ExtraGasLimitGuardedTx())
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricRewardsTopUpGradientPoint, node.CoreComponentsHolder.EconomicsData().RewardsTopUpGradientPoint().String())
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricTopUpFactor, fmt.Sprintf("%g", node.CoreComponentsHolder.EconomicsData().RewardsTopUpFactor()))
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricGasPriceModifier, fmt.Sprintf("%g", node.CoreComponentsHolder.EconomicsData().GasPriceModifier()))
metrics.SaveUint64Metric(node.StatusCoreComponents.AppStatusHandler(), common.MetricMaxGasPerTransaction, node.CoreComponentsHolder.EconomicsData().MaxGasLimitPerTx())
if configs.PreferencesConfig.Preferences.FullArchive {
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricPeerType, core.ObserverPeer.String())
metrics.SaveStringMetric(node.StatusCoreComponents.AppStatusHandler(), common.MetricPeerSubType, core.FullHistoryObserver.String())
}
return nil
}