Skip to content

Commit

Permalink
Remove dry_run_transaction and fix error display in withdrawal unlocker
Browse files Browse the repository at this point in the history
  • Loading branch information
blckngm authored and Flouse committed Feb 20, 2023
1 parent 8b44fbd commit 8e71e87
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 58 deletions.
45 changes: 24 additions & 21 deletions crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use crate::{
block_producer::{BlockProducer, BlockProducerCreateArgs},
block_sync_client::{block_sync_client_protocol, BlockSyncClient, P2PStream},
chain_updater::ChainUpdater,
challenger::{Challenger, ChallengerNewArgs},
cleaner::Cleaner,
psc::{PSCContext, ProduceSubmitConfirm},
test_mode_control::TestModeControl,
types::ChainEvent,
withdrawal_unlocker::FinalizedWithdrawalUnlocker,
use std::{
collections::HashMap,
net::{SocketAddr, ToSocketAddrs},
sync::Arc,
time::{Duration, Instant},
};

use anyhow::{anyhow, bail, Context, Result};
use futures::future::OptionFuture;
use gw_chain::chain::Chain;
Expand Down Expand Up @@ -39,34 +35,41 @@ use gw_rpc_server::{
registry::{BoxedTestModeRpc, Registry, RegistryArgs},
server::start_jsonrpc_server,
};
use gw_store::migrate::{init_migration_factory, open_or_create_db};
use gw_store::Store;
use gw_store::{
migrate::{init_migration_factory, open_or_create_db},
Store,
};
use gw_types::{
bytes::Bytes,
core::AllowedEoaType,
h256::*,
packed::{Byte32, CellDep, NumberHash, RollupConfig, Script},
prelude::*,
};
use gw_utils::RollupContext;
use gw_utils::{
exponential_backoff::ExponentialBackoff, genesis_info::CKBGenesisInfo, liveness::Liveness,
local_cells::LocalCellsManager, wallet::Wallet,
local_cells::LocalCellsManager, wallet::Wallet, RollupContext,
};
use semver::Version;
use std::{
collections::HashMap,
net::{SocketAddr, ToSocketAddrs},
sync::Arc,
time::{Duration, Instant},
};
use tentacle::service::ProtocolMeta;
use tokio::{
spawn,
sync::{broadcast, mpsc, Mutex},
};
use tracing::{info_span, instrument};

use crate::{
block_producer::{BlockProducer, BlockProducerCreateArgs},
block_sync_client::{block_sync_client_protocol, BlockSyncClient, P2PStream},
chain_updater::ChainUpdater,
challenger::{Challenger, ChallengerNewArgs},
cleaner::Cleaner,
psc::{PSCContext, ProduceSubmitConfirm},
test_mode_control::TestModeControl,
types::ChainEvent,
withdrawal_unlocker::FinalizedWithdrawalUnlocker,
};

const MIN_CKB_VERSION: &str = "0.40.0";
const EVENT_TIMEOUT_SECONDS: u64 = 30;

Expand Down Expand Up @@ -167,7 +170,7 @@ impl ChainTask {

if let Some(ref mut withdrawal_unlocker) = ctx.withdrawal_unlocker {
if let Err(err) = withdrawal_unlocker.handle_event(&event).await {
log::error!("[unlock withdrawal] {}", err);
log::error!("[unlock withdrawal] {:#}", err);
}
}

Expand Down
58 changes: 22 additions & 36 deletions crates/block-producer/src/withdrawal_unlocker.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
#![allow(clippy::mutable_key_type)]

use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use std::{
collections::{HashMap, HashSet},
sync::Arc,
};

use anyhow::{bail, Result};
use async_trait::async_trait;
use gw_config::{ContractsCellDep, DebugConfig};
use gw_rpc_client::contract::ContractsCellDepManager;
use gw_rpc_client::rpc_client::RPCClient;
use gw_types::h256::*;
use gw_types::offchain::{global_state_from_slice, CellInfo, CompatibleFinalizedTimepoint};
use gw_types::packed::{OutPoint, RollupConfig, Transaction};
use gw_types::prelude::*;
use gw_utils::fee::fill_tx_fee;
use gw_utils::genesis_info::CKBGenesisInfo;
use gw_utils::local_cells::LocalCellsManager;
use gw_utils::query_rollup_cell;
use gw_utils::transaction_skeleton::TransactionSkeleton;
use gw_utils::wallet::Wallet;
pub use gw_rpc_client::contract::Guard;
use gw_rpc_client::{contract::ContractsCellDepManager, rpc_client::RPCClient};
use gw_types::{
h256::*,
offchain::{global_state_from_slice, CellInfo, CompatibleFinalizedTimepoint},
packed::{OutPoint, RollupConfig, Transaction},
prelude::*,
};
use gw_utils::{
fee::fill_tx_fee, genesis_info::CKBGenesisInfo, local_cells::LocalCellsManager,
query_rollup_cell, transaction_skeleton::TransactionSkeleton, wallet::Wallet,
};
use tokio::sync::Mutex;
use tracing::instrument;

use crate::types::ChainEvent;
use crate::utils;

use crate::utils::global_state_last_finalized_timepoint_to_since;
pub use gw_rpc_client::contract::Guard;

const TRANSACTION_FAILED_TO_RESOLVE_ERROR: &str = "TransactionFailedToResolve";
use crate::{types::ChainEvent, utils, utils::global_state_last_finalized_timepoint_to_since};

pub struct FinalizedWithdrawalUnlocker {
unlocker: DefaultUnlocker,
Expand Down Expand Up @@ -68,25 +64,12 @@ impl FinalizedWithdrawalUnlocker {
let unlocked = &self.unlocked_set;
let rpc_client = &self.unlocker.rpc_client;
if let Some((tx, to_unlock)) = self.unlocker.query_and_unlock_to_owner(unlocked).await? {
if let Err(err) = rpc_client.dry_run_transaction(&tx).await {
let err_string = err.to_string();
if err_string.contains(TRANSACTION_FAILED_TO_RESOLVE_ERROR) {
// NOTE: Maybe unlocked withdrawals are included, this happens after restart.
// Wait indexer remove these cells.
log::info!(
"[unlock withdrawal] failed to resolve, wait unlocked become committed"
);
return Ok(());
}
bail!("dry unlock tx failed {}", err);
}

let tx_hash = match rpc_client.send_transaction(&tx).await {
Ok(tx_hash) => tx_hash,
Err(err) => {
let debug_tx_dump_path = &self.debug_config.debug_tx_dump_path;
utils::dump_transaction(debug_tx_dump_path, rpc_client, &tx).await;
bail!("send tx failed {}", err);
bail!(err);
}
};

Expand All @@ -106,7 +89,10 @@ impl FinalizedWithdrawalUnlocker {
match rpc_client.ckb.get_transaction_status(*tx_hash).await {
Err(err) => {
// Always drop this unlock tx and retry to avoid "lock" withdrawal cell
log::info!("[unlock withdrawal] get unlock tx failed {}, drop it", err);
log::info!(
"[unlock withdrawal] get unlock tx failed {:#}, drop it",
err
);
drop_txs.push(*tx_hash);
}
Ok(None) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc-client/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl TracingHttpClient {
self.inner.url()
}

#[instrument(target = "gw-rpc-client", skip_all, err, fields(method, params = field::Empty))]
#[instrument(target = "gw-rpc-client", skip_all, fields(method, params = field::Empty))]
pub async fn rpc(
&self,
method: &str,
Expand Down

0 comments on commit 8e71e87

Please sign in to comment.