/
ror_app_state.hpp
65 lines (52 loc) · 2.53 KB
/
ror_app_state.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <memory>
#include <string>
#include "bcstatetransfer/SimpleBCStateTransfer.hpp"
#include "blockchain/block.h"
#include "blockchain/db_adapter.h"
#include "kv_types.hpp"
#include "sliver.hpp"
#include "status.hpp"
#include "storage/db_interface.h"
#include "object_store/object_store_client.hpp"
const std::string kLastBlockIdKey = "1";
const std::string kLastReachableBlockIdKey = "2";
namespace concord {
namespace consensus {
class RoRAppState : public bftEngine::SimpleBlockchainStateTransfer::IAppState {
public:
~RoRAppState();
RoRAppState(std::shared_ptr<concord::storage::blockchain::DBKeyManipulator> keyManipulator,
std::shared_ptr<concord::storage::IDBClient> localClient,
std::shared_ptr<concord::storage::IDBClient> objectStoreClient);
// returns true IFF block blockId exists
// (i.e. the block is stored in the application/storage layer).
bool hasBlock(uint64_t blockId) override;
// If block blockId exists, then its content is returned via the arguments
// outBlock and outBlockSize. Returns true IFF block blockId exists.
bool getBlock(uint64_t blockId, char *outBlock, uint32_t *outBlockSize) override;
// If block blockId exists, then the digest of block blockId-1 is returned via
// the argument outPrevBlockDigest. Returns true IFF block blockId exists.
bool getPrevDigestFromBlock(uint64_t blockId,
bftEngine::SimpleBlockchainStateTransfer::StateTransferDigest *) override;
// adds block
// blockId - the block number
// block - pointer to a buffer that contains the new block
// blockSize - the size of the new block
bool putBlock(uint64_t blockId, char *block, uint32_t blockSize) override;
// returns the maximal block number n such that all blocks 1 <= i <= n exist.
// if block 1 does not exist, returns 0.
uint64_t getLastReachableBlockNum() override;
void setLastReachableBlockNum(uint64_t blockId) override { pImpl_->setLastReachableBlockNum(blockId); }
// returns the maximum block number that is currently stored in
// the application/storage layer.
uint64_t getLastBlockNum() override;
// When the state is updated by the application, getLastReachableBlockNum()
// and getLastBlockNum() should always return the same block number.
// When that state transfer module is updating the state, then these methods
// may return different block numbers.State
private:
std::shared_ptr<bftEngine::SimpleBlockchainStateTransfer::IAppState> pImpl_ = nullptr;
};
} // namespace consensus
} // namespace concord