Skip to content

Commit

Permalink
Merge pull request #51 from LogosNetwork/LOGOS-65-Integration-Issues
Browse files Browse the repository at this point in the history
Final fixes before testnet upgrade
  • Loading branch information
ShangyanLi authored Apr 25, 2019
2 parents bce0753 + 5406ed2 commit 8e2d455
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion logos/consensus/consensus_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ ConsensusContainer::CancelTimer(ConsensusType CT)
// 'manually' cancel the callback by setting _cancel_timer.
// When the callback is invoked, it will check this value
// and return early.
auto now = Clock::universal_time();
auto now = Clock::now();
if(now < timer.expires_at() && !timer.cancel() && _timer_set[CT])
{
LOG_DEBUG(_log) << "ConsensusContainer::CancelTimer " << ConsensusToName(CT) << " - force cancel.";
Expand Down
2 changes: 2 additions & 0 deletions logos/consensus/consensus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ void ConsensusManager<CT>::OnMessageQueued()
// Get most imminent timeout, if any, and schedule timer
auto imminent_timeout = GetHandler().GetImminentTimeout();
if (imminent_timeout == Min_DT) return;
LOG_DEBUG(_log) << "ConsensusManager<" << ConsensusToName(CT) << ">::OnMessageQueued - "
<< "imminent timeout is " << imminent_timeout << ", scheduling timer";
_scheduler.ScheduleTimer(CT, imminent_timeout);
}
}
Expand Down
9 changes: 4 additions & 5 deletions logos/consensus/message_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ MessageHandler<CT>::MessageHandler()
template<ConsensusType CT>
void MessageHandler<CT>::OnMessage(const MessagePtr & message, const Seconds & seconds)
{
OnMessage(message, Clock::universal_time() + seconds);
OnMessage(message, Clock::now() + seconds);
}

template<ConsensusType CT>
Expand Down Expand Up @@ -64,7 +64,7 @@ bool MessageHandler<CT>::PrimaryEmpty()
std::lock_guard<std::mutex> lock(_mutex);
auto &expiration_index = _entries. template get<2>();
auto it = expiration_index.lower_bound(Min_DT);
auto end = expiration_index.upper_bound(Clock::universal_time());
auto end = expiration_index.upper_bound(Clock::now());
return it == end;
}

Expand All @@ -73,7 +73,7 @@ auto MessageHandler<CT>::GetImminentTimeout() -> const TimePoint &
{
std::lock_guard<std::mutex> lock(_mutex);
auto &expiration_index = _entries. template get<2>();
auto it = expiration_index.lower_bound(Clock::universal_time());
auto it = expiration_index.lower_bound(Clock::now());
if (it == expiration_index.end()) return Min_DT;
return it->expiration;
}
Expand Down Expand Up @@ -137,8 +137,7 @@ void RequestMessageHandler::MoveToTarget(RequestInternalQueue & queue, size_t si
{
std::lock_guard<std::mutex> lock(_mutex);
auto &expiration_index = _entries. template get<2>();

auto end = expiration_index.upper_bound(Clock::universal_time()); // strictly greater than
auto end = expiration_index.upper_bound(Clock::now()); // strictly greater than

for(auto pos = expiration_index.lower_bound(Min_DT); pos != end && size != 0; size--)
{
Expand Down
6 changes: 4 additions & 2 deletions logos/consensus/messages/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <logos/lib/log.hpp>
#include <logos/lib/trace.hpp>
#include <arpa/inet.h>

#include <boost/algorithm/string.hpp>

static constexpr size_t MAX_MSG_SIZE = 1024*1024;
// TODO: Update based on new request types
Expand Down Expand Up @@ -206,7 +206,9 @@ struct PostCommittedBlock : public MessagePrequel<MessageType::Post_Committed_Bl
SerializeJson (tree);
std::stringstream ostream;
boost::property_tree::write_json(ostream, tree);
return ostream.str();
std::string s = ostream.str();
boost::replace_all(s, "\"[]\"", "[]");
return s;
}

uint32_t Serialize(logos::stream & stream, bool with_appendix, bool with_next) const
Expand Down
2 changes: 0 additions & 2 deletions logos/consensus/messages/receive_block.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,3 @@ struct ReceiveBlock
BlockHash send_hash;
uint16_t index2send = 0;
};


Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ void PersistenceManager<R>::ApplyRequest(RequestPtr request,

entry->balance -= revoke->transaction.amount;

ReceiveBlock receive(user_account.receive_head, revoke->GetHash(), 0);
ReceiveBlock receive(user_account.receive_head, revoke->GetHash(), Revoke::REVOKE_OFFSET);
user_account.receive_head = receive.Hash();

PlaceReceive(receive, timestamp, transaction);
Expand Down
6 changes: 3 additions & 3 deletions logos/consensus/request/request_backup_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ RequestBackupDelegate::HandleReject(const PrePrepare & message)
// If reason is contain invalid request, still need to queue up requests we agree on
std::lock_guard<std::mutex> lock(_mutex); // SYL Integration fix
_pre_prepare_hashes.clear();
auto timeout = Clock::universal_time() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE);
auto timeout = Clock::now() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE);
for(uint16_t i = 0; i < message.requests.size(); ++i)
{
if (!_rejection_map[i])
Expand Down Expand Up @@ -169,7 +169,7 @@ RequestBackupDelegate::HandleReject(const PrePrepare & message)
{
_handler.OnMessage(std::static_pointer_cast<Request>(message.requests[i]), timeout);
}
_scheduler.ScheduleTimer(R, Clock::universal_time() + timeout);
_scheduler.ScheduleTimer(R, Clock::now() + timeout);
}
break;
}
Expand All @@ -194,7 +194,7 @@ RequestBackupDelegate::HandlePrePrepare(const PrePrepare & message)
std::lock_guard<std::mutex> lock(_mutex); // SYL Integration fix
_pre_prepare_hashes.clear();

auto timeout = Clock::universal_time() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE);
auto timeout = Clock::now() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE);
for(uint64_t i = 0; i < message.requests.size(); ++i)
{
_pre_prepare_hashes.insert(message.requests[i]->GetHash());
Expand Down
3 changes: 2 additions & 1 deletion logos/lib/epoch_time_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
#include <stdint.h>
#include <mutex>
#include <functional>
#include <boost/asio/deadline_timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

using Milliseconds = std::chrono::milliseconds;
using Seconds = std::chrono::seconds;
using Minutes = std::chrono::minutes;
using Hours = std::chrono::hours;

using Clock = boost::posix_time::second_clock;
using Clock = boost::asio::deadline_timer::traits_type;
using TimePoint = boost::posix_time::ptime;
static const TimePoint Min_DT = TimePoint(boost::posix_time::min_date_time);

Expand Down
6 changes: 1 addition & 5 deletions logos/node/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,17 +1214,13 @@ void logos::rpc_handler::block_create ()
return;

}
if(type == RequestType::Issuance)
{
auto issuance = static_pointer_cast<Issuance>(created_request);
issuance->token_id = GetTokenID(*issuance);
}

std::shared_ptr<logos::Account> info_ptr;
if(!node.store.account_get(created_request->GetAccount(),info_ptr))
{
created_request->sequence = info_ptr->block_count;
created_request->previous = info_ptr->head;
created_request->Sign(prv.data, pub);
}

boost::property_tree::ptree response_l;
Expand Down
4 changes: 3 additions & 1 deletion logos/token/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Issuance::Issuance(bool & error,
}

issuer_info = tree.get<std::string>(ISSUER_INFO, "");

token_id = GetTokenID(symbol, name, origin, previous);
SignAndHash(error, tree);
}
catch (...)
Expand Down Expand Up @@ -479,7 +481,7 @@ IssueAdditional::IssueAdditional(bool & error,
return;
}

Hash();
SignAndHash(error, tree);
}
catch(...)
{
Expand Down
3 changes: 3 additions & 0 deletions logos/token/requests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ struct Revoke : TokenRequest

bool operator==(const Request & other) const override;

// offset of 128 to facilitate index lookup from revoke source's receive
static constexpr uint16_t REVOKE_OFFSET = 0x0080;

AccountAddress source;
Transaction transaction;
};
Expand Down
2 changes: 0 additions & 2 deletions logos/tx_acceptor/tx_acceptor_channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <logos/network/net_io_send.hpp>
#include <logos/lib/log.hpp>

#include <boost/asio/deadline_timer.hpp>

namespace logos { class node_config; }

/// Implements forwarding to the Delegate
Expand Down

0 comments on commit 8e2d455

Please sign in to comment.