Update serai-ethereum-processor to compile

This commit is contained in:
Luke Parker 2024-10-30 21:48:40 -04:00
parent 8e800885fb
commit b2ec58a445
No known key found for this signature in database
7 changed files with 27 additions and 68 deletions

View file

@ -296,7 +296,7 @@ pub async fn main_loop<
is equally valid unless we want to start introspecting (and should be our only is equally valid unless we want to start introspecting (and should be our only
Batch anyways). Batch anyways).
*/ */
burns.drain(..).collect(), std::mem::take(&mut burns),
key_to_activate, key_to_activate,
); );
} }

View file

@ -67,7 +67,7 @@ impl Deployer {
/// Construct a new view of the Deployer. /// Construct a new view of the Deployer.
/// ///
/// This will return None if the Deployer has yet to be deployed on-chain. /// This will return `None` if the Deployer has yet to be deployed on-chain.
pub async fn new( pub async fn new(
provider: Arc<RootProvider<SimpleRequest>>, provider: Arc<RootProvider<SimpleRequest>>,
) -> Result<Option<Self>, RpcError<TransportErrorKind>> { ) -> Result<Option<Self>, RpcError<TransportErrorKind>> {

View file

@ -168,20 +168,19 @@ impl From<&[(SeraiAddress, U256)]> for OutInstructions {
.map(|(address, amount)| { .map(|(address, amount)| {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let (destinationType, destination) = match address { let (destinationType, destination) = match address {
SeraiAddress::Address(address) => ( SeraiAddress::Address(address) => {
abi::DestinationType::Address, (abi::DestinationType::Address, (Address::from(address)).abi_encode())
(abi::AddressDestination { destination: Address::from(address) }).abi_encode(), }
),
SeraiAddress::Contract(contract) => ( SeraiAddress::Contract(contract) => (
abi::DestinationType::Code, abi::DestinationType::Code,
(abi::CodeDestination { (abi::CodeDestination {
gas_limit: contract.gas_limit(), gasLimit: contract.gas_limit(),
code: contract.code().to_vec().into(), code: contract.code().to_vec().into(),
}) })
.abi_encode(), .abi_encode(),
), ),
}; };
abi::OutInstruction { destinationType, destination: destination.into(), value: *amount } abi::OutInstruction { destinationType, destination: destination.into(), amount: *amount }
}) })
.collect(), .collect(),
) )
@ -298,11 +297,7 @@ impl Router {
/// Get the message to be signed in order to update the key for Serai. /// Get the message to be signed in order to update the key for Serai.
pub fn update_serai_key_message(nonce: u64, key: &PublicKey) -> Vec<u8> { pub fn update_serai_key_message(nonce: u64, key: &PublicKey) -> Vec<u8> {
( ("updateSeraiKey", U256::try_from(nonce).expect("couldn't convert u64 to u256"), key.eth_repr())
"updateSeraiKey",
U256::try_from(nonce).expect("couldn't convert u64 to u256"),
key.eth_repr(),
)
.abi_encode_packed() .abi_encode_packed()
} }
@ -320,12 +315,7 @@ impl Router {
} }
/// Get the message to be signed in order to execute a series of `OutInstruction`s. /// Get the message to be signed in order to execute a series of `OutInstruction`s.
pub fn execute_message( pub fn execute_message(nonce: u64, coin: Coin, fee: U256, outs: OutInstructions) -> Vec<u8> {
nonce: u64,
coin: Coin,
fee: U256,
outs: OutInstructions,
) -> Vec<u8> {
("execute", U256::try_from(nonce).unwrap(), coin.address(), fee, outs.0).abi_encode() ("execute", U256::try_from(nonce).unwrap(), coin.address(), fee, outs.0).abi_encode()
} }
@ -540,7 +530,7 @@ impl Router {
nonce: log.nonce.try_into().map_err(|e| { nonce: log.nonce.try_into().map_err(|e| {
TransportErrorKind::Custom(format!("filtered to convert nonce to u64: {e:?}").into()) TransportErrorKind::Custom(format!("filtered to convert nonce to u64: {e:?}").into())
})?, })?,
message_hash: log.message_hash.into(), message_hash: log.messageHash.into(),
}); });
} }
} }

View file

@ -8,10 +8,9 @@ static ALLOCATOR: zalloc::ZeroizingAlloc<std::alloc::System> =
use std::sync::Arc; use std::sync::Arc;
use alloy_core::primitives::U256;
use alloy_simple_request_transport::SimpleRequest; use alloy_simple_request_transport::SimpleRequest;
use alloy_rpc_client::ClientBuilder; use alloy_rpc_client::ClientBuilder;
use alloy_provider::{Provider, RootProvider}; use alloy_provider::RootProvider;
use serai_client::validator_sets::primitives::Session; use serai_client::validator_sets::primitives::Session;
@ -63,20 +62,10 @@ async fn main() {
ClientBuilder::default().transport(SimpleRequest::new(bin::url()), true), ClientBuilder::default().transport(SimpleRequest::new(bin::url()), true),
)); ));
let chain_id = loop {
match provider.get_chain_id().await {
Ok(chain_id) => break U256::try_from(chain_id).unwrap(),
Err(e) => {
log::error!("couldn't connect to the Ethereum node for the chain ID: {e:?}");
tokio::time::sleep(core::time::Duration::from_secs(5)).await;
}
}
};
bin::main_loop::<SetInitialKey, _, KeyGenParams, _>( bin::main_loop::<SetInitialKey, _, KeyGenParams, _>(
db.clone(), db.clone(),
Rpc { db: db.clone(), provider: provider.clone() }, Rpc { db: db.clone(), provider: provider.clone() },
Scheduler::<bin::Db>::new(SmartContract { chain_id }), Scheduler::<bin::Db>::new(SmartContract),
TransactionPublisher::new(db, provider, { TransactionPublisher::new(db, provider, {
let relayer_hostname = env::var("ETHEREUM_RELAYER_HOSTNAME") let relayer_hostname = env::var("ETHEREUM_RELAYER_HOSTNAME")
.expect("ethereum relayer hostname wasn't specified") .expect("ethereum relayer hostname wasn't specified")

View file

@ -17,8 +17,8 @@ use crate::{output::OutputId, machine::ClonableTransctionMachine};
#[derive(Clone, PartialEq, Debug)] #[derive(Clone, PartialEq, Debug)]
pub(crate) enum Action { pub(crate) enum Action {
SetKey { chain_id: U256, nonce: u64, key: PublicKey }, SetKey { nonce: u64, key: PublicKey },
Batch { chain_id: U256, nonce: u64, coin: Coin, fee: U256, outs: Vec<(Address, U256)> }, Batch { nonce: u64, coin: Coin, fee: U256, outs: Vec<(Address, U256)> },
} }
#[derive(Clone, PartialEq, Eq, Debug)] #[derive(Clone, PartialEq, Eq, Debug)]
@ -33,24 +33,16 @@ impl Action {
pub(crate) fn message(&self) -> Vec<u8> { pub(crate) fn message(&self) -> Vec<u8> {
match self { match self {
Action::SetKey { chain_id, nonce, key } => { Action::SetKey { nonce, key } => Router::update_serai_key_message(*nonce, key),
Router::update_serai_key_message(*chain_id, *nonce, key) Action::Batch { nonce, coin, fee, outs } => {
Router::execute_message(*nonce, *coin, *fee, OutInstructions::from(outs.as_ref()))
} }
Action::Batch { chain_id, nonce, coin, fee, outs } => Router::execute_message(
*chain_id,
*nonce,
*coin,
*fee,
OutInstructions::from(outs.as_ref()),
),
} }
} }
pub(crate) fn eventuality(&self) -> Eventuality { pub(crate) fn eventuality(&self) -> Eventuality {
Eventuality(match self { Eventuality(match self {
Self::SetKey { chain_id: _, nonce, key } => { Self::SetKey { nonce, key } => Executed::SetKey { nonce: *nonce, key: key.eth_repr() },
Executed::SetKey { nonce: *nonce, key: key.eth_repr() }
}
Self::Batch { nonce, .. } => { Self::Batch { nonce, .. } => {
Executed::Batch { nonce: *nonce, message_hash: keccak256(self.message()) } Executed::Batch { nonce: *nonce, message_hash: keccak256(self.message()) }
} }
@ -85,10 +77,6 @@ impl SignableTransaction for Action {
Err(io::Error::other("unrecognized Action type"))?; Err(io::Error::other("unrecognized Action type"))?;
} }
let mut chain_id = [0; 32];
reader.read_exact(&mut chain_id)?;
let chain_id = U256::from_le_bytes(chain_id);
let mut nonce = [0; 8]; let mut nonce = [0; 8];
reader.read_exact(&mut nonce)?; reader.read_exact(&mut nonce)?;
let nonce = u64::from_le_bytes(nonce); let nonce = u64::from_le_bytes(nonce);
@ -100,7 +88,7 @@ impl SignableTransaction for Action {
let key = let key =
PublicKey::from_eth_repr(key).ok_or_else(|| io::Error::other("invalid key in Action"))?; PublicKey::from_eth_repr(key).ok_or_else(|| io::Error::other("invalid key in Action"))?;
Action::SetKey { chain_id, nonce, key } Action::SetKey { nonce, key }
} }
1 => { 1 => {
let coin = Coin::read(reader)?; let coin = Coin::read(reader)?;
@ -123,22 +111,20 @@ impl SignableTransaction for Action {
outs.push((address, amount)); outs.push((address, amount));
} }
Action::Batch { chain_id, nonce, coin, fee, outs } Action::Batch { nonce, coin, fee, outs }
} }
_ => unreachable!(), _ => unreachable!(),
}) })
} }
fn write(&self, writer: &mut impl io::Write) -> io::Result<()> { fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
match self { match self {
Self::SetKey { chain_id, nonce, key } => { Self::SetKey { nonce, key } => {
writer.write_all(&[0])?; writer.write_all(&[0])?;
writer.write_all(&chain_id.as_le_bytes())?;
writer.write_all(&nonce.to_le_bytes())?; writer.write_all(&nonce.to_le_bytes())?;
writer.write_all(&key.eth_repr()) writer.write_all(&key.eth_repr())
} }
Self::Batch { chain_id, nonce, coin, fee, outs } => { Self::Batch { nonce, coin, fee, outs } => {
writer.write_all(&[1])?; writer.write_all(&[1])?;
writer.write_all(&chain_id.as_le_bytes())?;
writer.write_all(&nonce.to_le_bytes())?; writer.write_all(&nonce.to_le_bytes())?;
coin.write(writer)?; coin.write(writer)?;
writer.write_all(&fee.as_le_bytes())?; writer.write_all(&fee.as_le_bytes())?;

View file

@ -88,8 +88,8 @@ impl<D: Db> signers::TransactionPublisher<Transaction> for TransactionPublisher<
let nonce = tx.0.nonce(); let nonce = tx.0.nonce();
// Convert from an Action (an internal representation of a signable event) to a TxLegacy // Convert from an Action (an internal representation of a signable event) to a TxLegacy
let tx = match tx.0 { let tx = match tx.0 {
Action::SetKey { chain_id: _, nonce: _, key } => router.update_serai_key(&key, &tx.1), Action::SetKey { nonce: _, key } => router.update_serai_key(&key, &tx.1),
Action::Batch { chain_id: _, nonce: _, coin, fee, outs } => { Action::Batch { nonce: _, coin, fee, outs } => {
router.execute(coin, fee, OutInstructions::from(outs.as_ref()), &tx.1) router.execute(coin, fee, OutInstructions::from(outs.as_ref()), &tx.1)
} }
}; };

View file

@ -36,9 +36,7 @@ fn balance_to_ethereum_amount(balance: Balance) -> U256 {
} }
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct SmartContract { pub(crate) struct SmartContract;
pub(crate) chain_id: U256,
}
impl<D: Db> smart_contract_scheduler::SmartContract<Rpc<D>> for SmartContract { impl<D: Db> smart_contract_scheduler::SmartContract<Rpc<D>> for SmartContract {
type SignableTransaction = Action; type SignableTransaction = Action;
@ -48,11 +46,8 @@ impl<D: Db> smart_contract_scheduler::SmartContract<Rpc<D>> for SmartContract {
_retiring_key: KeyFor<Rpc<D>>, _retiring_key: KeyFor<Rpc<D>>,
new_key: KeyFor<Rpc<D>>, new_key: KeyFor<Rpc<D>>,
) -> (Self::SignableTransaction, EventualityFor<Rpc<D>>) { ) -> (Self::SignableTransaction, EventualityFor<Rpc<D>>) {
let action = Action::SetKey { let action =
chain_id: self.chain_id, Action::SetKey { nonce, key: PublicKey::new(new_key).expect("rotating to an invald key") };
nonce,
key: PublicKey::new(new_key).expect("rotating to an invald key"),
};
(action.clone(), action.eventuality()) (action.clone(), action.eventuality())
} }
@ -138,7 +133,6 @@ impl<D: Db> smart_contract_scheduler::SmartContract<Rpc<D>> for SmartContract {
} }
res.push(Action::Batch { res.push(Action::Batch {
chain_id: self.chain_id,
nonce, nonce,
coin: coin_to_ethereum_coin(coin), coin: coin_to_ethereum_coin(coin),
fee: U256::try_from(total_gas).unwrap() * fee_per_gas, fee: U256::try_from(total_gas).unwrap() * fee_per_gas,