Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adapt ckb light node #2590

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ckb-light-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v0.2.1
11 changes: 6 additions & 5 deletions packages/neuron-ui/src/components/NetworkSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ const NetworkSetting = ({ chain = chainState, settings: { networks = [] } }: Sta
<span className={styles.url}>{`(${network.remote}`}</span>
<NetworkTypeLabel type={network.chain} />
</span>

<button type="button" data-action="edit" aria-label={t('common.edit')} title={t('common.edit')}>
<EditNetwork />
</button>
{isDefault ? null : (
{network.chain === 'light_testnet' || (
<button type="button" data-action="edit" aria-label={t('common.edit')} title={t('common.edit')}>
<EditNetwork />
</button>
)}
{isDefault || network.chain === 'light_testnet' ? null : (
<button
type="button"
data-action="delete"
Expand Down
3 changes: 3 additions & 0 deletions packages/neuron-ui/src/components/NetworkTypeLabel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ const NetworkTypeLabel = ({ type }: { type: 'ckb' | 'ckb_testnet' | 'ckb_dev' |
case 'ckb_testnet': {
return <span className="label secondary">{t('settings.network.testnet')}</span>
}
case 'light_testnet': {
return <span className="label secondary">{t('settings.network.lightTestnet')}</span>
}
default: {
return <span className="label third">{t('settings.network.devnet')}</span>
}
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@
},
"mainnet": "Mainnet",
"testnet": "Testnet",
"lightTestnet": "Light Testnet",
"devnet": "Devnet"
},
"locale": {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
},
"mainnet": "主网",
"testnet": "测试网",
"lightTestnet": "轻节点测试网",
"devnet": "开发网"
},
"locale": {
Expand Down
3 changes: 1 addition & 2 deletions packages/neuron-ui/src/services/chain.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import CKBCore from '@nervosnetwork/ckb-sdk-core'

export const ckbCore = new CKBCore('')
export const { getHeader, getBlock, getBlockchainInfo, getTipHeader, getHeaderByNumber } = ckbCore.rpc
export const { getHeader, getBlockchainInfo, getTipHeader, getHeaderByNumber } = ckbCore.rpc

export const { calculateDaoMaximumWithdraw } = ckbCore

export const { toUint64Le, parseEpoch } = ckbCore.utils
export default {
ckbCore,
getBlock,
getBlockchainInfo,
getHeader,
getTipHeader,
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ body {
justify-content: center;
align-items: center;
height: 18px;
width: 58px;
min-width: 58px;
padding: 0 4px;
font-size: 9px;
font-weight: 600;
Expand Down
12 changes: 12 additions & 0 deletions packages/neuron-wallet/electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ win:
extraFiles:
- from: "bin/win/ckb.exe"
to: "bin/ckb.exe"
- from: "bin/win/ckb-light-client.exe"
to: "bin/ckb-light-client.exe"
- from: "light/ckb_light.toml"
to: "light/ckb_light.toml"
target:
- target: nsis
arch:
Expand All @@ -52,6 +56,10 @@ mac:
extraFiles:
- from: "bin/mac/ckb"
to: "bin/ckb"
- from: "bin/mac/ckb-light-client"
to: "bin/ckb-light-client"
- from: "light/ckb_light.toml"
to: "light/ckb_light.toml"
hardenedRuntime: true
gatekeeperAssess: false
entitlements: assets/entitlements.plist
Expand All @@ -70,5 +78,9 @@ linux:
extraFiles:
- from: "bin/linux/ckb"
to: "bin/ckb"
- from: "bin/linux/ckb-light-client"
to: "bin/ckb-light-client"
- from: "light/ckb_light.toml"
to: "light/ckb_light.toml"
target:
- AppImage
55 changes: 55 additions & 0 deletions packages/neuron-wallet/light/ckb_light.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# chain = "mainnet"
# chain = "testnet"
# chain = "your_path_to/dev.toml"
chain = "testnet"

[store]
path = "data/store"

[network]
path = "data/network"

listen_addresses = ["/ip4/0.0.0.0/tcp/8118"]
### Specify the public and routable network addresses
# public_addresses = []

# Node connects to nodes listed here to discovery other peers when there's no local stored peers.
# When chain.spec is changed, this usually should also be changed to the bootnodes in the new chain.
bootnodes = [
# Hangzhou, Asia
"/ip4/47.111.169.36/tcp/8111/p2p/QmNQ4jky6uVqLDrPU7snqxARuNGWNLgSrTnssbRuy3ij2W",
# Ohio, North America
"/ip4/18.217.146.65/tcp/8111/p2p/QmT6DFfm18wtbJz3y4aPNn3ac86N4d4p4xtfQRRPf73frC",
# Singapore, Asia
"/ip4/18.136.60.221/tcp/8111/p2p/QmTt6HeNakL8Fpmevrhdna7J4NzEMf9pLchf1CXtmtSrwb",
# London, Europe
"/ip4/35.176.207.239/tcp/8111/p2p/QmSJTsMsMGBjzv1oBNwQU36VhQRxc2WQpFoRu1ZifYKrjZ"
]

### Whitelist-only mode
# whitelist_only = false
### Whitelist peers connecting from the given IP addresses
# whitelist_peers = []

### Enable `SO_REUSEPORT` feature to reuse port on Linux, not supported on other OS yet
# reuse_port_on_linux = true

max_peers = 125
max_outbound_peers = 8
# 2 minutes
ping_interval_secs = 120
# 20 minutes
ping_timeout_secs = 1200
connect_outbound_interval_secs = 15
# If set to true, try to register upnp
upnp = false
# If set to true, network service will add discovered local address to peer store, it's helpful for private net development
discovery_local_address = false
# If set to true, random cleanup when there are too many inbound nodes
# Ensure that itself can continue to serve as a bootnode node
bootnode_mode = false

[rpc]
# Light client rpc is designed for self hosting, exposing to public network is not recommended and may cause security issues.
# By default RPC only binds to localhost, thus it only allows accessing from the same machine.
listen_address = "127.0.0.1:9000"
6 changes: 4 additions & 2 deletions packages/neuron-wallet/src/block-sync-renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import DataUpdateSubject from 'models/subjects/data-update'
import AddressCreatedSubject from 'models/subjects/address-created-subject'
import WalletDeletedSubject from 'models/subjects/wallet-deleted-subject'
import TxDbChangedSubject from 'models/subjects/tx-db-changed-subject'
import { LumosCellQuery, LumosCell } from './sync/indexer-connector'
import { LumosCellQuery } from './sync/connector'
import { LumosCell } from './sync/connector'
import { WorkerMessage, StartParams, QueryIndexerParams } from './task'
import logger from 'utils/logger'
import CommonUtils from 'utils/common'
Expand Down Expand Up @@ -105,7 +106,8 @@ export const createBlockSyncTask = async () => {
// prevents the sync task from being started repeatedly if fork does not finish executing.
child = fork(path.join(__dirname, 'task-wrapper.js'), [], {
env: { fileBasePath: env.fileBasePath },
stdio: ['ipc', process.stdout, 'pipe']
stdio: ['ipc', process.stdout, 'pipe'],
execArgv: env.app.isPackaged ? [] : ['--inspect']
})

child.on('message', ({ id, message, channel }: WorkerMessage) => {
Expand Down
44 changes: 44 additions & 0 deletions packages/neuron-wallet/src/block-sync-renderer/sync/connector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Subject } from 'rxjs'

export interface BlockTips {
cacheTipNumber: number
indexerTipNumber: number | undefined
}

export interface LumosCellQuery {
lock: CKBComponents.Script | null
type: CKBComponents.Script | null
data: string | null
}

export interface LumosCell {
block_hash: string
out_point: {
tx_hash: string
index: string
}
cell_output: {
capacity: string
lock: {
code_hash: string
args: string
hash_type: string
}
type?: {
code_hash: string
args: string
hash_type: string
}
}
data?: string
}

export abstract class Connector<T = unknown> {
abstract blockTipsSubject: Subject<BlockTips>
abstract transactionsSubject: Subject<{ txHashes: CKBComponents.Hash[]; params: T }>

abstract connect(): Promise<void>
abstract notifyCurrentBlockNumberProcessed(param: T): void
abstract stop(): void
abstract getLiveCellsByScript(query: LumosCellQuery): Promise<unknown>
}
Loading