Skip to content

Commit e22d445

Browse files
committed
use a patched codec
contains more verbose information about decoding errors
1 parent 2e7687a commit e22d445

File tree

6 files changed

+92
-90
lines changed

6 files changed

+92
-90
lines changed

Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jsonrpc-client-transports = { git = "https://github.com/paritytech/jsonrpc", bra
7070
jsonrpc-core = { git = "https://github.com/paritytech/jsonrpc", branch = "master", features = ["arbitrary_precision"] }
7171
jsonrpc-derive = { git = "https://github.com/paritytech/jsonrpc", branch = "master" }
7272
jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc", branch = "master" }
73+
codec = { git = "https://github.com/insipx/parity-scale-codec", branch = "insipx/debugging", package = "parity-scale-codec" }
7374

7475
[dev-dependencies]
7576
node-runtime = { git = "https://github.com/paritytech/substrate", package="node-runtime", branch="polkadot-master" }

polkadot-archive/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ impl ExtractCall for CallWrapper {
143143
Call::Registrar(call) => {
144144
(Module::Custom("Registrar".into()), Box::new(RegistrarCallWrapper(call.clone())))
145145
},
146-
//ElectionsPhragmen
147146
c @ _ => {
148147
warn!("Call Not Handled: {:?}", c);
149148
(Module::NotHandled, Box::new(NotHandled))

src/archive.rs

Lines changed: 84 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,44 @@
1717
//! Spawning of all tasks happens in this module
1818
//! Nowhere else is anything ever spawned
1919
20-
use log::*;
21-
use tokio::runtime::Runtime;
22-
use substrate_rpc_primitives::number::NumberOrHex;
2320
use futures::{
24-
Future, Stream,
21+
future::{self, loop_fn, Loop},
2522
sync::mpsc::{self, UnboundedReceiver, UnboundedSender},
26-
future::{self, loop_fn, Loop}
27-
};
28-
use substrate_primitives::{
29-
U256,
30-
storage::StorageKey,
31-
twox_128
23+
Future, Stream,
3224
};
25+
use log::*;
26+
use substrate_primitives::{storage::StorageKey, twox_128, U256};
27+
use substrate_rpc_primitives::number::NumberOrHex;
28+
use tokio::runtime::Runtime;
3329

3430
use std::sync::Arc;
3531

3632
use crate::{
3733
database::Database,
38-
rpc::Rpc,
3934
error::Error as ArchiveError,
40-
types::{System, Data}
35+
rpc::Rpc,
36+
types::{Data, System},
4137
};
4238

4339
// with the hopeful and long-anticipated release of async-await
4440
pub struct Archive<T: System> {
4541
rpc: Arc<Rpc<T>>,
4642
db: Arc<Database>,
47-
runtime: Runtime
43+
runtime: Runtime,
4844
}
4945

50-
impl<T> Archive<T> where T: System {
51-
46+
impl<T> Archive<T>
47+
where
48+
T: System,
49+
{
5250
pub fn new() -> Result<Self, ArchiveError> {
5351
let mut runtime = Runtime::new()?;
5452
let rpc = runtime.block_on(Rpc::<T>::new(url::Url::parse("ws://127.0.0.1:9944")?))?;
5553
let db = Database::new()?;
5654
let (rpc, db) = (Arc::new(rpc), Arc::new(db));
5755
debug!("METADATA: {}", rpc.metadata());
5856
debug!("KEYS: {:?}", rpc.keys());
59-
Ok( Self { rpc, db, runtime })
57+
Ok(Self { rpc, db, runtime })
6058
}
6159

6260
pub fn run(mut self) -> Result<(), ArchiveError> {
@@ -65,45 +63,44 @@ impl<T> Archive<T> where T: System {
6563
self.runtime.spawn(
6664
self.rpc
6765
.clone()
68-
.subscribe_blocks(sender.clone()).map_err(|e| println!("{:?}", e))
69-
);
70-
self.runtime.spawn(
71-
Self::sync(self.db.clone(), self.rpc.clone(), sender.clone())
72-
.map(|_| ())
66+
.subscribe_blocks(sender.clone())
67+
.map_err(|e| println!("{:?}", e)),
7368
);
69+
self.runtime
70+
.spawn(Self::sync(self.db.clone(), self.rpc.clone(), sender.clone()).map(|_| ()));
7471
tokio::run(Self::handle_data(receiver, self.db.clone()));
7572
Ok(())
7673
}
7774

7875
// TODO return a float between 0 and 1 corresponding to percent of database that is up-to-date?
7976
/// Verification task that ensures all blocks are in the database
80-
fn sync(db: Arc<Database>,
81-
rpc: Arc<Rpc<T>>,
82-
sender: UnboundedSender<Data<T>>
83-
) -> impl Future<Item = Sync, Error = ()> + 'static
84-
{
77+
fn sync(
78+
db: Arc<Database>,
79+
rpc: Arc<Rpc<T>>,
80+
sender: UnboundedSender<Data<T>>,
81+
) -> impl Future<Item = Sync, Error = ()> + 'static {
8582
loop_fn(Sync::new(), move |v| {
8683
let sender0 = sender.clone();
8784
v.sync(db.clone(), rpc.clone(), sender0.clone())
88-
.and_then(move |(sync, done)| {
89-
if done {
90-
Ok(Loop::Break(sync))
91-
} else {
92-
Ok(Loop::Continue(sync))
93-
}
94-
})
85+
.and_then(move |(sync, done)| {
86+
if done {
87+
Ok(Loop::Break(sync))
88+
} else {
89+
Ok(Loop::Continue(sync))
90+
}
91+
})
9592
})
9693
}
9794

98-
fn handle_data(receiver: UnboundedReceiver<Data<T>>,
99-
db: Arc<Database>,
100-
) -> impl Future<Item = (), Error = ()> + 'static
101-
{
95+
fn handle_data(
96+
receiver: UnboundedReceiver<Data<T>>,
97+
db: Arc<Database>,
98+
) -> impl Future<Item = (), Error = ()> + 'static {
10299
receiver.for_each(move |data| {
103100
match data {
104101
Data::SyncProgress(missing_blocks) => {
105102
println!("{} blocks missing", missing_blocks);
106-
},
103+
}
107104
c => {
108105
tokio::spawn(db.insert(c).map_err(|e| error!("{:?}", e)));
109106
}
@@ -120,60 +117,64 @@ struct Sync {
120117

121118
impl Sync {
122119
fn new() -> Self {
123-
Self {
124-
looped: 0,
125-
}
120+
Self { looped: 0 }
126121
}
127122

128-
fn sync<T>(self,
129-
db: Arc<Database>,
130-
rpc: Arc<Rpc<T>>,
131-
sender: UnboundedSender<Data<T>>,
123+
fn sync<T>(
124+
self,
125+
db: Arc<Database>,
126+
rpc: Arc<Rpc<T>>,
127+
sender: UnboundedSender<Data<T>>,
132128
) -> impl Future<Item = (Self, bool), Error = ()> + 'static
133-
where T: System + std::fmt::Debug + 'static
129+
where
130+
T: System + std::fmt::Debug + 'static,
134131
{
135132
let (sender0, sender1) = (sender.clone(), sender.clone());
136133
let (rpc0, rpc1) = (rpc.clone(), rpc.clone());
137134
let looped = self.looped;
138135
info!("Looped: {}", looped);
139136

140-
let missing_blocks =
141-
db.query_missing_blocks()
142-
.and_then(move |blocks| {
143-
match sender0
144-
.unbounded_send(Data::SyncProgress(blocks.len()))
145-
.map_err(Into::into) {
146-
Ok(()) => (),
147-
Err(e) => return future::err(e)
148-
}
149-
future::ok(
150-
blocks
151-
.into_iter()
152-
.take(100_000) // just do 100K blocks at a time
153-
.map(|b| NumberOrHex::Hex(U256::from(b)))
154-
.collect::<Vec<NumberOrHex<T::BlockNumber>>>()
155-
)
156-
}).and_then(move |blocks| {
157-
rpc0.batch_block_from_number(blocks, sender)
158-
.and_then(move |_| {
159-
let looped = looped + 1;
160-
future::ok((Self {looped}, false ))
161-
})
162-
});
163-
164-
let missing_timestamps =
165-
db.query_missing_timestamps::<T>()
166-
.and_then(move |hashes| {
167-
info!("Launching timestamp insertion thread for {} items", hashes.len());
168-
let timestamp_key = b"Timestamp Now";
169-
let storage_key = twox_128(timestamp_key);
170-
let keys = std::iter::repeat(StorageKey(storage_key.to_vec()))
171-
.take(hashes.len())
172-
.collect::<Vec<StorageKey>>();
173-
rpc1.batch_storage(sender1, keys, hashes)
137+
let missing_blocks = db
138+
.query_missing_blocks()
139+
.and_then(move |blocks| {
140+
match sender0
141+
.unbounded_send(Data::SyncProgress(blocks.len()))
142+
.map_err(Into::into)
143+
{
144+
Ok(()) => (),
145+
Err(e) => return future::err(e),
146+
}
147+
future::ok(
148+
blocks
149+
.into_iter()
150+
.take(100_000) // just do 100K blocks at a time
151+
.map(|b| NumberOrHex::Hex(U256::from(b)))
152+
.collect::<Vec<NumberOrHex<T::BlockNumber>>>(),
153+
)
154+
})
155+
.and_then(move |blocks| {
156+
rpc0.batch_block_from_number(blocks, sender)
157+
.and_then(move |_| {
158+
let looped = looped + 1;
159+
future::ok((Self { looped }, false))
160+
})
174161
});
175-
missing_timestamps.join(missing_blocks)
176-
.map_err(|e| error!("{:?}", e))
177-
.map(|(_, b)| b)
162+
163+
let missing_timestamps = db.query_missing_timestamps::<T>().and_then(move |hashes| {
164+
info!(
165+
"Launching timestamp insertion thread for {} items",
166+
hashes.len()
167+
);
168+
let timestamp_key = b"Timestamp Now";
169+
let storage_key = twox_128(timestamp_key);
170+
let keys = std::iter::repeat(StorageKey(storage_key.to_vec()))
171+
.take(hashes.len())
172+
.collect::<Vec<StorageKey>>();
173+
rpc1.batch_storage(sender1, keys, hashes)
174+
});
175+
missing_timestamps
176+
.join(missing_blocks)
177+
.map_err(|e| error!("{:?}", e))
178+
.map(|(_, b)| b)
178179
}
179180
}

src/extrinsics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,13 @@ where
7878

7979
if bytes[0] == 0x16 {
8080
let mut bytes = &bytes[1..];
81+
log::trace!("BYTES WITHOUT 0x16: {:?}", bytes);
8182
let reg: Result<RegistrarCall<RuntimeT>, _> = Decode::decode(&mut bytes).map_err(|_| warn!("Did not decode"));
8283
log::trace!("REGISTRAR CALL: {:?}", reg);
8384
}
8485

86+
log::trace!("bytes read from decoding extrinsic: {:X?}", bytes);
8587
let function = Decode::decode(&mut bytes.as_slice()).map_err(|e| { warn!("Error decoding call"); e })?;
86-
8788
Ok(Self { signature, function, version })
8889
}
8990
}

src/types/traits.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ pub trait System: Send + Sync + 'static + Debug {
7575

7676
/// the Opaque Extrinsic Type
7777
type Extrinsic: Send
78-
+ Sync + ToDatabaseExtrinsic
78+
+ Sync
79+
+ ToDatabaseExtrinsic
7980
+ Debug
8081
+ Serialize
8182
+ DeserializeOwned
8283
+ Clone
8384
+ Eq
8485
+ PartialEq
8586
+ Unpin;
87+
// require Iter
8688

8789
// type Block: BlockTrait + Encode + Decode + Debug;
8890
type Signature: Encode + Decode + Debug;

0 commit comments

Comments
 (0)