Skip to content

Commit

Permalink
feat: upgrade lumos
Browse files Browse the repository at this point in the history
  • Loading branch information
Daryl-L committed Jan 31, 2024
1 parent a40149e commit da049f8
Show file tree
Hide file tree
Showing 23 changed files with 4,030 additions and 4,683 deletions.
9 changes: 6 additions & 3 deletions ckb-contracts/types/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ cfg_if::cfg_if! {
pub const SUDT_HASH_TYPE: u8 = 1;
} else if #[cfg(feature = "devnet")] {
pub const SUDT_CODE_HASH: [u8; 32] = [
225, 227, 84, 214, 214, 67, 173, 66, 114, 77, 64, 150, 126, 51, 73, 132, 83, 78, 3, 103,
64, 92, 90, 228, 42, 157, 125, 99, 215, 125, 244, 25,
246, 133, 205, 19, 187, 166, 22,
202, 200, 125, 162, 19, 177, 84,
182, 234, 225, 250, 79, 0, 118,
228, 185, 55, 81, 252, 66, 178,
228, 166, 244, 108
];
pub const SUDT_HASH_TYPE: u8 = 0;
pub const SUDT_HASH_TYPE: u8 = 1;
}
}

Expand Down
166 changes: 166 additions & 0 deletions docker/ckb/ckb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Config generated by `ckb init --chain dev`

data_dir = "data"

[chain]
# Choose the kind of chains to run, possible values:
# - { file = "specs/dev.toml" }
# - { bundled = "specs/testnet.toml" }
# - { bundled = "specs/mainnet.toml" }
spec = { file = "specs/dev.toml" }

[logger]
filter = "info,ckb-script=debug"
color = true
log_to_file = true
log_to_stdout = true

[sentry]
# set to blank to disable sentry error collection
dsn = ""
# if you are willing to help us to improve,
# please leave a way to contact you when we have troubles to reproduce the errors.
# org_contact = ""

# # **Experimental** Monitor memory changes.
# [memory_tracker]
# # Seconds between checking the process, 0 is disable, default is 0.
# interval = 600

[db]
# The capacity of RocksDB cache, which caches uncompressed data blocks, indexes and filters, default is 128MB.
# Rocksdb will automatically create and use an 8MB internal cache if you set this value to 0.
# To turning off cache, you need to set this value to 0 and set `no_block_cache = true` in the options_file,
# however, we strongly discourage this setting, it may lead to severe performance degradation.
cache_size = 134217728

# Provide an options file to tune RocksDB for your workload and your system configuration.
# More details can be found in [the official tuning guide](https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide).
options_file = "default.db-options"

[network]
listen_addresses = ["/ip4/0.0.0.0/tcp/8115"]
### 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 = []

### 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 = true
# 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

# Supported protocols list, only "Sync" and "Identify" are mandatory, others are optional
support_protocols = ["Ping", "Discovery", "Identify", "Feeler", "DisconnectMessage", "Sync", "Relay", "Time", "Alert", "LightClient", "Filter"]

# [network.sync.header_map]
# memory_limit = "256MB"

[rpc]
# By default RPC only binds to localhost, thus it only allows accessing from the same machine.
#
# Allowing arbitrary machines to access the JSON-RPC port is dangerous and strongly discouraged.
# Please strictly limit the access to only trusted machines.
listen_address = "0.0.0.0:8114"

# Default is 10MiB = 10 * 1024 * 1024
max_request_body_size = 10485760

# List of API modules: ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug", "Indexer"]
modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment", "Debug", "Indexer"]

# By default RPC only binds to HTTP service, you can bind it to TCP and WebSocket.
# tcp_listen_address = "127.0.0.1:18114"
# ws_listen_address = "127.0.0.1:28114"
reject_ill_transactions = true

# By default deprecated rpc methods are disabled.
enable_deprecated_rpc = false

[tx_pool]
max_tx_pool_size = 180_000_000 # 180mb
min_fee_rate = 1_000 # Here fee_rate are calculated directly using size in units of shannons/KB
max_tx_verify_cycles = 70_000_000
max_ancestors_count = 25

[store]
header_cache_size = 4096
cell_data_cache_size = 128
block_proposals_cache_size = 30
block_tx_hashes_cache_size = 30
block_uncles_cache_size = 30

# [notifier]
# # Execute command when the new tip block changes, first arg is block hash.
# new_block_notify_script = "your_new_block_notify_script.sh"
# # Execute command when node received an network alert, first arg is alert message string.
# network_alert_notify_script = "your_network_alert_notify_script.sh"

# Set the lock script to protect mined CKB.
#
# CKB uses CS architecture for miner. Miner process (ckb miner) gets block
# template from the Node process (ckb run) via RPC. Thus the lock script is
# configured in ckb.toml instead of ckb-miner.toml, and the config takes effect
# after restarting Node process.
#
# The `code_hash` identifies different cryptography algorithm. Read the manual
# of the lock script provider about how to generate this config.
#
# CKB provides an secp256k1 implementation, it requires a hash on the
# compressed public key. The hash algorithm is blake2b, with personal
# "ckb-default-hash". The first 160 bits (20 bytes) are used as the only arg.
#
# You can use any tool you trust to generate a Bitcoin private key and public
# key pair, which can be used in CKB as well. CKB CLI provides the function for
# you to convert the public key into block assembler configuration parameters.
#
# Here is an example using ckb-cli to generate an account, this command will
# print the block assembler args(lock_arg) to screen:
#
# ckb-cli account new
#
# If you already have a raw secp256k1 private key, you can get the lock_arg by:
#
# ckb-cli util key-info --privkey-path <privkey-path>
#
# The command `ckb init` also accepts options to generate the block assembler
# directly. See `ckb init --help` for details.
#
# ckb init <lock_arg>
#
[block_assembler]
code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
args = "0x839f6f4d6fdf773d3e015f8b19fe5c4ccb07723d"
hash_type = "type"
message = "0x1234"
# #
# # CKB will prepend the binary version to message, to identify the block miner client. (default true, false to disable it)
# use_binary_version_as_message_prefix = true
# #
# # Block assembler will notify new block template through http post to specified endpoints when update
# notify = ["http://127.0.0.1:8888"]
# # Or you may want use more flexible scripts, block template as arg.
# notify_scripts = ["{cmd} {blocktemplate}"]
#
# [indexer_v2]
# # Indexing the pending txs in the ckb tx-pool
# index_tx_pool = false
44 changes: 22 additions & 22 deletions offchain-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,27 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.1",
"@types/jest": "^26.0.19",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"ava": "^3.15.0",
"codecov": "^3.8.1",
"eslint": "^7.22.0",
"eslint-formatter-pretty": "^4.0.0",
"eslint-plugin-deprecation": "^1.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-tsc": "^2.0.0",
"husky": "^6.0.0",
"lerna": "^4.0.0",
"lint-staged": "^10.5.4",
"npm-run-all": "^4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-node-dev": "^2.0.0",
"typescript": "^4.5"
"@istanbuljs/nyc-config-typescript": "1.0.1",
"@types/jest": "26.0.19",
"@typescript-eslint/eslint-plugin": "4.18.0",
"@typescript-eslint/parser": "4.18.0",
"ava": "3.15.0",
"codecov": "3.8.1",
"eslint": "7.22.0",
"eslint-formatter-pretty": "4.0.0",
"eslint-plugin-deprecation": "1.2.1",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-prettier": "3.3.1",
"eslint-plugin-tsc": "2.0.0",
"husky": "6.0.0",
"lerna": "4.0.0",
"lint-staged": "10.5.4",
"npm-run-all": "4.1.5",
"nyc": "15.1.0",
"prettier": "2.2.1",
"rimraf": "3.0.2",
"ts-node-dev": "2.0.0",
"typescript": "4.5"
},
"ava": {
"files": [
Expand Down Expand Up @@ -125,6 +125,6 @@
"node": "14.x"
},
"dependencies": {
"ts-node": "^10.9.2"
"ts-node": "10.9.2"
}
}
11 changes: 5 additions & 6 deletions offchain-modules/packages/app-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
"@force-bridge/app-rpc-server": "^0.0.38",
"@force-bridge/keystore": "^0.0.38",
"@force-bridge/x": "^0.0.38",
"@lay2/pw-core": "^0.3.22",
"@nervosnetwork/ckb-sdk-core": "^0.101.0",
"commander": "^8.1.0",
"ethereumjs-util": "^7.1.0",
"ethers": "^5.4.7",
"json-rpc-2.0": "^0.2.18"
"@nervosnetwork/ckb-sdk-core": "0.101.0",
"commander": "8.1.0",
"ethereumjs-util": "7.1.0",
"ethers": "5.4.7",
"json-rpc-2.0": "0.2.18"
},
"publishConfig": {
"access": "public"
Expand Down
15 changes: 8 additions & 7 deletions offchain-modules/packages/app-monitor/src/balanceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { CkbIndexer, Order, ScriptType, SearchKey } from '@force-bridge/x/dist/c
import { getOwnerTypeHash } from '@force-bridge/x/dist/ckb/tx-helper/multisig/multisig_helper';
import { logger } from '@force-bridge/x/dist/utils/logger';
import CKB from '@nervosnetwork/ckb-sdk-core';
import Web3 from 'web3';
import { AbiItem } from 'web3-utils';
// import Web3 from 'web3';
// import { AbiItem } from 'web3-utils';
import { ethers } from 'ethers';

const minERC20ABI = [
// balanceOf
Expand All @@ -27,26 +28,26 @@ const minERC20ABI = [
];

export class BalanceProvider {
private web3: Web3;
private web3: ethers.providers.JsonRpcProvider;
private ckb: CKB;
private ckbIndexer: CkbIndexer;
private ownerTypeHash: string;

constructor(ethRpcUrl: string, ckbRpcUrl: string, ckbIndexerUrl: string) {
this.web3 = new Web3(ethRpcUrl);
this.web3 = new ethers.providers.JsonRpcProvider(ethRpcUrl);
this.ckb = new CKB(ckbRpcUrl);
this.ckbIndexer = new CkbIndexer(ckbRpcUrl, ckbIndexerUrl);
this.ownerTypeHash = getOwnerTypeHash();
}

async ethBalance(address: string): Promise<bigint> {
const balance = await this.web3.eth.getBalance(address);
const balance = await this.web3.getBalance(address);
logger.info(`eth_balance name: ETH, address: ${address}, balance: ${balance}`);
return BigInt(balance);
return balance.toBigInt();
}

async ethErc20Balance(address: string, tokenAddress: string, name: string): Promise<bigint> {
const TokenContract = new this.web3.eth.Contract(minERC20ABI as AbiItem[], tokenAddress);
const TokenContract = new ethers.Contract(tokenAddress, minERC20ABI);
const erc20_amount = await TokenContract.methods.balanceOf(address).call();
const erc20_balance = erc20_amount.toString();
logger.info(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Cell, utils } from '@ckb-lumos/base';
import { bytes, number } from '@ckb-lumos/codec';
import { key } from '@ckb-lumos/hd';
import { parseAddress, TransactionSkeletonObject } from '@ckb-lumos/helpers';
import { commons, helpers } from '@ckb-lumos/lumos';
import { BI, commons, helpers } from '@ckb-lumos/lumos';
import { BtcAsset, ChainType, EosAsset, EthAsset, TronAsset } from '@force-bridge/x/dist/ckb/model/asset';
import { getOwnerTypeHash } from '@force-bridge/x/dist/ckb/tx-helper/multisig/multisig_helper';
import { ForceBridgeCore } from '@force-bridge/x/dist/core';
Expand All @@ -14,7 +15,6 @@ import {
} from '@force-bridge/x/dist/multisig/multisig-mgr';
import { verifyCollector } from '@force-bridge/x/dist/multisig/utils';
import { compareCkbAddress } from '@force-bridge/x/dist/utils';
import { Amount } from '@lay2/pw-core';
import { SigError, SigErrorCode, SigErrorOk } from './error';
import { SigResponse, SigServer } from './sigServer';

Expand Down Expand Up @@ -213,7 +213,7 @@ async function verifyEthMintRecords(records: mintRecord[]): Promise<SigError> {

async function verifyEthMintTx(mintRecord: mintRecord, output: Cell): Promise<SigError> {
const ownerTypeHash = getOwnerTypeHash();
const amount = new Amount(mintRecord.amount, 0);
const amount = BI.from(mintRecord.amount);
const asset = new EthAsset(mintRecord.asset, ownerTypeHash);
const recipientLockscript = parseAddress(mintRecord.recipientLockscript);
const bridgeCellLockscript = {
Expand Down Expand Up @@ -260,7 +260,7 @@ async function verifyEthMintTx(mintRecord: mintRecord, output: Cell): Promise<Si
return new SigError(SigErrorCode.InvalidRecord, `typescript args:${typeScript.args} doesn't with ${sudtArgs}`);
}

const data = amount.toUInt128LE();
const data = bytes.hexify(number.Uint128LE.pack(amount));
if (data !== output.data) {
return new SigError(SigErrorCode.InvalidRecord, `data:${output.data} doesn't with ${data}`);
}
Expand Down
2 changes: 1 addition & 1 deletion offchain-modules/packages/ckb-indexer-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"axios": "^0.21.1"
"axios": "0.21.1"
}
}
2 changes: 1 addition & 1 deletion offchain-modules/packages/keystore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"key-store": "^1.2.0"
"key-store": "1.2.0"
}
}
2 changes: 1 addition & 1 deletion offchain-modules/packages/reconc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"access": "public"
},
"dependencies": {
"bignumber.js": "^9.0.1"
"bignumber.js": "9.0.1"
}
}
Loading

0 comments on commit da049f8

Please sign in to comment.