Skip to content

Commit a8fe9fb

Browse files
authored
chainHead: Remove chainHead_genesis method (paritytech#2296)
The method has been removed from the spec (https://github.com/paritytech/json-rpc-interface-spec/tree/main/src), this PR keeps the `chainHead` in sync with that change. @paritytech/subxt-team --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
1 parent 34b2e92 commit a8fe9fb

4 files changed

Lines changed: 2 additions & 62 deletions

File tree

substrate/client/rpc-spec-v2/src/chain_head/api.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ pub trait ChainHeadApi<Hash> {
7474
hash: Hash,
7575
) -> RpcResult<Option<String>>;
7676

77-
/// Get the chain's genesis hash.
78-
///
79-
/// # Unstable
80-
///
81-
/// This method is unstable and subject to change in the future.
82-
#[method(name = "chainHead_unstable_genesisHash", blocking)]
83-
fn chain_head_unstable_genesis_hash(&self) -> RpcResult<String>;
84-
8577
/// Returns storage entries at a specific block's state.
8678
///
8779
/// # Unstable

substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ pub struct ChainHead<BE: Backend<Block>, Block: BlockT, Client> {
107107
executor: SubscriptionTaskExecutor,
108108
/// Keep track of the pinned blocks for each subscription.
109109
subscriptions: Arc<SubscriptionManagement<Block, BE>>,
110-
/// The hexadecimal encoded hash of the genesis block.
111-
genesis_hash: String,
112110
/// The maximum number of items reported by the `chainHead_storage` before
113111
/// pagination is required.
114112
operation_max_storage_items: usize,
@@ -118,14 +116,12 @@ pub struct ChainHead<BE: Backend<Block>, Block: BlockT, Client> {
118116

119117
impl<BE: Backend<Block>, Block: BlockT, Client> ChainHead<BE, Block, Client> {
120118
/// Create a new [`ChainHead`].
121-
pub fn new<GenesisHash: AsRef<[u8]>>(
119+
pub fn new(
122120
client: Arc<Client>,
123121
backend: Arc<BE>,
124122
executor: SubscriptionTaskExecutor,
125-
genesis_hash: GenesisHash,
126123
config: ChainHeadConfig,
127124
) -> Self {
128-
let genesis_hash = hex_string(&genesis_hash.as_ref());
129125
Self {
130126
client,
131127
backend: backend.clone(),
@@ -137,7 +133,6 @@ impl<BE: Backend<Block>, Block: BlockT, Client> ChainHead<BE, Block, Client> {
137133
backend,
138134
)),
139135
operation_max_storage_items: config.operation_max_storage_items,
140-
genesis_hash,
141136
_phantom: PhantomData,
142137
}
143138
}
@@ -315,10 +310,6 @@ where
315310
.map_err(Into::into)
316311
}
317312

318-
fn chain_head_unstable_genesis_hash(&self) -> RpcResult<String> {
319-
Ok(self.genesis_hash.clone())
320-
}
321-
322313
fn chain_head_unstable_storage(
323314
&self,
324315
follow_subscription: String,

substrate/client/rpc-spec-v2/src/chain_head/tests.rs

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use futures::Future;
2828
use jsonrpsee::{
2929
core::{error::Error, server::rpc_module::Subscription as RpcSubscription},
3030
rpc_params,
31-
types::{error::CallError, EmptyServerParams as EmptyParams},
31+
types::error::CallError,
3232
RpcModule,
3333
};
3434
use sc_block_builder::BlockBuilderBuilder;
@@ -61,7 +61,6 @@ const MAX_PINNED_BLOCKS: usize = 32;
6161
const MAX_PINNED_SECS: u64 = 60;
6262
const MAX_OPERATIONS: usize = 16;
6363
const MAX_PAGINATION_LIMIT: usize = 5;
64-
const CHAIN_GENESIS: [u8; 32] = [0; 32];
6564
const INVALID_HASH: [u8; 32] = [1; 32];
6665
const KEY: &[u8] = b":mock";
6766
const VALUE: &[u8] = b"hello world";
@@ -111,7 +110,6 @@ async fn setup_api() -> (
111110
client.clone(),
112111
backend,
113112
Arc::new(TaskExecutor::default()),
114-
CHAIN_GENESIS,
115113
ChainHeadConfig {
116114
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
117115
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -162,7 +160,6 @@ async fn follow_subscription_produces_blocks() {
162160
client.clone(),
163161
backend,
164162
Arc::new(TaskExecutor::default()),
165-
CHAIN_GENESIS,
166163
ChainHeadConfig {
167164
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
168165
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -231,7 +228,6 @@ async fn follow_with_runtime() {
231228
client.clone(),
232229
backend,
233230
Arc::new(TaskExecutor::default()),
234-
CHAIN_GENESIS,
235231
ChainHeadConfig {
236232
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
237233
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -345,31 +341,6 @@ async fn follow_with_runtime() {
345341
assert_eq!(event, expected);
346342
}
347343

348-
#[tokio::test]
349-
async fn get_genesis() {
350-
let builder = TestClientBuilder::new();
351-
let backend = builder.backend();
352-
let client = Arc::new(builder.build());
353-
354-
let api = ChainHead::new(
355-
client.clone(),
356-
backend,
357-
Arc::new(TaskExecutor::default()),
358-
CHAIN_GENESIS,
359-
ChainHeadConfig {
360-
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
361-
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
362-
subscription_max_ongoing_operations: MAX_OPERATIONS,
363-
operation_max_storage_items: MAX_PAGINATION_LIMIT,
364-
},
365-
)
366-
.into_rpc();
367-
368-
let genesis: String =
369-
api.call("chainHead_unstable_genesisHash", EmptyParams::new()).await.unwrap();
370-
assert_eq!(genesis, hex_string(&CHAIN_GENESIS));
371-
}
372-
373344
#[tokio::test]
374345
async fn get_header() {
375346
let (_client, api, _sub, sub_id, block) = setup_api().await;
@@ -569,7 +540,6 @@ async fn call_runtime_without_flag() {
569540
client.clone(),
570541
backend,
571542
Arc::new(TaskExecutor::default()),
572-
CHAIN_GENESIS,
573543
ChainHeadConfig {
574544
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
575545
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -1228,7 +1198,6 @@ async fn separate_operation_ids_for_subscriptions() {
12281198
client.clone(),
12291199
backend,
12301200
Arc::new(TaskExecutor::default()),
1231-
CHAIN_GENESIS,
12321201
ChainHeadConfig {
12331202
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
12341203
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -1316,7 +1285,6 @@ async fn follow_generates_initial_blocks() {
13161285
client.clone(),
13171286
backend,
13181287
Arc::new(TaskExecutor::default()),
1319-
CHAIN_GENESIS,
13201288
ChainHeadConfig {
13211289
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
13221290
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -1472,7 +1440,6 @@ async fn follow_exceeding_pinned_blocks() {
14721440
client.clone(),
14731441
backend,
14741442
Arc::new(TaskExecutor::default()),
1475-
CHAIN_GENESIS,
14761443
ChainHeadConfig {
14771444
global_max_pinned_blocks: 2,
14781445
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -1549,7 +1516,6 @@ async fn follow_with_unpin() {
15491516
client.clone(),
15501517
backend,
15511518
Arc::new(TaskExecutor::default()),
1552-
CHAIN_GENESIS,
15531519
ChainHeadConfig {
15541520
global_max_pinned_blocks: 2,
15551521
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -1815,7 +1781,6 @@ async fn follow_prune_best_block() {
18151781
client.clone(),
18161782
backend,
18171783
Arc::new(TaskExecutor::default()),
1818-
CHAIN_GENESIS,
18191784
ChainHeadConfig {
18201785
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
18211786
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -2001,7 +1966,6 @@ async fn follow_forks_pruned_block() {
20011966
client.clone(),
20021967
backend,
20031968
Arc::new(TaskExecutor::default()),
2004-
CHAIN_GENESIS,
20051969
ChainHeadConfig {
20061970
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
20071971
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -2153,7 +2117,6 @@ async fn follow_report_multiple_pruned_block() {
21532117
client.clone(),
21542118
backend,
21552119
Arc::new(TaskExecutor::default()),
2156-
CHAIN_GENESIS,
21572120
ChainHeadConfig {
21582121
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
21592122
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -2399,7 +2362,6 @@ async fn pin_block_references() {
23992362
client.clone(),
24002363
backend.clone(),
24012364
Arc::new(TaskExecutor::default()),
2402-
CHAIN_GENESIS,
24032365
ChainHeadConfig {
24042366
global_max_pinned_blocks: 3,
24052367
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -2537,7 +2499,6 @@ async fn follow_finalized_before_new_block() {
25372499
client_mock.clone(),
25382500
backend,
25392501
Arc::new(TaskExecutor::default()),
2540-
CHAIN_GENESIS,
25412502
ChainHeadConfig {
25422503
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
25432504
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -2652,7 +2613,6 @@ async fn ensure_operation_limits_works() {
26522613
client.clone(),
26532614
backend,
26542615
Arc::new(TaskExecutor::default()),
2655-
CHAIN_GENESIS,
26562616
ChainHeadConfig {
26572617
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
26582618
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -2757,7 +2717,6 @@ async fn check_continue_operation() {
27572717
client.clone(),
27582718
backend,
27592719
Arc::new(TaskExecutor::default()),
2760-
CHAIN_GENESIS,
27612720
ChainHeadConfig {
27622721
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
27632722
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),
@@ -2940,7 +2899,6 @@ async fn stop_storage_operation() {
29402899
client.clone(),
29412900
backend,
29422901
Arc::new(TaskExecutor::default()),
2943-
CHAIN_GENESIS,
29442902
ChainHeadConfig {
29452903
global_max_pinned_blocks: MAX_PINNED_BLOCKS,
29462904
subscription_max_pinned_duration: Duration::from_secs(MAX_PINNED_SECS),

substrate/client/service/src/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ where
637637
client.clone(),
638638
backend.clone(),
639639
task_executor.clone(),
640-
client.info().genesis_hash,
641640
// Defaults to sensible limits for the `ChainHead`.
642641
sc_rpc_spec_v2::chain_head::ChainHeadConfig::default(),
643642
)

0 commit comments

Comments
 (0)