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
6 changes: 6 additions & 0 deletions core/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ impl AccountData for TestBlockChainClient {
fn seq(&self, address: &Address, id: BlockId) -> Option<u64> {
match id {
BlockId::Latest => Some(self.seqs.read().get(address).cloned().unwrap_or(0)),
BlockId::Hash(hash) if hash == *self.last_hash.read() => {
Some(self.seqs.read().get(address).cloned().unwrap_or(0))
}
_ => None,
}
}
Expand All @@ -401,6 +404,9 @@ impl AccountData for TestBlockChainClient {
StateOrBlock::Block(BlockId::Latest) | StateOrBlock::State(_) => {
Some(self.balances.read().get(address).cloned().unwrap_or(0))
}
StateOrBlock::Block(BlockId::Hash(hash)) if hash == *self.last_hash.read() => {
Some(self.balances.read().get(address).cloned().unwrap_or(0))
}
_ => None,
}
}
Expand Down
10 changes: 6 additions & 4 deletions core/src/miner/mem_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use super::mem_pool_types::{
use super::TransactionImportResult;
use crate::client::{AccountData, BlockChainTrait};
use crate::transaction::{PendingSignedTransactions, SignedTransaction};
use crate::Error as CoreError;
use crate::{BlockId, Error as CoreError};

const DEFAULT_POOLING_PERIOD: BlockNumber = 128;

Expand Down Expand Up @@ -429,12 +429,14 @@ impl MemPool {

// Recover MemPool state from db stored data
pub fn recover_from_db<C: AccountData + BlockChainTrait>(&mut self, client: &C) {
let recover_block_hash = client.chain_info().best_block_hash;
let recover_block_id = BlockId::Hash(recover_block_hash);
let fetch_account = |p: &Public| -> AccountDetails {
let address = public_to_address(p);
let a = client.latest_regular_key_owner(&address).unwrap_or(address);
let a = client.regular_key_owner(&address, recover_block_id.into()).unwrap_or(address);
AccountDetails {
seq: client.latest_seq(&a),
balance: client.latest_balance(&a),
seq: client.seq(&a, recover_block_id).expect("Read from best block"),
balance: client.balance(&a, recover_block_id.into()).expect("Read from best block"),
}
};
let by_hash = backup::recover_to_data(self.db.as_ref());
Expand Down
20 changes: 12 additions & 8 deletions core/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ impl Miner {

let fetch_account = |p: &Public| -> AccountDetails {
let address = public_to_address(p);
let a = client.latest_regular_key_owner(&address).unwrap_or(address);
let a = client.regular_key_owner(&address, BlockId::Hash(best_header.hash()).into()).unwrap_or(address);
AccountDetails {
seq: client.latest_seq(&a),
balance: client.latest_balance(&a),
seq: client.seq(&a, BlockId::Hash(best_header.hash())).expect("Read from best block"),
balance: client.balance(&a, BlockId::Hash(best_header.hash()).into()).expect("Read from best block"),
}
};

Expand Down Expand Up @@ -718,10 +718,12 @@ impl Miner {
};
let block = open_block.close(&parent_header, &parent_common_params, term_common_params.as_ref())?;

let best_block_hash = chain.chain_info().best_block_hash;
let block_id = BlockId::Hash(best_block_hash);
let fetch_seq = |p: &Public| {
let address = public_to_address(p);
let a = chain.latest_regular_key_owner(&address).unwrap_or(address);
chain.latest_seq(&a)
let a = chain.regular_key_owner(&address, block_id.into()).unwrap_or(address);
chain.seq(&a, block_id).expect("Read from best block")
};

{
Expand Down Expand Up @@ -903,13 +905,15 @@ impl MinerService for Miner {

// ...and at the end remove the old ones
{
let current_block_hash = chain.chain_info().best_block_hash;
let block_id = BlockId::Hash(current_block_hash);
let fetch_account = |p: &Public| {
let address = public_to_address(p);
let a = chain.latest_regular_key_owner(&address).unwrap_or(address);
let a = chain.regular_key_owner(&address, block_id.into()).unwrap_or(address);

AccountDetails {
seq: chain.latest_seq(&a),
balance: chain.latest_balance(&a),
seq: chain.seq(&a, block_id).expect("Read from best block"),
balance: chain.balance(&a, block_id.into()).expect("Read from best block"),
}
};
let current_block_number = chain.chain_info().best_block_number;
Expand Down