SecretStore: do not update servers set until fully synchronized
This commit is contained in:
parent
009e350fc7
commit
37973f9112
@ -21,6 +21,7 @@ use futures::{future, Future};
|
|||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use ethcore::filter::Filter;
|
use ethcore::filter::Filter;
|
||||||
use ethcore::client::{Client, BlockChainClient, BlockId, ChainNotify};
|
use ethcore::client::{Client, BlockChainClient, BlockId, ChainNotify};
|
||||||
|
use ethsync::SyncProvider;
|
||||||
use native_contracts::KeyServerSet as KeyServerSetContract;
|
use native_contracts::KeyServerSet as KeyServerSetContract;
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
use bigint::hash::H256;
|
use bigint::hash::H256;
|
||||||
@ -56,6 +57,8 @@ pub struct OnChainKeyServerSet {
|
|||||||
struct CachedContract {
|
struct CachedContract {
|
||||||
/// Blockchain client.
|
/// Blockchain client.
|
||||||
client: Weak<Client>,
|
client: Weak<Client>,
|
||||||
|
/// Sync provider.
|
||||||
|
sync: Weak<SyncProvider>,
|
||||||
/// Contract address.
|
/// Contract address.
|
||||||
contract_addr: Option<Address>,
|
contract_addr: Option<Address>,
|
||||||
/// Active set of key servers.
|
/// Active set of key servers.
|
||||||
@ -63,8 +66,8 @@ struct CachedContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl OnChainKeyServerSet {
|
impl OnChainKeyServerSet {
|
||||||
pub fn new(client: &Arc<Client>, key_servers: BTreeMap<Public, NodeAddress>) -> Result<Arc<Self>, Error> {
|
pub fn new(client: &Arc<Client>, sync: &Arc<SyncProvider>, key_servers: BTreeMap<Public, NodeAddress>) -> Result<Arc<Self>, Error> {
|
||||||
let mut cached_contract = CachedContract::new(client, key_servers)?;
|
let mut cached_contract = CachedContract::new(client, sync, key_servers)?;
|
||||||
let key_server_contract_address = client.registry_address(KEY_SERVER_SET_CONTRACT_REGISTRY_NAME.to_owned());
|
let key_server_contract_address = client.registry_address(KEY_SERVER_SET_CONTRACT_REGISTRY_NAME.to_owned());
|
||||||
// only initialize from contract if it is installed. otherwise - use default nodes
|
// only initialize from contract if it is installed. otherwise - use default nodes
|
||||||
// once the contract is installed, all default nodes are lost (if not in the contract' set)
|
// once the contract is installed, all default nodes are lost (if not in the contract' set)
|
||||||
@ -95,9 +98,10 @@ impl ChainNotify for OnChainKeyServerSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CachedContract {
|
impl CachedContract {
|
||||||
pub fn new(client: &Arc<Client>, key_servers: BTreeMap<Public, NodeAddress>) -> Result<Self, Error> {
|
pub fn new(client: &Arc<Client>, sync: &Arc<SyncProvider>, key_servers: BTreeMap<Public, NodeAddress>) -> Result<Self, Error> {
|
||||||
Ok(CachedContract {
|
Ok(CachedContract {
|
||||||
client: Arc::downgrade(client),
|
client: Arc::downgrade(client),
|
||||||
|
sync: Arc::downgrade(sync),
|
||||||
contract_addr: None,
|
contract_addr: None,
|
||||||
key_servers: key_servers.into_iter()
|
key_servers: key_servers.into_iter()
|
||||||
.map(|(p, addr)| {
|
.map(|(p, addr)| {
|
||||||
@ -110,7 +114,12 @@ impl CachedContract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&mut self, enacted: Vec<H256>, retracted: Vec<H256>) {
|
pub fn update(&mut self, enacted: Vec<H256>, retracted: Vec<H256>) {
|
||||||
if let Some(client) = self.client.upgrade() {
|
if let (Some(client), Some(sync)) = (self.client.upgrade(), self.sync.upgrade()) {
|
||||||
|
// do not update initial server set until fully synchronized
|
||||||
|
if sync.status().is_syncing(client.queue_info()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let new_contract_addr = client.registry_address(KEY_SERVER_SET_CONTRACT_REGISTRY_NAME.to_owned());
|
let new_contract_addr = client.registry_address(KEY_SERVER_SET_CONTRACT_REGISTRY_NAME.to_owned());
|
||||||
|
|
||||||
// new contract installed => read nodes set from the contract
|
// new contract installed => read nodes set from the contract
|
||||||
|
@ -77,7 +77,7 @@ pub fn start(client: Arc<Client>, sync: Arc<SyncProvider>, self_key_pair: Arc<No
|
|||||||
} else {
|
} else {
|
||||||
Arc::new(acl_storage::DummyAclStorage::default())
|
Arc::new(acl_storage::DummyAclStorage::default())
|
||||||
};
|
};
|
||||||
let key_server_set = key_server_set::OnChainKeyServerSet::new(&client, /*&sync, */config.cluster_config.nodes.clone())?; // TODO: return empty set until fully synced
|
let key_server_set = key_server_set::OnChainKeyServerSet::new(&client, &sync, config.cluster_config.nodes.clone())?; // TODO: return empty set until fully synced
|
||||||
let key_storage = Arc::new(key_storage::PersistentKeyStorage::new(&config)?);
|
let key_storage = Arc::new(key_storage::PersistentKeyStorage::new(&config)?);
|
||||||
let key_server = Arc::new(key_server::KeyServerImpl::new(&config.cluster_config, key_server_set.clone(), self_key_pair.clone(), acl_storage, key_storage.clone())?);
|
let key_server = Arc::new(key_server::KeyServerImpl::new(&config.cluster_config, key_server_set.clone(), self_key_pair.clone(), acl_storage, key_storage.clone())?);
|
||||||
let cluster = key_server.cluster();
|
let cluster = key_server.cluster();
|
||||||
|
Loading…
Reference in New Issue
Block a user