-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserverless.yml
692 lines (686 loc) · 19.6 KB
/
serverless.yml
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
service: hathor-wallet-service
frameworkVersion: '2'
useDotenv: true
custom:
warmup:
walletWarmer: # Keeps the lambdas used by the wallets initialization warm
enabled: true
events:
- schedule: rate(5 minutes)
webpack:
webpackConfig: ./webpack.config.js
includeModules: true
prune:
automatic: true
number: 3
authorizer:
walletBearer:
name: bearerAuthorizer
type: TOKEN
identitySource: method.request.header.Authorization
identityValidationExpression: Bearer (.*)
# Configures throttling settings for the API Gateway stage
# They apply to all http endpoints, unless specifically overridden
apiGatewayThrottling:
maxRequestsPerSecond: 500
maxConcurrentRequests: 250
stage: ${opt:stage, 'dev'}
explorerServiceStage: ${env:EXPLORER_STAGE, 'dev'}
alerts:
stages: # Select which stages to deploy alarms to
- mainnet
- mainnet-stg
- testnet
topics: # SNS Topics to send alerts to
major:
alarm:
topic: arn:aws:sns:eu-central-1:${self:provider.environment.ACCOUNT_ID}:opsgenie-cloudwatch-integration-production-major
minor:
alarm:
topic: arn:aws:sns:eu-central-1:${self:provider.environment.ACCOUNT_ID}:opsgenie-cloudwatch-integration-production-minor
definitions: # Definition of alarms
majorFunctionErrors:
description: "Too many errors in hathor-wallet-service. Runbook: https://github.com/HathorNetwork/ops-tools/blob/master/docs/runbooks/wallet-service/errors-in-logs.md"
namespace: 'AWS/Lambda'
metric: Errors
threshold: 5
statistic: Sum
period: 60
evaluationPeriods: 5
comparisonOperator: GreaterThanOrEqualToThreshold
treatMissingData: notBreaching
alarmActions:
- major
minorFunctionErrors:
description: "Too many errors in hathor-wallet-service. Runbook: https://github.com/HathorNetwork/ops-tools/blob/master/docs/runbooks/wallet-service/errors-in-logs.md"
namespace: 'AWS/Lambda'
metric: Errors
threshold: 2
statistic: Sum
period: 60
evaluationPeriods: 1
comparisonOperator: GreaterThanOrEqualToThreshold
treatMissingData: notBreaching
alarmActions:
- minor
wsLambdasExecutionDuration:
description: "WebSocket lambda took too long to execute"
namespace: 'AWS/Lambda'
metric: "Duration"
statistic: Average
threshold: 1000 # This is in milliseconds
period: 60
evaluationPeriods: 1
comparisonOperator: GreaterThanThreshold
alarmActions:
- minor
cleanTxProposalsUtxosDuration:
description: "Clean tx proposals utxos cronjob taking too long"
namespace: 'AWS/Lambda'
metric: "Duration"
statistic: Average
threshold: 30000 # 30s
period: 60 # seconds
evaluationPeriods: 1
comparisonOperator: GreaterThanThreshold
alarmActions:
- minor
alarms: # Alarms that will be applied to all functions
- majorFunctionErrors
- minorFunctionErrors
plugins:
- serverless-offline
- serverless-webpack
- serverless-prune-plugin
- serverless-api-gateway-throttling
- serverless-plugin-warmup
- serverless-iam-roles-per-function
- serverless-plugin-aws-alerts
resources:
Resources:
# This is needed to add CORS headers when the authorizer rejects an authorization request
# as we don't have control over the response.
# Taken from: https://www.serverless.com/blog/cors-api-gateway-survival-guide/
GatewayResponseDefault4XX:
Type: 'AWS::ApiGateway::GatewayResponse'
Properties:
ResponseParameters:
gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
ResponseType: DEFAULT_4XX
RestApiId:
Ref: 'ApiGatewayRestApi'
WalletServiceNewTxQueue:
Type: "AWS::SQS::Queue"
Properties:
QueueName:
WalletServiceNewTxQueue_${self:custom.stage}
provider:
name: aws
runtime: nodejs16.x
lambdaHashingVersion: 20201221
# In MB. This is the memory allocated for the Lambdas, they cannot use more than this
# and will break if they try.
memorySize: 256
# This is the default timeout. Each function can specify a different value
timeout: 6
websocketsApiName: wallet-realtime-ws-api-${self:custom.stage}
websocketsApiRouteSelectionExpression: $request.body.action
vpc:
securityGroupIds:
- ${env:AWS_VPC_DEFAULT_SG_ID}
subnetIds:
- ${env:AWS_SUBNET_ID_1}
- ${env:AWS_SUBNET_ID_2}
- ${env:AWS_SUBNET_ID_3}
stackTags:
Application: "hathor-wallet-service"
Stage: "${self:custom.stage}"
apiGateway:
minimumCompressionSize: 1024 # Enable gzip compression for responses > 1 KB
environment:
ACCOUNT_ID: ${env:ACCOUNT_ID}
AUTH_SECRET: ${env:AUTH_SECRET}
AWS_VPC_DEFAULT_SG_ID: ${env:AWS_VPC_DEFAULT_SG_ID}
AWS_SUBNET_ID_1: ${env:AWS_SUBNET_ID_1}
AWS_SUBNET_ID_2: ${env:AWS_SUBNET_ID_2}
AWS_SUBNET_ID_3: ${env:AWS_SUBNET_ID_3}
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
APPLICATION_NAME: ${env:APPLICATION_NAME}
BLOCK_REWARD_LOCK: ${env:BLOCK_REWARD_LOCK}
CONFIRM_FIRST_ADDRESS: ${env:CONFIRM_FIRST_ADDRESS}
DB_ENDPOINT: ${env:DB_ENDPOINT}
DB_PORT: ${env:DB_PORT}
DB_NAME: ${env:DB_NAME}
DB_USER: ${env:DB_USER}
DB_PASS: ${env:DB_PASS}
MAX_ADDRESS_GAP: ${env:MAX_ADDRESS_GAP}
NETWORK: ${env:NETWORK}
NEW_TX_SQS: { Ref: WalletServiceNewTxQueue }
REDIS_URL: ${env:REDIS_URL}
REDIS_PASSWORD: ${env:REDIS_PASSWORD}
SERVICE_NAME: ${self:service}
STAGE: ${self:custom.stage}
EXPLORER_SERVICE_STAGE: ${self:custom.explorerServiceStage}
NFT_AUTO_REVIEW_ENABLED: ${env:NFT_AUTO_REVIEW_ENABLED}
VOIDED_TX_OFFSET: ${env:VOIDED_TX_OFFSET}
DEFAULT_SERVER: ${env:DEFAULT_SERVER}
WS_DOMAIN: ${env:WS_DOMAIN}
TX_HISTORY_MAX_COUNT: ${env:TX_HISTORY_MAX_COUNT}
WALLET_SERVICE_LAMBDA_ENDPOINT: ${env:WALLET_SERVICE_LAMBDA_ENDPOINT}
PUSH_NOTIFICATION_ENABLED: ${env:PUSH_NOTIFICATION_ENABLED}
PUSH_ALLOWED_PROVIDERS: ${env:PUSH_ALLOWED_PROVIDERS}
FIREBASE_PROJECT_ID: ${env:FIREBASE_PROJECT_ID}
FIREBASE_PRIVATE_KEY_ID: ${env:FIREBASE_PRIVATE_KEY_ID}
FIREBASE_PRIVATE_KEY: ${env:FIREBASE_PRIVATE_KEY}
FIREBASE_CLIENT_EMAIL: ${env:FIREBASE_CLIENT_EMAIL}
FIREBASE_CLIENT_ID: ${env:FIREBASE_CLIENT_ID}
FIREBASE_AUTH_URI: ${env:FIREBASE_AUTH_URI}
FIREBASE_TOKEN_URI: ${env:FIREBASE_TOKEN_URI}
FIREBASE_AUTH_PROVIDER_X509_CERT_URL: ${env:FIREBASE_AUTH_PROVIDER_X509_CERT_URL}
FIREBASE_CLIENT_X509_CERT_URL: ${env:FIREBASE_CLIENT_X509_CERT_URL}
LOG_LEVEL: ${env:LOG_LEVEL}
ALERT_MANAGER_REGION: ${env:ALERT_MANAGER_REGION}
ALERT_MANAGER_TOPIC: ${env:ALERT_MANAGER_TOPIC}
iamRoleStatements:
- Effect: Allow
Action:
- sqs:*
Resource:
- Fn::GetAtt: [ WalletServiceNewTxQueue, Arn ]
- arn:aws:sqs:${self:provider.environment.ALERT_MANAGER_REGION}:${self:provider.environment.ACCOUNT_ID}:${self:provider.environment.ALERT_MANAGER_TOPIC}
functions:
onHandleOldVoidedTxs:
handler: src/mempool.onHandleOldVoidedTxs
events:
- schedule: rate(${env:VOIDED_TX_OFFSET} minutes)
warmup:
walletWarmer:
enabled: false
getLatestBlock:
handler: src/height.getLatestBlock
warmup:
walletWarmer:
enabled: false
onNewTxRequest:
handler: src/txProcessor.onNewTxRequest
timeout: 12 # seconds
warmup:
walletWarmer:
enabled: false
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
Resource:
- Fn::GetAtt: [ OnNewNftEventLambdaFunction, Arn ]
- Fn::GetAtt: [ TxPushRequestedLambdaFunction, Arn ]
onMinersListRequest:
handler: src/api/miners.onMinersListRequest
warmup:
walletWarmer:
enabled: false
onTotalSupplyRequest:
handler: src/api/totalSupply.onTotalSupplyRequest
timeout: 120 # 2 minutes
warmup:
walletWarmer:
enabled: false
onHandleReorgRequest:
handler: src/txProcessor.onHandleReorgRequest
timeout: 300 # 5 minutes
warmup:
walletWarmer:
enabled: false
onNewTxEvent:
handler: src/txProcessor.onNewTxEvent
warmup:
walletWarmer:
enabled: false
onNewNftEvent:
handler: src/txProcessor.onNewNftEvent
warmup:
walletWarmer:
enabled: false
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
Resource:
arn:aws:lambda:eu-central-1:${self:provider.environment.ACCOUNT_ID}:function:hathor-explorer-service-${self:custom.explorerServiceStage}-create_or_update_dag_metadata
loadWalletAsync:
handler: src/api/wallet.loadWallet
warmup:
walletWarmer:
enabled: false
loadWalletApi:
role: arn:aws:iam::${self:provider.environment.ACCOUNT_ID}:role/WalletServiceLoadWalletLambda
handler: src/api/wallet.load
events:
- http:
path: wallet/init
method: post
cors: true
warmup:
walletWarmer:
enabled: true
changeWalletAuthXpubApi:
handler: src/api/wallet.changeAuthXpub
events:
- http:
path: wallet/auth
method: put
cors: true
warmup:
walletWarmer:
enabled: false
getWalletStatusApi:
handler: src/api/wallet.get
events:
- http:
path: wallet/status
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: true
checkAddressMineApi:
handler: src/api/addresses.checkMine
events:
- http:
path: wallet/addresses/check_mine
method: post
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: false
getAddressesApi:
handler: src/api/addresses.get
events:
- http:
path: wallet/addresses
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
index: false
warmup:
walletWarmer:
enabled: true
getNewAddresses:
handler: src/api/newAddresses.get
events:
- http:
path: wallet/addresses/new
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: true
getUtxos:
handler: src/api/txOutputs.getFilteredUtxos
events:
- http:
path: wallet/utxos
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: false
getTxOutputs:
handler: src/api/txOutputs.getFilteredTxOutputs
events:
- http:
path: wallet/tx_outputs
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: false
getBalanceApi:
handler: src/api/balances.get
events:
- http:
path: wallet/balances
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: true
getTokensApi:
handler: src/api/tokens.get
events:
- http:
path: wallet/tokens
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: true
getTokenDetails:
handler: src/api/tokens.getTokenDetails
events:
- http:
path: wallet/tokens/{token_id}/details
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
token_id: true
warmup:
walletWarmer:
enabled: false
getVersionData:
handler: src/api/version.get
events:
- http:
path: version
method: get
cors: true
warmup:
walletWarmer:
enabled: true
getTxHistoryApi:
handler: src/api/txhistory.get
events:
- http:
path: wallet/history
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: true
createTxProposalApi:
handler: src/api/txProposalCreate.create
events:
- http:
path: tx/proposal
method: post
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: false
sendTxProposalApi:
handler: src/api/txProposalSend.send
events:
- http:
path: tx/proposal/{txProposalId}
method: put
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
txProposalId: true
warmup:
walletWarmer:
enabled: false
deleteTxProposalApi:
handler: src/api/txProposalDestroy.destroy
events:
- http:
path: tx/proposal/{txProposalId}
method: delete
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
txProposalId: true
warmup:
walletWarmer:
enabled: false
wsConnect:
handler: src/ws/connection.connect
timeout: 2
events:
- websocket:
route: $connect
- websocket:
route: $disconnect
- websocket:
route: ping
warmup:
walletWarmer:
enabled: false
alarms: # This gets merged with the global alarms
- wsLambdasExecutionDuration
wsJoin:
handler: src/ws/join.handler
timeout: 2
events:
- websocket:
route: join
warmup:
walletWarmer:
enabled: false
alarms:
- wsLambdasExecutionDuration
wsTxNotifyNew:
handler: src/ws/txNotify.onNewTx
timeout: 2
events:
- sqs:
arn:
Fn::GetAtt:
- WalletServiceNewTxQueue
- Arn
batchSize: 1 # Will send every tx to the lambda istead of batching it, this should be tuned when we have more
# users using the wallet-service facade
maximumBatchingWindow: 0 # This is the default value, will wait 0 seconds before calling the lambda
warmup:
walletWarmer:
enabled: false
alarms:
- wsLambdasExecutionDuration
wsTxNotifyUpdate:
handler: src/ws/txNotify.onUpdateTx
timeout: 2
warmup:
walletWarmer:
enabled: false
alarms:
- wsLambdasExecutionDuration
wsAdminBroadcast:
handler: src/ws/admin.broadcast
timeout: 2
warmup:
walletWarmer:
enabled: false
alarms:
- wsLambdasExecutionDuration
wsAdminDisconnect:
handler: src/ws/admin.disconnect
timeout: 2
warmup:
walletWarmer:
enabled: false
alarms:
- wsLambdasExecutionDuration
wsAdminMulticast:
handler: src/ws/admin.multicast
timeout: 2
warmup:
walletWarmer:
enabled: false
alarms:
- wsLambdasExecutionDuration
authTokenApi:
handler: src/api/auth.tokenHandler
timeout: 6
events:
- http:
path: auth/token
method: post
cors: true
warmup:
walletWarmer:
enabled: false
bearerAuthorizer:
handler: src/api/auth.bearerAuthorizer
warmup:
walletWarmer:
enabled: false
metrics:
handler: src/metrics.getMetrics
events:
- http:
path: metrics
method: get
throttling:
maxRequestsPerSecond: 2
maxConcurrentRequests: 2
warmup:
walletWarmer:
enabled: false
pushRegister:
handler: src/api/pushRegister.register
events:
- http:
path: wallet/push/register
method: post
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: false
pushUpdate:
handler: src/api/pushUpdate.update
events:
- http:
path: wallet/push/update
method: put
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
warmup:
walletWarmer:
enabled: false
pushUnregister:
handler: src/api/pushUnregister.unregister
events:
- http:
path: wallet/push/unregister/{deviceId}
method: delete
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
deviceId: true
warmup:
walletWarmer:
enabled: false
getTxById:
handler: src/api/txById.get
events:
- http:
path: wallet/transactions/{txId}
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
txId: true
warmup:
walletWarmer:
enabled: false
proxiedGetTxById:
handler: src/api/fullnodeProxy.getTransactionById
events:
- http:
path: wallet/proxy/transactions/{txId}
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
txId: true
throttling:
maxRequestsPerSecond: 50
warmup:
walletWarmer:
enabled: false
proxiedGetConfirmationData:
handler: src/api/fullnodeProxy.getConfirmationData
events:
- http:
path: wallet/proxy/transactions/{txId}/confirmation_data
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
request:
parameters:
paths:
txId: true
throttling:
maxRequestsPerSecond: 10
warmup:
walletWarmer:
enabled: false
proxiedGraphvizNeighborsQuery:
handler: src/api/fullnodeProxy.queryGraphvizNeighbours
events:
- http:
path: wallet/proxy/graphviz/neighbours
method: get
cors: true
authorizer: ${self:custom.authorizer.walletBearer}
throttling:
maxRequestsPerSecond: 20
warmup:
walletWarmer:
enabled: false
sendNotificationToDevice:
handler: src/api/pushSendNotificationToDevice.send
warmup:
walletWarmer:
enabled: false
txPushRequested:
handler: src/api/txPushNotificationRequested.handleRequest
warmup:
walletWarmer:
enabled: false
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
Resource:
Fn::GetAtt: [ SendNotificationToDeviceLambdaFunction , Arn ]
deleteStalePushDevices:
handler: src/db/cronRoutines.cleanStalePushDevices
events:
- schedule: cron(17 3 */15 * ? *) # run every 15 days at 3:17 (GMT)
warmup:
walletWarmer:
enabled: false
cleanUnsentTxProposalsUtxos:
handler: src/db/cronRoutines.cleanUnsentTxProposalsUtxos
timeout: 60 # 1 minute
events:
- schedule: cron(*/5 * * * ? *) # run every 5 minutes
warmup:
walletWarmer:
enabled: false
alarms:
- cleanTxProposalsUtxosDuration