Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 71f57ea

Browse files
committed
Merge branch 'master' into td-signed-unsigned
2 parents 251a968 + 79809a6 commit 71f57ea

File tree

24 files changed

+233
-253
lines changed

24 files changed

+233
-253
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/node/cli/src/factory_impl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl<Number> FactoryState<Number> {
5959
frame_system::ValidateUnsigned::new(),
6060
pallet_transaction_payment::ChargeTransactionPayment::from(0),
6161
Default::default(),
62-
Default::default(),
6362
)
6463
}
6564
}
@@ -124,7 +123,7 @@ impl RuntimeAdapter for FactoryState<Number> {
124123
(*amount).into()
125124
)
126125
)
127-
}, key, (version, genesis_hash.clone(), prior_block_hash.clone(), (), (), (), (), (), ()))
126+
}, key, (version, genesis_hash.clone(), prior_block_hash.clone(), (), (), (), (), ()))
128127
}
129128

130129
fn inherent_extrinsics(&self) -> InherentData {

bin/node/cli/src/service.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,12 +619,11 @@ mod tests {
619619
check_unsigned,
620620
payment,
621621
Default::default(),
622-
Default::default(),
623622
);
624623
let raw_payload = SignedPayload::from_raw(
625624
function,
626625
extra,
627-
(version, genesis_hash, genesis_hash, (), (), (), (), (), ())
626+
(version, genesis_hash, genesis_hash, (), (), (), (), ())
628627
);
629628
let signature = raw_payload.using_encoded(|payload| {
630629
signer.sign(payload)

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub use pallet_timestamp::Call as TimestampCall;
5959
pub use pallet_balances::Call as BalancesCall;
6060
pub use pallet_contracts::Gas;
6161
pub use frame_support::StorageValue;
62-
pub use pallet_staking::{StakerStatus, LockStakingStatus};
62+
pub use pallet_staking::StakerStatus;
6363

6464
/// Implementations of some helper traits passed into runtime modules as associated types.
6565
pub mod impls;
@@ -108,7 +108,6 @@ impl frame_system::offchain::CreateTransaction<Runtime, UncheckedExtrinsic> for
108108
frame_system::ValidateUnsigned::<Runtime>::new(),
109109
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(tip),
110110
Default::default(),
111-
Default::default(),
112111
);
113112
let raw_payload = SignedPayload::new(call, extra).map_err(|e| {
114113
debug::warn!("Unable to create signed payload: {:?}", e);
@@ -713,7 +712,6 @@ pub type SignedExtra = (
713712
frame_system::ValidateUnsigned<Runtime>,
714713
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
715714
pallet_contracts::CheckBlockGasLimit<Runtime>,
716-
pallet_staking::LockStakingStatus<Runtime>,
717715
);
718716
/// Unchecked extrinsic type as expected by this runtime.
719717
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;

bin/node/testing/src/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl BenchDb {
186186
pruning: PruningMode::ArchiveAll,
187187
source: sc_client_db::DatabaseSettingsSrc::Path {
188188
path: dir.into(),
189-
cache_size: 128,
189+
cache_size: 512,
190190
},
191191
};
192192

bin/node/testing/src/keyring.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ pub fn signed_extra(nonce: Index, extra_fee: Balance) -> SignedExtra {
7676
frame_system::ValidateUnsigned::new(),
7777
pallet_transaction_payment::ChargeTransactionPayment::from(extra_fee),
7878
Default::default(),
79-
Default::default(),
8079
)
8180
}
8281

bin/utils/subkey/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ fn create_extrinsic<C: Crypto>(
691691
frame_system::ValidateUnsigned::<Runtime>::new(),
692692
pallet_transaction_payment::ChargeTransactionPayment::<Runtime>::from(f),
693693
Default::default(),
694-
Default::default(),
695694
)
696695
};
697696
let raw_payload = SignedPayload::from_raw(
@@ -706,7 +705,6 @@ fn create_extrinsic<C: Crypto>(
706705
(),
707706
(),
708707
(),
709-
(),
710708
),
711709
);
712710
let signature = raw_payload.using_encoded(|payload| signer.sign(payload)).into_runtime();

client/authority-discovery/src/error.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,20 @@ pub enum Error {
4040
MatchingHashedAuthorityIdWithAuthorityId,
4141
/// Failed to set the authority discovery peerset priority group in the peerset module.
4242
SettingPeersetPriorityGroup(String),
43+
/// The sender side of the dht event stream has been closed likely due to the network
44+
/// terminating.
45+
DhtEventStreamTerminated,
4346
/// Failed to encode a protobuf payload.
4447
EncodingProto(prost::EncodeError),
4548
/// Failed to decode a protobuf payload.
4649
DecodingProto(prost::DecodeError),
47-
/// Failed to encode or decode scale payload
50+
/// Failed to encode or decode scale payload.
4851
EncodingDecodingScale(codec::Error),
4952
/// Failed to parse a libp2p multi address.
5053
ParsingMultiaddress(libp2p::core::multiaddr::Error),
51-
/// Failed to sign using a specific public key
54+
/// Failed to sign using a specific public key.
5255
MissingSignature(CryptoTypePublicPair),
53-
/// Failed to sign using all public keys
56+
/// Failed to sign using all public keys.
5457
Signing,
5558
/// Failed to register Prometheus metric.
5659
Prometheus(prometheus_endpoint::PrometheusError),

client/authority-discovery/src/lib.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ where
330330
}
331331

332332
fn handle_dht_events(&mut self, cx: &mut Context) -> Result<()> {
333-
while let Poll::Ready(Some(event)) = self.dht_event_rx.poll_next_unpin(cx) {
334-
match event {
335-
DhtEvent::ValueFound(v) => {
333+
loop {
334+
match self.dht_event_rx.poll_next_unpin(cx) {
335+
Poll::Ready(Some(DhtEvent::ValueFound(v))) => {
336336
if let Some(metrics) = &self.metrics {
337337
metrics.dht_event_received.with_label_values(&["value_found"]).inc();
338338
}
@@ -347,7 +347,7 @@ where
347347

348348
self.handle_dht_value_found_event(v)?;
349349
}
350-
DhtEvent::ValueNotFound(hash) => {
350+
Poll::Ready(Some(DhtEvent::ValueNotFound(hash))) => {
351351
if let Some(metrics) = &self.metrics {
352352
metrics.dht_event_received.with_label_values(&["value_not_found"]).inc();
353353
}
@@ -357,7 +357,7 @@ where
357357
"Value for hash '{:?}' not found on Dht.", hash
358358
)
359359
},
360-
DhtEvent::ValuePut(hash) => {
360+
Poll::Ready(Some(DhtEvent::ValuePut(hash))) => {
361361
if let Some(metrics) = &self.metrics {
362362
metrics.dht_event_received.with_label_values(&["value_put"]).inc();
363363
}
@@ -367,7 +367,7 @@ where
367367
"Successfully put hash '{:?}' on Dht.", hash,
368368
)
369369
},
370-
DhtEvent::ValuePutFailed(hash) => {
370+
Poll::Ready(Some(DhtEvent::ValuePutFailed(hash))) => {
371371
if let Some(metrics) = &self.metrics {
372372
metrics.dht_event_received.with_label_values(&["value_put_failed"]).inc();
373373
}
@@ -377,10 +377,12 @@ where
377377
"Failed to put hash '{:?}' on Dht.", hash
378378
)
379379
},
380+
// The sender side of the dht event stream has been closed, likely due to the
381+
// network terminating.
382+
Poll::Ready(None) => return Err(Error::DhtEventStreamTerminated),
383+
Poll::Pending => return Ok(()),
380384
}
381385
}
382-
383-
Ok(())
384386
}
385387

386388
fn handle_dht_value_found_event(
@@ -483,7 +485,6 @@ where
483485
}
484486

485487
/// Update the peer set 'authority' priority group.
486-
//
487488
fn update_peer_set_priority_group(&self) -> Result<()> {
488489
let addresses = self.addr_cache.get_subset();
489490

@@ -539,11 +540,18 @@ where
539540

540541
match inner() {
541542
Ok(()) => {}
543+
544+
// Handle fatal errors.
545+
//
546+
// Given that the network likely terminated authority discovery should do the same.
547+
Err(Error::DhtEventStreamTerminated) => return Poll::Ready(()),
548+
549+
// Handle non-fatal errors.
542550
Err(e) => error!(target: "sub-authority-discovery", "Poll failure: {:?}", e),
543551
};
544552

545-
// Make sure to always return NotReady as this is a long running task with the same lifetime
546-
// as the node itself.
553+
// Return Poll::Pending as this is a long running task with the same lifetime as the node
554+
// itself.
547555
Poll::Pending
548556
}
549557
}

client/authority-discovery/src/tests.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::{iter::FromIterator, sync::{Arc, Mutex}};
1919
use futures::channel::mpsc::channel;
2020
use futures::executor::block_on;
2121
use futures::future::poll_fn;
22+
use futures::poll;
2223
use libp2p::{kad, PeerId};
2324

2425
use sp_api::{ProvideRuntimeApi, ApiRef};
@@ -346,3 +347,36 @@ fn handle_dht_events_with_value_found_should_call_set_priority_group() {
346347

347348
let _ = block_on(poll_fn(f));
348349
}
350+
351+
#[test]
352+
fn terminate_when_event_stream_terminates() {
353+
let (dht_event_tx, dht_event_rx) = channel(1000);
354+
let network: Arc<TestNetwork> = Arc::new(Default::default());
355+
let key_store = KeyStore::new();
356+
let test_api = Arc::new(TestApi {
357+
authorities: vec![],
358+
});
359+
360+
let mut authority_discovery = AuthorityDiscovery::new(
361+
test_api,
362+
network.clone(),
363+
vec![],
364+
key_store,
365+
dht_event_rx.boxed(),
366+
None,
367+
);
368+
369+
block_on(async {
370+
assert_eq!(Poll::Pending, poll!(&mut authority_discovery));
371+
372+
// Simulate termination of the network through dropping the sender side of the dht event
373+
// channel.
374+
drop(dht_event_tx);
375+
376+
assert_eq!(
377+
Poll::Ready(()), poll!(&mut authority_discovery),
378+
"Expect the authority discovery module to terminate once the sending side of the dht \
379+
event channel is terminated.",
380+
);
381+
});
382+
}

0 commit comments

Comments
 (0)