Skip to content

Commit

Permalink
chore: use packed cbor
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jul 23, 2024
1 parent 21b6b95 commit 2c94ad5
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 3 deletions.
101 changes: 101 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 9 additions & 3 deletions packages/dapi/lib/MasternodeListSync.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -43,6 +43,11 @@ class MasternodeListSync extends EventEmitter {
*/
network;

/**
* @type {Encoder}
*/
#cborEncoder;

/**
* @param {CoreRpcClient} coreRpc
* @param {ChainDataProvider} chainDataProvider
Expand All @@ -57,6 +62,7 @@ class MasternodeListSync extends EventEmitter {
this.logger = logger.child({
service: 'MasternodeListSync',
});
this.#cborEncoder = new Encoder({ pack: true });

this.setMaxListeners(1000);
}
Expand All @@ -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;

Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/dapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
106 changes: 106 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2c94ad5

Please sign in to comment.