Skip to content

Commit

Permalink
Minimum fix increase, high level api
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Juarez committed Jun 25, 2014
1 parent 69a7708 commit 76bb193
Show file tree
Hide file tree
Showing 82 changed files with 5,407 additions and 708 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
enable_testing()

include_directories(src contrib/epee/include external "${CMAKE_BINARY_DIR}/version")
include_directories(include src contrib/epee/include external "${CMAKE_BINARY_DIR}/version")
if(APPLE)
include_directories(SYSTEM /usr/include/malloc)
endif()

set(STATIC ${MSVC} CACHE BOOL "Link libraries statically")

if(MSVC)
add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__")
add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /D_VARIADIC_MAX=8 /FIinline_c.h /D__SSE4_1__")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760")
if(STATIC)
Expand Down
8 changes: 8 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Release notes 0.8.11

- Increased minimum transaction fee
- Transaction pool optimizations
- High level API implementation
- CryptoNight hash function optimization
- Improvements for wallet JSON RPC API

Release notes 0.8.10

- Optimized blockchain storage memory usage
Expand Down
45 changes: 33 additions & 12 deletions include/INode.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,54 @@
#pragma once

#include <cstdint>
#include <functional>
#include <system_error>
#include <vector>

#include "crypto/crypto.h"
#include "cryptonote_core/cryptonote_basic.h"
#include "cryptonote_protocol/cryptonote_protocol_defs.h"
#include "rpc/core_rpc_server_commands_defs.h"

namespace CryptoNote {

class INodeObserver {
public:
virtual void initCompleted(std::error_code result) {}

virtual ~INodeObserver() {}
virtual void peerCountUpdated(size_t count) {}
virtual void lastLocalBlockHeightUpdated(uint64_t height) {}
virtual void localBlockchainUpdated(uint64_t height) {}
virtual void lastKnownBlockHeightUpdated(uint64_t height) {}
};

virtual void blockchainReorganized(uint64_t height) {}
struct OutEntry {
uint64_t outGlobalIndex;
crypto::public_key outKey;
};

struct OutsForAmount {
uint64_t amount;
std::vector<OutEntry> outs;
};

class INode {
public:
virtual ~INode() = 0;
virtual void addObserver(INodeObserver* observer) = 0;
virtual void removeObserver(INodeObserver* observer) = 0;
typedef std::function<void(std::error_code)> Callback;

virtual ~INode() {}
virtual bool addObserver(INodeObserver* observer) = 0;
virtual bool removeObserver(INodeObserver* observer) = 0;

virtual void init(const Callback& callback) = 0;
virtual bool shutdown() = 0;

virtual void init() = 0;
virtual void shutdown() = 0;
virtual size_t getPeerCount() const = 0;
virtual uint64_t getLastLocalBlockHeight() const = 0;
virtual uint64_t getLastKnownBlockHeight() const = 0;

virtual size_t getPeerCount() = 0;
virtual uint64_t getLastLocalBlockHeight() = 0;
virtual uint64_t getLastKnownBlockHeight() = 0;
virtual void relayTransaction(const cryptonote::transaction& transaction, const Callback& callback) = 0;
virtual void getRandomOutsByAmounts(std::vector<uint64_t>&& amounts, uint64_t outsCount, std::vector<cryptonote::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::outs_for_amount>& result, const Callback& callback) = 0;
virtual void getNewBlocks(std::list<crypto::hash>&& knownBlockIds, std::list<cryptonote::block_complete_entry>& newBlocks, uint64_t& startHeight, const Callback& callback) = 0;
virtual void getTransactionOutsGlobalIndices(const crypto::hash& transactionHash, std::vector<uint64_t>& outsGlobalIndices, const Callback& callback) = 0;
};

}
8 changes: 4 additions & 4 deletions include/IWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace CryptoNote {

typedef size_t TransactionId;
typedef size_t TransferId;
typedef std::array<uint8_t, 32> TransacitonHash;
typedef std::array<uint8_t, 32> TransactionHash;

struct Transfer {
std::string address;
Expand All @@ -33,7 +33,7 @@ struct Transaction {
size_t transferCount;
int64_t totalAmount;
uint64_t fee;
TransacitonHash hash;
TransactionHash hash;
bool isCoinbase;
uint64_t blockHeight;
uint64_t timestamp;
Expand All @@ -44,7 +44,7 @@ class IWalletObserver {
public:
virtual void initCompleted(std::error_code result) {}
virtual void saveCompleted(std::error_code result) {}
virtual void synchronizationProgressUpdated(uint64_t current, uint64_t total) {}
virtual void synchronizationProgressUpdated(uint64_t current, uint64_t total, std::error_code result) {}
virtual void actualBalanceUpdated(uint64_t actualBalance) {}
virtual void pendingBalanceUpdated(uint64_t pendingBalance) {}
virtual void externalTransactionCreated(TransactionId transactionId) {}
Expand All @@ -54,7 +54,7 @@ class IWalletObserver {

class IWallet {
public:
virtual ~IWallet() = 0;
virtual ~IWallet() {} ;
virtual void addObserver(IWalletObserver* observer) = 0;
virtual void removeObserver(IWalletObserver* observer) = 0;

Expand Down
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ file(GLOB_RECURSE SIMPLEWALLET simplewallet/*)
file(GLOB_RECURSE CONN_TOOL connectivity_tool/*)
file(GLOB_RECURSE WALLET wallet/*)
file(GLOB_RECURSE MINER miner/*)
file(GLOB_RECURSE NODE_RPC_PROXY node_rpc_proxy/*)

source_group(common FILES ${COMMON})
source_group(crypto FILES ${CRYPTO})
Expand All @@ -23,6 +24,7 @@ source_group(simplewallet FILES ${SIMPLEWALLET})
source_group(connectivity-tool FILES ${CONN_TOOL})
source_group(wallet FILES ${WALLET})
source_group(simpleminer FILES ${MINER})
source_group(node_rpc_proxy FILES ${NODE_RPC_PROXY})

add_library(common ${COMMON})
add_library(crypto ${CRYPTO})
Expand All @@ -37,10 +39,12 @@ add_library(rpc ${RPC})
add_library(wallet ${WALLET})
add_executable(simplewallet ${SIMPLEWALLET} )
target_link_libraries(simplewallet wallet rpc cryptonote_core crypto common upnpc-static ${Boost_LIBRARIES})
add_library(node_rpc_proxy ${NODE_RPC_PROXY})

add_dependencies(daemon version)
add_dependencies(rpc version)
add_dependencies(simplewallet version)

set_property(TARGET common crypto cryptonote_core rpc wallet PROPERTY FOLDER "libs")
set_property(TARGET common crypto cryptonote_core rpc wallet node_rpc_proxy PROPERTY FOLDER "libs")
set_property(TARGET daemon simplewallet connectivity_tool simpleminer PROPERTY FOLDER "prog")
set_property(TARGET daemon PROPERTY OUTPUT_NAME "bytecoind")
116 changes: 116 additions & 0 deletions src/common/ObserverManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright (c) 2012-2013 The Cryptonote developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#pragma once

#include <mutex>
#include <vector>

namespace tools {

template<typename T>
class ObserverManager {
public:
bool add(T* observer) {
std::unique_lock<std::mutex> lock(m_observersMutex);
auto it = std::find(m_observers.begin(), m_observers.end(), observer);
if (m_observers.end() == it) {
m_observers.push_back(observer);
return true;
} else {
return false;
}
}

bool remove(T* observer) {
std::unique_lock<std::mutex> lock(m_observersMutex);
auto it = std::find(m_observers.begin(), m_observers.end(), observer);
if (m_observers.end() == it) {
return false;
} else {
m_observers.erase(it);
return true;
}
}

void clear() {
std::unique_lock<std::mutex> lock(m_observersMutex);
m_observers.clear();
}

#if defined(_MSC_VER)
template<typename F>
void notify(F notification) {
std::vector<T*> observersCopy;
{
std::unique_lock<std::mutex> lock(m_observersMutex);
observersCopy = m_observers;
}

for (T* observer : observersCopy) {
(observer->*notification)();
}
}

template<typename F, typename Arg0>
void notify(F notification, const Arg0& arg0) {
std::vector<T*> observersCopy;
{
std::unique_lock<std::mutex> lock(m_observersMutex);
observersCopy = m_observers;
}

for (T* observer : observersCopy) {
(observer->*notification)(arg0);
}
}

template<typename F, typename Arg0, typename Arg1>
void notify(F notification, const Arg0& arg0, const Arg1& arg1) {
std::vector<T*> observersCopy;
{
std::unique_lock<std::mutex> lock(m_observersMutex);
observersCopy = m_observers;
}

for (T* observer : observersCopy) {
(observer->*notification)(arg0, arg1);
}
}

template<typename F, typename Arg0, typename Arg1, typename Arg2>
void notify(F notification, const Arg0& arg0, const Arg1& arg1, const Arg2& arg2) {
std::vector<T*> observersCopy;
{
std::unique_lock<std::mutex> lock(m_observersMutex);
observersCopy = m_observers;
}

for (T* observer : observersCopy) {
(observer->*notification)(arg0, arg1, arg2);
}
}

#else

template<typename F, typename... Args>
void notify(F notification, Args... args) {
std::vector<T*> observersCopy;
{
std::unique_lock<std::mutex> lock(m_observersMutex);
observersCopy = m_observers;
}

for (T* observer : observersCopy) {
(observer->*notification)(args...);
}
}
#endif

private:
std::vector<T*> m_observers;
std::mutex m_observersMutex;
};

}
2 changes: 1 addition & 1 deletion src/common/base58.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace tools

void encode_block(const char* block, size_t size, char* res)
{
assert(1 <= size && size <= sizeof(full_block_size));
assert(1 <= size && size <= full_block_size);

uint64_t num = uint_8be_to_64(reinterpret_cast<const uint8_t*>(block), size);
int i = static_cast<int>(encoded_block_sizes[size]) - 1;
Expand Down
12 changes: 6 additions & 6 deletions src/crypto/chacha8.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ namespace crypto {
chacha8(data, length, reinterpret_cast<const uint8_t*>(&key), reinterpret_cast<const uint8_t*>(&iv), cipher);
}

inline void generate_chacha8_key(std::string password, chacha8_key& key) {
inline void generate_chacha8_key(crypto::cn_context &context, std::string password, chacha8_key& key) {
static_assert(sizeof(chacha8_key) <= sizeof(hash), "Size of hash must be at least that of chacha8_key");
char pwd_hash[HASH_SIZE];
crypto::cn_slow_hash(password.data(), password.size(), pwd_hash);
memcpy(&key, pwd_hash, sizeof(key));
memset(pwd_hash, 0, sizeof(pwd_hash));
crypto::hash pwd_hash;
crypto::cn_slow_hash(context, password.data(), password.size(), pwd_hash);
memcpy(&key, &pwd_hash, sizeof(key));
memset(&pwd_hash, 0, sizeof(pwd_hash));
}
}

#endif
#endif
6 changes: 4 additions & 2 deletions src/crypto/hash-ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ void hash_process(union hash_state *state, const uint8_t *buf, size_t count);

enum {
HASH_SIZE = 32,
HASH_DATA_AREA = 136
HASH_DATA_AREA = 136,
SLOW_HASH_CONTEXT_SIZE = 2097552
};

void cn_fast_hash(const void *data, size_t length, char *hash);
void cn_slow_hash(const void *data, size_t length, char *hash);

void cn_slow_hash_f(void *, const void *, size_t, void *);

void hash_extra_blake(const void *data, size_t length, char *hash);
void hash_extra_groestl(const void *data, size_t length, char *hash);
Expand Down
22 changes: 19 additions & 3 deletions src/crypto/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,24 @@ namespace crypto {
return h;
}

inline void cn_slow_hash(const void *data, std::size_t length, hash &hash) {
cn_slow_hash(data, length, reinterpret_cast<char *>(&hash));
class cn_context {
public:

cn_context();
~cn_context();
#if !defined(_MSC_VER) || _MSC_VER >= 1800
cn_context(const cn_context &) = delete;
void operator=(const cn_context &) = delete;
#endif

private:

void *data;
friend inline void cn_slow_hash(cn_context &, const void *, std::size_t, hash &);
};

inline void cn_slow_hash(cn_context &context, const void *data, std::size_t length, hash &hash) {
(*cn_slow_hash_f)(context.data, data, length, reinterpret_cast<void *>(&hash));
}

inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
Expand All @@ -47,4 +63,4 @@ namespace crypto {

}

CRYPTO_MAKE_HASHABLE(hash)
CRYPTO_MAKE_HASHABLE(hash)
Loading

1 comment on commit 76bb193

@fluffypony
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additions to the wallet RPC call taken from Monero: monero-project/monero@117393d

It's a pleasure, feel free to copy and paste our code any time.

Please sign in to comment.