Skip to content

Commit 394323e

Browse files
ruzell22petermetz
authored andcommitted
fix(connector-besu): do not crash if ledger unreachable - send HTTP 503
Primary Changes --------------- 1. Yarn patch to [email protected] so that it does not crash nodejs process Without the catch block, the rejection is an unhandled rejection that bubbles up to the top of the callstack where NodeJS itself catches it and then crashes the entire process. (used to be that it just logged a warning but since some of the newer versions it crashes which allows us to find these bugs in our code / library's code) 2. It is returning a 503 instead of a 500 3. Added a static retry-after header value of 5 seconds 4. Added test case in test-ledger which has run-transaction at the end that is expected to give error 503 when the backing ledger is unavailable Fixes: #3406 Co-authored-by: Peter Somogyvari <[email protected]> Signed-off-by: ruzell22 <[email protected]> Signed-off-by: Peter Somogyvari <[email protected]>
1 parent 4424bf9 commit 394323e

File tree

24 files changed

+1311
-173
lines changed

24 files changed

+1311
-173
lines changed

.cspell.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
"trivyignores",
203203
"txid",
204204
"txqueue",
205+
"UIDH",
205206
"Uisrs",
206207
"undici",
207208
"unixfs",
@@ -214,7 +215,8 @@
214215
"websocat",
215216
"WSPROVIDER",
216217
"Xdai",
217-
"xeipuuv"
218+
"xeipuuv",
219+
"XUIDH"
218220
],
219221
"dictionaries": [
220222
"typescript,node,npm,go,rust"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/lib/index.js b/lib/index.js
2+
index de2853c247b334e6b22cee42b3e597281c44efdc..787aecf6758228c092f1a3cd8097f64e76cc573d 100644
3+
--- a/lib/index.js
4+
+++ b/lib/index.js
5+
@@ -344,7 +344,7 @@ function _handleTxPricing(_this, tx) {
6+
throw Error("Network doesn't support eip-1559");
7+
resolve({ gasPrice });
8+
}
9+
- });
10+
+ }).catch((ex) => reject(ex));
11+
}
12+
}
13+
catch (error) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"ws": ">=1.1.5",
120120
"xml2js": ">=0.5.0",
121121
"yargs-parser": ">=18.1.1",
122+
"web3-eth-accounts@npm:1.6.1": "patch:web3-eth-accounts@npm%3A1.6.1#~/.yarn/patches/web3-eth-accounts-npm-1.6.1-c95f31ca81.patch",
122123
"zod": ">=3.22.3"
123124
},
124125
"devDependencies": {
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* A list of well-known headers as published on Wikipedia.
3+
* @see https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
4+
*
5+
* TODO Finish documenting each enum item and make sure to also include
6+
* the examples provided on the linked Wikipedia page above. The first
7+
* few headers are documented this way but we need all of them like that.
8+
*
9+
* TODO Ensure that there are no typos in the header names.
10+
*/
11+
export enum HttpHeader {
12+
// Standard request fields
13+
14+
/**
15+
* Acceptable instance-manipulations for the request.
16+
* @example A-IM: feed
17+
* @see https://datatracker.ietf.org/doc/html/rfc3229
18+
*/
19+
A_IM = "A-IM",
20+
/**
21+
* Media type(s) that is/are acceptable for the response. See Content negotiation.
22+
* @example Accept: text/html
23+
* @see https://datatracker.ietf.org/doc/html/rfc9110
24+
*/
25+
Accept = "Accept",
26+
/**
27+
* Character sets that are acceptable.
28+
* @example Accept-Charset: utf-8
29+
* @see https://datatracker.ietf.org/doc/html/rfc9110
30+
*/
31+
AcceptCharset = "Accept-Charset",
32+
/**
33+
* Acceptable version in time.
34+
* @example Accept-Datetime: Thu, 31 May 2007 20:35:00 GMT
35+
* @see https://datatracker.ietf.org/doc/html/rfc7089
36+
*/
37+
AcceptDatetime = "Accept-Datetime",
38+
AcceptEncoding = "Accept-Encoding",
39+
AcceptLanguage = "Accept-Language",
40+
AccessControlAllowOrigin = "Access-Control-Allow-Origin",
41+
AccessControlAllowCredentials = "Access-Control-Allow-Credentials",
42+
AccessControlExposeHeaders = "Access-Control-Expose-Headers",
43+
AccessControlMaxAge = "Access-Control-Max-Age",
44+
AccessControlAllowMethods = "Access-Control-Allow-Methods",
45+
AccessControlAllowHeaders = "Access-Control-Allow-Headers",
46+
Authorization = "Authorization",
47+
CacheControl = "Cache-Control",
48+
Connection = "Connection",
49+
ContentDisposition = "Content-Disposition",
50+
ContentEncoding = "Content-Encoding",
51+
ContentLength = "Content-Length",
52+
ContentLocation = "Content-Location",
53+
ContentMD5 = "Content-MD5",
54+
ContentType = "Content-Type",
55+
Cookie = "Cookie",
56+
Date = "Date",
57+
Expect = "Expect",
58+
Forwarded = "Forwarded",
59+
From = "From",
60+
Host = "Host",
61+
IfMatch = "If-Match",
62+
IfModifiedSince = "If-Modified-Since",
63+
IfNoneMatch = "If-None-Match",
64+
IfRange = "If-Range",
65+
IfUnmodifiedSince = "If-Unmodified-Since",
66+
MaxForwards = "Max-Forwards",
67+
Origin = "Origin",
68+
Pragma = "Pragma",
69+
Prefer = "Prefer",
70+
ProxyAuthorization = "Proxy-Authorization",
71+
Range = "Range",
72+
Referer = "Referer",
73+
TE = "TE",
74+
Trailer = "Trailer",
75+
TransferEncoding = "Transfer-Encoding",
76+
Upgrade = "Upgrade",
77+
UserAgent = "User-Agent",
78+
79+
// Common non-standard request fields
80+
UpgradeInsecureRequests = "Upgrade-Insecure-Requests",
81+
XRequestedWith = "X-Requested-With",
82+
DNT = "DNT",
83+
XForwardedFor = "X-Forwarded-For",
84+
XForwardedHost = "X-Forwarded-Host",
85+
XForwardedProto = "X-Forwarded-Proto",
86+
FrontEndHttps = "Front-End-Https",
87+
XHttpMethodOverride = "X-Http-Method-Override",
88+
XAttDeviceId = "X-Att-DeviceId",
89+
XWapProfile = "X-Wap-Profile",
90+
ProxyConnection = "Proxy-Connection",
91+
XUIDH = "X-UIDH",
92+
XCsrfToken = "X-Csrf-Token",
93+
XRequestId = "X-Request-ID", // Alternative X-Request-Id
94+
CorrelationId = "X-Correlation-ID", // Alternative Correlation-ID
95+
SaveData = "Save-Data",
96+
SecGpc = "Sec-GPC",
97+
98+
// Standard response fields
99+
AcceptCH = "Accept-CH",
100+
AcceptPatch = "Accept-Patch",
101+
AltSvc = "Alt-Svc",
102+
Age = "Age",
103+
Allow = "Allow",
104+
Expires = "Expires",
105+
IM = "IM",
106+
LastModified = "Last-Modified",
107+
Link = "Link",
108+
Location = "Location",
109+
P3P = "P3P",
110+
ProxyAuthenticate = "Proxy-Authenticate",
111+
PublicKeyPins = "Public-Key-Pins",
112+
/**
113+
* f an entity is temporarily unavailable, this instructs the client
114+
* to try again later. Value could be a specified period of time
115+
* (in seconds) or a HTTP-date.
116+
*
117+
* There are two accepted formats when it comes to the values of the header:
118+
* ```http
119+
* Retry-After: <http-date>
120+
* Retry-After: <delay-seconds>
121+
* ```
122+
*
123+
* `<http-date>`
124+
* A date after which to retry. See the Date header for more details on the HTTP date format.
125+
*
126+
* `<delay-seconds>`
127+
* A non-negative decimal integer indicating the seconds to delay after the response is received.
128+
*
129+
* @example Retry-After: 120
130+
* @example Retry-After: Fri, 07 Nov 2014 23:59:59 GMT
131+
*
132+
* @see https://datatracker.ietf.org/doc/html/rfc9110#section-10.2.3
133+
*/
134+
RetryAfter = "Retry-After",
135+
Server = "Server",
136+
SetCookie = "Set-Cookie",
137+
StrictTransportSecurity = "Strict-Transport-Security",
138+
Tk = "Tk",
139+
Vary = "Vary",
140+
Via = "Via", // Same as request field
141+
/**
142+
* Indicates the authentication scheme that should be used to access the requested entity.
143+
* @example WWW-Authenticate: Basic
144+
* @see https://datatracker.ietf.org/doc/html/rfc9110
145+
*/
146+
WWWAuthenticate = "WWW-Authenticate",
147+
XFrameOptions = "X-Frame-Options",
148+
149+
// Common non-standard response fields
150+
ContentSecurityPolicy = "Content-Security-Policy",
151+
ExpectCT = "Expect-CT",
152+
NEL = "NEL",
153+
PermissionsPolicy = "Permissions-Policy",
154+
Refresh = "Refresh",
155+
ReportTo = "Report-To",
156+
Timing_Allow_Origin = "Timing-Allow-Origin",
157+
}

packages/cactus-common/src/main/typescript/public-api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ export {
4747
} from "./http/express-http-verb-method-name";
4848

4949
export { isGrpcStatusObjectWithCode } from "./grpc/is-grpc-status-object-with-code";
50+
51+
export { HttpHeader } from "./http/http-header";

packages/cactus-plugin-ledger-connector-besu/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@
8080
"web3-eth": "1.6.1",
8181
"web3-eth-contract": "1.6.1",
8282
"web3-utils": "1.6.1",
83-
"web3js-quorum": "22.4.0"
83+
"web3js-quorum": "22.4.0",
84+
"websocket-event-codes": "1.1.0"
8485
},
8586
"devDependencies": {
8687
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0",
@@ -105,7 +106,8 @@
105106
"tsx": "4.16.2",
106107
"uuid": "10.0.0",
107108
"web3-core": "1.6.1",
108-
"web3-eth": "1.6.1"
109+
"web3-eth": "1.6.1",
110+
"web3-eth-accounts": "patch:web3-eth-accounts@npm%3A1.6.1#~/.yarn/patches/web3-eth-accounts-npm-1.6.1-c95f31ca81.patch"
109111
},
110112
"engines": {
111113
"node": ">=18",

packages/cactus-plugin-ledger-connector-besu/src/main/go/generated/openapi/go-client/.openapi-generator/FILES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ client.go
66
configuration.go
77
go.mod
88
go.sum
9+
model_backing_ledger_unavailable_error.go
910
model_besu_private_transaction_config.go
1011
model_besu_transaction_config.go
1112
model_besu_transaction_config_to.go

packages/cactus-plugin-ledger-connector-besu/src/main/go/generated/openapi/go-client/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Class | Method | HTTP request | Description
9393

9494
## Documentation For Models
9595

96+
- [BackingLedgerUnavailableError](docs/BackingLedgerUnavailableError.md)
9697
- [BesuPrivateTransactionConfig](docs/BesuPrivateTransactionConfig.md)
9798
- [BesuTransactionConfig](docs/BesuTransactionConfig.md)
9899
- [BesuTransactionConfigTo](docs/BesuTransactionConfigTo.md)

0 commit comments

Comments
 (0)