Skip to content

Commit db8ebcd

Browse files
committed
init
0 parents  commit db8ebcd

File tree

162 files changed

+13853
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+13853
-0
lines changed

.gitignore

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
node_modules
2+
.DS_Store
3+
dist
4+
/es
5+
*.local
6+
thumbs.db
7+
.fun
8+
.fun/*
9+
10+
.eslintcache
11+
12+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
13+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
14+
15+
# User-specific stuff
16+
.idea/**/workspace.xml
17+
.idea/**/tasks.xml
18+
.idea/**/usage.statistics.xml
19+
.idea/**/dictionaries
20+
.idea/**/shelf
21+
22+
# Generated files
23+
.idea/**/contentModel.xml
24+
25+
# Sensitive or high-churn files
26+
.idea/**/dataSources/
27+
.idea/**/dataSources.ids
28+
.idea/**/dataSources.local.xml
29+
.idea/**/sqlDataSources.xml
30+
.idea/**/dynamic.xml
31+
.idea/**/uiDesigner.xml
32+
.idea/**/dbnavigator.xml
33+
34+
# Gradle
35+
.idea/**/gradle.xml
36+
.idea/**/libraries
37+
38+
# Gradle and Maven with auto-import
39+
# When using Gradle or Maven with auto-import, you should exclude module files,
40+
# since they will be recreated, and may cause churn. Uncomment if using
41+
# auto-import.
42+
.idea/artifacts
43+
.idea/compiler.xml
44+
.idea/jarRepositories.xml
45+
.idea/modules.xml
46+
.idea/*.iml
47+
.idea/modules
48+
*.iml
49+
*.ipr
50+
51+
# Mongo Explorer plugin
52+
.idea/**/mongoSettings.xml
53+
54+
# File-based project format
55+
*.iws
56+
57+
# Editor-based Rest Client
58+
.idea/httpRequests
59+
/.idea/csv-plugin.xml
60+
nest-app/dist
61+
62+
**/ui/src/**/*.js
63+
/dockerdb
64+
**/ipfsdb/
65+
**/wasm/target/

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hoist-pattern[]=ts-node
2+
public-hoist-pattern[]=antd

.prettierrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"useTabs": false,
5+
"singleQuote": true,
6+
"semi": true,
7+
"trailingComma": "all",
8+
"bracketSpacing": true,
9+
"arrowParens": "always",
10+
"parser": "typescript"
11+
}
12+

logo.svg

Lines changed: 35 additions & 0 deletions
Loading

packages/network/package.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@chain-web/network",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"module": "./src/index",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"type": "module",
11+
"keywords": [],
12+
"author": "scc",
13+
"license": "ISC",
14+
"dependencies": {
15+
"@chainsafe/libp2p-noise": "^10.2.0",
16+
"@multiformats/multiaddr": "^11.1.0",
17+
"libp2p": "^0.41.0",
18+
"uint8arrays": "^4.0.2"
19+
}
20+
}

packages/network/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createLibp2p } from 'libp2p'
2+
import { Noise } from '@chainsafe/libp2p-noise'
3+
import { multiaddr } from '@multiformats/multiaddr'
4+
import first from "it-first";
5+
import { pipe } from "it-pipe";
6+
import { fromString, toString } from "uint8arrays";
7+
import { webRTC } from 'js-libp2p-webrtc'
8+
9+
const node = await createLibp2p({
10+
transports: [webRTC()],
11+
connectionEncryption: [() => new Noise()],
12+
});
13+
14+
await node.start()
15+
16+
const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ')
17+
const stream = await node.dialProtocol(ma, ['/my-protocol/1.0.0'])
18+
const message = `Hello js-libp2p-webrtc\n`
19+
const response = await pipe([fromString(message)], stream, async (source) => await first(source))
20+
const responseDecoded = toString(response.slice(0, response.length))

packages/network/tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"module": "ESNext",
4+
"target": "esnext",
5+
"sourceMap": true,
6+
"moduleResolution": "NodeNext",
7+
"resolveJsonModule": true,
8+
"allowSyntheticDefaultImports": true,
9+
"skipLibCheck": true,
10+
"strict": true,
11+
"declaration": true,
12+
"isolatedModules": true,
13+
"esModuleInterop": true,
14+
"types": ["node"],
15+
"lib": ["ESNext"],
16+
"outDir": "./dist",
17+
"baseUrl": "./src"
18+
},
19+
"include": ["./src/**/*.ts"],
20+
"esm": true
21+
}

packages/skchain/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "skchain",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"type": "module",
10+
"keywords": [],
11+
"author": "scc",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@types/node": "^18.11.13"
15+
},
16+
"dependencies": {
17+
"@ipld/dag-cbor": "^8.0.0",
18+
"datastore-level": "^9.0.4",
19+
"multiformats": "^10.0.2",
20+
"ts-node": "^10.9.1",
21+
"typescript": "^4.9.3",
22+
"xstate": "^4.35.0",
23+
"@chain-web/network": "workspace:*"
24+
}
25+
}

packages/skchain/src/config/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as mainConfig from './mainnet.config';
2+
import * as testConfig from './testnet.config';
3+
export const configMap = {
4+
mainnet: mainConfig,
5+
testnet: testConfig,
6+
};
7+
8+
// export const isBrowser = (() => {
9+
// try {
10+
// window.navigator;
11+
// return true;
12+
// } catch (error) {
13+
// return false;
14+
// }
15+
// })();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { networkidType } from './types';
2+
3+
export const networkid: networkidType = 'mainnet';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import BigNumber from 'bignumber.js';
2+
import { GenesisConfig, networkidType } from './types';
3+
4+
export const networkid: networkidType = 'testnet';
5+
6+
export const genesis: GenesisConfig = {
7+
hash: '0000000000000000000000000000000000000000000000',
8+
parent: '0000000000000000000000000000000000000000000000',
9+
logsBloom: '0',
10+
difficulty: new BigNumber(10),
11+
number: new BigNumber(0),
12+
cuLimit: new BigNumber(1000),
13+
timestamp: 1636461884881,
14+
alloc: {
15+
'12D3KooWL8qb3L8nKPjDtQmJU8jge5Qspsn6YLSBei9MsbTjJDr8': {
16+
balance: new BigNumber(10000000),
17+
},
18+
'12D3KooWL1NF6fdTJ9cucEuwvuX8V8KtpJZZnUE4umdLBuK15eUZ': {
19+
balance: new BigNumber(10000000),
20+
},
21+
},
22+
};

packages/skchain/src/config/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { CID } from 'multiformats/cid';
2+
import BigNumber from 'bignumber.js';
3+
4+
export type networkidType = 'mainnet' | 'testnet';
5+
6+
export interface GenesisConfig {
7+
hash: string;
8+
parent: string;
9+
// stateRoot: cidHash; // 全账户状态树根节点hash
10+
// transactionsRoot: cidHash; // 当前块的交易树根节点hash
11+
// receiptRoot: cidHash; // 当前块的收据树根节点hash
12+
logsBloom: string; // 当前块交易接收者的bloom,用于快速查找
13+
difficulty: BigNumber; // 难度,用来调整出块时间,由于不挖矿,具体实现待定
14+
number: BigNumber; // 当前块序号
15+
cuLimit: BigNumber; // 当前块,计算量上限
16+
timestamp: number;
17+
alloc?: { [key: string]: { balance: BigNumber } };
18+
}
19+
20+
// filterPeer

packages/skchain/src/lib/base.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { SKChain } from '../skChain';
2+
export class SKChainLibBase {
3+
constructor(chain: SKChain) {
4+
this.chain = chain;
5+
}
6+
7+
chain: SKChain;
8+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
使用pos + 分片实现共识
2+
3+
分片
4+
按照账户的id进行分片
5+
分片计划按照账户数量+节点数量进行动态调整
6+
每个进行打包的节点在打包完成后要进行分片调整(分片调整需要计算和网路开销)
7+
所有节点都有state tree,block header;对所有的block body数据进行分片存储,减少存储压力,后续会尽可能通过分片的方式来减少冗余存储
8+
9+
10+
节点的分片策略是在节点运行之后进行动态变更的
11+
所有符合下一分片规则的节点会一起订阅下一分片的消息,一旦下一订阅的节点数量大于限制数量,就会进行分片
12+
13+
因为DID生成是用的base58做的hash,所以最后字符串的每一位都有可能有58种可能
14+
15+
<!-- 扩张过程 -->
16+
最开始都是o分片,然后根据自己的id最后一位,判断自己是否大于等于29,去订阅o-l或o-r
17+
当o-l和o-r节点数量都到了一定量之后,进行分片
18+
分片后的o-l再根据自己的倒数第二位是否大于等于29,去订阅o-l-l、o-l-r,依次类推,每往前进一位,分片数量*2
19+
20+
<!-- 缩量过程 -->
21+
当前分片的节点数量小于64时,会跟同层节点合并,比如o-l-l-l 本来有100节点,但忽然降到60,就会导致o-l-l-r-?包括子分片在内的节点都回到o-l-l,直到o-l-l可以分为o-l-l-l和o-l-l-r
22+
因为DID生成是随机的,所以不会存在非常严重的树不平衡的状态
23+
24+
至少保证在每个分片内有64个节点进行竞争打包
25+
竞争打包是通过pubsub进行协商,协商的过程中如果单一竞争方大于128可以进行二分片
26+
27+
28+
29+
活跃度参数
30+
因为完全依赖pos的话会有存在屯币的缺陷,需要引入活跃度作为打包节点选出的条件之一来平衡
31+
32+
proof of contribute 对网络的贡献? POC
33+
对网络的贡献 = ?,应该是一个动态计算的东西,随着时间的推移,它会动态改变
34+
全节点参与POC
35+
36+
如果有分叉,就选择 contribute 最大的一个链作为主链
37+
38+
时空:、、、?
39+
每条数据都是一个时间的函数,输入是元数据+时间,输出是输入时间对应的结果数据

0 commit comments

Comments
 (0)