mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
ExternalBlock handler
This commit is contained in:
@@ -25,6 +25,14 @@ impl<D: Db> TributaryDb<D> {
|
|||||||
self.0.get(Self::block_key(genesis)).unwrap_or(genesis.to_vec()).try_into().unwrap()
|
self.0.get(Self::block_key(genesis)).unwrap_or(genesis.to_vec()).try_into().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This shouldn't need genesis? Yet it's saner to have then quibble about.
|
||||||
|
fn batch_id_key(genesis: &[u8], ext_block: [u8; 32]) -> Vec<u8> {
|
||||||
|
Self::tributary_key(b"batch_id", [genesis, ext_block.as_ref()].concat())
|
||||||
|
}
|
||||||
|
pub fn batch_id<G: Get>(getter: &G, genesis: [u8; 32], ext_block: [u8; 32]) -> Option<[u8; 32]> {
|
||||||
|
getter.get(Self::batch_id_key(&genesis, ext_block)).map(|bytes| bytes.try_into().unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
fn recognized_id_key(label: &'static str, genesis: [u8; 32], id: [u8; 32]) -> Vec<u8> {
|
fn recognized_id_key(label: &'static str, genesis: [u8; 32], id: [u8; 32]) -> Vec<u8> {
|
||||||
Self::tributary_key(b"recognized", [label.as_bytes(), genesis.as_ref(), id.as_ref()].concat())
|
Self::tributary_key(b"recognized", [label.as_bytes(), genesis.as_ref(), id.as_ref()].concat())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,20 +46,24 @@ async fn handle_block<D: Db, Pro: Processor, P: P2p>(
|
|||||||
Sign,
|
Sign,
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut handle = |zone, label, needed, id, attempt, mut bytes: Vec<u8>, signed: Signed| {
|
impl Zone {
|
||||||
|
fn label(&self) -> &'static str {
|
||||||
|
match self {
|
||||||
|
Zone::Dkg => {
|
||||||
|
panic!("getting the label for dkg despite dkg code paths not needing a label")
|
||||||
|
}
|
||||||
|
Zone::Batch => "batch",
|
||||||
|
Zone::Sign => "sign",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut handle =
|
||||||
|
|zone: Zone, label, needed, id, attempt, mut bytes: Vec<u8>, signed: Signed| {
|
||||||
if zone == Zone::Dkg {
|
if zone == Zone::Dkg {
|
||||||
// Since Dkg doesn't have an ID, solely attempts, this should just be [0; 32]
|
// Since Dkg doesn't have an ID, solely attempts, this should just be [0; 32]
|
||||||
assert_eq!(id, [0; 32], "DKG, which shouldn't have IDs, had a non-0 ID");
|
assert_eq!(id, [0; 32], "DKG, which shouldn't have IDs, had a non-0 ID");
|
||||||
} else if !TributaryDb::<D>::recognized_id(
|
} else if !TributaryDb::<D>::recognized_id(&txn, zone.label(), tributary.genesis(), id) {
|
||||||
&txn,
|
|
||||||
match zone {
|
|
||||||
Zone::Dkg => panic!("zone was Dkg despite prior if clause handling Dkg"),
|
|
||||||
Zone::Batch => "batch",
|
|
||||||
Zone::Sign => "sign",
|
|
||||||
},
|
|
||||||
tributary.genesis(),
|
|
||||||
id,
|
|
||||||
) {
|
|
||||||
// TODO: Full slash
|
// TODO: Full slash
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
@@ -163,8 +167,25 @@ async fn handle_block<D: Db, Pro: Processor, P: P2p>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
Transaction::ExternalBlock(block) => {
|
||||||
Transaction::ExternalBlock(..) => todo!(),
|
// Because this external block has been finalized, its batch ID should be authorized
|
||||||
|
|
||||||
|
// If we didn't provide this transaction, we should halt until we do
|
||||||
|
// If we provided a distinct transaction, we should error
|
||||||
|
// If we did provide this transaction, we should've set the batch ID for the block
|
||||||
|
let batch_id =
|
||||||
|
TributaryDb::<D>::batch_id(&txn, tributary.genesis(), block).expect(concat!(
|
||||||
|
"synced a tributary block finalizing a block in a provided transaction despite ",
|
||||||
|
"us not providing that transaction"
|
||||||
|
));
|
||||||
|
|
||||||
|
TributaryDb::<D>::recognize_id(
|
||||||
|
&mut txn,
|
||||||
|
Zone::Batch.label(),
|
||||||
|
tributary.genesis(),
|
||||||
|
batch_id,
|
||||||
|
);
|
||||||
|
}
|
||||||
Transaction::SeraiBlock(..) => todo!(),
|
Transaction::SeraiBlock(..) => todo!(),
|
||||||
|
|
||||||
Transaction::BatchPreprocess(data) => {
|
Transaction::BatchPreprocess(data) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user