fix(chain): withdrawal not enough sudt amount
When sudt amount is 0 or sudt script hash is CKB_SUDT_SCRIPT_ARGS,
skip `checked_sub_sudt`.
use anyhow::{anyhow, bail, Context, Result};
use gw_challenge::offchain::{verify_tx::TxWithContext, OffChainMockContext};
-use gw_common::{sparse_merkle_tree, state::State, H256};
+use gw_common::{sparse_merkle_tree, state::State, CKB_SUDT_SCRIPT_ARGS, H256};
use gw_config::ChainConfig;
use gw_generator::{
generator::{ApplyBlockArgs, ApplyBlockResult},
@@ -616,13 +616,15 @@ impl Chain {
.capacity
.checked_sub(w.raw().capacity().unpack().into())
.context("withdrawal not enough capacity")?;
+
+ let sudt_amount = w.raw().amount().unpack();
+ let sudt_script_hash: [u8; 32] = w.raw().sudt_script_hash().unpack();
+ if 0 != sudt_amount && CKB_SUDT_SCRIPT_ARGS != sudt_script_hash {
finalized_custodians
- .checked_sub_sudt(
- w.raw().sudt_script_hash().unpack(),
- w.raw().amount().unpack(),
- )
+ .checked_sub_sudt(sudt_script_hash, sudt_amount)
.context("withdrawal not enough sudt amount")?;
}
+ }
db.set_block_post_finalized_custodian_capacity(
block_number,
&finalized_custodians.pack().as_reader(),
