The transaction execution step of the application. Combines what used to be `BeginBlock`, `DeliverTx`, and `EndBlock`.
(
&self,
request: request::FinalizeBlock,
)
| 921 | } |
| 922 | /// The transaction execution step of the application. Combines what used to be `BeginBlock`, `DeliverTx`, and `EndBlock`. |
| 923 | async fn finalize_block( |
| 924 | &self, |
| 925 | request: request::FinalizeBlock, |
| 926 | ) -> AbciResult<response::FinalizeBlock> { |
| 927 | tracing::debug!( |
| 928 | height = request.height.value(), |
| 929 | timestamp = request.time.unix_timestamp(), |
| 930 | hash = request.hash.to_string(), |
| 931 | "finalize block" |
| 932 | ); |
| 933 | |
| 934 | // BeginBlock |
| 935 | let block_height = request.height.into(); |
| 936 | let block_hash = match request.hash { |
| 937 | tendermint::Hash::Sha256(h) => h, |
| 938 | tendermint::Hash::None => return Err(anyhow!("empty block hash").into()), |
| 939 | }; |
| 940 | |
| 941 | if self.halt_height != 0 && block_height == self.halt_height { |
| 942 | tracing::info!( |
| 943 | height = block_height, |
| 944 | "Stopping node due to reaching halt height" |
| 945 | ); |
| 946 | std::process::exit(AppExitCode::Halt as i32); |
| 947 | } |
| 948 | |
| 949 | let db = self.state_store_clone(); |
| 950 | let state = self.committed_state()?; |
| 951 | let mut state_params = state.state_params.clone(); |
| 952 | |
| 953 | state_params.timestamp = to_timestamp(request.time); |
| 954 | |
| 955 | let state = FvmExecState::new(db, self.multi_engine.as_ref(), block_height, state_params) |
| 956 | .context("error creating new state")? |
| 957 | .with_block_hash(block_hash) |
| 958 | .with_validator_id(request.proposer_address); |
| 959 | |
| 960 | tracing::debug!("initialized exec state"); |
| 961 | |
| 962 | self.put_exec_state(state).await; |
| 963 | |
| 964 | let ret = self |
| 965 | .modify_exec_state(|s| self.interpreter.begin(s)) |
| 966 | .await |
| 967 | .context("begin failed")?; |
| 968 | |
| 969 | // [Deliver Tx] |
| 970 | let mut tx_results = Vec::new(); |
| 971 | for tx in request.txs { |
| 972 | let msg = tx.to_vec(); |
| 973 | let (result, block_hash) = self |
| 974 | .modify_exec_state(|s| async { |
| 975 | let ((env, state), res) = self.interpreter.deliver(s, msg).await?; |
| 976 | let block_hash = state.block_hash(); |
| 977 | Ok(((env, state), (res, block_hash))) |
| 978 | }) |
| 979 | .await |
| 980 | .context("deliver failed")?; |
nothing calls this directly
no test coverage detected