mirror of
https://github.com/serai-dex/serai.git
synced 2025-03-23 23:58:53 +00:00
Correct compilation errors
This commit is contained in:
parent
bc0cc5a754
commit
ce805c8cc8
8 changed files with 77 additions and 50 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -8669,6 +8669,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"parity-scale-codec",
|
"parity-scale-codec",
|
||||||
"serai-db",
|
"serai-db",
|
||||||
|
"serai-in-instructions-primitives",
|
||||||
"serai-primitives",
|
"serai-primitives",
|
||||||
"serai-processor-messages",
|
"serai-processor-messages",
|
||||||
"serai-processor-primitives",
|
"serai-processor-primitives",
|
||||||
|
|
|
@ -2,7 +2,7 @@ use core::fmt::Debug;
|
||||||
|
|
||||||
use group::{Group, GroupEncoding};
|
use group::{Group, GroupEncoding};
|
||||||
|
|
||||||
use crate::{Id, ReceivedOutput};
|
use crate::{Id, Address, ReceivedOutput};
|
||||||
|
|
||||||
/// A block header from an external network.
|
/// A block header from an external network.
|
||||||
pub trait BlockHeader: Send + Sync + Sized + Clone + Debug {
|
pub trait BlockHeader: Send + Sync + Sized + Clone + Debug {
|
||||||
|
@ -28,7 +28,7 @@ pub trait Block: Send + Sync + Sized + Clone + Debug {
|
||||||
/// The type used to represent keys on this external network.
|
/// The type used to represent keys on this external network.
|
||||||
type Key: Group + GroupEncoding;
|
type Key: Group + GroupEncoding;
|
||||||
/// The type used to represent addresses on this external network.
|
/// The type used to represent addresses on this external network.
|
||||||
type Address;
|
type Address: Address;
|
||||||
/// The type used to represent received outputs on this external network.
|
/// The type used to represent received outputs on this external network.
|
||||||
type Output: ReceivedOutput<Self::Key, Self::Address>;
|
type Output: ReceivedOutput<Self::Key, Self::Address>;
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,13 @@ use std::io;
|
||||||
|
|
||||||
use group::GroupEncoding;
|
use group::GroupEncoding;
|
||||||
|
|
||||||
use serai_primitives::Balance;
|
use serai_primitives::{ExternalAddress, Balance};
|
||||||
|
|
||||||
use crate::Id;
|
use crate::Id;
|
||||||
|
|
||||||
|
/// An address on the external network.
|
||||||
|
pub trait Address: Send + Sync + TryFrom<ExternalAddress> {}
|
||||||
|
|
||||||
/// The type of the output.
|
/// The type of the output.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||||
pub enum OutputType {
|
pub enum OutputType {
|
||||||
|
@ -81,7 +84,7 @@ impl OutputType {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A received output.
|
/// A received output.
|
||||||
pub trait ReceivedOutput<K: GroupEncoding, A>:
|
pub trait ReceivedOutput<K: GroupEncoding, A: Address>:
|
||||||
Send + Sync + Sized + Clone + PartialEq + Eq + Debug
|
Send + Sync + Sized + Clone + PartialEq + Eq + Debug
|
||||||
{
|
{
|
||||||
/// The type used to identify this output.
|
/// The type used to identify this output.
|
||||||
|
|
|
@ -36,6 +36,7 @@ tokio = { version = "1", default-features = false, features = ["rt-multi-thread"
|
||||||
serai-db = { path = "../../common/db" }
|
serai-db = { path = "../../common/db" }
|
||||||
|
|
||||||
serai-primitives = { path = "../../substrate/primitives", default-features = false, features = ["std"] }
|
serai-primitives = { path = "../../substrate/primitives", default-features = false, features = ["std"] }
|
||||||
|
serai-in-instructions-primitives = { path = "../../substrate/in-instructions/primitives", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
messages = { package = "serai-processor-messages", path = "../messages" }
|
messages = { package = "serai-processor-messages", path = "../messages" }
|
||||||
primitives = { package = "serai-processor-primitives", path = "../primitives" }
|
primitives = { package = "serai-processor-primitives", path = "../primitives" }
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
use group::GroupEncoding;
|
||||||
|
|
||||||
|
use scale::{Encode, Decode};
|
||||||
use borsh::{BorshSerialize, BorshDeserialize};
|
use borsh::{BorshSerialize, BorshDeserialize};
|
||||||
use serai_db::{Get, DbTxn, create_db};
|
use serai_db::{Get, DbTxn, create_db};
|
||||||
|
|
||||||
|
use serai_in_instructions_primitives::InInstructionWithBalance;
|
||||||
|
|
||||||
use primitives::{Id, ReceivedOutput, Block, BorshG};
|
use primitives::{Id, ReceivedOutput, Block, BorshG};
|
||||||
|
|
||||||
use crate::{lifetime::LifetimeStage, ScannerFeed, BlockIdFor, KeyFor, OutputFor};
|
use crate::{lifetime::LifetimeStage, ScannerFeed, BlockIdFor, KeyFor, AddressFor, OutputFor};
|
||||||
|
|
||||||
// The DB macro doesn't support `BorshSerialize + BorshDeserialize` as a bound, hence this.
|
// The DB macro doesn't support `BorshSerialize + BorshDeserialize` as a bound, hence this.
|
||||||
trait Borshy: BorshSerialize + BorshDeserialize {}
|
trait Borshy: BorshSerialize + BorshDeserialize {}
|
||||||
|
@ -22,16 +28,16 @@ pub(crate) struct SeraiKey<K> {
|
||||||
pub(crate) key: K,
|
pub(crate) key: K,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct OutputWithInInstruction<K: GroupEncoding, A, O: ReceivedOutput<K, A>> {
|
pub(crate) struct OutputWithInInstruction<S: ScannerFeed> {
|
||||||
output: O,
|
pub(crate) output: OutputFor<S>,
|
||||||
refund_address: A,
|
pub(crate) return_address: Option<AddressFor<S>>,
|
||||||
in_instruction: InInstructionWithBalance,
|
pub(crate) in_instruction: InInstructionWithBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: GroupEncoding, A, O: ReceivedOutput<K, A>> OutputWithInInstruction<K, A, O> {
|
impl<S: ScannerFeed> OutputWithInInstruction<S> {
|
||||||
fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
fn write(&self, writer: &mut impl io::Write) -> io::Result<()> {
|
||||||
self.output.write(writer)?;
|
self.output.write(writer)?;
|
||||||
// TODO self.refund_address.write(writer)?;
|
// TODO self.return_address.write(writer)?;
|
||||||
self.in_instruction.encode_to(writer);
|
self.in_instruction.encode_to(writer);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -172,6 +178,7 @@ impl<S: ScannerFeed> ScannerDb<S> {
|
||||||
// We can only scan up to whatever block we've checked the Eventualities of, plus the window
|
// We can only scan up to whatever block we've checked the Eventualities of, plus the window
|
||||||
// length. Since this returns an inclusive bound, we need to subtract 1
|
// length. Since this returns an inclusive bound, we need to subtract 1
|
||||||
// See `eventuality.rs` for more info
|
// See `eventuality.rs` for more info
|
||||||
|
// TODO: Adjust based on register eventualities
|
||||||
NextToCheckForEventualitiesBlock::get(getter).map(|b| b + S::WINDOW_LENGTH - 1)
|
NextToCheckForEventualitiesBlock::get(getter).map(|b| b + S::WINDOW_LENGTH - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +226,11 @@ impl<S: ScannerFeed> ScannerDb<S> {
|
||||||
HighestAcknowledgedBlock::get(getter)
|
HighestAcknowledgedBlock::get(getter)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn set_in_instructions(txn: &mut impl DbTxn, block_number: u64, outputs: Vec<OutputWithInInstruction<KeyFor<S>, AddressFor<S>, OutputFor<S>>>) {
|
pub(crate) fn set_in_instructions(
|
||||||
|
txn: &mut impl DbTxn,
|
||||||
|
block_number: u64,
|
||||||
|
outputs: Vec<OutputWithInInstruction<S>>,
|
||||||
|
) {
|
||||||
if outputs.is_empty() {
|
if outputs.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use core::{fmt::Debug, time::Duration};
|
use core::{marker::PhantomData, fmt::Debug, time::Duration};
|
||||||
|
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
|
|
||||||
|
@ -86,6 +86,7 @@ pub trait ScannerFeed: Send + Sync {
|
||||||
|
|
||||||
type BlockIdFor<S> = <<<S as ScannerFeed>::Block as Block>::Header as BlockHeader>::Id;
|
type BlockIdFor<S> = <<<S as ScannerFeed>::Block as Block>::Header as BlockHeader>::Id;
|
||||||
type KeyFor<S> = <<S as ScannerFeed>::Block as Block>::Key;
|
type KeyFor<S> = <<S as ScannerFeed>::Block as Block>::Key;
|
||||||
|
type AddressFor<S> = <<S as ScannerFeed>::Block as Block>::Address;
|
||||||
type OutputFor<S> = <<S as ScannerFeed>::Block as Block>::Output;
|
type OutputFor<S> = <<S as ScannerFeed>::Block as Block>::Output;
|
||||||
|
|
||||||
/// A handle to immediately run an iteration of a task.
|
/// A handle to immediately run an iteration of a task.
|
||||||
|
@ -171,8 +172,8 @@ pub(crate) trait ContinuallyRan: Sized {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A representation of a scanner.
|
/// A representation of a scanner.
|
||||||
pub struct Scanner;
|
pub struct Scanner<S: ScannerFeed>(PhantomData<S>);
|
||||||
impl Scanner {
|
impl<S: ScannerFeed> Scanner<S> {
|
||||||
/// Create a new scanner.
|
/// Create a new scanner.
|
||||||
///
|
///
|
||||||
/// This will begin its execution, spawning several asynchronous tasks.
|
/// This will begin its execution, spawning several asynchronous tasks.
|
||||||
|
@ -189,9 +190,12 @@ impl Scanner {
|
||||||
&mut self,
|
&mut self,
|
||||||
block_number: u64,
|
block_number: u64,
|
||||||
key_to_activate: Option<()>,
|
key_to_activate: Option<()>,
|
||||||
forwarded_outputs: Vec<()>,
|
) -> Vec<OutputFor<S>> {
|
||||||
eventualities_created: Vec<()>,
|
todo!("TODO")
|
||||||
) {
|
}
|
||||||
|
|
||||||
|
/// Register the Eventualities caused by a block.
|
||||||
|
pub fn register_eventualities(&mut self, block_number: u64, eventualities: Vec<()>) {
|
||||||
todo!("TODO")
|
todo!("TODO")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use serai_db::{Db, DbTxn};
|
use serai_db::{Db, DbTxn};
|
||||||
|
|
||||||
use primitives::{Id, Block};
|
use primitives::{Id, OutputType, Block};
|
||||||
|
|
||||||
// TODO: Localize to ReportDb?
|
// TODO: Localize to ReportDb?
|
||||||
use crate::{db::ScannerDb, ScannerFeed, ContinuallyRan};
|
use crate::{db::ScannerDb, ScannerFeed, ContinuallyRan};
|
||||||
|
@ -40,20 +40,8 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for ReportTask<D, S> {
|
||||||
|
|
||||||
for b in next_to_potentially_report ..= highest_reportable {
|
for b in next_to_potentially_report ..= highest_reportable {
|
||||||
if ScannerDb::<S>::is_block_notable(&self.db, b) {
|
if ScannerDb::<S>::is_block_notable(&self.db, b) {
|
||||||
let outputs = todo!("TODO");
|
let in_instructions = todo!("TODO");
|
||||||
let in_instructions_to_report = vec![];
|
// TODO: Also pull the InInstructions from forwarding
|
||||||
for output in outputs {
|
|
||||||
match output.kind() {
|
|
||||||
// These do get reported since the scanner eliminates any which shouldn't be reported
|
|
||||||
OutputType::External => todo!("TODO"),
|
|
||||||
// These do not get reported in Batches
|
|
||||||
OutputType::Branch | OutputType::Change => {}
|
|
||||||
// These now get reported if they're legitimately forwarded
|
|
||||||
OutputType::Forwarded => {
|
|
||||||
todo!("TODO")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
todo!("TODO: Make Batches, which requires handling Forwarded within this crate");
|
todo!("TODO: Make Batches, which requires handling Forwarded within this crate");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,28 @@
|
||||||
|
use group::GroupEncoding;
|
||||||
|
|
||||||
|
use scale::{Encode, Decode};
|
||||||
use serai_db::{Db, DbTxn};
|
use serai_db::{Db, DbTxn};
|
||||||
|
|
||||||
use primitives::{Id, ReceivedOutput, Block};
|
use serai_primitives::{MAX_DATA_LEN, ExternalAddress};
|
||||||
|
use serai_in_instructions_primitives::{
|
||||||
|
Shorthand, RefundableInInstruction, InInstruction, InInstructionWithBalance,
|
||||||
|
};
|
||||||
|
|
||||||
|
use primitives::{Id, OutputType, ReceivedOutput, Block};
|
||||||
|
|
||||||
// TODO: Localize to ScanDb?
|
// TODO: Localize to ScanDb?
|
||||||
use crate::{db::ScannerDb, ScannerFeed, ContinuallyRan};
|
use crate::{
|
||||||
|
lifetime::LifetimeStage,
|
||||||
|
db::{OutputWithInInstruction, ScannerDb},
|
||||||
|
ScannerFeed, AddressFor, OutputFor, ContinuallyRan,
|
||||||
|
};
|
||||||
|
|
||||||
// Construct an InInstruction from an external output.
|
// Construct an InInstruction from an external output.
|
||||||
//
|
//
|
||||||
// Also returns the address to refund the coins to upon error.
|
// Also returns the address to return the coins to upon error.
|
||||||
fn in_instruction_from_output<K: GroupEncoding, A>(
|
fn in_instruction_from_output<S: ScannerFeed>(
|
||||||
output: &impl ReceivedOutput<K, A>,
|
output: &OutputFor<S>,
|
||||||
) -> (Option<ExternalAddress>, Option<InInstruction>) {
|
) -> (Option<AddressFor<S>>, Option<InInstruction>) {
|
||||||
assert_eq!(output.kind(), OutputType::External);
|
assert_eq!(output.kind(), OutputType::External);
|
||||||
|
|
||||||
let presumed_origin = output.presumed_origin();
|
let presumed_origin = output.presumed_origin();
|
||||||
|
@ -18,7 +30,7 @@ fn in_instruction_from_output<K: GroupEncoding, A>(
|
||||||
let mut data = output.data();
|
let mut data = output.data();
|
||||||
let max_data_len = usize::try_from(MAX_DATA_LEN).unwrap();
|
let max_data_len = usize::try_from(MAX_DATA_LEN).unwrap();
|
||||||
if data.len() > max_data_len {
|
if data.len() > max_data_len {
|
||||||
error!(
|
log::info!(
|
||||||
"data in output {} exceeded MAX_DATA_LEN ({MAX_DATA_LEN}): {}. skipping",
|
"data in output {} exceeded MAX_DATA_LEN ({MAX_DATA_LEN}): {}. skipping",
|
||||||
hex::encode(output.id()),
|
hex::encode(output.id()),
|
||||||
data.len(),
|
data.len(),
|
||||||
|
@ -29,14 +41,14 @@ fn in_instruction_from_output<K: GroupEncoding, A>(
|
||||||
let shorthand = match Shorthand::decode(&mut data) {
|
let shorthand = match Shorthand::decode(&mut data) {
|
||||||
Ok(shorthand) => shorthand,
|
Ok(shorthand) => shorthand,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
info!("data in output {} wasn't valid shorthand: {e:?}", hex::encode(output.id()));
|
log::info!("data in output {} wasn't valid shorthand: {e:?}", hex::encode(output.id()));
|
||||||
return (presumed_origin, None);
|
return (presumed_origin, None);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let instruction = match RefundableInInstruction::try_from(shorthand) {
|
let instruction = match RefundableInInstruction::try_from(shorthand) {
|
||||||
Ok(instruction) => instruction,
|
Ok(instruction) => instruction,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
info!(
|
log::info!(
|
||||||
"shorthand in output {} wasn't convertible to a RefundableInInstruction: {e:?}",
|
"shorthand in output {} wasn't convertible to a RefundableInInstruction: {e:?}",
|
||||||
hex::encode(output.id())
|
hex::encode(output.id())
|
||||||
);
|
);
|
||||||
|
@ -45,7 +57,7 @@ fn in_instruction_from_output<K: GroupEncoding, A>(
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
instruction.origin.and_then(|addr| A::try_from(addr).ok()).or(presumed_origin),
|
instruction.origin.and_then(|addr| AddressFor::<S>::try_from(addr).ok()).or(presumed_origin),
|
||||||
Some(instruction.instruction),
|
Some(instruction.instruction),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -174,18 +186,25 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for ScanForOutputsTask<D, S> {
|
||||||
if balance.amount.0 < self.feed.dust(balance.coin).0 {
|
if balance.amount.0 < self.feed.dust(balance.coin).0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
balance
|
||||||
};
|
};
|
||||||
|
|
||||||
// Decode and save the InInstruction/refund addr for this output
|
// Decode and save the InInstruction/return addr for this output
|
||||||
match in_instruction_from_output::<S::Key, S::Address>(output) {
|
match in_instruction_from_output::<S>(&output) {
|
||||||
(refund_addr, Some(instruction)) => {
|
(return_address, Some(instruction)) => {
|
||||||
let instruction = InInstructionWithBalance { instruction, balance: balance_to_use };
|
let in_instruction =
|
||||||
|
InInstructionWithBalance { instruction, balance: balance_to_use };
|
||||||
// TODO: Make a proper struct out of this
|
// TODO: Make a proper struct out of this
|
||||||
in_instructions.push((output.id(), refund_addr, instruction));
|
in_instructions.push(OutputWithInInstruction {
|
||||||
|
output,
|
||||||
|
return_address,
|
||||||
|
in_instruction,
|
||||||
|
});
|
||||||
todo!("TODO: Save to be reported")
|
todo!("TODO: Save to be reported")
|
||||||
}
|
}
|
||||||
(Some(refund_addr), None) => todo!("TODO: Queue refund"),
|
(Some(return_addr), None) => todo!("TODO: Queue return"),
|
||||||
// Since we didn't receive an instruction nor can we refund this, accumulate it
|
// Since we didn't receive an instruction nor can we return this, accumulate it
|
||||||
(None, None) => {}
|
(None, None) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue