Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release branch polkadot-v1.0.0 #1123

Merged
merged 1 commit into from
Jul 29, 2023
Merged

Release branch polkadot-v1.0.0 #1123

merged 1 commit into from
Jul 29, 2023

Conversation

koushiro
Copy link
Collaborator

related PR: paritytech/substrate#14594

Close #1122

@koushiro koushiro requested a review from sorpaas as a code owner July 29, 2023 14:59
@koushiro
Copy link
Collaborator Author

koushiro commented Jul 29, 2023

better to merge #1091 and #1104 first and rebase the polkadot-v1.0.0 branch

@sorpaas
Copy link
Member

sorpaas commented Jul 29, 2023

Let's just do backports. polkadot-v1.0.0 is LTS so I'm supposing it will happen quite often.

@sorpaas sorpaas merged commit 7d93355 into polkadot-evm:polkadot-v1.0.0 Jul 29, 2023
3 of 4 checks passed
@koushiro koushiro deleted the v1.0.0-backport branch July 30, 2023 03:01
@koushiro
Copy link
Collaborator Author

koushiro commented Jul 30, 2023

@sorpaas I found CI was broken by the tests about checking pending state.

related PR:

Frontier

The pending runtime api use the same runtime api instance for different blocks.

The implementation here is wrong, and so is #814. We should intruduce the inherent provider rather than to change the at params of runtime api.

fn pending_runtime_api<'a, B: BlockT, C, BE, A: ChainApi>(
	client: &'a C,
	graph: &'a Pool<A>,
) -> RpcResult<ApiRef<'a, C::Api>>
where
	B: BlockT,
	C: ProvideRuntimeApi<B>,
	C::Api: BlockBuilderApi<B> + EthereumRuntimeRPCApi<B>,
	C: HeaderBackend<B> + StorageProvider<B, BE> + 'static,
	BE: Backend<B>,
	A: ChainApi<Block = B> + 'static,
{
	// In case of Pending, we need an overlayed state to query over.
	let api = client.runtime_api();
	let best_hash = client.info().best_hash;
	// Get all transactions in the ready queue.
	let xts: Vec<<B as BlockT>::Extrinsic> = graph
		.validated_pool()
		.ready()
		.map(|in_pool_tx| in_pool_tx.data().clone())
		.collect::<Vec<<B as BlockT>::Extrinsic>>();
	// Manually initialize the overlay.
	if let Ok(Some(header)) = client.header(best_hash) {
		let parent_hash = *header.parent_hash();
		api.initialize_block(parent_hash, &header)            <======================== parent_hash
			.map_err(|e| internal_err(format!("Runtime api access error: {:?}", e)))?;
		// Apply the ready queue to the best block's state.
		for xt in xts {
			let _ = api.apply_extrinsic(best_hash, xt);   <======================== best_hash
		}
		Ok(api)
	} else {
		Err(internal_err(format!(
			"Cannot get header for block {:?}",
			best_hash
		)))
	}
}

Substrate

https://github.com/paritytech/substrate/blob/31491fa24164b1cc9fffd5f07f06f41c8fef437d/primitives/api/proc-macro/src/impl_runtime_apis.rs#L514C1-L532C1

fn __runtime_api_internal_call_api_at(
    &self,
    at: <__SrApiBlock__ as #crate_::BlockT>::Hash,
    params: std::vec::Vec<u8>,
    fn_name: &dyn Fn(#crate_::RuntimeVersion) -> &'static str,
) -> std::result::Result<std::vec::Vec<u8>, #crate_::ApiError> {
    // If we are not already in a transaction, we should create a new transaction
    // and then commit/roll it back at the end!
    let transaction_depth = *std::cell::RefCell::borrow(&self.transaction_depth);

    if transaction_depth == 0 {
        self.start_transaction();
    }

    let res = (|| {
        let version = #crate_::CallApiAt::<__SrApiBlock__>::runtime_version_at(
	    self.call,
	    at,
	    )?;

        match &mut *std::cell::RefCell::borrow_mut(&self.extensions_generated_for) {
	    Some(generated_for) => {
	        if *generated_for != at {
		    return std::result::Result::Err(
			 #crate_::ApiError::UsingSameInstanceForDifferentBlocks   <============== error
		    )
		}
	    },
	    generated_for @ None => {
	        #crate_::CallApiAt::<__SrApiBlock__>::initialize_extensions(
		    self.call,
		    at,
	            &mut std::cell::RefCell::borrow_mut(&self.extensions),
	        )?;

	       *generated_for = Some(at);
	    }
	}

	let params = #crate_::CallApiAtParams {
		at,
		function: (*fn_name)(version),
		arguments: params,
		overlayed_changes: &self.changes,
		storage_transaction_cache: &self.storage_transaction_cache,
		call_context: self.call_context,
		recorder: &self.recorder,
		extensions: &self.extensions,
	};

	#crate_::CallApiAt::<__SrApiBlock__>::call_api_at(
		self.call,
		params,
	)
	})();

	if transaction_depth == 0 {
		self.commit_or_rollback_transaction(std::result::Result::is_ok(&res));
	}

	res
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants