mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
Split FinalizedBlock into ExternalBlock and SeraiBlock
Also re-arranges their orders.
This commit is contained in:
parent
9c2a44f9df
commit
a26ca1a92f
3 changed files with 76 additions and 56 deletions
|
@ -71,11 +71,12 @@ fn serialize_transaction() {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
test_read_write(Transaction::SignPreprocess(random_sign_data(&mut OsRng)));
|
test_read_write(Transaction::ExternalBlock(OsRng.next_u64()));
|
||||||
test_read_write(Transaction::SignShare(random_sign_data(&mut OsRng)));
|
test_read_write(Transaction::SeraiBlock(OsRng.next_u64()));
|
||||||
|
|
||||||
test_read_write(Transaction::FinalizedBlock(OsRng.next_u64()));
|
|
||||||
|
|
||||||
test_read_write(Transaction::BatchPreprocess(random_sign_data(&mut OsRng)));
|
test_read_write(Transaction::BatchPreprocess(random_sign_data(&mut OsRng)));
|
||||||
test_read_write(Transaction::BatchShare(random_sign_data(&mut OsRng)));
|
test_read_write(Transaction::BatchShare(random_sign_data(&mut OsRng)));
|
||||||
|
|
||||||
|
test_read_write(Transaction::SignPreprocess(random_sign_data(&mut OsRng)));
|
||||||
|
test_read_write(Transaction::SignShare(random_sign_data(&mut OsRng)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,13 +157,17 @@ pub enum Transaction {
|
||||||
DkgCommitments(u32, Vec<u8>, Signed),
|
DkgCommitments(u32, Vec<u8>, Signed),
|
||||||
DkgShares(u32, HashMap<Participant, Vec<u8>>, Signed),
|
DkgShares(u32, HashMap<Participant, Vec<u8>>, Signed),
|
||||||
|
|
||||||
SignPreprocess(SignData),
|
// When an external block is finalized, we can allow the associated batch IDs
|
||||||
SignShare(SignData),
|
ExternalBlock(u64),
|
||||||
|
// When a Serai block is finalized, with the contained batches, we can allow the associated plan
|
||||||
FinalizedBlock(u64),
|
// IDs
|
||||||
|
SeraiBlock(u64),
|
||||||
|
|
||||||
BatchPreprocess(SignData),
|
BatchPreprocess(SignData),
|
||||||
BatchShare(SignData),
|
BatchShare(SignData),
|
||||||
|
|
||||||
|
SignPreprocess(SignData),
|
||||||
|
SignShare(SignData),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReadWrite for Transaction {
|
impl ReadWrite for Transaction {
|
||||||
|
@ -218,17 +222,24 @@ impl ReadWrite for Transaction {
|
||||||
Ok(Transaction::DkgShares(attempt, shares, signed))
|
Ok(Transaction::DkgShares(attempt, shares, signed))
|
||||||
}
|
}
|
||||||
|
|
||||||
2 => SignData::read(reader).map(Transaction::SignPreprocess),
|
2 => {
|
||||||
3 => SignData::read(reader).map(Transaction::SignShare),
|
|
||||||
|
|
||||||
4 => {
|
|
||||||
let mut block = [0; 8];
|
let mut block = [0; 8];
|
||||||
reader.read_exact(&mut block)?;
|
reader.read_exact(&mut block)?;
|
||||||
Ok(Transaction::FinalizedBlock(u64::from_le_bytes(block)))
|
Ok(Transaction::ExternalBlock(u64::from_le_bytes(block)))
|
||||||
}
|
}
|
||||||
|
|
||||||
5 => SignData::read(reader).map(Transaction::BatchPreprocess),
|
3 => {
|
||||||
6 => SignData::read(reader).map(Transaction::BatchShare),
|
let mut block = [0; 8];
|
||||||
|
reader.read_exact(&mut block)?;
|
||||||
|
Ok(Transaction::SeraiBlock(u64::from_le_bytes(block)))
|
||||||
|
}
|
||||||
|
|
||||||
|
4 => SignData::read(reader).map(Transaction::BatchPreprocess),
|
||||||
|
5 => SignData::read(reader).map(Transaction::BatchShare),
|
||||||
|
|
||||||
|
6 => SignData::read(reader).map(Transaction::SignPreprocess),
|
||||||
|
7 => SignData::read(reader).map(Transaction::SignShare),
|
||||||
|
|
||||||
_ => Err(io::Error::new(io::ErrorKind::Other, "invalid transaction type")),
|
_ => Err(io::Error::new(io::ErrorKind::Other, "invalid transaction type")),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,28 +285,33 @@ impl ReadWrite for Transaction {
|
||||||
signed.write(writer)
|
signed.write(writer)
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction::SignPreprocess(data) => {
|
Transaction::ExternalBlock(block) => {
|
||||||
writer.write_all(&[2])?;
|
writer.write_all(&[2])?;
|
||||||
data.write(writer)
|
writer.write_all(&block.to_le_bytes())
|
||||||
}
|
|
||||||
Transaction::SignShare(data) => {
|
|
||||||
writer.write_all(&[3])?;
|
|
||||||
data.write(writer)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction::FinalizedBlock(block) => {
|
Transaction::SeraiBlock(block) => {
|
||||||
writer.write_all(&[4])?;
|
writer.write_all(&[3])?;
|
||||||
writer.write_all(&block.to_le_bytes())
|
writer.write_all(&block.to_le_bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction::BatchPreprocess(data) => {
|
Transaction::BatchPreprocess(data) => {
|
||||||
writer.write_all(&[5])?;
|
writer.write_all(&[4])?;
|
||||||
data.write(writer)
|
data.write(writer)
|
||||||
}
|
}
|
||||||
Transaction::BatchShare(data) => {
|
Transaction::BatchShare(data) => {
|
||||||
|
writer.write_all(&[5])?;
|
||||||
|
data.write(writer)
|
||||||
|
}
|
||||||
|
|
||||||
|
Transaction::SignPreprocess(data) => {
|
||||||
writer.write_all(&[6])?;
|
writer.write_all(&[6])?;
|
||||||
data.write(writer)
|
data.write(writer)
|
||||||
}
|
}
|
||||||
|
Transaction::SignShare(data) => {
|
||||||
|
writer.write_all(&[7])?;
|
||||||
|
data.write(writer)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -306,13 +322,15 @@ impl TransactionTrait for Transaction {
|
||||||
Transaction::DkgCommitments(_, _, signed) => TransactionKind::Signed(signed),
|
Transaction::DkgCommitments(_, _, signed) => TransactionKind::Signed(signed),
|
||||||
Transaction::DkgShares(_, _, signed) => TransactionKind::Signed(signed),
|
Transaction::DkgShares(_, _, signed) => TransactionKind::Signed(signed),
|
||||||
|
|
||||||
Transaction::SignPreprocess(data) => TransactionKind::Signed(&data.signed),
|
// TODO: Tributary requires these be perfectly ordered, yet they have two separate clocks
|
||||||
Transaction::SignShare(data) => TransactionKind::Signed(&data.signed),
|
Transaction::ExternalBlock(_) => TransactionKind::Provided,
|
||||||
|
Transaction::SeraiBlock(_) => TransactionKind::Provided,
|
||||||
Transaction::FinalizedBlock(_) => TransactionKind::Provided,
|
|
||||||
|
|
||||||
Transaction::BatchPreprocess(data) => TransactionKind::Signed(&data.signed),
|
Transaction::BatchPreprocess(data) => TransactionKind::Signed(&data.signed),
|
||||||
Transaction::BatchShare(data) => TransactionKind::Signed(&data.signed),
|
Transaction::BatchShare(data) => TransactionKind::Signed(&data.signed),
|
||||||
|
|
||||||
|
Transaction::SignPreprocess(data) => TransactionKind::Signed(&data.signed),
|
||||||
|
Transaction::SignShare(data) => TransactionKind::Signed(&data.signed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,35 +135,9 @@ async fn handle_block<D: Db, Pro: Processor, P: P2p>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction::SignPreprocess(data) => {
|
|
||||||
// TODO: Validate data.plan
|
|
||||||
if let Some(preprocesses) =
|
|
||||||
handle(b"sign_preprocess", spec.t(), data.plan, data.attempt, data.data, data.signed)
|
|
||||||
{
|
|
||||||
processor
|
|
||||||
.send(CoordinatorMessage::Sign(sign::CoordinatorMessage::Preprocesses {
|
|
||||||
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
|
||||||
preprocesses,
|
|
||||||
}))
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Transaction::SignShare(data) => {
|
|
||||||
// TODO: Validate data.plan
|
|
||||||
if let Some(shares) =
|
|
||||||
handle(b"sign_share", spec.t(), data.plan, data.attempt, data.data, data.signed)
|
|
||||||
{
|
|
||||||
processor
|
|
||||||
.send(CoordinatorMessage::Sign(sign::CoordinatorMessage::Shares {
|
|
||||||
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
|
||||||
shares,
|
|
||||||
}))
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
Transaction::FinalizedBlock(..) => todo!(),
|
Transaction::ExternalBlock(..) => todo!(),
|
||||||
|
Transaction::SeraiBlock(..) => todo!(),
|
||||||
|
|
||||||
Transaction::BatchPreprocess(data) => {
|
Transaction::BatchPreprocess(data) => {
|
||||||
// TODO: Validate data.plan
|
// TODO: Validate data.plan
|
||||||
|
@ -196,6 +170,33 @@ async fn handle_block<D: Db, Pro: Processor, P: P2p>(
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Transaction::SignPreprocess(data) => {
|
||||||
|
// TODO: Validate data.plan
|
||||||
|
if let Some(preprocesses) =
|
||||||
|
handle(b"sign_preprocess", spec.t(), data.plan, data.attempt, data.data, data.signed)
|
||||||
|
{
|
||||||
|
processor
|
||||||
|
.send(CoordinatorMessage::Sign(sign::CoordinatorMessage::Preprocesses {
|
||||||
|
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
||||||
|
preprocesses,
|
||||||
|
}))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Transaction::SignShare(data) => {
|
||||||
|
// TODO: Validate data.plan
|
||||||
|
if let Some(shares) =
|
||||||
|
handle(b"sign_share", spec.t(), data.plan, data.attempt, data.data, data.signed)
|
||||||
|
{
|
||||||
|
processor
|
||||||
|
.send(CoordinatorMessage::Sign(sign::CoordinatorMessage::Shares {
|
||||||
|
id: SignId { key: todo!(), id: data.plan, attempt: data.attempt },
|
||||||
|
shares,
|
||||||
|
}))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TributaryDb::<D>::handle_event(&mut txn, hash, event_id);
|
TributaryDb::<D>::handle_event(&mut txn, hash, event_id);
|
||||||
|
|
Loading…
Reference in a new issue