Chainspec and lmdb size check updates (#351)
* Rename DD spec, update spec type * Update tests for renames
This commit is contained in:
@@ -3,4 +3,4 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export { default as alexander } from './alexander';
|
||||
export { default as drieddanta } from './drieddanta';
|
||||
export { default as driedDanta } from './dried-danta';
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export type Telemetry = [string, number];
|
||||
|
||||
export type Chainspec = {
|
||||
bootNodes: Array<string>,
|
||||
id: string,
|
||||
@@ -16,5 +18,6 @@ export type Chainspec = {
|
||||
[index: string]: any
|
||||
},
|
||||
protocolId: string | null,
|
||||
telemetryUrl: string | null
|
||||
telemetryUrl?: string | null,
|
||||
telemetryEndpoints?: Array<Telemetry>
|
||||
};
|
||||
|
||||
@@ -8,9 +8,11 @@ import fs from 'fs';
|
||||
import mkdirp from 'mkdirp';
|
||||
import lmdb from 'node-lmdb';
|
||||
import path from 'path';
|
||||
import { bufferToU8a, u8aToBuffer } from '@polkadot/util/index';
|
||||
import { bufferToU8a, logger, u8aToBuffer } from '@polkadot/util/index';
|
||||
|
||||
const BASE_MAPSIZE = 2 * 1024 * 1024 * 1024; // 2GB
|
||||
const GB = 1 * 1024 * 1024 * 1024;
|
||||
|
||||
const l = logger('db/lmdb');
|
||||
|
||||
export default class LmDb implements BaseDb {
|
||||
private _env: any;
|
||||
@@ -25,18 +27,23 @@ export default class LmDb implements BaseDb {
|
||||
|
||||
mkdirp.sync(this._path);
|
||||
|
||||
const dbsize = this.size(true);
|
||||
const mapSize = Math.ceil(1 + (dbsize / GB)) * GB;
|
||||
|
||||
l.debug(() => `Current mapsize set to ${(mapSize / GB).toFixed(1)}GB`);
|
||||
|
||||
this._env.open({
|
||||
path: this._path,
|
||||
mapSize: this.getMapSize() * BASE_MAPSIZE
|
||||
mapSize
|
||||
});
|
||||
}
|
||||
|
||||
private getMapSize (): number {
|
||||
const size = this.size();
|
||||
const max = Math.ceil(size / BASE_MAPSIZE);
|
||||
const use = size / (max * BASE_MAPSIZE);
|
||||
const dbsize = this.size();
|
||||
const max = Math.ceil(dbsize / GB) * GB;
|
||||
const remaining = (max - dbsize) / GB;
|
||||
|
||||
return (use > 0.75)
|
||||
return (remaining < 0.25)
|
||||
? max + 1
|
||||
: max;
|
||||
}
|
||||
@@ -44,10 +51,11 @@ export default class LmDb implements BaseDb {
|
||||
private growMapSize (): void {
|
||||
const info = this._env.info();
|
||||
const next = this.getMapSize();
|
||||
const current = Math.ceil(info.mapSize / BASE_MAPSIZE);
|
||||
|
||||
if (current < next) {
|
||||
this._env.resize(next * BASE_MAPSIZE);
|
||||
if (next > info.mapSize) {
|
||||
l.debug(() => `Growing mapsize to ${(next / GB).toFixed(1)}GB`);
|
||||
|
||||
this._env.resize(next);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,8 +92,12 @@ export default class LmDb implements BaseDb {
|
||||
// nothing
|
||||
}
|
||||
|
||||
size (): number {
|
||||
return fs.statSync(path.join(this._path, 'data.mdb')).size;
|
||||
size (withExistsSync: boolean = false): number {
|
||||
const db = path.join(this._path, 'data.mdb');
|
||||
|
||||
return !withExistsSync || fs.existsSync(db)
|
||||
? fs.statSync(db).size
|
||||
: 0;
|
||||
}
|
||||
|
||||
txCommit (): void {
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { alexander, drieddanta } from '@polkadot/chainspec/index';
|
||||
import { alexander, driedDanta } from '@polkadot/chainspec/index';
|
||||
import { hexToU8a, u8aToHex } from '@polkadot/util/index';
|
||||
|
||||
import Trie from './index';
|
||||
|
||||
describe('genesis roots', () => {
|
||||
[alexander, drieddanta].forEach(({ genesis: { raw }, genesisRoot, name }) => {
|
||||
[alexander, driedDanta].forEach(({ genesis: { raw }, genesisRoot, name }) => {
|
||||
it(`has the correct root for ${name}`, () => {
|
||||
const trie = new Trie();
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { alexander, drieddanta } from '@polkadot/chainspec/index';
|
||||
import { alexander, driedDanta } from '@polkadot/chainspec/index';
|
||||
import { hexToU8a, u8aToHex } from '@polkadot/util/index';
|
||||
|
||||
import trieRoot from './trieRoot';
|
||||
|
||||
describe('genesis roots', () => {
|
||||
[alexander, drieddanta].forEach(({ genesis: { raw }, genesisRoot, name }) => {
|
||||
[alexander, driedDanta].forEach(({ genesis: { raw }, genesisRoot, name }) => {
|
||||
it(`has the correct root for ${name}`, () => {
|
||||
expect(
|
||||
u8aToHex(
|
||||
|
||||
Reference in New Issue
Block a user