fix block response decoding
This commit is contained in:
		
							parent
							
								
									974f89d5bf
								
							
						
					
					
						commit
						5700f4ac81
					
				| @ -407,7 +407,7 @@ impl LightProtocol { | |||||||
| 		let req_id = ReqId(raw.val_at(0)?); | 		let req_id = ReqId(raw.val_at(0)?); | ||||||
| 		let cur_credits: U256 = raw.val_at(1)?; | 		let cur_credits: U256 = raw.val_at(1)?; | ||||||
| 
 | 
 | ||||||
| 		trace!(target: "pip", "pre-verifying response from peer {}", peer); | 		trace!(target: "pip", "pre-verifying response for {} from peer {}", req_id, peer); | ||||||
| 
 | 
 | ||||||
| 		let peers = self.peers.read(); | 		let peers = self.peers.read(); | ||||||
| 		let res = match peers.get(peer) { | 		let res = match peers.get(peer) { | ||||||
|  | |||||||
| @ -37,7 +37,7 @@ use rlp::RlpStream; | |||||||
| use util::{Bytes, RwLock, Mutex, U256, H256}; | use util::{Bytes, RwLock, Mutex, U256, H256}; | ||||||
| use util::sha3::{SHA3_NULL_RLP, SHA3_EMPTY_LIST_RLP}; | use util::sha3::{SHA3_NULL_RLP, SHA3_EMPTY_LIST_RLP}; | ||||||
| 
 | 
 | ||||||
| use net::{Handler, Status, Capabilities, Announcement, EventContext, BasicContext, ReqId}; | use net::{self, Handler, Status, Capabilities, Announcement, EventContext, BasicContext, ReqId}; | ||||||
| use cache::Cache; | use cache::Cache; | ||||||
| use request::{self as basic_request, Request as NetworkRequest, Response as NetworkResponse}; | use request::{self as basic_request, Request as NetworkRequest, Response as NetworkResponse}; | ||||||
| 
 | 
 | ||||||
| @ -303,17 +303,21 @@ impl OnDemand { | |||||||
| 
 | 
 | ||||||
| 		let complete = builder.build(); | 		let complete = builder.build(); | ||||||
| 
 | 
 | ||||||
|  | 		let kind = complete.requests()[0].kind(); | ||||||
| 		for (id, peer) in self.peers.read().iter() { | 		for (id, peer) in self.peers.read().iter() { | ||||||
| 			if !peer.can_handle(&pending) { continue } | 			if !peer.can_handle(&pending) { continue } | ||||||
| 			match ctx.request_from(*id, complete.clone()) { | 			match ctx.request_from(*id, complete.clone()) { | ||||||
| 				Ok(req_id) => { | 				Ok(req_id) => { | ||||||
| 					trace!(target: "on_demand", "Assigning request to peer {}", id); | 					trace!(target: "on_demand", "{}: Assigned {:?} to peer {}", | ||||||
|  | 						req_id, kind, id); | ||||||
|  | 
 | ||||||
| 					self.pending_requests.write().insert( | 					self.pending_requests.write().insert( | ||||||
| 						req_id, | 						req_id, | ||||||
| 						pending, | 						pending, | ||||||
| 					); | 					); | ||||||
| 					return | 					return | ||||||
| 				} | 				} | ||||||
|  | 				Err(net::Error::NoCredits) => {} | ||||||
| 				Err(e) => | 				Err(e) => | ||||||
| 					trace!(target: "on_demand", "Failed to make request of peer {}: {:?}", id, e), | 					trace!(target: "on_demand", "Failed to make request of peer {}: {:?}", id, e), | ||||||
| 			} | 			} | ||||||
|  | |||||||
| @ -244,7 +244,8 @@ pub enum CompleteRequest { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Request { | impl Request { | ||||||
| 	fn kind(&self) -> Kind { | 	/// Get the request kind.
 | ||||||
|  | 	pub fn kind(&self) -> Kind { | ||||||
| 		match *self { | 		match *self { | ||||||
| 			Request::Headers(_) => Kind::Headers, | 			Request::Headers(_) => Kind::Headers, | ||||||
| 			Request::HeaderProof(_) => Kind::HeaderProof, | 			Request::HeaderProof(_) => Kind::HeaderProof, | ||||||
| @ -727,7 +728,6 @@ pub mod header_proof { | |||||||
| 
 | 
 | ||||||
| 	impl Decodable for Response { | 	impl Decodable for Response { | ||||||
| 		fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> { | 		fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> { | ||||||
| 
 |  | ||||||
| 			Ok(Response { | 			Ok(Response { | ||||||
| 				proof: rlp.list_at(0)?, | 				proof: rlp.list_at(0)?, | ||||||
| 				hash: rlp.val_at(1)?, | 				hash: rlp.val_at(1)?, | ||||||
| @ -825,7 +825,6 @@ pub mod block_receipts { | |||||||
| 
 | 
 | ||||||
| 	impl Decodable for Response { | 	impl Decodable for Response { | ||||||
| 		fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> { | 		fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> { | ||||||
| 
 |  | ||||||
| 			Ok(Response { | 			Ok(Response { | ||||||
| 				receipts: rlp.as_list()?, | 				receipts: rlp.as_list()?, | ||||||
| 			}) | 			}) | ||||||
| @ -922,8 +921,8 @@ pub mod block_body { | |||||||
| 			use ethcore::transaction::UnverifiedTransaction; | 			use ethcore::transaction::UnverifiedTransaction; | ||||||
| 
 | 
 | ||||||
| 			// check body validity.
 | 			// check body validity.
 | ||||||
| 			let _: Vec<FullHeader> = rlp.list_at(0)?; | 			let _: Vec<UnverifiedTransaction> = rlp.list_at(0)?; | ||||||
| 			let _: Vec<UnverifiedTransaction> = rlp.list_at(1)?; | 			let _: Vec<FullHeader> = rlp.list_at(1)?; | ||||||
| 
 | 
 | ||||||
| 			Ok(Response { | 			Ok(Response { | ||||||
| 				body: encoded::Body::new(rlp.as_raw().to_owned()), | 				body: encoded::Body::new(rlp.as_raw().to_owned()), | ||||||
| @ -1480,9 +1479,16 @@ mod tests { | |||||||
| 	fn check_roundtrip<T>(val: T) | 	fn check_roundtrip<T>(val: T) | ||||||
| 		where T: ::rlp::Encodable + ::rlp::Decodable + PartialEq + ::std::fmt::Debug | 		where T: ::rlp::Encodable + ::rlp::Decodable + PartialEq + ::std::fmt::Debug | ||||||
| 	{ | 	{ | ||||||
|  | 		// check as single value.
 | ||||||
| 		let bytes = ::rlp::encode(&val); | 		let bytes = ::rlp::encode(&val); | ||||||
| 		let new_val: T = ::rlp::decode(&bytes); | 		let new_val: T = ::rlp::decode(&bytes); | ||||||
| 		assert_eq!(val, new_val); | 		assert_eq!(val, new_val); | ||||||
|  | 
 | ||||||
|  | 		// check as list containing single value.
 | ||||||
|  | 		let list = [val]; | ||||||
|  | 		let bytes = ::rlp::encode_list(&list); | ||||||
|  | 		let new_list: Vec<T> = ::rlp::decode_list(&bytes); | ||||||
|  | 		assert_eq!(&list, &new_list[..]); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	#[test] | 	#[test] | ||||||
| @ -1566,6 +1572,7 @@ mod tests { | |||||||
| 
 | 
 | ||||||
| 	#[test] | 	#[test] | ||||||
| 	fn body_roundtrip() { | 	fn body_roundtrip() { | ||||||
|  | 		use ethcore::transaction::{Transaction, UnverifiedTransaction}; | ||||||
| 		let req = IncompleteBodyRequest { | 		let req = IncompleteBodyRequest { | ||||||
| 			hash: Field::Scalar(Default::default()), | 			hash: Field::Scalar(Default::default()), | ||||||
| 		}; | 		}; | ||||||
| @ -1573,8 +1580,12 @@ mod tests { | |||||||
| 		let full_req = Request::Body(req.clone()); | 		let full_req = Request::Body(req.clone()); | ||||||
| 		let res = BodyResponse { | 		let res = BodyResponse { | ||||||
| 			body: { | 			body: { | ||||||
|  | 				let header = ::ethcore::header::Header::default(); | ||||||
|  | 				let tx = UnverifiedTransaction::from(Transaction::default().fake_sign(Default::default())); | ||||||
| 				let mut stream = RlpStream::new_list(2); | 				let mut stream = RlpStream::new_list(2); | ||||||
| 				stream.begin_list(0).begin_list(0); | 				stream.begin_list(2).append(&tx).append(&tx) | ||||||
|  | 					.begin_list(1).append(&header); | ||||||
|  | 
 | ||||||
| 				::ethcore::encoded::Body::new(stream.out()) | 				::ethcore::encoded::Body::new(stream.out()) | ||||||
| 			}, | 			}, | ||||||
| 		}; | 		}; | ||||||
|  | |||||||
| @ -166,7 +166,6 @@ impl EthClient { | |||||||
| 	fn proved_execution(&self, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<ExecutionResult, Error> { | 	fn proved_execution(&self, req: CallRequest, num: Trailing<BlockNumber>) -> BoxFuture<ExecutionResult, Error> { | ||||||
| 		const DEFAULT_GAS_PRICE: U256 = U256([0, 0, 0, 21_000_000]); | 		const DEFAULT_GAS_PRICE: U256 = U256([0, 0, 0, 21_000_000]); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 		let (sync, on_demand, client) = (self.sync.clone(), self.on_demand.clone(), self.client.clone()); | 		let (sync, on_demand, client) = (self.sync.clone(), self.on_demand.clone(), self.client.clone()); | ||||||
| 		let req: CRequest = req.into(); | 		let req: CRequest = req.into(); | ||||||
| 		let id = num.0.into(); | 		let id = num.0.into(); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user