-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction writeset store #3903
base: master
Are you sure you want to change the base?
Changes from 3 commits
b44f03d
517cc31
6e0b101
bafb56c
dfbd2cd
0e474eb
afb0a2b
8b6a73f
17de1ba
710e91c
5f39577
304eaca
a49efe1
1b6e033
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,15 @@ use starcoin_types::transaction::TransactionStatus; | |
use starcoin_types::transaction::{Transaction, TransactionInfo}; | ||
use starcoin_vm_runtime::metrics::VMMetrics; | ||
use starcoin_vm_types::contract_event::ContractEvent; | ||
use starcoin_vm_types::write_set::WriteSet; | ||
use std::collections::HashMap; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub struct BlockExecutedData { | ||
pub state_root: HashValue, | ||
pub txn_infos: Vec<TransactionInfo>, | ||
pub txn_events: Vec<Vec<ContractEvent>>, | ||
pub txn_write_sets: HashMap<HashValue, WriteSet>, | ||
} | ||
|
||
impl Default for BlockExecutedData { | ||
|
@@ -23,6 +26,7 @@ impl Default for BlockExecutedData { | |
state_root: HashValue::zero(), | ||
txn_events: vec![], | ||
txn_infos: vec![], | ||
txn_write_sets: HashMap::default(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里为什么用HashMap,之前都是vec!, 这里有快速查找和插入需求吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里因为一个block涉及到多个transaction,map实现起来比较方便 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是L80还是哪里?方便给我说下 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里改成了vec,没改之前的考虑是方便说外面一对一的去取;改了之后的考虑是1. 如果有重复hashvalue则不会覆盖造成数据丢失,2. 存数据库时也是用的顺序存储 |
||
} | ||
} | ||
} | ||
|
@@ -53,12 +57,13 @@ pub fn block_execute<S: ChainStateReader + ChainStateWriter>( | |
} | ||
TransactionStatus::Keep(status) => { | ||
chain_state | ||
.apply_write_set(write_set) | ||
.apply_write_set(write_set.clone()) | ||
.map_err(BlockExecutorError::BlockChainStateErr)?; | ||
|
||
let txn_state_root = chain_state | ||
.commit() | ||
.map_err(BlockExecutorError::BlockChainStateErr)?; | ||
|
||
#[cfg(testing)] | ||
info!("txn_hash {} gas_used {}", txn_hash, gas_used); | ||
executed_data.txn_infos.push(TransactionInfo::new( | ||
|
@@ -68,7 +73,11 @@ pub fn block_execute<S: ChainStateReader + ChainStateWriter>( | |
gas_used, | ||
status, | ||
)); | ||
|
||
executed_data.txn_events.push(events); | ||
|
||
// Put write set into result | ||
executed_data.txn_write_sets.insert(txn_hash, write_set); | ||
} | ||
}; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can consume the
txn_write_set
, becase it will not be used any more.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passed it into batch save function