From 58c943e44eea09e6f0c80c487547d0ff11f9eccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marin=20Ver=C5=A1i=C4=87?= Date: Mon, 5 Aug 2024 10:09:24 +0200 Subject: [PATCH] refactor!: remove `event_recommendations` from block (#4932) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marin Veršić --- core/benches/blocks/common.rs | 8 +++++--- core/benches/kura.rs | 2 +- core/benches/validation.rs | 2 +- core/src/block.rs | 22 ++++++---------------- core/src/smartcontracts/isi/query.rs | 6 +++--- core/src/smartcontracts/wasm.rs | 14 +++++++++----- core/src/sumeragi/main_loop.rs | 8 +++----- data_model/src/block.rs | 6 +----- docs/source/references/schema.json | 7 ------- schema/gen/src/lib.rs | 1 - 10 files changed, 29 insertions(+), 47 deletions(-) diff --git a/core/benches/blocks/common.rs b/core/benches/blocks/common.rs index 92f1416a558..5bbfcb0628b 100644 --- a/core/benches/blocks/common.rs +++ b/core/benches/blocks/common.rs @@ -38,10 +38,12 @@ pub fn create_block( .sign(account_private_key); let limits = state.transaction_executor().limits; - let block = BlockBuilder::new( - vec![AcceptedTransaction::accept(transaction, &chain_id, limits).unwrap()], - Vec::new(), + let block = BlockBuilder::new(vec![AcceptedTransaction::accept( + transaction, + &chain_id, + limits, ) + .unwrap()]) .chain(0, state) .sign(peer_private_key) .unpack(|_| {}) diff --git a/core/benches/kura.rs b/core/benches/kura.rs index 4fac9fa8144..061d8de8532 100644 --- a/core/benches/kura.rs +++ b/core/benches/kura.rs @@ -52,7 +52,7 @@ async fn measure_block_size_for_n_executors(n_executors: u32) { let topology = Topology::new(vec![peer_id]); let mut block = { let mut state_block = state.block(); - BlockBuilder::new(vec![tx], Vec::new()) + BlockBuilder::new(vec![tx]) .chain(0, &mut state_block) .sign(&peer_private_key) .unpack(|_| {}) diff --git a/core/benches/validation.rs b/core/benches/validation.rs index 9881be3789b..ff7cc119d1e 100644 --- a/core/benches/validation.rs +++ b/core/benches/validation.rs @@ -151,7 +151,7 @@ fn sign_blocks(criterion: &mut Criterion) { let mut count = 0; let mut state_block = state.block(); - let block = BlockBuilder::new(vec![transaction], Vec::new()).chain(0, &mut state_block); + let block = BlockBuilder::new(vec![transaction]).chain(0, &mut state_block); let _ = criterion.bench_function("sign_block", |b| { b.iter_batched( diff --git a/core/src/block.rs b/core/src/block.rs index aaa09efcf61..b007c36e740 100644 --- a/core/src/block.rs +++ b/core/src/block.rs @@ -131,8 +131,6 @@ mod pending { /// Collection of transactions which have been accepted. /// Transaction will be validated when block is chained. transactions: Vec, - /// Event recommendations for use in triggers and off-chain work - event_recommendations: Vec, } impl BlockBuilder { @@ -142,14 +140,8 @@ mod pending { /// /// if the given list of transaction is empty #[inline] - pub fn new( - transactions: Vec, - event_recommendations: Vec, - ) -> Self { - Self(Pending { - transactions, - event_recommendations, - }) + pub fn new(transactions: Vec) -> Self { + Self(Pending { transactions }) } fn make_header( @@ -238,7 +230,6 @@ mod pending { state.world.parameters().sumeragi.consensus_estimation(), ), transactions, - event_recommendations: self.0.event_recommendations, })) } } @@ -750,7 +741,6 @@ mod valid { consensus_estimation_ms: 4_000, }, transactions: Vec::new(), - event_recommendations: Vec::new(), }; f(&mut payload); BlockBuilder(Chained(payload)) @@ -1117,7 +1107,7 @@ mod tests { // Creating a block of two identical transactions and validating it let transactions = vec![tx.clone(), tx]; - let valid_block = BlockBuilder::new(transactions, Vec::new()) + let valid_block = BlockBuilder::new(transactions) .chain(0, &mut state_block) .sign(alice_keypair.private_key()) .unpack(|_| {}); @@ -1188,7 +1178,7 @@ mod tests { // Creating a block of two identical transactions and validating it let transactions = vec![tx0, tx, tx2]; - let valid_block = BlockBuilder::new(transactions, Vec::new()) + let valid_block = BlockBuilder::new(transactions) .chain(0, &mut state_block) .sign(alice_keypair.private_key()) .unpack(|_| {}); @@ -1247,7 +1237,7 @@ mod tests { // Creating a block of where first transaction must fail and second one fully executed let transactions = vec![tx_fail, tx_accept]; - let valid_block = BlockBuilder::new(transactions, Vec::new()) + let valid_block = BlockBuilder::new(transactions) .chain(0, &mut state_block) .sign(alice_keypair.private_key()) .unpack(|_| {}); @@ -1321,7 +1311,7 @@ mod tests { let (peer_public_key, _) = KeyPair::random().into_parts(); let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key); let topology = Topology::new(vec![peer_id]); - let valid_block = BlockBuilder::new(transactions, Vec::new()) + let valid_block = BlockBuilder::new(transactions) .chain(0, &mut state_block) .sign(genesis_correct_key.private_key()) .unpack(|_| {}); diff --git a/core/src/smartcontracts/isi/query.rs b/core/src/smartcontracts/isi/query.rs index cbe95e62919..c6ce936e1c7 100644 --- a/core/src/smartcontracts/isi/query.rs +++ b/core/src/smartcontracts/isi/query.rs @@ -397,7 +397,7 @@ mod tests { let (peer_public_key, peer_private_key) = KeyPair::random().into_parts(); let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key); let topology = Topology::new(vec![peer_id]); - let first_block = BlockBuilder::new(transactions.clone(), Vec::new()) + let first_block = BlockBuilder::new(transactions.clone()) .chain(0, &mut state_block) .sign(&peer_private_key) .unpack(|_| {}) @@ -409,7 +409,7 @@ mod tests { kura.store_block(first_block); for _ in 1u64..blocks { - let block = BlockBuilder::new(transactions.clone(), Vec::new()) + let block = BlockBuilder::new(transactions.clone()) .chain(0, &mut state_block) .sign(&peer_private_key) .unpack(|_| {}) @@ -548,7 +548,7 @@ mod tests { let (peer_public_key, _) = KeyPair::random().into_parts(); let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key); let topology = Topology::new(vec![peer_id]); - let vcb = BlockBuilder::new(vec![va_tx.clone()], Vec::new()) + let vcb = BlockBuilder::new(vec![va_tx.clone()]) .chain(0, &mut state_block) .sign(ALICE_KEYPAIR.private_key()) .unpack(|_| {}) diff --git a/core/src/smartcontracts/wasm.rs b/core/src/smartcontracts/wasm.rs index 68a97541554..d0317c3a7c8 100644 --- a/core/src/smartcontracts/wasm.rs +++ b/core/src/smartcontracts/wasm.rs @@ -284,11 +284,10 @@ fn create_config() -> Result { fn forget_all_executed_queries( query_handle: &LiveQueryStoreHandle, executed_queries: impl IntoIterator, -) -> Result<()> { +) { for query_id in executed_queries { query_handle.drop_query(query_id); } - Ok(()) } /// Limits checker for smartcontracts. @@ -780,7 +779,8 @@ impl Runtime> { forget_all_executed_queries( state.state.state().borrow().query_handle(), executed_queries, - )?; + ); + Ok(validation_res) } } @@ -936,7 +936,9 @@ impl<'wrld, 'block: 'wrld, 'state: 'block> Runtime Runtime, - /// Event recommendations. - pub event_recommendations: Vec, } /// Signature of a block @@ -296,7 +294,6 @@ impl SignedBlock { let payload = BlockPayload { header, transactions, - event_recommendations: vec![], }; let signature = BlockSignature(0, SignatureOf::new(genesis_private_key, &payload)); @@ -407,7 +404,6 @@ mod candidate { if expected_txs_hash != actual_txs_hash { return Err("Transactions' hash incorrect. Expected: {expected_txs_hash:?}, actual: {actual_txs_hash:?}"); } - // TODO: Validate Event recommendations somehow? Ok(()) } diff --git a/docs/source/references/schema.json b/docs/source/references/schema.json index 8fa48af0637..9729ea18fe0 100644 --- a/docs/source/references/schema.json +++ b/docs/source/references/schema.json @@ -633,10 +633,6 @@ { "name": "transactions", "type": "Vec" - }, - { - "name": "event_recommendations", - "type": "Vec" } ] }, @@ -4478,9 +4474,6 @@ "Vec": { "Vec": "CommittedTransaction" }, - "Vec": { - "Vec": "EventBox" - }, "Vec": { "Vec": "EventFilterBox" }, diff --git a/schema/gen/src/lib.rs b/schema/gen/src/lib.rs index 38bf08080c3..8c8fe509767 100644 --- a/schema/gen/src/lib.rs +++ b/schema/gen/src/lib.rs @@ -413,7 +413,6 @@ types!( ValidationFail, Vec, Vec, - Vec, Vec, Vec, Vec,