-
Notifications
You must be signed in to change notification settings - Fork 243
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
feat: World State Re-orgs #9035
Changes from all commits
46b24db
87a2642
bd0aab7
eb8ad58
8448cdc
7fbb305
30a0d5e
f8cba90
5b6284e
af13709
b21d995
60664e8
bd0bae9
c86cb35
1697a23
8db2c50
01bd840
cee7209
115e9be
91f37cc
dd914ef
8997dd3
72b5fa8
a0d3b33
399492e
0f6a272
83aaaca
cda2860
307e29b
2df113d
6ef0218
bb189b6
4a9b68d
ff41a25
e0e2367
52440b9
545b604
910e7b5
3c642d4
cc41c3f
5d9c985
ff8de80
afd7a0f
9e0afd8
2fe4e8b
77a4c49
de1496b
fcdf688
d77ab63
30868b6
c7e27e9
e17afdd
04c66ba
5c1d51b
9b9257a
03bde5a
83f0d52
d603135
1bc51b0
c73bfb2
6036ae9
3beddf3
f192da8
c7740d1
fbfd5d3
fb4b197
5955387
8a5768b
beb6333
53757f1
42e96f8
8fb271c
027c4ae
52be23e
49ac72f
19bd6a9
ead7b6d
65ab5af
4aa86aa
51bf6b6
1572dc5
bd7fb8d
e102a9e
f84bb85
dd4485d
ed9f638
2e3c5d0
46f2004
91058e3
0c9aedd
0a4f447
f75a6cc
184d3d5
1cff79a
04ddfa0
cc202d2
cba51ff
e580483
9fb122b
48e41ef
ba1518f
764c47c
dade28f
b54bfbb
b1a597f
184666b
40d4f36
4d753df
d85c4fa
051a924
c01d985
aa55f0d
5e7e5e0
8e8da28
07ff556
2c48b54
ead6f2c
4d2a540
5431d20
8503881
e292749
6982054
58c83f5
04bd242
80f722c
8412e78
97964fd
d0d57b3
7c08711
770e6b3
3789fbd
201e362
5095704
3129dfa
07b976c
37476b6
4529d52
962b4b8
d2de085
b0858a5
b5aa8a7
b92dd48
c2bb92c
950c00b
a0a87ed
f4674d2
a2244b6
b75d97d
08bf9a2
c8bfbb1
d220da0
6d743b5
bcb86c3
53057bf
05f600e
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 |
---|---|---|
|
@@ -46,6 +46,9 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn | |
using GetLeafCallback = std::function<void(const TypedResponse<GetLeafResponse>&)>; | ||
using CommitCallback = std::function<void(const Response&)>; | ||
using RollbackCallback = std::function<void(const Response&)>; | ||
using RemoveHistoricBlockCallback = std::function<void(const Response&)>; | ||
using UnwindBlockCallback = std::function<void(const Response&)>; | ||
using FinaliseBlockCallback = std::function<void(const Response&)>; | ||
|
||
// Only construct from provided store and thread pool, no copies or moves | ||
ContentAddressedAppendOnlyTree(std::unique_ptr<Store> store, | ||
|
@@ -167,15 +170,15 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn | |
* @brief Returns the index of the provided leaf in the tree only if it exists after the index value provided | ||
*/ | ||
void find_leaf_index_from(const fr& leaf, | ||
index_t start_index, | ||
const index_t& start_index, | ||
bool includeUncommitted, | ||
const FindLeafCallback& on_completion) const; | ||
|
||
/** | ||
* @brief Returns the index of the provided leaf in the tree only if it exists after the index value provided | ||
*/ | ||
void find_leaf_index_from(const fr& leaf, | ||
index_t start_index, | ||
const index_t& start_index, | ||
const index_t& blockNumber, | ||
bool includeUncommitted, | ||
const FindLeafCallback& on_completion) const; | ||
|
@@ -195,6 +198,12 @@ template <typename Store, typename HashingPolicy> class ContentAddressedAppendOn | |
*/ | ||
uint32_t depth() const { return depth_; } | ||
|
||
void remove_historic_block(const index_t& blockNumber, const RemoveHistoricBlockCallback& on_completion); | ||
|
||
void unwind_block(const index_t& blockNumber, const UnwindBlockCallback& on_completion); | ||
|
||
void finalise_block(const index_t& blockNumber, const FinaliseBlockCallback& on_completion); | ||
|
||
protected: | ||
using ReadTransaction = typename Store::ReadTransaction; | ||
using ReadTransactionPtr = typename Store::ReadTransactionPtr; | ||
|
@@ -355,6 +364,9 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_sibling_path(cons | |
auto job = [=, this]() { | ||
execute_and_report<GetSiblingPathResponse>( | ||
[=, this](TypedResponse<GetSiblingPathResponse>& response) { | ||
if (blockNumber == 0) { | ||
throw std::runtime_error("Invalid block number"); | ||
} | ||
ReadTransactionPtr tx = store_->create_read_transaction(); | ||
BlockPayload blockData; | ||
if (!store_->get_block_data(blockNumber, blockData, *tx)) { | ||
|
@@ -409,6 +421,7 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_subtree_sibling_p | |
RequestContext requestContext; | ||
requestContext.includeUncommitted = includeUncommitted; | ||
requestContext.root = store_->get_current_root(*tx, includeUncommitted); | ||
// std::cout << "Current root: " << requestContext.root << std::endl; | ||
OptionalSiblingPath optional_path = | ||
get_subtree_sibling_path_internal(leaf_index, subtree_depth, requestContext, *tx); | ||
response.inner.path = optional_sibling_path_to_full_sibling_path(optional_path); | ||
|
@@ -467,7 +480,7 @@ std::optional<fr> ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_lea | |
// std::cout << "No child" << std::endl; | ||
return std::nullopt; | ||
} | ||
// std::cout << "Found child" << std::endl; | ||
// std::cout << "Found child " << child.value() << std::endl; | ||
|
||
hash = child.value(); | ||
|
||
|
@@ -572,6 +585,9 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_leaf(const index_ | |
auto job = [=, this]() { | ||
execute_and_report<GetLeafResponse>( | ||
[=, this](TypedResponse<GetLeafResponse>& response) { | ||
if (blockNumber == 0) { | ||
throw std::runtime_error("Invalid block number"); | ||
} | ||
ReadTransactionPtr tx = store_->create_read_transaction(); | ||
BlockPayload blockData; | ||
if (!store_->get_block_data(blockNumber, blockData, *tx)) { | ||
|
@@ -616,12 +632,12 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index(const | |
|
||
template <typename Store, typename HashingPolicy> | ||
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index_from( | ||
const fr& leaf, index_t start_index, bool includeUncommitted, const FindLeafCallback& on_completion) const | ||
const fr& leaf, const index_t& start_index, bool includeUncommitted, const FindLeafCallback& on_completion) const | ||
{ | ||
auto job = [=, this]() -> void { | ||
execute_and_report<FindLeafIndexResponse>( | ||
[=, this](TypedResponse<FindLeafIndexResponse>& response) { | ||
typename Store::ReadTransactionPtr tx = store_->create_read_transaction(); | ||
ReadTransactionPtr tx = store_->create_read_transaction(); | ||
RequestContext requestContext; | ||
requestContext.includeUncommitted = includeUncommitted; | ||
requestContext.root = store_->get_current_root(*tx, includeUncommitted); | ||
|
@@ -640,15 +656,18 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index_from( | |
template <typename Store, typename HashingPolicy> | ||
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::find_leaf_index_from( | ||
const fr& leaf, | ||
index_t start_index, | ||
const index_t& start_index, | ||
const index_t& blockNumber, | ||
bool includeUncommitted, | ||
const FindLeafCallback& on_completion) const | ||
{ | ||
auto job = [=, this]() -> void { | ||
execute_and_report<FindLeafIndexResponse>( | ||
[=, this](TypedResponse<FindLeafIndexResponse>& response) { | ||
typename Store::ReadTransactionPtr tx = store_->create_read_transaction(); | ||
if (blockNumber == 0) { | ||
throw std::runtime_error("Invalid block number"); | ||
} | ||
ReadTransactionPtr tx = store_->create_read_transaction(); | ||
BlockPayload blockData; | ||
if (!store_->get_block_data(blockNumber, blockData, *tx)) { | ||
throw std::runtime_error("Data for block unavailable"); | ||
|
@@ -712,6 +731,57 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::rollback(const Rollba | |
workers_->enqueue(job); | ||
} | ||
|
||
template <typename Store, typename HashingPolicy> | ||
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::remove_historic_block( | ||
const index_t& blockNumber, const RemoveHistoricBlockCallback& on_completion) | ||
{ | ||
auto job = [=, this]() { | ||
execute_and_report( | ||
[=, this]() { | ||
if (blockNumber == 0) { | ||
throw std::runtime_error("Invalid block number"); | ||
} | ||
store_->remove_historical_block(blockNumber); | ||
}, | ||
on_completion); | ||
}; | ||
workers_->enqueue(job); | ||
} | ||
|
||
template <typename Store, typename HashingPolicy> | ||
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::unwind_block( | ||
const index_t& blockNumber, const RemoveHistoricBlockCallback& on_completion) | ||
{ | ||
auto job = [=, this]() { | ||
execute_and_report( | ||
[=, this]() { | ||
if (blockNumber == 0) { | ||
throw std::runtime_error("Invalid block number"); | ||
} | ||
Comment on lines
+758
to
+760
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. Does this mean we cannot unwind to genesis, which means initial epoch cannot be unwound? 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. Also, should we check we are not accidentally removing the finalised block, both here and when removing historical? (maybe it's checked somewhere else) 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, the api here is 'off by one' compared to TS. So unwinding block 1 leaves you at block 0. 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. Will protect against removing the current finalised block in either direction. |
||
store_->unwind_block(blockNumber); | ||
}, | ||
on_completion); | ||
}; | ||
workers_->enqueue(job); | ||
} | ||
|
||
template <typename Store, typename HashingPolicy> | ||
void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::finalise_block(const index_t& blockNumber, | ||
const FinaliseBlockCallback& on_completion) | ||
{ | ||
auto job = [=, this]() { | ||
execute_and_report( | ||
[=, this]() { | ||
if (blockNumber == 0) { | ||
throw std::runtime_error("Invalid block number"); | ||
} | ||
store_->advance_finalised_block(blockNumber); | ||
}, | ||
on_completion); | ||
}; | ||
workers_->enqueue(job); | ||
} | ||
|
||
template <typename Store, typename HashingPolicy> | ||
index_t ContentAddressedAppendOnlyTree<Store, HashingPolicy>::get_batch_insertion_size(index_t treeSize, | ||
index_t remainingAppendSize) | ||
|
@@ -738,7 +808,7 @@ void ContentAddressedAppendOnlyTree<Store, HashingPolicy>::add_values_internal(s | |
index_t& new_size, | ||
bool update_index) | ||
{ | ||
typename Store::ReadTransactionPtr tx = store_->create_read_transaction(); | ||
ReadTransactionPtr tx = store_->create_read_transaction(); | ||
TreeMeta meta; | ||
store_->get_meta(meta, *tx, true); | ||
index_t sizeToAppend = values->size(); | ||
|
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.
Don't we ever request the sibling path for the genesis block (0) on the archive tree? Seems not, since this is not blowing up, but I'd've expected to be possible to fetch it?
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.
I don't believe so.