Skip to content

Commit

Permalink
Merge 27e137d into 7d81571
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Jul 4, 2018
2 parents 7d81571 + 27e137d commit 3024f45
Show file tree
Hide file tree
Showing 73 changed files with 921 additions and 690 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "10"
- "10.5"
cache:
yarn: true
directories:
Expand Down
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -2,7 +2,7 @@
"version": "0.13.3",
"private": true,
"engines": {
"node": "^10.1.0",
"node": "^10.5.0",
"yarn": "^1.3.2"
},
"workspaces": [
Expand All @@ -13,10 +13,10 @@
"check": "tslint --project . && tsc --noEmit",
"clean": "polkadot-dev-clean-build",
"postinstall": "polkadot-dev-yarn-only",
"test": "jest --coverage",
"start": "node packages/client/scripts/polkadot.js --db-path ./tmp/start-1",
"start2": "node packages/client/scripts/polkadot.js --db-path ./tmp/start-2 --p2p-nodes /ip4/127.0.0.1/tcp/39933/ipfs/QmfUiXCYtrKotHgDbP4Kc74NUi2LxckEiAdkK1SMSosLaz --p2p-port 39934 --rpc-port 9934",
"start-rust": "node packages/client/scripts/polkadot.js --db-path ./tmp/start-rust --p2p-nodes /ip4/127.0.0.1/tcp/30333/ipfs/QmbggqmmTM1irJkKbxi9TX8WyHy4c2f2HFGVhQHhR7orBH /ip4/127.0.0.1/tcp/39933/ipfs/QmfUiXCYtrKotHgDbP4Kc74NUi2LxckEiAdkK1SMSosLaz --p2p-port 39935 --rpc-port 9935"
"test": "NODE_OPTIONS=--experimental-worker jest --coverage",
"start": "NODE_OPTIONS=--experimental-worker node packages/client/scripts/polkadot.js --db-path ./tmp/start-1",
"start2": "NODE_OPTIONS=--experimental-worker node packages/client/scripts/polkadot.js --db-path ./tmp/start-2 --p2p-nodes /ip4/127.0.0.1/tcp/39933/ipfs/QmfUiXCYtrKotHgDbP4Kc74NUi2LxckEiAdkK1SMSosLaz --p2p-port 39934 --rpc-port 9934",
"start-rust": "NODE_OPTIONS=--experimental-worker node packages/client/scripts/polkadot.js --db-path ./tmp/start-rust --p2p-nodes /ip4/127.0.0.1/tcp/30333/ipfs/QmRZB66LjCH9MSMLsTZjkQGBo7sGmqi6PfRyV5dDL9wPyr --p2p-port 39935 --rpc-port 9935"
},
"devDependencies": {
"@polkadot/dev": "^0.20.9",
Expand Down
14 changes: 7 additions & 7 deletions packages/client-chains/package.json
Expand Up @@ -37,16 +37,16 @@
"@polkadot/client-db-chain": "^0.13.3",
"@polkadot/client-runtime": "^0.13.3",
"@polkadot/client-wasm": "^0.13.3",
"@polkadot/storage": "^0.26.10",
"@polkadot/util": "^0.26.10",
"@polkadot/util-crypto": "^0.26.10",
"@polkadot/util-keyring": "^0.26.10"
"@polkadot/storage": "^0.26.14",
"@polkadot/util": "^0.26.14",
"@polkadot/util-crypto": "^0.26.14",
"@polkadot/util-keyring": "^0.26.14"
},
"devDependencies": {
"@polkadot/client": "^0.13.3",
"@polkadot/client-db": "^0.13.3",
"@polkadot/extrinsics": "^0.26.10",
"@polkadot/primitives": "^0.26.10",
"@polkadot/storage": "^0.26.10"
"@polkadot/extrinsics": "^0.26.14",
"@polkadot/primitives": "^0.26.14",
"@polkadot/storage": "^0.26.14"
}
}
19 changes: 10 additions & 9 deletions packages/client-chains/src/chains/chain-dev.spec.js
Expand Up @@ -2,19 +2,16 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import memDb from '@polkadot/util-triedb/temp';
import toU8a from '@polkadot/util/u8a/toU8a';
import HashDb from '@polkadot/client-db/Hash';
import MemoryDb from '@polkadot/client-db/Memory';

import init from '../index';

describe('genesis', () => {
let genesis;

beforeEach(() => {
const stateDb = memDb();
const blockDb = memDb();

genesis = init({ chain: 'dev' }, stateDb, blockDb).genesis;
});
const blockDb = new HashDb();
const stateDb = new MemoryDb();
const genesis = init({ chain: 'dev' }, stateDb, blockDb).genesis;

it('creates a correct genesis block (stateRoot)', () => {
expect(
Expand Down Expand Up @@ -45,4 +42,8 @@ describe('genesis', () => {
])
);
});

it('terminates', () => {
return stateDb.terminate();
});
});
2 changes: 0 additions & 2 deletions packages/client-chains/src/genesis/block.ts
Expand Up @@ -21,7 +21,6 @@ export default function genesisBlock ({ stateDb: { db } }: ChainState): ChainGen
throw new Error('Unable to retrieve genesis code');
}

const codeHash = blake2Asu8a(code, 256);
const block = createBlock({
header: {
stateRoot: db.trieRoot(),
Expand All @@ -34,7 +33,6 @@ export default function genesisBlock ({ stateDb: { db } }: ChainState): ChainGen
return {
block: encodeBlock(block),
code,
codeHash,
header: block.header,
headerHash
};
Expand Down
5 changes: 3 additions & 2 deletions packages/client-chains/src/genesis/index.ts
Expand Up @@ -16,8 +16,9 @@ export default function initGenesis (self: ChainState, initialState: ChainGenesi
self.blockDb.bestNumber.set(0);
self.blockDb.block.set(genesis.block, genesis.headerHash);

self.stateDb.system.blockHashAt.set(genesis.headerHash, 0);
self.stateDb.db.commit();
// self.stateDb.db.checkpoint();
// self.stateDb.system.blockHashAt.set(genesis.headerHash, 0);
// self.stateDb.db.commit();

return genesis;
}
4 changes: 3 additions & 1 deletion packages/client-chains/src/genesis/state.ts
Expand Up @@ -7,8 +7,10 @@ import { ChainState, ChainGenesisState } from '../types';
import hexToU8a from '@polkadot/util/hex/toU8a';

export default function genesisState ({ stateDb: { db } }: ChainState, initial: ChainGenesisState): void {
db.checkpoint();

Object.keys(initial).forEach((key) =>
db.set(hexToU8a(key), hexToU8a(initial[key]))
db.put(hexToU8a(key), hexToU8a(initial[key]))
);

db.commit();
Expand Down
23 changes: 11 additions & 12 deletions packages/client-chains/src/index.spec.js
Expand Up @@ -2,22 +2,17 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import memoryDb from '@polkadot/util-triedb/temp';
import HashDb from '@polkadot/client-db/Hash';
import MemoryDb from '@polkadot/client-db/Memory';

import createChain from './index';

describe('client-chains', () => {
let config;
let blockDb;
let stateDb;

beforeEach(() => {
config = {
chain: 'dev'
};
blockDb = memoryDb();
stateDb = memoryDb();
});
const config = {
chain: 'dev'
};
const blockDb = new HashDb();
const stateDb = new MemoryDb();

it('instantiates a known chain', () => {
expect(
Expand All @@ -32,4 +27,8 @@ describe('client-chains', () => {
() => createChain(config, stateDb, blockDb)
).toThrow(/Unable to find builtin chain/);
});

it('terminates', () => {
return stateDb.terminate();
});
});
4 changes: 2 additions & 2 deletions packages/client-chains/src/index.ts
Expand Up @@ -3,7 +3,7 @@
// of the ISC license. See the LICENSE file for details.

import { Config } from '@polkadot/client/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb, TrieDb } from '@polkadot/client-db/types';
import { ChainInterface } from './types';

import createExecutor from '@polkadot/client-wasm/index';
Expand All @@ -12,7 +12,7 @@ import loadChain from './load';
import createGenesis from './genesis';
import createState from './state';

export default function chains (config: Config, baseStateDb: TrieDb, baseBlockDb: TrieDb): ChainInterface {
export default function chains (config: Config, baseStateDb: TrieDb, baseBlockDb: BaseDb): ChainInterface {
const initial = loadChain(config.chain);
const self = createState(config, baseStateDb, baseBlockDb);
const genesis = createGenesis(self, initial);
Expand Down
8 changes: 4 additions & 4 deletions packages/client-chains/src/state.ts
Expand Up @@ -3,19 +3,19 @@
// of the ISC license. See the LICENSE file for details.

import { Config } from '@polkadot/client/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb, TrieDb } from '@polkadot/client-db/types';
import { ChainState } from './types';

import createBlockDb from '@polkadot/client-db-chain/block';
import createStateDb from '@polkadot/client-db-chain/state';
import createRuntime from '@polkadot/client-runtime/index';
import logger from '@polkadot/util/logger';

export default function state (config: Config, baseStateDb: TrieDb, baseBlockDb: TrieDb): ChainState {
const l = logger(`chain-${config.chain}`);
export default function state (config: Config, baseStateDb: TrieDb, baseBlockDb: BaseDb): ChainState {
const l = logger(`chain/${config.chain}`);
const runtime = createRuntime(baseStateDb);
const blockDb = createBlockDb(baseBlockDb);
const stateDb = createStateDb(runtime.environment.db);
const stateDb = createStateDb(baseStateDb);

return {
blockDb,
Expand Down
1 change: 0 additions & 1 deletion packages/client-chains/src/types.d.ts
Expand Up @@ -19,7 +19,6 @@ export type ChainGenesisState = {
export type ChainGenesis = {
block: Uint8Array,
code: Uint8Array,
codeHash: Uint8Array,
header: Header,
headerHash: Uint8Array
};
Expand Down
10 changes: 5 additions & 5 deletions packages/client-db-chain/package.json
Expand Up @@ -35,12 +35,12 @@
"dependencies": {
"@babel/runtime": "^7.0.0-beta.51",
"@polkadot/client-db": "^0.13.3",
"@polkadot/storage": "^0.26.10",
"@polkadot/trie-hash": "^0.26.10",
"@polkadot/util": "^0.26.10",
"@polkadot/util-crypto": "^0.26.10"
"@polkadot/storage": "^0.26.14",
"@polkadot/trie-hash": "^0.26.14",
"@polkadot/util": "^0.26.14",
"@polkadot/util-crypto": "^0.26.14"
},
"devDependencies": {
"@polkadot/storage": "^0.26.10"
"@polkadot/storage": "^0.26.14"
}
}
4 changes: 2 additions & 2 deletions packages/client-db-chain/src/block/index.ts
Expand Up @@ -2,14 +2,14 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb } from '@polkadot/client-db/types';
import { BlockDb } from '../types';

import createBn from '../db/bn';
import createU8a from '../db/u8a';
import keys from './keys';

export default function blockDb (db: TrieDb): BlockDb {
export default function blockDb (db: BaseDb): BlockDb {
return {
db,
bestHash: createU8a(db, keys.public.bestHash),
Expand Down
6 changes: 3 additions & 3 deletions packages/client-db-chain/src/db/arrayU8a.ts
Expand Up @@ -4,7 +4,7 @@

import { SectionItem } from '@polkadot/params/types';
import { Storage$Key$Value } from '@polkadot/storage/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb } from '@polkadot/client-db/types';
import { StorageMethod$ArrayU8a } from '../types';

import bnToU8a from '@polkadot/util/bn/toU8a';
Expand All @@ -13,7 +13,7 @@ import u8aToBn from '@polkadot/util/u8a/toBn';

import creator from '../key';

export default function decodeArrayU8a <T> (db: TrieDb, key: SectionItem<T>): StorageMethod$ArrayU8a {
export default function decodeArrayU8a <T> (db: BaseDb, key: SectionItem<T>): StorageMethod$ArrayU8a {
const createKey = creator(key);

return {
Expand All @@ -37,7 +37,7 @@ export default function decodeArrayU8a <T> (db: TrieDb, key: SectionItem<T>): St
return result;
},
set: (value: Array<Uint8Array>, ...keyParams: Array<Storage$Key$Value>): void =>
db.set(createKey(keyParams), u8aConcat(
db.put(createKey(keyParams), u8aConcat(
bnToU8a(value.length, 32, true),
u8aConcat.apply(null, value))
),
Expand Down
6 changes: 3 additions & 3 deletions packages/client-db-chain/src/db/base.ts
Expand Up @@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb } from '@polkadot/client-db/types';

type Base <T> = {
del (key: Uint8Array): void,
Expand All @@ -13,7 +13,7 @@ type Base <T> = {

type Subscribers <T> = Array<(value: T, raw: Uint8Array) => void>;

export default function base <T> (db: TrieDb): Base<T> {
export default function base <T> (db: BaseDb): Base<T> {
const subscribers: Subscribers<T> = [];

return {
Expand All @@ -22,7 +22,7 @@ export default function base <T> (db: TrieDb): Base<T> {
get: (key: Uint8Array): Uint8Array =>
db.get(key) || new Uint8Array([]),
set: (key: Uint8Array, value: T, raw: Uint8Array): void => {
db.set(key, raw);
db.put(key, raw);
subscribers.forEach((subscriber) =>
subscriber(value, raw)
);
Expand Down
4 changes: 2 additions & 2 deletions packages/client-db-chain/src/db/bn.ts
Expand Up @@ -5,7 +5,7 @@
import BN from 'bn.js';
import { SectionItem } from '@polkadot/params/types';
import { Storage$Key$Value } from '@polkadot/storage/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb } from '@polkadot/client-db/types';
import { StorageMethod$Bn } from '../types';

import bnToU8a from '@polkadot/util/bn/toU8a';
Expand All @@ -14,7 +14,7 @@ import u8aToBn from '@polkadot/util/u8a/toBn';
import createBase from './base';
import creator from '../key';

export default function decodeBn <T> (db: TrieDb, key: SectionItem<T>, bitLength: 32 | 64 | 128): StorageMethod$Bn {
export default function decodeBn <T> (db: BaseDb, key: SectionItem<T>, bitLength: 32 | 64 | 128): StorageMethod$Bn {
const createKey = creator(key);
const base = createBase<BN | number>(db);

Expand Down
4 changes: 2 additions & 2 deletions packages/client-db-chain/src/db/bool.ts
Expand Up @@ -4,13 +4,13 @@

import { SectionItem } from '@polkadot/params/types';
import { Storage$Key$Value } from '@polkadot/storage/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb } from '@polkadot/client-db/types';
import { StorageMethod$Bool } from '../types';

import createBase from './base';
import creator from '../key';

export default function decodeBool <T> (db: TrieDb, key: SectionItem<T>): StorageMethod$Bool {
export default function decodeBool <T> (db: BaseDb, key: SectionItem<T>): StorageMethod$Bool {
const createKey = creator(key);
const base = createBase<boolean>(db);

Expand Down
4 changes: 2 additions & 2 deletions packages/client-db-chain/src/db/u8a.ts
Expand Up @@ -4,13 +4,13 @@

import { SectionItem } from '@polkadot/params/types';
import { Storage$Key$Value } from '@polkadot/storage/types';
import { TrieDb } from '@polkadot/util-triedb/types';
import { BaseDb } from '@polkadot/client-db/types';
import { StorageMethod$U8a } from '../types';

import creator from '../key';
import createBase from './base';

export default function decodeU8a <T> (db: TrieDb, key: SectionItem<T>): StorageMethod$U8a {
export default function decodeU8a <T> (db: BaseDb, key: SectionItem<T>): StorageMethod$U8a {
const createKey = creator(key);
const base = createBase<Uint8Array>(db);

Expand Down
2 changes: 1 addition & 1 deletion packages/client-db-chain/src/state/accountIndexOf.spec.js
Expand Up @@ -24,7 +24,7 @@ describe('accountIndexOf', () => {

return store[u8aToHex(key)] || new Uint8Array([]);
},
set: (key, value) => {
put: (key, value) => {
console.log('setting', u8aToHex(key), value);

store[u8aToHex(key)] = value;
Expand Down
2 changes: 1 addition & 1 deletion packages/client-db-chain/src/state/balance.spec.js
Expand Up @@ -54,7 +54,7 @@ describe('balance', () => {

staking = db({
get: (key) => store[u8aToHex(key)] || new Uint8Array([]),
set: (key, value) => {
put: (key, value) => {
store[u8aToHex(key)] = value;
}
}).staking;
Expand Down
4 changes: 2 additions & 2 deletions packages/client-db-chain/src/state/blockHash.spec.js
Expand Up @@ -24,7 +24,7 @@ describe('blockHash', () => {

return store[u8aToHex(key)] || new Uint8Array([]);
},
set: (value, key) => {
put: (value, key) => {
console.log('setting', u8aToHex(key), value);

store[u8aToHex(key)] = value;
Expand All @@ -45,7 +45,7 @@ describe('blockHash', () => {

system = db({
get: (key) => store[u8aToHex(key)] || new Uint8Array([]),
set: (key, value) => {
put: (key, value) => {
store[u8aToHex(key)] = value;
}
}).system;
Expand Down

0 comments on commit 3024f45

Please sign in to comment.