Skip to content

Commit

Permalink
Temporary patch for load_block_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
tgmichel committed Sep 28, 2020
1 parent ec5d86b commit 5506e3b
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ethereum::{Block as EthereumBlock, Transaction as EthereumTransaction};
use ethereum_types::{H160, H256, H64, U256, U64, H512};
use jsonrpc_core::{BoxFuture, Result, futures::future::{self, Future}};
use futures::future::TryFutureExt;
use sp_runtime::traits::{Block as BlockT, UniqueSaturatedInto, Zero, One, Saturating};
use sp_runtime::traits::{Block as BlockT, Header as _, UniqueSaturatedInto, Zero, One, Saturating};
use sp_runtime::transaction_validity::TransactionSource;
use sp_api::{ProvideRuntimeApi, BlockId};
use sp_transaction_pool::TransactionPool;
Expand Down Expand Up @@ -225,6 +225,16 @@ impl<B, C, P, CT, BE> EthApi<B, C, P, CT, BE> where
}
Ok(None)
}

fn headers(&self, id: &BlockId<B>) -> (u64,u64) {
let best_number: u64 = UniqueSaturatedInto::<u64>::unique_saturated_into(
self.client.info().best_number
);
let header_number: u64 = UniqueSaturatedInto::<u64>::unique_saturated_into(
*self.client.header(id.clone()).unwrap().unwrap().number()
);
(best_number, header_number)
}
}

impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
Expand Down Expand Up @@ -331,6 +341,10 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
Some(hash) => hash,
_ => return Ok(None),
};
let (best_number, header_number) = self.headers(&id);
if header_number > best_number {
return Ok(None);
}

let block = self.client.runtime_api().current_block(&id)
.map_err(|err| internal_err(format!("call runtime failed: {:?}", err)))?;
Expand Down Expand Up @@ -403,6 +417,10 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
Some(hash) => hash,
_ => return Ok(None),
};
let (best_number, header_number) = self.headers(&id);
if header_number > best_number {
return Ok(None);
}

let block = self.client.runtime_api()
.current_block(&id)
Expand Down Expand Up @@ -548,6 +566,10 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
Some(hash) => hash,
_ => return Ok(None),
};
let (best_number, header_number) = self.headers(&id);
if header_number > best_number {
return Ok(None);
}

let block = self.client.runtime_api().current_block(&id)
.map_err(|err| internal_err(format!("call runtime failed: {:?}", err)))?;
Expand Down Expand Up @@ -577,6 +599,10 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
Some(hash) => hash,
_ => return Ok(None),
};
let (best_number, header_number) = self.headers(&id);
if header_number > best_number {
return Ok(None);
}
let index = index.value();

let block = self.client.runtime_api().current_block(&id)
Expand Down Expand Up @@ -639,6 +665,10 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
Some(hash) => hash,
_ => return Ok(None),
};
let (best_number, header_number) = self.headers(&id);
if header_number > best_number {
return Ok(None);
}

let block = self.client.runtime_api().current_block(&id)
.map_err(|err| internal_err(format!("call runtime failed: {:?}", err)))?;
Expand Down Expand Up @@ -729,6 +759,10 @@ impl<B, C, P, CT, BE> EthApiT for EthApi<B, C, P, CT, BE> where
Some(hash) => hash,
_ => return Ok(Vec::new()),
};
let (best_number, header_number) = self.headers(&id);
if header_number > best_number {
return Ok(Vec::new());
}

let block = self.client.runtime_api()
.current_block(&id)
Expand Down

0 comments on commit 5506e3b

Please sign in to comment.