Merge pull request #3873 from ethcore/fix-collision
Fix naming collision
This commit is contained in:
commit
d9b9172089
@ -100,6 +100,7 @@ impl AsMillis for Duration {
|
|||||||
impl AuthorityRound {
|
impl AuthorityRound {
|
||||||
/// Create a new instance of AuthorityRound engine.
|
/// Create a new instance of AuthorityRound engine.
|
||||||
pub fn new(params: CommonParams, our_params: AuthorityRoundParams, builtins: BTreeMap<Address, Builtin>) -> Result<Arc<Self>, Error> {
|
pub fn new(params: CommonParams, our_params: AuthorityRoundParams, builtins: BTreeMap<Address, Builtin>) -> Result<Arc<Self>, Error> {
|
||||||
|
let should_timeout = our_params.start_step.is_none();
|
||||||
let initial_step = our_params.start_step.unwrap_or_else(|| (unix_now().as_secs() / our_params.step_duration.as_secs())) as usize;
|
let initial_step = our_params.start_step.unwrap_or_else(|| (unix_now().as_secs() / our_params.step_duration.as_secs())) as usize;
|
||||||
let engine = Arc::new(
|
let engine = Arc::new(
|
||||||
AuthorityRound {
|
AuthorityRound {
|
||||||
@ -113,18 +114,17 @@ impl AuthorityRound {
|
|||||||
account_provider: Mutex::new(None),
|
account_provider: Mutex::new(None),
|
||||||
password: RwLock::new(None),
|
password: RwLock::new(None),
|
||||||
});
|
});
|
||||||
let handler = TransitionHandler { engine: Arc::downgrade(&engine) };
|
// Do not initialize timeouts for tests.
|
||||||
try!(engine.transition_service.register_handler(Arc::new(handler)));
|
if should_timeout {
|
||||||
|
let handler = TransitionHandler { engine: Arc::downgrade(&engine) };
|
||||||
|
try!(engine.transition_service.register_handler(Arc::new(handler)));
|
||||||
|
}
|
||||||
Ok(engine)
|
Ok(engine)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn step(&self) -> usize {
|
|
||||||
self.step.load(AtomicOrdering::SeqCst)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn remaining_step_duration(&self) -> Duration {
|
fn remaining_step_duration(&self) -> Duration {
|
||||||
let now = unix_now();
|
let now = unix_now();
|
||||||
let step_end = self.our_params.step_duration * (self.step() as u32 + 1);
|
let step_end = self.our_params.step_duration * (self.step.load(AtomicOrdering::SeqCst) as u32 + 1);
|
||||||
if step_end > now {
|
if step_end > now {
|
||||||
step_end - now
|
step_end - now
|
||||||
} else {
|
} else {
|
||||||
@ -228,7 +228,7 @@ impl Engine for AuthorityRound {
|
|||||||
fn generate_seal(&self, block: &ExecutedBlock) -> Seal {
|
fn generate_seal(&self, block: &ExecutedBlock) -> Seal {
|
||||||
if self.proposed.load(AtomicOrdering::SeqCst) { return Seal::None; }
|
if self.proposed.load(AtomicOrdering::SeqCst) { return Seal::None; }
|
||||||
let header = block.header();
|
let header = block.header();
|
||||||
let step = self.step();
|
let step = self.step.load(AtomicOrdering::SeqCst);
|
||||||
if self.is_step_proposer(step, header.author()) {
|
if self.is_step_proposer(step, header.author()) {
|
||||||
if let Some(ref ap) = *self.account_provider.lock() {
|
if let Some(ref ap) = *self.account_provider.lock() {
|
||||||
// Account should be permanently unlocked, otherwise sealing will fail.
|
// Account should be permanently unlocked, otherwise sealing will fail.
|
||||||
@ -265,7 +265,7 @@ impl Engine for AuthorityRound {
|
|||||||
fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
fn verify_block_unordered(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||||
let header_step = try!(header_step(header));
|
let header_step = try!(header_step(header));
|
||||||
// Give one step slack if step is lagging, double vote is still not possible.
|
// Give one step slack if step is lagging, double vote is still not possible.
|
||||||
if header_step <= self.step() + 1 {
|
if header_step <= self.step.load(AtomicOrdering::SeqCst) + 1 {
|
||||||
let proposer_signature = try!(header_signature(header));
|
let proposer_signature = try!(header_signature(header));
|
||||||
let ok_sig = try!(verify_address(self.step_proposer(header_step), &proposer_signature, &header.bare_hash()));
|
let ok_sig = try!(verify_address(self.step_proposer(header_step), &proposer_signature, &header.bare_hash()));
|
||||||
if ok_sig {
|
if ok_sig {
|
||||||
|
@ -82,12 +82,14 @@ fn authority_round() {
|
|||||||
net.sync();
|
net.sync();
|
||||||
// Trigger block proposal
|
// Trigger block proposal
|
||||||
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 0.into())).unwrap();
|
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 0.into())).unwrap();
|
||||||
|
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 0.into())).unwrap();
|
||||||
// Sync a block
|
// Sync a block
|
||||||
net.sync();
|
net.sync();
|
||||||
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 1);
|
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 1);
|
||||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 1);
|
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 1);
|
||||||
|
|
||||||
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 0.into())).unwrap();
|
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 1.into())).unwrap();
|
||||||
|
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 1.into())).unwrap();
|
||||||
// Move to next proposer step
|
// Move to next proposer step
|
||||||
net.peer(0).chain.engine().step();
|
net.peer(0).chain.engine().step();
|
||||||
net.peer(1).chain.engine().step();
|
net.peer(1).chain.engine().step();
|
||||||
@ -96,14 +98,17 @@ fn authority_round() {
|
|||||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 2);
|
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 2);
|
||||||
|
|
||||||
// Fork the network
|
// Fork the network
|
||||||
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 1.into())).unwrap();
|
net.peer(0).chain.miner().import_own_transaction(&*net.peer(0).chain, new_tx(s0.secret(), 2.into())).unwrap();
|
||||||
|
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 2.into())).unwrap();
|
||||||
net.peer(0).chain.engine().step();
|
net.peer(0).chain.engine().step();
|
||||||
net.peer(1).chain.engine().step();
|
net.peer(1).chain.engine().step();
|
||||||
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 3);
|
|
||||||
net.peer(1).chain.miner().import_own_transaction(&*net.peer(1).chain, new_tx(s1.secret(), 1.into())).unwrap();
|
|
||||||
net.peer(0).chain.engine().step();
|
net.peer(0).chain.engine().step();
|
||||||
net.peer(1).chain.engine().step();
|
net.peer(1).chain.engine().step();
|
||||||
assert_eq!(net.peer(1).chain.chain_info().best_block_number, 3);
|
let ci0 = net.peer(0).chain.chain_info();
|
||||||
|
let ci1 = net.peer(1).chain.chain_info();
|
||||||
|
assert_eq!(ci0.best_block_number, 3);
|
||||||
|
assert_eq!(ci1.best_block_number, 3);
|
||||||
|
assert!(ci0.best_block_hash != ci1.best_block_hash);
|
||||||
// Reorg to the correct one.
|
// Reorg to the correct one.
|
||||||
net.sync();
|
net.sync();
|
||||||
let ci0 = net.peer(0).chain.chain_info();
|
let ci0 = net.peer(0).chain.chain_info();
|
||||||
|
Loading…
Reference in New Issue
Block a user