mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Remove OutInstruction's data field
It makes sense for networks which support arbitrary data to do as part of their address. This reduces the ability to perform DoSs, achieves better performance, and better uses the type system (as now networks we don't support data on don't have a data field). Updates the Ethereum address definition in serai-client accordingly
This commit is contained in:
@@ -192,7 +192,7 @@ contract Router {
|
||||
_transferOut(nextAddress, transactions[i].coin, transactions[i].value);
|
||||
|
||||
// Perform the calls with a set gas budget
|
||||
(uint24 gas, bytes memory code) = abi.decode(transactions[i].destination, (uint24, bytes));
|
||||
(uint32 gas, bytes memory code) = abi.decode(transactions[i].destination, (uint32, bytes));
|
||||
address(this).call{
|
||||
gas: gas
|
||||
}(abi.encodeWithSelector(Router.arbitaryCallOut.selector, code));
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::io;
|
||||
use scale::{Encode, Decode, IoReader};
|
||||
use borsh::{BorshSerialize, BorshDeserialize};
|
||||
|
||||
use serai_primitives::{Balance, Data};
|
||||
use serai_primitives::Balance;
|
||||
use serai_coins_primitives::OutInstructionWithBalance;
|
||||
|
||||
use crate::Address;
|
||||
@@ -13,7 +13,6 @@ use crate::Address;
|
||||
pub struct Payment<A: Address> {
|
||||
address: A,
|
||||
balance: Balance,
|
||||
data: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl<A: Address> TryFrom<OutInstructionWithBalance> for Payment<A> {
|
||||
@@ -22,15 +21,14 @@ impl<A: Address> TryFrom<OutInstructionWithBalance> for Payment<A> {
|
||||
Ok(Payment {
|
||||
address: out_instruction_with_balance.instruction.address.try_into().map_err(|_| ())?,
|
||||
balance: out_instruction_with_balance.balance,
|
||||
data: out_instruction_with_balance.instruction.data.map(Data::consume),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: Address> Payment<A> {
|
||||
/// Create a new Payment.
|
||||
pub fn new(address: A, balance: Balance, data: Option<Vec<u8>>) -> Self {
|
||||
Payment { address, balance, data }
|
||||
pub fn new(address: A, balance: Balance) -> Self {
|
||||
Payment { address, balance }
|
||||
}
|
||||
|
||||
/// The address to pay.
|
||||
@@ -41,24 +39,18 @@ impl<A: Address> Payment<A> {
|
||||
pub fn balance(&self) -> Balance {
|
||||
self.balance
|
||||
}
|
||||
/// The data to associate with this payment.
|
||||
pub fn data(&self) -> &Option<Vec<u8>> {
|
||||
&self.data
|
||||
}
|
||||
|
||||
/// Read a Payment.
|
||||
pub fn read(reader: &mut impl io::Read) -> io::Result<Self> {
|
||||
let address = A::deserialize_reader(reader)?;
|
||||
let reader = &mut IoReader(reader);
|
||||
let balance = Balance::decode(reader).map_err(io::Error::other)?;
|
||||
let data = Option::<Vec<u8>>::decode(reader).map_err(io::Error::other)?;
|
||||
Ok(Self { address, balance, data })
|
||||
Ok(Self { address, balance })
|
||||
}
|
||||
/// Write the Payment.
|
||||
pub fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
||||
self.address.serialize(writer)?;
|
||||
self.balance.encode_to(writer);
|
||||
self.data.encode_to(writer);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ use std::collections::HashMap;
|
||||
use scale::Decode;
|
||||
use serai_db::{Get, DbTxn, Db};
|
||||
|
||||
use serai_primitives::MAX_DATA_LEN;
|
||||
use serai_in_instructions_primitives::{
|
||||
Shorthand, RefundableInInstruction, InInstruction, InInstructionWithBalance,
|
||||
};
|
||||
@@ -56,16 +55,6 @@ fn in_instruction_from_output<S: ScannerFeed>(
|
||||
let presumed_origin = output.presumed_origin();
|
||||
|
||||
let mut data = output.data();
|
||||
let max_data_len = usize::try_from(MAX_DATA_LEN).unwrap();
|
||||
if data.len() > max_data_len {
|
||||
log::info!(
|
||||
"data in output {} exceeded MAX_DATA_LEN ({MAX_DATA_LEN}): {}. skipping",
|
||||
hex::encode(output.id()),
|
||||
data.len(),
|
||||
);
|
||||
return (presumed_origin, None);
|
||||
}
|
||||
|
||||
let shorthand = match Shorthand::decode(&mut data) {
|
||||
Ok(shorthand) => shorthand,
|
||||
Err(e) => {
|
||||
|
||||
@@ -142,7 +142,7 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for SubstrateTask<D, S> {
|
||||
|
||||
if let Some(report::ReturnInformation { address, balance }) = return_information {
|
||||
burns.push(OutInstructionWithBalance {
|
||||
instruction: OutInstruction { address: address.into(), data: None },
|
||||
instruction: OutInstruction { address: address.into() },
|
||||
balance,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ impl<S: ScannerFeed, SC: Send + Sync + SmartContract<S>> SchedulerTrait<S> for S
|
||||
.returns()
|
||||
.iter()
|
||||
.map(|to_return| {
|
||||
Payment::new(to_return.address().clone(), to_return.output().balance(), None)
|
||||
Payment::new(to_return.address().clone(), to_return.output().balance())
|
||||
})
|
||||
.collect::<Vec<_>>(),
|
||||
),
|
||||
|
||||
@@ -115,11 +115,7 @@ impl<A: Address> TreeTransaction<A> {
|
||||
.filter_map(|(payment, amount)| {
|
||||
amount.map(|amount| {
|
||||
// The existing payment, with the new amount
|
||||
Payment::new(
|
||||
payment.address().clone(),
|
||||
Balance { coin, amount: Amount(amount) },
|
||||
payment.data().clone(),
|
||||
)
|
||||
Payment::new(payment.address().clone(), Balance { coin, amount: Amount(amount) })
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
@@ -130,7 +126,7 @@ impl<A: Address> TreeTransaction<A> {
|
||||
.filter_map(|amount| {
|
||||
amount.map(|amount| {
|
||||
// A branch output with the new amount
|
||||
Payment::new(branch_address.clone(), Balance { coin, amount: Amount(amount) }, None)
|
||||
Payment::new(branch_address.clone(), Balance { coin, amount: Amount(amount) })
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
|
||||
@@ -489,7 +489,7 @@ impl<S: ScannerFeed, P: TransactionPlanner<S, ()>> SchedulerTrait<S> for Schedul
|
||||
&mut 0,
|
||||
block,
|
||||
vec![forward.clone()],
|
||||
vec![Payment::new(P::forwarding_address(forward_to_key), forward.balance(), None)],
|
||||
vec![Payment::new(P::forwarding_address(forward_to_key), forward.balance())],
|
||||
None,
|
||||
)
|
||||
.await?
|
||||
@@ -501,7 +501,7 @@ impl<S: ScannerFeed, P: TransactionPlanner<S, ()>> SchedulerTrait<S> for Schedul
|
||||
for to_return in update.returns() {
|
||||
let key = to_return.output().key();
|
||||
let out_instruction =
|
||||
Payment::new(to_return.address().clone(), to_return.output().balance(), None);
|
||||
Payment::new(to_return.address().clone(), to_return.output().balance());
|
||||
let Some(plan) = self
|
||||
.planner
|
||||
.plan_transaction_with_fee_amortization(
|
||||
|
||||
@@ -507,7 +507,7 @@ impl<S: ScannerFeed, P: TransactionPlanner<S, EffectedReceivedOutputs<S>>> Sched
|
||||
&mut 0,
|
||||
block,
|
||||
vec![forward.clone()],
|
||||
vec![Payment::new(P::forwarding_address(forward_to_key), forward.balance(), None)],
|
||||
vec![Payment::new(P::forwarding_address(forward_to_key), forward.balance())],
|
||||
None,
|
||||
)
|
||||
.await?
|
||||
@@ -519,7 +519,7 @@ impl<S: ScannerFeed, P: TransactionPlanner<S, EffectedReceivedOutputs<S>>> Sched
|
||||
for to_return in update.returns() {
|
||||
let key = to_return.output().key();
|
||||
let out_instruction =
|
||||
Payment::new(to_return.address().clone(), to_return.output().balance(), None);
|
||||
Payment::new(to_return.address().clone(), to_return.output().balance());
|
||||
let Some(plan) = self
|
||||
.planner
|
||||
.plan_transaction_with_fee_amortization(
|
||||
|
||||
@@ -184,7 +184,6 @@ pub async fn test_signer<N: Network>(
|
||||
let mut scheduler = N::Scheduler::new::<MemDb>(&mut txn, key, N::NETWORK);
|
||||
let payments = vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_signer called with Serai"),
|
||||
|
||||
@@ -88,7 +88,6 @@ pub async fn test_wallet<N: Network>(
|
||||
outputs.clone(),
|
||||
vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_wallet called with Serai"),
|
||||
@@ -116,7 +115,6 @@ pub async fn test_wallet<N: Network>(
|
||||
plans[0].payments,
|
||||
vec![Payment {
|
||||
address: N::external_address(&network, key).await,
|
||||
data: None,
|
||||
balance: Balance {
|
||||
coin: match N::NETWORK {
|
||||
NetworkId::Serai => panic!("test_wallet called with Serai"),
|
||||
|
||||
Reference in New Issue
Block a user