Skip to content

Commit 9129cb2

Browse files
Junha Yangjunha1
authored andcommitted
Fix bug in transaction execution
append() had consumed transactions, making the zipped iterator always empty. As a consequence, execute_transactions() never had created events.
1 parent 65fbe78 commit 9129cb2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

core/src/block.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ impl OpenBlock {
188188
pub fn execute_transactions(
189189
&mut self,
190190
block_executor: &dyn BlockExecutor,
191-
mut transactions: Vec<Transaction>,
191+
transactions: Vec<Transaction>,
192192
) -> Result<(), Error> {
193193
let execution_id = self.execution_id.expect("Txs can be executed only after opening a block");
194194
// TODO: Handle erroneous transactions
195195
let transaction_results = block_executor
196196
.execute_transactions(execution_id, self.inner_mut().state_mut(), &transactions)
197197
.map_err(|_| Error::Other(String::from("Rejected while executing transactions")))?;
198-
self.block.transactions.append(&mut transactions);
198+
self.block.transactions.append(&mut transactions.clone());
199199
// TODO: How to do this without copy?
200200
let mut tx_events: HashMap<TxHash, Vec<Event>> = HashMap::new();
201201
for (tx, result) in transactions.into_iter().zip(transaction_results.into_iter()) {

integration-test/tests/multi.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
extern crate foundry_integration_test as test_common;
2121

22+
use ckey::{Ed25519KeyPair, Generator, KeyPairTrait, Random};
2223
use std::time::Duration;
2324
use test_common::*;
2425
use tokio::time::delay_for;
@@ -97,3 +98,21 @@ async fn track_blocks() {
9798
}
9899
panic!("Failed to sync 4 nodes")
99100
}
101+
102+
#[actix_rt::test]
103+
async fn events_stored_in_every_nodes() {
104+
let _node: Vec<FoundryNode> = (0..4).into_iter().map(|i| run_node_override(simple_multi_node(i))).collect();
105+
delay_for(Duration::from_secs(3)).await;
106+
107+
let user: Ed25519KeyPair = Random.generate().unwrap();
108+
109+
let tx = create_tx_hello(GRAPHQL_PORT_BASE, user.public(), user.private(), 0).await;
110+
send_tx(GRAPHQL_PORT_BASE, tx.tx_type(), tx.body()).await.unwrap();
111+
112+
delay_for(Duration::from_secs(4)).await;
113+
114+
for i in 0..4 {
115+
let result = get_event(GRAPHQL_PORT_BASE + i, *tx.hash()).await;
116+
assert_eq!(1, result.len());
117+
}
118+
}

0 commit comments

Comments
 (0)