Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .githooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ SPDX-License-Identifier: Apache-2.0

# Git Hooks

This folder _might_ contain some git-hooks to execute various checkup in Kagome.
This folder _might_ contain some git-hooks to execute various checkup in Lean.

To activate presented (_and all future_) hooks just execute **once** shell-script [activate_hooks.sh](./activate_hooks.sh) from Kagome project root path.
To activate presented (_and all future_) hooks just execute **once** shell-script [activate_hooks.sh](./activate_hooks.sh) from Lean project root path.

## pre-commit

Expand Down
6 changes: 5 additions & 1 deletion src/blockchain/genesis_block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ namespace lean::blockchain {

class GenesisBlockHeader : public BlockHeader {
public:
using BlockHeader::BlockHeader;
template <typename... Args>
GenesisBlockHeader(Args &&...args)
: BlockHeader(std::forward<Args>(args)...) {
updateHash();
}
};

} // namespace lean::blockchain
4 changes: 2 additions & 2 deletions src/blockchain/impl/block_storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ namespace lean::blockchain {
if (encoded_header_opt.has_value()) {
auto &encoded_header = encoded_header_opt.value();
OUTCOME_TRY(header, decode<BlockHeader>(encoded_header));
header.hash_opt.emplace(block_hash);
return std::make_optional(std::move(header));
BOOST_ASSERT((header.updateHash(), header.hash() == block_hash));
return std::make_optional(header);
}
return std::nullopt;
}
Expand Down
7 changes: 0 additions & 7 deletions src/blockchain/impl/block_tree_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ namespace lean::blockchain {
});
}

void BlockTreeImpl::notifyChainEventsEngine(EventTypes event,
const BlockHeader &header) {
BOOST_ASSERT(header.hash_opt.has_value());
auto header_ptr = std::make_shared<BlockHeader>(header);
se_manager_->notify(event, header_ptr);
}

outcome::result<void> BlockTreeImpl::removeLeaf(const BlockHash &block_hash) {
return block_tree_data_.exclusiveAccess(
[&](BlockTreeData &p) -> outcome::result<void> {
Expand Down
2 changes: 0 additions & 2 deletions src/blockchain/impl/block_tree_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ namespace lean::blockchain {
const BlockHash &block_hash,
const BlockHeader &block_header);

void notifyChainEventsEngine(EventTypes event, const BlockHeader &header);

class SafeBlockTreeData {
public:
explicit SafeBlockTreeData(BlockTreeData data);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/production/production.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace lean::modules {
block.slot = msg->slot;
block.proposer_index = producer_index;
block.parent_root = parent_hash;
block.state_root = {};
// block.state_root = ;

// Add a block into the block tree
auto res = block_tree_->addBlock(block);
Expand Down
22 changes: 22 additions & 0 deletions src/serde/serialization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,26 @@ namespace lean {
memcpy(hash2.data(), hash1.data(), hash1.size());
return hash2;
}

template <size_t N>
std::array<uint8_t, N>& as_u8(std::array<std::byte, N>& v) {
return reinterpret_cast<std::array<uint8_t, N>&>(v);
}

template <size_t N>
std::array<std::byte, N>& as_byte(std::array<uint8_t, N>& v) {
return reinterpret_cast<std::array<std::byte, N>&>(v);
}

template <size_t N>
std::array<uint8_t, N> as_u8(std::array<std::byte, N>&& v) {
return reinterpret_cast<std::array<uint8_t, N>&>(v);
}

template <size_t N>
std::array<std::byte, N> as_byte(std::array<uint8_t, N>&& v) {
return reinterpret_cast<std::array<std::byte, N>&>(v);
}


} // namespace lean
7 changes: 5 additions & 2 deletions src/types/block_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace lean {
class BlockHeader : public ssz::ssz_container {
public:
/// The block’s slot number
Slot slot;
Slot slot{};
/// Index of the validator that proposed the block
ProposerIndex proposer_index;
ProposerIndex proposer_index{};
/// Hash of the parent block
HeaderHash parent_root;
/// Hash of the post-state after the block is processed
Expand All @@ -34,9 +34,11 @@ namespace lean {

BlockHeader() = default;

private:
/// Block hash if calculated
mutable std::optional<HeaderHash> hash_opt{};

public:
CUSTOM_EQUALITY(
BlockHeader, slot, proposer_index, parent_root, state_root, body_root);

Expand All @@ -56,4 +58,5 @@ namespace lean {
return {slot, hash()};
}
};

} // namespace lean
1 change: 1 addition & 0 deletions src/types/checkpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#pragma once

#include <qtils/byte_arr.hpp>
#include <sszpp/ssz++.hpp>

#include "types.hpp"

Expand Down
12 changes: 8 additions & 4 deletions tests/unit/blockchain/block_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class BlockStorageTest : public testing::Test {
}

void SetUp() override {
genesis_header->hash_opt = genesis_block_hash;
genesis_header->updateHash();
genesis_block_hash = genesis_header->hash();

hasher = std::make_shared<HasherMock>();
spaced_storage = std::make_shared<SpacedStorageMock>();
Expand Down Expand Up @@ -231,16 +232,19 @@ TEST_F(BlockStorageTest, PutWithStorageError) {
BlockHeader header;
header.slot = 1;
header.parent_root = genesis_block_hash;
header.body_root = {}; // ssz::hash_tree_root(body);
header.updateHash();
header.body_root = lean::sszHash(body);

BlockData block;
block.header.emplace(header);
block.header->slot = 1;
block.header->parent_root = genesis_block_hash;
block.body.emplace(body);

ByteVec key{block.header->hash()};
auto encoded_header = ByteVec(encode(*block.header).value());
ON_CALL(*hasher, sha2_256(encoded_header.view()))
.WillByDefault(Return(regular_block_hash));

ByteVec key{lean::sszHash(header)};

EXPECT_CALL(*spaces[Space::Body], put(key.view(), _))
.WillOnce(Return(lean::storage::StorageError::IO_ERROR));
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/storage/rocksdb/rocksdb_integration_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace fs = std::filesystem;

struct RocksDb_Integration_Test : public test::BaseRocksDB_Test {
RocksDb_Integration_Test()
: test::BaseRocksDB_Test("/tmp/kagome_rocksdb_integration_test") {}
: test::BaseRocksDB_Test("/tmp/lean_rocksdb_integration_test") {}

Buffer key_{1, 3, 3, 7};
Buffer value_{1, 2, 3};
Expand Down
Loading