Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
Miscellaneous changes (#975)
Browse files Browse the repository at this point in the history
* dead code

* fix typo

* use const refs

* use context manager with lock

* Prevent goto-fail-like errors

* remove dead code

* remove pointless semicolon

* unused header

* unused constant

* superfluous getter

* Move implementations to cpp file; singleton should have private dtor

* Restore HTTPRequest::header_length()

* Restore MainChainRpcService::state()

* Revert changes to Metrics apart from private dtor

* Style
  • Loading branch information
Wojciech Kaluza authored May 14, 2019
1 parent e3f5b83 commit 5dfdb75
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 75 deletions.
1 change: 0 additions & 1 deletion apps/constellation/constellation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ namespace {

using LaneIndex = fetch::ledger::LaneIdentity::lane_type;

// static const std::chrono::milliseconds LANE_CONNECTION_TIME{10000};
static const std::size_t HTTP_THREADS{4};

bool WaitForLaneServersToStart()
Expand Down
13 changes: 0 additions & 13 deletions apps/constellation/constellation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,6 @@

namespace fetch {

namespace ledger {
namespace consensus {

enum class ConsensusMinerType
{
NO_MINER = 0,
DUMMY_MINER = 1,
BAD_MINER = 2
};

} // namespace consensus
} // namespace ledger

/**
* Top level container for all components that are required to run a ledger instance
*/
Expand Down
14 changes: 7 additions & 7 deletions apps/constellation/health_check_http_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class HealthCheckHttpModule : public http::HTTPModule
using MainChain = ledger::MainChain;
using MainChainRpcService = ledger::MainChainRpcService;

HealthCheckHttpModule(MainChain &chain, MainChainRpcService &chain_service,
BlockCoordinator &block_coordinator)
HealthCheckHttpModule(MainChain const &chain, MainChainRpcService const &chain_service,
BlockCoordinator const &block_coordinator)
: chain_{chain}
, chain_service_{chain_service}
, block_coordinator_{block_coordinator}
Expand All @@ -41,7 +41,7 @@ class HealthCheckHttpModule : public http::HTTPModule

Get("/api/health/ready", [this](http::ViewParameters const &, http::HTTPRequest const &) {
// determine the state of the machine system state machines
bool const chain_synced = chain_service_.state() == MainChainRpcService::State::SYNCHRONISED;
bool const chain_synced = chain_service_.IsSynced();
bool const chain_executed_finished =
block_coordinator_.GetStateMachine().state() == BlockCoordinator::State::SYNCHRONIZED;
bool const chain_execution_complete =
Expand All @@ -64,9 +64,9 @@ class HealthCheckHttpModule : public http::HTTPModule
}

private:
MainChain & chain_;
MainChainRpcService &chain_service_;
BlockCoordinator & block_coordinator_;
MainChain const & chain_;
MainChainRpcService const &chain_service_;
BlockCoordinator const & block_coordinator_;
};

} // namespace fetch
} // namespace fetch
25 changes: 0 additions & 25 deletions libs/http/include/http/middleware.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion libs/http/include/http/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class HTTPRequest
void SetMethod(Method method)
{
method_ = method;
};
}

void SetURI(byte_array_type const &uri)
{
Expand Down
2 changes: 1 addition & 1 deletion libs/http/src/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ bool HTTPRequest::ParseHeader(asio::streambuf &buffer, std::size_t const &end)

header_data_[i] = uint8_t(c);

// find either the header seperator ':' (in the case of KEY: VALUE header) to the new line
// find either the header separator ':' (in the case of KEY: VALUE header) to the new line
// which indicated the value is complete
switch (c)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "ledger/chain/main_chain.hpp"
#include "network/service/protocol.hpp"

#include <algorithm>

namespace fetch {
namespace ledger {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,14 @@ class MainChainRpcService : public muddle::rpc::Server,

bool IsSynced() const
{
return (State::SYNCHRONISED == state());
return State::SYNCHRONISED == state_machine_->state();
}

// Operators
MainChainRpcService &operator=(MainChainRpcService const &) = delete;
MainChainRpcService &operator=(MainChainRpcService &&) = delete;

private:
static constexpr std::size_t BLOCK_CATCHUP_STEP_SIZE = 30;

using BlockList = fetch::ledger::MainChainProtocol::Blocks;
using StateMachine = core::StateMachine<State>;
using StateMachinePtr = std::shared_ptr<StateMachine>;
Expand Down
1 change: 0 additions & 1 deletion libs/ledger/tests/chain/fake_storage_unit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,4 @@ class FakeStorageUnit : public fetch::ledger::StorageUnitInterface
StateHistory state_history_{};
StateHashStack state_history_stack_{fetch::ledger::GENESIS_MERKLE_ROOT};
Hash current_hash_{fetch::ledger::GENESIS_MERKLE_ROOT};
Hash last_commit_hash_{};
};
10 changes: 5 additions & 5 deletions libs/metrics/include/metrics/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ class Metrics
// Construction / Destruction
Metrics(Metrics const &) = delete;
Metrics(Metrics &&) = delete;
~Metrics()
{
RemoveMetricHandler();
}

// Configuration
void ConfigureFileHandler(std::string filename);
Expand Down Expand Up @@ -77,8 +73,12 @@ class Metrics
Metrics &operator=(Metrics &&) = delete;

private:
// Hidden construction
// Hidden construction / destruction
Metrics() = default;
~Metrics()
{
RemoveMetricHandler();
}
void RemoveMetricHandler();

std::unique_ptr<MetricHandler> handler_object_;
Expand Down
3 changes: 3 additions & 0 deletions libs/ml/include/ml/layers/convolution_1d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class Convolution1D : public SubGraph<T>
{
// Return pre-computed value if exist
if (output_shape_.size() != 0)
{
return output_shape_;
}

// output_shape_[0]=number of output channels
output_shape_.emplace_back(output_channels_);
// output_shape_[1]=number of stride_size steps over input size
Expand Down
3 changes: 3 additions & 0 deletions libs/ml/include/ml/layers/convolution_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class Convolution2D : public SubGraph<T>
{
// Return pre-computed value if exist
if (output_shape_.size() != 0)
{
return output_shape_;
}

// output_shape_[0]=number of output channels
output_shape_.emplace_back(output_channels_);
// output_shape_[1]=number of stride_size steps over input height
Expand Down
3 changes: 3 additions & 0 deletions libs/ml/include/ml/ops/convolution_1d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ std::vector<typename ArrayType::SizeType> Convolution1D<ArrayType>::ComputeOutpu
{
// Return pre-computed value if exist
if (output_shape_.size() != 0)
{
return output_shape_;
}

// output_shape_[0]=number of output channels
output_shape_.emplace_back(inputs.at(1).get().shape()[0]);
// output_shape_[1]=number of stride_size steps over input size
Expand Down
3 changes: 3 additions & 0 deletions libs/ml/include/ml/ops/max_pool_1d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ class MaxPool1D : public BatchOps<T>
{
// Return pre-computed value if exist
if (output_shape_.size() != 0)
{
return output_shape_;
}

// output_shape_[0]=number of output channels
output_shape_.emplace_back(inputs.at(0).get().shape().at(0));
// output_shape_[1]=number of stride_size steps over input size
Expand Down
3 changes: 3 additions & 0 deletions libs/ml/include/ml/ops/max_pool_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ class MaxPool2D : public BatchOps<T>
{
// Return pre-computed value if exist
if (output_shape_.size() != 0)
{
return output_shape_;
}

// output_shape_[0]=number of output channels
output_shape_.emplace_back(inputs.at(0).get().shape().at(0));
// output_shape_[1]=number of stride_size steps over input height
Expand Down
4 changes: 0 additions & 4 deletions libs/network/tests/network/tcp_client_server_stress_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ using namespace fetch::byte_array;

static constexpr char const *LOGGING_NAME = "TcpClientServerStressTests";

std::atomic<std::size_t> clientReceivedCount_{0};
std::atomic<std::size_t> serverReceivedCount{0};

std::vector<message_type> globalMessagesFromServer_{};
std::vector<message_type> globalMessagesToServer_{};
std::mutex messages_;

// Basic server
Expand Down
2 changes: 0 additions & 2 deletions libs/python/include/python/http/py_middleware.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@
//
//------------------------------------------------------------------------------

#include "http/middleware.hpp"

#include "fetch_pybind.hpp"
15 changes: 5 additions & 10 deletions scripts/apply_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@ def find_clang_format():
return potential_path


def output(text=None):
output_lock.acquire()
if text is not None:
sys.stdout.write(str(text))
sys.stdout.write('\n')
sys.stdout.flush()
output_lock.release()
def output(text):
with output_lock:
sys.stdout.write('{}\n'.format(text))
sys.stdout.flush()


def parse_commandline():
Expand Down Expand Up @@ -223,8 +220,7 @@ def compare_against_original(reformatted, source_path, rel_path, names_only):
if names_only:
output(rel_path)
else:
output('Style mismatch in: {}'.format(rel_path))
output()
output('Style mismatch in: {}\n'.format(rel_path))
output('\n'.join(out[3:])) # first 3 elements are garbage
success = False

Expand All @@ -237,7 +233,6 @@ def format_cpp(args):
output('Unable to locate clang-format tool')
sys.exit(1)

# generate the
cmd_prefix = [
clang_format,
'-style=file',
Expand Down

0 comments on commit 5dfdb75

Please sign in to comment.