Parse messages in the mempool and pass them into the inner `ChainMessage` interpreter.
(
&self,
state: Self::State,
msgs: Vec<Self::Message>,
)
| 72 | |
| 73 | /// Parse messages in the mempool and pass them into the inner `ChainMessage` interpreter. |
| 74 | async fn prepare( |
| 75 | &self, |
| 76 | state: Self::State, |
| 77 | msgs: Vec<Self::Message>, |
| 78 | ) -> anyhow::Result<Vec<Self::Message>> { |
| 79 | // Collect the messages to pass to the inner interpreter. |
| 80 | let chain_msgs = match self.prepare_mode { |
| 81 | ProposalPrepareMode::PassThrough => { |
| 82 | let mut chain_msgs = Vec::new(); |
| 83 | for msg in msgs.iter() { |
| 84 | match fvm_ipld_encoding::from_slice::<ChainMessage>(msg) { |
| 85 | Err(e) => { |
| 86 | // This should not happen because the `CheckInterpreter` implementation below would |
| 87 | // have rejected any such user transaction. |
| 88 | tracing::warn!( |
| 89 | error = e.to_string(), |
| 90 | "failed to decode message in mempool as ChainMessage" |
| 91 | ); |
| 92 | } |
| 93 | Ok(msg) => chain_msgs.push(msg), |
| 94 | } |
| 95 | } |
| 96 | chain_msgs |
| 97 | } |
| 98 | ProposalPrepareMode::AppendOnly | ProposalPrepareMode::PrependOnly => Vec::new(), |
| 99 | }; |
| 100 | |
| 101 | let chain_msgs = self.inner.prepare(state, chain_msgs).await?; |
| 102 | |
| 103 | let chain_msgs = chain_msgs |
| 104 | .into_iter() |
| 105 | .map(|msg| { |
| 106 | fvm_ipld_encoding::to_vec(&msg).context("failed to encode ChainMessage as IPLD") |
| 107 | }) |
| 108 | .collect::<anyhow::Result<Vec<Self::Message>>>()?; |
| 109 | |
| 110 | let mut all_msgs = match self.prepare_mode { |
| 111 | ProposalPrepareMode::PassThrough => chain_msgs, |
| 112 | ProposalPrepareMode::AppendOnly => [msgs, chain_msgs].concat(), |
| 113 | ProposalPrepareMode::PrependOnly => [chain_msgs, msgs].concat(), |
| 114 | }; |
| 115 | |
| 116 | if all_msgs.len() > self.max_msgs { |
| 117 | tracing::warn!( |
| 118 | max_msgs = self.max_msgs, |
| 119 | all_msgs = all_msgs.len(), |
| 120 | "truncating proposal" |
| 121 | ); |
| 122 | all_msgs.truncate(self.max_msgs); |
| 123 | } |
| 124 | |
| 125 | Ok(all_msgs) |
| 126 | } |
| 127 | |
| 128 | /// Parse messages in the block, reject if unknown format. Pass the rest to the inner `ChainMessage` interpreter. |
| 129 | async fn process(&self, state: Self::State, msgs: Vec<Self::Message>) -> anyhow::Result<bool> { |
no test coverage detected