-
Notifications
You must be signed in to change notification settings - Fork 216
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
Blocks && fully spent transactions pruning #510
Changes from 3 commits
a690ba5
be2f488
89e9afd
fd600d5
eaf274b
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ pub const COL_TRANSACTIONS: u32 = 4; | |
pub const COL_TRANSACTIONS_META: u32 = 5; | ||
pub const COL_BLOCK_NUMBERS: u32 = 6; | ||
pub const COL_CONFIGURATION: u32 = 7; | ||
pub const COL_SPENT_TRANSACTIONS: u32 = 8; | ||
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. Note to myself (and possibly others reviewing this code): we have 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. Yes. I even had an idea to keep this in-memory only - so if node doesn't restarts while syncing, all fully spent transactions will be pruned. But in the case of restart, we could miss some fully spent transactions => 'garbage' in db. Not sure - what's better in general, but for my use-cases (I'm often restarting the node), the permanent storage is better. |
||
|
||
#[derive(Debug)] | ||
pub enum Operation { | ||
|
@@ -30,6 +31,7 @@ pub enum KeyValue { | |
TransactionMeta(H256, TransactionMeta), | ||
BlockNumber(H256, u32), | ||
Configuration(&'static str, Bytes), | ||
SpentTransactions(u32, List<H256>), | ||
} | ||
|
||
#[derive(Debug)] | ||
|
@@ -42,6 +44,7 @@ pub enum Key { | |
TransactionMeta(H256), | ||
BlockNumber(H256), | ||
Configuration(&'static str), | ||
SpentTransactions(u32), | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
|
@@ -54,6 +57,7 @@ pub enum Value { | |
TransactionMeta(TransactionMeta), | ||
BlockNumber(u32), | ||
Configuration(Bytes), | ||
SpentTransactions(List<H256>), | ||
} | ||
|
||
impl Value { | ||
|
@@ -67,6 +71,7 @@ impl Value { | |
Key::TransactionMeta(_) => deserialize(bytes).map(Value::TransactionMeta), | ||
Key::BlockNumber(_) => deserialize(bytes).map(Value::BlockNumber), | ||
Key::Configuration(_) => deserialize(bytes).map(Value::Configuration), | ||
Key::SpentTransactions(_) => deserialize(bytes).map(Value::SpentTransactions), | ||
}.map_err(|e| format!("{:?}", e)) | ||
} | ||
|
||
|
@@ -125,6 +130,13 @@ impl Value { | |
_ => None, | ||
} | ||
} | ||
|
||
pub fn as_spent_transactions(self) -> Option<List<H256>> { | ||
match self { | ||
Value::SpentTransactions(list) => Some(list), | ||
_ => None, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
|
@@ -228,6 +240,7 @@ impl<'a> From<&'a KeyValue> for RawKeyValue { | |
KeyValue::TransactionMeta(ref key, ref value) => (COL_TRANSACTIONS_META, serialize(key), serialize(value)), | ||
KeyValue::BlockNumber(ref key, ref value) => (COL_BLOCK_NUMBERS, serialize(key), serialize(value)), | ||
KeyValue::Configuration(ref key, ref value) => (COL_CONFIGURATION, serialize(key), serialize(value)), | ||
KeyValue::SpentTransactions(ref key, ref value) => (COL_SPENT_TRANSACTIONS, serialize(key), serialize(value)), | ||
}; | ||
|
||
RawKeyValue { | ||
|
@@ -263,6 +276,7 @@ impl<'a> From<&'a Key> for RawKey { | |
Key::TransactionMeta(ref key) => (COL_TRANSACTIONS_META, serialize(key)), | ||
Key::BlockNumber(ref key) => (COL_BLOCK_NUMBERS, serialize(key)), | ||
Key::Configuration(ref key) => (COL_CONFIGURATION, serialize(key)), | ||
Key::SpentTransactions(ref key) => (COL_SPENT_TRANSACTIONS, serialize(key)), | ||
}; | ||
|
||
RawKey { | ||
|
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.
Extra tab typo.