Skip to content

Commit 5b5c284

Browse files
authored
Ledger chunking (#1274)
1 parent e1b405d commit 5b5c284

File tree

25 files changed

+1588
-306
lines changed

25 files changed

+1588
-306
lines changed

.azure-pipelines-templates/install.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ steps:
1717
-b ${{ parameters.install_prefix }}/bin \
1818
-g $(pwd)/../../src/runtime_config/gov.lua \
1919
-v
20-
cp ./workspace/start_network_0/0.ledger .
20+
cp -r ./workspace/start_network_0/0.ledger .
2121
cp ./workspace/start_network_0/network_enc_pubk.pem .
2222
timeout --signal=SIGINT --kill-after=30s --preserve-status 30s \
2323
python ${{ parameters.install_prefix }}/bin/start_network.py \
2424
-p ../../build/liblogging \
2525
-b ${{ parameters.install_prefix }}/bin \
2626
-v \
2727
--recover \
28-
--ledger 0.ledger \
28+
--ledger-dir 0.ledger \
2929
--network-enc-pubk network_enc_pubk.pem \
3030
--common-dir ./workspace/start_network_common/
3131
displayName: Test installed CCF

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ if(BUILD_TESTS)
313313
target_link_libraries(encryptor_test PRIVATE secp256k1.host)
314314

315315
add_unit_test(
316-
historical_queries_test ${CMAKE_CURRENT_SOURCE_DIR}/src/node/test/historical_queries.cpp
316+
historical_queries_test
317+
${CMAKE_CURRENT_SOURCE_DIR}/src/node/test/historical_queries.cpp
317318
)
318319
target_link_libraries(historical_queries_test PRIVATE secp256k1.host)
319320

@@ -461,9 +462,7 @@ if(BUILD_TESTS)
461462
kv_bench SRCS src/kv/test/kv_bench.cpp src/crypto/symmetric_key.cpp
462463
src/enclave/thread_local.cpp
463464
)
464-
add_picobench(
465-
hash_bench SRCS src/ds/test/hash_bench.cpp
466-
)
465+
add_picobench(hash_bench SRCS src/ds/test/hash_bench.cpp)
467466

468467
# Storing signed governance operations
469468
add_e2e_test(
@@ -483,6 +482,10 @@ if(BUILD_TESTS)
483482
# purpose to check that a recovery network is robust to a view change.
484483
--raft-election-timeout
485484
4000
485+
# Smaller ledger chunks than default to make sure that a ledger made of
486+
# multiple chunks can be recovered
487+
--ledger-chunk-max-bytes
488+
20KB
486489
)
487490

488491
add_e2e_test(

doc/developers/ledger.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Ledger
33

44
The ledger is the persistent distributed append-only record of the transactions that have been executed by the network. It is written by the primary when a transaction is committed and replicated to all backups which maintain their own duplicated copy.
55

6-
A node writes its ledger to a file as specified by the ``--ledger-file`` command line argument.
6+
A node writes its ledger to a directory as specified by the ``--ledger-dir`` command line argument.
77

88
Ledger Encryption
99
-----------------

doc/operators/recovery.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ To initiate the first phase of the recovery procedure, one or several nodes shou
2626
--rpc-address <ccf-node-address>
2727
--public-rpc-address <ccf-node-public-address>
2828
[--domain domain]
29-
--ledger-file /path/to/ledger/to/recover
29+
--ledger-dir /path/to/ledger/dir/to/recover
3030
--node-cert-file /path/to/node_certificate
3131
recover
3232
--network-cert-file /path/to/network_certificate
3333
34-
Each node will then immediately restore the public entries of its ledger (``--ledger-file``). Because deserialising the public entries present in the ledger may take some time, operators can query the progress of the public recovery by calling ``getSignedIndex`` which returns the version of the last signed recovered ledger entry. Once the public ledger is fully recovered, the recovered node automatically becomes part of the public network, allowing other nodes to join the network.
34+
Each node will then immediately restore the public entries of its ledger (``--ledger-dir``). Because deserialising the public entries present in the ledger may take some time, operators can query the progress of the public recovery by calling ``getSignedIndex`` which returns the version of the last signed recovered ledger entry. Once the public ledger is fully recovered, the recovered node automatically becomes part of the public network, allowing other nodes to join the network.
3535

3636
.. note:: If more than one node were started in ``recover`` mode, the node with the highest signed index (as per the response to the ``getSignedIndex`` RPC) should be preferred to start the new network. Other nodes should be shutdown and new nodes restarted with the ``join`` option.
3737

@@ -44,7 +44,7 @@ Similarly to the normal join protocol (see :ref:`operators/start_network:Adding
4444
participant Node 2
4545
participant Node 3
4646

47-
Operators->>+Node 2: cchost --rpc-address=ip2:port2 --ledger-file=ledger0 recover
47+
Operators->>+Node 2: cchost --rpc-address=ip2:port2 --ledger-dir=./ledger recover
4848
Node 2-->>Operators: Network Certificate
4949
Note over Node 2: Reading Public Ledger...
5050

doc/operators/start_network.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To create a new CCF network, the first node of the network should be invoked wit
1919
--node-address <ccf-node-to-node-address>
2020
--public-rpc-address <ccf-node-public-address>
2121
[--domain domain]
22-
--ledger-file /path/to/ledger
22+
--ledger-dir /path/to/ledger/dir
2323
--node-cert-file /path/to/node_certificate
2424
[--sig-max-tx number_of_transactions]
2525
[--sig-max-ms number_of_milliseconds]
@@ -81,7 +81,7 @@ To add a new node to an existing opening network, other nodes should be started
8181
--rpc-address <ccf-node-address>
8282
--node-address <ccf-node-to-node-address>
8383
--public-rpc-address <ccf-node-public-address>
84-
--ledger-file /path/to/ledger
84+
--ledger-dir /path/to/ledger/dir
8585
--node-cert-file /path/to/node_certificate
8686
join
8787
--network-cert-file /path/to/existing/network_certificate

doc/users/deploy_app.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ The ``start_test_network.sh`` script can also be used to automatically recover a
4141
.. code-block:: bash
4242
4343
$ cd CCF/build
44-
$ cp ./workspace/test_network_0/0.ledger .
44+
$ cp -r ./workspace/test_network_0/0.ledger .
4545
$ cp ./workspace/test_network_0/network_enc_pubk.pem .
46-
$ ../start_test_network.sh -p liblogging.enclave.so.signed --recover --ledger 0.ledger --network-enc-pubk network_enc_pubk.pem --common-dir ./workspace/test_network_common/
46+
$ ../start_test_network.sh -p liblogging.enclave.so.signed --recover --ledger-dir 0.ledger --network-enc-pubk network_enc_pubk.pem --common-dir ./workspace/test_network_common/
4747
[2020-05-14 14:50:19.746] Starting 3 CCF nodes...
4848
[2020-05-14 14:50:19.746] Recovering network from:
4949
[2020-05-14 14:50:19.746] - Ledger: 0.ledger

src/consensus/ledger_enclave.h

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,70 +28,56 @@ namespace consensus
2828
* Put a single entry to be written the ledger, when primary.
2929
*
3030
* @param entry Serialised entry
31+
* @param globally_committable True is entry is signature transaction
3132
*/
32-
void put_entry(const std::vector<uint8_t>& entry)
33+
void put_entry(const std::vector<uint8_t>& entry, bool globally_committable)
3334
{
34-
// write the message
35-
RINGBUFFER_WRITE_MESSAGE(consensus::ledger_append, to_host, entry);
35+
put_entry(entry.data(), entry.size(), globally_committable);
3636
}
3737

3838
/**
3939
* Put a single entry to be written the ledger, when primary.
4040
*
4141
* @param data Serialised entry start
4242
* @param size Serialised entry size
43+
* @param globally_committable True is entry is signature transaction
4344
*/
44-
void put_entry(const uint8_t* data, size_t size)
45+
void put_entry(const uint8_t* data, size_t size, bool globally_committable)
4546
{
4647
serializer::ByteRange byte_range = {data, size};
4748
// write the message
48-
RINGBUFFER_WRITE_MESSAGE(consensus::ledger_append, to_host, byte_range);
49+
RINGBUFFER_WRITE_MESSAGE(
50+
consensus::ledger_append, to_host, globally_committable, byte_range);
4951
}
5052

5153
/**
52-
* Record a single entry to the ledger, when backup.
54+
* Skip a single entry, when backup.
55+
*
56+
* Does not write any entry to the legder.
5357
*
5458
* @param data Serialised entries
5559
* @param size Size of overall serialised entries
56-
*
57-
* @return Pair of boolean status (false if rejected), raw data as a vector
5860
*/
59-
std::pair<std::vector<uint8_t>, bool> record_entry(
60-
const uint8_t*& data, size_t& size)
61+
void skip_entry(const uint8_t*& data, size_t& size)
6162
{
6263
auto entry_len = serialized::read<uint32_t>(data, size);
63-
std::vector<uint8_t> entry(data, data + entry_len);
64-
65-
RINGBUFFER_WRITE_MESSAGE(consensus::ledger_append, to_host, entry);
66-
6764
serialized::skip(data, size, entry_len);
68-
69-
return std::make_pair(std::move(entry), true);
7065
}
7166

7267
/**
73-
* Skip a single entry, when backup.
74-
*
75-
* Does not write any entry to the legder.
68+
* Retrieve a single entry, advancing offset to the next entry.
7669
*
7770
* @param data Serialised entries
7871
* @param size Size of overall serialised entries
72+
*
73+
* @return Raw entry as a vector
7974
*/
80-
void skip_entry(const uint8_t*& data, size_t& size)
81-
{
82-
auto entry_len = serialized::read<uint32_t>(data, size);
83-
serialized::skip(data, size, entry_len);
84-
}
85-
86-
std::pair<std::vector<uint8_t>, bool> get_entry(
87-
const uint8_t*& data, size_t& size)
75+
std::vector<uint8_t> get_entry(const uint8_t*& data, size_t& size)
8876
{
8977
auto entry_len = serialized::read<uint32_t>(data, size);
9078
std::vector<uint8_t> entry(data, data + entry_len);
91-
9279
serialized::skip(data, size, entry_len);
93-
94-
return std::make_pair(std::move(entry), true);
80+
return entry;
9581
}
9682

9783
/**
@@ -103,5 +89,15 @@ namespace consensus
10389
{
10490
RINGBUFFER_WRITE_MESSAGE(consensus::ledger_truncate, to_host, idx);
10591
}
92+
93+
/**
94+
* Commit the ledger at a given index.
95+
*
96+
* @param idx Index to commit at
97+
*/
98+
void commit(Index idx)
99+
{
100+
RINGBUFFER_WRITE_MESSAGE(consensus::ledger_commit, to_host, idx);
101+
}
106102
};
107103
}

src/consensus/ledger_enclave_types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace consensus
3030
/// Modify the local ledger. Enclave -> Host
3131
DEFINE_RINGBUFFER_MSG_TYPE(ledger_append),
3232
DEFINE_RINGBUFFER_MSG_TYPE(ledger_truncate),
33+
DEFINE_RINGBUFFER_MSG_TYPE(ledger_commit),
3334
///@}
3435
};
3536
}
@@ -46,6 +47,7 @@ DECLARE_RINGBUFFER_MESSAGE_PAYLOAD(
4647
consensus::Index,
4748
consensus::LedgerRequestPurpose);
4849
DECLARE_RINGBUFFER_MESSAGE_PAYLOAD(
49-
consensus::ledger_append, std::vector<uint8_t>);
50+
consensus::ledger_append, bool /* committable */, std::vector<uint8_t>);
5051
DECLARE_RINGBUFFER_MESSAGE_PAYLOAD(
5152
consensus::ledger_truncate, consensus::Index);
53+
DECLARE_RINGBUFFER_MESSAGE_PAYLOAD(consensus::ledger_commit, consensus::Index);

src/consensus/pbft/libbyz/ledger_writer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// Licensed under the MIT license.
33
#pragma once
44

5+
#include "consensus/pbft/libbyz/ledger.h"
56
#include "consensus/pbft/pbft_new_views.h"
67
#include "consensus/pbft/pbft_pre_prepares.h"
78
#include "consensus/pbft/pbft_requests.h"
89
#include "consensus/pbft/pbft_types.h"
910
#include "kv/kv_types.h"
10-
#include "ledger.h"
1111
#include "new_view.h"
1212
#include "node/signatures.h"
1313
#include "prepared_cert.h"

src/consensus/pbft/libbyz/test/replica_unit_tests.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "consensus/pbft/pbft_tables.h"
99
#include "consensus/pbft/pbft_types.h"
1010
#include "ds/ccf_exception.h"
11-
#include "host/ledger.h"
1211
#include "kv/store.h"
1312
#include "kv/test/stub_consensus.h"
1413
#include "message.h"

0 commit comments

Comments
 (0)