mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-06 14:58:03 +00:00
Make digest compilation work.
This commit is contained in:
@@ -71,7 +71,7 @@ mod tests {
|
||||
|
||||
let transaction_root = ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0;
|
||||
|
||||
let header = Header {
|
||||
let mut header = Header {
|
||||
parent_hash,
|
||||
number,
|
||||
state_root,
|
||||
@@ -83,16 +83,16 @@ mod tests {
|
||||
let mut overlay = OverlayedChanges::default();
|
||||
|
||||
for tx in transactions.iter() {
|
||||
let _ = execute(
|
||||
header = Header::from_slice(&execute(
|
||||
backend,
|
||||
&mut overlay,
|
||||
&executor(),
|
||||
"execute_transaction",
|
||||
&CallData(vec![].join(&number).join(tx))
|
||||
).unwrap();
|
||||
&CallData(vec![].join(&header).join(tx))
|
||||
).unwrap()).unwrap();
|
||||
}
|
||||
|
||||
let header = Header::from_slice(&execute(
|
||||
header = Header::from_slice(&execute(
|
||||
backend,
|
||||
&mut overlay,
|
||||
&executor(),
|
||||
|
||||
@@ -44,7 +44,7 @@ mod tests {
|
||||
use super::*;
|
||||
use runtime_std::TestExternalities;
|
||||
use native_runtime::codec::{KeyedVec, Joiner, Slicable};
|
||||
use native_runtime::support::{one, two, StaticHexInto, Hashable};
|
||||
use native_runtime::support::{one, two, Hashable};
|
||||
use native_runtime::primitives::*;
|
||||
use native_runtime::runtime::staking::balance;
|
||||
use primitives::twox_128;
|
||||
@@ -71,7 +71,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = NativeExecutor.call(&mut t, BLOATY_CODE, "execute_transaction", &CallData(vec![].join(&1u64).join(&tx())));
|
||||
let r = NativeExecutor.call(&mut t, BLOATY_CODE, "execute_transaction", &CallData(vec![].join(&Header::from_block_number(1u64)).join(&tx())));
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![68u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = NativeExecutor.call(&mut t, COMPACT_CODE, "execute_transaction", &CallData(vec![].join(&1u64).join(&tx())));
|
||||
let r = NativeExecutor.call(&mut t, COMPACT_CODE, "execute_transaction", &CallData(vec![].join(&Header::from_block_number(1u64)).join(&tx())));
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = NativeExecutor.call(&mut t, COMPACT_CODE, "execute_transaction", &CallData(vec![].join(&1u64).join(&tx())));
|
||||
let r = NativeExecutor.call(&mut t, COMPACT_CODE, "execute_transaction", &CallData(vec![].join(&Header::from_block_number(1u64)).join(&tx())));
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_std::with_externalities(&mut t, || {
|
||||
@@ -113,7 +113,7 @@ mod tests {
|
||||
twox_128(&one.to_keyed_vec(b"sta:bal:")).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0]
|
||||
], };
|
||||
|
||||
let r = NativeExecutor.call(&mut t, BLOATY_CODE, "execute_transaction", &CallData(vec![].join(&1u64).join(&tx())));
|
||||
let r = NativeExecutor.call(&mut t, BLOATY_CODE, "execute_transaction", &CallData(vec![].join(&Header::from_block_number(1u64)).join(&tx())));
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_std::with_externalities(&mut t, || {
|
||||
|
||||
@@ -293,7 +293,7 @@ mod tests {
|
||||
use primitives::{blake2_256, twox_128};
|
||||
use runtime_std::{self, TestExternalities};
|
||||
use native_runtime::support::{one, two};
|
||||
use native_runtime::primitives::{UncheckedTransaction, AccountID};
|
||||
use native_runtime::primitives::{UncheckedTransaction, AccountID, Header};
|
||||
use native_runtime::codec::{Joiner, KeyedVec};
|
||||
use native_runtime::runtime::staking::balance;
|
||||
|
||||
@@ -436,7 +436,7 @@ mod tests {
|
||||
], };
|
||||
|
||||
let foreign_code = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.wasm");
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &CallData(vec![].join(&1u64).join(&tx())));
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &CallData(vec![].join(&Header::from_block_number(1u64)).join(&tx())));
|
||||
assert!(r.is_err());
|
||||
}
|
||||
|
||||
@@ -450,7 +450,7 @@ mod tests {
|
||||
], };
|
||||
|
||||
let foreign_code = include_bytes!("../../wasm-runtime/target/wasm32-unknown-unknown/release/runtime_polkadot.compact.wasm");
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &CallData(vec![].join(&1u64).join(&tx())));
|
||||
let r = WasmExecutor.call(&mut t, &foreign_code[..], "execute_transaction", &CallData(vec![].join(&Header::from_block_number(1u64)).join(&tx())));
|
||||
assert!(r.is_ok());
|
||||
|
||||
runtime_std::with_externalities(&mut t, || {
|
||||
|
||||
@@ -38,7 +38,7 @@ pub mod runtime;
|
||||
use runtime_std::prelude::*;
|
||||
use codec::{Slicable, Joiner};
|
||||
use runtime_std::print;
|
||||
use primitives::{Block, Header, BlockNumber, UncheckedTransaction};
|
||||
use primitives::{Block, Header, UncheckedTransaction};
|
||||
|
||||
/// Execute a block, with `input` being the canonical serialisation of the block. Returns the
|
||||
/// empty vector.
|
||||
@@ -49,10 +49,10 @@ pub fn execute_block(input: &[u8]) -> Vec<u8> {
|
||||
|
||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||
pub fn execute_transaction(input: &[u8]) -> Vec<u8> {
|
||||
let number = BlockNumber::from_slice(&input[0..8]).unwrap();
|
||||
let utx = UncheckedTransaction::from_slice(&input[8..]).unwrap();
|
||||
runtime::system::internal::execute_transaction(&utx, Header::from_block_number(number));
|
||||
Vec::new()
|
||||
let header = Header::from_slice(input).unwrap();
|
||||
let utx = UncheckedTransaction::from_slice(&input[Header::size_of(input).unwrap()..]).unwrap();
|
||||
let header = runtime::system::internal::execute_transaction(&utx, header);
|
||||
Vec::new().join(&header)
|
||||
}
|
||||
|
||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
use runtime_std::prelude::*;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[cfg_attr(feature = "with-std", derive(PartialEq, Debug))]
|
||||
#[derive(Clone, Default, PartialEq)]
|
||||
#[cfg_attr(feature = "with-std", derive(Debug))]
|
||||
/// The digest of a block, useful for light-clients.
|
||||
pub struct Digest {
|
||||
/// All logs that have happened in the block.
|
||||
|
||||
@@ -51,11 +51,8 @@ pub mod internal {
|
||||
use super::*;
|
||||
|
||||
/// Deposits a log and ensures it matches the blocks log data.
|
||||
pub fn deposit_log(log: &[u8]) {
|
||||
with_env(|e| {
|
||||
assert_eq!(log, &e.digest.logs[e.next_log_index][..]);
|
||||
e.next_log_index += 1;
|
||||
});
|
||||
pub fn deposit_log(log: Vec<u8>) {
|
||||
with_env(|e| e.digest.logs.push(log));
|
||||
}
|
||||
|
||||
/// Actually execute all transitioning for `block`.
|
||||
@@ -63,8 +60,6 @@ pub mod internal {
|
||||
// populate environment from header.
|
||||
with_env(|e| {
|
||||
e.block_number = block.header.number;
|
||||
mem::swap(&mut e.digest, &mut block.header.digest);
|
||||
e.next_log_index = 0;
|
||||
});
|
||||
|
||||
let ref header = block.header;
|
||||
@@ -104,15 +99,19 @@ pub mod internal {
|
||||
|
||||
/// Execute a transaction outside of the block execution function.
|
||||
/// This doesn't attempt to validate anything regarding the block.
|
||||
pub fn execute_transaction(utx: &UncheckedTransaction, mut header: Header) {
|
||||
pub fn execute_transaction(utx: &UncheckedTransaction, mut header: Header) -> Header {
|
||||
// populate environment from header.
|
||||
with_env(|e| {
|
||||
e.block_number = header.number;
|
||||
mem::swap(&mut e.digest, &mut header.digest);
|
||||
e.next_log_index = 0;
|
||||
mem::swap(&mut header.digest, &mut e.digest);
|
||||
});
|
||||
|
||||
super::execute_transaction(utx);
|
||||
|
||||
with_env(|e| {
|
||||
mem::swap(&mut header.digest, &mut e.digest);
|
||||
});
|
||||
header
|
||||
}
|
||||
|
||||
/// Finalise the block - it is up the caller to ensure that all header fields are valid
|
||||
@@ -122,6 +121,9 @@ pub mod internal {
|
||||
session::internal::check_rotate_session();
|
||||
|
||||
header.state_root = storage_root();
|
||||
with_env(|e| {
|
||||
mem::swap(&mut header.digest, &mut e.digest);
|
||||
});
|
||||
|
||||
post_finalise(&header);
|
||||
|
||||
@@ -160,7 +162,7 @@ fn execute_transaction(utx: &UncheckedTransaction) {
|
||||
|
||||
fn final_checks(_block: &Block) {
|
||||
with_env(|e| {
|
||||
assert_eq!(e.next_log_index, e.digest.logs.len());
|
||||
assert!(_block.header.digest == e.digest);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +30,6 @@ pub struct Environment {
|
||||
pub block_number: BlockNumber,
|
||||
/// The current block digest.
|
||||
pub digest: Digest,
|
||||
/// The number of log items in this block that have been accounted for so far.
|
||||
pub next_log_index: usize,
|
||||
}
|
||||
|
||||
/// Do something with the environment and return its value. Keep the function short.
|
||||
|
||||
BIN
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user