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

chore!(v0): update v0 for the upcoming ckb 2023 hardfork #1084

Merged
merged 10 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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,038 changes: 573 additions & 465 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 @@ -22,7 +22,6 @@ members = [
"crates/benches",
"crates/version",
"crates/utils",
"crates/ckb-hardfork",
"crates/tx-filter",
"crates/replay-chain",
"crates/dynamic-config",
Expand Down
9 changes: 4 additions & 5 deletions crates/block-producer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ gw-web3-indexer = { path = "../web3-indexer" }
gw-poa = { path = "../poa" }
gw-utils = { path = "../utils" }
gw-version = { path = "../version" }
gw-ckb-hardfork = { path = "../ckb-hardfork" }
gw-dynamic-config = { path = "../dynamic-config"}
ckb-crypto = "0.100.0"
ckb-fixed-hash = "0.100.0"
ckb-types = "0.100.0"
ckb-chain-spec = "0.100.0"
ckb-crypto = "0.111.0"
ckb-fixed-hash = "0.111.0"
ckb-types = "0.111.0"
ckb-chain-spec = "0.111.0"
toml = "0.5"
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
Expand Down
8 changes: 4 additions & 4 deletions crates/block-producer/src/block_producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,10 @@ impl BlockProducer {
let dep_cell_by_data: HashMap<[u8; 32], OutPoint> = dep_cells
.iter()
.map(|cell| {
let data_hash =
ckb_types::packed::CellOutput::calc_data_hash(&cell.data).unpack();
let data_hash: [u8; 32] =
ckb_types::packed::CellOutput::calc_data_hash(&cell.data)
.unpack()
.into();
(data_hash, cell.out_point.clone())
})
.collect();
Expand Down Expand Up @@ -902,7 +904,6 @@ impl BlockProducer {
if input_len != witness_len {
// append dummy witness args to align our reverted deposit witness args
let dummy_witness_argses = (0..input_len - witness_len)
.into_iter()
.map(|_| WitnessArgs::default())
.collect::<Vec<_>>();
tx_skeleton.witnesses_mut().extend(dummy_witness_argses);
Expand Down Expand Up @@ -930,7 +931,6 @@ impl BlockProducer {
if input_len != witness_len {
// append dummy witness args to align our reverted withdrawal witness args
let dummy_witness_argses = (0..input_len - witness_len)
.into_iter()
.map(|_| WitnessArgs::default())
.collect::<Vec<_>>();
tx_skeleton.witnesses_mut().extend(dummy_witness_argses);
Expand Down
32 changes: 21 additions & 11 deletions crates/block-producer/src/challenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ use gw_rpc_client::contract::ContractsCellDepManager;
use gw_rpc_client::rpc_client::RPCClient;
use gw_types::bytes::Bytes;
use gw_types::core::{ChallengeTargetType, Status};
use gw_types::offchain::{
global_state_from_slice, CellInfo, InputCellInfo, RollupContext, TxStatus,
};
use gw_types::offchain::{global_state_from_slice, CellInfo, InputCellInfo, RollupContext};
use gw_types::packed::{
CellDep, CellInput, CellOutput, ChallengeLockArgs, ChallengeLockArgsReader, ChallengeTarget,
GlobalState, OutPoint, Script, Transaction, WitnessArgs,
Expand Down Expand Up @@ -407,7 +405,10 @@ impl Challenger {
let challenge_tx_block_number = {
let tx_hash: H256 = challenge_cell.out_point.tx_hash().unpack();
let tx_status = self.rpc_client.get_transaction_status(tx_hash).await?;
if !matches!(tx_status, Some(TxStatus::Committed)) {
if !matches!(
tx_status,
Some(gw_jsonrpc_types::ckb_jsonrpc_types::Status::Committed)
) {
log::debug!("challenge tx isn't committed");
return Ok(());
}
Expand Down Expand Up @@ -604,7 +605,6 @@ impl Challenger {
if input_len != witness_len {
// append dummy witness args to align our reverted deposit witness args
let dummy_witness_argses = (0..input_len - witness_len)
.into_iter()
.map(|_| WitnessArgs::default())
.collect::<Vec<_>>();
tx_skeleton.witnesses_mut().extend(dummy_witness_argses);
Expand Down Expand Up @@ -677,14 +677,19 @@ impl Challenger {
}

async fn wait_tx_proposed(&self, tx_hash: H256) -> Result<()> {
use gw_jsonrpc_types::ckb_jsonrpc_types::Status;

let timeout = Duration::new(30, 0);
let now = Instant::now();

loop {
match self.rpc_client.get_transaction_status(tx_hash).await? {
Some(TxStatus::Proposed) | Some(TxStatus::Committed) => return Ok(()),
Some(TxStatus::Pending) => (),
None => return Err(anyhow!("tx hash {} not found", to_hex(&tx_hash))),
Some(Status::Proposed) | Some(Status::Committed) => return Ok(()),
Some(Status::Pending) => (),
Some(Status::Rejected) => bail!("tx hash {} rejected", to_hex(&tx_hash)),
Some(Status::Unknown) | None => {
return Err(anyhow!("tx hash {} not found", to_hex(&tx_hash)))
}
}

if now.elapsed() >= timeout {
Expand All @@ -696,14 +701,19 @@ impl Challenger {
}

async fn wait_tx_committed(&self, tx_hash: H256) -> Result<()> {
use gw_jsonrpc_types::ckb_jsonrpc_types::Status;

let timeout = Duration::new(30, 0);
let now = Instant::now();

loop {
match self.rpc_client.get_transaction_status(tx_hash).await? {
Some(TxStatus::Committed) => return Ok(()),
Some(TxStatus::Proposed) | Some(TxStatus::Pending) => (),
None => return Err(anyhow!("tx hash {} not found", to_hex(&tx_hash))),
Some(Status::Committed) => return Ok(()),
Some(Status::Proposed) | Some(Status::Pending) => (),
Some(Status::Rejected) => bail!("tx {} rejected", to_hex(&tx_hash)),
Some(Status::Unknown) | None => {
return Err(anyhow!("tx hash {} not found", to_hex(&tx_hash)))
}
}

if now.elapsed() >= timeout {
Expand Down
12 changes: 9 additions & 3 deletions crates/block-producer/src/cleaner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use gw_challenge::cancel_challenge::RecoverAccountsContext;
use gw_common::H256;
use gw_rpc_client::rpc_client::RPCClient;
use gw_types::core::Status;
use gw_types::offchain::{global_state_from_slice, CellInfo, InputCellInfo, TxStatus};
use gw_types::offchain::{global_state_from_slice, CellInfo, InputCellInfo};
use gw_types::packed::{CellDep, CellInput, Transaction, WitnessArgs};
use gw_types::prelude::Unpack;

Expand Down Expand Up @@ -104,7 +104,10 @@ impl Cleaner {
let tip_l1_block_number = rpc_client.get_tip().await?.number().unpack();
for tx_hash in consumed_txs {
let tx_status = rpc_client.get_transaction_status(tx_hash).await?;
if !matches!(tx_status, Some(TxStatus::Committed)) {
if !matches!(
tx_status,
Some(gw_jsonrpc_types::ckb_jsonrpc_types::Status::Committed)
) {
continue;
}

Expand Down Expand Up @@ -154,7 +157,10 @@ impl Cleaner {
let verifier_status = rpc_client
.get_transaction_status(verifier.tx_hash())
.await?;
if !matches!(verifier_status, Some(TxStatus::Committed)) {
if !matches!(
verifier_status,
Some(gw_jsonrpc_types::ckb_jsonrpc_types::Status::Committed)
) {
continue;
}

Expand Down
6 changes: 2 additions & 4 deletions crates/block-producer/src/db_block_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ impl DBBlockCancelChallengeValidator {
.into_par_iter()
.try_for_each(|block_number| self.verify_block(block_number))?;
} else {
(from_block..=to_block)
.into_iter()
.try_for_each(|block_number| self.verify_block(block_number))?;
(from_block..=to_block).try_for_each(|block_number| self.verify_block(block_number))?;
}

Ok(())
Expand Down Expand Up @@ -316,7 +314,7 @@ impl DBBlockCancelChallengeValidator {
let dump = || -> Result<_> {
let debug_config = &self.debug_config;
let dir = debug_config.debug_tx_dump_path.as_path();
create_dir_all(&dir)?;
create_dir_all(dir)?;

let mut dump_path = PathBuf::new();
dump_path.push(dir);
Expand Down
14 changes: 6 additions & 8 deletions crates/block-producer/src/debugger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use gw_jsonrpc_types::{
use gw_rpc_client::rpc_client::RPCClient;
use gw_types::{
core::DepType,
offchain::TxStatus,
packed::{CellDep, OutPointVec, Transaction},
prelude::*,
};
Expand All @@ -31,11 +30,10 @@ pub async fn dump_transaction<P: AsRef<Path>>(

let mut dump_path = PathBuf::new();
dump_path.push(dir);
let json_content;
match build_mock_transaction(rpc_client, tx).await {
let json_content = match build_mock_transaction(rpc_client, tx).await {
Ok(mock_tx) => {
dump_path.push(format!("{}-mock-tx.json", tx_hash));
json_content = serde_json::to_string_pretty(&mock_tx)?;
serde_json::to_string_pretty(&mock_tx)?
}
Err(err) => {
log::error!(
Expand All @@ -47,9 +45,9 @@ pub async fn dump_transaction<P: AsRef<Path>>(
dump_path.push(format!("{}-raw-tx.json", tx_hash));
let json_tx: ckb_jsonrpc_types::Transaction =
{ ckb_types::packed::Transaction::new_unchecked(tx.as_bytes()).into() };
json_content = serde_json::to_string_pretty(&json_tx)?;
serde_json::to_string_pretty(&json_tx)?
}
}
};
log::info!("Dump transaction {} to {:?}", tx_hash, dump_path);
write(dump_path, json_content)?;
Ok(())
Expand Down Expand Up @@ -111,7 +109,7 @@ pub async fn build_mock_transaction(

let input_tx_hash = input.previous_output().tx_hash().unpack();
let input_block_hash = match rpc_client.get_transaction_status(input_tx_hash).await? {
Some(TxStatus::Committed) => {
Some(ckb_jsonrpc_types::Status::Committed) => {
let block_hash = rpc_client.get_transaction_block_hash(input_tx_hash).await?;
Some(block_hash.ok_or_else(|| anyhow!("not found input cell tx hash"))?)
}
Expand Down Expand Up @@ -161,7 +159,7 @@ pub async fn build_mock_transaction(
.ok_or_else(|| anyhow!("can't find dep cell"))?;
let dep_cell_tx_hash = cell_dep.out_point().tx_hash().unpack();
let dep_cell_block_hash = match rpc_client.get_transaction_status(dep_cell_tx_hash).await? {
Some(TxStatus::Committed) => {
Some(ckb_jsonrpc_types::Status::Committed) => {
let query = rpc_client
.get_transaction_block_hash(dep_cell_tx_hash)
.await?;
Expand Down
6 changes: 3 additions & 3 deletions crates/block-producer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async fn run_cli() -> Result<()> {
match matches.subcommand() {
(COMMAND_RUN, Some(m)) => {
let config_path = m.value_of(ARG_CONFIG).unwrap();
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init(config.trace)?;
runner::run(config, m.is_present(ARG_SKIP_CONFIG_CHECK)).await?;
}
Expand All @@ -112,7 +112,7 @@ async fn run_cli() -> Result<()> {
}
(COMMAND_VERIFY_DB_BLOCK, Some(m)) => {
let config_path = m.value_of(ARG_CONFIG).unwrap();
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init(None)?;
let from_block: Option<u64> = m.value_of(ARG_FROM_BLOCK).map(str::parse).transpose()?;
let to_block: Option<u64> = m.value_of(ARG_TO_BLOCK).map(str::parse).transpose()?;
Expand All @@ -121,7 +121,7 @@ async fn run_cli() -> Result<()> {
_ => {
// default command: start a Godwoken node
let config_path = "./config.toml";
let config = read_config(&config_path)?;
let config = read_config(config_path)?;
let _guard = trace::init(config.trace)?;
runner::run(config, false).await?;
}
Expand Down
43 changes: 14 additions & 29 deletions crates/block-producer/src/poller.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![allow(clippy::mutable_key_type)]

use crate::types::ChainEvent;
use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use async_jsonrpc_client::Params as ClientParams;
use ckb_fixed_hash::H256;
use gw_chain::chain::{
Chain, ChallengeCell, L1Action, L1ActionContext, RevertL1ActionContext, RevertedL1Action,
SyncParam,
};
use gw_jsonrpc_types::ckb_jsonrpc_types::{BlockNumber, HeaderView, TransactionWithStatus, Uint32};
use gw_jsonrpc_types::ckb_jsonrpc_types::{BlockNumber, HeaderView, Status, Uint32};
use gw_rpc_client::{
indexer_types::{Order, Pagination, ScriptType, SearchKey, SearchKeyFilter, Tx},
rpc_client::RPCClient,
Expand All @@ -17,7 +17,7 @@ use gw_store::traits::chain_store::ChainStore;
use gw_types::{
bytes::Bytes,
core::ScriptHashType,
offchain::{RollupContext, TxStatus},
offchain::RollupContext,
packed::{
CellInput, CellOutput, ChallengeLockArgs, ChallengeLockArgsReader, DepositLockArgs,
DepositRequest, L2BlockCommittedInfo, OutPoint, RollupAction, RollupActionUnion, Script,
Expand Down Expand Up @@ -217,18 +217,12 @@ impl ChainUpdater {
}
}

let tx: Option<TransactionWithStatus> = self
.rpc_client
.ckb
.request(
"get_transaction",
Some(ClientParams::Array(vec![json!(tx_hash)])),
)
.await?;
let tx_with_status =
tx.ok_or_else(|| QueryL1TxError::new(tx_hash, anyhow!("cannot locate tx")))?;
let tx_with_status = self.rpc_client.ckb.get_transaction(tx_hash).await?;
let tx = tx_with_status
.transaction
.ok_or_else(|| QueryL1TxError::new(tx_hash, anyhow!("cannot locate tx")))?;
let tx = {
let tx: ckb_types::packed::Transaction = tx_with_status.transaction.inner.into();
let tx: ckb_types::packed::Transaction = tx.inner.into();
Transaction::new_unchecked(tx.as_bytes())
};
let block_hash = tx_with_status.tx_status.block_hash.ok_or_else(|| {
Expand Down Expand Up @@ -317,7 +311,7 @@ impl ChainUpdater {
let tx_hash: gw_common::H256 =
From::<[u8; 32]>::from(committed_info.transaction_hash().unpack());
let tx_status = rpc_client.get_transaction_status(tx_hash).await?;
if !matches!(tx_status, Some(TxStatus::Committed)) {
if !matches!(tx_status, Some(Status::Committed)) {
return Ok(false);
}

Expand Down Expand Up @@ -415,7 +409,7 @@ impl ChainUpdater {
fn extract_rollup_action(&self, tx: &Transaction) -> Result<RollupAction> {
let rollup_type_hash: [u8; 32] = {
let hash = self.rollup_type_script.calc_script_hash();
ckb_types::prelude::Unpack::unpack(&hash)
ckb_types::prelude::Unpack::unpack(&hash).into()
};

// find rollup state cell from outputs
Expand Down Expand Up @@ -505,20 +499,11 @@ impl ChainUpdater {
// Load cell denoted by the transaction input
let tx_hash: H256 = input.previous_output().tx_hash().unpack();
let index = input.previous_output().index().unpack();
let tx: Option<TransactionWithStatus> = self
let tx = self
.rpc_client
.ckb
.request(
"get_transaction",
Some(ClientParams::Array(vec![json!(tx_hash)])),
)
.await?;
let tx_with_status =
tx.ok_or_else(|| QueryL1TxError::new(&tx_hash, anyhow!("cannot locate tx")))?;
let tx = {
let tx: ckb_types::packed::Transaction = tx_with_status.transaction.inner.into();
Transaction::new_unchecked(tx.as_bytes())
};
.get_transaction(tx_hash.0.into())
.await?
.with_context(move || QueryL1TxError::new(&tx_hash, anyhow!("")))?;
let cell_output = tx
.raw()
.outputs()
Expand Down
Loading
Loading