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

Remove web3 indexer crate #717

Merged
merged 3 commits into from
Jun 6, 2022
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
403 changes: 5 additions & 398 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ members = [
"crates/rpc-ws-server",
"crates/tools",
"crates/tests",
"crates/web3-indexer",
"crates/benches",
"crates/version",
"crates/utils",
Expand Down
2 changes: 0 additions & 2 deletions crates/block-producer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ gw-jsonrpc-types = { path = "../jsonrpc-types" }
gw-rpc-server = { path = "../rpc-server" }
gw-rpc-client = { path = "../rpc-client" }
gw-rpc-ws-server = { path = "../rpc-ws-server" }
gw-web3-indexer = { path = "../web3-indexer" }
gw-utils = { path = "../utils" }
gw-version = { path = "../version" }
gw-ckb-hardfork = { path = "../ckb-hardfork" }
Expand All @@ -45,7 +44,6 @@ log = "0.4.14"
serde_json = "1.0"
tokio = { version = "1.17", features = ["full", "tracing"] }
lazy_static = "1.4"
sqlx = { version = "0.5", features = [ "runtime-tokio-native-tls", "postgres", "sqlite", "chrono", "decimal" ] }
openssl = { version = "0.10", features = ["vendored"] }
hex = "0.4"
async-trait = "0.1"
Expand Down
15 changes: 0 additions & 15 deletions crates/block-producer/src/poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use gw_types::{
},
prelude::*,
};
use gw_web3_indexer::indexer::Web3Indexer;
use serde_json::json;
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -58,7 +57,6 @@ pub struct ChainUpdater {
last_tx_hash: Option<H256>,
rollup_context: RollupContext,
rollup_type_script: ckb_types::packed::Script,
web3_indexer: Option<Web3Indexer>,
initialized: bool,
sync_monitor: TaskMonitor,
}
Expand All @@ -69,7 +67,6 @@ impl ChainUpdater {
rpc_client: RPCClient,
rollup_context: RollupContext,
rollup_type_script: Script,
web3_indexer: Option<Web3Indexer>,
) -> ChainUpdater {
let rollup_type_script =
ckb_types::packed::Script::new_unchecked(rollup_type_script.as_bytes());
Expand All @@ -88,7 +85,6 @@ impl ChainUpdater {
rollup_context,
rollup_type_script,
last_tx_hash: None,
web3_indexer,
initialized: false,
sync_monitor,
}
Expand Down Expand Up @@ -316,17 +312,6 @@ impl ChainUpdater {
};
self.chain.lock().await.sync(sync_param).await?;

// TODO sync missed block
match &self.web3_indexer {
Some(indexer) => {
let store = { self.chain.lock().await.store().to_owned() };
if let Err(err) = indexer.store(&store, &tx).await {
log::error!("Web3 indexer store failed: {:?}", err);
}
}
None => {}
}

Ok(())
}

Expand Down
52 changes: 2 additions & 50 deletions crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,7 @@ use gw_utils::{
exponential_backoff::ExponentialBackoff, genesis_info::CKBGenesisInfo,
since::EpochNumberWithFraction, wallet::Wallet,
};
use gw_web3_indexer::Web3Indexer;
use semver::Version;
use sqlx::{
postgres::{PgConnectOptions, PgPoolOptions},
ConnectOptions,
};
use std::{
collections::HashMap,
net::{SocketAddr, ToSocketAddrs},
Expand Down Expand Up @@ -573,7 +568,7 @@ pub async fn run(config: Config, skip_config_check: bool) -> Result<()> {
}
}
let base = BaseInitComponents::init(&config, skip_config_check).await?;
let (mem_pool, wallet, offchain_mock_context, pg_pool, err_receipt_notify_ctrl) =
let (mem_pool, wallet, offchain_mock_context, err_receipt_notify_ctrl) =
match config.block_producer.as_ref() {
Some(block_producer_config) => {
let wallet = Wallet::from_config(&block_producer_config.wallet_config)
Expand All @@ -586,20 +581,6 @@ pub async fn run(config: Config, skip_config_check: bool) -> Result<()> {
base.store.clone(),
config.mem_pool.mem_block.clone(),
);
let pg_pool = match config.web3_indexer.as_ref() {
Some(web3_indexer_config) => {
let mut opts: PgConnectOptions =
web3_indexer_config.database_url.parse()?;
opts.log_statements(log::LevelFilter::Debug)
.log_slow_statements(log::LevelFilter::Warn, Duration::from_secs(5));
let pool = PgPoolOptions::new()
.max_connections(5)
.connect_with(opts)
.await?;
Some(pool)
}
None => None,
};
let notify_controller = {
let opt_ws_listen = config.rpc_server.err_receipt_ws_listen.as_ref();
opt_ws_listen.map(|_| NotifyService::new().start())
Expand Down Expand Up @@ -632,11 +613,10 @@ pub async fn run(config: Config, skip_config_check: bool) -> Result<()> {
Some(mem_pool),
Some(wallet),
Some(offchain_mock_context),
pg_pool,
notify_controller,
)
}
None => (None, None, None, None, None),
None => (None, None, None, None),
};

let BaseInitComponents {
Expand Down Expand Up @@ -672,40 +652,12 @@ pub async fn run(config: Config, skip_config_check: bool) -> Result<()> {
.with_context(|| "create chain")?,
));

// create web3 indexer
let web3_indexer = match config.web3_indexer {
Some(web3_indexer_config) => {
let pool = pg_pool.unwrap();
let polyjuce_type_script_hash = web3_indexer_config.polyjuice_script_type_hash;
let eth_account_lock_hash = web3_indexer_config.eth_account_lock_hash;
let tron_account_lock_hash = web3_indexer_config.tron_account_lock_hash;
let web3_indexer = Web3Indexer::new(
pool,
config
.genesis
.rollup_config
.l2_sudt_validator_script_type_hash,
polyjuce_type_script_hash,
config.genesis.rollup_type_hash,
eth_account_lock_hash,
tron_account_lock_hash,
);
// fix missing genesis block
log::info!("Check web3 indexing...");
web3_indexer.store_genesis(&store).await?;
web3_indexer.fix_missing_blocks(&store).await?;
Some(web3_indexer)
}
None => None,
};

// create chain updater
let chain_updater = ChainUpdater::new(
Arc::clone(&chain),
rpc_client.clone(),
rollup_context.clone(),
rollup_type_script.clone(),
web3_indexer,
);

let (block_producer, challenger, test_mode_control, withdrawal_unlocker, cleaner) = match config
Expand Down
9 changes: 0 additions & 9 deletions crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub struct Config {
#[serde(default)]
pub debug: DebugConfig,
pub block_producer: Option<BlockProducerConfig>,
pub web3_indexer: Option<Web3IndexerConfig>,
#[serde(default)]
pub offchain_validator: Option<OffChainValidatorConfig>,
#[serde(default)]
Expand Down Expand Up @@ -233,14 +232,6 @@ impl Default for DebugConfig {
}
}

#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct Web3IndexerConfig {
pub database_url: String,
pub polyjuice_script_type_hash: H256,
pub eth_account_lock_hash: H256,
pub tron_account_lock_hash: Option<H256>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct OffChainValidatorConfig {
pub verify_withdrawal_signature: bool,
Expand Down
25 changes: 2 additions & 23 deletions crates/tools/src/generate_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use gw_common::builtins::ETH_REGISTRY_ACCOUNT_ID;
use gw_config::{
BackendConfig, BlockProducerConfig, ChainConfig, ChallengerConfig, Config, ConsensusConfig,
ContractTypeScriptConfig, GenesisConfig, NodeMode, RPCClientConfig, RPCServerConfig,
RegistryAddressConfig, StoreConfig, WalletConfig, Web3IndexerConfig,
RegistryAddressConfig, StoreConfig, WalletConfig,
};
use gw_jsonrpc_types::godwoken::{AllowedEoaType, L2BlockCommittedInfo};
use gw_jsonrpc_types::godwoken::L2BlockCommittedInfo;
use gw_rpc_client::ckb_client::CKBClient;
use gw_types::{core::ScriptHashType, packed::Script, prelude::*};
use std::collections::HashMap;
Expand All @@ -27,7 +27,6 @@ pub struct GenerateNodeConfigArgs<'a> {
pub privkey_path: &'a Path,
pub ckb_url: String,
pub indexer_url: String,
pub database_url: Option<&'a str>,
pub build_scripts_result: &'a BuildScriptsResult,
pub server_url: String,
pub user_rollup_config: &'a UserRollupConfig,
Expand All @@ -43,7 +42,6 @@ pub async fn generate_node_config(args: GenerateNodeConfigArgs<'_>) -> Result<Co
privkey_path,
ckb_url,
indexer_url,
database_url,
build_scripts_result,
server_url,
user_rollup_config,
Expand Down Expand Up @@ -226,24 +224,6 @@ pub async fn generate_node_config(args: GenerateNodeConfigArgs<'_>) -> Result<Co
rollup_config,
secp_data_dep,
};
let allowed_eoa_type_hashes = &genesis.rollup_config.allowed_eoa_type_hashes;
let eth_account_lock_type_hash = allowed_eoa_type_hashes
.iter()
.find(|th| th.type_ == AllowedEoaType::Eth)
.ok_or_else(|| anyhow!("No allowed EoA type hashes in the rollup config"))?;
let tron_account_lock_type_hash = allowed_eoa_type_hashes
.iter()
.find(|th| th.type_ == AllowedEoaType::Tron);

let web3_indexer = database_url.map(|database_url| Web3IndexerConfig {
database_url: database_url.to_owned(),
polyjuice_script_type_hash: scripts_deployment
.polyjuice_validator
.script_type_hash
.clone(),
eth_account_lock_hash: eth_account_lock_type_hash.hash.to_owned(),
tron_account_lock_hash: tron_account_lock_type_hash.map(|th| th.hash.to_owned()),
});

let config: Config = Config {
backends,
Expand All @@ -253,7 +233,6 @@ pub async fn generate_node_config(args: GenerateNodeConfigArgs<'_>) -> Result<Co
rpc_server,
consensus,
block_producer,
web3_indexer,
node_mode,
debug: Default::default(),
offchain_validator: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion crates/tools/src/godwoken_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl GodwokenRpcClient {
) -> Result<SuccessResponse> {
self.id.fetch_add(1, Ordering::SeqCst);
let mut req_json = serde_json::Map::new();
req_json.insert("id".to_owned(), serde_json::to_value(&self.id).unwrap());
req_json.insert("id".to_owned(), serde_json::to_value(&*self.id).unwrap());
req_json.insert("jsonrpc".to_owned(), serde_json::to_value(&"2.0").unwrap());
req_json.insert("method".to_owned(), serde_json::to_value(method).unwrap());
req_json.insert("params".to_owned(), params);
Expand Down
8 changes: 0 additions & 8 deletions crates/tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,6 @@ async fn main() -> Result<()> {
.help("The omni lock config json file path"),
)
.arg(arg_privkey_path.clone())
.arg(
Arg::with_name("database-url")
.short("d")
.takes_value(true)
.help("The web3 store database url"),
)
.arg(
Arg::with_name("block-producer-address")
.long("block-producer-address")
Expand Down Expand Up @@ -939,7 +933,6 @@ async fn main() -> Result<()> {
let user_rollup_config_path = Path::new(m.value_of("user-rollup-config-path").unwrap());
let privkey_path = Path::new(m.value_of("privkey-path").unwrap());
let output_path = Path::new(m.value_of("output-path").unwrap());
let database_url = m.value_of("database-url");
let scripts_config_path =
Path::new(m.value_of("scripts-deployment-config-path").unwrap());
let server_url = m.value_of("rpc-server-url").unwrap().to_string();
Expand Down Expand Up @@ -980,7 +973,6 @@ async fn main() -> Result<()> {
privkey_path,
ckb_url,
indexer_url,
database_url,
server_url,
user_rollup_config: &user_rollup_config,
omni_lock_config: &omni_lock_config,
Expand Down
1 change: 0 additions & 1 deletion crates/tools/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ pub async fn setup(args: SetupArgs<'_>) {
privkey_path: &privkey_path,
ckb_url: ckb_rpc_url.to_string(),
indexer_url: indexer_url.to_string(),
database_url: None,
build_scripts_result: &build_scripts_result,
server_url: server_url.to_string(),
user_rollup_config: &rollup_config,
Expand Down
33 changes: 0 additions & 33 deletions crates/web3-indexer/Cargo.toml

This file was deleted.

12 changes: 0 additions & 12 deletions crates/web3-indexer/migrations/20210420113426_create_blocks.sql

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions crates/web3-indexer/migrations/20210420113522_create_logs.sql

This file was deleted.

Loading