mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-19 20:25:40 +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 transaction_root = ordered_trie_root(transactions.iter().map(Slicable::to_vec)).0;
|
||||||
|
|
||||||
let header = Header {
|
let mut header = Header {
|
||||||
parent_hash,
|
parent_hash,
|
||||||
number,
|
number,
|
||||||
state_root,
|
state_root,
|
||||||
@@ -83,16 +83,16 @@ mod tests {
|
|||||||
let mut overlay = OverlayedChanges::default();
|
let mut overlay = OverlayedChanges::default();
|
||||||
|
|
||||||
for tx in transactions.iter() {
|
for tx in transactions.iter() {
|
||||||
let _ = execute(
|
header = Header::from_slice(&execute(
|
||||||
backend,
|
backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&executor(),
|
||||||
"execute_transaction",
|
"execute_transaction",
|
||||||
&CallData(vec![].join(&number).join(tx))
|
&CallData(vec![].join(&header).join(tx))
|
||||||
).unwrap();
|
).unwrap()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let header = Header::from_slice(&execute(
|
header = Header::from_slice(&execute(
|
||||||
backend,
|
backend,
|
||||||
&mut overlay,
|
&mut overlay,
|
||||||
&executor(),
|
&executor(),
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use runtime_std::TestExternalities;
|
use runtime_std::TestExternalities;
|
||||||
use native_runtime::codec::{KeyedVec, Joiner, Slicable};
|
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::primitives::*;
|
||||||
use native_runtime::runtime::staking::balance;
|
use native_runtime::runtime::staking::balance;
|
||||||
use primitives::twox_128;
|
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]
|
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());
|
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]
|
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());
|
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]
|
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());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
runtime_std::with_externalities(&mut t, || {
|
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]
|
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());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
runtime_std::with_externalities(&mut t, || {
|
runtime_std::with_externalities(&mut t, || {
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ mod tests {
|
|||||||
use primitives::{blake2_256, twox_128};
|
use primitives::{blake2_256, twox_128};
|
||||||
use runtime_std::{self, TestExternalities};
|
use runtime_std::{self, TestExternalities};
|
||||||
use native_runtime::support::{one, two};
|
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::codec::{Joiner, KeyedVec};
|
||||||
use native_runtime::runtime::staking::balance;
|
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 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());
|
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 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());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
runtime_std::with_externalities(&mut t, || {
|
runtime_std::with_externalities(&mut t, || {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub mod runtime;
|
|||||||
use runtime_std::prelude::*;
|
use runtime_std::prelude::*;
|
||||||
use codec::{Slicable, Joiner};
|
use codec::{Slicable, Joiner};
|
||||||
use runtime_std::print;
|
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
|
/// Execute a block, with `input` being the canonical serialisation of the block. Returns the
|
||||||
/// empty vector.
|
/// empty vector.
|
||||||
@@ -49,10 +49,10 @@ pub fn execute_block(input: &[u8]) -> Vec<u8> {
|
|||||||
|
|
||||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||||
pub fn execute_transaction(input: &[u8]) -> Vec<u8> {
|
pub fn execute_transaction(input: &[u8]) -> Vec<u8> {
|
||||||
let number = BlockNumber::from_slice(&input[0..8]).unwrap();
|
let header = Header::from_slice(input).unwrap();
|
||||||
let utx = UncheckedTransaction::from_slice(&input[8..]).unwrap();
|
let utx = UncheckedTransaction::from_slice(&input[Header::size_of(input).unwrap()..]).unwrap();
|
||||||
runtime::system::internal::execute_transaction(&utx, Header::from_block_number(number));
|
let header = runtime::system::internal::execute_transaction(&utx, header);
|
||||||
Vec::new()
|
Vec::new().join(&header)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a given, serialised, transaction. Returns the empty vector.
|
/// Execute a given, serialised, transaction. Returns the empty vector.
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
|
|
||||||
use runtime_std::prelude::*;
|
use runtime_std::prelude::*;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default, PartialEq)]
|
||||||
#[cfg_attr(feature = "with-std", derive(PartialEq, Debug))]
|
#[cfg_attr(feature = "with-std", derive(Debug))]
|
||||||
/// The digest of a block, useful for light-clients.
|
/// The digest of a block, useful for light-clients.
|
||||||
pub struct Digest {
|
pub struct Digest {
|
||||||
/// All logs that have happened in the block.
|
/// All logs that have happened in the block.
|
||||||
|
|||||||
@@ -51,11 +51,8 @@ pub mod internal {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// Deposits a log and ensures it matches the blocks log data.
|
/// Deposits a log and ensures it matches the blocks log data.
|
||||||
pub fn deposit_log(log: &[u8]) {
|
pub fn deposit_log(log: Vec<u8>) {
|
||||||
with_env(|e| {
|
with_env(|e| e.digest.logs.push(log));
|
||||||
assert_eq!(log, &e.digest.logs[e.next_log_index][..]);
|
|
||||||
e.next_log_index += 1;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Actually execute all transitioning for `block`.
|
/// Actually execute all transitioning for `block`.
|
||||||
@@ -63,8 +60,6 @@ pub mod internal {
|
|||||||
// populate environment from header.
|
// populate environment from header.
|
||||||
with_env(|e| {
|
with_env(|e| {
|
||||||
e.block_number = block.header.number;
|
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;
|
let ref header = block.header;
|
||||||
@@ -104,15 +99,19 @@ pub mod internal {
|
|||||||
|
|
||||||
/// Execute a transaction outside of the block execution function.
|
/// Execute a transaction outside of the block execution function.
|
||||||
/// This doesn't attempt to validate anything regarding the block.
|
/// 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.
|
// populate environment from header.
|
||||||
with_env(|e| {
|
with_env(|e| {
|
||||||
e.block_number = header.number;
|
e.block_number = header.number;
|
||||||
mem::swap(&mut e.digest, &mut header.digest);
|
mem::swap(&mut header.digest, &mut e.digest);
|
||||||
e.next_log_index = 0;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
super::execute_transaction(utx);
|
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
|
/// 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();
|
session::internal::check_rotate_session();
|
||||||
|
|
||||||
header.state_root = storage_root();
|
header.state_root = storage_root();
|
||||||
|
with_env(|e| {
|
||||||
|
mem::swap(&mut header.digest, &mut e.digest);
|
||||||
|
});
|
||||||
|
|
||||||
post_finalise(&header);
|
post_finalise(&header);
|
||||||
|
|
||||||
@@ -160,7 +162,7 @@ fn execute_transaction(utx: &UncheckedTransaction) {
|
|||||||
|
|
||||||
fn final_checks(_block: &Block) {
|
fn final_checks(_block: &Block) {
|
||||||
with_env(|e| {
|
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,
|
pub block_number: BlockNumber,
|
||||||
/// The current block digest.
|
/// The current block digest.
|
||||||
pub digest: 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.
|
/// 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