Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ pub struct ExecutedBlock {
}

impl ExecutedBlock {
fn new(state: TopLevelState) -> ExecutedBlock {
fn new(state: TopLevelState, parent: &Header) -> ExecutedBlock {
ExecutedBlock {
header: Default::default(),
header: parent.generate_child(),
state,
transactions: Default::default(),
invoices: Default::default(),
Expand Down Expand Up @@ -132,17 +132,13 @@ impl<'x> OpenBlock<'x> {
author: Address,
extra_data: Bytes,
) -> Result<Self, Error> {
let number = parent.number() + 1;
let state = TopLevelState::from_existing(db, *parent.state_root()).map_err(StateError::from)?;
let mut r = OpenBlock {
block: ExecutedBlock::new(state),
block: ExecutedBlock::new(state, parent),
engine,
};

r.block.header.set_parent_hash(parent.hash());
r.block.header.set_number(number);
r.block.header.set_author(author);
r.block.header.set_timestamp_now(parent.timestamp());
r.block.header.set_extra_data(extra_data);
r.block.header.note_dirty();

Expand Down
11 changes: 11 additions & 0 deletions core/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,17 @@ impl Header {
pub fn rlp_blake(&self, with_seal: &Seal) -> H256 {
blake256(&self.rlp(with_seal))
}

pub fn generate_child(&self) -> Self {
let mut header = Header::default();

header.set_parent_hash(self.hash());
header.set_number(self.number() + 1);
header.set_timestamp_now(self.timestamp());
header.note_dirty();

header
}
}

impl Decodable for Header {
Expand Down
8 changes: 4 additions & 4 deletions core/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl Miner {
default_origin: TxOrigin,
mem_pool: &mut MemPool,
) -> Vec<Result<TransactionImportResult, Error>> {
let best_block_header = client.best_block_header().decode();
let fake_header = client.best_block_header().decode().generate_child();
let current_block_number = client.chain_info().best_block_number;
let current_timestamp = client.chain_info().best_block_timestamp;
let mut inserted = Vec::with_capacity(transactions.len());
Expand All @@ -274,16 +274,16 @@ impl Miner {
}
match self
.engine
.verify_transaction_basic(&tx, &best_block_header)
.and_then(|_| self.engine.verify_transaction_unordered(tx, &best_block_header))
.verify_transaction_basic(&tx, &fake_header)
.and_then(|_| self.engine.verify_transaction_unordered(tx, &fake_header))
{
Err(e) => {
cdebug!(MINER, "Rejected transaction {:?} with invalid signature: {:?}", hash, e);
Err(e)
}
Ok(tx) => {
// This check goes here because verify_transaction takes SignedTransaction parameter
self.engine.machine().verify_transaction(&tx, &best_block_header, client, false)?;
self.engine.machine().verify_transaction(&tx, &fake_header, client, false)?;

let origin = self
.accounts
Expand Down
4 changes: 2 additions & 2 deletions test/src/e2e.long/expiration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("TransferAsset expiration test", function() {

// 3. Send TransferAsset transactions (which should not processed)
const seq = await node.sdk.rpc.chain.getSeq(faucetAddress);
startTime = Math.round(new Date().getTime() / 1000);
startTime = Math.round(new Date().getTime() / 1000) + 5;
for (let i = 0; i < numTx; i++) {
const recipient = await node.createP2PKHAddress();
const tx = node.sdk.core.createTransferAssetTransaction({
Expand Down Expand Up @@ -95,7 +95,7 @@ describe("TransferAsset expiration test", function() {
const isExpired = bestBlockTimestamp > startTime + numTx - i;
expect(isResultsEmpty).to.be.equal(isExpired);
}
}).timeout(10_000);
}).timeout(15_000);
});

afterEach(async function() {
Expand Down