-
Notifications
You must be signed in to change notification settings - Fork 2
Add DispatchOriginForCallOrigin Config for bridge-dispatch pallet. #100
Comments
I see what you mean. I am not so sure if |
It will validate nonce inside Stack Runner: |
Yeah, some basic checks are done in the stake runner, and some are not. fn validate_transaction_common(
origin: H160,
transaction_data: &TransactionData,
) -> Result<(U256, u64), TransactionValidityError> {
println!("this is in the validate transaction in common");
let gas_limit = transaction_data.gas_limit;
// We must ensure a transaction can pay the cost of its data bytes.
// If it can't it should not be included in a block.
let mut gasometer = evm::gasometer::Gasometer::new(
gas_limit.low_u64(),
<T as darwinia_evm::Config>::config(),
);
let transaction_cost = match transaction_data.action {
TransactionAction::Call(_) => evm::gasometer::call_transaction_cost(
&transaction_data.input,
&transaction_data.access_list,
),
TransactionAction::Create => evm::gasometer::create_transaction_cost(
&transaction_data.input,
&transaction_data.access_list,
),
};
if gasometer.record_transaction(transaction_cost).is_err() {
return Err(InvalidTransaction::Custom(
TransactionValidationError::InvalidGasLimit as u8,
)
.into());
}
if let Some(chain_id) = transaction_data.chain_id {
if chain_id != T::ChainId::get() {
return Err(InvalidTransaction::Custom(
TransactionValidationError::InvalidChainId as u8,
)
.into());
}
}
if gas_limit >= T::BlockGasLimit::get() {
return Err(InvalidTransaction::Custom(
TransactionValidationError::InvalidGasLimit as u8,
)
.into());
}
let base_fee = T::FeeCalculator::min_gas_price();
let mut priority = 0;
let gas_price = if let Some(gas_price) = transaction_data.gas_price {
// Legacy and EIP-2930 transactions.
// Handle priority here. On legacy transaction everything in gas_price except
// the current base_fee is considered a tip to the miner and thus the priority.
priority = gas_price.saturating_sub(base_fee).unique_saturated_into();
gas_price
} else if let Some(max_fee_per_gas) = transaction_data.max_fee_per_gas {
// EIP-1559 transactions.
max_fee_per_gas
} else {
return Err(InvalidTransaction::Payment.into());
};
if gas_price < base_fee {
return Err(InvalidTransaction::Payment.into());
}
let mut fee = gas_price.saturating_mul(gas_limit);
if let Some(max_priority_fee_per_gas) = transaction_data.max_priority_fee_per_gas {
// EIP-1559 transaction priority is determined by `max_priority_fee_per_gas`.
// If the transaction do not include this optional parameter, priority is now considered
// zero.
priority = max_priority_fee_per_gas.unique_saturated_into();
// Add the priority tip to the payable fee.
fee = fee.saturating_add(max_priority_fee_per_gas.saturating_mul(gas_limit));
}
let account_data = <T as darwinia_evm::Config>::RingAccountBasic::account_basic(&origin);
let total_payment = transaction_data.value.saturating_add(fee);
if account_data.balance < total_payment {
return Err(InvalidTransaction::Payment.into());
}
Ok((account_data.nonce, priority))
} |
Be careful to handle the fee charge part, especially related to the |
For the
We can CallFilter config in bridge-dispatch to validate, because for evm tx, it is not validate in dispatch call, they validate in pool and
|
Another issue is: For evm tx, the fee is paid inside EVM executor, not in
|
Fixed in #130 |
Related darwinia-network/darwinia-common#1235
In this case, we do not need to add
substrate_transact
then.something like
For runtime to config, e.g. if the CallOrigin is
CallOrigin::SourceAccount(source_account_id)
and source_account_id is from derived from ethereum, then calculate derive and dispatch asRawOrigin::EthereumTransaction(n)
in Crab/Pangolin runtime.https://github.com/darwinia-network/darwinia-messages-substrate/blob/main/modules/dispatch/src/lib.rs#L254-L259
Replace the
pay_dispatch_fee
parameter with Origin here.darwinia-messages-substrate/modules/dispatch/src/lib.rs
Line 303 in 8c877be
darwinia-messages-substrate/modules/dispatch/src/lib.rs
Line 323 in 8c877be
The text was updated successfully, but these errors were encountered: