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

Fix panic in pending_runtime_api with Aura consensus env #814

Merged
merged 4 commits into from
Aug 15, 2022

Conversation

icodezjb
Copy link
Contributor

  1. The result of the pending query is not necessarily the final result (for example, inserting many transactions in the next second causes the previous transaction to expire, or the block may be rolled back) just to provide a reference value.
  2. The current pending_runtime_api implementation will report the following panic for Aura consensus.
    1. steps to reproduce
cargo build --release
./target/release/frontier-template-node --tmp --dev --rpc-port 8546

curl -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "eth_getBalance", "params": ["0x77777FeDdddFfC19Ff86DB637967013e6C6A116C","pending"],"id": 1}' http://127.0.0.1:8546

get error:
{"jsonrpc":"2.0","error":{"code":-32603,"message":"Runtime api access error: Application(Execution(RuntimePanicked(\"Slot must increase\")))"},"id":1}
    1. panic infos

The same slot is used twice at https://github.com/paritytech/substrate/blob/master/frame/aura/src/lib.rs#L93

====================

Version: 0.0.0-45f13e0e-x86_64-linux-gnu

   0: sp_panic_handler::set::{{closure}}
   1: std::panicking::rust_panic_with_hook
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/std/src/panicking.rs:610:17
   2: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/std/src/panicking.rs:500:13
   3: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/std/src/sys_common/backtrace.rs:139:18
   4: rust_begin_unwind
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/std/src/panicking.rs:498:5
   5: core::panicking::panic_fmt
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/core/src/panicking.rs:106:14
   6: <(TupleElement0,TupleElement1) as frame_support::traits::hooks::OnInitialize<BlockNumber>>::on_initialize
   7: <(TupleElement0,TupleElement1) as frame_support::traits::hooks::OnInitialize<BlockNumber>>::on_initialize
   8: <(TupleElement0,TupleElement1) as frame_support::traits::hooks::OnInitialize<BlockNumber>>::on_initialize
   9: <(TupleElement0,TupleElement1) as frame_support::traits::hooks::OnInitialize<BlockNumber>>::on_initialize
  10: frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::initialize_block
  11: std::panicking::try
  12: std::thread::local::LocalKey<T>::with
  13: sc_executor::native_executor::WasmExecutor<H>::with_instance::{{closure}}
  14: sc_executor::wasm_runtime::RuntimeCache::with_instance
  15: <sc_executor::native_executor::NativeElseWasmExecutor<D> as sp_core::traits::CodeExecutor>::call
  16: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_aux
  17: sp_state_machine::execution::StateMachine<B,H,Exec>::execute_using_consensus_failure_handler
  18: <sc_service::client::call_executor::LocalCallExecutor<Block,B,E> as sc_client_api::call_executor::CallExecutor<Block>>::contextual_call
  19: <sc_service::client::client::Client<B,E,Block,RA> as sp_api::CallApiAt<Block>>::call_api_at
  20: sp_api::runtime_decl_for_Core::initialize_block_call_api_at
  21: <frontier_template_runtime::RuntimeApiImpl<__SR_API_BLOCK__,RuntimeApiImplCall> as sp_api::Core<__SR_API_BLOCK__>>::Core_initialize_block_runtime_api_impl
  22: sp_api::Core::initialize_block
  23: fc_rpc::eth::pending_runtime_api
  24: <fc_rpc::eth::EthApi<B,C,P,CT,BE,H,A,F> as fc_rpc_core::eth::rpc_impl_EthApi::gen_server::EthApi>::balance
  25: <jsonrpc_core::delegates::DelegateAsyncMethod<T,F> as jsonrpc_core::calls::RpcMethod<M>>::call
  26: <sc_rpc_server::middleware::RpcMiddleware as jsonrpc_core::middleware::Middleware<M>>::on_call
  27: <sc_rpc_server::middleware::RpcMiddleware as jsonrpc_core::middleware::Middleware<M>>::on_request
  28: jsonrpc_core::io::MetaIoHandler<T,S>::handle_request
  29: <jsonrpc_http_server::handler::RpcHandler<M,S> as core::future::future::Future>::poll
  30: <jsonrpc_http_server::handler::RpcHandler<M,S> as core::future::future::Future>::poll
  31: hyper::proto::h1::dispatch::Dispatcher<D,Bs,I,T>::poll_catch
  32: <hyper::server::conn::upgrades::UpgradeableConnection<I,S,E> as core::future::future::Future>::poll
  33: <hyper::server::conn::spawn_all::NewSvcTask<I,N,S,E,W> as core::future::future::Future>::poll
  34: tokio::runtime::task::core::CoreStage<T>::poll
  35: tokio::runtime::task::harness::Harness<T,S>::poll
  36: std::thread::local::LocalKey<T>::with
  37: tokio::runtime::thread_pool::worker::Context::run_task
  38: tokio::runtime::thread_pool::worker::Context::run
  39: tokio::macros::scoped_tls::ScopedKey<T>::set
  40: tokio::runtime::thread_pool::worker::run
  41: tokio::loom::std::unsafe_cell::UnsafeCell<T>::with_mut
  42: tokio::runtime::task::harness::Harness<T,S>::poll
  43: tokio::runtime::blocking::pool::Inner::run
  44: std::sys_common::backtrace::__rust_begin_short_backtrace
  45: core::ops::function::FnOnce::call_once{{vtable.shim}}
  46: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/alloc/src/boxed.rs:1691:9
      <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/alloc/src/boxed.rs:1691:9
      std::sys::unix::thread::Thread::new::thread_start
             at /rustc/0727994435c75fdedd3e9d226cf434089b0ab585/library/std/src/sys/unix/thread.rs:106:17
  47: start_thread
             at /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477:8
  48: clone
             at /build/glibc-eX1tMB/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95


Thread 'tokio-runtime-worker' panicked at 'Slot must increase', /home/zjb/.cargo/git/checkouts/substrate-7e08433d4c370a21/fc3fd07/frame/aura/src/lib.rs:92

This is a bug. Please report it at:

	support.anonymous.an

  1. choose api.initialize_block(&parent_hash, &best_header) instead of api.initialize_block(&best_hash, &best_header)
    It solves the panic of 2, reason refer to 1

@@ -482,7 +482,8 @@ where
.collect::<Vec<<B as BlockT>::Extrinsic>>();
// Manually initialize the overlay.
let header = client.header(best).unwrap().unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove all those unwraps.

@sorpaas sorpaas merged commit fdbe44e into polkadot-evm:master Aug 15, 2022
tgmichel added a commit to moonbeam-foundation/frontier that referenced this pull request Sep 12, 2022
tgmichel added a commit to moonbeam-foundation/frontier that referenced this pull request Sep 22, 2022
abhijeetbhagat pushed a commit to web3labs/frontier that referenced this pull request Jan 11, 2023
…m#814)

* Fix pending_runtime_api

* Use sp_api::HeaderT

* Fix lint

* Fix lint

Co-authored-by: icodezjb <icodezjb@users.noreply.github.com>
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