From 435b68e05ec658641c8660924823f9bcd40de6ef Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Fri, 16 Aug 2024 19:05:20 +0800 Subject: [PATCH 1/6] add subcommand aggregator. --- .dockerignore | 1 + .gitignore | 1 + Makefile | 2 +- .../src/transaction/leap.rs | 1 - ckb-bin/src/lib.rs | 1 + ckb-bin/src/subcommand/aggregator.rs | 8 + ckb-bin/src/subcommand/init.rs | 6 +- ckb-bin/src/subcommand/mod.rs | 2 + resource/build.rs | 1 + resource/ckb-aggregator.toml | 199 ++++++++++++++++++ resource/src/lib.rs | 14 ++ util/app-config/src/app_config.rs | 107 +++++++++- util/app-config/src/args.rs | 8 +- util/app-config/src/cli.rs | 7 + util/app-config/src/legacy/mod.rs | 54 +++++ util/app-config/src/lib.rs | 20 +- 16 files changed, 418 insertions(+), 14 deletions(-) create mode 100644 ckb-bin/src/subcommand/aggregator.rs create mode 100644 resource/ckb-aggregator.toml diff --git a/.dockerignore b/.dockerignore index 722d2c117d..60c632efa4 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ README.md ckb.toml ckb-miner.toml +ckb-aggregator.toml target/ data/ specs/ diff --git a/.gitignore b/.gitignore index d943ec4450..ab9d230dad 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,7 @@ tags # runtime folder /ckb.toml /ckb-miner.toml +/ckb-aggregator.toml /default.db-options /data /specs diff --git a/Makefile b/Makefile index 7eedf87a76..43f30ce2e0 100644 --- a/Makefile +++ b/Makefile @@ -273,7 +273,7 @@ ${GEN_MOL_OUT_DIR}/protocols.rs: ${GEN_MOL_IN_DIR}/protocols.mol ##@ Cleanup .PHONY: clean-node-files clean-node-files: ## Clean files generated by `ckb init` - rm -rf ckb.toml ckb-miner.toml default.db-options specs/ data/ + rm -rf ckb.toml ckb-miner.toml ckb-aggregator.toml default.db-options specs/ data/ ##@ Helpers .PHONY: stats diff --git a/branch-chain-aggregator/src/transaction/leap.rs b/branch-chain-aggregator/src/transaction/leap.rs index e40d9c35f6..a3c7b5fcb0 100644 --- a/branch-chain-aggregator/src/transaction/leap.rs +++ b/branch-chain-aggregator/src/transaction/leap.rs @@ -270,7 +270,6 @@ impl Aggregator { OutPoint::from_slice(&witness_input_type.raw_data()).map_err(|e| { Error::TransactionParseError(format!("get queue from witness error: {}", e)) })?; - info!("Found message queue in leap tx witness"); Ok((queue_out_point, tx_hash)) } diff --git a/ckb-bin/src/lib.rs b/ckb-bin/src/lib.rs index f959724667..33edea3388 100644 --- a/ckb-bin/src/lib.rs +++ b/ckb-bin/src/lib.rs @@ -130,6 +130,7 @@ fn run_app_inner( let ret = match cmd { cli::CMD_RUN => subcommand::run(setup.run(matches)?, version, handle.clone()), cli::CMD_MINER => subcommand::miner(setup.miner(matches)?, handle.clone()), + cli::CMD_AGGREGATOR => subcommand::aggregator(setup.aggregator(matches)?, handle.clone()), cli::CMD_REPLAY => subcommand::replay(setup.replay(matches)?, handle.clone()), cli::CMD_EXPORT => subcommand::export(setup.export(matches)?, handle.clone()), cli::CMD_IMPORT => subcommand::import(setup.import(matches)?, handle.clone()), diff --git a/ckb-bin/src/subcommand/aggregator.rs b/ckb-bin/src/subcommand/aggregator.rs new file mode 100644 index 0000000000..db583f0b95 --- /dev/null +++ b/ckb-bin/src/subcommand/aggregator.rs @@ -0,0 +1,8 @@ +use ckb_app_config::{AggregatorArgs, ExitCode}; +use ckb_async_runtime::Handle; +use ckb_logger::info; + +pub fn aggregator(_args: AggregatorArgs, _async_handle: Handle) -> Result<(), ExitCode> { + info!("Starting aggregator..."); + Ok(()) +} diff --git a/ckb-bin/src/subcommand/init.rs b/ckb-bin/src/subcommand/init.rs index 2cdcc13b26..a90d1af67a 100644 --- a/ckb-bin/src/subcommand/init.rs +++ b/ckb-bin/src/subcommand/init.rs @@ -7,8 +7,8 @@ use ckb_app_config::{cli, AppConfig, ExitCode, InitArgs}; use ckb_chain_spec::ChainSpec; use ckb_jsonrpc_types::ScriptHashType; use ckb_resource::{ - Resource, TemplateContext, AVAILABLE_SPECS, CKB_CONFIG_FILE_NAME, DB_OPTIONS_FILE_NAME, - MINER_CONFIG_FILE_NAME, SPEC_DEV_FILE_NAME, + Resource, TemplateContext, AGGREGATOR_CONFIG_FILE_NAME, AVAILABLE_SPECS, CKB_CONFIG_FILE_NAME, + DB_OPTIONS_FILE_NAME, MINER_CONFIG_FILE_NAME, SPEC_DEV_FILE_NAME, }; use ckb_types::{prelude::*, H256}; @@ -201,6 +201,8 @@ pub fn init(args: InitArgs) -> Result<(), ExitCode> { Resource::bundled_ckb_config().export(&context, &args.root_dir)?; println!("Create {MINER_CONFIG_FILE_NAME}"); Resource::bundled_miner_config().export(&context, &args.root_dir)?; + println!("Create {AGGREGATOR_CONFIG_FILE_NAME}"); + Resource::bundled_aggregator_config().export(&context, &args.root_dir)?; println!("Create {DB_OPTIONS_FILE_NAME}"); Resource::bundled_db_options().export(&context, &args.root_dir)?; diff --git a/ckb-bin/src/subcommand/mod.rs b/ckb-bin/src/subcommand/mod.rs index cc75d07be5..dd04966b96 100644 --- a/ckb-bin/src/subcommand/mod.rs +++ b/ckb-bin/src/subcommand/mod.rs @@ -1,3 +1,4 @@ +mod aggregator; #[cfg(not(target_os = "windows"))] mod daemon; mod export; @@ -12,6 +13,7 @@ mod reset_data; mod run; mod stats; +pub use self::aggregator::aggregator; #[cfg(not(target_os = "windows"))] pub use self::daemon::{check_process, daemon}; pub use self::export::export; diff --git a/resource/build.rs b/resource/build.rs index 42b0515c79..ff4e01583a 100644 --- a/resource/build.rs +++ b/resource/build.rs @@ -18,6 +18,7 @@ fn main() { for f in &[ "ckb.toml", "ckb-miner.toml", + "ckb-aggregator.toml", "default.db-options", "xudt_rce", ] { diff --git a/resource/ckb-aggregator.toml b/resource/ckb-aggregator.toml new file mode 100644 index 0000000000..650893fb50 --- /dev/null +++ b/resource/ckb-aggregator.toml @@ -0,0 +1,199 @@ +# Branch Chain built-in aggregator settings. + +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" } # {{ +# testnet => spec = { {spec_source} = "specs/testnet.toml" } +# mainnet => spec = { {spec_source} = "specs/mainnet.toml" } +# staging => spec = { {spec_source} = "specs/staging.toml" } +# integration => spec = { file = "specs/integration.toml" } +# }} + +[logger] +filter = "info" +color = true +log_to_file = true # {{ +# _ => log_to_file = {log_to_file} +# }} +log_to_stdout = true # {{ +# _ => log_to_stdout = {log_to_stdout} +# }} + +[sentry] +# set to blank to disable sentry error collection +dsn = "" # {{ +# testnet => dsn = "https://dda4f353e15f4b62800d273a2afe70c2@sentry.nervos.org/4" +# staging => dsn = "https://dda4f353e15f4b62800d273a2afe70c2@sentry.nervos.org/4" +# }} +# 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 + +[aggregator] +# RGB++ uri +rgbpp_uri = "https://testnet.ckb.dev" +rgbpp_ckb_provider_key_path = "../dev/rgbpp_ckb_provider_key" +rgbpp_queue_lock_key_path = "../dev/rgbpp_queue_lock_key" +rgbpp_custodian_lock_key_path = "../dev/rgbpp_custodian_lock_key" + +# Branch Chain +branch_uri = "http://localhost:8114" +branch_chain_capacity_provider_key_path = "../dev/branch_chain_capacity_provider_key" +branch_chain_token_manager_lock_key_path = "../dev/branch_chain_token_manager_key" + +[[aggregator.gbpp_scripts]] +script_name = "secp256k1_blake160" +script = ''' +{ + "args": "0x", + "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hash_type": "type" +} +''' +cell_dep = ''' +{ + "dep_type": "dep_group", + "out_point": { + "index": "0x0", + "tx_hash": "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37" + } +} +''' + +[[aggregator.rgbpp_scripts]] +script_name = "xudt" +script = ''' +{ + "args": "0x", + "code_hash": "0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb", + "hash_type": "type" +} +''' +cell_dep = ''' +{ + "dep_type": "code", + "out_point": { + "index": "0x0", + "tx_hash": "0xbf6fb538763efec2a70a6a3dcb7242787087e1030c4e7d86585bc63a9d337f5f" + } +} +''' + +[[aggregator.rgbpp_scripts]] +script_name = "request_lock" +script = ''' +{ + "args": "0x", + "code_hash": "0x2fca96b423bd2b4d0d4b5098bf7a3e74ea42c3f2e1bb6f973f7c1c68adfa3d9c", + "hash_type": "type" +} +''' +cell_dep = ''' +{ + "dep_type": "code", + "out_point": { + "index": "0x0", + "tx_hash": "0x79e7a69cf175cde1d8f4fd1f7f5c9792cf07b4099a4a75946393ac6616b7aa0b" + } +} +''' + +[[aggregator.rgbpp_scripts]] +script_name = "queue_type" +script = ''' +{ + "args": "0x4242", + "code_hash": "0x2da1e80cec3e553a76e22d826b63ce5f65d77622de48caa5a2fe724b0f9a18f2", + "hash_type": "type" +} +''' +cell_dep = ''' +{ + "dep_type": "code", + "out_point": { + "index": "0x0", + "tx_hash": "0xeb4614bc1d8b2aadb928758c77a07720f1794418d0257a61bac94240d4c21905" + } +} +''' + +[[aggregator.branch_scripts]] +script_name = "secp256k1_blake160" +script = ''' +{ + "args": "0x", + "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hash_type": "type" +} +''' +cell_dep = ''' +{ + "dep_type": "dep_group", + "out_point": { + "index": "0x0", + "tx_hash": "0x8cca9bc6626cd5bd9890e5468cee855b87943b1fa4c0db92c39ba4f0dd61b90c" + } +} +''' + +[[aggregator.branch_scripts]] +script_name = "xudt" +script = ''' +{ + "args": "0x", + "code_hash": "0x6283a479a3cf5d4276cd93594de9f1827ab9b55c7b05b3d28e4c2e0a696cfefd", + "hash_type": "type" +} +''' +cell_dep = ''' +{ + "dep_type": "code", + "out_point": { + "index": "0x5", + "tx_hash": "0xad501cf59dc57021e4e4879a5f54aff4fe91771685e9fcfa3896ecdbf0664ed4" + } +} +''' + +[[aggregator.rgbpp_assets]] +asset_name = "f091" +# Only the first is_capacity = true is valid; others should be treated as false +is_capacity = true +asset_id = "29b0b1a449b0e7fb08881e1d810a6abbedb119e9c4ffc76eebbc757fb214f091" +script = ''' +{ + "args": "0x562e4e8a2f64a3e9c24beb4b7dd002d0ad3b842d0cc77924328e36ad114e3ebe3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333", + "code_hash": "0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb", + "hash_type": "type" +} +''' + +[[aggregator.rgbpp_asset_locks]] +lock_hash = "562e4e8a2f64a3e9c24beb4b7dd002d0ad3b842d0cc77924328e36ad114e3ebe" +script = ''' +{ + "args": "0xf9a9ad51ed14936d33f7bb854aaefa5f47a3ccbd", + "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hash_type": "type" +} +''' + +[[aggregator.rgbpp_asset_locks]] +lock_hash = "3494ad80b80de5ce7bcbbbdac53d888666c576ea8a49b83ca108fc18641eb278" +script = ''' +{ + "args": "0x0dc39ff2d4da099fbd2613fdab8fe55f65e23143", + "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hash_type": "type" +} +''' \ No newline at end of file diff --git a/resource/src/lib.rs b/resource/src/lib.rs index eb29cf4b02..6973165d15 100644 --- a/resource/src/lib.rs +++ b/resource/src/lib.rs @@ -51,6 +51,8 @@ include!(concat!(env!("OUT_DIR"), "/code_hashes.rs")); pub const CKB_CONFIG_FILE_NAME: &str = "ckb.toml"; /// CKB miner config file name. pub const MINER_CONFIG_FILE_NAME: &str = "ckb-miner.toml"; +/// CKB aggregator config file name. +pub const AGGREGATOR_CONFIG_FILE_NAME: &str = "ckb-aggregator.toml"; /// The relative spec file path for the dev chain. pub const SPEC_DEV_FILE_NAME: &str = "specs/dev.toml"; /// The file name of the generated RocksDB options file. @@ -107,6 +109,13 @@ impl Resource { Resource::file_system(root_dir.as_ref().join(MINER_CONFIG_FILE_NAME)) } + /// Creates the CKB aggregator config file resource from the file system. + /// + /// It searches the file name `AGGREGATOR_CONFIG_FILE_NAME` in the directory `root_dir`. + pub fn aggregator_config>(root_dir: P) -> Resource { + Resource::file_system(root_dir.as_ref().join(AGGREGATOR_CONFIG_FILE_NAME)) + } + /// Creates the RocksDB options file resource from the file system. /// /// It searches the file name `DB_OPTIONS_FILE_NAME` in the directory `root_dir`. @@ -124,6 +133,11 @@ impl Resource { Resource::bundled(MINER_CONFIG_FILE_NAME.to_string()) } + /// Creates the bundled CKB aggregator config file resource. + pub fn bundled_aggregator_config() -> Resource { + Resource::bundled(AGGREGATOR_CONFIG_FILE_NAME.to_string()) + } + /// Creates the bundled RocksDB options file resource. pub fn bundled_db_options() -> Resource { Resource::bundled(DB_OPTIONS_FILE_NAME.to_string()) diff --git a/util/app-config/src/app_config.rs b/util/app-config/src/app_config.rs index 529e9162ab..1f9efcfb38 100644 --- a/util/app-config/src/app_config.rs +++ b/util/app-config/src/app_config.rs @@ -23,12 +23,14 @@ use super::{cli, legacy, ExitCode}; /// The parsed config file. /// -/// CKB process reads `ckb.toml` or `ckb-miner.toml`, depending what subcommand to be executed. +/// CKB process reads `ckb.toml`, `ckb-miner.toml` or `ckb-aggregator.toml`, depending what subcommand to be executed. pub enum AppConfig { /// The parsed `ckb.toml.` CKB(Box), /// The parsed `ckb-miner.toml.` Miner(Box), + /// The parsed `ckb-aggregator.toml.` + Aggregator(Box), } /// The main config file for the most subcommands. Usually it is the `ckb.toml` in the CKB root @@ -134,6 +136,41 @@ pub struct MinerAppConfig { pub miner: MinerConfig, } +/// The aggregator config file for `ckb aggregator`. Usually it is the `ckb-aggregator.toml` in the CKB root +/// directory. +#[derive(Clone, Debug, Serialize)] +#[serde(deny_unknown_fields)] +pub struct AggregatorAppConfig { + /// The binary name. + #[serde(skip)] + pub bin_name: String, + /// The root directory. + #[serde(skip)] + pub root_dir: PathBuf, + /// The data directory. + pub data_dir: PathBuf, + /// Chain config options. + pub chain: ChainConfig, + /// Logger config options. + pub logger: LogConfig, + /// Sentry config options. + #[cfg(feature = "with_sentry")] + pub sentry: SentryConfig, + /// Metrics options. + /// + /// Developers can collect metrics for performance tuning and troubleshooting. + #[serde(default)] + pub metrics: MetricsConfig, + /// Memory tracker options. + /// + /// Developers can enable memory tracker to analyze the process memory usage. + #[serde(default)] + pub memory_tracker: MemoryTrackerConfig, + + /// The aggregator config options. + pub aggregator: AggregatorConfig, +} + /// The chain config options. #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(deny_unknown_fields)] @@ -145,8 +182,9 @@ pub struct ChainConfig { impl AppConfig { /// Reads the config file for the subcommand. /// - /// This will reads the `ckb-miner.toml` in the CKB directory for `ckb miner`, and `ckb.toml` - /// for all other subcommands. + /// This will reads the `ckb-miner.toml` in the CKB directory for `ckb miner`, + /// `ckb-aggregator.toml` for `ckb aggregator`, + /// and `ckb.toml` for all other subcommands. pub fn load_for_subcommand>( root_dir: P, subcommand_name: &str, @@ -160,6 +198,14 @@ impl AppConfig { config.derive_options(root_dir.as_ref())?, )) } + cli::CMD_AGGREGATOR => { + let resource = ensure_ckb_dir(Resource::aggregator_config(root_dir.as_ref()))?; + let config = AggregatorAppConfig::load_from_slice(&resource.get()?)?; + + Ok(AppConfig::with_aggregator( + config.derive_options(root_dir.as_ref())?, + )) + } _ => { let resource = ensure_ckb_dir(Resource::ckb_config(root_dir.as_ref()))?; let config = CKBAppConfig::load_from_slice(&resource.get()?)?; @@ -176,6 +222,7 @@ impl AppConfig { match self { AppConfig::CKB(config) => &config.logger, AppConfig::Miner(config) => &config.logger, + AppConfig::Aggregator(config) => &config.logger, } } @@ -185,6 +232,7 @@ impl AppConfig { match self { AppConfig::CKB(config) => &config.sentry, AppConfig::Miner(config) => &config.sentry, + AppConfig::Aggregator(config) => &config.sentry, } } @@ -193,6 +241,7 @@ impl AppConfig { match self { AppConfig::CKB(config) => &config.metrics, AppConfig::Miner(config) => &config.metrics, + AppConfig::Aggregator(config) => &config.metrics, } } @@ -201,6 +250,7 @@ impl AppConfig { match self { AppConfig::CKB(config) => &config.memory_tracker, AppConfig::Miner(config) => &config.memory_tracker, + AppConfig::Aggregator(config) => &config.memory_tracker, } } @@ -209,6 +259,7 @@ impl AppConfig { let spec_resource = match self { AppConfig::CKB(config) => &config.chain.spec, AppConfig::Miner(config) => &config.chain.spec, + AppConfig::Aggregator(config) => &config.chain.spec, }; ChainSpec::load_from(spec_resource).map_err(|err| { eprintln!("{err}"); @@ -218,7 +269,7 @@ impl AppConfig { /// Unpacks the parsed ckb.toml config file. /// - /// Panics when this is a parsed ckb-miner.toml. + /// Panics when this is a parsed ckb-miner.toml or ckb-aggregator.toml. pub fn into_ckb(self) -> Result, ExitCode> { match self { AppConfig::CKB(config) => Ok(config), @@ -231,7 +282,7 @@ impl AppConfig { /// Unpacks the parsed ckb-miner.toml config file. /// - /// Panics when this is a parsed ckb.toml. + /// Panics when this is a parsed ckb.toml or ckb-aggregator.toml. pub fn into_miner(self) -> Result, ExitCode> { match self { AppConfig::Miner(config) => Ok(config), @@ -242,11 +293,25 @@ impl AppConfig { } } + /// Unpacks the parsed ckb-aggregator.toml config file. + /// + /// Panics when this is a parsed ckb.toml or ckb-miner.toml. + pub fn into_aggregator(self) -> Result, ExitCode> { + match self { + AppConfig::Aggregator(config) => Ok(config), + _ => { + eprintln!("Unmatched config file"); + Err(ExitCode::Failure) + } + } + } + /// Set the binary name with full path. pub fn set_bin_name(&mut self, bin_name: String) { match self { AppConfig::CKB(config) => config.bin_name = bin_name, AppConfig::Miner(config) => config.bin_name = bin_name, + AppConfig::Aggregator(config) => config.bin_name = bin_name, } } } @@ -258,6 +323,9 @@ impl AppConfig { fn with_miner(config: MinerAppConfig) -> AppConfig { AppConfig::Miner(Box::new(config)) } + fn with_aggregator(config: AggregatorAppConfig) -> AppConfig { + AppConfig::Aggregator(Box::new(config)) + } } impl CKBAppConfig { @@ -352,6 +420,35 @@ impl MinerAppConfig { } } +impl AggregatorAppConfig { + /// Load a new instance from a file. + pub fn load_from_slice(slice: &[u8]) -> Result { + let legacy_config: legacy::AggregatorAppConfig = toml::from_slice(slice)?; + for field in legacy_config.deprecated_fields() { + eprintln!( + "WARN: the option \"{}\" in configuration files is deprecated since v{}.", + field.path, field.since + ); + } + Ok(legacy_config.into()) + } + + fn derive_options(mut self, root_dir: &Path) -> Result { + self.root_dir = root_dir.to_path_buf(); + + self.data_dir = mkdir(canonicalize_data_dir(self.data_dir, root_dir))?; + self.logger.log_dir = self.data_dir.join("logs"); + self.logger.file = Path::new("aggregator.log").to_path_buf(); + if self.logger.log_to_file { + mkdir(self.logger.log_dir.clone())?; + touch(self.logger.log_dir.join(&self.logger.file))?; + } + self.chain.spec.absolutize(root_dir); + + Ok(self) + } +} + fn canonicalize_data_dir(data_dir: PathBuf, root_dir: &Path) -> PathBuf { if data_dir.is_absolute() { data_dir diff --git a/util/app-config/src/args.rs b/util/app-config/src/args.rs index e12ac4be45..6499f7e6a9 100644 --- a/util/app-config/src/args.rs +++ b/util/app-config/src/args.rs @@ -1,4 +1,4 @@ -use crate::{CKBAppConfig, MemoryTrackerConfig, MinerConfig}; +use crate::{AggregatorConfig, CKBAppConfig, MemoryTrackerConfig, MinerConfig}; use ckb_chain_spec::consensus::Consensus; use ckb_jsonrpc_types::ScriptHashType; use ckb_pow::PowEngine; @@ -95,6 +95,12 @@ pub struct MinerArgs { pub limit: u128, } +/// Parsed command line arguments for `ckb aggregator`. +pub struct AggregatorArgs { + /// Parsed `ckb-aggregator.toml`. + pub config: AggregatorConfig, +} + /// Parsed command line arguments for `ckb stats`. pub struct StatsArgs { /// Parsed `ckb.toml`. diff --git a/util/app-config/src/cli.rs b/util/app-config/src/cli.rs index 4a31dd93a8..ec009ddbbc 100644 --- a/util/app-config/src/cli.rs +++ b/util/app-config/src/cli.rs @@ -10,6 +10,8 @@ pub const BIN_NAME: &str = "ckb"; pub const CMD_RUN: &str = "run"; /// Subcommand `miner`. pub const CMD_MINER: &str = "miner"; +/// Subcommand `aggregator`. +pub const CMD_AGGREGATOR: &str = "aggregator"; /// Subcommand `export`. pub const CMD_EXPORT: &str = "export"; /// Subcommand `import`. @@ -146,6 +148,7 @@ pub fn basic_app() -> Command { ) .subcommand(run()) .subcommand(miner()) + .subcommand(aggregator()) .subcommand(export()) .subcommand(import()) .subcommand(list_hashes()) @@ -256,6 +259,10 @@ fn miner() -> Command { ) } +fn aggregator() -> Command { + Command::new(CMD_AGGREGATOR).about("Runs Branch aggregator") +} + fn reset_data() -> Command { Command::new(CMD_RESET_DATA) .about( diff --git a/util/app-config/src/legacy/mod.rs b/util/app-config/src/legacy/mod.rs index c322fe4978..faec9eb2fa 100644 --- a/util/app-config/src/legacy/mod.rs +++ b/util/app-config/src/legacy/mod.rs @@ -83,6 +83,26 @@ pub(crate) struct MinerAppConfig { miner: crate::MinerConfig, } +#[derive(Clone, Debug, Deserialize)] +#[serde(deny_unknown_fields)] +pub(crate) struct AggregatorAppConfig { + data_dir: PathBuf, + chain: crate::ChainConfig, + logger: crate::LogConfig, + + #[cfg(feature = "with_sentry")] + sentry: crate::SentryConfig, + #[cfg(not(feature = "with_sentry"))] + #[serde(default)] + sentry: serde_json::Value, + + #[serde(default)] + metrics: crate::MetricsConfig, + #[serde(default)] + memory_tracker: crate::MemoryTrackerConfig, + aggregator: crate::AggregatorConfig, +} + // // The conversion which convert legacy structs to latest structs. // @@ -167,6 +187,34 @@ impl From for crate::MinerAppConfig { } } +impl From for crate::AggregatorAppConfig { + fn from(input: AggregatorAppConfig) -> Self { + let AggregatorAppConfig { + data_dir, + chain, + logger, + sentry, + metrics, + memory_tracker, + aggregator, + } = input; + #[cfg(not(feature = "with_sentry"))] + let _ = sentry; + Self { + bin_name: cli::BIN_NAME.to_owned(), + root_dir: Default::default(), + data_dir, + chain, + logger, + #[cfg(feature = "with_sentry")] + sentry, + metrics, + memory_tracker, + aggregator, + } + } +} + // // The core functions. // @@ -209,3 +257,9 @@ impl MinerAppConfig { Vec::new() } } + +impl AggregatorAppConfig { + pub(crate) fn deprecated_fields(&self) -> Vec { + Vec::new() + } +} diff --git a/util/app-config/src/lib.rs b/util/app-config/src/lib.rs index 02110816aa..e0e3c11685 100644 --- a/util/app-config/src/lib.rs +++ b/util/app-config/src/lib.rs @@ -12,11 +12,12 @@ mod sentry_config; mod tests; pub use app_config::{ - AppConfig, CKBAppConfig, ChainConfig, LogConfig, MetricsConfig, MinerAppConfig, + AggregatorAppConfig, AppConfig, CKBAppConfig, ChainConfig, LogConfig, MetricsConfig, + MinerAppConfig, }; pub use args::{ - DaemonArgs, ExportArgs, ImportArgs, InitArgs, MigrateArgs, MinerArgs, PeerIDArgs, ReplayArgs, - ResetDataArgs, RunArgs, StatsArgs, + AggregatorArgs, DaemonArgs, ExportArgs, ImportArgs, InitArgs, MigrateArgs, MinerArgs, + PeerIDArgs, ReplayArgs, ResetDataArgs, RunArgs, StatsArgs, }; use ckb_logger::info; pub use configs::*; @@ -165,6 +166,14 @@ impl Setup { }) } + /// Executes `ckb aggregator`. + pub fn aggregator(self, _matches: &ArgMatches) -> Result { + let config = self.config.into_aggregator()?; + Ok(AggregatorArgs { + config: config.aggregator, + }) + } + /// Executes `ckb replay`. pub fn replay(self, matches: &ArgMatches) -> Result { let consensus = self.consensus()?; @@ -479,7 +488,10 @@ impl Setup { #[cfg(feature = "with_sentry")] fn is_daemon(subcommand_name: &str) -> bool { - matches!(subcommand_name, cli::CMD_RUN | cli::CMD_MINER) + matches!( + subcommand_name, + cli::CMD_RUN | cli::CMD_MINER | cli::CMD_AGGREGATOR + ) } fn consensus_from_spec(spec: &ChainSpec) -> Result { From a8f3d203024b382b9b822d7488a4f470cb2a09b2 Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Sat, 17 Aug 2024 10:34:35 +0800 Subject: [PATCH 2/6] aggregator separation. --- Cargo.lock | 1 + ckb-bin/Cargo.toml | 1 + ckb-bin/src/lib.rs | 3 ++- ckb-bin/src/subcommand/aggregator.rs | 19 +++++++++++++++++-- util/app-config/src/app_config.rs | 4 ++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b248696fd4..9d702bc9e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -717,6 +717,7 @@ name = "ckb-bin" version = "0.116.1" dependencies = [ "base64 0.21.7", + "branch-chain-aggregator", "ckb-app-config", "ckb-async-runtime", "ckb-build-info", diff --git a/ckb-bin/Cargo.toml b/ckb-bin/Cargo.toml index ba3774a679..3892e4aa60 100644 --- a/ckb-bin/Cargo.toml +++ b/ckb-bin/Cargo.toml @@ -38,6 +38,7 @@ ckb-verification-traits = { path = "../verification/traits", version = "= 0.116. ckb-async-runtime = { path = "../util/runtime", version = "= 0.116.1" } ckb-migrate = { path = "../util/migrate", version = "= 0.116.1" } ckb-launcher = { path = "../util/launcher", version = "= 0.116.1" } +branch-chain-aggregator = { path = "../branch-chain-aggregator", version = "= 0.1.0" } base64 = "0.21.0" tempfile.workspace = true rayon = "1.0" diff --git a/ckb-bin/src/lib.rs b/ckb-bin/src/lib.rs index 33edea3388..15c40ad8a9 100644 --- a/ckb-bin/src/lib.rs +++ b/ckb-bin/src/lib.rs @@ -123,6 +123,7 @@ fn run_app_inner( let is_silent_logging = is_silent_logging(cmd); let (mut handle, mut handle_stop_rx, _runtime) = new_global_runtime(); let setup = Setup::from_matches(bin_name, cmd, matches)?; + let chain_id = setup.consensus()?.clone().identify_name(); let _guard = SetupGuard::from_setup(&setup, &version, handle.clone(), is_silent_logging)?; raise_fd_limit(); @@ -130,7 +131,7 @@ fn run_app_inner( let ret = match cmd { cli::CMD_RUN => subcommand::run(setup.run(matches)?, version, handle.clone()), cli::CMD_MINER => subcommand::miner(setup.miner(matches)?, handle.clone()), - cli::CMD_AGGREGATOR => subcommand::aggregator(setup.aggregator(matches)?, handle.clone()), + cli::CMD_AGGREGATOR => subcommand::aggregator(setup.aggregator(matches)?, chain_id), cli::CMD_REPLAY => subcommand::replay(setup.replay(matches)?, handle.clone()), cli::CMD_EXPORT => subcommand::export(setup.export(matches)?, handle.clone()), cli::CMD_IMPORT => subcommand::import(setup.import(matches)?, handle.clone()), diff --git a/ckb-bin/src/subcommand/aggregator.rs b/ckb-bin/src/subcommand/aggregator.rs index db583f0b95..27523bab69 100644 --- a/ckb-bin/src/subcommand/aggregator.rs +++ b/ckb-bin/src/subcommand/aggregator.rs @@ -1,8 +1,23 @@ +use branch_chain_aggregator::Aggregator; use ckb_app_config::{AggregatorArgs, ExitCode}; -use ckb_async_runtime::Handle; use ckb_logger::info; +use ckb_stop_handler::{broadcast_exit_signals, wait_all_ckb_services_exit}; -pub fn aggregator(_args: AggregatorArgs, _async_handle: Handle) -> Result<(), ExitCode> { +use std::time::Duration; + +pub fn aggregator(args: AggregatorArgs, chain_id: String) -> Result<(), ExitCode> { info!("Starting aggregator..."); + let aggregator = Aggregator::new(args.config, Duration::from_secs(2), chain_id); + aggregator.run(); + + info!("Branch Aggregator service started ..."); + ctrlc::set_handler(|| { + info!("Trapped exit signal, exiting..."); + broadcast_exit_signals(); + }) + .expect("Error setting Ctrl-C handler"); + + wait_all_ckb_services_exit(); + Ok(()) } diff --git a/util/app-config/src/app_config.rs b/util/app-config/src/app_config.rs index 1f9efcfb38..60ec1133df 100644 --- a/util/app-config/src/app_config.rs +++ b/util/app-config/src/app_config.rs @@ -437,6 +437,10 @@ impl AggregatorAppConfig { self.root_dir = root_dir.to_path_buf(); self.data_dir = mkdir(canonicalize_data_dir(self.data_dir, root_dir))?; + + let branch_chain_path = mkdir(self.data_dir.join("branch_chain"))?; + self.aggregator.adjust(root_dir, branch_chain_path); + self.logger.log_dir = self.data_dir.join("logs"); self.logger.file = Path::new("aggregator.log").to_path_buf(); if self.logger.log_to_file { From d77f8eded8d4ff6bb582a2c33c9770568ac4a59e Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Sat, 17 Aug 2024 10:40:13 +0800 Subject: [PATCH 3/6] remove legacy aggregator run in ckb launcher. --- Cargo.lock | 1 - util/app-config/src/app_config.rs | 6 ------ util/app-config/src/legacy/mod.rs | 4 ---- util/launcher/Cargo.toml | 1 - util/launcher/src/lib.rs | 10 ---------- 5 files changed, 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d702bc9e8..b539fd0d9e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1208,7 +1208,6 @@ dependencies = [ name = "ckb-launcher" version = "0.116.1" dependencies = [ - "branch-chain-aggregator", "branch-chain-producer", "ckb-app-config", "ckb-async-runtime", diff --git a/util/app-config/src/app_config.rs b/util/app-config/src/app_config.rs index 60ec1133df..fa5caa5f54 100644 --- a/util/app-config/src/app_config.rs +++ b/util/app-config/src/app_config.rs @@ -94,9 +94,6 @@ pub struct CKBAppConfig { /// Indexer config options. #[serde(default)] pub indexer: IndexerConfig, - /// Branch config options. - #[serde(default)] - pub aggregator: AggregatorConfig, } /// The miner config file for `ckb miner`. Usually it is the `ckb-miner.toml` in the CKB root @@ -368,9 +365,6 @@ impl CKBAppConfig { let indexer_path = mkdir(self.data_dir.join("indexer"))?; self.indexer.adjust(root_dir, indexer_path); - let branch_chain_path = mkdir(self.data_dir.join("branch_chain"))?; - self.aggregator.adjust(root_dir, branch_chain_path); - if subcommand_name == cli::CMD_RESET_DATA { return Ok(self); } diff --git a/util/app-config/src/legacy/mod.rs b/util/app-config/src/legacy/mod.rs index faec9eb2fa..227aa8c2f3 100644 --- a/util/app-config/src/legacy/mod.rs +++ b/util/app-config/src/legacy/mod.rs @@ -59,8 +59,6 @@ pub(crate) struct CKBAppConfig { notify: crate::NotifyConfig, #[serde(default)] indexer_v2: crate::IndexerConfig, - #[serde(default)] - aggregator: crate::AggregatorConfig, } #[derive(Clone, Debug, Deserialize)] @@ -128,7 +126,6 @@ impl From for crate::CKBAppConfig { alert_signature, notify, indexer_v2, - aggregator, } = input; #[cfg(not(feature = "with_sentry"))] let _ = sentry; @@ -154,7 +151,6 @@ impl From for crate::CKBAppConfig { alert_signature, notify, indexer: indexer_v2, - aggregator, } } } diff --git a/util/launcher/Cargo.toml b/util/launcher/Cargo.toml index a78de216a1..adbf9cc4f9 100644 --- a/util/launcher/Cargo.toml +++ b/util/launcher/Cargo.toml @@ -33,7 +33,6 @@ ckb-tx-pool = { path = "../../tx-pool", version = "= 0.116.1" } ckb-light-client-protocol-server = { path = "../light-client-protocol-server", version = "= 0.116.1" } ckb-block-filter = { path = "../../block-filter", version = "= 0.116.1" } branch-chain-producer = { path = "../../branch-chain-producer", version = "= 0.1.0" } -branch-chain-aggregator = { path = "../../branch-chain-aggregator", version = "= 0.1.0" } [features] with_sentry = [ "ckb-sync/with_sentry", "ckb-network/with_sentry", "ckb-app-config/with_sentry" ] diff --git a/util/launcher/src/lib.rs b/util/launcher/src/lib.rs index 01a6e0b5a2..f58439cf1b 100644 --- a/util/launcher/src/lib.rs +++ b/util/launcher/src/lib.rs @@ -2,7 +2,6 @@ //! //! ckb launcher is helps to launch ckb node. -use branch_chain_aggregator::Aggregator; use ckb_app_config::{ BlockAssemblerConfig, ExitCode, RpcConfig, RpcModule, RunArgs, SupportProtocol, }; @@ -403,15 +402,6 @@ impl Launcher { ); block_producer.produce_blocks_on_schedule(); - // Branch Chain Aggregator - let aggregator_config = self.args.config.aggregator.clone(); - let aggregator = Aggregator::new( - aggregator_config, - Duration::from_secs(2), - shared.consensus().identify_name(), - ); - aggregator.run(); - let rpc_config = self.adjust_rpc_config(); let mut builder = ServiceBuilder::new(&rpc_config) .enable_chain(shared.clone()) From 5a0921513017d3e66f3739659cee04bc0930ef8b Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Sat, 17 Aug 2024 11:03:36 +0800 Subject: [PATCH 4/6] refactoring --- Cargo.lock | 1 + branch-chain-aggregator/Cargo.toml | 1 + branch-chain-aggregator/src/lib.rs | 146 ++++++++++++--------------- ckb-bin/src/subcommand/aggregator.rs | 19 +++- 4 files changed, 84 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b539fd0d9e..a331a4d46e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -401,6 +401,7 @@ version = "0.1.0" dependencies = [ "ckb-app-config", "ckb-async-runtime", + "ckb-channel 0.116.1", "ckb-gen-types 0.116.1 (registry+https://github.com/rust-lang/crates.io-index)", "ckb-hash 0.116.1 (registry+https://github.com/rust-lang/crates.io-index)", "ckb-jsonrpc-types 0.116.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/branch-chain-aggregator/Cargo.toml b/branch-chain-aggregator/Cargo.toml index 31029eb867..d7753907c4 100644 --- a/branch-chain-aggregator/Cargo.toml +++ b/branch-chain-aggregator/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" [dependencies] ckb-app-config = { path = "../util/app-config", version = "= 0.116.1" } ckb-async-runtime = { path = "../util/runtime", version = "= 0.116.1" } +ckb-channel = { path = "../util/channel", version = "= 0.116.1" } ckb-logger = { path = "../util/logger", version = "= 0.116.1" } ckb-stop-handler = { path = "../util/stop-handler", version = "= 0.116.1" } diff --git a/branch-chain-aggregator/src/lib.rs b/branch-chain-aggregator/src/lib.rs index 2246618cfa..5eb27bf93f 100644 --- a/branch-chain-aggregator/src/lib.rs +++ b/branch-chain-aggregator/src/lib.rs @@ -16,6 +16,7 @@ use crate::utils::{ }; use ckb_app_config::{AggregatorConfig, AssetConfig, LockConfig, ScriptConfig}; +use ckb_channel::Receiver; use ckb_logger::{error, info, warn}; use ckb_sdk::traits::LiveCell; use ckb_sdk::{ @@ -24,9 +25,7 @@ use ckb_sdk::{ traits::{CellQueryOptions, MaturityOption, PrimaryScriptType, QueryOrder}, Since, SinceType, }; -use ckb_stop_handler::{ - new_crossbeam_exit_rx, new_tokio_exit_rx, register_thread, CancellationToken, -}; +use ckb_stop_handler::{new_tokio_exit_rx, CancellationToken}; use ckb_types::H256; use ckb_types::{ bytes::Bytes, @@ -42,7 +41,6 @@ use std::thread; use std::thread::sleep; use std::time::Duration; -const THREAD_NAME: &str = "Aggregator"; const CKB_FEE_RATE_LIMIT: u64 = 5000; const CONFIRMATION_THRESHOLD: u64 = 24; /// @@ -98,86 +96,74 @@ impl Aggregator { } /// Run the Aggregator - pub fn run(&self) { - info!("chain id: {}", self.chain_id); - - // Setup cancellation token - let stop_rx = new_crossbeam_exit_rx(); + pub fn run(&self, stop_rx: Receiver<()>) { let poll_interval = self.poll_interval; let poll_service: Aggregator = self.clone(); - let aggregator_jh = thread::Builder::new() - .name(THREAD_NAME.into()) - .spawn(move || { - loop { - match stop_rx.try_recv() { - Ok(_) => { - info!("Aggregator received exit signal, stopped"); - break; - } - Err(crossbeam_channel::TryRecvError::Empty) => { - // No exit signal, continue execution - } - Err(_) => { - info!("Error receiving exit signal"); - break; - } - } - - // get queue data - let rgbpp_requests = poll_service.get_rgbpp_queue_requests(); - let (rgbpp_requests, queue_cell) = match rgbpp_requests { - Ok((rgbpp_requests, queue_cell)) => (rgbpp_requests, queue_cell), - Err(e) => { - error!("get RGB++ queue data error: {}", e.to_string()); - continue; - } - }; - - let leap_tx = - poll_service.create_leap_tx(rgbpp_requests.clone(), queue_cell.clone()); - let leap_tx = match leap_tx { - Ok(leap_tx) => leap_tx, - Err(e) => { - error!("create leap transaction error: {}", e.to_string()); - continue; - } - }; - match wait_for_tx_confirmation( - poll_service.rgbpp_rpc_client.clone(), - leap_tx, - Duration::from_secs(600), - ) { - Ok(()) => {} - Err(e) => error!("{}", e.to_string()), - } - - let update_queue_tx = - poll_service.create_clear_queue_tx(rgbpp_requests, queue_cell); - let update_queue_tx = match update_queue_tx { - Ok(update_queue_tx) => update_queue_tx, - Err(e) => { - error!("{}", e.to_string()); - continue; - } - }; - match wait_for_tx_confirmation( - poll_service.rgbpp_rpc_client.clone(), - update_queue_tx, - Duration::from_secs(600), - ) { - Ok(()) => {} - Err(e) => error!("{}", e.to_string()), - } - - if let Err(e) = poll_service.scan_rgbpp_request() { - info!("Aggregator: {:?}", e); - } - thread::sleep(poll_interval); + loop { + match stop_rx.try_recv() { + Ok(_) => { + info!("Aggregator received exit signal, stopped"); + break; } - }) - .expect("Start aggregator failed!"); - register_thread(THREAD_NAME, aggregator_jh); + Err(crossbeam_channel::TryRecvError::Empty) => { + // No exit signal, continue execution + } + Err(_) => { + info!("Error receiving exit signal"); + break; + } + } + + // get queue data + let rgbpp_requests = poll_service.get_rgbpp_queue_requests(); + let (rgbpp_requests, queue_cell) = match rgbpp_requests { + Ok((rgbpp_requests, queue_cell)) => (rgbpp_requests, queue_cell), + Err(e) => { + error!("get RGB++ queue data error: {}", e.to_string()); + continue; + } + }; + + let leap_tx = poll_service.create_leap_tx(rgbpp_requests.clone(), queue_cell.clone()); + let leap_tx = match leap_tx { + Ok(leap_tx) => leap_tx, + Err(e) => { + error!("create leap transaction error: {}", e.to_string()); + continue; + } + }; + match wait_for_tx_confirmation( + poll_service.rgbpp_rpc_client.clone(), + leap_tx, + Duration::from_secs(600), + ) { + Ok(()) => {} + Err(e) => error!("{}", e.to_string()), + } + + let update_queue_tx = poll_service.create_clear_queue_tx(rgbpp_requests, queue_cell); + let update_queue_tx = match update_queue_tx { + Ok(update_queue_tx) => update_queue_tx, + Err(e) => { + error!("{}", e.to_string()); + continue; + } + }; + match wait_for_tx_confirmation( + poll_service.rgbpp_rpc_client.clone(), + update_queue_tx, + Duration::from_secs(600), + ) { + Ok(()) => {} + Err(e) => error!("{}", e.to_string()), + } + + if let Err(e) = poll_service.scan_rgbpp_request() { + info!("Aggregator: {:?}", e); + } + thread::sleep(poll_interval); + } } fn scan_rgbpp_request(&self) -> Result<(), Error> { diff --git a/ckb-bin/src/subcommand/aggregator.rs b/ckb-bin/src/subcommand/aggregator.rs index 27523bab69..3236965716 100644 --- a/ckb-bin/src/subcommand/aggregator.rs +++ b/ckb-bin/src/subcommand/aggregator.rs @@ -1,14 +1,27 @@ use branch_chain_aggregator::Aggregator; use ckb_app_config::{AggregatorArgs, ExitCode}; use ckb_logger::info; -use ckb_stop_handler::{broadcast_exit_signals, wait_all_ckb_services_exit}; +use ckb_stop_handler::{ + broadcast_exit_signals, new_crossbeam_exit_rx, register_thread, wait_all_ckb_services_exit, +}; +use std::thread; use std::time::Duration; pub fn aggregator(args: AggregatorArgs, chain_id: String) -> Result<(), ExitCode> { - info!("Starting aggregator..."); + info!("chain id: {}", chain_id); + let aggregator = Aggregator::new(args.config, Duration::from_secs(2), chain_id); - aggregator.run(); + + let stop_rx = new_crossbeam_exit_rx(); + const THREAD_NAME: &str = "Aggregator"; + let aggregator_jh = thread::Builder::new() + .name(THREAD_NAME.into()) + .spawn(move || { + aggregator.run(stop_rx); + }) + .expect("Start aggregator failed!"); + register_thread(THREAD_NAME, aggregator_jh); info!("Branch Aggregator service started ..."); ctrlc::set_handler(|| { From dc906fc5be8a7e367dd3b33d83a5274e0c037318 Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Sat, 17 Aug 2024 11:06:38 +0800 Subject: [PATCH 5/6] remove branch config in ckb config. --- resource/ckb.toml | 149 ---------------------------------------------- 1 file changed, 149 deletions(-) diff --git a/resource/ckb.toml b/resource/ckb.toml index 8ae1d671ef..49cf93b2f1 100644 --- a/resource/ckb.toml +++ b/resource/ckb.toml @@ -216,152 +216,3 @@ block_uncles_cache_size = 30 # db_port = 5432 # db_user = "postgres" # db_password = "123456" - -# Branch Chain built-in aggregator settings. -[aggregator] -# RGB++ uri -rgbpp_uri = "https://testnet.ckb.dev" -rgbpp_ckb_provider_key_path = "../dev/rgbpp_ckb_provider_key" -rgbpp_queue_lock_key_path = "../dev/rgbpp_queue_lock_key" -rgbpp_custodian_lock_key_path = "../dev/rgbpp_custodian_lock_key" -# Branch Chain -branch_uri = "http://localhost:8114" -branch_chain_capacity_provider_key_path = "../dev/branch_chain_capacity_provider_key" -branch_chain_token_manager_lock_key_path = "../dev/branch_chain_token_manager_key" - -[[aggregator.rgbpp_scripts]] -script_name = "secp256k1_blake160" -script = ''' -{ - "args": "0x", - "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", - "hash_type": "type" -} -''' -cell_dep = ''' -{ - "dep_type": "dep_group", - "out_point": { - "index": "0x0", - "tx_hash": "0xf8de3bb47d055cdf460d93a2a6e1b05f7432f9777c8c474abf4eec1d4aee5d37" - } -} -''' - -[[aggregator.rgbpp_scripts]] -script_name = "xudt" -script = ''' -{ - "args": "0x", - "code_hash": "0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb", - "hash_type": "type" -} -''' -cell_dep = ''' -{ - "dep_type": "code", - "out_point": { - "index": "0x0", - "tx_hash": "0xbf6fb538763efec2a70a6a3dcb7242787087e1030c4e7d86585bc63a9d337f5f" - } -} -''' - -[[aggregator.rgbpp_scripts]] -script_name = "request_lock" -script = ''' -{ - "args": "0x", - "code_hash": "0x2fca96b423bd2b4d0d4b5098bf7a3e74ea42c3f2e1bb6f973f7c1c68adfa3d9c", - "hash_type": "type" -} -''' -cell_dep = ''' -{ - "dep_type": "code", - "out_point": { - "index": "0x0", - "tx_hash": "0x79e7a69cf175cde1d8f4fd1f7f5c9792cf07b4099a4a75946393ac6616b7aa0b" - } -} -''' - -[[aggregator.rgbpp_scripts]] -script_name = "queue_type" -script = ''' -{ - "args": "0x4242", - "code_hash": "0x2da1e80cec3e553a76e22d826b63ce5f65d77622de48caa5a2fe724b0f9a18f2", - "hash_type": "type" -} -''' -cell_dep = ''' -{ - "dep_type": "code", - "out_point": { - "index": "0x0", - "tx_hash": "0xeb4614bc1d8b2aadb928758c77a07720f1794418d0257a61bac94240d4c21905" - } -} -''' - -[[aggregator.branch_scripts]] -script_name = "secp256k1_blake160" -script = ''' -{ - "args": "0x", - "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", - "hash_type": "type" -} -''' -cell_dep = ''' -{ - "dep_type": "dep_group", - "out_point": { - "index": "0x0", - "tx_hash": "0x8cca9bc6626cd5bd9890e5468cee855b87943b1fa4c0db92c39ba4f0dd61b90c" - } -} -''' - -[[aggregator.branch_scripts]] -script_name = "xudt" -script = ''' -{ - "args": "0x", - "code_hash": "0x6283a479a3cf5d4276cd93594de9f1827ab9b55c7b05b3d28e4c2e0a696cfefd", - "hash_type": "type" -} -''' -cell_dep = ''' -{ - "dep_type": "code", - "out_point": { - "index": "0x5", - "tx_hash": "0xad501cf59dc57021e4e4879a5f54aff4fe91771685e9fcfa3896ecdbf0664ed4" - } -} -''' - -[[aggregator.rgbpp_assets]] -asset_name = "d7d6" -# Only the first is_capacity = true is valid; others should be treated as false -is_capacity = true -asset_id = "1e1e5f0d711c1b9a5231d49997ed1c0bf7d602de53d960770b1cb38f4e6fd7d6" -script = ''' -{ - "args": "0x737e3449341faf2704ff6883cd09d22639f71cc7f69aee10d6505eeef1474493", - "code_hash": "0x25c29dc317811a6f6f3985a7a9ebc4838bd388d19d0feeecf0bcd60f6c0975bb", - "hash_type": "type" -} -''' - -[[aggregator.rgbpp_asset_locks]] -lock_hash = "562e4e8a2f64a3e9c24beb4b7dd002d0ad3b842d0cc77924328e36ad114e3ebe" -script = ''' -{ - "args": "0xf9a9ad51ed14936d33f7bb854aaefa5f47a3ccbd", - "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", - "hash_type": "type" -} -''' \ No newline at end of file From 54ad9de6943b76eced67cb257450b96820e52a09 Mon Sep 17 00:00:00 2001 From: EthanYuan Date: Sat, 17 Aug 2024 11:24:40 +0800 Subject: [PATCH 6/6] update readme --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d5499aaea1..fc3293c9bc 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ cd branch-dev ckb init --chain dev --genesis-message branch-dev ``` -### Configure +### Branch Configure The following settings are used to configure the `block_assembler` in the `ckb.toml` file: @@ -70,6 +70,21 @@ ckb run --indexer ``` Restarting in the same directory will reuse the data. +### Aggregator Configure + +The following settings are used to configure the `block_assembler` in the `ckb-aggregator.toml` file: + +```toml +branch_uri = "http://localhost:8114" +``` +Fill in the target Branch node. + +### Start Aggregator + +```shell +ckb aggregator +``` + ## Use RPC Find RPC port in the log output, the following command assumes 8114 is used: