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

Refactor tx verification #677

Merged
merged 5 commits into from
Apr 27, 2022
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
17 changes: 8 additions & 9 deletions crates/block-producer/src/withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,14 @@ mod test {
.unwrap();
let (output, data) = generated.unwrap().outputs.first().unwrap().to_owned();

let (expected_output, expected_data) =
gw_generator::Generator::build_withdrawal_cell_output(
&rollup_context,
&withdrawal_extra,
&block.hash().into(),
block.raw().number().unpack(),
Some(sudt_script.clone()),
)
.unwrap();
let (expected_output, expected_data) = gw_generator::utils::build_withdrawal_cell_output(
&rollup_context,
&withdrawal_extra,
&block.hash().into(),
block.raw().number().unpack(),
Some(sudt_script.clone()),
)
.unwrap();

assert_eq!(expected_output.as_slice(), output.as_slice());
assert_eq!(expected_data, data);
Expand Down
8 changes: 4 additions & 4 deletions crates/generator/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO ensure this value
pub const MIN_WITHDRAWAL_CAPACITY: u64 = 1000_00000000;
// TODO ensure this value
pub const MIN_DEPOSIT_CAPACITY: u64 = 1000_00000000;
/// MAX tx size 50 KB
pub const MAX_TX_SIZE: usize = 50_000;
/// MAX withdrawal size 50 KB
pub const MAX_WITHDRAWAL_SIZE: usize = 50_000;
// 25 KB
pub const MAX_WRITE_DATA_BYTES_LIMIT: usize = 25_000;
// 2MB
Expand Down
17 changes: 15 additions & 2 deletions crates/generator/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ pub enum WithdrawalError {
NonPositiveSUDTAmount,
#[error("Expected owner lock hash {0}")]
OwnerLock(Byte32),
#[error("Insufficient capacity expected {expected} actual {actual}")]
InsufficientCapacity { expected: u128, actual: u64 },
#[error(
"Exceeded maximum withdrawal size: max size {max_size}, withdrawal size {withdrawal_size}"
)]
ExceededMaxWithdrawalSize {
max_size: usize,
withdrawal_size: usize,
},
}

impl From<WithdrawalError> for Error {
Expand All @@ -82,8 +91,6 @@ impl From<WithdrawalError> for Error {

#[derive(Error, Debug, PartialEq, Clone, Eq)]
pub enum AccountError {
#[error("Insufficient capacity expected {expected} actual {actual}")]
InsufficientCapacity { expected: u128, actual: u64 },
#[error("Invalid SUDT operation")]
InvalidSUDTOperation,
#[error("Unknown SUDT")]
Expand Down Expand Up @@ -140,6 +147,12 @@ pub enum TransactionError {
BackendMustIncreaseNonce,
#[error("ScriptHashNotFound")]
ScriptHashNotFound,
#[error("Exceeded maximum tx size: max size {max_size}, tx size {tx_size}")]
ExceededMaxTxSize { max_size: usize, tx_size: usize },
#[error("Insufficient balance")]
InsufficientBalance,
#[error("Tx has no cost")]
NoCost,
}

impl From<VMError> for TransactionError {
Expand Down
Loading