Skip to content

Commit

Permalink
reafactor!: remove event_recommendations from block
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Aug 2, 2024
1 parent 4983549 commit 2b1a49b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 45 deletions.
8 changes: 5 additions & 3 deletions core/benches/blocks/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| {})
Expand Down
2 changes: 1 addition & 1 deletion core/benches/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| {})
Expand Down
2 changes: 1 addition & 1 deletion core/benches/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 6 additions & 16 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ mod pending {
/// Collection of transactions which have been accepted.
/// Transaction will be validated when block is chained.
transactions: Vec<AcceptedTransaction>,
/// Event recommendations for use in triggers and off-chain work
event_recommendations: Vec<EventBox>,
}

impl BlockBuilder<Pending> {
Expand All @@ -142,14 +140,8 @@ mod pending {
///
/// if the given list of transaction is empty
#[inline]
pub fn new(
transactions: Vec<AcceptedTransaction>,
event_recommendations: Vec<EventBox>,
) -> Self {
Self(Pending {
transactions,
event_recommendations,
})
pub fn new(transactions: Vec<AcceptedTransaction>) -> Self {
Self(Pending { transactions })
}

fn make_header(
Expand Down Expand Up @@ -238,7 +230,6 @@ mod pending {
state.world.parameters().sumeragi.consensus_estimation(),
),
transactions,
event_recommendations: self.0.event_recommendations,
}))
}
}
Expand Down Expand Up @@ -750,7 +741,6 @@ mod valid {
consensus_estimation_ms: 4_000,
},
transactions: Vec::new(),
event_recommendations: Vec::new(),
};
f(&mut payload);
BlockBuilder(Chained(payload))
Expand Down Expand Up @@ -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(|_| {});
Expand Down Expand Up @@ -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(|_| {});
Expand Down Expand Up @@ -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(|_| {});
Expand Down Expand Up @@ -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(|_| {});
Expand Down
6 changes: 3 additions & 3 deletions core/src/smartcontracts/isi/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|_| {})
Expand All @@ -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(|_| {})
Expand Down Expand Up @@ -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(|_| {})
Expand Down
14 changes: 9 additions & 5 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ fn create_config() -> Result<WasmtimeConfig> {
fn forget_all_executed_queries(
query_handle: &LiveQueryStoreHandle,
executed_queries: impl IntoIterator<Item = QueryId>,
) -> Result<()> {
) {
for query_id in executed_queries {
query_handle.drop_query(query_id);
}
Ok(())
}

/// Limits checker for smartcontracts.
Expand Down Expand Up @@ -780,7 +779,8 @@ impl<W: state::chain_state::ConstState, S> Runtime<state::CommonState<W, S>> {
forget_all_executed_queries(
state.state.state().borrow().query_handle(),
executed_queries,
)?;
);

Ok(validation_res)
}
}
Expand Down Expand Up @@ -936,7 +936,9 @@ impl<'wrld, 'block: 'wrld, 'state: 'block> Runtime<state::SmartContract<'wrld, '
.map_err(ExportFnCallError::from)?;
let mut state = store.into_data();
let executed_queries = state.take_executed_queries();
forget_all_executed_queries(state.state.0.query_handle, executed_queries)
forget_all_executed_queries(state.state.0.query_handle, executed_queries);

Ok(())
}

#[codec::wrap]
Expand Down Expand Up @@ -1008,7 +1010,9 @@ impl<'wrld, 'block: 'wrld, 'state: 'block> Runtime<state::Trigger<'wrld, 'block,

let mut state = store.into_data();
let executed_queries = state.take_executed_queries();
forget_all_executed_queries(state.state.0.query_handle, executed_queries)
forget_all_executed_queries(state.state.0.query_handle, executed_queries);

Ok(())
}

#[codec::wrap]
Expand Down
7 changes: 3 additions & 4 deletions core/src/sumeragi/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,8 @@ impl Sumeragi {

// TODO: properly process triggers!
let mut state_block = state.block();
let event_recommendations = Vec::new();
let create_block_start_time = Instant::now();
let new_block = BlockBuilder::new(transactions, event_recommendations)
let new_block = BlockBuilder::new(transactions)
.chain(self.topology.view_change_index(), &mut state_block)
.sign(self.key_pair.private_key())
.unpack(|e| self.send_event(e));
Expand Down Expand Up @@ -1429,7 +1428,7 @@ mod tests {
.expect("Valid");

// Creating a block of two identical transactions and validating it
let block = BlockBuilder::new(vec![peers, tx.clone(), tx], Vec::new())
let block = BlockBuilder::new(vec![peers, tx.clone(), tx])
.chain(0, &mut state_block)
.sign(leader_private_key)
.unpack(|_| {});
Expand Down Expand Up @@ -1474,7 +1473,7 @@ mod tests {
.expect("Valid");

// Creating a block of two identical transactions and validating it
BlockBuilder::new(vec![tx1, tx2], Vec::new())
BlockBuilder::new(vec![tx1, tx2])
.chain(0, &mut state_block)
.sign(leader_private_key)
.unpack(|_| {})
Expand Down
6 changes: 1 addition & 5 deletions data_model/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use parity_scale_codec::{Decode, Encode};
use serde::{Deserialize, Serialize};

pub use self::model::*;
use crate::{events::prelude::*, transaction::prelude::*};
use crate::transaction::prelude::*;

#[model]
mod model {
Expand Down Expand Up @@ -93,8 +93,6 @@ mod model {
pub header: BlockHeader,
/// array of transactions, which successfully passed validation and consensus step.
pub transactions: Vec<CommittedTransaction>,
/// Event recommendations.
pub event_recommendations: Vec<EventBox>,
}

/// Signature of a block
Expand Down Expand Up @@ -296,7 +294,6 @@ impl SignedBlock {
let payload = BlockPayload {
header,
transactions,
event_recommendations: vec![],
};

let signature = BlockSignature(0, SignatureOf::new(genesis_private_key, &payload));
Expand Down Expand Up @@ -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(())
}
Expand Down
7 changes: 0 additions & 7 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,6 @@
{
"name": "transactions",
"type": "Vec<CommittedTransaction>"
},
{
"name": "event_recommendations",
"type": "Vec<EventBox>"
}
]
},
Expand Down Expand Up @@ -4478,9 +4474,6 @@
"Vec<CommittedTransaction>": {
"Vec": "CommittedTransaction"
},
"Vec<EventBox>": {
"Vec": "EventBox"
},
"Vec<EventFilterBox>": {
"Vec": "EventFilterBox"
},
Expand Down

0 comments on commit 2b1a49b

Please sign in to comment.