Offchain worker: Enable http2 and improve logging (#10305)

* Offchain worker: Enable http2 and improve logging

Apparently some webpages now return http2 by default and that silently breaks the offchain http
extension. The solution to this is to enable the `http2` feature of hyper. Besides that, this pr
improves the logging to make it easier to debug such errors.

* FMT

* Adds http2 test
This commit is contained in:
Bastian Köcher
2021-11-19 12:33:28 +01:00
committed by GitHub
parent 34bc24624a
commit 090b55b791
5 changed files with 172 additions and 55 deletions
+28 -22
View File
@@ -37,10 +37,11 @@ mod http;
mod timestamp;
fn unavailable_yet<R: Default>(name: &str) -> R {
log::error!(
target: "sc_offchain",
tracing::error!(
target: super::LOG_TARGET,
"The {:?} API is not available for offchain workers yet. Follow \
https://github.com/paritytech/substrate/issues/1458 for details", name
https://github.com/paritytech/substrate/issues/1458 for details",
name
);
Default::default()
}
@@ -75,9 +76,12 @@ impl<Storage: OffchainStorage> Db<Storage> {
impl<Storage: OffchainStorage> offchain::DbExternalities for Db<Storage> {
fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8]) {
log::debug!(
target: "sc_offchain",
"{:?}: Write: {:?} <= {:?}", kind, hex::encode(key), hex::encode(value)
tracing::debug!(
target: "offchain-worker::storage",
?kind,
key = ?hex::encode(key),
value = ?hex::encode(value),
"Write",
);
match kind {
StorageKind::PERSISTENT => self.persistent.set(STORAGE_PREFIX, key, value),
@@ -86,9 +90,11 @@ impl<Storage: OffchainStorage> offchain::DbExternalities for Db<Storage> {
}
fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8]) {
log::debug!(
target: "sc_offchain",
"{:?}: Clear: {:?}", kind, hex::encode(key)
tracing::debug!(
target: "offchain-worker::storage",
?kind,
key = ?hex::encode(key),
"Clear",
);
match kind {
StorageKind::PERSISTENT => self.persistent.remove(STORAGE_PREFIX, key),
@@ -103,13 +109,13 @@ impl<Storage: OffchainStorage> offchain::DbExternalities for Db<Storage> {
old_value: Option<&[u8]>,
new_value: &[u8],
) -> bool {
log::debug!(
target: "sc_offchain",
"{:?}: CAS: {:?} <= {:?} vs {:?}",
kind,
hex::encode(key),
hex::encode(new_value),
old_value.as_ref().map(hex::encode),
tracing::debug!(
target: "offchain-worker::storage",
?kind,
key = ?hex::encode(key),
new_value = ?hex::encode(new_value),
old_value = ?old_value.as_ref().map(hex::encode),
"CAS",
);
match kind {
StorageKind::PERSISTENT =>
@@ -123,12 +129,12 @@ impl<Storage: OffchainStorage> offchain::DbExternalities for Db<Storage> {
StorageKind::PERSISTENT => self.persistent.get(STORAGE_PREFIX, key),
StorageKind::LOCAL => unavailable_yet(LOCAL_DB),
};
log::debug!(
target: "sc_offchain",
"{:?}: Read: {:?} => {:?}",
kind,
hex::encode(key),
result.as_ref().map(hex::encode)
tracing::debug!(
target: "offchain-worker::storage",
?kind,
key = ?hex::encode(key),
result = ?result.as_ref().map(hex::encode),
"Read",
);
result
}