Skip to content

Commit

Permalink
fix(connector-besu): do not crash if ledger unreachable - send HTTP 503
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ruzell22 committed Nov 4, 2024
1 parent 35f31fa commit 47b1645
Show file tree
Hide file tree
Showing 11 changed files with 597 additions and 31 deletions.
13 changes: 13 additions & 0 deletions .yarn/patches/web3-eth-accounts-npm-1.6.1-c95f31ca81.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/lib/index.js b/lib/index.js
index de2853c247b334e6b22cee42b3e597281c44efdc..787aecf6758228c092f1a3cd8097f64e76cc573d 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -344,7 +344,7 @@ function _handleTxPricing(_this, tx) {
throw Error("Network doesn't support eip-1559");
resolve({ gasPrice });
}
- });
+ }).catch((ex) => reject(ex));
}
}
catch (error) {
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"ws": ">=1.1.5",
"xml2js": ">=0.5.0",
"yargs-parser": ">=18.1.1",
"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",
"zod": ">=3.22.3"
},
"devDependencies": {
Expand Down
157 changes: 157 additions & 0 deletions packages/cactus-common/src/main/typescript/http/http-header.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/**
* A list of well-known headers as published on Wikipedia.
* @see https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
*
* TODO Finish documenting each enum item and make sure to also include
* the examples provided on the linked Wikipedia page above. The first
* few headers are documented this way but we need all of them like that.
*
* TODO Ensure that there are no typos in the header names.
*/
export enum HttpHeader {
// Standard request fields

/**
* Acceptable instance-manipulations for the request.
* @example A-IM: feed
* @see https://datatracker.ietf.org/doc/html/rfc3229
*/
A_IM = "A-IM",
/**
* Media type(s) that is/are acceptable for the response. See Content negotiation.
* @example Accept: text/html
* @see https://datatracker.ietf.org/doc/html/rfc9110
*/
Accept = "Accept",
/**
* Character sets that are acceptable.
* @example Accept-Charset: utf-8
* @see https://datatracker.ietf.org/doc/html/rfc9110
*/
AcceptCharset = "Accept-Charset",
/**
* Acceptable version in time.
* @example Accept-Datetime: Thu, 31 May 2007 20:35:00 GMT
* @see https://datatracker.ietf.org/doc/html/rfc7089
*/
AcceptDatetime = "Accept-Datetime",
AcceptEncoding = "Accept-Encoding",
AcceptLanguage = "Accept-Language",
AccessControlAllowOrigin = "Access-Control-Allow-Origin",
AccessControlAllowCredentials = "Access-Control-Allow-Credentials",
AccessControlExposeHeaders = "Access-Control-Expose-Headers",
AccessControlMaxAge = "Access-Control-Max-Age",
AccessControlAllowMethods = "Access-Control-Allow-Methods",
AccessControlAllowHeaders = "Access-Control-Allow-Headers",
Authorization = "Authorization",
CacheControl = "Cache-Control",
Connection = "Connection",
ContentDisposition = "Content-Disposition",
ContentEncoding = "Content-Encoding",
ContentLength = "Content-Length",
ContentLocation = "Content-Location",
ContentMD5 = "Content-MD5",
ContentType = "Content-Type",
Cookie = "Cookie",
Date = "Date",
Expect = "Expect",
Forwarded = "Forwarded",
From = "From",
Host = "Host",
IfMatch = "If-Match",
IfModifiedSince = "If-Modified-Since",
IfNoneMatch = "If-None-Match",
IfRange = "If-Range",
IfUnmodifiedSince = "If-Unmodified-Since",
MaxForwards = "Max-Forwards",
Origin = "Origin",
Pragma = "Pragma",
Prefer = "Prefer",
ProxyAuthorization = "Proxy-Authorization",
Range = "Range",
Referer = "Referer",
TE = "TE",
Trailer = "Trailer",
TransferEncoding = "Transfer-Encoding",
Upgrade = "Upgrade",
UserAgent = "User-Agent",

// Common non-standard request fields
UpgradeInsecureRequests = "Upgrade-Insecure-Requests",
XRequestedWith = "X-Requested-With",
DNT = "DNT",
XForwardedFor = "X-Forwarded-For",
XForwardedHost = "X-Forwarded-Host",
XForwardedProto = "X-Forwarded-Proto",
FrontEndHttps = "Front-End-Https",
XHttpMethodOverride = "X-Http-Method-Override",
XAttDeviceId = "X-Att-DeviceId",
XWapProfile = "X-Wap-Profile",
ProxyConnection = "Proxy-Connection",
XUIDH = "X-UIDH",
XCsrfToken = "X-Csrf-Token",
XRequestId = "X-Request-ID", // Alternative X-Request-Id
CorrelationId = "X-Correlation-ID", // Alternative Correlation-ID
SaveData = "Save-Data",
SecGpc = "Sec-GPC",

// Standard response fields
AcceptCH = "Accept-CH",
AcceptPatch = "Accept-Patch",
AltSvc = "Alt-Svc",
Age = "Age",
Allow = "Allow",
Expires = "Expires",
IM = "IM",
LastModified = "Last-Modified",
Link = "Link",
Location = "Location",
P3P = "P3P",
ProxyAuthenticate = "Proxy-Authenticate",
PublicKeyPins = "Public-Key-Pins",
/**
* f an entity is temporarily unavailable, this instructs the client
* to try again later. Value could be a specified period of time
* (in seconds) or a HTTP-date.
*
* There are two accepted formats when it comes to the values of the header:
* ```http
* Retry-After: <http-date>
* Retry-After: <delay-seconds>
* ```
*
* `<http-date>`
* A date after which to retry. See the Date header for more details on the HTTP date format.
*
* `<delay-seconds>`
* A non-negative decimal integer indicating the seconds to delay after the response is received.
*
* @example Retry-After: 120
* @example Retry-After: Fri, 07 Nov 2014 23:59:59 GMT
*
* @see https://datatracker.ietf.org/doc/html/rfc9110#section-10.2.3
*/
RetryAfter = "Retry-After",
Server = "Server",
SetCookie = "Set-Cookie",
StrictTransportSecurity = "Strict-Transport-Security",
Tk = "Tk",
Vary = "Vary",
Via = "Via", // Same as request field
/**
* Indicates the authentication scheme that should be used to access the requested entity.
* @example WWW-Authenticate: Basic
* @see https://datatracker.ietf.org/doc/html/rfc9110
*/
WWWAuthenticate = "WWW-Authenticate",
XFrameOptions = "X-Frame-Options",

// Common non-standard response fields
ContentSecurityPolicy = "Content-Security-Policy",
ExpectCT = "Expect-CT",
NEL = "NEL",
PermissionsPolicy = "Permissions-Policy",
Refresh = "Refresh",
ReportTo = "Report-To",
Timing_Allow_Origin = "Timing-Allow-Origin",
}
2 changes: 2 additions & 0 deletions packages/cactus-common/src/main/typescript/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ export {
} from "./http/express-http-verb-method-name";

export { isGrpcStatusObjectWithCode } from "./grpc/is-grpc-status-object-with-code";

export { HttpHeader } from "./http/http-header";
6 changes: 4 additions & 2 deletions packages/cactus-plugin-ledger-connector-besu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"web3-eth": "1.6.1",
"web3-eth-contract": "1.6.1",
"web3-utils": "1.6.1",
"web3js-quorum": "22.4.0"
"web3js-quorum": "22.4.0",
"websocket-event-codes": "1.1.0"
},
"devDependencies": {
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0",
Expand All @@ -105,7 +106,8 @@
"tsx": "4.16.2",
"uuid": "10.0.0",
"web3-core": "1.6.1",
"web3-eth": "1.6.1"
"web3-eth": "1.6.1",
"web3-eth-accounts": "patch:web3-eth-accounts@npm%3A1.6.1#~/.yarn/patches/web3-eth-accounts-npm-1.6.1-c95f31ca81.patch"
},
"engines": {
"node": ">=18",
Expand Down
Loading

0 comments on commit 47b1645

Please sign in to comment.