Skip to content
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

1545 state locking final - dont review yet #2024

Draft
wants to merge 291 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
291 commits
Select commit Hold shift + click to select a range
43bc3d8
#1545 state locking
kladkogex Jul 17, 2024
55687aa
#1545 state locking
kladkogex Jul 17, 2024
9252264
#1545 state locking
kladkogex Jul 17, 2024
9ec0cfa
#1545 state locking
kladkogex Jul 17, 2024
1c6ab4f
#1545 state locking
kladkogex Jul 17, 2024
2d40ed9
#1545 state locking
kladkogex Jul 17, 2024
f4e3901
1545 improved locking for preseal
kladkogex Jul 18, 2024
bcd42f0
1545 improved locking for preseal
kladkogex Jul 18, 2024
b4b439b
1545 improved locking for preseal
kladkogex Jul 18, 2024
bd24efa
1545 improved locking for preseal
kladkogex Jul 19, 2024
dd7bbe2
1545 improved locking for preseal
kladkogex Jul 19, 2024
2544716
1545 improved locking for preseal
kladkogex Jul 19, 2024
7d0ff2a
1545 improved locking for preseal
kladkogex Jul 19, 2024
c6a4e37
1545 improved locking for preseal
kladkogex Jul 19, 2024
02aa2f8
1545 improved locking for preseal
kladkogex Jul 19, 2024
ffba8e8
1545 improved locking for preseal
kladkogex Jul 19, 2024
5574a0a
1545 improved locking for preseal
kladkogex Jul 19, 2024
3b605e0
1545 improved locking for preseal
kladkogex Jul 19, 2024
7a9bd1d
1545 improved locking for preseal
kladkogex Jul 19, 2024
45ca874
1545 improved locking for preseal
kladkogex Jul 19, 2024
03d5f07
#1545 state locking
kladkogex Jul 22, 2024
6e5b77b
#1545 state locking
kladkogex Jul 22, 2024
f569004
#1545 state locking
kladkogex Jul 22, 2024
a6538f6
#1545 state locking
kladkogex Jul 22, 2024
d729d01
#1545 state locking
kladkogex Jul 22, 2024
fcf950d
#1545 state locking
kladkogex Jul 22, 2024
cb53e1d
#1545 state locking
kladkogex Jul 22, 2024
42c43e5
#1545 state locking
kladkogex Jul 22, 2024
1115682
#1545 state locking
kladkogex Jul 23, 2024
9c2ea64
#1545 state locking
kladkogex Jul 23, 2024
3ded249
1545 add exception
kladkogex Jul 29, 2024
d1abaa0
1545 add exception
kladkogex Jul 30, 2024
149f4f2
1545 add exception
kladkogex Jul 30, 2024
798b909
1545 add exception
kladkogex Jul 30, 2024
b899b78
1545 add exception
kladkogex Jul 30, 2024
f1e8a6a
1545 fix test
kladkogex Jul 31, 2024
d926a03
1545 fix formatiing
kladkogex Jul 31, 2024
ce283d5
1545 fix formatiing
kladkogex Jul 31, 2024
a1e6282
1545 fix formatiing
kladkogex Jul 31, 2024
9766ddd
1545 fix formatiing
kladkogex Jul 31, 2024
3dcc3b0
1545 fix formatiing
kladkogex Jul 31, 2024
6afc927
1545 fix formatiing
kladkogex Jul 31, 2024
a8dad3a
1545 fix formatiing
kladkogex Aug 1, 2024
3025f31
1545 fix formatiing
kladkogex Aug 1, 2024
f19f5a0
1545 fix formatiing
kladkogex Aug 1, 2024
0e13adb
1545 adding perf test
kladkogex Aug 2, 2024
2f8390b
1545 adding perf test
kladkogex Aug 2, 2024
3d1c761
1545 adding perf test
kladkogex Aug 2, 2024
88a5f0c
1545 adding perf test
kladkogex Aug 3, 2024
5338ba1
1545 adding perf test
kladkogex Aug 3, 2024
0a6f85e
1545 adding perf test
kladkogex Aug 3, 2024
20ff651
1545 adding perf test
kladkogex Aug 3, 2024
cc136cf
1545 adding perf test
kladkogex Aug 3, 2024
43e20a5
1545 adding perf test
kladkogex Aug 3, 2024
c51d958
1545 adding perf test
kladkogex Aug 3, 2024
2c2bbbc
1545 adding perf test
kladkogex Aug 3, 2024
8f846cf
1545 adding perf test
kladkogex Aug 3, 2024
fe2ae46
1545 adding perf test
kladkogex Aug 3, 2024
4be3027
1545 adding perf test
kladkogex Aug 3, 2024
0ec0d38
1545 adding perf test
kladkogex Aug 3, 2024
1b860ca
1545 adding perf test
kladkogex Aug 3, 2024
87aa5e1
1545 adding perf test
kladkogex Aug 3, 2024
fd2f564
1545 adding perf test
kladkogex Aug 3, 2024
ce6ff71
1545 adding perf test
kladkogex Aug 3, 2024
8cfc47f
1545 adding perf test
kladkogex Aug 3, 2024
4692c29
1545 adding perf test
kladkogex Aug 3, 2024
4b4c3e0
1545 Fox cmake
kladkogex Aug 4, 2024
94885ee
1545 Fox cmake
kladkogex Aug 4, 2024
b53f013
1545 Fox cmake
kladkogex Aug 4, 2024
38f64f1
1545 Fox cmake
kladkogex Aug 4, 2024
afa9946
1545 Fox cmake
kladkogex Aug 4, 2024
398a057
1545 Test get balance
kladkogex Aug 4, 2024
152079f
1545 adding raw transaction
kladkogex Aug 5, 2024
4a89bd7
1545 adding raw transaction
kladkogex Aug 5, 2024
8fd1caa
1545 adding raw transaction
kladkogex Aug 5, 2024
2866d3f
1545 adding raw transaction
kladkogex Aug 5, 2024
3d08afd
1545 adding raw transaction
kladkogex Aug 5, 2024
fe8dd7d
1545 removed perf trackr
kladkogex Aug 5, 2024
42f5e8c
1545 removed perf trackr
kladkogex Aug 5, 2024
2e5be99
1545 Skaled config
kladkogex Aug 5, 2024
d1ce088
1545 removed perf trackr
kladkogex Aug 6, 2024
ed99c42
1545 removed perf trackr
kladkogex Aug 6, 2024
60b3244
1545 and account split
kladkogex Aug 6, 2024
af18d0f
1545 and account split
kladkogex Aug 6, 2024
e7a9942
1545 and account split
kladkogex Aug 6, 2024
6bdba6b
1545 and account split
kladkogex Aug 6, 2024
2f30af2
1545 and account split
kladkogex Aug 6, 2024
3851b3b
1545 and account split
kladkogex Aug 6, 2024
d03e8e5
1545 and account split
kladkogex Aug 6, 2024
ee6df1c
1545 and account split
kladkogex Aug 6, 2024
6c5d640
1545 and account split
kladkogex Aug 6, 2024
8f82fd7
1545 and account split
kladkogex Aug 6, 2024
fa35f0a
1545 and account split
kladkogex Aug 6, 2024
9937fe3
1545 and account split
kladkogex Aug 6, 2024
468de19
1545 and account split
kladkogex Aug 6, 2024
7f439f8
1545 and account split
kladkogex Aug 7, 2024
ea7be10
1545 and account split
kladkogex Aug 7, 2024
f93300d
1545 and account split
kladkogex Aug 7, 2024
4b98b1e
1545 and account split
kladkogex Aug 7, 2024
faedb7a
1545 Refactoring libcurl
kladkogex Aug 8, 2024
071ec0e
1545 Refactoring libcurl
kladkogex Aug 8, 2024
5c40e69
1545 Refactoring libcurl
kladkogex Aug 8, 2024
24c8e8d
1545 Refactoring libcurl
kladkogex Aug 8, 2024
448f8b9
1545 Refactoring libcurl
kladkogex Aug 8, 2024
91ec85a
1545 Refactoring libcurl
kladkogex Aug 8, 2024
05898d8
1545 Refactoring libcurl
kladkogex Aug 9, 2024
2ca6f70
1545 Refactoring libcurl
kladkogex Aug 9, 2024
27ab89c
1545 Optimizing TransactionQueue.cpp
kladkogex Aug 9, 2024
11968ad
1545 Optimizing TransactionQueue.cpp
kladkogex Aug 9, 2024
11ff7d3
1545 Optimizing test
kladkogex Aug 10, 2024
2da839b
1545 Optimizing test
kladkogex Aug 10, 2024
294ffda
1545 Optimizing test
kladkogex Aug 10, 2024
ca75e87
1545 Optimizing test
kladkogex Aug 10, 2024
6fb81a7
1545 Optimizing test
kladkogex Aug 10, 2024
27ddb7d
1545 Optimizing test
kladkogex Aug 11, 2024
7aa3339
1545 Optimizing test
kladkogex Aug 11, 2024
97837fa
1545 Optimizing test
kladkogex Aug 11, 2024
a22b7d7
1545 Optimizing test
kladkogex Aug 11, 2024
1e7a1fe
1545 Optimizing test
kladkogex Aug 11, 2024
49f55f3
1545 Optimizing test
kladkogex Aug 11, 2024
a8dcb2a
1545 Optimizing test
kladkogex Aug 11, 2024
3644139
1545 Optimizing test
kladkogex Aug 11, 2024
3630a7b
1545 and account split
kladkogex Aug 12, 2024
2743cc2
1545 and account split
kladkogex Aug 12, 2024
9a8083b
1545 improve test performance
kladkogex Aug 13, 2024
4ed9afc
1545 improve test performance
kladkogex Aug 13, 2024
daf39dd
1545 improve test performance
kladkogex Aug 13, 2024
eb7fd23
1545 improve test performance
kladkogex Aug 13, 2024
c2c67eb
1545 improve test performance
kladkogex Aug 13, 2024
58b9882
1545 improve test performance
kladkogex Aug 13, 2024
1c94524
1545 improve performance
kladkogex Aug 13, 2024
fa471eb
1545 Adding performance tests
kladkogex Aug 13, 2024
30b54d2
1545 Improve locking
kladkogex Aug 13, 2024
c6f23a5
1545 improve test performance
kladkogex Aug 13, 2024
fb5a59b
1545 Improve locks
kladkogex Aug 13, 2024
0ed1850
1545 state locking
kladkogex Aug 29, 2024
4ecc300
1545 Fixing partial transactions
kladkogex Aug 29, 2024
0fc5a30
1545_state_locking Fixing partial transaction receipts
kladkogex Aug 29, 2024
9e78536
1545 partial catchup
kladkogex Sep 4, 2024
91d37da
1545 state locking
kladkogex Sep 5, 2024
9ff801e
1545 Add ERC-20
kladkogex Sep 9, 2024
ada6e57
1545_state_locking adding ERC-20 test
kladkogex Sep 9, 2024
75ef6fa
1545 state locking
kladkogex Sep 9, 2024
07c9cd5
1545 State locking fix timestamp
kladkogex Sep 10, 2024
6a5b5f1
1545 State locking add contract deploy
kladkogex Sep 10, 2024
84bd8bb
1545 State locking add contract deploy
kladkogex Sep 10, 2024
ea69dc4
1545 State locking add contract deploy
kladkogex Sep 11, 2024
c359023
1545 State locking add contract deploy
kladkogex Sep 11, 2024
fcdbd30
1545 State locking add contract deploy
kladkogex Sep 11, 2024
9ddd3ea
1545 State locking add contract deploy
kladkogex Sep 11, 2024
05a234e
1545 State locking add contract deploy
kladkogex Sep 11, 2024
4bd0f2f
1545 State locking add contract deploy
kladkogex Sep 11, 2024
1a4ab58
1545 State locking add contract deploy
kladkogex Sep 12, 2024
f2068a9
Merge branch 'develop' into 1545_state_locking_final
kladkogex Sep 12, 2024
5d8f1f4
1545 Added clang format ignore
kladkogex Sep 12, 2024
6cfcb40
1545 clang format
kladkogex Sep 12, 2024
7fd4900
1545 add clang format ignore
kladkogex Sep 12, 2024
5ebb3ab
1545 add ignore
kladkogex Sep 12, 2024
b8f712f
1545 ignore
kladkogex Sep 12, 2024
4fa20ea
1545 clang-format ignore
kladkogex Sep 12, 2024
a39ab1e
1545 git ignore
kladkogex Sep 12, 2024
277dc9e
1545 fix formatting
kladkogex Sep 12, 2024
b6cc143
1545 fix formatting
kladkogex Sep 12, 2024
5504949
1545 fix formatting
kladkogex Sep 12, 2024
ccdf163
1545 fix formatting
kladkogex Sep 12, 2024
432d4a9
1545 clang format
kladkogex Sep 12, 2024
3ae7286
1545 fix clang-format
kladkogex Sep 12, 2024
8ee156a
1545 clang-format
kladkogex Sep 12, 2024
e8c87f4
1545 fix clang format
kladkogex Sep 12, 2024
41f199d
1545 fix format
kladkogex Sep 12, 2024
470a0cb
1545 fix formatting
kladkogex Sep 12, 2024
5744159
1545 fix formatting
kladkogex Sep 12, 2024
f676bf6
1545 fixed tests and merge
kladkogex Sep 12, 2024
f8b55d8
1545 send erc-20
kladkogex Sep 12, 2024
039b9ed
1545 do erc-20 transfers
kladkogex Sep 12, 2024
c9d1701
1545 ERC-20 tests
kladkogex Sep 12, 2024
f2f04c2
1545 Add ERC-20 test
kladkogex Sep 12, 2024
d761535
1545 remove transaction cache
kladkogex Sep 12, 2024
d4cd772
1545 State locking add contract deploy
kladkogex Sep 12, 2024
79d6ea7
1545 Fixing transaction receipt
kladkogex Sep 12, 2024
6ab597b
1545 Fix partial receipt read/write
kladkogex Sep 23, 2024
97df8c8
1545 Added Type 1 tests
kladkogex Sep 23, 2024
f610b3a
1545 Added type2 test
kladkogex Sep 23, 2024
bbd92e3
1545 Added PoW test for a single node
kladkogex Sep 24, 2024
7f60a1a
1545 state locking
kladkogex Sep 24, 2024
580e6fe
1545 Make error message identical to geth
kladkogex Sep 25, 2024
08d9499
1545 Add MTM mode test
kladkogex Sep 25, 2024
e9211d3
1545 added multi-transaction-mode test
kladkogex Sep 25, 2024
193e9b7
1545 adding multi node tests
kladkogex Sep 26, 2024
bf3cb92
1545 adding 4 node files
kladkogex Sep 26, 2024
68087b5
1545 added 16 node tests
kladkogex Sep 30, 2024
a840871
1545 Add 16 node tests
kladkogex Sep 30, 2024
27d3235
1545 Add 16 node tests
kladkogex Sep 30, 2024
e3ccd55
1545 Remove categories
kladkogex Sep 30, 2024
8b13aad
1545 Remove categories
kladkogex Sep 30, 2024
97ff591
1545 Increase HighWaterMark so tests pass
kladkogex Sep 30, 2024
2d92636
1545 Increase HighWaterMark so tests pass
kladkogex Sep 30, 2024
46fc534
1545 Limit queue size
kladkogex Oct 7, 2024
29bcaff
1545 Limit queue size
kladkogex Oct 7, 2024
31679c3
1545 Fixing stats
kladkogex Oct 7, 2024
5785cad
1545 Fixing stats
kladkogex Oct 7, 2024
c27a0d5
1545 Fixing stats
kladkogex Oct 7, 2024
af4e217
1545 Fixing stats
kladkogex Oct 7, 2024
6aec22b
1545 Fixing stats
kladkogex Oct 7, 2024
419df8a
1545 Fixing stats
kladkogex Oct 7, 2024
ab72ba7
1545 Fixing stats
kladkogex Oct 7, 2024
3f8920e
1545 Fixing stats
kladkogex Oct 7, 2024
4136203
1545 Fixing stats
kladkogex Oct 7, 2024
5bbc5e6
1545 Fixing stats
kladkogex Oct 7, 2024
a04a264
1545 Fixing stats
kladkogex Oct 8, 2024
6409416
1545 Fixing stats
kladkogex Oct 8, 2024
3ee3b48
1545 Fixing stats
kladkogex Oct 9, 2024
d14d59a
1545 Fixing stats
kladkogex Oct 9, 2024
8e87e73
1545 fix clan-format
kladkogex Oct 9, 2024
e507c50
1545 clang-format
kladkogex Oct 9, 2024
41599b2
1545 Clang-format
kladkogex Oct 9, 2024
9d0abc2
1545 Clang-format
kladkogex Oct 9, 2024
865ca5f
Merge branch 'v3.20.0' into 1545_state_locking_final
kladkogex Oct 11, 2024
395c3f4
1545 merge with 3.20
kladkogex Oct 11, 2024
e997209
1545 merge with 3.20
kladkogex Oct 11, 2024
8ddc49c
1545 fix tests
kladkogex Oct 13, 2024
c744f90
1545 fix tests
kladkogex Oct 13, 2024
9ed27f5
1545 Fixing tests
kladkogex Oct 14, 2024
c9a2698
1545 Fixing tests
kladkogex Oct 14, 2024
77bcbe3
1545 Fixing tests
kladkogex Oct 14, 2024
f689751
1545 Fixing tests
kladkogex Oct 14, 2024
b8e9bbb
1545 Fixing tests
kladkogex Oct 15, 2024
fa6ca9a
1545 Fixing tests
kladkogex Nov 5, 2024
f99e3a2
1545 Fixing tests
kladkogex Nov 5, 2024
111eaed
1545 Fixing tests
kladkogex Nov 6, 2024
4b052a6
1545 fix tests
kladkogex Nov 7, 2024
bab09db
1545 Fixing tests
kladkogex Nov 13, 2024
858d770
1545 Fixing tests
kladkogex Nov 13, 2024
d6f5f74
1545 Fixing tests
kladkogex Nov 13, 2024
5bab9c6
1545 Fixing tests
kladkogex Nov 13, 2024
7b0afc7
1545 Fixing tests
kladkogex Nov 13, 2024
fe236ae
1545 Fixing tests
kladkogex Nov 13, 2024
a08d439
1545 Fixing tests
kladkogex Nov 19, 2024
6b9aad6
1545 Fixing tests
kladkogex Nov 19, 2024
3bc2048
1545 Fixing tests
kladkogex Nov 19, 2024
32c6e6c
1545 Fixing tests
kladkogex Nov 19, 2024
d938467
1545 Fixing tests
kladkogex Nov 19, 2024
929e680
1545 Fixing tests
kladkogex Nov 19, 2024
59eb445
1545 Fixing tests
kladkogex Nov 19, 2024
db7817f
1545 Fixing tests
kladkogex Nov 19, 2024
253edec
1545 Fixing tests
kladkogex Nov 20, 2024
c6bd1bb
1545 Fixing tests
kladkogex Nov 20, 2024
b93c3db
1545 Fixing tests
kladkogex Nov 20, 2024
ac34631
1545 Fixing tests
kladkogex Nov 20, 2024
578f06a
SKALED-1545 Formatting
dimalit Nov 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
./test/tools/libtesteth/*
./test/tools/fuzzTesting/*
./test/tools/libtestutils/*
./test/tools/jsontests/*
./test/unittests/external-dependencies/*
./test/unittests/libskutils/*
./test/unittests/libdevcrypto/*
./test/unittests/libethcore/*
./test/unittests/libethereum/*
./test/unittests/libweb3core/*
./test/unittests/libweb3jsonrpc/*
./test/unittests/libtesteth/*
./test/unittests/libdevcore/*
./test/unittests/libethashseal/*
./test/unittests/mapreduce_consensus/*
./test/unittests/libevm/*
./test/unittests/libskale/*
./storage_benchmark/*
./skale-vm/*
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ The SKALE network supports an unlimited number of independent blockchains with z

## Forklessness

Skaled is forkless, meaning that blockchain a linear chain (and not a tree of forks as with ETH 1.0). Every block is provably finalized within finite time.
Skaled is forkless, meaning that blockchain a linear chain (and not a tree of forks as with ETH 1.0). Every block is provably finalized immediately after creation.
Therefore, finalization time for skaled is equal to block time, which is
much faster than 13 minutes for Eth main net.


## Asynchronous block production
Expand Down
5 changes: 0 additions & 5 deletions libbatched-io/batched_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ namespace batched_io {

using namespace dev::db;

batched_db::~batched_db() {
// all batches should be either commit()'ted or revert()'ed!
assert( !m_batch );
}

db_operations_face* db_splitter::new_interface() {
assert( this->m_interfaces.size() < 256 );

Expand Down
86 changes: 75 additions & 11 deletions libbatched-io/batched_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "batched_io.h"

#include <libdevcore/DBImpl.h>
#include <libdevcore/LevelDB.h>

#include <shared_mutex>
Expand Down Expand Up @@ -39,50 +40,113 @@ class batched_db : public db_face {
public:
void open( std::shared_ptr< dev::db::DatabaseFace > _db ) { m_db = _db; }
bool is_open() const { return !!m_db; }
void insert( dev::db::Slice _key, dev::db::Slice _value ) {
void insert( dev::db::Slice _key, dev::db::Slice _value ) override {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
ensure_batch();
m_batch->insert( _key, _value );
}
void kill( dev::db::Slice _key ) {
void kill( dev::db::Slice _key ) override {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
ensure_batch();
m_batch->kill( _key );
}
virtual void revert() {
void revert() override {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
if ( m_batch )
m_batch.reset();
m_db->discardCreatedBatches();
}
virtual void commit( const std::string& test_crash_string = std::string() ) {
void commit( const std::string& test_crash_string = std::string() ) override {
std::lock_guard< std::mutex > batch_lock( m_batch_mutex );
ensure_batch();
test_crash_before_commit( test_crash_string );
m_db->commit( std::move( m_batch ) );
}

// readonly
virtual std::string lookup( dev::db::Slice _key ) const { return m_db->lookup( _key ); }
virtual bool exists( dev::db::Slice _key ) const { return m_db->exists( _key ); }
virtual void forEach( std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const {
std::string lookup( dev::db::Slice _key ) const override { return m_db->lookup( _key ); }

bool exists( dev::db::Slice _key ) const override { return m_db->exists( _key ); }

void forEach( std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const override {
std::lock_guard< std::mutex > foreach_lock( m_batch_mutex );
m_db->forEach( f );
}

virtual void forEachWithPrefix(
std::string& _prefix, std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const {
void forEachWithPrefix( std::string& _prefix,
std::function< bool( dev::db::Slice, dev::db::Slice ) > f ) const override {
std::lock_guard< std::mutex > foreach_lock( m_batch_mutex );
m_db->forEachWithPrefix( _prefix, f );
}

virtual ~batched_db();
~batched_db() override {
// all batches should be either commit()'ted or revert()'ed!
assert( !m_batch );
}

protected:
void recover() { /*nothing*/
void recover() override { /*nothing*/
}
};


class read_only_snap_based_batched_db : public db_face {
private:
std::shared_ptr< dev::db::DBImpl > m_db;
std::shared_ptr< dev::db::LevelDBSnap > m_snap;

public:
read_only_snap_based_batched_db(
std::shared_ptr< dev::db::DBImpl > _db, std::shared_ptr< dev::db::LevelDBSnap > _snap ) {
LDB_CHECK( _db );
LDB_CHECK( _snap );
m_db = _db;
m_snap = _snap;
}

bool is_open() const { return !!m_db; };

void insert( dev::db::Slice, dev::db::Slice ) override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

void kill( dev::db::Slice ) override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

void revert() override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

void commit( const std::string& ) override {
throw std::runtime_error( "Function not implemented:" + std::string( __FUNCTION__ ) );
}

// readonly
std::string lookup( dev::db::Slice _key ) const override {
return m_db->lookup( _key, m_snap );
}

bool exists( dev::db::Slice _key ) const override { return m_db->exists( _key, m_snap ); }

void forEach( std::function< bool( dev::db::Slice, dev::db::Slice ) > _f ) const override {
static std::string emptyString;
return forEachWithPrefix( emptyString, _f );
}

void forEachWithPrefix( std::string& _prefix,
std::function< bool( dev::db::Slice, dev::db::Slice ) > _f ) const override {
m_db->forEachWithPrefix( _prefix, _f, m_snap );
}

virtual ~read_only_snap_based_batched_db() = default;

protected:
void recover() override { /*nothing*/
}
};


class db_splitter {
private:
std::shared_ptr< db_face > m_backend;
Expand Down
2 changes: 1 addition & 1 deletion libconsensus
Submodule libconsensus updated 0 files
106 changes: 78 additions & 28 deletions libdevcore/LevelDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "LevelDB.h"
#include "Assertions.h"
#include "LevelDBSnap.h"
#include "Log.h"
#include <libdevcore/microprofile.h>

Expand All @@ -29,8 +30,6 @@ namespace dev::db {

unsigned c_maxOpenLeveldbFiles = 25;

const size_t LevelDB::BATCH_CHUNK_SIZE = 10000;

namespace {
inline leveldb::Slice toLDBSlice( Slice _slice ) {
return leveldb::Slice( _slice.data(), _slice.size() );
Expand Down Expand Up @@ -144,6 +143,7 @@ void LevelDB::openDBInstanceUnsafe() {

m_db.reset( db );
m_lastDBOpenTimeMs = getCurrentTimeMs();
m_dbReopenId++;
cnote << "LEVELDB_OPENED:TIME_MS:" << m_lastDBOpenTimeMs - startTimeMs;
}
uint64_t LevelDB::getCurrentTimeMs() {
Expand All @@ -159,14 +159,15 @@ LevelDB::~LevelDB() {
}

std::string LevelDB::lookup( Slice _key ) const {
return lookup( _key, nullptr );
}

std::string LevelDB::lookup( Slice _key, const std::shared_ptr< LevelDBSnap >& _snap ) const {
leveldb::Slice const key( _key.data(), _key.size() );
std::string value;

leveldb::Status status;
{
SharedDBGuard readLock( *this );
status = m_db->Get( m_readOptions, key, &value );
}
auto status = getValue( m_readOptions, key, value, _snap );

if ( status.IsNotFound() )
return std::string();

Expand All @@ -175,26 +176,41 @@ std::string LevelDB::lookup( Slice _key ) const {
}

bool LevelDB::exists( Slice _key ) const {
return exists( _key, nullptr );
}

bool LevelDB::exists( Slice _key, const std::shared_ptr< LevelDBSnap >& _snap ) const {
std::string value;
leveldb::Slice const key( _key.data(), _key.size() );
leveldb::Status status;
{
SharedDBGuard lock( *this );
status = m_db->Get( m_readOptions, key, &value );
}

auto status = getValue( m_readOptions, key, value, _snap );

if ( status.IsNotFound() )
return false;

checkStatus( status );
return true;
}

leveldb::Status LevelDB::getValue( leveldb::ReadOptions _readOptions, const leveldb::Slice& _key,
std::string& _value, const std::shared_ptr< LevelDBSnap >& _snap ) const {
SharedDBGuard lock( *this ); // protect so db is not reopened during get call
if ( _snap ) {
// sanity check to make sure that the snap was created for this particular
// db handle
LDB_CHECK( m_dbReopenId == _snap->getParentDbReopenId() );
return _snap->getValue( m_db, _readOptions, _key, _value );
} else {
return m_db->Get( _readOptions, _key, &_value );
}
}

void LevelDB::insert( Slice _key, Slice _value ) {
leveldb::Slice const key( _key.data(), _key.size() );
leveldb::Slice const value( _value.data(), _value.size() );
leveldb::Status status;
{
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during Put() call
status = m_db->Put( m_writeOptions, key, value );
}
checkStatus( status );
Expand Down Expand Up @@ -224,7 +240,7 @@ void LevelDB::commit( std::unique_ptr< WriteBatchFace > _batch ) {
}
leveldb::Status status;
{
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during Write() call
status = m_db->Write( m_writeOptions, &batchPtr->writeBatch() );
}
// Commit happened. This means the keys actually got deleted in LevelDB. Increment key deletes
Expand All @@ -247,17 +263,25 @@ void LevelDB::reopenDataBaseIfNeeded() {
auto currentTimeMs = getCurrentTimeMs();

if ( currentTimeMs - m_lastDBOpenTimeMs >= ( uint64_t ) m_reopenPeriodMs ) {
ExclusiveDBGuard lock( *this );
// releasing unique pointer will cause database destructor to be called that will close db
m_db.reset();
// now open db while holding the exclusive lock
openDBInstanceUnsafe();
reopen();
}
}
void LevelDB::reopen() {
ExclusiveDBGuard lock( *this );
// close all current snaps by passing max lifetime as zero
auto aliveSnaps = m_snapManager.garbageCollectUnusedOldSnaps( m_db, m_dbReopenId, 0 );
LDB_CHECK( aliveSnaps == 0 );

// releasing unique pointer will cause database destructor to be called that will close db
LDB_CHECK( m_db );
m_db.reset();
// now open db while holding the exclusive lock
openDBInstanceUnsafe();
}

void LevelDB::forEach( std::function< bool( Slice, Slice ) > f ) const {
cwarn << "Iterating over the entire LevelDB database: " << this->m_path;
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during iteration
std::unique_ptr< leveldb::Iterator > itr( m_db->NewIterator( m_readOptions ) );
if ( itr == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
Expand All @@ -273,10 +297,22 @@ void LevelDB::forEach( std::function< bool( Slice, Slice ) > f ) const {
}

void LevelDB::forEachWithPrefix(
std::string& _prefix, std::function< bool( Slice, Slice ) > f ) const {
cnote << "Iterating over the LevelDB prefix: " << _prefix;
SharedDBGuard lock( *this );
std::unique_ptr< leveldb::Iterator > itr( m_db->NewIterator( m_readOptions ) );
std::string& _prefix, std::function< bool( Slice, Slice ) > _f ) const {
forEachWithPrefix( _prefix, _f, nullptr );
}

void LevelDB::forEachWithPrefix( std::string& _prefix, std::function< bool( Slice, Slice ) > f,
const std::shared_ptr< LevelDBSnap >& _snap ) const {
SharedDBGuard lock( *this ); // protect so DB is not reopened during iteration

std::unique_ptr< leveldb::Iterator > itr;

if ( _snap ) {
LDB_CHECK( m_dbReopenId == _snap->getParentDbReopenId() );
itr = _snap->getIterator( m_db, m_readOptions );
} else {
itr.reset( m_db->NewIterator( m_readOptions ) );
}
if ( itr == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
}
Expand All @@ -293,7 +329,7 @@ void LevelDB::forEachWithPrefix(
}

h256 LevelDB::hashBase() const {
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during iteration
std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) );
if ( it == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
Expand Down Expand Up @@ -321,7 +357,7 @@ h256 LevelDB::hashBase() const {
}

h256 LevelDB::hashBaseWithPrefix( char _prefix ) const {
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during iteration
std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) );
if ( it == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
Expand All @@ -345,7 +381,7 @@ h256 LevelDB::hashBaseWithPrefix( char _prefix ) const {
}

bool LevelDB::hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashedKey ) const {
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during iteration
std::unique_ptr< leveldb::Iterator > it( m_db->NewIterator( m_readOptions ) );
if ( it == nullptr ) {
BOOST_THROW_EXCEPTION( DatabaseError() << errinfo_comment( "null iterator" ) );
Expand Down Expand Up @@ -379,15 +415,29 @@ bool LevelDB::hashBasePartially( secp256k1_sha256_t* ctx, std::string& lastHashe
}

void LevelDB::doCompaction() const {
SharedDBGuard lock( *this );
SharedDBGuard lock( *this ); // protect so db is not reopened during compaction
m_db->CompactRange( nullptr, nullptr );
}


void LevelDB::createBlockSnap( uint64_t _blockNumber ) {
SharedDBGuard lock( *this ); // protect so db is not reopened during snap creation
m_snapManager.addSnapForBlock( _blockNumber, m_db, m_dbReopenId );
}

std::shared_ptr< LevelDBSnap > LevelDB::getLastBlockSnap() const {
SharedDBGuard lock( *this ); // protect so db is not reopened when while we get snap
auto snap = m_snapManager.getLastBlockSnap();
LDB_CHECK( snap );
return snap;
}

std::atomic< uint64_t > LevelDB::g_keysToBeDeletedStats = 0;
std::atomic< uint64_t > LevelDB::g_keyDeletesStats = 0;

uint64_t LevelDB::getKeyDeletesStats() {
return g_keyDeletesStats;
}


} // namespace dev::db
Loading
Loading