diff --git a/.pnp.cjs b/.pnp.cjs index d25d4593be4..6a5c27c049f 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -2515,6 +2515,60 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["@cbor-extract/cbor-extract-darwin-arm64", [\ + ["npm:2.2.0", {\ + "packageLocation": "./.yarn/unplugged/@cbor-extract-cbor-extract-darwin-arm64-npm-2.2.0-11327a5a22/node_modules/@cbor-extract/cbor-extract-darwin-arm64/",\ + "packageDependencies": [\ + ["@cbor-extract/cbor-extract-darwin-arm64", "npm:2.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ + ["@cbor-extract/cbor-extract-darwin-x64", [\ + ["npm:2.2.0", {\ + "packageLocation": "./.yarn/unplugged/@cbor-extract-cbor-extract-darwin-x64-npm-2.2.0-fa1def18ac/node_modules/@cbor-extract/cbor-extract-darwin-x64/",\ + "packageDependencies": [\ + ["@cbor-extract/cbor-extract-darwin-x64", "npm:2.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ + ["@cbor-extract/cbor-extract-linux-arm", [\ + ["npm:2.2.0", {\ + "packageLocation": "./.yarn/unplugged/@cbor-extract-cbor-extract-linux-arm-npm-2.2.0-7117e8edac/node_modules/@cbor-extract/cbor-extract-linux-arm/",\ + "packageDependencies": [\ + ["@cbor-extract/cbor-extract-linux-arm", "npm:2.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ + ["@cbor-extract/cbor-extract-linux-arm64", [\ + ["npm:2.2.0", {\ + "packageLocation": "./.yarn/unplugged/@cbor-extract-cbor-extract-linux-arm64-npm-2.2.0-4f85f696e6/node_modules/@cbor-extract/cbor-extract-linux-arm64/",\ + "packageDependencies": [\ + ["@cbor-extract/cbor-extract-linux-arm64", "npm:2.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ + ["@cbor-extract/cbor-extract-linux-x64", [\ + ["npm:2.2.0", {\ + "packageLocation": "./.yarn/unplugged/@cbor-extract-cbor-extract-linux-x64-npm-2.2.0-93e9fdc4a6/node_modules/@cbor-extract/cbor-extract-linux-x64/",\ + "packageDependencies": [\ + ["@cbor-extract/cbor-extract-linux-x64", "npm:2.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ + ["@cbor-extract/cbor-extract-win32-x64", [\ + ["npm:2.2.0", {\ + "packageLocation": "./.yarn/unplugged/@cbor-extract-cbor-extract-win32-x64-npm-2.2.0-7cdd589d64/node_modules/@cbor-extract/cbor-extract-win32-x64/",\ + "packageDependencies": [\ + ["@cbor-extract/cbor-extract-win32-x64", "npm:2.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["@colors/colors", [\ ["npm:1.5.0", {\ "packageLocation": "./.yarn/cache/@colors-colors-npm-1.5.0-875af3a8b4-9d226461c1.zip/node_modules/@colors/colors/",\ @@ -2599,6 +2653,7 @@ const RAW_RUNTIME_STATE = ["ajv", "npm:8.12.0"],\ ["bs58", "npm:4.0.1"],\ ["cbor", "npm:8.1.0"],\ + ["cbor-x", "npm:1.5.9"],\ ["chai", "npm:4.3.10"],\ ["chai-as-promised", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:7.1.1"],\ ["dirty-chai", "virtual:e2d057e7cc143d3cb9bec864f4a2d862441b5a09f81f8e6c46e7a098cbc89e4d07017cc6e2e2142d5704bb55da853cbec2d025ebc0b30e8696c31380c00f2c7d#npm:2.0.1"],\ @@ -7204,6 +7259,33 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["cbor-extract", [\ + ["npm:2.2.0", {\ + "packageLocation": "./.yarn/unplugged/cbor-extract-npm-2.2.0-6c1f6274a3/node_modules/cbor-extract/",\ + "packageDependencies": [\ + ["cbor-extract", "npm:2.2.0"],\ + ["@cbor-extract/cbor-extract-darwin-arm64", "npm:2.2.0"],\ + ["@cbor-extract/cbor-extract-darwin-x64", "npm:2.2.0"],\ + ["@cbor-extract/cbor-extract-linux-arm", "npm:2.2.0"],\ + ["@cbor-extract/cbor-extract-linux-arm64", "npm:2.2.0"],\ + ["@cbor-extract/cbor-extract-linux-x64", "npm:2.2.0"],\ + ["@cbor-extract/cbor-extract-win32-x64", "npm:2.2.0"],\ + ["node-gyp", "npm:10.0.1"],\ + ["node-gyp-build-optional-packages", "npm:5.1.1"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ + ["cbor-x", [\ + ["npm:1.5.9", {\ + "packageLocation": "./.yarn/cache/cbor-x-npm-1.5.9-33c037d606-69da4bbaed.zip/node_modules/cbor-x/",\ + "packageDependencies": [\ + ["cbor-x", "npm:1.5.9"],\ + ["cbor-extract", "npm:2.2.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["chai", [\ ["npm:4.3.10", {\ "packageLocation": "./.yarn/cache/chai-npm-4.3.10-96f52a35f0-9e545fd60f.zip/node_modules/chai/",\ @@ -8885,6 +8967,15 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["detect-libc", [\ + ["npm:2.0.3", {\ + "packageLocation": "./.yarn/cache/detect-libc-npm-2.0.3-2ddae34945-b4ea018d62.zip/node_modules/detect-libc/",\ + "packageDependencies": [\ + ["detect-libc", "npm:2.0.3"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["dezalgo", [\ ["npm:1.0.3", {\ "packageLocation": "./.yarn/cache/dezalgo-npm-1.0.3-e2bc978ebd-960f4b6230.zip/node_modules/dezalgo/",\ @@ -14508,6 +14599,16 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["node-gyp-build-optional-packages", [\ + ["npm:5.1.1", {\ + "packageLocation": "./.yarn/cache/node-gyp-build-optional-packages-npm-5.1.1-ff11e179dd-96dbeeba03.zip/node_modules/node-gyp-build-optional-packages/",\ + "packageDependencies": [\ + ["node-gyp-build-optional-packages", "npm:5.1.1"],\ + ["detect-libc", "npm:2.0.3"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["node-inspect-extracted", [\ ["npm:1.0.8", {\ "packageLocation": "./.yarn/cache/node-inspect-extracted-npm-1.0.8-53baa7fd4f-4647a29afd.zip/node_modules/node-inspect-extracted/",\ diff --git a/.yarn/cache/@cbor-extract-cbor-extract-darwin-arm64-npm-2.2.0-11327a5a22-10.zip b/.yarn/cache/@cbor-extract-cbor-extract-darwin-arm64-npm-2.2.0-11327a5a22-10.zip new file mode 100644 index 00000000000..c802a3c1cbc Binary files /dev/null and b/.yarn/cache/@cbor-extract-cbor-extract-darwin-arm64-npm-2.2.0-11327a5a22-10.zip differ diff --git a/.yarn/cache/cbor-extract-npm-2.2.0-6c1f6274a3-c23bb69059.zip b/.yarn/cache/cbor-extract-npm-2.2.0-6c1f6274a3-c23bb69059.zip new file mode 100644 index 00000000000..6934a030109 Binary files /dev/null and b/.yarn/cache/cbor-extract-npm-2.2.0-6c1f6274a3-c23bb69059.zip differ diff --git a/.yarn/cache/cbor-x-npm-1.5.9-33c037d606-69da4bbaed.zip b/.yarn/cache/cbor-x-npm-1.5.9-33c037d606-69da4bbaed.zip new file mode 100644 index 00000000000..6a3ba2da13e Binary files /dev/null and b/.yarn/cache/cbor-x-npm-1.5.9-33c037d606-69da4bbaed.zip differ diff --git a/.yarn/cache/detect-libc-npm-2.0.3-2ddae34945-b4ea018d62.zip b/.yarn/cache/detect-libc-npm-2.0.3-2ddae34945-b4ea018d62.zip new file mode 100644 index 00000000000..46f4bae9475 Binary files /dev/null and b/.yarn/cache/detect-libc-npm-2.0.3-2ddae34945-b4ea018d62.zip differ diff --git a/.yarn/cache/node-gyp-build-optional-packages-npm-5.1.1-ff11e179dd-96dbeeba03.zip b/.yarn/cache/node-gyp-build-optional-packages-npm-5.1.1-ff11e179dd-96dbeeba03.zip new file mode 100644 index 00000000000..f61b29a0239 Binary files /dev/null and b/.yarn/cache/node-gyp-build-optional-packages-npm-5.1.1-ff11e179dd-96dbeeba03.zip differ diff --git a/packages/dapi/lib/MasternodeListSync.js b/packages/dapi/lib/MasternodeListSync.js index 1793c42c5e4..48928fdf1bf 100644 --- a/packages/dapi/lib/MasternodeListSync.js +++ b/packages/dapi/lib/MasternodeListSync.js @@ -1,5 +1,5 @@ const EventEmitter = require('events'); -const cbor = require('cbor'); +const { Encoder } = require('cbor-x'); const logger = require('./logger'); const NULL_HASH = '0000000000000000000000000000000000000000000000000000000000000000'; @@ -43,6 +43,11 @@ class MasternodeListSync extends EventEmitter { */ network; + /** + * @type {Encoder} + */ + #cborEncoder; + /** * @param {CoreRpcClient} coreRpc * @param {ChainDataProvider} chainDataProvider @@ -57,6 +62,7 @@ class MasternodeListSync extends EventEmitter { this.logger = logger.child({ service: 'MasternodeListSync', }); + this.#cborEncoder = new Encoder({ pack: true }); this.setMaxListeners(1000); } @@ -76,7 +82,7 @@ class MasternodeListSync extends EventEmitter { // design it's impossible to deserialize it back without knowing of the protocol version. // In future, we want to switch to Rust implementation of SML so we don't want to spend // time on fixing this issue in JS dashcore-lib - this.fullDiffBuffer = await cbor.encodeAsync(fullDiffObject); + this.fullDiffBuffer = this.#cborEncoder.encode(fullDiffObject); this.blockHeight = blockHeight; this.blockHash = blockHash; @@ -96,7 +102,7 @@ class MasternodeListSync extends EventEmitter { // design it's impossible to deserialize it back without knowing of the protocol version. // In future, we want to switch to Rust implementation of SML so we don't want to spend // time on fixing this issue in JS dashcore-lib - const diffBuffer = await cbor.encodeAsync(diffObject); + const diffBuffer = this.#cborEncoder.encode(diffObject); this.logger.debug({ previousBlockHash, diff --git a/packages/dapi/package.json b/packages/dapi/package.json index 742637b2969..1e2235e554e 100644 --- a/packages/dapi/package.json +++ b/packages/dapi/package.json @@ -44,6 +44,7 @@ "ajv": "^8.6.0", "bs58": "^4.0.1", "cbor": "^8.0.0", + "cbor-x": "^1.5.9", "dotenv": "^8.6.0", "dotenv-expand": "^5.1.0", "dotenv-safe": "^8.2.0", diff --git a/yarn.lock b/yarn.lock index 38844ad76ac..887a6da7f9f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1405,6 +1405,48 @@ __metadata: languageName: node linkType: hard +"@cbor-extract/cbor-extract-darwin-arm64@npm:2.2.0": + version: 2.2.0 + resolution: "@cbor-extract/cbor-extract-darwin-arm64@npm:2.2.0" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"@cbor-extract/cbor-extract-darwin-x64@npm:2.2.0": + version: 2.2.0 + resolution: "@cbor-extract/cbor-extract-darwin-x64@npm:2.2.0" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"@cbor-extract/cbor-extract-linux-arm64@npm:2.2.0": + version: 2.2.0 + resolution: "@cbor-extract/cbor-extract-linux-arm64@npm:2.2.0" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + +"@cbor-extract/cbor-extract-linux-arm@npm:2.2.0": + version: 2.2.0 + resolution: "@cbor-extract/cbor-extract-linux-arm@npm:2.2.0" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + +"@cbor-extract/cbor-extract-linux-x64@npm:2.2.0": + version: 2.2.0 + resolution: "@cbor-extract/cbor-extract-linux-x64@npm:2.2.0" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + +"@cbor-extract/cbor-extract-win32-x64@npm:2.2.0": + version: 2.2.0 + resolution: "@cbor-extract/cbor-extract-win32-x64@npm:2.2.0" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@colors/colors@npm:1.5.0": version: 1.5.0 resolution: "@colors/colors@npm:1.5.0" @@ -1561,6 +1603,7 @@ __metadata: ajv: "npm:^8.6.0" bs58: "npm:^4.0.1" cbor: "npm:^8.0.0" + cbor-x: "npm:^1.5.9" chai: "npm:^4.3.10" chai-as-promised: "npm:^7.1.1" dirty-chai: "npm:^2.0.1" @@ -5217,6 +5260,49 @@ __metadata: languageName: node linkType: hard +"cbor-extract@npm:^2.2.0": + version: 2.2.0 + resolution: "cbor-extract@npm:2.2.0" + dependencies: + "@cbor-extract/cbor-extract-darwin-arm64": "npm:2.2.0" + "@cbor-extract/cbor-extract-darwin-x64": "npm:2.2.0" + "@cbor-extract/cbor-extract-linux-arm": "npm:2.2.0" + "@cbor-extract/cbor-extract-linux-arm64": "npm:2.2.0" + "@cbor-extract/cbor-extract-linux-x64": "npm:2.2.0" + "@cbor-extract/cbor-extract-win32-x64": "npm:2.2.0" + node-gyp: "npm:latest" + node-gyp-build-optional-packages: "npm:5.1.1" + dependenciesMeta: + "@cbor-extract/cbor-extract-darwin-arm64": + optional: true + "@cbor-extract/cbor-extract-darwin-x64": + optional: true + "@cbor-extract/cbor-extract-linux-arm": + optional: true + "@cbor-extract/cbor-extract-linux-arm64": + optional: true + "@cbor-extract/cbor-extract-linux-x64": + optional: true + "@cbor-extract/cbor-extract-win32-x64": + optional: true + bin: + download-cbor-prebuilds: bin/download-prebuilds.js + checksum: c23bb69059407c1d7847d4347e9453336d0f1dfe0c82cf4cb0e91a48feb7d2ea453244b2b5823f7fe7e699745a29bab44fcb5e341fa940d290fab41a970db3ba + languageName: node + linkType: hard + +"cbor-x@npm:^1.5.9": + version: 1.5.9 + resolution: "cbor-x@npm:1.5.9" + dependencies: + cbor-extract: "npm:^2.2.0" + dependenciesMeta: + cbor-extract: + optional: true + checksum: 69da4bbaed47094e90dd41585f57e9ca29fbb99147ea30927d649038b8fc9204f220120bdfb7e9bd2af4d4790e3ff565b3fa0dcee3e7dab722dc93fcc7d54f6f + languageName: node + linkType: hard + "cbor@npm:^8.0.0": version: 8.1.0 resolution: "cbor@npm:8.1.0" @@ -6631,6 +6717,13 @@ __metadata: languageName: node linkType: hard +"detect-libc@npm:^2.0.1": + version: 2.0.3 + resolution: "detect-libc@npm:2.0.3" + checksum: b4ea018d623e077bd395f168a9e81db77370dde36a5b01d067f2ad7989924a81d31cb547ff764acb2aa25d50bb7fdde0b0a93bec02212b0cb430621623246d39 + languageName: node + linkType: hard + "dezalgo@npm:^1.0.0": version: 1.0.3 resolution: "dezalgo@npm:1.0.3" @@ -11349,6 +11442,19 @@ __metadata: languageName: node linkType: hard +"node-gyp-build-optional-packages@npm:5.1.1": + version: 5.1.1 + resolution: "node-gyp-build-optional-packages@npm:5.1.1" + dependencies: + detect-libc: "npm:^2.0.1" + bin: + node-gyp-build-optional-packages: bin.js + node-gyp-build-optional-packages-optional: optional.js + node-gyp-build-optional-packages-test: build-test.js + checksum: 96dbeeba03fe5b9e86e1dc4491d7932cbf4c23f4ef8e63fb83bbbdcaf4553d8cbd5f23b9bc3632cb76a0739524f4b64f829daa5b608ebd72285ffdb03a9bdd81 + languageName: node + linkType: hard + "node-gyp-build@npm:^4.3.0": version: 4.3.0 resolution: "node-gyp-build@npm:4.3.0"