@ethersphere/bee-js 9.1.2 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/utils/size.js +6 -0
- package/dist/cjs/utils/stamps.js +33 -33
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/utils/size.js +6 -0
- package/dist/mjs/utils/stamps.js +16 -22
- package/dist/types/utils/size.d.ts +2 -0
- package/package.json +1 -1
package/dist/mjs/utils/size.js
CHANGED
|
@@ -16,6 +16,12 @@ export class Size {
|
|
|
16
16
|
static fromBytes(bytes) {
|
|
17
17
|
return new Size(bytes);
|
|
18
18
|
}
|
|
19
|
+
static fromKilobytes(kilobytes) {
|
|
20
|
+
return new Size(kilobytes * 1000);
|
|
21
|
+
}
|
|
22
|
+
static fromMegabytes(megabytes) {
|
|
23
|
+
return new Size(megabytes * 1000 * 1000);
|
|
24
|
+
}
|
|
19
25
|
static fromGigabytes(gigabytes) {
|
|
20
26
|
return new Size(gigabytes * 1000 * 1000 * 1000);
|
|
21
27
|
}
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Bytes } from "./bytes.js";
|
|
|
3
3
|
import { Duration } from "./duration.js";
|
|
4
4
|
import { BZZ } from "./tokens.js";
|
|
5
5
|
import { asNumberString } from "./type.js";
|
|
6
|
+
const MAX_UTILIZATION = 0.9;
|
|
6
7
|
/**
|
|
7
8
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
8
9
|
*
|
|
@@ -25,23 +26,9 @@ export function getStampTheoreticalBytes(depth) {
|
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
29
|
+
* Optimised for encrypted, medium erasure coding
|
|
28
30
|
*/
|
|
29
|
-
const
|
|
30
|
-
22: 0.2867,
|
|
31
|
-
23: 0.4956,
|
|
32
|
-
24: 0.6433,
|
|
33
|
-
25: 0.7478,
|
|
34
|
-
26: 0.8217,
|
|
35
|
-
27: 0.8739,
|
|
36
|
-
28: 0.9108,
|
|
37
|
-
29: 0.9369,
|
|
38
|
-
30: 0.9554,
|
|
39
|
-
31: 0.9685,
|
|
40
|
-
32: 0.9777,
|
|
41
|
-
33: 0.9842,
|
|
42
|
-
34: 0.9889
|
|
43
|
-
};
|
|
44
|
-
const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102.78], [26, 225.87], [27, 480.44], [28, 1001.44], [29, 2060.27], [30, 4201.9], [31, 8519.02], [32, 17199.89], [33, 34628.46]];
|
|
31
|
+
const effectiveSizeBreakpoints = [[17, 0.00004089], [18, 0.00609], [19, 0.10249], [20, 0.62891], [21, 2.38], [22, 7.07], [23, 18.24], [24, 43.04], [25, 96.5], [26, 208.52], [27, 435.98], [28, 908.81], [29, 1870], [30, 3810], [31, 7730], [32, 15610], [33, 31430], [34, 63150]];
|
|
45
32
|
/**
|
|
46
33
|
* Utility function that calculates the effective size of a postage batch based on its depth.
|
|
47
34
|
*
|
|
@@ -51,15 +38,22 @@ const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102
|
|
|
51
38
|
* @returns {number} The effective size of the postage batch in bytes.
|
|
52
39
|
*/
|
|
53
40
|
export function getStampEffectiveBytes(depth) {
|
|
54
|
-
if (depth <
|
|
41
|
+
if (depth < 17) {
|
|
55
42
|
return 0;
|
|
56
43
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
44
|
+
const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
|
|
45
|
+
if (depth === d) {
|
|
46
|
+
return size;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (breakpoint) {
|
|
50
|
+
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
51
|
+
}
|
|
52
|
+
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
59
53
|
}
|
|
60
54
|
export function getStampEffectiveBytesBreakpoints() {
|
|
61
55
|
const map = new Map();
|
|
62
|
-
for (let i =
|
|
56
|
+
for (let i = 17; i < 35; i++) {
|
|
63
57
|
map.set(i, getStampEffectiveBytes(i));
|
|
64
58
|
}
|
|
65
59
|
return map;
|
|
@@ -99,11 +93,11 @@ export function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
|
99
93
|
*/
|
|
100
94
|
export function getDepthForSize(size) {
|
|
101
95
|
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
102
|
-
if (size.
|
|
96
|
+
if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
|
|
103
97
|
return depth;
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
|
-
return
|
|
100
|
+
return 35;
|
|
107
101
|
}
|
|
108
102
|
export function convertEnvelopeToMarshaledStamp(envelope) {
|
|
109
103
|
return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
|
|
@@ -9,6 +9,8 @@ export declare class Size {
|
|
|
9
9
|
private bytes;
|
|
10
10
|
private constructor();
|
|
11
11
|
static fromBytes(bytes: number): Size;
|
|
12
|
+
static fromKilobytes(kilobytes: number): Size;
|
|
13
|
+
static fromMegabytes(megabytes: number): Size;
|
|
12
14
|
static fromGigabytes(gigabytes: number): Size;
|
|
13
15
|
toBytes(): number;
|
|
14
16
|
toGigabytes(): number;
|