Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connector-besu): do not crash if ledger unreachable - send HTTP 503 #3573

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Comment on lines +1 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide more details about this (in commit & PR message). In particular:

  • Link to an issue reported on web3js repository
  • What this patch does
  • Why we need this, what will happen if we remove it (specific scenario).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruzell22 +1 to the above, this should be explained in detail.
@outSH I wrote the code, here's the answer that @ruzell22 can copy paste into the PR description and the commit message: 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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petermetz this is a nice learning! (Never knew that we can patch and include packages this way as well)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jagpreetsinghsasan Yeah, it's very useful when you need it. :-)

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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-rc.5",
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
Loading