Add Batch messages from processor, verify Batchs published on-chain

Renames Update to SignedBatch.

Checks Batch equality via a hash of the InInstructions. That prevents needing
to keep the Batch in node state or TX introspect.
This commit is contained in:
Luke Parker
2023-09-29 03:51:01 -04:00
parent 0be567ff69
commit 0eff3d9453
18 changed files with 281 additions and 80 deletions

View File

@@ -17,9 +17,10 @@ thiserror = { version = "1", optional = true }
scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2", default-features = false, features = ["derive"] }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-io = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-application-crypto = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-runtime = { git = "https://github.com/serai-dex/substrate", default-features = false }
sp-core = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-system = { git = "https://github.com/serai-dex/substrate", default-features = false }
frame-support = { git = "https://github.com/serai-dex/substrate", default-features = false }
@@ -37,6 +38,9 @@ std = [
"scale/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-application-crypto/std",
"sp-runtime/std",
"frame-system/std",

View File

@@ -4,6 +4,7 @@
use scale::Encode;
use sp_io::hashing::blake2_256;
use sp_runtime::RuntimeDebug;
use serai_primitives::{BlockHash, NetworkId};
@@ -45,7 +46,7 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(fn deposit_event)]
pub enum Event<T: Config> {
Batch { network: NetworkId, id: u32, block: BlockHash },
Batch { network: NetworkId, id: u32, block: BlockHash, instructions_hash: [u8; 32] },
InstructionFailure { network: NetworkId, id: u32, index: u32 },
}
@@ -123,6 +124,7 @@ pub mod pallet {
network: batch.network,
id: batch.id,
block: batch.block,
instructions_hash: blake2_256(&batch.instructions.encode()),
});
for (i, instruction) in batch.instructions.into_iter().enumerate() {
// TODO: Check this balance's coin belongs to this network